PageRenderTime 42ms CodeModel.GetById 2ms app.highlight 31ms RepoModel.GetById 1ms app.codeStats 1ms

/ModuleInstall/PackageManager/PackageManagerDisplay.php

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