PageRenderTime 74ms CodeModel.GetById 15ms app.highlight 52ms RepoModel.GetById 1ms app.codeStats 0ms

/ModuleInstall/PackageManager/PackageManagerDisplay.php

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