PageRenderTime 65ms CodeModel.GetById 32ms RepoModel.GetById 0ms app.codeStats 0ms

/ModuleInstall/PackageManager/PackageManagerDisplay.php

https://github.com/mikmagic/sugarcrm_dev
PHP | 606 lines | 440 code | 49 blank | 117 comment | 57 complexity | 48d00f1fb6f7904ae1dc22166a2f0637 MD5 | raw file
Possible License(s): MPL-2.0-no-copyleft-exception, LGPL-2.1, BSD-3-Clause, AGPL-3.0
  1. <?php
  2. /*********************************************************************************
  3. * SugarCRM Community Edition 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. $contents = sugar_file_get_contents($license_file);
  300. $div_id = urlencode($zipFile);
  301. $display = "<form name='delete{$zipFile}' action='{$form_action}' method='POST'>";
  302. $display .= "<input type='hidden' name='current_step' value='{$next_step}'>";
  303. $display .= "<input type='hidden' name='languagePackAction' value='{$type}'>";
  304. $display .= "<input type='hidden' name='manifest' value='\".urlencode($manifest).\"'>";
  305. $display .= "<input type='hidden' name='zipFile' value='\".urlencode($zipFile).\"'>";
  306. $display .= "<table><tr>";
  307. $display .= "<td align=\"left\" valign=\"top\" colspan=2>";
  308. $display .= "<b><font color='red' >{$mod_strings['LBL_MODULE_LICENSE']}</font></b>";
  309. $display .= "</td>";
  310. $display .= "<td>";
  311. $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>";
  312. $display .= "</td>";
  313. $display .= "</tr>";
  314. $display .= "</table>";
  315. $display .= "<div id='span_license_div_$div_id' style=\"display: none;\">";
  316. $display .= "<table>";
  317. $display .= "<tr>";
  318. $display .= "<td align=\"left\" valign=\"top\" colspan=2>";
  319. $display .= "<textarea cols=\"100\" rows=\"8\">{$contents}</textarea>";
  320. $display .= "</td>";
  321. $display .= "</tr>";
  322. $display .= "<tr>";
  323. $display .= "<td align=\"left\" valign=\"top\" colspan=2>";
  324. $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;";
  325. $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']}";
  326. $display .= "</td>";
  327. $display .= "</tr>";
  328. $display .= "</table>";
  329. $display .= "</div>";
  330. $display .= "</form>";
  331. return $display;
  332. }
  333. /**
  334. * A Static method used to generate the javascript for the page
  335. *
  336. * @return String - the javascript required for the page
  337. */
  338. function getDisplayScript($install = false, $type = 'module', $releases = null, $types = array(), $isAlive = true){
  339. global $sugar_version, $sugar_config;
  340. global $current_language;
  341. $mod_strings = return_module_language($current_language, "Administration");
  342. $ss = new Sugar_Smarty();
  343. $ss->assign('MOD', $mod_strings);
  344. if(!$install){
  345. $install = 0;
  346. }
  347. $ss->assign('INSTALLATION', $install);
  348. $ss->assign('WAIT_IMAGE', SugarThemeRegistry::current()->getImage("loading","border='0' align='bottom'"));
  349. $ss->assign('sugar_version', $sugar_version);
  350. $ss->assign('js_custom_version', $sugar_config['js_custom_version']);
  351. $ss->assign('IS_ALIVE', $isAlive);
  352. //if($type == 'patch' && $releases != null){
  353. if($type == 'patch'){
  354. $ss->assign('module_load', 'false');
  355. $patches = PackageManagerDisplay::createJavascriptPackageArray($releases);
  356. $ss->assign('PATCHES', $patches);
  357. $ss->assign('GRID_TYPE', implode(',', $types));
  358. }else{
  359. $pm = new PackageManager();
  360. $releases = $pm->getPackagesInStaging();
  361. $patches = PackageManagerDisplay::createJavascriptModuleArray($releases);
  362. $ss->assign('PATCHES', $patches);
  363. $installeds = $pm->getinstalledPackages();
  364. $patches = PackageManagerDisplay::createJavascriptModuleArray($installeds, 'mti_installed_data');
  365. $ss->assign('INSTALLED_MODULES', $patches);
  366. $ss->assign('UPGARDE_WIZARD_URL', 'index.php?module=UpgradeWizard&action=index');
  367. $ss->assign('module_load', 'true');
  368. }
  369. if(!empty($GLOBALS['ML_STATUS_MESSAGE']))
  370. $ss->assign('ML_STATUS_MESSAGE',$GLOBALS['ML_STATUS_MESSAGE']);
  371. //Bug 24064. Checking and Defining labels since these might not be cached during Upgrade
  372. if(!isset($mod_strings['LBL_ML_INSTALL']) || empty($mod_strings['LBL_ML_INSTALL'])){
  373. $mod_strings['LBL_ML_INSTALL'] = 'Install';
  374. }
  375. if(!isset($mod_strings['LBL_ML_ENABLE_OR_DISABLE']) || empty($mod_strings['LBL_ML_ENABLE_OR_DISABLE'])) {
  376. $mod_strings['LBL_ML_ENABLE_OR_DISABLE'] = 'Enable/Disable';
  377. }
  378. if(!isset($mod_strings['LBL_ML_DELETE'])|| empty($mod_strings['LBL_ML_DELETE'])){
  379. $mod_strings['LBL_ML_DELETE'] = 'Delete';
  380. }
  381. //Add by jchi 6/23/2008 to fix the bug 21667
  382. $filegrid_column_ary = array(
  383. 'Name' => $mod_strings['LBL_ML_NAME'],
  384. 'Install' => $mod_strings['LBL_ML_INSTALL'],
  385. 'Delete' => $mod_strings['LBL_ML_DELETE'],
  386. 'Type' => $mod_strings['LBL_ML_TYPE'],
  387. 'Version' => $mod_strings['LBL_ML_VERSION'],
  388. 'Published' => $mod_strings['LBL_ML_PUBLISHED'],
  389. 'Uninstallable' => $mod_strings['LBL_ML_UNINSTALLABLE'],
  390. 'Description' => $mod_strings['LBL_ML_DESCRIPTION']
  391. );
  392. $filegridinstalled_column_ary = array(
  393. 'Name' => $mod_strings['LBL_ML_NAME'],
  394. 'Install' => $mod_strings['LBL_ML_INSTALL'],
  395. 'Action' => $mod_strings['LBL_ML_ACTION'],
  396. 'Enable_Or_Disable' => $mod_strings['LBL_ML_ENABLE_OR_DISABLE'],
  397. 'Type' => $mod_strings['LBL_ML_TYPE'],
  398. 'Version' => $mod_strings['LBL_ML_VERSION'],
  399. 'Date_Installed' => $mod_strings['LBL_ML_INSTALLED'],
  400. 'Uninstallable' => $mod_strings['LBL_ML_UNINSTALLABLE'],
  401. 'Description' => $mod_strings['LBL_ML_DESCRIPTION']
  402. );
  403. $ss->assign('ML_FILEGRID_COLUMN',$filegrid_column_ary);
  404. $ss->assign('ML_FILEGRIDINSTALLED_COLUMN',$filegridinstalled_column_ary);
  405. //end
  406. $str = $ss->fetch('ModuleInstall/PackageManager/tpls/PackageManagerScripts.tpl');
  407. return $str;
  408. }
  409. function createJavascriptPackageArray($releases){
  410. $output = "var mti_data = [";
  411. $count = count($releases);
  412. $index = 1;
  413. if(!empty($releases['packages'])){
  414. foreach($releases['packages'] as $release){
  415. $release = PackageManager::fromNameValueList($release);
  416. $output .= "[";
  417. $output .= "'".$release['description']."', '".$release['version']."', '".$release['build_number']."', '".$release['id']."'";
  418. $output .= "]";
  419. if($index < $count)
  420. $output .= ",";
  421. $index++;
  422. }
  423. }
  424. $output .= "]\n;";
  425. return $output;
  426. }
  427. function createJavascriptModuleArray($modules, $variable_name = 'mti_data'){
  428. $output = "var ".$variable_name." = [";
  429. $count = count($modules);
  430. $index = 1;
  431. if(!empty($modules)){
  432. foreach($modules as $module){
  433. $output .= "[";
  434. $output .= "'".$module['name']."', '".$module['file_install']."', '".$module['file']."', '";
  435. if(!empty($module['enabled']))
  436. $output .= $module['enabled'].'_'.$module['file']."', '";
  437. $description = js_escape($module['description']);
  438. $output .= $module['type']."', '".$module['version']."', '".$module['published_date']."', '".$module['uninstallable']."', '".$description."'".(isset($module['upload_file'])?" , '".$module['upload_file']."']":"]");
  439. if($index < $count)
  440. $output .= ",";
  441. $index++;
  442. }
  443. }
  444. $output .= "]\n;";
  445. return $output;
  446. }
  447. /**
  448. * This method is meant to be used to display the license agreement inline on the page
  449. * if the system would like to perform the installation on the same page via an Ajax call
  450. */
  451. function buildLicenseOutput($file){
  452. global $current_language;
  453. $mod_strings = return_module_language($current_language, "Administration");
  454. $contents = '';
  455. $pm = new PackageManager();
  456. $contents = $pm->getLicenseFromFile($file);
  457. $ss = new Sugar_Smarty();
  458. $ss->assign('MOD', $mod_strings);
  459. $ss->assign('LICENSE_CONTENTS', $contents);
  460. $ss->assign('FILE', $file);
  461. $str = $ss->fetch('ModuleInstall/PackageManagerLicense.tpl');
  462. $GLOBALS['log']->debug('LICENSE OUTPUT: '.$str);
  463. return $str;
  464. }
  465. function getHeader(){
  466. global $current_language;
  467. $mod_strings = return_module_language($current_language, "Administration");
  468. $header_text = '';
  469. $isAlive = false;
  470. $show_login = false;
  471. if(!function_exists('curl_init') && $show_login){
  472. $header_text = "<font color='red'><b>".$mod_strings['ERR_ENABLE_CURL']."</b></font>";
  473. $show_login = false;
  474. }else{
  475. $credentials = PackageManager::getCredentials();
  476. if(empty($credentials['username']) || empty($credentials['password'])){
  477. //$header_text = "<font color='red'><b>".$mod_strings['ERR_CREDENTIALS_MISSING']."</b></font>";
  478. }
  479. else{
  480. $result = PackageManagerComm::login();
  481. if((is_array($result) && !empty($result['faultcode'])) || $result == false){
  482. $header_text = "<font color='red'><b>".$result['faultstring']."</b></font>";
  483. }else{
  484. $header_text = PackageManager::getPromotion();
  485. $isAlive = true;
  486. }
  487. }
  488. }
  489. return array('text' => $header_text, 'isAlive' => $isAlive, 'show_login' => $show_login);
  490. }
  491. function buildInstallGrid($view){
  492. $uh = new UpgradeHistory();
  493. $installeds = $uh->getAll();
  494. $upgrades_installed = 0;
  495. $installed_objects = array();
  496. foreach($installeds as $installed)
  497. {
  498. $filename = from_html($installed->filename);
  499. $date_entered = $installed->date_entered;
  500. $type = $installed->type;
  501. $version = $installed->version;
  502. $upgrades_installed++;
  503. $link = "";
  504. switch($type)
  505. {
  506. case "theme":
  507. case "langpack":
  508. case "module":
  509. case "patch":
  510. $manifest_file = extractManifest($filename);
  511. require_once($manifest_file);
  512. $name = empty($manifest['name']) ? $filename : $manifest['name'];
  513. $description = empty($manifest['description']) ? $mod_strings['LBL_UW_NONE'] : $manifest['description'];
  514. if(($upgrades_installed==0 || $uh->UninstallAvailable($installeds, $installed))
  515. && is_file($filename) && !empty($manifest['is_uninstallable']))
  516. {
  517. $link = urlencode( $filename );
  518. }
  519. else
  520. {
  521. $link = 'false';
  522. }
  523. break;
  524. default:
  525. break;
  526. }
  527. if($view == 'default' && $type != 'patch')
  528. {
  529. continue;
  530. }
  531. if($view == 'module'
  532. && $type != 'module' && $type != 'theme' && $type != 'langpack')
  533. {
  534. continue;
  535. }
  536. $target_manifest = remove_file_extension( $filename ) . "-manifest.php";
  537. require_once( "$target_manifest" );
  538. if(isset($manifest['icon']) && $manifest['icon'] != "")
  539. {
  540. $manifest_copy_files_to_dir = isset($manifest['copy_files']['to_dir']) ? clean_path($manifest['copy_files']['to_dir']) : "";
  541. $manifest_copy_files_from_dir = isset($manifest['copy_files']['from_dir']) ? clean_path($manifest['copy_files']['from_dir']) : "";
  542. $manifest_icon = clean_path($manifest['icon']);
  543. $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 ) . "\">";
  544. }
  545. else
  546. {
  547. $icon = getImageForType( $manifest['type'] );
  548. }
  549. $installed_objects[] = array('icon' => $icon, 'name' => $name, 'type' => $type, 'version' => $version, 'date_entered' => $date_entered, 'description' => $description, 'file' => $link);
  550. //print( "<form action=\"" . $form_action . "_prepare\" method=\"post\">\n" );
  551. //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" );
  552. //print( "</form>\n" );
  553. }
  554. }
  555. }
  556. ?>