2 if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
3 /*********************************************************************************
4 * SugarCRM is a customer relationship management program developed by
5 * SugarCRM, Inc. Copyright (C) 2004-2011 SugarCRM Inc.
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.
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
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
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.
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.
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 ********************************************************************************/
38 /*********************************************************************************
40 * $Description: TODO: To be written. Portions created by SugarCRM are Copyright
41 * (C) SugarCRM, Inc. All Rights Reserved. Contributor(s):
42 * ______________________________________..
43 * *******************************************************************************/
45 require_once('include/utils/zip_utils.php');
47 require_once('include/upload_file.php');
51 ///////////////////////////////////////////////////////////////////////////////
54 * returns lowercase lang encoding
55 * @return string encoding or blank on false
57 function parseAcceptLanguage() {
58 $lang = $_SERVER['HTTP_ACCEPT_LANGUAGE'];
59 if(strpos($lang, ';')) {
60 $exLang = explode(';', $lang);
61 return strtolower(str_replace('-','_',$exLang[0]));
64 if(preg_match("#\w{2}\-?\_?\w{2}#", $lang, $match)) {
65 return strtolower(str_replace('-','_',$match[0]));
72 ///////////////////////////////////////////////////////////////////////////////
73 //// FROM localization.php
75 * copies the temporary unzip'd files to their final destination
76 * removes unzip'd files from system if $uninstall=true
77 * @param bool uninstall true if uninstalling a language pack
78 * @return array sugar_config
80 function commitLanguagePack($uninstall=false) {
83 global $base_upgrade_dir;
84 global $base_tmp_upgrade_dir;
87 $manifest = urldecode($_REQUEST['manifest']);
88 $zipFile = urldecode($_REQUEST['zipFile']);
91 $unzip_dir = mk_temp_dir( $base_tmp_upgrade_dir );
94 $zip_force_copy = array();
96 if($uninstall == false && isset($_SESSION['INSTALLED_LANG_PACKS']) && in_array($zipFile, $_SESSION['INSTALLED_LANG_PACKS'])) {
100 // unzip lang pack to temp dir
101 if(isset($zipFile) && !empty($zipFile)) {
102 if(is_file($zipFile)) {
103 unzip( $zipFile, $unzip_dir );
105 echo $mod_strings['ERR_LANG_MISSING_FILE'].$zipFile;
106 die(); // no point going any further
110 // filter for special to/from dir conditions (langpacks generally don't have them)
111 if(isset($manifest) && !empty($manifest)) {
112 if(is_file($manifest)) {
114 if( isset( $manifest['copy_files']['from_dir'] ) && $manifest['copy_files']['from_dir'] != "" ){
115 $zip_from_dir = $manifest['copy_files']['from_dir'];
117 if( isset( $manifest['copy_files']['to_dir'] ) && $manifest['copy_files']['to_dir'] != "" ){
118 $zip_to_dir = $manifest['copy_files']['to_dir'];
120 if( isset( $manifest['copy_files']['force_copy'] ) && $manifest['copy_files']['force_copy'] != "" ){
121 $zip_force_copy = $manifest['copy_files']['force_copy'];
123 if( isset( $manifest['version'] ) ){
124 $version = $manifest['version'];
127 $errors[] = $mod_strings['ERR_LANG_MISSING_FILE'].$manifest;
132 // find name of language pack: find single file in include/language/xx_xx.lang.php
133 $d = dir( "$unzip_dir/$zip_from_dir/include/language" );
134 while( $f = $d->read() ){
135 if( $f == "." || $f == ".." ){
138 else if( preg_match("/(.*)\.lang\.php\$/", $f, $match) ){
139 $new_lang_name = $match[1];
142 if( $new_lang_name == "" ){
143 die( $mod_strings['ERR_LANG_NO_LANG_FILE'].$zipFile );
145 $new_lang_desc = getLanguagePackName( "$unzip_dir/$zip_from_dir/include/language/$new_lang_name.lang.php" );
146 if( $new_lang_desc == "" ){
147 die( "No language pack description found at include/language/$new_lang_name.lang.php inside $install_file." );
149 // add language to available languages
150 $sugar_config['languages'][$new_lang_name] = ($new_lang_desc);
152 // get an array of all files to be moved
153 $filesFrom = array();
154 $filesFrom = findAllFiles($unzip_dir, $filesFrom);
158 ///////////////////////////////////////////////////////////////////////////
161 // unlink all pack files
162 foreach($filesFrom as $fileFrom) {
163 //echo "deleting: ".getcwd().substr($fileFrom, strlen($unzip_dir), strlen($fileFrom))."<br>";
164 @unlink(getcwd().substr($fileFrom, strlen($unzip_dir), strlen($fileFrom)));
167 // remove session entry
168 if(isset($_SESSION['INSTALLED_LANG_PACKS']) && is_array($_SESSION['INSTALLED_LANG_PACKS'])) {
169 foreach($_SESSION['INSTALLED_LANG_PACKS'] as $k => $langPack) {
170 if($langPack == $zipFile) {
171 unset($_SESSION['INSTALLED_LANG_PACKS'][$k]);
172 unset($_SESSION['INSTALLED_LANG_PACKS_VERSION'][$k]);
173 unset($_SESSION['INSTALLED_LANG_PACKS_MANIFEST'][$k]);
178 // remove language from config
179 $new_langs = array();
180 $old_langs = $sugar_config['languages'];
181 foreach( $old_langs as $key => $value ){
182 if( $key != $removedLang ){
183 $new_langs += array( $key => $value );
186 $sugar_config['languages'] = $new_langs;
189 // copy filesFrom to filesTo
190 foreach($filesFrom as $fileFrom) {
191 @copy($fileFrom, getcwd().substr($fileFrom, strlen($unzip_dir), strlen($fileFrom)));
194 $_SESSION['INSTALLED_LANG_PACKS'][$new_lang_name] = $zipFile;
195 $_SESSION['INSTALLED_LANG_PACKS_VERSION'][$new_lang_name] = $version;
196 $serial_manifest = array();
197 $serial_manifest['manifest'] = (isset($manifest) ? $manifest : '');
198 $serial_manifest['installdefs'] = (isset($installdefs) ? $installdefs : '');
199 $serial_manifest['upgrade_manifest'] = (isset($upgrade_manifest) ? $upgrade_manifest : '');
200 $_SESSION['INSTALLED_LANG_PACKS_MANIFEST'][$new_lang_name] = base64_encode(serialize($serial_manifest));
203 writeSugarConfig($sugar_config);
205 return $sugar_config;
208 function commitPatch($unlink = false, $type = 'patch'){
209 require_once('ModuleInstall/ModuleInstaller.php');
210 require_once('include/entryPoint.php');
214 global $base_upgrade_dir;
215 global $base_tmp_upgrade_dir;
217 $GLOBALS['db'] = $db;
220 global $current_user;
221 $current_user = new User();
222 $current_user->is_admin = '1';
223 $old_mod_strings = $mod_strings;
224 if(is_dir(getcwd()."/cache/upload/upgrades")) {
225 $files = findAllFiles(getcwd()."/cache/upload/upgrades/$type", $files);
226 $mi = new ModuleInstaller();
228 $mod_strings = return_module_language('en', "Administration");
230 foreach($files as $file) {
231 if(!preg_match("#.*\.zip\$#", $file)) {
234 // handle manifest.php
235 $target_manifest = remove_file_extension( $file ) . '-manifest.php';
237 include($target_manifest);
239 $unzip_dir = mk_temp_dir( $base_tmp_upgrade_dir );
240 unzip($file, $unzip_dir );
241 if(file_exists("$unzip_dir/scripts/pre_install.php")){
242 require_once("$unzip_dir/scripts/pre_install.php");
245 if( isset( $manifest['copy_files']['from_dir'] ) && $manifest['copy_files']['from_dir'] != "" ){
246 $zip_from_dir = $manifest['copy_files']['from_dir'];
248 $source = "$unzip_dir/$zip_from_dir";
250 copy_recursive($source, $dest);
252 if(file_exists("$unzip_dir/scripts/post_install.php")){
253 require_once("$unzip_dir/scripts/post_install.php");
256 $new_upgrade = new UpgradeHistory();
257 $new_upgrade->filename = $file;
258 $new_upgrade->md5sum = md5_file($file);
259 $new_upgrade->type = $manifest['type'];
260 $new_upgrade->version = $manifest['version'];
261 $new_upgrade->status = "installed";
262 //$new_upgrade->author = $manifest['author'];
263 $new_upgrade->name = $manifest['name'];
264 $new_upgrade->description = $manifest['description'];
265 $serial_manifest = array();
266 $serial_manifest['manifest'] = (isset($manifest) ? $manifest : '');
267 $serial_manifest['installdefs'] = (isset($installdefs) ? $installdefs : '');
268 $serial_manifest['upgrade_manifest'] = (isset($upgrade_manifest) ? $upgrade_manifest : '');
269 $new_upgrade->manifest = base64_encode(serialize($serial_manifest));
270 $new_upgrade->save();
274 $mod_strings = $old_mod_strings;
277 function commitModules($unlink = false, $type = 'module'){
278 require_once('ModuleInstall/ModuleInstaller.php');
279 require_once('include/entryPoint.php');
283 global $base_upgrade_dir;
284 global $base_tmp_upgrade_dir;
286 $GLOBALS['db'] = $db;
289 global $current_user;
290 $current_user = new User();
291 $current_user->is_admin = '1';
292 $old_mod_strings = $mod_strings;
293 if(is_dir(getcwd()."/cache/upload/upgrades")) {
294 $files = findAllFiles(getcwd()."/cache/upload/upgrades/$type", $files);
295 $mi = new ModuleInstaller();
297 $mod_strings = return_module_language('en', "Administration");
299 foreach($files as $file) {
300 if(!preg_match("#.*\.zip\$#", $file)) {
303 $lic_name = 'accept_lic_'.str_replace('.', '_', urlencode(basename($file)));
306 if(isset($_REQUEST[$lic_name])){
307 if($_REQUEST[$lic_name] == 'yes'){
310 $can_install = false;
314 // handle manifest.php
315 $target_manifest = remove_file_extension( $file ) . '-manifest.php';
316 if($type == 'langpack'){
317 $_REQUEST['manifest'] = $target_manifest;
318 $_REQUEST['zipFile'] = $file;
319 commitLanguagePack();
322 include($target_manifest);
324 $unzip_dir = mk_temp_dir( $base_tmp_upgrade_dir );
325 unzip($file, $unzip_dir );
326 $_REQUEST['install_file'] = $file;
327 $mi->install($unzip_dir);
328 $new_upgrade = new UpgradeHistory();
329 $new_upgrade->filename = $file;
330 $new_upgrade->md5sum = md5_file($file);
331 $new_upgrade->type = $manifest['type'];
332 $new_upgrade->version = $manifest['version'];
333 $new_upgrade->status = "installed";
334 // $new_upgrade->author = $manifest['author'];
335 $new_upgrade->name = $manifest['name'];
336 $new_upgrade->description = $manifest['description'];
337 $new_upgrade->id_name = (isset($installdefs['id_name'])) ? $installdefs['id_name'] : '';
338 $serial_manifest = array();
339 $serial_manifest['manifest'] = (isset($manifest) ? $manifest : '');
340 $serial_manifest['installdefs'] = (isset($installdefs) ? $installdefs : '');
341 $serial_manifest['upgrade_manifest'] = (isset($upgrade_manifest) ? $upgrade_manifest : '');
342 $new_upgrade->manifest = base64_encode(serialize($serial_manifest));
343 $new_upgrade->save();
348 $mod_strings = $old_mod_strings;
352 * creates UpgradeHistory entries
353 * @param mode string Install or Uninstall
355 function updateUpgradeHistory() {
356 if(isset($_SESSION['INSTALLED_LANG_PACKS']) && count($_SESSION['INSTALLED_LANG_PACKS']) > 0) {
357 foreach($_SESSION['INSTALLED_LANG_PACKS'] as $k => $zipFile) {
358 $new_upgrade = new UpgradeHistory();
359 $new_upgrade->filename = $zipFile;
360 $new_upgrade->md5sum = md5_file($zipFile);
361 $new_upgrade->type = 'langpack';
362 $new_upgrade->version = $_SESSION['INSTALLED_LANG_PACKS_VERSION'][$k];
363 $new_upgrade->status = "installed";
364 $new_upgrade->manifest = $_SESSION['INSTALLED_LANG_PACKS_MANIFEST'][$k];
365 $new_upgrade->save();
372 * removes the installed language pack, but the zip is still in the cache dir
374 function removeLanguagePack() {
376 global $sugar_config;
379 $manifest = urldecode($_REQUEST['manifest']);
380 $zipFile = urldecode($_REQUEST['zipFile']);
382 if(isset($manifest) && !empty($manifest)) {
383 if(is_file($manifest)) {
384 if(!unlink($manifest)) {
385 $errors[] = $mod_strings['ERR_LANG_CANNOT_DELETE_FILE'].$manifest;
388 $errors[] = $mod_strings['ERR_LANG_MISSING_FILE'].$manifest;
390 unset($_SESSION['packages_to_install'][$manifest]);
392 if(isset($zipFile) && !empty($zipFile)) {
393 if(is_file($zipFile)) {
394 if(!unlink($zipFile)) {
395 $errors[] = $mod_strings['ERR_LANG_CANNOT_DELETE_FILE'].$zipFile;
398 $errors[] = $mod_strings['ERR_LANG_MISSING_FILE'].$zipFile;
401 if(count($errors > 0)) {
402 echo "<p class='error'>";
403 foreach($errors as $error) {
409 unlinkTempFiles($manifest, $zipFile);
415 * takes the current value of $sugar_config and writes it out to config.php (sorta the same as the final step)
416 * @param array sugar_config
418 function writeSugarConfig($sugar_config) {
419 ksort($sugar_config);
420 $sugar_config_string = "<?php\n" .
421 '// created: ' . date('Y-m-d H:i:s') . "\n" .
423 var_export($sugar_config, true) .
425 if(is_writable('config.php') && write_array_to_file( "sugar_config", $sugar_config, "config.php")) {
431 * uninstalls the Language pack
433 function uninstallLangPack() {
434 global $sugar_config;
436 // remove language from config
437 $new_langs = array();
438 $old_langs = $sugar_config['languages'];
439 foreach( $old_langs as $key => $value ){
440 if( $key != $_REQUEST['new_lang_name'] ){
441 $new_langs += array( $key => $value );
444 $sugar_config['languages'] = $new_langs;
446 writeSugarConfig($sugar_config);
450 * retrieves the name of the language
452 if ( !function_exists('getLanguagePackName') ) {
453 function getLanguagePackName($the_file) {
454 require_once( "$the_file" );
455 if( isset( $app_list_strings["language_pack_name"] ) ){
456 return( $app_list_strings["language_pack_name"] );
462 function getInstalledLangPacks($showButtons=true) {
466 $ret = "<tr><td colspan=7 align=left>{$mod_strings['LBL_LANG_PACK_INSTALLED']}</td></tr>";
467 //$ret .="<table width='100%' cellpadding='0' cellspacing='0' border='0'>";
469 <td width='15%' ><b>{$mod_strings['LBL_ML_NAME']}</b></td>
470 <td width='15%' ><b>{$mod_strings['LBL_ML_VERSION']}</b></td>
471 <td width='15%' ><b>{$mod_strings['LBL_ML_PUBLISHED']}</b></td>
472 <td width='15%' ><b>{$mod_strings['LBL_ML_UNINSTALLABLE']}</b></td>
473 <td width='15%' ><b>{$mod_strings['LBL_ML_DESCRIPTION']}</b></td>
474 <td width='15%' ></td>
475 <td width='15%' ></td>
478 $files = findAllFiles(getcwd()."/cache/upload/upgrades", $files);
480 if(isset($_SESSION['INSTALLED_LANG_PACKS']) && !empty($_SESSION['INSTALLED_LANG_PACKS'])){
481 if(count($_SESSION['INSTALLED_LANG_PACKS'] > 0)) {
482 foreach($_SESSION['INSTALLED_LANG_PACKS'] as $file) {
483 // handle manifest.php
484 $target_manifest = remove_file_extension( $file ) . '-manifest.php';
485 include($target_manifest);
487 $name = empty($manifest['name']) ? $file : $manifest['name'];
488 $version = empty($manifest['version']) ? '' : $manifest['version'];
489 $published_date = empty($manifest['published_date']) ? '' : $manifest['published_date'];
491 $description = empty($manifest['description']) ? 'None' : $manifest['description'];
492 $uninstallable = empty($manifest['is_uninstallable']) ? 'No' : 'Yes';
493 $manifest_type = $manifest['type'];
495 $deletePackage = getPackButton('uninstall', $target_manifest, $file, $next_step, $uninstallable, $showButtons);
496 //$ret .="<table width='100%' cellpadding='0' cellspacing='0' border='0'>";
498 $ret .= "<td width='15%' >".$name."</td>";
499 $ret .= "<td width='15%' >".$version."</td>";
500 $ret .= "<td width='15%' >".$published_date."</td>";
501 $ret .= "<td width='15%' >".$uninstallable."</td>";
502 $ret .= "<td width='15%' >".$description."</td>";
503 $ret .= "<td width='15%' ></td>";
504 $ret .= "<td width='15%' >{$deletePackage}</td>";
508 $ret .= "</tr><td colspan=7><i>{$mod_strings['LBL_LANG_NO_PACKS']}</i></td></tr>";
511 $ret .= "</tr><td colspan=7><i>{$mod_strings['LBL_LANG_NO_PACKS']}</i></td></tr>";
517 function uninstallLanguagePack() {
518 return commitLanguagePack(true);
522 function getSugarConfigLanguageArray($langZip) {
523 global $sugar_config;
525 include(remove_file_extension($langZip)."-manifest.php");
527 if(isset($installdefs['id']) && isset($manifest['name'])) {
528 $ret = $installdefs['id']."::".$manifest['name']."::".$manifest['version'];
536 ///////////////////////////////////////////////////////////////////////////////
537 //// FROM performSetup.php
539 * creates the Sugar DB user (if not admin)
541 function handleDbCreateSugarUser() {
543 global $setup_db_database_name;
544 global $setup_db_host_name;
545 global $setup_db_host_instance;
546 global $setup_db_admin_user_name;
547 global $setup_db_admin_password;
548 global $sugar_config;
549 global $setup_db_sugarsales_user;
550 global $setup_site_host_name;
551 global $setup_db_sugarsales_password;
553 echo $mod_strings['LBL_PERFORM_CREATE_DB_USER'];
555 switch($_SESSION['setup_db_type']) {
557 if(isset($_SESSION['mysql_type'])){
558 $host_name = getHostPortFromString($setup_db_host_name);
559 if(empty($host_name)){
560 $link = @mysqli_connect($setup_db_host_name, $setup_db_admin_user_name, $setup_db_admin_password);
562 $link = @mysqli_connect($host_name[0], $setup_db_admin_user_name, $setup_db_admin_password,null,$host_name[1]);
564 $query = "GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, ALTER, DROP, INDEX
565 ON `{$setup_db_database_name}`.*
566 TO \"{$setup_db_sugarsales_user}\"@\"{$setup_site_host_name}\"
567 IDENTIFIED BY '{$setup_db_sugarsales_password}';";
569 if(!@mysqli_query($link, $query)) {
570 $errno = mysqli_errno($link);
571 $error = mysqli_error($link);
574 $query = "SET PASSWORD FOR \"{$setup_db_sugarsales_user}\"@\"{$setup_site_host_name}\" = old_password('{$setup_db_sugarsales_password}');";
576 if(!@mysqli_query($link, $query)) {
577 $errno = mysqli_errno($link);
578 $error = mysqli_error($link);
581 if($setup_site_host_name != 'localhost') {
582 echo $mod_strings['LBL_PERFORM_CREATE_LOCALHOST'];
584 $host_name = getHostPortFromString($setup_db_host_name);
585 if(empty($host_name)){
586 $link = @mysqli_connect($setup_db_host_name, $setup_db_admin_user_name, $setup_db_admin_password);
588 $link = @mysqli_connect($host_name[0], $setup_db_admin_user_name, $setup_db_admin_password,null,$host_name[1]);
591 $query = "GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, ALTER, DROP, INDEX
592 ON `{$setup_db_database_name}`.*
593 TO \"{$setup_db_sugarsales_user}\"@\"localhost\"
594 IDENTIFIED BY '{$setup_db_sugarsales_password}';";
595 if(!@mysqli_query($link, $query)) {
596 $errno = mysqli_errno($link);
597 $error = mysqli_error($link);
600 $query = "SET PASSWORD FOR \"{$setup_db_sugarsales_user}\"@\"localhost\"\ = old_password('{$setup_db_sugarsales_password}');";
602 if(!@mysqli_query($link, $query)) {
603 $errno = mysqli_errno($link);
604 $error = mysqli_error($link);
611 $link = @mysql_connect($setup_db_host_name, $setup_db_admin_user_name, $setup_db_admin_password);
612 $query = "GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, ALTER, DROP, INDEX
613 ON `{$setup_db_database_name}`.*
614 TO \"{$setup_db_sugarsales_user}\"@\"{$setup_site_host_name}\"
615 IDENTIFIED BY '{$setup_db_sugarsales_password}';";
617 if(!@mysql_query($query, $link)) {
618 $errno = mysql_errno();
619 $error = mysql_error();
622 $query = "SET PASSWORD FOR \"{$setup_db_sugarsales_user}\"@\"{$setup_site_host_name}\" = old_password('{$setup_db_sugarsales_password}');";
624 if(!@mysql_query($query, $link)) {
625 $errno = mysql_errno();
626 $error = mysql_error();
629 if($setup_site_host_name != 'localhost') {
630 echo $mod_strings['LBL_PERFORM_CREATE_LOCALHOST'];
632 $link = @mysql_connect($setup_db_host_name, $setup_db_admin_user_name, $setup_db_admin_password);
633 $query = "GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, ALTER, DROP, INDEX
634 ON `{$setup_db_database_name}`.*
635 TO \"{$setup_db_sugarsales_user}\"@\"localhost\"
636 IDENTIFIED BY '{$setup_db_sugarsales_password}';";
637 if(!@mysql_query($query, $link)) {
638 $errno = mysql_errno();
639 $error = mysql_error();
642 $query = "SET PASSWORD FOR \"{$setup_db_sugarsales_user}\"@\"localhost\"\ = old_password('{$setup_db_sugarsales_password}');";
644 if(!@mysql_query($query, $link)) {
645 $errno = mysql_errno();
646 $error = mysql_error();
656 $setup_db_host_instance = trim($setup_db_host_instance);
659 if (empty($setup_db_host_instance)){
660 $connect_host = $setup_db_host_name ;
662 $connect_host = $setup_db_host_name . "\\" . $setup_db_host_instance;
664 if(isset($_SESSION['mssql_type'])){
665 $link = sqlsrv_connect($connect_host , array( 'UID' => $setup_db_admin_user_name, 'PWD' => $setup_db_admin_password));
666 $query = "USE " . $setup_db_database_name . ";";
667 @sqlsrv_query($link,$query);
669 $query = "CREATE LOGIN $setup_db_sugarsales_user WITH PASSWORD = '$setup_db_sugarsales_password'";
670 if(!sqlsrv_query($link,$query)) {
672 displayMssqlErrors('mssqlsrv', $query);
676 $query = "CREATE USER $setup_db_sugarsales_user FOR LOGIN $setup_db_sugarsales_user ";
677 if(!sqlsrv_query($link,$query)) {
679 displayMssqlErrors('mssqlsrv', $query);
683 $query = "EXEC sp_addRoleMember 'db_ddladmin ', '$setup_db_sugarsales_user'";
684 if(!sqlsrv_query($link,$query)) {
686 displayMssqlErrors('mssqlsrv', $query);
690 $query = "EXEC sp_addRoleMember 'db_datareader','$setup_db_sugarsales_user'";
691 if(!sqlsrv_query($link,$query)) {
693 displayMssqlErrors('mssqlsrv', $query);
697 $query = "EXEC sp_addRoleMember 'db_datawriter','$setup_db_sugarsales_user'";
698 if(!sqlsrv_query($link,$query)) {
700 displayMssqlErrors('mssqlsrv', $query);
705 $link = mssql_connect($connect_host , $setup_db_admin_user_name, $setup_db_admin_password);
706 $query = "USE " . $setup_db_database_name . ";";
707 @mssql_query($query);
709 $query = "CREATE LOGIN $setup_db_sugarsales_user WITH PASSWORD = '$setup_db_sugarsales_password'";
710 if(!@mssql_query($query)) {
712 $error = "Error Adding Login. SQL Query: $query";
713 displayMssqlErrors('mssql', $query);
717 $query = "CREATE USER $setup_db_sugarsales_user FOR LOGIN $setup_db_sugarsales_user ";
718 if(!@mssql_query($query)) {
720 $error = "Error Granting Access. SQL Query: $query";
721 displayMssqlErrors('mssql', $query);
725 $query = "EXEC sp_addRoleMember 'db_ddladmin ', '$setup_db_sugarsales_user'";
726 if(!@mssql_query($query)) {
728 $error = "Error Adding Role db_owner. SQL Query: $query";
729 displayMssqlErrors('mssql', $query);
733 $query = "EXEC sp_addRoleMember 'db_datareader','$setup_db_sugarsales_user'";
734 if(!@mssql_query($query)) {
736 $error = "Error Adding Role db_datareader. SQL Query: $query";
737 displayMssqlErrors('mssql', $query);
741 $query = "EXEC sp_addRoleMember 'db_datawriter','$setup_db_sugarsales_user'";
742 if(!@mssql_query($query)) {
744 $error = "Error Adding Role db_datawriter. SQL Query: $query";
745 displayMssqlErrors('mssql', $query);
752 echo $mod_strings['LBL_PERFORM_DONE'];
755 function displayMssqlErrors($driver_type, $query) {
756 global $sugar_config;
757 if($driver_type =='mssqlsrv' && ($errors = sqlsrv_errors(SQLSRV_ERR_ALL) ) != null)
759 foreach( $errors as $error)
762 echo "<div style='color:red;'>";
763 echo "An error occured when performing the folloing query:<br>";
766 installLog("An error occured when performing the query:".$query." SQLSTATE: ".$error[ 'SQLSTATE']." message: ".$error[ 'message']);
769 if($driver_type =='mssql')
771 echo "<div style='color:red;'>";
772 echo "An error occured when performing the folloing query:<br>";
775 installLog("An error occured when performing the query:".$query." message: ".mssql_get_last_message());
779 * ensures that the charset and collation for a given database is set
782 function handleDbCharsetCollation() {
784 global $setup_db_database_name;
785 global $setup_db_host_name;
786 global $setup_db_admin_user_name;
787 global $setup_db_admin_password;
788 global $sugar_config;
790 if($_SESSION['setup_db_type'] == 'mysql') {
791 if(isset($_SESSION['mysql_type'])){
792 $host_name = getHostPortFromString($setup_db_host_name);
793 if(empty($host_name)){
794 $link = @mysqli_connect($setup_db_host_name, $setup_db_admin_user_name, $setup_db_admin_password);
797 $link = @mysqli_connect($host_name[0], $setup_db_admin_user_name, $setup_db_admin_password,null,$host_name[1]);
800 $q1 = "ALTER DATABASE `{$setup_db_database_name}` DEFAULT CHARACTER SET utf8";
801 $q2 = "ALTER DATABASE `{$setup_db_database_name}` DEFAULT COLLATE utf8_general_ci";
802 @mysqli_query($link, $q1);
803 @mysqli_query($link, $q2);
806 $link = @mysql_connect($setup_db_host_name, $setup_db_admin_user_name, $setup_db_admin_password);
807 $q1 = "ALTER DATABASE `{$setup_db_database_name}` DEFAULT CHARACTER SET utf8";
808 $q2 = "ALTER DATABASE `{$setup_db_database_name}` DEFAULT COLLATE utf8_general_ci";
809 @mysql_query($q1, $link);
810 @mysql_query($q2, $link);
817 * creates the new database
819 function handleDbCreateDatabase() {
821 global $setup_db_database_name;
822 global $setup_db_host_name;
823 global $setup_db_host_instance;
824 global $setup_db_admin_user_name;
825 global $setup_db_admin_password;
826 global $sugar_config;
828 echo "{$mod_strings['LBL_PERFORM_CREATE_DB_1']} {$setup_db_database_name} {$mod_strings['LBL_PERFORM_CREATE_DB_2']} {$setup_db_host_name}...";
830 switch($_SESSION['setup_db_type']) {
832 if(isset($_SESSION['mysql_type'])){
833 $host_name = getHostPortFromString($setup_db_host_name);
834 if(empty($host_name)){
835 $link = @mysqli_connect($setup_db_host_name, $setup_db_admin_user_name, $setup_db_admin_password);
837 $link = @mysqli_connect($host_name[0], $setup_db_admin_user_name, $setup_db_admin_password,null,$host_name[1]);
839 $drop = 'DROP DATABASE IF EXISTS '.$setup_db_database_name;
840 @mysqli_query($link, $drop);
842 $query = 'CREATE DATABASE `' . $setup_db_database_name . '` CHARACTER SET utf8 COLLATE utf8_general_ci';
843 @mysqli_query($link, $query);
847 $link = @mysql_connect($setup_db_host_name, $setup_db_admin_user_name, $setup_db_admin_password);
848 $drop = 'DROP DATABASE IF EXISTS '.$setup_db_database_name;
849 @mysql_query($drop, $link);
851 $query = 'CREATE DATABASE `' . $setup_db_database_name . '` CHARACTER SET utf8 COLLATE utf8_general_ci';
852 @mysql_query($query, $link);
860 $setup_db_host_instance = trim($setup_db_host_instance);
861 if (empty($setup_db_host_instance)){
862 $connect_host = $setup_db_host_name ;
864 $connect_host = $setup_db_host_name . "\\" . $setup_db_host_instance;
866 if(isset($_SESSION['mssql_type'])){
867 $link = sqlsrv_connect($connect_host , array( 'UID' => $setup_db_admin_user_name, 'PWD' => $setup_db_admin_password));
868 $setup_db_database_name = str_replace(' ', '_', $setup_db_database_name); // remove space
870 //create check to see if this is existing db
871 $check = "SELECT count(name) num FROM master..sysdatabases WHERE name = N'".$setup_db_database_name."'";
872 $tableCntRes = sqlsrv_query($link,$check);
873 $tableCnt= sqlsrv_fetch_array($tableCntRes);
875 //if this db already exists, then drop it
877 $drop = "DROP DATABASE $setup_db_database_name";
878 @ sqlsrv_query($link,$drop);
882 $query = 'create database '.$setup_db_database_name;
883 @sqlsrv_query($link,$query);
884 @sqlsrv_close($link);
887 $link = @mssql_connect($connect_host, $setup_db_admin_user_name, $setup_db_admin_password);
888 $setup_db_database_name = str_replace(' ', '_', $setup_db_database_name); // remove space
890 //create check to see if this is existing db
891 $check = "SELECT count(name) num FROM master..sysdatabases WHERE name = N'".$setup_db_database_name."'";
892 $tableCntRes = mssql_query($check);
893 $tableCnt= mssql_fetch_row($tableCntRes);
895 //if this db already exists, then drop it
897 $drop = "DROP DATABASE $setup_db_database_name";
898 @ mssql_query($drop);
902 $query = 'create database '.$setup_db_database_name;
903 @mssql_query($query);
909 echo $mod_strings['LBL_PERFORM_DONE'];
914 * handles creation of Log4PHP properties file
915 * This function has been deprecated. Use SugarLogger.
917 function handleLog4Php() {
919 /* global $setup_site_log_dir;
920 global $setup_site_log_file;
922 if(is_writable("log4php.properties") && ($fh = @ sugar_fopen("log4php.properties", "r+"))) {
923 $props = fread($fh, filesize("log4php.properties"));
924 $props = preg_replace('/(log4php.appender.A2.File=).*\n/', "$1" . $setup_site_log_dir . "/" . $setup_site_log_file . "\n", $props);
926 fwrite( $fh, $props );
927 ftruncate( $fh, ftell($fh) );
933 function installLog($entry) {
936 '.gmdate("Y-m-d H:i:s").'...';
937 $log = clean_path(getcwd().'/install.log');
939 // create if not exists
940 if(!file_exists($log)) {
941 $fp = @sugar_fopen($log, 'w+'); // attempts to create file
942 if(!is_resource($fp)) {
943 $GLOBALS['log']->fatal('could not create the install.log file');
946 $fp = @sugar_fopen($log, 'a+'); // write pointer at end of file
947 if(!is_resource($fp)) {
948 $GLOBALS['log']->fatal('could not open/lock install.log file');
954 if(@fwrite($fp, $nl.$entry) === false) {
955 $GLOBALS['log']->fatal('could not write to install.log: '.$entry);
958 if(is_resource($fp)) {
966 * takes session vars and creates config.php
967 * @return array bottle collection of error messages
969 function handleSugarConfig() {
973 global $setup_db_host_name;
974 global $setup_db_host_instance;
975 global $setup_db_sugarsales_user;
976 global $setup_db_sugarsales_password;
977 global $setup_db_database_name;
978 global $setup_site_host_name;
979 global $setup_site_log_dir;
980 global $setup_site_log_file;
981 global $setup_site_session_path;
982 global $setup_site_guid;
983 global $setup_site_url;
984 global $setup_sugar_version;
985 global $sugar_config;
986 global $setup_site_log_level;
988 echo "<b>{$mod_strings['LBL_PERFORM_CONFIG_PHP']} (config.php)</b><br>";
989 ///////////////////////////////////////////////////////////////////////////////
990 //// $sugar_config SETTINGS
991 if( is_file('config.php') ){
992 $is_writable = is_writable('config.php');
993 // require is needed here (config.php is sometimes require'd from install.php)
994 require('config.php');
996 $is_writable = is_writable('.');
999 // build default sugar_config and merge with new values
1000 $sugar_config = sugarArrayMerge(get_sugar_config_defaults(), $sugar_config);
1001 // always lock the installer
1002 $sugar_config['installer_locked'] = true;
1003 // we're setting these since the user was given a fair chance to change them
1004 $sugar_config['dbconfig']['db_host_name'] = $setup_db_host_name;
1005 if($_SESSION['setup_db_type'] == 'mssql') {
1006 $sugar_config['dbconfig']['db_host_instance'] = $setup_db_host_instance;
1008 $sugar_config['dbconfig']['db_user_name'] = $setup_db_sugarsales_user;
1009 $sugar_config['dbconfig']['db_password'] = $setup_db_sugarsales_password;
1010 $sugar_config['dbconfig']['db_name'] = $setup_db_database_name;
1011 $sugar_config['dbconfig']['db_type'] = $_SESSION['setup_db_type'];
1012 if(isset($_SESSION['setup_db_port_num'])){
1013 $sugar_config['dbconfig']['db_port'] = $_SESSION['setup_db_port_num'];
1015 $sugar_config['cache_dir'] = $cache_dir;
1016 $sugar_config['default_charset'] = $mod_strings['DEFAULT_CHARSET'];
1017 $sugar_config['default_email_client'] = 'sugar';
1018 $sugar_config['default_email_editor'] = 'html';
1019 $sugar_config['host_name'] = $setup_site_host_name;
1020 $sugar_config['import_dir'] = $cache_dir.'import/';
1021 $sugar_config['js_custom_version'] = '';
1022 $sugar_config['use_real_names'] = true;
1023 $sugar_config['log_dir'] = $setup_site_log_dir;
1024 $sugar_config['log_file'] = $setup_site_log_file;
1026 /*nsingh(bug 22402): Consolidate logger settings under $config['logger'] as liked by the new logger! If log4pphp exists,
1027 these settings will be overwritten by those in log4php.properties when the user access admin->system settings.*/
1028 $sugar_config['logger'] =
1029 array ('level'=>$setup_site_log_level,
1032 'name' => 'sugarcrm',
1033 'dateFormat' => '%c',
1034 'maxSize' => '10MB',
1036 'suffix' => '%m_%Y'),
1038 $sugar_config['session_dir'] = $setup_site_session_path;
1039 $sugar_config['site_url'] = $setup_site_url;
1040 $sugar_config['sugar_version'] = $setup_sugar_version;
1041 $sugar_config['tmp_dir'] = $cache_dir.'xml/';
1042 $sugar_config['upload_dir'] = $cache_dir.'upload/';
1043 $sugar_config['use_php_code_json'] = returnPhpJsonStatus(); // true on error
1044 if( isset($_SESSION['setup_site_sugarbeet_anonymous_stats']) ){
1045 $sugar_config['sugarbeet'] = $_SESSION['setup_site_sugarbeet_anonymous_stats'];
1047 $sugar_config['demoData'] = $_SESSION['demoData'];
1048 if( isset( $setup_site_guid ) ){
1049 $sugar_config['unique_key'] = $setup_site_guid;
1051 if(empty($sugar_config['unique_key'])){
1052 $sugar_config['unique_key'] = md5( create_guid() );
1054 // add installed langs to config
1055 // entry in upgrade_history comes AFTER table creation
1056 if(isset($_SESSION['INSTALLED_LANG_PACKS']) && is_array($_SESSION['INSTALLED_LANG_PACKS']) && !empty($_SESSION['INSTALLED_LANG_PACKS'])) {
1057 foreach($_SESSION['INSTALLED_LANG_PACKS'] as $langZip) {
1058 $lang = getSugarConfigLanguageArray($langZip);
1060 $exLang = explode('::', $lang);
1061 if(is_array($exLang) && count($exLang) == 3) {
1062 $sugar_config['languages'][$exLang[0]] = $exLang[1];
1067 if(file_exists('install/lang.config.php')){
1068 include('install/lang.config.php');
1069 if(!empty($config['languages'])){
1070 foreach($config['languages'] as $lang=>$label){
1071 $sugar_config['languages'][$lang] = $label;
1076 ksort($sugar_config);
1077 $sugar_config_string = "<?php\n" .
1078 '// created: ' . date('Y-m-d H:i:s') . "\n" .
1079 '$sugar_config = ' .
1080 var_export($sugar_config, true) .
1082 if($is_writable && write_array_to_file( "sugar_config", $sugar_config, "config.php")) {
1086 echo "<p>{$mod_strings['ERR_PERFORM_CONFIG_PHP_1']}</p>\n";
1087 echo "<p>{$mod_strings['ERR_PERFORM_CONFIG_PHP_2']}</p>\n";
1088 echo "<TEXTAREA rows=\"15\" cols=\"80\">".$sugar_config_string."</TEXTAREA>";
1089 echo "<p>{$mod_strings['ERR_PERFORM_CONFIG_PHP_3']}</p>";
1091 $bottle[] = $mod_strings['ERR_PERFORM_CONFIG_PHP_4'];
1094 //// END $sugar_config
1095 ///////////////////////////////////////////////////////////////////////////////
1099 * (re)write the .htaccess file to prevent browser access to the log file
1101 function handleHtaccess(){
1102 global $mod_strings;
1103 $ignoreCase = (substr_count(strtolower($_SERVER['SERVER_SOFTWARE']), 'apache/2') > 0)?'(?i)':'';
1104 $htaccess_file = getcwd() . "/.htaccess";
1106 $restrict_str = <<<EOQ
1108 # BEGIN SUGARCRM RESTRICTIONS
1109 RedirectMatch 403 {$ignoreCase}.*\.log$
1110 RedirectMatch 403 {$ignoreCase}/+not_imported_.*\.txt
1111 RedirectMatch 403 {$ignoreCase}/+(soap|cache|xtemplate|data|examples|include|log4php|metadata|modules)/+.*\.(php|tpl)
1112 RedirectMatch 403 {$ignoreCase}/+emailmandelivery\.php
1113 RedirectMatch 403 {$ignoreCase}/+cache/+upload
1114 RedirectMatch 403 {$ignoreCase}/+cache/+diagnostic
1115 RedirectMatch 403 {$ignoreCase}/+files\.md5$
1116 # END SUGARCRM RESTRICTIONS
1118 if(file_exists($htaccess_file)){
1119 $fp = fopen($htaccess_file, 'r');
1121 while($line = fgets($fp)){
1123 if(preg_match("/\s*#\s*BEGIN\s*SUGARCRM\s*RESTRICTIONS/i", $line))$skip = true;
1124 if(!$skip)$contents .= $line;
1125 if(preg_match("/\s*#\s*END\s*SUGARCRM\s*RESTRICTIONS/i", $line))$skip = false;
1128 $status = file_put_contents($htaccess_file, $contents . $restrict_str);
1130 echo "<p>{$mod_strings['ERR_PERFORM_HTACCESS_1']}<span class=stop>{$htaccess_file}</span> {$mod_strings['ERR_PERFORM_HTACCESS_2']}</p>\n";
1131 echo "<p>{$mod_strings['ERR_PERFORM_HTACCESS_3']}</p>\n";
1138 * (re)write the web.config file to prevent browser access to the log file
1140 function handleWebConfig() {
1141 global $setup_site_log_dir;
1142 global $setup_site_log_file;
1143 global $sugar_config;
1145 // Bug 36968 - Fallback to using $sugar_config values when we are not calling this from the installer
1146 if (empty($setup_site_log_file)) {
1147 $setup_site_log_file = $sugar_config['log_file'];
1148 if ( empty($sugar_config['log_file']) ) {
1149 $setup_site_log_file = 'sugarcrm.log';
1152 if (empty($setup_site_log_dir)) {
1153 $setup_site_log_dir = $sugar_config['log_dir'];
1154 if ( empty($sugar_config['log_dir']) ) {
1155 $setup_site_log_dir = '.';
1159 $prefix = $setup_site_log_dir.empty($setup_site_log_dir)?'':'/';
1162 $config_array = array(
1163 array('1'=> $prefix.str_replace('.','\\.',$setup_site_log_file).'\\.*' ,'2'=>'log_file_restricted.html'),
1164 array('1'=> $prefix.'install.log' ,'2'=>'log_file_restricted.html'),
1165 array('1'=> $prefix.'upgradeWizard.log' ,'2'=>'log_file_restricted.html'),
1166 array('1'=> $prefix.'emailman.log' ,'2'=>'log_file_restricted.html'),
1167 array('1'=>'not_imported_.*.txt' ,'2'=>'log_file_restricted.html'),
1168 array('1'=>'XTemplate/(.*)/(.*).php' ,'2'=>'index.php'),
1169 array('1'=>'data/(.*).php' ,'2'=>'index.php'),
1170 array('1'=>'examples/(.*).php' ,'2'=>'index.php'),
1171 array('1'=>'include/(.*).php' ,'2'=>'index.php'),
1172 array('1'=>'include/(.*)/(.*).php' ,'2'=>'index.php'),
1173 array('1'=>'log4php/(.*).php' ,'2'=>'index.php'),
1174 array('1'=>'log4php/(.*)/(.*)' ,'2'=>'index.php'),
1175 array('1'=>'metadata/(.*)/(.*).php' ,'2'=>'index.php'),
1176 array('1'=>'modules/(.*)/(.*).php' ,'2'=>'index.php'),
1177 array('1'=>'soap/(.*).php' ,'2'=>'index.php'),
1178 array('1'=>'emailmandelivery.php' ,'2'=>'index.php'),
1179 array('1'=>'cron.php' ,'2'=>'index.php'),
1180 array('1'=> $sugar_config['upload_dir'].'.*' ,'2'=>'index.php'),
1184 $xmldoc = new XMLWriter();
1185 $xmldoc->openURI('web.config');
1186 $xmldoc->setIndent(true);
1187 $xmldoc->setIndentString(' ');
1188 $xmldoc->startDocument('1.0','UTF-8');
1189 $xmldoc->startElement('configuration');
1190 $xmldoc->startElement('system.webServer');
1191 $xmldoc->startElement('rewrite');
1192 $xmldoc->startElement('rules');
1193 for ($i = 0; $i < count($config_array); $i++) {
1194 $xmldoc->startElement('rule');
1195 $xmldoc->writeAttribute('name', "redirect$i");
1196 $xmldoc->writeAttribute('stopProcessing', 'true');
1197 $xmldoc->startElement('match');
1198 $xmldoc->writeAttribute('url', $config_array[$i]['1']);
1199 $xmldoc->endElement();
1200 $xmldoc->startElement('action');
1201 $xmldoc->writeAttribute('type', 'Redirect');
1202 $xmldoc->writeAttribute('url', $config_array[$i]['2']);
1203 $xmldoc->writeAttribute('redirectType', 'Found');
1204 $xmldoc->endElement();
1205 $xmldoc->endElement();
1207 $xmldoc->endElement();
1208 $xmldoc->endElement();
1209 $xmldoc->endElement();
1210 $xmldoc->endElement();
1211 $xmldoc->endDocument();
1216 * Drop old tables if table exists and told to drop it
1218 function drop_table_install( &$focus ){
1222 $result = $db->tableExists($focus->table_name);
1225 $focus->drop_tables();
1226 $GLOBALS['log']->info("Dropped old ".$focus->table_name." table.");
1230 $GLOBALS['log']->info("Did not need to drop old ".$focus->table_name." table. It doesn't exist.");
1235 // Creating new tables if they don't exist.
1236 function create_table_if_not_exist( &$focus ){
1238 $table_created = false;
1240 // normal code follows
1241 $result = $db->tableExists($focus->table_name);
1243 $GLOBALS['log']->info("Table ".$focus->table_name." already exists.");
1245 $focus->create_tables();
1246 $GLOBALS['log']->info("Created ".$focus->table_name." table.");
1247 $table_created = true;
1249 return $table_created;
1254 function create_default_users(){
1256 global $setup_site_admin_password;
1257 global $setup_site_admin_user_name;
1258 global $create_default_user;
1259 global $sugar_config;
1261 //Create default admin user
1264 $user->new_with_id = true;
1265 $user->last_name = 'Administrator';
1266 //$user->user_name = 'admin';
1267 $user->user_name = $setup_site_admin_user_name;
1268 $user->title = "Administrator";
1269 $user->status = 'Active';
1270 $user->is_admin = true;
1271 $user->employee_status = 'Active';
1272 //$user->user_password = $user->encrypt_password($setup_site_admin_password);
1273 $user->user_hash = strtolower(md5($setup_site_admin_password));
1277 // echo 'Creating RSS Feeds';
1278 //$feed = new Feed();
1279 //$feed->createRSSHomePage($user->id);
1282 // We need to change the admin user to a fixed id of 1.
1283 // $query = "update users set id='1' where user_name='$user->user_name'";
1284 // $result = $db->query($query, true, "Error updating admin user ID: ");
1286 $GLOBALS['log']->info("Created ".$user->table_name." table. for user $user->id");
1288 if( $create_default_user ){
1289 $default_user = new User();
1290 $default_user->last_name = $sugar_config['default_user_name'];
1291 $default_user->user_name = $sugar_config['default_user_name'];
1292 $default_user->status = 'Active';
1293 if( isset($sugar_config['default_user_is_admin']) && $sugar_config['default_user_is_admin'] ){
1294 $default_user->is_admin = true;
1296 //$default_user->user_password = $default_user->encrypt_password($sugar_config['default_password']);
1297 $default_user->user_hash = strtolower(md5($sugar_config['default_password']));
1298 $default_user->save();
1299 //$feed->createRSSHomePage($user->id);
1303 function set_admin_password( $password ) {
1307 $encrypted_password = $user->encrypt_password($password);
1308 $user_hash = strtolower(md5($password));
1310 //$query = "update users set user_password='$encrypted_password', user_hash='$user_hash' where id='1'";
1311 $query = "update users set user_hash='$user_hash' where id='1'";
1316 function insert_default_settings(){
1318 global $setup_sugar_version;
1319 global $sugar_db_version;
1322 $db->query("INSERT INTO config (category, name, value) VALUES ('notify', 'fromaddress', 'do_not_reply@example.com')");
1323 $db->query("INSERT INTO config (category, name, value) VALUES ('notify', 'fromname', 'SugarCRM')");
1324 $db->query("INSERT INTO config (category, name, value) VALUES ('notify', 'send_by_default', '1')");
1325 $db->query("INSERT INTO config (category, name, value) VALUES ('notify', 'on', '1')");
1326 $db->query("INSERT INTO config (category, name, value) VALUES ('notify', 'send_from_assigning_user', '0')");
1327 /* cn: moved to OutboundEmail class
1328 $db->query("INSERT INTO config (category, name, value) VALUES ('mail', 'smtpserver', 'localhost')");
1329 $db->query("INSERT INTO config (category, name, value) VALUES ('mail', 'smtpport', '25')");
1330 $db->query("INSERT INTO config (category, name, value) VALUES ('mail', 'sendtype', 'smtp')");
1331 $db->query("INSERT INTO config (category, name, value) VALUES ('mail', 'smtpuser', '')");
1332 $db->query("INSERT INTO config (category, name, value) VALUES ('mail', 'smtppass', '')");
1333 $db->query("INSERT INTO config (category, name, value) VALUES ('mail', 'smtpauth_req', '0')");
1335 $db->query("INSERT INTO config (category, name, value) VALUES ('info', 'sugar_version', '" . $sugar_db_version . "')");
1336 $db->query("INSERT INTO config (category, name, value) VALUES ('MySettings', 'tab', '')");
1337 $db->query("INSERT INTO config (category, name, value) VALUES ('portal', 'on', '0')");
1341 //insert default tracker settings
1342 $db->query("INSERT INTO config (category, name, value) VALUES ('tracker', 'Tracker', '1')");
1346 $db->query( "INSERT INTO config (category, name, value) VALUES ( 'system', 'skypeout_on', '1')" );
1357 // Returns true if the given file/dir has been made writable (or is already
1359 function make_writable($file)
1363 if(is_file($file) || is_dir($file))
1365 if(is_writable($file))
1371 $original_fileperms = fileperms($file);
1373 // add user writable permission
1374 $new_fileperms = $original_fileperms | 0x0080;
1375 @sugar_chmod($file, $new_fileperms);
1377 if(is_writable($file))
1383 // add group writable permission
1384 $new_fileperms = $original_fileperms | 0x0010;
1385 @chmod($file, $new_fileperms);
1387 if(is_writable($file))
1393 // add world writable permission
1394 $new_fileperms = $original_fileperms | 0x0002;
1395 @chmod($file, $new_fileperms);
1397 if(is_writable($file))
1409 function recursive_make_writable($start_file)
1411 $ret_val = make_writable($start_file);
1413 if($ret_val && is_dir($start_file))
1415 // PHP 4 alternative to scandir()
1417 $dh = opendir($start_file);
1418 $filename = readdir($dh);
1419 while(!empty($filename))
1421 if($filename != '.' && $filename != '..' && $filename != '.svn')
1423 $files[] = $filename;
1426 $filename = readdir($dh);
1429 foreach($files as $file)
1431 $ret_val = recursive_make_writable($start_file . '/' . $file);
1435 $_SESSION['unwriteable_module_files'][dirname($file)] = dirname($file);
1436 $fnl_ret_val = false;
1443 $unwriteable_directory = is_dir($start_file) ? $start_file : dirname($start_file);
1444 if($unwriteable_directory[0] == '.'){$unwriteable_directory = substr($unwriteable_directory,1);}
1445 $_SESSION['unwriteable_module_files'][$unwriteable_directory] = $unwriteable_directory;
1446 $_SESSION['unwriteable_module_files']['failed'] = true;
1452 function recursive_is_writable($start_file)
1454 $ret_val = is_writable($start_file);
1456 if($ret_val && is_dir($start_file))
1458 // PHP 4 alternative to scandir()
1460 $dh = opendir($start_file);
1461 $filename = readdir($dh);
1462 while(!empty($filename))
1464 if($filename != '.' && $filename != '..' && $filename != '.svn')
1466 $files[] = $filename;
1469 $filename = readdir($dh);
1472 foreach($files as $file)
1474 $ret_val = recursive_is_writable($start_file . '/' . $file);
1489 function getMysqlVersion($link) {
1491 if(isset($_SESSION['mysql_type'])){
1492 $version = mysqli_get_server_info($link);
1494 if(is_resource($link)) {
1495 $version = mysql_get_server_info($link);
1498 return preg_replace('/[A-Za-z\-]/','',$version);
1506 // one place for form validation/conversion to boolean
1507 function get_boolean_from_request( $field ){
1508 if( !isset($_REQUEST[$field]) ){
1512 if( ($_REQUEST[$field] == 'on') || ($_REQUEST[$field] == 'yes') ){
1520 function stripslashes_checkstrings($value){
1521 if(is_string($value)){
1522 return stripslashes($value);
1528 function print_debug_array( $name, $debug_array ){
1529 ksort( $debug_array );
1531 print( "$name vars:\n" );
1534 foreach( $debug_array as $key => $value ){
1535 if( stristr( $key, "password" ) ){
1538 print( " [$key] => $value\n" );
1544 function print_debug_comment(){
1545 if( !empty($_REQUEST['debug']) ){
1546 $_SESSION['debug'] = $_REQUEST['debug'];
1549 if( !empty($_SESSION['debug']) && ($_SESSION['debug'] == 'true') ){
1550 print( "<!-- debug is on (to turn off, hit any page with 'debug=false' as a URL parameter.\n" );
1552 print_debug_array( "Session", $_SESSION );
1553 print_debug_array( "Request", $_REQUEST );
1554 print_debug_array( "Post", $_POST );
1555 print_debug_array( "Get", $_GET );
1561 function validate_systemOptions() {
1562 global $mod_strings;
1564 switch( $_SESSION['setup_db_type'] ){
1570 $errors[] = "<span class='error'>".$mod_strings['ERR_DB_INVALID']."</span>";
1577 function validate_dbConfig() {
1578 global $mod_strings;
1579 require_once('install/checkDBSettings.php');
1580 return checkDBSettings(true);
1584 function validate_siteConfig($type){
1585 global $mod_strings;
1589 if(empty($_SESSION['setup_system_name'])){
1590 $errors[] = "<span class='error'>".$mod_strings['LBL_REQUIRED_SYSTEM_NAME']."</span>";
1592 if($_SESSION['setup_site_url'] == ''){
1593 $errors[] = "<span class='error'>".$mod_strings['ERR_URL_BLANK']."</span>";
1596 if($_SESSION['setup_site_admin_user_name'] == '') {
1597 $errors[] = "<span class='error'>".$mod_strings['ERR_ADMIN_USER_NAME_BLANK']."</span>";
1600 if($_SESSION['setup_site_admin_password'] == ''){
1601 $errors[] = "<span class='error'>".$mod_strings['ERR_ADMIN_PASS_BLANK']."</span>";
1604 if($_SESSION['setup_site_admin_password'] != $_SESSION['setup_site_admin_password_retype']){
1605 $errors[] = "<span class='error'>".$mod_strings['ERR_PASSWORD_MISMATCH']."</span>";
1608 if(!empty($_SESSION['setup_site_custom_session_path']) && $_SESSION['setup_site_session_path'] == ''){
1609 $errors[] = "<span class='error'>".$mod_strings['ERR_SESSION_PATH']."</span>";
1612 if(!empty($_SESSION['setup_site_custom_session_path']) && $_SESSION['setup_site_session_path'] != ''){
1613 if(is_dir($_SESSION['setup_site_session_path'])){
1614 if(!is_writable($_SESSION['setup_site_session_path'])){
1615 $errors[] = "<span class='error'>".$mod_strings['ERR_SESSION_DIRECTORY']."</span>";
1619 $errors[] = "<span class='error'>".$mod_strings['ERR_SESSION_DIRECTORY_NOT_EXISTS']."</span>";
1623 if(!empty($_SESSION['setup_site_custom_log_dir']) && $_SESSION['setup_site_log_dir'] == ''){
1624 $errors[] = "<span class='error'>".$mod_strings['ERR_LOG_DIRECTORY_NOT_EXISTS']."</span>";
1627 if(!empty($_SESSION['setup_site_custom_log_dir']) && $_SESSION['setup_site_log_dir'] != ''){
1628 if(is_dir($_SESSION['setup_site_log_dir'])){
1629 if(!is_writable($_SESSION['setup_site_log_dir'])) {
1630 $errors[] = "<span class='error'>".$mod_strings['ERR_LOG_DIRECTORY_NOT_WRITABLE']."</span>";
1634 $errors[] = "<span class='error'>".$mod_strings['ERR_LOG_DIRECTORY_NOT_EXISTS']."</span>";
1638 if(!empty($_SESSION['setup_site_specify_guid']) && $_SESSION['setup_site_guid'] == ''){
1639 $errors[] = "<span class='error'>".$mod_strings['ERR_SITE_GUID']."</span>";
1647 function pullSilentInstallVarsIntoSession() {
1648 global $mod_strings;
1649 global $sugar_config;
1652 if( file_exists('config_si.php') ){
1653 require_once('config_si.php');
1655 else if( empty($sugar_config_si) ){
1656 die( $mod_strings['ERR_SI_NO_CONFIG'] );
1659 $config_subset = array (
1660 'setup_site_url' => isset($sugar_config['site_url']) ? $sugar_config['site_url'] : '',
1661 'setup_db_host_name' => isset($sugar_config['dbconfig']['db_host_name']) ? $sugar_config['dbconfig']['db_host_name'] : '',
1662 'setup_db_sugarsales_user' => isset($sugar_config['dbconfig']['db_user_name']) ? $sugar_config['dbconfig']['db_user_name'] : '',
1663 'setup_db_sugarsales_password' => isset($sugar_config['dbconfig']['db_password']) ? $sugar_config['dbconfig']['db_password'] : '',
1664 'setup_db_database_name' => isset($sugar_config['dbconfig']['db_name']) ? $sugar_config['dbconfig']['db_name'] : '',
1665 'setup_db_type' => isset($sugar_config['dbconfig']['db_type']) ? $sugar_config['dbconfig']['db_type'] : '',
1667 // third array of values derived from above values
1669 'setup_site_admin_password_retype' => $sugar_config_si['setup_site_admin_password'],
1670 'setup_db_sugarsales_password_retype' => $config_subset['setup_db_sugarsales_password'],
1673 $needles = array('setup_license_key_users','setup_license_key_expire_date','setup_license_key', 'setup_num_lic_oc',
1674 'default_currency_iso4217', 'default_currency_name', 'default_currency_significant_digits',
1675 'default_currency_symbol', 'default_date_format', 'default_time_format', 'default_decimal_seperator',
1676 'default_export_charset', 'default_language', 'default_locale_name_format', 'default_number_grouping_seperator',
1677 'export_delimiter');
1678 copyFromArray($sugar_config_si, $needles, $derived);
1679 $all_config_vars = array_merge( $config_subset, $sugar_config_si, $derived );
1681 // bug 16860 tyoung - trim leading and trailing whitespace from license_key
1682 if (isset($all_config_vars['setup_license_key'])) {
1683 $all_config_vars['setup_license_key'] = trim($all_config_vars['setup_license_key']);
1686 foreach( $all_config_vars as $key => $value ){
1687 $_SESSION[$key] = $value;
1692 * given an array it will check to determine if the key exists in the array, if so
1693 * it will addd to the return array
1695 * @param intput_array haystack to check
1696 * @param needles list of needles to search for
1697 * @param output_array the array to add the keys to
1699 function copyFromArray($input_array, $needles, $output_array){
1700 foreach($needles as $needle){
1701 if(isset($input_array[$needle])){
1702 $output_array[$needle] = $input_array[$needle];
1710 * handles language pack uploads - code based off of upload_file->final_move()
1711 * puts it into the cache/upload dir to be handed off to langPackUnpack();
1713 * @param object file UploadFile object
1714 * @return bool true if successful
1716 function langPackFinalMove($file) {
1717 global $sugar_config;
1718 //."upgrades/langpack/"
1719 $destination = $sugar_config['upload_dir'].$file->stored_file_name;
1720 if(!move_uploaded_file($_FILES[$file->field_name]['tmp_name'], $destination)) {
1721 die ("ERROR: can't move_uploaded_file to $destination. You should try making the directory writable by the webserver");
1726 function getLicenseDisplay($type, $manifest, $zipFile, $next_step, $license_file, $clean_file) {
1727 return PackageManagerDisplay::getLicenseDisplay($license_file, 'install.php', $next_step, $zipFile, $type, $manifest, $clean_file);
1732 * creates the remove/delete form for langpack page
1733 * @param string type commit/remove
1734 * @param string manifest path to manifest file
1735 * @param string zipFile path to uploaded zip file
1736 * @param int nextstep current step
1737 * @return string ret <form> for this package
1739 function getPackButton($type, $manifest, $zipFile, $next_step, $uninstallable='Yes', $showButtons=true) {
1740 global $mod_strings;
1742 $button = $mod_strings['LBL_LANG_BUTTON_COMMIT'];
1743 if($type == 'remove') {
1744 $button = $mod_strings['LBL_LANG_BUTTON_REMOVE'];
1745 } elseif($type == 'uninstall') {
1746 $button = $mod_strings['LBL_LANG_BUTTON_UNINSTALL'];
1749 $disabled = ($uninstallable == 'Yes') ? false : true;
1751 $ret = "<form name='delete{$zipFile}' action='install.php' method='POST'>
1752 <input type='hidden' name='current_step' value='{$next_step}'>
1753 <input type='hidden' name='goto' value='{$mod_strings['LBL_CHECKSYS_RECHECK']}'>
1754 <input type='hidden' name='languagePackAction' value='{$type}'>
1755 <input type='hidden' name='manifest' value='".urlencode($manifest)."'>
1756 <input type='hidden' name='zipFile' value='".urlencode($zipFile)."'>
1757 <input type='hidden' name='install_type' value='custom'>";
1758 if(!$disabled && $showButtons) {
1759 $ret .= "<input type='submit' value='{$button}' class='button'>";
1766 * finds all installed languages and returns an array with the names
1767 * @return array langs array of installed languages
1769 function getInstalledLanguages() {
1770 $langDir = 'include/language/';
1771 $dh = opendir($langDir);
1774 while($file = readdir($dh)) {
1775 if(substr($file, -3) == 'php') {
1784 * searches upgrade dir for lang pack files.
1786 * @return string HTML of available lang packs
1788 function getLangPacks($display_commit = true, $types = array('langpack'), $notice_text = '') {
1789 global $mod_strings;
1791 global $base_upgrade_dir;
1793 if(empty($notice_text)){
1794 $notice_text = $mod_strings['LBL_LANG_PACK_READY'];
1796 $ret = "<tr><td colspan=7 align=left>{$notice_text}</td></tr>";
1797 //$ret .="<table width='100%' cellpadding='0' cellspacing='0' border='0'>";
1799 <td width='20%' ><b>{$mod_strings['LBL_ML_NAME']}</b></td>
1800 <td width='15%' ><b>{$mod_strings['LBL_ML_VERSION']}</b></td>
1801 <td width='15%' ><b>{$mod_strings['LBL_ML_PUBLISHED']}</b></td>
1802 <td width='15%' ><b>{$mod_strings['LBL_ML_UNINSTALLABLE']}</b></td>
1803 <td width='20%' ><b>{$mod_strings['LBL_ML_DESCRIPTION']}</b></td>
1804 <td width='7%' ></td>
1805 <td width='1%' ></td>
1806 <td width='7%' ></td>
1810 // duh, new installs won't have the upgrade folders
1811 if(!is_dir(getcwd()."/cache/upload/upgrades")) {
1812 mkdir_recursive( "$base_upgrade_dir");
1814 $subdirs = array('full', 'langpack', 'module', 'patch', 'theme', 'temp');
1815 foreach( $subdirs as $subdir ){
1816 mkdir_recursive( "$base_upgrade_dir/$subdir" );
1819 $files = findAllFiles(getcwd()."/cache/upload/upgrades", $files);
1821 unset($_SESSION['hidden_input']);
1823 foreach($files as $file) {
1824 if(!preg_match("#.*\.zip\$#", $file)) {
1828 // skip installed lang packs
1829 if(isset($_SESSION['INSTALLED_LANG_PACKS']) && in_array($file, $_SESSION['INSTALLED_LANG_PACKS'])) {
1833 // handle manifest.php
1834 $target_manifest = remove_file_extension( $file ) . '-manifest.php';
1835 $license_file = remove_file_extension( $file ) . '-license.txt';
1836 include($target_manifest);
1839 if(!in_array(strtolower($manifest['type']), $types))
1843 $md5_matches = array();
1844 if($manifest['type'] == 'module'){
1845 $uh = new UpgradeHistory();
1846 $upgrade_content = clean_path($file);
1847 $the_base = basename($upgrade_content);
1848 $the_md5 = md5_file($upgrade_content);
1849 $md5_matches = $uh->findByMd5($the_md5);
1852 if($manifest['type']!= 'module' || 0 == sizeof($md5_matches)){
1853 $name = empty($manifest['name']) ? $file : $manifest['name'];
1854 $version = empty($manifest['version']) ? '' : $manifest['version'];
1855 $published_date = empty($manifest['published_date']) ? '' : $manifest['published_date'];
1857 $description = empty($manifest['description']) ? 'None' : $manifest['description'];
1858 $uninstallable = empty($manifest['is_uninstallable']) ? 'No' : 'Yes';
1859 $manifest_type = $manifest['type'];
1860 $commitPackage = getPackButton('commit', $target_manifest, $file, $next_step);
1861 $deletePackage = getPackButton('remove', $target_manifest, $file, $next_step);
1862 //$ret .="<table width='100%' cellpadding='0' cellspacing='0' border='0'>";
1864 $ret .= "<td width='20%' >".$name."</td>";
1865 $ret .= "<td width='15%' >".$version."</td>";
1866 $ret .= "<td width='15%' >".$published_date."</td>";
1867 $ret .= "<td width='15%' >".$uninstallable."</td>";
1868 $ret .= "<td width='20%' >".$description."</td>";
1871 $ret .= "<td width='7%'>{$commitPackage}</td>";
1872 $ret .= "<td width='1%'></td>";
1873 $ret .= "<td width='7%'>{$deletePackage}</td>";
1874 $ret .= "</td></tr>";
1876 $clean_field_name = "accept_lic_".str_replace('.', '_', urlencode(basename($file)));
1878 if(is_file($license_file)){
1880 $ret .= "<tr><td colspan=6>";
1881 $ret .= getLicenseDisplay('commit', $target_manifest, $file, $next_step, $license_file, $clean_field_name);
1882 $ret .= "</td></tr>";
1883 $hidden_input .= "<input type='hidden' name='$clean_field_name' id='$clean_field_name' value='no'>";
1885 $hidden_input .= "<input type='hidden' name='$clean_field_name' id='$clean_field_name' value='yes'>";
1889 $_SESSION['hidden_input'] = $hidden_input;
1891 if(count($files) > 0 ) {
1892 $ret .= "</tr><td colspan=7>";
1893 $ret .= "<form name='commit' action='install.php' method='POST'>
1894 <input type='hidden' name='current_step' value='{$next_step}'>
1895 <input type='hidden' name='goto' value='Re-check'>
1896 <input type='hidden' name='languagePackAction' value='commit'>
1897 <input type='hidden' name='install_type' value='custom'>
1900 $ret .= "</td></tr>";
1902 $ret .= "</tr><td colspan=7><i>{$mod_strings['LBL_LANG_NO_PACKS']}</i></td></tr>";
1907 if ( !function_exists('extractFile') ) {
1908 function extractFile( $zip_file, $file_in_zip, $base_tmp_upgrade_dir){
1909 $my_zip_dir = mk_temp_dir( $base_tmp_upgrade_dir );
1910 unzip_file( $zip_file, $file_in_zip, $my_zip_dir );
1911 return( "$my_zip_dir/$file_in_zip" );
1915 if ( !function_exists('extractManifest') ) {
1916 function extractManifest( $zip_file,$base_tmp_upgrade_dir ) {
1917 return( extractFile( $zip_file, "manifest.php",$base_tmp_upgrade_dir ) );
1921 if ( !function_exists('unlinkTempFiles') ) {
1922 function unlinkTempFiles($manifest, $zipFile) {
1923 global $sugar_config;
1925 @unlink($_FILES['language_pack']['tmp_name']);
1926 if(!empty($manifest))
1928 if(!empty($zipFile)) {
1929 //@unlink($zipFile);
1930 $tmpZipFile = substr($zipFile, strpos($zipFile, 'langpack/') + 9, strlen($zipFile));
1931 @unlink(getcwd()."/".$sugar_config['upload_dir'].$tmpZipFile);
1934 rmdir_recursive(getcwd()."/".$sugar_config['upload_dir']."upgrades/temp");
1935 sugar_mkdir(getcwd()."/".$sugar_config['upload_dir']."upgrades/temp");
1939 function langPackUnpack($unpack_type = 'langpack', $full_file = '') {
1940 global $sugar_config;
1941 global $base_upgrade_dir;
1942 global $base_tmp_upgrade_dir;
1944 $manifest = array();
1945 if(!empty($full_file)){
1946 $tempFile = $full_file;
1947 $base_filename = urldecode($tempFile);
1948 $base_filename = preg_replace( "#\\\\#", "/", $base_filename );
1949 $base_filename = basename( $base_filename );
1951 $tempFile = getcwd().'/'.$sugar_config['upload_dir'].$_FILES['language_pack']['name'];
1952 $base_filename = $_FILES['language_pack']['name'];
1954 $manifest_file = extractManifest($tempFile, $base_tmp_upgrade_dir);
1955 if($unpack_type == 'module')
1956 $license_file = extractFile($tempFile, 'LICENSE.txt', $base_tmp_upgrade_dir);
1958 if(is_file($manifest_file)) {
1960 if($unpack_type == 'module' && is_file($license_file)){
1961 copy($license_file, getcwd().'/'.$sugar_config['upload_dir'].'upgrades/'.$unpack_type.'/'.remove_file_extension($base_filename)."-license.txt");
1963 copy($manifest_file, getcwd().'/'.$sugar_config['upload_dir'].'upgrades/'.$unpack_type.'/'.remove_file_extension($base_filename)."-manifest.php");
1965 require_once( $manifest_file );
1966 validate_manifest( $manifest );
1967 $upgrade_zip_type = $manifest['type'];
1969 // exclude the bad permutations
1970 /*if($upgrade_zip_type != "langpack") {
1971 unlinkTempFiles($manifest_file, $tempFile);
1972 die( "You can only upload module packs, theme packs, and language packs on this page." );
1975 //$base_filename = urldecode( $_REQUEST['language_pack_escaped'] );
1976 $base_filename = preg_replace( "#\\\\#", "/", $base_filename );
1977 $base_filename = basename( $base_filename );
1979 mkdir_recursive( "$base_upgrade_dir/$upgrade_zip_type" );
1980 $target_path = getcwd()."/$base_upgrade_dir/$upgrade_zip_type/$base_filename";
1981 $target_manifest = remove_file_extension( $target_path ) . "-manifest.php";
1983 if( isset($manifest['icon']) && $manifest['icon'] != "" ) {
1984 $icon_location = extractFile( $tempFile, $manifest['icon'], $base_tmp_upgrade_dir );
1985 $path_parts = pathinfo( $icon_location );
1986 copy( $icon_location, remove_file_extension( $target_path ) . "-icon." . $path_parts['extension'] );
1989 // move file from cache/upload to cache/upload/langpack
1990 if( copy( $tempFile , $target_path ) ){
1991 copy( $manifest_file, $target_manifest );
1992 unlink($tempFile); // remove tempFile
1993 return "The file $base_filename has been uploaded.<br>\n";
1995 unlinkTempFiles($manifest_file, $tempFile);
1996 return "There was an error uploading the file, please try again!<br>\n";
1999 die("The zip file is missing a manifest.php file. Cannot proceed.");
2001 unlinkTempFiles($manifest_file, '');
2004 if ( !function_exists('validate_manifest') ) {
2005 function validate_manifest( $manifest ){
2006 // takes a manifest.php manifest array and validates contents
2008 global $sugar_version;
2009 global $sugar_flavor;
2010 global $mod_strings;
2012 if( !isset($manifest['type']) ){
2013 die($mod_strings['ERROR_MANIFEST_TYPE']);
2015 $type = $manifest['type'];
2016 if( getInstallType( "/$type/" ) == "" ){
2017 die($mod_strings['ERROR_PACKAGE_TYPE']. ": '" . $type . "'." );
2020 return true; // making this a bit more relaxed since we updated the language extraction and merge capabilities
2023 if( isset($manifest['acceptable_sugar_versions']) ){
2024 $version_ok = false;
2025 $matches_empty = true;
2026 if( isset($manifest['acceptable_sugar_versions']['exact_matches']) ){
2027 $matches_empty = false;
2028 foreach( $manifest['acceptable_sugar_versions']['exact_matches'] as $match ){
2029 if( $match == $sugar_version ){
2034 if( !$version_ok && isset($manifest['acceptable_sugar_versions']['regex_matches']) ){
2035 $matches_empty = false;
2036 foreach( $manifest['acceptable_sugar_versions']['regex_matches'] as $match ){
2037 if( preg_match( "/$match/", $sugar_version ) ){
2043 if( !$matches_empty && !$version_ok ){
2044 die( $mod_strings['ERROR_VERSION_INCOMPATIBLE'] . $sugar_version );
2048 if( isset($manifest['acceptable_sugar_flavors']) && sizeof($manifest['acceptable_sugar_flavors']) > 0 ){
2050 foreach( $manifest['acceptable_sugar_flavors'] as $match ){
2051 if( $match == $sugar_flavor ){
2056 //die( $mod_strings['ERROR_FLAVOR_INCOMPATIBLE'] . $sugar_flavor );
2062 if ( !function_exists('getInstallType') ) {
2063 function getInstallType( $type_string ){
2065 $subdirs = array('full', 'langpack', 'module', 'patch', 'theme', 'temp');
2066 foreach( $subdirs as $subdir ){
2067 if( preg_match( "#/$subdir/#", $type_string ) ){
2071 // return empty if no match
2078 //mysqli connector has a separate parameter for port.. We need to separate it out from the host name
2079 function getHostPortFromString($hostname=''){
2081 $pos=strpos($hostname,':');
2083 //no need to process as string is empty or does not contain ':' delimiter
2087 $hostArr = explode(':', $hostname);
2093 function getLicenseContents($filename)
2096 if(file_exists($filename) && filesize($filename) >0){
2097 $fh = sugar_fopen( $filename, 'r' ) or die( "License file not found!" );
2098 $license_file = fread( $fh, filesize( $filename ) );
2101 return $license_file;
2111 ///////////////////////////////////////////////////////////////////////////////
2112 //// FROM POPULATE SEED DATA
2114 'qa', 'dev', 'beans',
2115 'info', 'sales', 'support',
2116 'kid', 'the', 'section',
2117 'sugar', 'hr', 'im',
2118 'kid', 'vegan', 'phone',
2121 ".com", ".org", ".net", ".tv", ".cn", ".co.jp", ".us",
2122 ".edu", ".tw", ".de", ".it", ".co.uk", ".info", ".biz",
2127 * creates a random, DNS-clean webaddress
2129 function createWebAddress() {
2133 $one = $seed[rand(0, count($seed)-1)];
2134 $two = $seed[rand(0, count($seed)-1)];
2135 $tld = $tlds[rand(0, count($tlds)-1)];
2137 return "www.{$one}{$two}{$tld}";
2141 * creates a random email address
2144 function createEmailAddress() {
2148 $part[0] = $seed[rand(0, count($seed)-1)];
2149 $part[1] = $seed[rand(0, count($seed)-1)];
2150 $part[2] = $seed[rand(0, count($seed)-1)];
2152 $tld = $tlds[rand(0, count($tlds)-1)];
2157 for($i=0; $i<$len; $i++) {
2158 $ret .= (empty($ret)) ? '' : '.';
2163 $ret .= rand(10, 99);
2166 return "{$ret}@example{$tld}";
2170 function add_digits($quantity, &$string, $min = 0, $max = 9) {
2171 for($i=0; $i < $quantity; $i++) {
2172 $string .= mt_rand($min,$max);
2176 function create_phone_number() {
2178 add_digits(3, $phone);
2180 add_digits(3, $phone);
2182 add_digits(4, $phone);
2187 function create_date($year=null,$mnth=null,$day=null) {
2190 if ($mnth ==null) $mnth=date("m");
2191 if ($day==null) $day=date("d")+mt_rand(0,365);
2192 if ($year==null) $year=date("Y");
2194 $date = date($timedate->get_db_date_format(), mktime(0, 0, 0, $mnth, $day, $year));
2198 function create_current_date_time() {
2201 $time=date($timedate->get_db_date_format() . ' ' . $timedate->get_db_date_format(),mktime());
2205 function create_time($hr=null,$min=null,$sec=null) {
2207 if ($hr==null) $hr=mt_rand(6,19);
2208 if ($min==null) $min=(mt_rand(0,3)*15);
2209 if ($sec==null) $sec=0;
2211 $time=date($timedate->get_db_time_format(),mktime($hr, $min, $sec, 7, 10, 2007));
2215 function create_past_date() {
2218 $date = date($timedate->get_date_format(), mktime(0, 0, 0, date("m"), date("d")+mt_rand(-365,-1), date("Y")));
2223 * This method will look for a file modules_post_install.php in the root directory and based on the
2224 * contents of this file, it will silently install any modules as specified in this array.
2226 function post_install_modules(){
2227 if(is_file('modules_post_install.php')){
2228 global $current_user, $mod_strings;
2229 $current_user = new User();
2230 $current_user->is_admin = '1';
2231 require_once('ModuleInstall/PackageManager/PackageManager.php');
2232 require_once('modules_post_install.php');
2233 //we now have the $modules_to_install array in memory
2234 $pm = new PackageManager();
2235 $old_mod_strings = $mod_strings;
2236 foreach($modules_to_install as $module_to_install){
2237 if(is_file($module_to_install)){
2238 $pm->performSetup($module_to_install, 'module', false);
2239 $file_to_install = 'cache/upload/upgrades/module/'.basename($module_to_install);
2240 $_REQUEST['install_file'] = $file_to_install;
2241 $pm->performInstall($file_to_install);
2244 $mod_strings = $old_mod_strings;
2248 function get_help_button_url(){
2249 $help_url = 'http://www.sugarcrm.com/docs/Administration_Guides/CommunityEdition_Admin_Guide_5.0/toc.html';
2254 function create_db_user_creds($numChars=10){
2255 $numChars = 7; // number of chars in the password
2256 //chars to select from
2257 $charBKT = "abcdefghijklmnpqrstuvwxyz123456789ABCDEFGHIJKLMNPQRSTUVWXYZ";
2258 // seed the random number generator
2259 srand((double)microtime()*1000000);
2261 for ($i=0;$i<$numChars;$i++) // loop and create password
2262 $password = $password . substr ($charBKT, rand() % strlen($charBKT), 1);
2268 function addDefaultRoles($defaultRoles = array()) {
2272 foreach($defaultRoles as $roleName=>$role){
2273 $ACLField = new ACLField();
2274 $role1= new ACLRole();
2275 $role1->name = $roleName;
2276 $role1->description = $roleName." Role";
2277 $role1_id=$role1->save();
2278 foreach($role as $category=>$actions){
2279 foreach($actions as $name=>$access_override){
2280 if($name=='fields'){
2281 foreach($access_override as $field_id=>$access){
2282 $ACLField->setAccessControl($category, $role1_id, $field_id, $access);
2285 $queryACL="SELECT id FROM acl_actions where category='$category' and name='$name'";
2286 $result = $db->query($queryACL);
2287 $actionId=$db->fetchByAssoc($result);
2288 if (isset($actionId['id']) && !empty($actionId['id'])){
2289 $role1->setAction($role1_id, $actionId['id'], $access_override);
2298 * Fully enable SugarFeeds, enabling the user feed and all available modules that have SugarFeed data.
2300 function enableSugarFeeds()
2302 $admin = new Administration();
2303 $admin->saveSetting('sugarfeed','enabled','1');
2305 foreach ( SugarFeed::getAllFeedModules() as $module )
2306 SugarFeed::activateModuleFeed($module);