PageRenderTime 62ms CodeModel.GetById 27ms RepoModel.GetById 0ms app.codeStats 0ms

/ModuleInstall/PackageManager/PackageManagerDisplay.php

https://github.com/item/sugarcrm_dev
PHP | 608 lines | 442 code | 49 blank | 117 comment | 57 complexity | 93b924429334f29e194a1a8a12fdc0a8 MD5 | raw file
Possible License(s): AGPL-3.0, LGPL-2.1
  1. <?php
  2. /*********************************************************************************
  3. * SugarCRM is a customer relationship management program developed by
  4. * SugarCRM, Inc. Copyright (C) 2004-2011 SugarCRM Inc.
  5. *
  6. * This program is free software; you can redistribute it and/or modify it under
  7. * the terms of the GNU Affero General Public License version 3 as published by the
  8. * Free Software Foundation with the addition of the following permission added
  9. * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
  10. * IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
  11. * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
  12. *
  13. * This program is distributed in the hope that it will be useful, but WITHOUT
  14. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  15. * FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
  16. * details.
  17. *
  18. * You should have received a copy of the GNU Affero General Public License along with
  19. * this program; if not, see http://www.gnu.org/licenses or write to the Free
  20. * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  21. * 02110-1301 USA.
  22. *
  23. * You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
  24. * SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
  25. *
  26. * The interactive user interfaces in modified source and object code versions
  27. * of this program must display Appropriate Legal Notices, as required under
  28. * Section 5 of the GNU Affero General Public License version 3.
  29. *
  30. * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
  31. * these Appropriate Legal Notices must retain the display of the "Powered by
  32. * SugarCRM" logo. If the display of the logo is not reasonably feasible for
  33. * technical reasons, the Appropriate Legal Notices must display the words
  34. * "Powered by SugarCRM".
  35. ********************************************************************************/
  36. require_once('ModuleInstall/PackageManager/PackageManager.php');
  37. require_once('include/ytree/Tree.php');
  38. require_once('include/ytree/Node.php');
  39. require_once('ModuleInstall/PackageManager/ListViewPackages.php');
  40. class PackageManagerDisplay{
  41. /**
  42. * A Static method to Build the display for the package manager
  43. *
  44. * @param String form1 - the form to display for manual downloading
  45. * @param String hidden_fields - the hidden fields related to downloading a package
  46. * @param String form_action - the form_action to be used when downloading from the server
  47. * @param String types - the types of objects we will request from the server
  48. * @param String active_form - the form to display first
  49. * @return String - a string of html which will be used to display the forms
  50. */
  51. function buildPackageDisplay($form1, $hidden_fields, $form_action, $types = array('module'), $active_form = 'form1', $install = false){
  52. global $current_language;
  53. $mod_strings = return_module_language($current_language, "Administration");
  54. global $app_strings;
  55. global $sugar_version, $sugar_config;
  56. $app_strings = return_application_language($current_language);
  57. $ss = new Sugar_Smarty();
  58. $ss->assign('FORM_1_PLACE_HOLDER', $form1);
  59. $ss->assign('form_action', $form_action);
  60. $ss->assign('hidden_fields', $hidden_fields);
  61. $result = PackageManagerDisplay::getHeader();
  62. $header_text = $result['text'];
  63. $isAlive = $result['isAlive'];
  64. $show_login = $result['show_login'];
  65. $mi_errors = ModuleInstaller::getErrors();
  66. $error_html = "";
  67. if(!empty($mi_errors)){
  68. $error_html = "<tr><td><span>";
  69. foreach($mi_errors as $error){
  70. $error_html .= "<font color='red'>".$error."</font><br>";
  71. }
  72. $error_html .= "</span></td></tr>";
  73. }
  74. $form2 = "<table class='tabForm' width='100%' cellpadding='0' cellspacing='0' width='100%' border='0'>";
  75. $form2 .= $error_html;
  76. if(!$isAlive)
  77. $form2 .= "<tr><td><span id='span_display_html'>".$header_text."</span></td></tr>";
  78. $form2 .= "</table>";
  79. $tree = null;
  80. //if($isAlive){
  81. $tree = PackageManagerDisplay::buildTreeView('treeview', $isAlive);
  82. $tree->tree_style= 'include/ytree/TreeView/css/check/tree.css';
  83. $ss->assign('TREEHEADER',$tree->generate_header());
  84. //}
  85. //$form2 .= PackageManagerDisplay::buildLoginPanel($mod_strings);
  86. $form2 .= "<table class='tabForm' cellpadding='0' cellspacing='0' width='100%' border='0'>";
  87. $form2 .= "<tr><td></td><td align='left'>";
  88. if($isAlive){
  89. $form2 .= "<input type='button' id='modifCredentialsBtn' class='button' onClick='PackageManager.showLoginDialog(true);' value='".$mod_strings['LBL_MODIFY_CREDENTIALS']."'>";
  90. }else{
  91. $form2 .= "<input type='button' id='modifCredentialsBtn' class='button' onClick='PackageManager.showLoginDialog(true);' value='".$mod_strings['LBL_MODIFY_CREDENTIALS']."'style='display:none;'>";
  92. }
  93. $form2 .= "</td><td align='left'><div id='workingStatusDiv' style='display:none;'>".SugarThemeRegistry::current()->getImage("sqsWait","border='0' align='bottom'")."</div></td><td align='right'>";
  94. if($isAlive){
  95. $form2 .= "<slot><a class=\"listViewTdToolsS1\" id='href_animate' onClick=\"PackageManager.toggleDiv('span_animate_server_div', 'catview');\"><span id='span_animate_server_div'><img src='".SugarThemeRegistry::current()->getImageURL('basic_search.gif')."' width='8' height='8' border='0'>&nbsp;Collapse</span></a></slot>";
  96. }else{
  97. $form2 .= "<slot><a class=\"listViewTdToolsS1\" id='href_animate' onClick=\"PackageManager.toggleDiv('span_animate_server_div', 'catview');\"><span id='span_animate_server_div' style='display:none;'><img src='".SugarThemeRegistry::current()->getImageURL('basic_search.gif')."' width='8' height='8' border='0'>&nbsp;Collapse</span></a></slot>";
  98. }
  99. $form2 .= "</td></tr></table>";
  100. $form2 = ''; //Commenting out the form as part of sugar depot hiding.
  101. $ss->assign('installation', ($install ? 'true' : 'false'));
  102. $mod_strings = return_module_language($current_language, "Administration");
  103. $ss->assign('MOD', $mod_strings);
  104. $ss->assign('module_load', 'true');
  105. $ss->assign('scripts', PackageManagerDisplay::getDisplayScript($install));
  106. $show_login = false; //hiding install from sugar
  107. $ss->assign('MODULE_SELECTOR', PackageManagerDisplay::buildGridOutput($tree, $mod_strings, $isAlive, $show_login));
  108. $ss->assign('FORM_2_PLACE_HOLDER', $form2);
  109. $ss->assign('MOD', $mod_strings);
  110. $descItemsInstalled = $mod_strings['LBL_UW_DESC_MODULES_INSTALLED'];
  111. $ss->assign('INSTALLED_PACKAGES_HOLDER', PackageManagerDisplay::buildInstalledGrid($mod_strings, $types));
  112. $str = $ss->fetch('ModuleInstall/PackageManager/tpls/PackageForm.tpl');
  113. return $str;
  114. }
  115. /**
  116. * A Static method to Build the display for the package manager
  117. *
  118. * @param String form1 - the form to display for manual downloading
  119. * @param String hidden_fields - the hidden fields related to downloading a package
  120. * @param String form_action - the form_action to be used when downloading from the server
  121. * @param String types - the types of objects we will request from the server
  122. * @param String active_form - the form to display first
  123. * @return String - a string of html which will be used to display the forms
  124. */
  125. function buildPatchDisplay($form1, $hidden_fields, $form_action, $types = array('module'), $active_form = 'form1'){
  126. global $current_language;
  127. $mod_strings = return_module_language($current_language, "Administration");
  128. $ss = new Sugar_Smarty();
  129. $ss->assign('FORM_1_PLACE_HOLDER', $form1);
  130. $ss->assign('form_action', $form_action);
  131. $ss->assign('hidden_fields', $hidden_fields);
  132. $mod_strings = return_module_language($current_language, "Administration");
  133. $ss->assign('MOD', $mod_strings);
  134. $result = PackageManagerDisplay::getHeader();
  135. $header_text = $result['text'];
  136. $isAlive = $result['isAlive'];
  137. $show_login = $result['show_login'];
  138. $display = 'none';
  139. //if($isAlive){
  140. $display = 'block';
  141. //}
  142. $form2 = "<table class='tabForm' width='100%' cellpadding='0' cellspacing='0' width='100%' border='0'>";
  143. if(!$isAlive)
  144. $form2 .= "<tr><td><span id='span_display_html'>".$header_text."</span></td></tr>";
  145. $form2 .= "</table>";
  146. $form2 .= "<table width='100%'><tr><td align='left'>";
  147. if($show_login){
  148. $form2 .= "<input type='button' class='button' onClick='PackageManager.showLoginDialog(true);' value='".$mod_strings['LBL_MODIFY_CREDENTIALS']."'>";
  149. }
  150. $form2 .= "</td><td align='right'><div id='workingStatusDiv' style='display:none;'>".SugarThemeRegistry::current()->getImage("sqsWait","border='0' align='bottom'")."</div></td></tr><tr><td colspan='2'>";
  151. $loginViewStyle = ($isAlive ? 'none' : 'block');
  152. $selectViewStyle = ($isAlive ? 'block' : 'none');
  153. $form2 .= "<div id='selectView' style='display:".$selectViewStyle."'>";
  154. $form2 .= " <div id='patch_downloads' class='ygrid-mso' style='height:205px; display: ".$display.";'></div>";
  155. $form2 .= "</div>";
  156. if(!$show_login)
  157. $loginViewStyle = 'none';
  158. //$form2 .= "<div id='loginView' style='display:".$loginViewStyle."'>";
  159. //$form2 .= PackageManagerDisplay::buildLoginPanel($mod_strings, $isAlive);
  160. //$form2 .= "</div>";
  161. $form2 .= "</td></tr></table>";
  162. $form2 = '';
  163. $packages = array();
  164. $releases = array();
  165. if($isAlive){
  166. $filter = array();
  167. $count = count($types);
  168. $index = 1;
  169. $type_str = '"';
  170. foreach($types as $type){
  171. $type_str .= "'".$type."'";
  172. if($index < $count)
  173. $type_str .= ",";
  174. $index++;
  175. }
  176. $type_str .= '"';
  177. $filter = array('type' => $type_str);
  178. $filter = PackageManager::toNameValueList($filter);
  179. $pm = new PackageManager();
  180. /*if(in_array('patch', $types)){
  181. $releases = $pm->getReleases('3', '3', $filter);
  182. }else{
  183. $releases = $pm->getReleases('', '', $filter);
  184. }*/
  185. }
  186. if($form_action == 'install.php' && (empty($releases) || count($releases['packages']) == 0)){
  187. //return false;
  188. }
  189. $tree = PackageManagerDisplay::buildTreeView('treeview', $isAlive);
  190. $tree->tree_style= 'include/ytree/TreeView/css/check/tree.css';
  191. $ss->assign('TREEHEADER',$tree->generate_header());
  192. $ss->assign('module_load', 'false');
  193. $ss->assign('MODULE_SELECTOR', PackageManagerDisplay::buildGridOutput($tree, $mod_strings, $isAlive, $show_login));
  194. $ss->assign('FORM_2_PLACE_HOLDER', $form2);
  195. $ss->assign('scripts', PackageManagerDisplay::getDisplayScript(false, 'patch', $releases, $types, $isAlive));
  196. $str = $ss->fetch('ModuleInstall/PackageManager/tpls/PackageForm.tpl');
  197. return $str;
  198. }
  199. function buildInstalledGrid($mod_strings, $types = array('modules')){
  200. $descItemsInstalled = $mod_strings['LBL_UW_DESC_MODULES_INSTALLED'];
  201. $output = '<table width="100%" border="0" cellspacing="0" cellpadding="0" ><tr><td align="left">'.$descItemsInstalled.'</td>';
  202. $output .= '</td></tr></table>';
  203. $output .= "<table width='100%'><tr><td ><div id='installed_grid' class='ygrid-mso' style='height:205px;'></div></td></tr></table>";
  204. return $output;
  205. }
  206. function buildLoginPanel($mod_strings, $display_cancel){
  207. $credentials = PackageManager::getCredentials();
  208. $output = "<div id='login_panel'><div class='hd'><b>".$mod_strings['HDR_LOGIN_PANEL']."</b></div>";
  209. $output .= "<div class='bd'><form><table><tr><td>".$mod_strings['LBL_USERNAME']."</td><td><input type='text' name='login_panel_username' id='login_panel_username' value='".$credentials['username']."'></td><td><a href='http://www.sugarcrm.com/crm/index.php?option=com_registration&task=register' target='blank'>".$mod_strings['LNK_NEW_ACCOUNT']."</a></td>";
  210. $output .= "</tr><tr><td>".$mod_strings['LBL_PASSWORD']."</td><td><input type='password' name='login_panel_password' id='login_panel_password'></td><td><a href='http://www.sugarcrm.com/crm/component/option,com_registration/Itemid,0/task,lostPassword/' target='blank'>".$mod_strings['LNK_FORGOT_PASS']."</a></td>";
  211. $terms = PackageManager::getTermsAndConditions();
  212. $output .= "</tr><tr><td colspan='6' valign='top'><b>".$mod_strings['LBL_TERMS_AND_CONDITIONS']."</b><br><textarea readonly cols=80 rows=8>" . $terms['terms'] . '</textarea></td>';
  213. $_SESSION['SugarDepot_TermsVersion'] = (!empty($terms['version']) ? $terms['version'] : '');
  214. $output .= "</td></tr><tr><td colspan='6'><input class='checkbox' type='checkbox' name='cb_terms' id='cb_terms' onclick='if(this.checked){this.form.panel_login_button.disabled=false;}else{this.form.panel_login_button.disabled=true;}'>".$mod_strings['LBL_ACCEPT_TERMS']."</td></tr><tr>";
  215. $output .= "<td align='left'>";
  216. $output .= "<input type='button' id='panel_login_button' name='panel_login_button' value='Login' class='button' onClick='PackageManager.authenticate(this.form.login_panel_username.value, this.form.login_panel_password.value, \"\",\"" . $terms['version'] . "\");' disabled>";
  217. if($display_cancel){
  218. $output .= "&nbsp;<input type='button' id='panel_cancel_button' value='Cancel' class='button' onClick='PackageManager.showLoginDialog(false);'>";
  219. }
  220. $output .= "</td><td></td></tr>";
  221. $output .= "<tr></td><td></td></tr>";
  222. $output .= "</table></div>";
  223. $output .= "<div class='ft'></div></form></div>";
  224. return $output;
  225. }
  226. /**
  227. * Build html in order to display the grids relevant for module loader
  228. *
  229. * @param Tree tree - the tree which we are using to display the categories
  230. * @param Array mod_strings - the local mod strings to display
  231. * @return String - a string of html
  232. */
  233. function buildGridOutput($tree, $mod_strings, $display = true, $show_login = true){
  234. $output = "<div id='catview'>";
  235. $loginViewStyle = ($display ? 'none' : 'block');
  236. $selectViewStyle = ($display ? 'block' : 'none');
  237. $output .= "<div id='selectView' style='display:".$selectViewStyle."'>";
  238. //if($display){
  239. $output .= "<table border=0 width='100%' class='moduleTitle'><tr><td width='100%' valign='top'>";
  240. $output .= "<div id='treeview'>";
  241. $output .= $tree->generate_nodes_array();
  242. $output .= "</div>";
  243. $output .= "</td></tr>";
  244. $output .= "<tr><td width='100%'>";
  245. $output .= "<div id='tabs1'></div>";
  246. $output .= "</td></tr>";
  247. $output .= "<tr><td width='100%' align='left'>";
  248. $output .= "<input type='button' class='button' value='Download Selected' onClick='PackageManager.download();'>";
  249. $output .= "</td></tr></table>";
  250. // }
  251. $output .= "</div>";
  252. if(!$show_login)
  253. $loginViewStyle = 'none';
  254. // $output .= "<div id='loginView' style='display:".$loginViewStyle."'>";
  255. // jchi ,#24296 :commented code because we are currently not using depot, in the future this may change so you can put this code back in.
  256. //$output .= PackageManagerDisplay::buildLoginPanel($mod_strings, $display);
  257. //$output .= "</div>";
  258. //$output .= "<table width='100%' class='moduleTitle' border=1><tr><td><div id='patch_downloads' class='ygrid-mso' style='height:205px;'></div></td></tr></table>";
  259. $output .= "</div>";
  260. return $output;
  261. }
  262. /**
  263. * A Static method used to build the initial treeview when the page is first displayed
  264. *
  265. * @param String div_id - this div in which to display the tree
  266. * @return Tree - the tree that is built
  267. */
  268. function buildTreeView($div_id, $isAlive = true){
  269. $tree = new Tree($div_id);
  270. $nodes = array();
  271. if($isAlive)
  272. $nodes = PackageManager::getCategories('');
  273. foreach($nodes as $arr_node){
  274. $node = new Node($arr_node['id'], $arr_node['label']);
  275. $node->dynamicloadfunction = 'PackageManager.loadDataForNodeForPackage';
  276. $node->expanded = false;
  277. $node->dynamic_load = true;
  278. $node->set_property('href',"javascript:PackageManager.catClick('treeview');");
  279. $tree->add_node($node);
  280. $node->set_property('description', $arr_node['description']);
  281. }
  282. return $tree;
  283. }
  284. /**
  285. * A Static method used to obtain the div for the license
  286. *
  287. * @param String license_file - the path to the license file
  288. * @param String form_action - the form action when accepting the license file
  289. * @param String next_step - the value for the next step in the installation process
  290. * @param String zipFile - a string representing the path to the zip file
  291. * @param String type - module/patch....
  292. * @param String manifest - the path to the manifest file
  293. * @param String modify_field - the field to update when the radio button is changed
  294. * @return String - a form used to display the license
  295. */
  296. function getLicenseDisplay($license_file, $form_action, $next_step, $zipFile, $type, $manifest, $modify_field){
  297. global $current_language;
  298. $mod_strings = return_module_language($current_language, "Administration");
  299. $fh = sugar_fopen($license_file, 'r');
  300. $contents = fread($fh, filesize($license_file));
  301. fclose($fh);
  302. $div_id = urlencode($zipFile);
  303. $display = "<form name='delete{$zipFile}' action='{$form_action}' method='POST'>";
  304. $display .= "<input type='hidden' name='current_step' value='{$next_step}'>";
  305. $display .= "<input type='hidden' name='languagePackAction' value='{$type}'>";
  306. $display .= "<input type='hidden' name='manifest' value='\".urlencode($manifest).\"'>";
  307. $display .= "<input type='hidden' name='zipFile' value='\".urlencode($zipFile).\"'>";
  308. $display .= "<table><tr>";
  309. $display .= "<td align=\"left\" valign=\"top\" colspan=2>";
  310. $display .= "<b><font color='red' >{$mod_strings['LBL_MODULE_LICENSE']}</font></b>";
  311. $display .= "</td>";
  312. $display .= "<td>";
  313. $display .= "<slot><a class=\"listViewTdToolsS1\" id='href_animate' onClick=\"PackageManager.toggleLowerDiv('span_animate_div_$div_id', 'span_license_div_$div_id', 350, 0);\"><span id='span_animate_div_$div_id'<img src='".SugarThemeRegistry::current()->getImageURL('advanced_search.gif')."' width='8' height='8' alt='Advanced' border='0'>&nbsp;Expand</span></a></slot></td>";
  314. $display .= "</td>";
  315. $display .= "</tr>";
  316. $display .= "</table>";
  317. $display .= "<div id='span_license_div_$div_id' style=\"display: none;\">";
  318. $display .= "<table>";
  319. $display .= "<tr>";
  320. $display .= "<td align=\"left\" valign=\"top\" colspan=2>";
  321. $display .= "<textarea cols=\"100\" rows=\"8\">{$contents}</textarea>";
  322. $display .= "</td>";
  323. $display .= "</tr>";
  324. $display .= "<tr>";
  325. $display .= "<td align=\"left\" valign=\"top\" colspan=2>";
  326. $display .= "<input type='radio' id='radio_license_agreement_accept' name='radio_license_agreement' value='accept' onClick=\"document.getElementById('$modify_field').value = 'yes';\">{$mod_strings['LBL_ACCEPT']}&nbsp;";
  327. $display .= "<input type='radio' id='radio_license_agreement_reject' name='radio_license_agreement' value='reject' checked onClick=\"document.getElementById('$modify_field').value = 'no';\">{$mod_strings['LBL_DENY']}";
  328. $display .= "</td>";
  329. $display .= "</tr>";
  330. $display .= "</table>";
  331. $display .= "</div>";
  332. $display .= "</form>";
  333. return $display;
  334. }
  335. /**
  336. * A Static method used to generate the javascript for the page
  337. *
  338. * @return String - the javascript required for the page
  339. */
  340. function getDisplayScript($install = false, $type = 'module', $releases = null, $types = array(), $isAlive = true){
  341. global $sugar_version, $sugar_config;
  342. global $current_language;
  343. $mod_strings = return_module_language($current_language, "Administration");
  344. $ss = new Sugar_Smarty();
  345. $ss->assign('MOD', $mod_strings);
  346. if(!$install){
  347. $install = 0;
  348. }
  349. $ss->assign('INSTALLATION', $install);
  350. $ss->assign('WAIT_IMAGE', SugarThemeRegistry::current()->getImage("loading","border='0' align='bottom'"));
  351. $ss->assign('sugar_version', $sugar_version);
  352. $ss->assign('js_custom_version', $sugar_config['js_custom_version']);
  353. $ss->assign('IS_ALIVE', $isAlive);
  354. //if($type == 'patch' && $releases != null){
  355. if($type == 'patch'){
  356. $ss->assign('module_load', 'false');
  357. $patches = PackageManagerDisplay::createJavascriptPackageArray($releases);
  358. $ss->assign('PATCHES', $patches);
  359. $ss->assign('GRID_TYPE', implode(',', $types));
  360. }else{
  361. $pm = new PackageManager();
  362. $releases = $pm->getPackagesInStaging();
  363. $patches = PackageManagerDisplay::createJavascriptModuleArray($releases);
  364. $ss->assign('PATCHES', $patches);
  365. $installeds = $pm->getinstalledPackages();
  366. $patches = PackageManagerDisplay::createJavascriptModuleArray($installeds, 'mti_installed_data');
  367. $ss->assign('INSTALLED_MODULES', $patches);
  368. $ss->assign('UPGARDE_WIZARD_URL', 'index.php?module=UpgradeWizard&action=index');
  369. $ss->assign('module_load', 'true');
  370. }
  371. if(!empty($GLOBALS['ML_STATUS_MESSAGE']))
  372. $ss->assign('ML_STATUS_MESSAGE',$GLOBALS['ML_STATUS_MESSAGE']);
  373. //Bug 24064. Checking and Defining labels since these might not be cached during Upgrade
  374. if(!isset($mod_strings['LBL_ML_INSTALL']) || empty($mod_strings['LBL_ML_INSTALL'])){
  375. $mod_strings['LBL_ML_INSTALL'] = 'Install';
  376. }
  377. if(!isset($mod_strings['LBL_ML_ENABLE_OR_DISABLE']) || empty($mod_strings['LBL_ML_ENABLE_OR_DISABLE'])) {
  378. $mod_strings['LBL_ML_ENABLE_OR_DISABLE'] = 'Enable/Disable';
  379. }
  380. if(!isset($mod_strings['LBL_ML_DELETE'])|| empty($mod_strings['LBL_ML_DELETE'])){
  381. $mod_strings['LBL_ML_DELETE'] = 'Delete';
  382. }
  383. //Add by jchi 6/23/2008 to fix the bug 21667
  384. $filegrid_column_ary = array(
  385. 'Name' => $mod_strings['LBL_ML_NAME'],
  386. 'Install' => $mod_strings['LBL_ML_INSTALL'],
  387. 'Delete' => $mod_strings['LBL_ML_DELETE'],
  388. 'Type' => $mod_strings['LBL_ML_TYPE'],
  389. 'Version' => $mod_strings['LBL_ML_VERSION'],
  390. 'Published' => $mod_strings['LBL_ML_PUBLISHED'],
  391. 'Uninstallable' => $mod_strings['LBL_ML_UNINSTALLABLE'],
  392. 'Description' => $mod_strings['LBL_ML_DESCRIPTION']
  393. );
  394. $filegridinstalled_column_ary = array(
  395. 'Name' => $mod_strings['LBL_ML_NAME'],
  396. 'Install' => $mod_strings['LBL_ML_INSTALL'],
  397. 'Action' => $mod_strings['LBL_ML_ACTION'],
  398. 'Enable_Or_Disable' => $mod_strings['LBL_ML_ENABLE_OR_DISABLE'],
  399. 'Type' => $mod_strings['LBL_ML_TYPE'],
  400. 'Version' => $mod_strings['LBL_ML_VERSION'],
  401. 'Date_Installed' => $mod_strings['LBL_ML_INSTALLED'],
  402. 'Uninstallable' => $mod_strings['LBL_ML_UNINSTALLABLE'],
  403. 'Description' => $mod_strings['LBL_ML_DESCRIPTION']
  404. );
  405. $ss->assign('ML_FILEGRID_COLUMN',$filegrid_column_ary);
  406. $ss->assign('ML_FILEGRIDINSTALLED_COLUMN',$filegridinstalled_column_ary);
  407. //end
  408. $str = $ss->fetch('ModuleInstall/PackageManager/tpls/PackageManagerScripts.tpl');
  409. return $str;
  410. }
  411. function createJavascriptPackageArray($releases){
  412. $output = "var mti_data = [";
  413. $count = count($releases);
  414. $index = 1;
  415. if(!empty($releases['packages'])){
  416. foreach($releases['packages'] as $release){
  417. $release = PackageManager::fromNameValueList($release);
  418. $output .= "[";
  419. $output .= "'".$release['description']."', '".$release['version']."', '".$release['build_number']."', '".$release['id']."'";
  420. $output .= "]";
  421. if($index < $count)
  422. $output .= ",";
  423. $index++;
  424. }
  425. }
  426. $output .= "]\n;";
  427. return $output;
  428. }
  429. function createJavascriptModuleArray($modules, $variable_name = 'mti_data'){
  430. $output = "var ".$variable_name." = [";
  431. $count = count($modules);
  432. $index = 1;
  433. if(!empty($modules)){
  434. foreach($modules as $module){
  435. $output .= "[";
  436. $output .= "'".$module['name']."', '".$module['file_install']."', '".$module['file']."', '";
  437. if(!empty($module['enabled']))
  438. $output .= $module['enabled'].'_'.$module['file']."', '";
  439. $description = js_escape($module['description']);
  440. $output .= $module['type']."', '".$module['version']."', '".$module['published_date']."', '".$module['uninstallable']."', '".$description."'".(isset($module['upload_file'])?" , '".$module['upload_file']."']":"]");
  441. if($index < $count)
  442. $output .= ",";
  443. $index++;
  444. }
  445. }
  446. $output .= "]\n;";
  447. return $output;
  448. }
  449. /**
  450. * This method is meant to be used to display the license agreement inline on the page
  451. * if the system would like to perform the installation on the same page via an Ajax call
  452. */
  453. function buildLicenseOutput($file){
  454. global $current_language;
  455. $mod_strings = return_module_language($current_language, "Administration");
  456. $contents = '';
  457. $pm = new PackageManager();
  458. $contents = $pm->getLicenseFromFile($file);
  459. $ss = new Sugar_Smarty();
  460. $ss->assign('MOD', $mod_strings);
  461. $ss->assign('LICENSE_CONTENTS', $contents);
  462. $ss->assign('FILE', $file);
  463. $str = $ss->fetch('ModuleInstall/PackageManagerLicense.tpl');
  464. $GLOBALS['log']->debug('LICENSE OUTPUT: '.$str);
  465. return $str;
  466. }
  467. function getHeader(){
  468. global $current_language;
  469. $mod_strings = return_module_language($current_language, "Administration");
  470. $header_text = '';
  471. $isAlive = false;
  472. $show_login = false;
  473. if(!function_exists('curl_init') && $show_login){
  474. $header_text = "<font color='red'><b>".$mod_strings['ERR_ENABLE_CURL']."</b></font>";
  475. $show_login = false;
  476. }else{
  477. $credentials = PackageManager::getCredentials();
  478. if(empty($credentials['username']) || empty($credentials['password'])){
  479. //$header_text = "<font color='red'><b>".$mod_strings['ERR_CREDENTIALS_MISSING']."</b></font>";
  480. }
  481. else{
  482. $result = PackageManagerComm::login();
  483. if((is_array($result) && !empty($result['faultcode'])) || $result == false){
  484. $header_text = "<font color='red'><b>".$result['faultstring']."</b></font>";
  485. }else{
  486. $header_text = PackageManager::getPromotion();
  487. $isAlive = true;
  488. }
  489. }
  490. }
  491. return array('text' => $header_text, 'isAlive' => $isAlive, 'show_login' => $show_login);
  492. }
  493. function buildInstallGrid($view){
  494. $uh = new UpgradeHistory();
  495. $installeds = $uh->getAll();
  496. $upgrades_installed = 0;
  497. $installed_objects = array();
  498. foreach($installeds as $installed)
  499. {
  500. $filename = from_html($installed->filename);
  501. $date_entered = $installed->date_entered;
  502. $type = $installed->type;
  503. $version = $installed->version;
  504. $upgrades_installed++;
  505. $link = "";
  506. switch($type)
  507. {
  508. case "theme":
  509. case "langpack":
  510. case "module":
  511. case "patch":
  512. $manifest_file = extractManifest($filename);
  513. require_once($manifest_file);
  514. $name = empty($manifest['name']) ? $filename : $manifest['name'];
  515. $description = empty($manifest['description']) ? $mod_strings['LBL_UW_NONE'] : $manifest['description'];
  516. if(($upgrades_installed==0 || $uh->UninstallAvailable($installeds, $installed))
  517. && is_file($filename) && !empty($manifest['is_uninstallable']))
  518. {
  519. $link = urlencode( $filename );
  520. }
  521. else
  522. {
  523. $link = 'false';
  524. }
  525. break;
  526. default:
  527. break;
  528. }
  529. if($view == 'default' && $type != 'patch')
  530. {
  531. continue;
  532. }
  533. if($view == 'module'
  534. && $type != 'module' && $type != 'theme' && $type != 'langpack')
  535. {
  536. continue;
  537. }
  538. $target_manifest = remove_file_extension( $filename ) . "-manifest.php";
  539. require_once( "$target_manifest" );
  540. if(isset($manifest['icon']) && $manifest['icon'] != "")
  541. {
  542. $manifest_copy_files_to_dir = isset($manifest['copy_files']['to_dir']) ? clean_path($manifest['copy_files']['to_dir']) : "";
  543. $manifest_copy_files_from_dir = isset($manifest['copy_files']['from_dir']) ? clean_path($manifest['copy_files']['from_dir']) : "";
  544. $manifest_icon = clean_path($manifest['icon']);
  545. $icon = "<img src=\"" . $manifest_copy_files_to_dir . ($manifest_copy_files_from_dir != "" ? substr($manifest_icon, strlen($manifest_copy_files_from_dir)+1) : $manifest_icon ) . "\">";
  546. }
  547. else
  548. {
  549. $icon = getImageForType( $manifest['type'] );
  550. }
  551. $installed_objects[] = array('icon' => $icon, 'name' => $name, 'type' => $type, 'version' => $version, 'date_entered' => $date_entered, 'description' => $description, 'file' => $link);
  552. //print( "<form action=\"" . $form_action . "_prepare\" method=\"post\">\n" );
  553. //print( "<tr><td>$icon</td><td>$name</td><td>$type</td><td>$version</td><td>$date_entered</td><td>$description</td><td>$link</td></tr>\n" );
  554. //print( "</form>\n" );
  555. }
  556. }
  557. }
  558. ?>