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