PageRenderTime 66ms CodeModel.GetById 2ms app.highlight 56ms RepoModel.GetById 1ms app.codeStats 0ms

/ModuleInstall/PackageManager/PackageManagerDisplay.php

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