]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - install/download_modules.php
Release 6.2.0
[Github/sugarcrm.git] / install / download_modules.php
1 <?php
2 if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
3 /*********************************************************************************
4  * SugarCRM Community Edition is a customer relationship management program developed by
5  * SugarCRM, Inc. Copyright (C) 2004-2011 SugarCRM Inc.
6  * 
7  * This program is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU Affero General Public License version 3 as published by the
9  * Free Software Foundation with the addition of the following permission added
10  * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
11  * IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
12  * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
13  * 
14  * This program is distributed in the hope that it will be useful, but WITHOUT
15  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16  * FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public License for more
17  * details.
18  * 
19  * You should have received a copy of the GNU Affero General Public License along with
20  * this program; if not, see http://www.gnu.org/licenses or write to the Free
21  * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
22  * 02110-1301 USA.
23  * 
24  * You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
25  * SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
26  * 
27  * The interactive user interfaces in modified source and object code versions
28  * of this program must display Appropriate Legal Notices, as required under
29  * Section 5 of the GNU Affero General Public License version 3.
30  * 
31  * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
32  * these Appropriate Legal Notices must retain the display of the "Powered by
33  * SugarCRM" logo. If the display of the logo is not reasonably feasible for
34  * technical reasons, the Appropriate Legal Notices must display the words
35  * "Powered by SugarCRM".
36  ********************************************************************************/
37
38 global $sugar_version, $js_custom_version;
39 $lang_curr = $_SESSION['language'];
40 require_once('ModuleInstall/PackageManager/PackageManagerDisplay.php');
41 if( !isset( $install_script ) || !$install_script ){
42     die($mod_strings['ERR_NO_DIRECT_SCRIPT']);
43 }
44 ///////////////////////////////////////////////////////////////////////////////
45 ////    PREFILL $sugar_config VARS
46 if(empty($sugar_config['upload_dir'])) {
47     $sugar_config['upload_dir'] = 'cache/upload/';
48 }
49 if(empty($sugar_config['upload_maxsize'])) {
50     $sugar_config['upload_maxsize'] = 8192000;
51 }
52 if(empty($sugar_config['upload_badext'])) {
53     $sugar_config['upload_badext'] = array('php', 'php3', 'php4', 'php5', 'pl', 'cgi', 'py', 'asp', 'cfm', 'js', 'vbs', 'html', 'htm');
54 }
55 ////    END PREFILL $sugar_config VARS
56 ///////////////////////////////////////////////////////////////////////////////
57 require_once('include/utils/zip_utils.php');
58
59 require_once('include/upload_file.php');
60
61
62
63 $GLOBALS['log'] = LoggerManager::getLogger('SugarCRM');
64
65 ///////////////////////////////////////////////////////////////////////////////
66 ////    PREP VARS FOR LANG PACK
67     $base_upgrade_dir       = $sugar_config['upload_dir'] . "upgrades";
68     $base_tmp_upgrade_dir   = $base_upgrade_dir."/temp";
69 ///////////////////////////////////////////////////////////////////////////////
70
71 ///////////////////////////////////////////////////////////////////////////////
72 ////    HANDLE FILE UPLOAD AND PROCESSING
73 $errors = array();
74 $uploadResult = '';
75 //commitModules();
76 if(isset($_REQUEST['languagePackAction']) && !empty($_REQUEST['languagePackAction'])) {
77     switch($_REQUEST['languagePackAction']) {
78         case 'upload':
79         $perform = false;
80         $tempFile = '';
81         if(isset($_REQUEST['release_id']) && $_REQUEST['release_id'] != ""){
82             require_once('ModuleInstall/PackageManager/PackageManager.php');
83             $pm = new PackageManager();
84             $tempFile = $pm->download($_REQUEST['release_id'], getcwd().'/'.$sugar_config['upload_dir']);
85             $perform = true;
86             //$base_filename = urldecode($tempFile);
87         }else{
88             $file = new UploadFile('language_pack');
89             if($file->confirm_upload()){
90             $perform = true;
91              if(strpos($file->mime_type, 'zip') !== false) { // only .zip files
92                     if(langPackFinalMove($file)) {
93                         $perform = true;
94                     }
95                     else {
96                         $errors[] = $mod_strings['ERR_LANG_UPLOAD_3'];
97                     }
98                 } else {
99                     $errors[] = $mod_strings['ERR_LANG_UPLOAD_2'];
100                 }
101             }
102         }
103
104
105             if($perform) { // check for a real file
106                         $uploadResult = $mod_strings['LBL_LANG_SUCCESS'];
107                         $result = langPackUnpack('langpack', $tempFile);
108             } else {
109                 $errors[] = $mod_strings['ERR_LANG_UPLOAD_1'];
110             }
111
112             if(count($errors) > 0) {
113                 foreach($errors as $error) {
114                     $uploadResult .= $error."<br />";
115                 }
116             }
117             break; // end 'validate'
118         case 'commit':
119             $sugar_config = commitModules(false, 'langpack');
120             break;
121         case 'uninstall': // leaves zip file in "uploaded" state
122             $sugar_config = uninstallLanguagePack();
123             break;
124         case 'remove':
125             removeLanguagePack();
126             break;
127         default:
128             break;
129     }
130 }
131 ////    END HANDLE FILE UPLOAD AND PROCESSING
132 ///////////////////////////////////////////////////////////////////////////////
133
134
135 ///////////////////////////////////////////////////////////////////////////////
136 ////    PRELOAD DISPLAY DATA
137 $upload_max_filesize = ini_get('upload_max_filesize');
138 $upload_max_filesize_bytes = return_bytes($upload_max_filesize);
139 $fileMaxSize ='';
140 if(!defined('SUGARCRM_MIN_UPLOAD_MAX_FILESIZE_BYTES')){
141     define('SUGARCRM_MIN_UPLOAD_MAX_FILESIZE_BYTES', 6 * 1024 * 1024);
142 }
143
144 if($upload_max_filesize_bytes < constant('SUGARCRM_MIN_UPLOAD_MAX_FILESIZE_BYTES')) {
145     $GLOBALS['log']->debug("detected upload_max_filesize: $upload_max_filesize");
146     $fileMaxSize = '<p class="error">'.$mod_strings['ERR_UPLOAD_MAX_FILESIZE']."</p>\n";
147 }
148 $availablePatches = getLangPacks(true);
149 $installedLanguagePacks = getInstalledLangPacks();
150 $errs = '';
151 if(isset($validation_errors)) {
152     if(count($validation_errors) > 0) {
153         $errs  = '<div id="errorMsgs">';
154         $errs .= "<p>{$mod_strings['LBL_SYSOPTS_ERRS_TITLE']}</p>";
155         $errs .= '<ul>';
156
157         foreach($validation_errors as $error) {
158             $errs .= '<li>' . $error . '</li>';
159         }
160
161         $errs .= '</ul>';
162         $errs .= '</div>';
163     }
164 }
165
166
167
168 ////    PRELOAD DISPLAY DATA
169 ///////////////////////////////////////////////////////////////////////////////
170
171
172 ///////////////////////////////////////////////////////////////////////////////
173 ////    BEING PAGE OUTPUT
174 $disabled = "";
175 $result = "";
176 $out =<<<EOQ
177 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
178 <html>
179 <head>
180    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
181    <meta http-equiv="Content-Script-Type" content="text/javascript">
182    <meta http-equiv="Content-Style-Type" content="text/css">
183    <title>{$mod_strings['LBL_WIZARD_TITLE']} {$mod_strings['LBL_MODULE_TITLE']}</title>
184    <link REL="SHORTCUT ICON" HREF="include/images/sugar_icon.ico">
185    <link rel="stylesheet" href="install/install.css" type="text/css">
186    <script type="text/javascript" src="install/installCommon.js"></script>
187    <link rel="stylesheet" type="text/css" media="all" href="jscalendar/calendar-win2k-cold-1.css?s={$sugar_version}&c={$js_custom_version}">
188    <script>jscal_today = 1161698116000; if(typeof app_strings == "undefined") app_strings = new Array();</script>
189    <script type="text/javascript" src="include/javascript/sugar_grp1.js?s={$sugar_version}&c={$js_custom_version}"></script>
190    <script type="text/javascript" src="include/javascript/sugar_grp1_yui.js?s={$sugar_version}&c={$js_custom_version}"></script>
191    <script type="text/javascript">
192    <!--
193    if ( YAHOO.env.ua )
194         UA = YAHOO.env.ua;
195    -->
196    </script>
197 </head>
198
199 <body onLoad="document.getElementById('defaultFocus').focus();">
200 {$fileMaxSize}
201   <table cellspacing="0" width="100%" cellpadding="0" border="0" align="center" class="shell">
202       <tr><td colspan="2" id="help"><a href="{$help_url}" target='_blank'>{$mod_strings['LBL_HELP']} </a></td></tr>
203     <tr>
204       <th width="500">
205                 <p>
206                 <img src="{$sugar_md}" alt="SugarCRM" border="0">
207                 </p>{$mod_strings['LBL_MODULE_TITLE']}</th>
208       <th width="200" style="text-align: right;"><a href="http://www.sugarcrm.com" target=
209       "_blank"><IMG src="include/images/sugarcrm_login.png" width="145" height="30" alt="SugarCRM" border="0"></a>
210         </th>
211     </tr>
212
213     <tr>
214         <td colspan="2">
215             <p>{$mod_strings['LBL_LANG_1']}</p>
216             <table width="100%" cellspacing="0" cellpadding="0" border="0" align="center" class="StyleDottedHr">
217                 <tr>
218                     <th colspan="2" align="left">{$mod_strings['LBL_LANG_TITLE']}</th>
219                 </tr>
220                 <tr>
221                     <td colspan="2">
222 EOQ;
223 $form =<<<EOQ1
224                     <form name="the_form" enctype="multipart/form-data"
225                         action="install.php" method="post">
226                         <input type="hidden" name="current_step" value="{$next_step}">
227                         <input type="hidden" name="language" value="{$lang_curr}">
228                         <input type="hidden" name="goto" value="{$mod_strings['LBL_CHECKSYS_RECHECK']}">
229                         <input type="hidden" name="languagePackAction" value="upload">
230                                                 <input type="hidden" name="install_type" value="custom">
231                     <table width="100%" border="0" cellspacing="0" cellpadding="0" class="edit view">
232                         <tr>
233                             <td>
234                                 <table width="450" border="0" cellspacing="0" cellpadding="0">
235                                     <tr>
236                                                                                 <td colspan='2'>
237                                                                                          {$mod_strings['LBL_LANG_UPLOAD']}:<br />
238                                                                                 </td>
239                                                                         </tr>
240                                                                         <tr>
241                                         <td>
242
243                                         <input type="file" name="language_pack" onchange="uploadCheck();" size="40" />
244                                         </td>
245                                         <td valign="bottom">
246                                             <input class='button' id="upload_button" type=button value="{$mod_strings['LBL_LANG_BUTTON_UPLOAD']}"
247                                                 disabled="disabled"
248                                                 onClick="document.the_form.language_pack_escaped.value = escape( document.the_form.language_pack.value );
249                                                          document.the_form.submit();"
250                                             />
251                                             <input type=hidden name="language_pack_escaped" value="" />
252                                         </td>
253                                     </tr>
254                                 </table>
255                             </td>
256                         </tr>
257                         <tr>
258                             <td>
259                                 {$uploadResult}
260                             </td>
261                         </tr>
262                     </table>
263                     </form>
264 <script type="text/javascript" language="Javascript" src="include/JSON.js"></script>
265 <script>
266  function uploadCheck(){
267    var len = escape(document.the_form.language_pack.value).length;
268    if(escape(document.the_form.language_pack.value).substr(len-3,len) !='zip'){
269                 //document.the_form.upgrade_zip.value = '';
270                 //document.getElementById("upgrade_zip").value = '';
271                 alert('Not a zip file');
272                 document.the_form.language_pack.value = '';
273                 //document.getElementById("language_pack").value='';
274                 document.getElementById("upload_button").disabled='disabled';
275    }
276    else{
277         //AJAX call for checking the file size and comparing with php.ini settings.
278         var callback = {
279                  success:function(r) {
280                         document.the_form.upload_button.disabled='';
281                  }
282         }
283     //var file_name = document.getElementById('upgrade_zip').value;
284         var file_name = document.the_form.language_pack.value;
285         postData = 'file_name=' + file_name + 'install&action=UploadLangFileCheck&to_pdf=1';
286         YAHOO.util.Connect.asyncRequest('POST', 'index.php', callback, postData);
287    }
288 }
289 </script>
290 EOQ1;
291 $out1 =<<<EOQ2
292                   </td>
293                 </tr>
294                 <tr>
295                     <td colspan=2>
296                         {$result}
297                     </td>
298                 </tr>
299                 <!--// Available Upgrades //-->
300                 <tr>
301                     <td align="left" colspan="2">
302                         <hr>
303                         <table cellspacing="0" cellpadding="0" border="0" class="stdTable">
304                             {$availablePatches}
305                         </table>
306                     </td>
307                 </tr>
308
309                     <td align="left" colspan="2">
310                         <hr>
311                         <table cellspacing="0" cellpadding="0" border="0" class="stdTable">
312                             {$installedLanguagePacks}
313                         </table>
314                     </td>
315                 </tr>
316                 <tr>
317                     <td align="right" colspan="2">
318                         <hr>
319                         <form name="the_form1" action="install.php" method="post" id="form">
320                         <input type="hidden" name="current_step" value="{$next_step}">
321                         <input type="hidden" name="language" value="{$lang_curr}">
322                         <input type="hidden" name="install_type" value="custom">
323                         <table cellspacing="0" cellpadding="0" border="0" class="stdTable">
324                             <tr>
325
326                                 <td>
327                                    <input type="hidden" name="default_user_name" value="admin">
328                                 </td>
329                                 <td>
330                                     <input class="button" type="submit" name="goto" value="{$mod_strings['LBL_NEXT']}" id="defaultFocus" {$disabled} />
331                                 </td>
332                             </tr>
333                         </table>
334                         </form>
335                     </td>
336                 </tr>
337             </table>
338         </td>
339     </tr>
340 </table>
341
342 </body>
343 </html>
344 EOQ2;
345 $hidden_fields =  "<input type=\"hidden\" name=\"current_step\" value=\"{$next_step}\">";
346 $hidden_fields .=  "<input type=\"hidden\" name=\"goto\" value=\"{$mod_strings['LBL_CHECKSYS_RECHECK']}\">";
347 $hidden_fields .=  "<input type=\"hidden\" name=\"languagePackAction\" value=\"commit\">";
348 //$form2 = PackageManagerDisplay::buildPackageDisplay($form, $hidden_fields, 'install.php', array('langpack'), 'form1', true);
349 $form2 = PackageManagerDisplay::buildPatchDisplay($form, $hidden_fields, 'install.php', array('langpack'));
350
351 echo $out.$form2.$out1;
352
353 //unlinkTempFiles('','');
354 ////    END PAGEOUTPUT
355 ///////////////////////////////////////////////////////////////////////////////
356 ?>