[ Index ]

PHP Cross Reference of vtigercrm-6.1.0

title

Body

[close]

/modules/Install/models/ -> Utils.php (source)

   1  <?php
   2  /* +***********************************************************************************
   3   * The contents of this file are subject to the vtiger CRM Public License Version 1.0
   4   * ("License"); You may not use this file except in compliance with the License
   5   * The Original Code is:  vtiger CRM Open Source
   6   * The Initial Developer of the Original Code is vtiger.
   7   * Portions created by vtiger are Copyright (C) vtiger.
   8   * All Rights Reserved.
   9   * *********************************************************************************** */
  10  
  11  class Install_Utils_Model {
  12  
  13      /**
  14       * variable has all the files and folder that should be writable
  15       * @var <Array>
  16       */
  17      public static $writableFilesAndFolders = array (
  18          'Configuration File' => './config.inc.php',
  19          'Tabdata File' => './tabdata.php',
  20          'Parent Tabdata File' => './parent_tabdata.php',
  21          'Cache Directory' => './cache/',
  22          'Image Cache Directory' => './cache/images/',
  23          'Import Cache Directory' => './cache/import/',
  24          'Storage Directory' => './storage/',
  25          'User Privileges Directory' => './user_privileges/',
  26          'Modules Directory' => './modules/',
  27          'Cron Modules Directory' => './cron/modules/',
  28          'Vtlib Test Directory' => './test/vtlib/',
  29          'Vtlib Test HTML Directory' => './test/vtlib/HTML',
  30          'Mail Merge Template Directory' => './test/wordtemplatedownload/',
  31          'Product Image Directory' => './test/product/',
  32          'User Image Directory' => './test/user/',
  33          'Contact Image Directory' => './test/contact/',
  34          'Logo Directory' => './test/logo/',
  35          'Logs Directory' => './logs/',
  36      );
  37  
  38      /**
  39       * Function returns all the files and folder that are not writable
  40       * @return <Array>
  41       */
  42  	public static function getFailedPermissionsFiles() {
  43          $writableFilesAndFolders = self::$writableFilesAndFolders;
  44          $failedPermissions = array();
  45          require_once  ('include/utils/VtlibUtils.php');
  46          foreach ($writableFilesAndFolders as $index => $value) {
  47              if (!vtlib_isWriteable($value)) {
  48                  $failedPermissions[$index] = $value;
  49              }
  50          }
  51          return $failedPermissions;
  52      }
  53  
  54      /**
  55       * Function returns the php.ini file settings required for installing vtigerCRM
  56       * @return <Array>
  57       */
  58  	static function getCurrentDirectiveValue() {
  59          $directiveValues = array();
  60          if (ini_get('safe_mode') == '1' || stripos(ini_get('safe_mode'), 'On') > -1)
  61              $directiveValues['safe_mode'] = 'On';
  62          if (ini_get('display_errors') != '1' || stripos(ini_get('display_errors'), 'Off') > -1)
  63              $directiveValues['display_errors'] = 'Off';
  64          if (ini_get('file_uploads') != '1' || stripos(ini_get('file_uploads'), 'Off') > -1)
  65              $directiveValues['file_uploads'] = 'Off';
  66          if (ini_get('register_globals') == '1' || stripos(ini_get('register_globals'), 'On') > -1)
  67              $directiveValues['register_globals'] = 'On';
  68          if (ini_get(('output_buffering') < '4096' && ini_get('output_buffering') != '0') || stripos(ini_get('output_buffering'), 'Off') > -1)
  69              $directiveValues['output_buffering'] = 'Off';
  70          if (ini_get('max_execution_time') < 600)
  71              $directiveValues['max_execution_time'] = ini_get('max_execution_time');
  72          if (ini_get('memory_limit') < 32)
  73              $directiveValues['memory_limit'] = ini_get('memory_limit');
  74          $errorReportingValue = E_WARNING & ~E_NOTICE;
  75                  if(version_compare(PHP_VERSION, '5.5.0') >= 0){
  76                      $errorReportingValue = E_WARNING & ~E_NOTICE & ~E_DEPRECATED & ~E_STRICT;
  77                  }
  78                  else if(version_compare(PHP_VERSION, '5.3.0') >= 0) {
  79              $errorReportingValue = E_WARNING & ~E_NOTICE & ~E_DEPRECATED;
  80          }
  81          if (ini_get('error_reporting') != $errorReportingValue)
  82              $directiveValues['error_reporting'] = 'NOT RECOMMENDED';
  83          if (ini_get('log_errors') == '1' || stripos(ini_get('log_errors'), 'On') > -1)
  84              $directiveValues['log_errors'] = 'On';
  85          if (ini_get('short_open_tag') != '1' || stripos(ini_get('short_open_tag'), 'Off') > -1)
  86              $directiveValues['short_open_tag'] = 'Off';
  87  
  88          return $directiveValues;
  89      }
  90  
  91      /**
  92       * Variable has the recommended php settings for smooth running of vtigerCRM
  93       * @var <Array>
  94       */
  95      public static $recommendedDirectives = array (
  96          'safe_mode' => 'Off',
  97          'display_errors' => 'On',
  98          'file_uploads' => 'On',
  99          'register_globals' => 'On',
 100          'output_buffering' => 'On',
 101          'max_execution_time' => '600',
 102          'memory_limit' => '32',
 103          'error_reporting' => 'E_WARNING & ~E_NOTICE',
 104          'log_errors' => 'Off',
 105          'short_open_tag' => 'On'
 106      );
 107  
 108      /**
 109       * Returns the recommended php settings for vtigerCRM
 110       * @return type
 111       */
 112  	function getRecommendedDirectives(){
 113              if(version_compare(PHP_VERSION, '5.5.0') >= 0){
 114                  self::$recommendedDirectives['error_reporting'] = 'E_WARNING & ~E_NOTICE & ~E_DEPRECATED & ~E_STRICT';
 115              }
 116          else if(version_compare(PHP_VERSION, '5.3.0') >= 0) {
 117              self::$recommendedDirectives['error_reporting'] = 'E_WARNING & ~E_NOTICE & ~E_DEPRECATED';
 118          }
 119          return self::$recommendedDirectives;
 120      }
 121  
 122      /**
 123       * Function checks for vtigerCRM installation prerequisites
 124       * @return <Array>
 125       */
 126  	function getSystemPreInstallParameters() {
 127          $preInstallConfig = array();
 128          // Name => array( System Value, Recommended value, supported or not(true/false) );
 129          $preInstallConfig['LBL_PHP_VERSION']    = array(phpversion(), '5.3.0', (version_compare(phpversion(), '5.3.0', '>=')));
 130          $preInstallConfig['LBL_IMAP_SUPPORT']    = array(function_exists('imap_open'), true, (function_exists('imap_open') == true));
 131          $preInstallConfig['LBL_ZLIB_SUPPORT']    = array(function_exists('gzinflate'), true, (function_exists('gzinflate') == true));
 132                  if ($preInstallConfig['LBL_PHP_VERSION'] >= '5.5.0') {
 133                      $preInstallConfig['LBL_MYSQLI_CONNECT_SUPPORT'] = array(extension_loaded('mysqli'), true, extension_loaded('mysqli'));
 134                  }
 135                  $preInstallConfig['LBL_OPEN_SSL'] = array(extension_loaded('openssl'), true, extension_loaded('openssl'));
 136                  $preInstallConfig['LBL_CURL'] = array(extension_loaded('curl'), true, extension_loaded('curl'));
 137                  $gnInstalled = false;
 138          if(!function_exists('gd_info')) {
 139              eval(self::$gdInfoAlternate);
 140          }
 141          $gd_info = gd_info();
 142          if (isset($gd_info['GD Version'])) {
 143              $gnInstalled = true;
 144          }
 145          $preInstallConfig['LBL_GD_LIBRARY']        = array((extension_loaded('gd') || $gnInstalled), true, (extension_loaded('gd') || $gnInstalled));
 146          $preInstallConfig['LBL_ZLIB_SUPPORT']    = array(function_exists('gzinflate'), true, (function_exists('gzinflate') == true));
 147  
 148          return $preInstallConfig;
 149      }
 150      
 151      /**
 152       * Function that provides default configuration based on installer setup
 153       * @return <Array>
 154       */
 155  	function getDefaultPreInstallParameters() {
 156          include  'config.db.php';
 157          
 158          $parameters = array(
 159              'db_hostname' => '',
 160              'db_username' => '',
 161              'db_password' => '',
 162              'db_name'     => '',
 163              'admin_name'  => 'admin',
 164              'admin_lastname'=> 'Administrator',
 165              'admin_password'=>'',
 166              'admin_email' => '',
 167          );
 168          
 169          if (isset($dbconfig) && isset($vtconfig)) {
 170              if (isset($dbconfig['db_server']) && $dbconfig['db_server'] != '_DBC_SERVER_') {
 171                  $parameters['db_hostname'] = $dbconfig['db_server'] . ':' . $dbconfig['db_port'];
 172                  $parameters['db_username'] = $dbconfig['db_username'];
 173                  $parameters['db_password'] = $dbconfig['db_password'];
 174                  $parameters['db_name']     = $dbconfig['db_name'];
 175                  
 176                  $parameters['admin_password'] = $vtconfig['adminPwd'];
 177                  $parameters['admin_email']    = $vtconfig['adminEmail'];
 178              }
 179          }
 180          
 181          return $parameters;
 182      }
 183  
 184      /**
 185       * Function returns gd library information
 186       * @var type
 187       */
 188      public static $gdInfoAlternate = 'function gd_info() {
 189          $array = Array(
 190                     "GD Version" => "",
 191                     "FreeType Support" => 0,
 192                     "FreeType Support" => 0,
 193                     "FreeType Linkage" => "",
 194                     "T1Lib Support" => 0,
 195                     "GIF Read Support" => 0,
 196                     "GIF Create Support" => 0,
 197                     "JPG Support" => 0,
 198                     "PNG Support" => 0,
 199                     "WBMP Support" => 0,
 200                     "XBM Support" => 0
 201                   );
 202                 $gif_support = 0;
 203  
 204                 ob_start();
 205                 eval("phpinfo();");
 206                 $info = ob_get_contents();
 207                 ob_end_clean();
 208  
 209                 foreach(explode("\n", $info) as $line) {
 210                     if(strpos($line, "GD Version")!==false)
 211                         $array["GD Version"] = trim(str_replace("GD Version", "", strip_tags($line)));
 212                     if(strpos($line, "FreeType Support")!==false)
 213                         $array["FreeType Support"] = trim(str_replace("FreeType Support", "", strip_tags($line)));
 214                     if(strpos($line, "FreeType Linkage")!==false)
 215                         $array["FreeType Linkage"] = trim(str_replace("FreeType Linkage", "", strip_tags($line)));
 216                     if(strpos($line, "T1Lib Support")!==false)
 217                         $array["T1Lib Support"] = trim(str_replace("T1Lib Support", "", strip_tags($line)));
 218                     if(strpos($line, "GIF Read Support")!==false)
 219                         $array["GIF Read Support"] = trim(str_replace("GIF Read Support", "", strip_tags($line)));
 220                     if(strpos($line, "GIF Create Support")!==false)
 221                         $array["GIF Create Support"] = trim(str_replace("GIF Create Support", "", strip_tags($line)));
 222                     if(strpos($line, "GIF Support")!==false)
 223                         $gif_support = trim(str_replace("GIF Support", "", strip_tags($line)));
 224                     if(strpos($line, "JPG Support")!==false)
 225                         $array["JPG Support"] = trim(str_replace("JPG Support", "", strip_tags($line)));
 226                     if(strpos($line, "PNG Support")!==false)
 227                         $array["PNG Support"] = trim(str_replace("PNG Support", "", strip_tags($line)));
 228                     if(strpos($line, "WBMP Support")!==false)
 229                         $array["WBMP Support"] = trim(str_replace("WBMP Support", "", strip_tags($line)));
 230                     if(strpos($line, "XBM Support")!==false)
 231                         $array["XBM Support"] = trim(str_replace("XBM Support", "", strip_tags($line)));
 232                 }
 233  
 234                 if($gif_support==="enabled") {
 235                     $array["GIF Read Support"]  = 1;
 236                     $array["GIF Create Support"] = 1;
 237                 }
 238  
 239                 if($array["FreeType Support"]==="enabled"){
 240                     $array["FreeType Support"] = 1;    }
 241  
 242                 if($array["T1Lib Support"]==="enabled")
 243                     $array["T1Lib Support"] = 1;
 244  
 245                 if($array["GIF Read Support"]==="enabled"){
 246                     $array["GIF Read Support"] = 1;    }
 247  
 248                 if($array["GIF Create Support"]==="enabled")
 249                     $array["GIF Create Support"] = 1;
 250  
 251                 if($array["JPG Support"]==="enabled")
 252                     $array["JPG Support"] = 1;
 253  
 254                 if($array["PNG Support"]==="enabled")
 255                     $array["PNG Support"] = 1;
 256  
 257                 if($array["WBMP Support"]==="enabled")
 258                     $array["WBMP Support"] = 1;
 259  
 260                 if($array["XBM Support"]==="enabled")
 261                     $array["XBM Support"] = 1;
 262  
 263                 return $array;
 264  
 265          }';
 266  
 267      /**
 268       * Returns list of currencies
 269       * @return <Array>
 270       */
 271  	public static function getCurrencyList() {
 272          require_once  'modules/Utilities/Currencies.php';
 273          return $currencies;
 274      }
 275  
 276      /**
 277       * Function checks if its mysql type
 278       * @param type $dbType
 279       * @return type
 280       */
 281  	static function isMySQL($dbType) {
 282          return (stripos($dbType ,'mysql') === 0);
 283      }
 284  
 285      /**
 286       * Function returns mysql version
 287       * @param type $serverInfo
 288       * @return type
 289       */
 290  	public static function getMySQLVersion($serverInfo) {
 291          if(!is_array($serverInfo)) {
 292              $version = explode('-',$serverInfo);
 293              $mysql_server_version=$version[0];
 294          } else {
 295              $mysql_server_version = $serverInfo['version'];
 296          }
 297          return $mysql_server_version;
 298      }
 299  
 300      /**
 301       * Function checks the database connection
 302       * @param <String> $db_type
 303       * @param <String> $db_hostname
 304       * @param <String> $db_username
 305       * @param <String> $db_password
 306       * @param <String> $db_name
 307       * @param <String> $create_db
 308       * @param <String> $create_utf8_db
 309       * @param <String> $root_user
 310       * @param <String> $root_password
 311       * @return <Array>
 312       */
 313  	public static function checkDbConnection($db_type, $db_hostname, $db_username, $db_password, $db_name, $create_db=false, $create_utf8_db=true, $root_user='', $root_password='') {
 314          $dbCheckResult = array();
 315  
 316          $db_type_status = false; // is there a db type?
 317          $db_server_status = false; // does the db server connection exist?
 318          $db_creation_failed = false; // did we try to create a database and fail?
 319          $db_exist_status = false; // does the database exist?
 320          $db_utf8_support = false; // does the database support utf8?
 321  
 322          //Checking for database connection parameters
 323          if($db_type) {
 324              $conn = &NewADOConnection($db_type);
 325              $db_type_status = true;
 326              if(@$conn->Connect($db_hostname,$db_username,$db_password)) {
 327                  $db_server_status = true;
 328                  $serverInfo = $conn->ServerInfo();
 329                  if(self::isMySQL($db_type)) {
 330                      $mysql_server_version = self::getMySQLVersion($serverInfo);
 331                  }
 332                  if($create_db) {
 333                      // drop the current database if it exists
 334                      $dropdb_conn = &NewADOConnection($db_type);
 335                      if(@$dropdb_conn->Connect($db_hostname, $root_user, $root_password, $db_name)) {
 336                          $query = "DROP DATABASE ".$db_name;
 337                          $dropdb_conn->Execute($query);
 338                          $dropdb_conn->Close();
 339                      }
 340  
 341                      // create the new database
 342                      $db_creation_failed = true;
 343                      $createdb_conn = &NewADOConnection($db_type);
 344                      if(@$createdb_conn->Connect($db_hostname, $root_user, $root_password)) {
 345                          $query = "CREATE DATABASE ".$db_name;
 346                          if($create_utf8_db == 'true') {
 347                              if(self::isMySQL($db_type))
 348                                  $query .= " DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_general_ci";
 349                              $db_utf8_support = true;
 350                          }
 351                          if($createdb_conn->Execute($query)) {
 352                              $db_creation_failed = false;
 353                          }
 354                          $createdb_conn->Close();
 355                      }
 356                  }
 357  
 358                  if(@$conn->Connect($db_hostname, $db_username, $db_password, $db_name)) {
 359                      $db_exist_status = true;
 360                      if(!$db_utf8_support) {
 361                          $db_utf8_support = Vtiger_Util_Helper::checkDbUTF8Support($conn);
 362                      }
 363                  }
 364                  $conn->Close();
 365              }
 366          }
 367          $dbCheckResult['db_utf8_support'] = $db_utf8_support;
 368  
 369          $error_msg = '';
 370          $error_msg_info = '';
 371  
 372          if(!$db_type_status || !$db_server_status) {
 373              $error_msg = getTranslatedString('ERR_DATABASE_CONNECTION_FAILED', 'Install').'. '.getTranslatedString('ERR_INVALID_MYSQL_PARAMETERS', 'Install');
 374              $error_msg_info = getTranslatedString('MSG_LIST_REASONS', 'Install').':<br>
 375                      -  '.getTranslatedString('MSG_DB_PARAMETERS_INVALID', 'Install').'
 376                      -  '.getTranslatedString('MSG_DB_USER_NOT_AUTHORIZED', 'Install');
 377          } elseif(self::isMySQL($db_type) && $mysql_server_version < 4.1) {
 378              $error_msg = $mysql_server_version.' -> '.getTranslatedString('ERR_INVALID_MYSQL_VERSION', 'Install');
 379          } elseif($db_creation_failed) {
 380              $error_msg = getTranslatedString('ERR_UNABLE_CREATE_DATABASE', 'Install').' '.$db_name;
 381              $error_msg_info = getTranslatedString('MSG_DB_ROOT_USER_NOT_AUTHORIZED', 'Install');
 382          } elseif(!$db_exist_status) {
 383              $error_msg = $db_name.' -> '.getTranslatedString('ERR_DB_NOT_FOUND', 'Install');
 384          } else {
 385              $dbCheckResult['flag'] = true;
 386              return $dbCheckResult;
 387          }
 388          $dbCheckResult['flag'] = false;
 389          $dbCheckResult['error_msg'] = $error_msg;
 390          $dbCheckResult['error_msg_info'] = $error_msg_info;
 391          return $dbCheckResult;
 392      }
 393  
 394      /**
 395       * Function installs all the available modules
 396       */
 397  	public static function installModules() {
 398          require_once ('vtlib/Vtiger/Package.php');
 399          require_once ('vtlib/Vtiger/Module.php');
 400          require_once ('include/utils/utils.php');
 401  
 402          $moduleFolders = array('packages/vtiger/mandatory', 'packages/vtiger/optional');
 403          foreach($moduleFolders as $moduleFolder) {
 404              if ($handle = opendir($moduleFolder)) {
 405                  while (false !== ($file = readdir($handle))) {
 406                      $packageNameParts = explode(".",$file);
 407                      if($packageNameParts[count($packageNameParts)-1] != 'zip'){
 408                          continue;
 409                      }
 410                      array_pop($packageNameParts);
 411                      $packageName = implode("",$packageNameParts);
 412                      if (!empty($packageName)) {
 413                          $packagepath = "$moduleFolder/$file";
 414                          $package = new Vtiger_Package();
 415                          $module = $package->getModuleNameFromZip($packagepath);
 416                          if($module != null) {
 417                              $moduleInstance = Vtiger_Module::getInstance($module);
 418                              if($moduleInstance) {
 419                                  updateVtlibModule($module, $packagepath);
 420                              } else {
 421                                  installVtlibModule($module, $packagepath);
 422                              }
 423                          }
 424                      }
 425                  }
 426                  closedir($handle);
 427              }
 428          }
 429      }
 430  }


Generated: Fri Nov 28 20:08:37 2014 Cross-referenced by PHPXref 0.7.1