PageRenderTime 54ms CodeModel.GetById 25ms RepoModel.GetById 0ms app.codeStats 0ms

/ModuleInstall/PackageManager/PackageManagerDisplay.php

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