PageRenderTime 44ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/ModuleInstall/PackageManager/PackageManagerDisplay.php

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