PageRenderTime 50ms CodeModel.GetById 18ms RepoModel.GetById 1ms app.codeStats 0ms

/ModuleInstall/PackageManager/PackageManagerDisplay.php

https://github.com/mitani/dashlet-subpanels
PHP | 604 lines | 439 code | 48 blank | 117 comment | 57 complexity | fa5c6570d5ce46f0bf9a15b0a72ec4b7 MD5 | raw file
Possible License(s): LGPL-2.1, MPL-2.0-no-copyleft-exception
  1. <?php
  2. /*********************************************************************************
  3. * SugarCRM is a customer relationship management program developed by
  4. * SugarCRM, Inc. Copyright (C) 2004 - 2009 SugarCRM Inc.
  5. *
  6. * This program is free software; you can redistribute it and/or modify it under
  7. * the terms of the GNU 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 General Public License for more
  16. * details.
  17. *
  18. * You should have received a copy of the GNU 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 General Public License version 3.
  29. *
  30. * In accordance with Section 7(b) of the GNU 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('en_us');
  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. $ss->assign('module_load', 'false');
  190. $ss->assign('MODULE_SELECTOR', '');
  191. $ss->assign('FORM_2_PLACE_HOLDER', $form2);
  192. $ss->assign('scripts', PackageManagerDisplay::getDisplayScript(false, 'patch', $releases, $types, $isAlive));
  193. $str = $ss->fetch('ModuleInstall/PackageManager/tpls/PackageForm.tpl');
  194. return $str;
  195. }
  196. function buildInstalledGrid($mod_strings, $types = array('modules')){
  197. $descItemsInstalled = $mod_strings['LBL_UW_DESC_MODULES_INSTALLED'];
  198. $output = '<table width="100%" border="0" cellspacing="0" cellpadding="0" ><tr><td align="left">'.$descItemsInstalled.'</td>';
  199. $output .= '</td></tr></table>';
  200. $output .= "<table width='100%' class='moduleTitle yui-skin-sam' border=1><tr><td ><div id='installed_grid' class='ygrid-mso' style='height:205px;'></div></td></tr></table>";
  201. return $output;
  202. }
  203. function buildLoginPanel($mod_strings, $display_cancel){
  204. $credentials = PackageManager::getCredentials();
  205. $output = "<div id='login_panel'><div class='hd'><b>".$mod_strings['HDR_LOGIN_PANEL']."</b></div>";
  206. $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>";
  207. $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>";
  208. $terms = PackageManager::getTermsAndConditions();
  209. $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>';
  210. $_SESSION['SugarDepot_TermsVersion'] = (!empty($terms['version']) ? $terms['version'] : '');
  211. $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>";
  212. $output .= "<td align='left'>";
  213. $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>";
  214. if($display_cancel){
  215. $output .= "&nbsp;<input type='button' id='panel_cancel_button' value='Cancel' class='button' onClick='PackageManager.showLoginDialog(false);'>";
  216. }
  217. $output .= "</td><td></td></tr>";
  218. $output .= "<tr></td><td></td></tr>";
  219. $output .= "</table></div>";
  220. $output .= "<div class='ft'></div></form></div>";
  221. return $output;
  222. }
  223. /**
  224. * Build html in order to display the grids relevant for module loader
  225. *
  226. * @param Tree tree - the tree which we are using to display the categories
  227. * @param Array mod_strings - the local mod strings to display
  228. * @return String - a string of html
  229. */
  230. function buildGridOutput($tree, $mod_strings, $display = true, $show_login = true){
  231. $output = "<div id='catview'>";
  232. $loginViewStyle = ($display ? 'none' : 'block');
  233. $selectViewStyle = ($display ? 'block' : 'none');
  234. $output .= "<div id='selectView' style='display:".$selectViewStyle."'>";
  235. //if($display){
  236. $output .= "<table border=0 width='100%' class='moduleTitle yui-skin-sam'><tr><td width='100%' valign='top'>";
  237. $output .= "<div id='treeview'>";
  238. $output .= $tree->generate_nodes_array();
  239. $output .= "</div>";
  240. $output .= "</td></tr>";
  241. $output .= "<tr><td width='100%'>";
  242. $output .= "<div id='tabs1'></div>";
  243. $output .= "</td></tr>";
  244. $output .= "<tr><td width='100%' align='left'>";
  245. $output .= "<input type='button' class='button' value='Download Selected' onClick='PackageManager.download();'>";
  246. $output .= "</td></tr></table>";
  247. // }
  248. $output .= "</div>";
  249. if(!$show_login)
  250. $loginViewStyle = 'none';
  251. // $output .= "<div id='loginView' style='display:".$loginViewStyle."'>";
  252. // 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.
  253. //$output .= PackageManagerDisplay::buildLoginPanel($mod_strings, $display);
  254. //$output .= "</div>";
  255. //$output .= "<table width='100%' class='moduleTitle' border=1><tr><td><div id='patch_downloads' class='ygrid-mso' style='height:205px;'></div></td></tr></table>";
  256. $output .= "</div>";
  257. return $output;
  258. }
  259. /**
  260. * A Static method used to build the initial treeview when the page is first displayed
  261. *
  262. * @param String div_id - this div in which to display the tree
  263. * @return Tree - the tree that is built
  264. */
  265. function buildTreeView($div_id, $isAlive = true){
  266. $tree = new Tree($div_id);
  267. $nodes = array();
  268. if($isAlive)
  269. $nodes = PackageManager::getCategories('');
  270. foreach($nodes as $arr_node){
  271. $node = new Node($arr_node['id'], $arr_node['label']);
  272. $node->dynamicloadfunction = 'PackageManager.loadDataForNodeForPackage';
  273. $node->expanded = false;
  274. $node->dynamic_load = true;
  275. $node->set_property('href',"javascript:PackageManager.catClick('treeview');");
  276. $tree->add_node($node);
  277. $node->set_property('description', $arr_node['description']);
  278. }
  279. return $tree;
  280. }
  281. /**
  282. * A Static method used to obtain the div for the license
  283. *
  284. * @param String license_file - the path to the license file
  285. * @param String form_action - the form action when accepting the license file
  286. * @param String next_step - the value for the next step in the installation process
  287. * @param String zipFile - a string representing the path to the zip file
  288. * @param String type - module/patch....
  289. * @param String manifest - the path to the manifest file
  290. * @param String modify_field - the field to update when the radio button is changed
  291. * @return String - a form used to display the license
  292. */
  293. function getLicenseDisplay($license_file, $form_action, $next_step, $zipFile, $type, $manifest, $modify_field){
  294. global $current_language;
  295. $mod_strings = return_module_language($current_language, "Administration");
  296. $fh = sugar_fopen($license_file, 'r');
  297. $contents = fread($fh, filesize($license_file));
  298. fclose($fh);
  299. $div_id = urlencode($zipFile);
  300. $display = "<form name='delete{$zipFile}' action='{$form_action}' method='POST'>";
  301. $display .= "<input type='hidden' name='current_step' value='{$next_step}'>";
  302. $display .= "<input type='hidden' name='languagePackAction' value='{$type}'>";
  303. $display .= "<input type='hidden' name='manifest' value='\".urlencode($manifest).\"'>";
  304. $display .= "<input type='hidden' name='zipFile' value='\".urlencode($zipFile).\"'>";
  305. $display .= "<table><tr>";
  306. $display .= "<td align=\"left\" valign=\"top\" colspan=2>";
  307. $display .= "<b><font color='red' >{$mod_strings['LBL_MODULE_LICENSE']}</font></b>";
  308. $display .= "</td>";
  309. $display .= "<td>";
  310. $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>";
  311. $display .= "</td>";
  312. $display .= "</tr>";
  313. $display .= "</table>";
  314. $display .= "<div id='span_license_div_$div_id' style=\"display: none;\">";
  315. $display .= "<table>";
  316. $display .= "<tr>";
  317. $display .= "<td align=\"left\" valign=\"top\" colspan=2>";
  318. $display .= "<textarea cols=\"100\" rows=\"8\">{$contents}</textarea>";
  319. $display .= "</td>";
  320. $display .= "</tr>";
  321. $display .= "<tr>";
  322. $display .= "<td align=\"left\" valign=\"top\" colspan=2>";
  323. $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;";
  324. $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']}";
  325. $display .= "</td>";
  326. $display .= "</tr>";
  327. $display .= "</table>";
  328. $display .= "</div>";
  329. $display .= "</form>";
  330. return $display;
  331. }
  332. /**
  333. * A Static method used to generate the javascript for the page
  334. *
  335. * @return String - the javascript required for the page
  336. */
  337. function getDisplayScript($install = false, $type = 'module', $releases = null, $types = array(), $isAlive = true){
  338. global $sugar_version, $sugar_config;
  339. global $current_language;
  340. $mod_strings = return_module_language($current_language, "Administration");
  341. $ss = new Sugar_Smarty();
  342. $ss->assign('MOD', $mod_strings);
  343. if(!$install){
  344. $install = 0;
  345. }
  346. $ss->assign('INSTALLATION', $install);
  347. $ss->assign('WAIT_IMAGE', SugarThemeRegistry::current()->getImage("loading","border='0' align='bottom'"));
  348. $ss->assign('sugar_version', $sugar_version);
  349. $ss->assign('js_custom_version', $sugar_config['js_custom_version']);
  350. $ss->assign('IS_ALIVE', $isAlive);
  351. //if($type == 'patch' && $releases != null){
  352. if($type == 'patch'){
  353. $ss->assign('module_load', 'false');
  354. $patches = PackageManagerDisplay::createJavascriptPackageArray($releases);
  355. $ss->assign('PATCHES', $patches);
  356. $ss->assign('GRID_TYPE', implode(',', $types));
  357. }else{
  358. $pm = new PackageManager();
  359. $releases = $pm->getPackagesInStaging();
  360. $patches = PackageManagerDisplay::createJavascriptModuleArray($releases);
  361. $ss->assign('PATCHES', $patches);
  362. $installeds = $pm->getinstalledPackages();
  363. $patches = PackageManagerDisplay::createJavascriptModuleArray($installeds, 'mti_installed_data');
  364. $ss->assign('INSTALLED_MODULES', $patches);
  365. $ss->assign('UPGARDE_WIZARD_URL', 'index.php?module=UpgradeWizard&action=index');
  366. $ss->assign('module_load', 'true');
  367. }
  368. if(!empty($GLOBALS['ML_STATUS_MESSAGE']))
  369. $ss->assign('ML_STATUS_MESSAGE',$GLOBALS['ML_STATUS_MESSAGE']);
  370. //Bug 24064. Checking and Defining labels since these might not be cached during Upgrade
  371. if(!isset($mod_strings['LBL_ML_INSTALL']) || empty($mod_strings['LBL_ML_INSTALL'])){
  372. $mod_strings['LBL_ML_INSTALL'] = 'Install';
  373. }
  374. if(!isset($mod_strings['LBL_ML_ENABLE_OR_DISABLE']) || empty($mod_strings['LBL_ML_ENABLE_OR_DISABLE'])) {
  375. $mod_strings['LBL_ML_ENABLE_OR_DISABLE'] = 'Enable/Disable';
  376. }
  377. if(!isset($mod_strings['LBL_ML_DELETE'])|| empty($mod_strings['LBL_ML_DELETE'])){
  378. $mod_strings['LBL_ML_DELETE'] = 'Delete';
  379. }
  380. //Add by jchi 6/23/2008 to fix the bug 21667
  381. $filegrid_column_ary = array(
  382. 'Name' => $mod_strings['LBL_ML_NAME'],
  383. 'Install' => $mod_strings['LBL_ML_INSTALL'],
  384. 'Delete' => $mod_strings['LBL_ML_DELETE'],
  385. 'Type' => $mod_strings['LBL_ML_TYPE'],
  386. 'Version' => $mod_strings['LBL_ML_VERSION'],
  387. 'Published' => $mod_strings['LBL_ML_PUBLISHED'],
  388. 'Uninstallable' => $mod_strings['LBL_ML_UNINSTALLABLE'],
  389. 'Description' => $mod_strings['LBL_ML_DESCRIPTION']
  390. );
  391. $filegridinstalled_column_ary = array(
  392. 'Name' => $mod_strings['LBL_ML_NAME'],
  393. 'Install' => $mod_strings['LBL_ML_INSTALL'],
  394. 'Action' => $mod_strings['LBL_ML_ACTION'],
  395. 'Enable_Or_Disable' => $mod_strings['LBL_ML_ENABLE_OR_DISABLE'],
  396. 'Type' => $mod_strings['LBL_ML_TYPE'],
  397. 'Version' => $mod_strings['LBL_ML_VERSION'],
  398. 'Date_Installed' => $mod_strings['LBL_ML_INSTALLED'],
  399. 'Uninstallable' => $mod_strings['LBL_ML_UNINSTALLABLE'],
  400. 'Description' => $mod_strings['LBL_ML_DESCRIPTION']
  401. );
  402. $ss->assign('ML_FILEGRID_COLUMN',$filegrid_column_ary);
  403. $ss->assign('ML_FILEGRIDINSTALLED_COLUMN',$filegridinstalled_column_ary);
  404. //end
  405. $str = $ss->fetch('ModuleInstall/PackageManager/tpls/PackageManagerScripts.tpl');
  406. return $str;
  407. }
  408. function createJavascriptPackageArray($releases){
  409. $output = "var mti_data = [";
  410. $count = count($releases);
  411. $index = 1;
  412. if(!empty($releases['packages'])){
  413. foreach($releases['packages'] as $release){
  414. $release = PackageManager::fromNameValueList($release);
  415. $output .= "[";
  416. $output .= "'".$release['description']."', '".$release['version']."', '".$release['build_number']."', '".$release['id']."'";
  417. $output .= "]";
  418. if($index < $count)
  419. $output .= ",";
  420. $index++;
  421. }
  422. }
  423. $output .= "]\n;";
  424. return $output;
  425. }
  426. function createJavascriptModuleArray($modules, $variable_name = 'mti_data'){
  427. $output = "var ".$variable_name." = [";
  428. $count = count($modules);
  429. $index = 1;
  430. if(!empty($modules)){
  431. foreach($modules as $module){
  432. $output .= "[";
  433. $output .= "'".$module['name']."', '".$module['file_install']."', '".$module['file']."', '";
  434. if(!empty($module['enabled']))
  435. $output .= $module['enabled'].'_'.$module['file']."', '";
  436. $description = js_escape($module['description']);
  437. $output .= $module['type']."', '".$module['version']."', '".$module['published_date']."', '".$module['uninstallable']."', '".$description."']";
  438. if($index < $count)
  439. $output .= ",";
  440. $index++;
  441. }
  442. }
  443. $output .= "]\n;";
  444. return $output;
  445. }
  446. /**
  447. * This method is meant to be used to display the license agreement inline on the page
  448. * if the system would like to perform the installation on the same page via an Ajax call
  449. */
  450. function buildLicenseOutput($file){
  451. global $current_language;
  452. $mod_strings = return_module_language($current_language, "Administration");
  453. $contents = '';
  454. $pm = new PackageManager();
  455. $contents = $pm->getLicenseFromFile($file);
  456. $ss = new Sugar_Smarty();
  457. $ss->assign('MOD', $mod_strings);
  458. $ss->assign('LICENSE_CONTENTS', $contents);
  459. $ss->assign('FILE', $file);
  460. $str = $ss->fetch('ModuleInstall/PackageManagerLicense.tpl');
  461. $GLOBALS['log']->debug('LICENSE OUTPUT: '.$str);
  462. return $str;
  463. }
  464. function getHeader(){
  465. global $current_language;
  466. $mod_strings = return_module_language($current_language, "Administration");
  467. $header_text = '';
  468. $isAlive = false;
  469. $show_login = false;
  470. if(!function_exists('curl_init') && $show_login){
  471. $header_text = "<font color='red'><b>".$mod_strings['ERR_ENABLE_CURL']."</b></font>";
  472. $show_login = false;
  473. }else{
  474. $credentials = PackageManager::getCredentials();
  475. if(empty($credentials['username']) || empty($credentials['password'])){
  476. //$header_text = "<font color='red'><b>".$mod_strings['ERR_CREDENTIALS_MISSING']."</b></font>";
  477. }
  478. else{
  479. $result = PackageManagerComm::login();
  480. if((is_array($result) && !empty($result['faultcode'])) || $result == false){
  481. $header_text = "<font color='red'><b>".$result['faultstring']."</b></font>";
  482. }else{
  483. $header_text = PackageManager::getPromotion();
  484. $isAlive = true;
  485. }
  486. }
  487. }
  488. return array('text' => $header_text, 'isAlive' => $isAlive, 'show_login' => $show_login);
  489. }
  490. function buildInstallGrid($view){
  491. $uh = new UpgradeHistory();
  492. $installeds = $uh->getAll();
  493. $upgrades_installed = 0;
  494. $installed_objects = array();
  495. foreach($installeds as $installed)
  496. {
  497. $filename = from_html($installed->filename);
  498. $date_entered = $installed->date_entered;
  499. $type = $installed->type;
  500. $version = $installed->version;
  501. $upgrades_installed++;
  502. $link = "";
  503. switch($type)
  504. {
  505. case "theme":
  506. case "langpack":
  507. case "module":
  508. case "patch":
  509. $manifest_file = extractManifest($filename);
  510. require_once($manifest_file);
  511. $name = empty($manifest['name']) ? $filename : $manifest['name'];
  512. $description = empty($manifest['description']) ? $mod_strings['LBL_UW_NONE'] : $manifest['description'];
  513. if(($upgrades_installed==0 || $uh->UninstallAvailable($installeds, $installed))
  514. && is_file($filename) && !empty($manifest['is_uninstallable']))
  515. {
  516. $link = urlencode( $filename );
  517. }
  518. else
  519. {
  520. $link = 'false';
  521. }
  522. break;
  523. default:
  524. break;
  525. }
  526. if($view == 'default' && $type != 'patch')
  527. {
  528. continue;
  529. }
  530. if($view == 'module'
  531. && $type != 'module' && $type != 'theme' && $type != 'langpack')
  532. {
  533. continue;
  534. }
  535. $target_manifest = remove_file_extension( $filename ) . "-manifest.php";
  536. require_once( "$target_manifest" );
  537. if(isset($manifest['icon']) && $manifest['icon'] != "")
  538. {
  539. $manifest_copy_files_to_dir = isset($manifest['copy_files']['to_dir']) ? clean_path($manifest['copy_files']['to_dir']) : "";
  540. $manifest_copy_files_from_dir = isset($manifest['copy_files']['from_dir']) ? clean_path($manifest['copy_files']['from_dir']) : "";
  541. $manifest_icon = clean_path($manifest['icon']);
  542. $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 ) . "\">";
  543. }
  544. else
  545. {
  546. $icon = getImageForType( $manifest['type'] );
  547. }
  548. $installed_objects[] = array('icon' => $icon, 'name' => $name, 'type' => $type, 'version' => $version, 'date_entered' => $date_entered, 'description' => $description, 'file' => $link);
  549. //print( "<form action=\"" . $form_action . "_prepare\" method=\"post\">\n" );
  550. //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" );
  551. //print( "</form>\n" );
  552. }
  553. }
  554. }
  555. ?>