1   <?php
  2           
  3           /*
  4           *       $tool_db                - connection to in-portal database
  5           *       TABLE_PREFIX    - prefix for each table in that db
  6           *       BASE_PATH               - path to in-portal root directory
  7           */
  8           
  9           // all things tool need to survive
  10           define('CONFIG_FILE','../config.php');
  11           
  12           require_once '../kernel/include/db.class.php';
  13           
  14           // get db connection information from config
  15           $db_info=Array();
  16           $file=file(CONFIG_FILE);
  17           foreach($file as $line)
  18           {
  19                   if( substr($line,0,2) == 'DB' )
  20                   {
  21                           preg_match('/(.*) = "(.*)"/',$line,$rets);
  22                           $db_info[$rets[1]]=$rets[2];
  23                   }
  24                   elseif( substr($line,0,5) == 'Table' )
  25                   {
  26                           preg_match('/(.*) = "(.*)"/',$line,$rets);
  27                           define('TABLE_PREFIX',$rets[2]);
  28                   }
  29           }
  30           
  31           // connect to in-portal database
  32           $tool_db=new DBConnection($db_info['DBType']);
  33           $tool_db->Connect($db_info['DBHost'],$db_info['DBUser'],$db_info['DBUserPassword'],$db_info['DBName']);
  34           
  35           $sub_folder=$tool_db->GetOne('SELECT VariableValue FROM '.TABLE_PREFIX.'ConfigurationValues WHERE VariableName=\'Site_Path\'');
  36           define('BASE_PATH', $_SERVER['DOCUMENT_ROOT'].rtrim($sub_folder,'/'));
  37           unset($sub_folder);
  38           
  39           /**
  40            * Same as print_r, but for html pages
  41            *
  42            * @param string $s
  43            * @param bool $returnResult
  44            * @return string
  45            * @access public
  46            */
  47           function tool_printPre($s,$returnResult=false)
  48           {
  49                   $ret='<pre>'.print_r($s,true).'</pre>';
  50                   if($returnResult) return $ret;
  51                   echo $ret;
  52           }
  53  
  54   ?>