]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - install/download_modules.php
Release 6.4.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
42 if(!isset( $install_script ) || !$install_script || empty($_SESSION['setup_db_admin_user_name'])){
43     die($mod_strings['ERR_NO_DIRECT_SCRIPT']);
44 }
45 ///////////////////////////////////////////////////////////////////////////////
46 ////    PREFILL $sugar_config VARS
47 if(empty($sugar_config['upload_dir'])) {
48     $sugar_config['upload_dir'] = 'upload/';
49 }
50 if(empty($sugar_config['upload_maxsize'])) {
51     $sugar_config['upload_maxsize'] = 8192000;
52 }
53 if(empty($sugar_config['upload_badext'])) {
54     $sugar_config['upload_badext'] = array('php', 'php3', 'php4', 'php5', 'pl', 'cgi', 'py', 'asp', 'cfm', 'js', 'vbs', 'html', 'htm');
55 }
56 ////    END PREFILL $sugar_config VARS
57 ///////////////////////////////////////////////////////////////////////////////
58 require_once('include/utils/zip_utils.php');
59
60 require_once('include/upload_file.php');
61
62
63
64 $GLOBALS['log'] = LoggerManager::getLogger('SugarCRM');
65
66 ///////////////////////////////////////////////////////////////////////////////
67 ////    PREP VARS FOR LANG PACK
68     $base_upgrade_dir       = sugar_cached("upgrades");
69     $base_tmp_upgrade_dir   = $base_upgrade_dir."/temp";
70 ///////////////////////////////////////////////////////////////////////////////
71
72 ///////////////////////////////////////////////////////////////////////////////
73 ////    HANDLE FILE UPLOAD AND PROCESSING
74 $errors = array();
75 $uploadResult = '';
76 //commitModules();
77 if(isset($_REQUEST['languagePackAction']) && !empty($_REQUEST['languagePackAction'])) {
78     switch($_REQUEST['languagePackAction']) {
79         case 'upload':
80         $perform = false;
81         $tempFile = '';
82         if(isset($_REQUEST['release_id']) && $_REQUEST['release_id'] != ""){
83             require_once('ModuleInstall/PackageManager/PackageManager.php');
84             $pm = new PackageManager();
85             $tempFile = $pm->download($_REQUEST['release_id']);
86             $perform = true;
87             //$base_filename = urldecode($tempFile);
88         }else{
89             $file = new UploadFile('language_pack');
90             if($file->confirm_upload()){
91             $perform = true;
92              if(strpos($file->mime_type, 'zip') !== false) { // only .zip files
93                                         $tempFile = $file->get_stored_filename();
94                                         if($file->final_move($tempFile)) {
95                         $perform = true;
96                     }
97                     else {
98                         $errors[] = $mod_strings['ERR_LANG_UPLOAD_3'];
99                     }
100                 } else {
101                     $errors[] = $mod_strings['ERR_LANG_UPLOAD_2'];
102                 }
103             }
104         }
105
106
107             if($perform) { // check for a real file
108                         $uploadResult = $mod_strings['LBL_LANG_SUCCESS'];
109                         $result = langPackUnpack('langpack', $tempFile);
110             } else {
111                 $errors[] = $mod_strings['ERR_LANG_UPLOAD_1'];
112             }
113
114             if(count($errors) > 0) {
115                 foreach($errors as $error) {
116                     $uploadResult .= $error."<br />";
117                 }
118             }
119             break; // end 'validate'
120         case 'commit':
121             $sugar_config = commitModules(false, 'langpack');
122             break;
123         case 'uninstall': // leaves zip file in "uploaded" state
124             $sugar_config = uninstallLanguagePack();
125             break;
126         case 'remove':
127             removeLanguagePack();
128             break;
129         default:
130             break;
131     }
132 }
133 ////    END HANDLE FILE UPLOAD AND PROCESSING
134 ///////////////////////////////////////////////////////////////////////////////
135
136
137 ///////////////////////////////////////////////////////////////////////////////
138 ////    PRELOAD DISPLAY DATA
139 $upload_max_filesize = ini_get('upload_max_filesize');
140 $upload_max_filesize_bytes = return_bytes($upload_max_filesize);
141 $fileMaxSize ='';
142 if(!defined('SUGARCRM_MIN_UPLOAD_MAX_FILESIZE_BYTES')){
143     define('SUGARCRM_MIN_UPLOAD_MAX_FILESIZE_BYTES', 6 * 1024 * 1024);
144 }
145
146 if($upload_max_filesize_bytes < constant('SUGARCRM_MIN_UPLOAD_MAX_FILESIZE_BYTES')) {
147     $GLOBALS['log']->debug("detected upload_max_filesize: $upload_max_filesize");
148     $fileMaxSize = '<p class="error">'.$mod_strings['ERR_UPLOAD_MAX_FILESIZE']."</p>\n";
149 }
150 $availablePatches = getLangPacks(true);
151 $installedLanguagePacks = getInstalledLangPacks();
152 $errs = '';
153 if(isset($validation_errors)) {
154     if(count($validation_errors) > 0) {
155         $errs  = '<div id="errorMsgs">';
156         $errs .= "<p>{$mod_strings['LBL_SYSOPTS_ERRS_TITLE']}</p>";
157         $errs .= '<ul>';
158
159         foreach($validation_errors as $error) {
160             $errs .= '<li>' . $error . '</li>';
161         }
162
163         $errs .= '</ul>';
164         $errs .= '</div>';
165     }
166 }
167
168
169
170 ////    PRELOAD DISPLAY DATA
171 ///////////////////////////////////////////////////////////////////////////////
172
173
174 ///////////////////////////////////////////////////////////////////////////////
175 ////    BEING PAGE OUTPUT
176 $disabled = "";
177 $result = "";
178 $langHeader = get_language_header();
179 $out =<<<EOQ
180 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
181 <html {$langHeader}>
182 <head>
183    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
184    <meta http-equiv="Content-Script-Type" content="text/javascript">
185    <meta http-equiv="Content-Style-Type" content="text/css">
186    <title>{$mod_strings['LBL_WIZARD_TITLE']} {$mod_strings['LBL_MODULE_TITLE']}</title>
187    <link REL="SHORTCUT ICON" HREF="include/images/sugar_icon.ico">
188    <link rel="stylesheet" href="install/install.css" type="text/css">
189    <script type="text/javascript" src="install/installCommon.js"></script>
190    <link rel="stylesheet" type="text/css" media="all" href="jscalendar/calendar-win2k-cold-1.css?s={$sugar_version}&c={$js_custom_version}">
191    <script>jscal_today = 1161698116000; if(typeof app_strings == "undefined") app_strings = new Array();</script>
192    <script type="text/javascript" src="cache/include/javascript/sugar_grp1.js?s={$sugar_version}&c={$js_custom_version}"></script>
193    <script type="text/javascript" src="cache/include/javascript/sugar_grp1_yui.js?s={$sugar_version}&c={$js_custom_version}"></script>
194    <script type="text/javascript">
195    <!--
196    if ( YAHOO.env.ua )
197         UA = YAHOO.env.ua;
198    -->
199    </script>
200 </head>
201
202 <body onLoad="document.getElementById('button_next2').focus();">
203 {$fileMaxSize}
204   <table cellspacing="0" width="100%" cellpadding="0" border="0" align="center" class="shell">
205       <tr><td colspan="2" id="help"><a href="{$help_url}" target='_blank'>{$mod_strings['LBL_HELP']} </a></td></tr>
206     <tr>
207       <th width="500">
208                 <p>
209                 <img src="{$sugar_md}" alt="SugarCRM" border="0">
210                 </p>{$mod_strings['LBL_MODULE_TITLE']}</th>
211       <th width="200" style="text-align: right;"><a href="http://www.sugarcrm.com" target=
212       "_blank"><IMG src="include/images/sugarcrm_login.png" width="145" height="30" alt="SugarCRM" border="0"></a>
213         </th>
214     </tr>
215
216     <tr>
217         <td colspan="2">
218             <p>{$mod_strings['LBL_LANG_1']}</p>
219             <table width="100%" cellspacing="0" cellpadding="0" border="0" align="center" class="StyleDottedHr">
220                 <tr>
221                     <th colspan="2" align="left">{$mod_strings['LBL_LANG_TITLE']}</th>
222                 </tr>
223                 <tr>
224                     <td colspan="2">
225 EOQ;
226 $form =<<<EOQ1
227                     <form name="the_form" enctype="multipart/form-data"
228                         action="install.php" method="post">
229                         <input type="hidden" name="current_step" value="{$next_step}">
230                         <input type="hidden" name="language" value="{$lang_curr}">
231                         <input type="hidden" name="goto" value="{$mod_strings['LBL_CHECKSYS_RECHECK']}">
232                         <input type="hidden" name="languagePackAction" value="upload">
233                                                 <input type="hidden" name="install_type" value="custom">
234                     <table width="100%" border="0" cellspacing="0" cellpadding="0" class="edit view">
235                         <tr>
236                             <td>
237                                 <table width="450" border="0" cellspacing="0" cellpadding="0">
238                                     <tr>
239                                                                                 <td colspan='2'>
240                                                                                          {$mod_strings['LBL_LANG_UPLOAD']}:<br />
241                                                                                 </td>
242                                                                         </tr>
243                                                                         <tr>
244                                         <td>
245
246                                         <input type="file" name="language_pack" onchange="uploadCheck();" size="40" />
247                                         </td>
248                                         <td valign="bottom">
249                                             <input class='button' id="upload_button" type=button value="{$mod_strings['LBL_LANG_BUTTON_UPLOAD']}"
250                                                 disabled="disabled"
251                                                 onClick="document.the_form.language_pack_escaped.value = escape( document.the_form.language_pack.value );
252                                                          document.the_form.submit();"
253                                             />
254                                             <input type=hidden name="language_pack_escaped" value="" />
255                                         </td>
256                                     </tr>
257                                 </table>
258                             </td>
259                         </tr>
260                         <tr>
261                             <td>
262                                 {$uploadResult}
263                             </td>
264                         </tr>
265                     </table>
266                     </form>
267 <script>
268  function uploadCheck(){
269    var len = escape(document.the_form.language_pack.value).length;
270    if(escape(document.the_form.language_pack.value).substr(len-3,len) !='zip'){
271                 //document.the_form.upgrade_zip.value = '';
272                 //document.getElementById("upgrade_zip").value = '';
273                 alert('Not a zip file');
274                 document.the_form.language_pack.value = '';
275                 //document.getElementById("language_pack").value='';
276                 document.getElementById("upload_button").disabled='disabled';
277    }
278    else{
279         //AJAX call for checking the file size and comparing with php.ini settings.
280         var callback = {
281                  success:function(r) {
282                         document.the_form.upload_button.disabled='';
283                  }
284         }
285     //var file_name = document.getElementById('upgrade_zip').value;
286         var file_name = document.the_form.language_pack.value;
287         postData = 'file_name=' + file_name + 'install&action=UploadLangFileCheck&to_pdf=1';
288         YAHOO.util.Connect.asyncRequest('POST', 'index.php', callback, postData);
289    }
290 }
291 </script>
292 EOQ1;
293 $out1 =<<<EOQ2
294                   </td>
295                 </tr>
296                 <tr>
297                     <td colspan=2>
298                         {$result}
299                     </td>
300                 </tr>
301                 <!--// Available Upgrades //-->
302                 <tr>
303                     <td align="left" colspan="2">
304                         <hr>
305                         <table cellspacing="0" cellpadding="0" border="0" class="stdTable">
306                             {$availablePatches}
307                         </table>
308                     </td>
309                 </tr>
310
311                     <td align="left" colspan="2">
312                         <hr>
313                         <table cellspacing="0" cellpadding="0" border="0" class="stdTable">
314                             {$installedLanguagePacks}
315                         </table>
316                     </td>
317                 </tr>
318                 <tr>
319                     <td align="right" colspan="2">
320                         <hr>
321                         <form name="the_form1" action="install.php" method="post" id="form">
322                         <input type="hidden" name="current_step" value="{$next_step}">
323                         <input type="hidden" name="language" value="{$lang_curr}">
324                         <input type="hidden" name="install_type" value="custom">
325                         <table cellspacing="0" cellpadding="0" border="0" class="stdTable">
326                             <tr>
327
328                                 <td>
329                                    <input type="hidden" name="default_user_name" value="admin">
330                                 </td>
331                                 <td>
332                                     <input class="button" type="submit" name="goto" value="{$mod_strings['LBL_NEXT']}" id="button_next2" {$disabled} />
333                                 </td>
334                             </tr>
335                         </table>
336                         </form>
337                     </td>
338                 </tr>
339             </table>
340         </td>
341     </tr>
342 </table>
343
344 </body>
345 </html>
346 EOQ2;
347 $hidden_fields =  "<input type=\"hidden\" name=\"current_step\" value=\"{$next_step}\">";
348 $hidden_fields .=  "<input type=\"hidden\" name=\"goto\" value=\"{$mod_strings['LBL_CHECKSYS_RECHECK']}\">";
349 $hidden_fields .=  "<input type=\"hidden\" name=\"languagePackAction\" value=\"commit\">";
350 //$form2 = PackageManagerDisplay::buildPackageDisplay($form, $hidden_fields, 'install.php', array('langpack'), 'form1', true);
351 $form2 = PackageManagerDisplay::buildPatchDisplay($form, $hidden_fields, 'install.php', array('langpack'));
352
353 echo $out.$form2.$out1;
354
355 //unlinkTempFiles('','');
356 ////    END PAGEOUTPUT
357 ///////////////////////////////////////////////////////////////////////////////
358 ?>