From 2a4c9a8eb2a445259af20aca85c17f89a2de1fe9 Mon Sep 17 00:00:00 2001 From: tbrehm <t.brehm@ispconfig.org> Date: Tue, 18 Dec 2012 06:15:49 -0500 Subject: [PATCH] Merged language files. --- server/lib/classes/db_mysql.inc.php | 72 ++++++++++++++++++++--------------- 1 files changed, 41 insertions(+), 31 deletions(-) diff --git a/server/lib/classes/db_mysql.inc.php b/server/lib/classes/db_mysql.inc.php index 27a62bd..4c75e62 100644 --- a/server/lib/classes/db_mysql.inc.php +++ b/server/lib/classes/db_mysql.inc.php @@ -1,4 +1,3 @@ - <?php /* Copyright (c) 2005, Till Brehm, projektfarm Gmbh @@ -30,7 +29,7 @@ class db extends mysqli { - private $dbHost = ''; // hostname of the MySQL server + protected $dbHost = ''; // hostname of the MySQL server private $dbName = ''; // logical database name on that server private $dbUser = ''; // database authorized user private $dbPass = ''; // user's password @@ -42,34 +41,39 @@ private $record = array(); // last record fetched private $autoCommit = 1; // Autocommit Transactions private $currentRow; // current row number - private $errorNumber = 0; // last error number + public $errorNumber = 0; // last error number public $errorMessage = ''; // last error message private $errorLocation = '';// last error location public $show_error_messages = false; // false in server, true in interface // constructor - public function __construct() { - global $conf; - $this->dbHost = $conf['db_host']; - $this->dbName = $conf['db_database']; - $this->dbUser = $conf['db_user']; - $this->dbPass = $conf['db_password']; + public function __construct($host = NULL , $user = NULL, $pass = NULL, $database = NULL) { + global $app, $conf; + + $this->dbHost = $host ? $host : $conf['db_host']; + $this->dbName = $database ? $database : $conf['db_database']; + $this->dbUser = $user ? $user : $conf['db_user']; + $this->dbPass = $pass ? $pass : $conf['db_password']; $this->dbCharset = $conf['db_charset']; $this->dbNewLink = $conf['db_new_link']; $this->dbClientFlags = $conf['db_client_flags']; - parent::__construct($conf['db_host'], $conf['db_user'],$conf['db_password'],$conf['db_database']); + + parent::__construct($this->dbHost, $this->dbUser, $this->dbPass,$this->dbName); if ($this->connect_error) { $this->updateError('DB::__construct'); - return false; } parent::query( 'SET NAMES '.$this->dbCharset); parent::query( "SET character_set_results = '".$this->dbCharset."', character_set_client = '".$this->dbCharset."', character_set_connection = '".$this->dbCharset."', character_set_database = '".$this->dbCharset."', character_set_server = '".$this->dbCharset."'"); - } public function __destruct() { $this->close(); // helps avoid memory leaks, and persitent connections that don't go away. } + + /* This allows our private variables to be "read" out side of the class */ + public function __get($var) { + return isset($this->$var) ? $this->$var : NULL; + } // error handler public function updateError($location) { @@ -89,14 +93,18 @@ // This right here will allow us to use the samefile for server & interface if($this->show_error_messages) { echo $error_msg; - } else if(method_exists($app, 'log')) { + } else if(is_object($app) && method_exists($app, 'log')) { $app->log($error_msg, LOGLEVEL_WARN); + } else { + /* This could be called before $app is ever declared.. In that case we should just spit out to error_log() */ + error_log($error_msg); } } } public function query($queryString) { - $this->queryId = parent::query($queryString); + parent::ping(); + $this->queryId = parent::query($queryString); $this->updateError('DB::query('.$queryString.') -> mysqli_query'); if(!$this->queryId) { return false; @@ -218,10 +226,10 @@ if(is_array($record_old) && count($record_old) > 0) { foreach($record_old as $key => $val) { // if(!isset($record_new[$key]) || $record_new[$key] != $val) { - if($record_new[$key] != $val) { + if(@$record_new[$key] != $val) { // Record has changed $diffrec_full['old'][$key] = $val; - $diffrec_full['new'][$key] = $record_new[$key]; + $diffrec_full['new'][$key] = @$record_new[$key]; $diff_num++; } else { $diffrec_full['old'][$key] = $val; @@ -245,8 +253,8 @@ return array('diff_num' => $diff_num, 'diff_rec' => $diffrec_full); } - - //** Function to fill the datalog with a full differential record. + + //** Function to fill the datalog with a full differential record. public function datalogSave($db_table, $action, $primary_field, $primary_id, $record_old, $record_new) { global $app,$conf; @@ -267,19 +275,21 @@ if(isset($record_new['server_id'])) $server_id = $record_new['server_id']; - if($diff_num > 0) { - //print_r($diff_num); - //print_r($diffrec_full); - $diffstr = $app->db->quote(serialize($diffrec_full)); - $username = $app->db->quote($_SESSION['s']['user']['username']); - $dbidx = $primary_field.':'.$primary_id; + if($diff_num > 0) { + $diffstr = $this->quote(serialize($diffrec_full)); + if(isset($_SESSION)) { + $username = $this->quote($_SESSION['s']['user']['username']); + } else { + $username = 'admin'; + } + $dbidx = $primary_field.':'.$primary_id; - if($action == 'INSERT') $action = 'i'; - if($action == 'UPDATE') $action = 'u'; - if($action == 'DELETE') $action = 'd'; - $sql = "INSERT INTO sys_datalog (dbtable,dbidx,server_id,action,tstamp,user,data) VALUES ('".$db_table."','$dbidx','$server_id','$action','".time()."','$username','$diffstr')"; - $app->db->query($sql); - } + if($action == 'INSERT') $action = 'i'; + if($action == 'UPDATE') $action = 'u'; + if($action == 'DELETE') $action = 'd'; + $sql = "INSERT INTO sys_datalog (dbtable,dbidx,server_id,action,tstamp,user,data) VALUES ('".$db_table."','$dbidx','$server_id','$action','".time()."','$username','$diffstr')"; + $this->query($sql); + } return true; } @@ -583,4 +593,4 @@ } - ?> + ?> \ No newline at end of file -- Gitblit v1.9.1