diff --git a/core/trunk/core/class/class_alert_engine.php b/core/trunk/core/class/class_alert_engine.php index bd2b6b80e67716465307a53aaf9da45ac6ef5f77..6ca5cf18eeaab1f4689857fa9606d7d5c5943430 100644 --- a/core/trunk/core/class/class_alert_engine.php +++ b/core/trunk/core/class/class_alert_engine.php @@ -9,7 +9,7 @@ * @license GPL * @author Laurent Giovannoni <dev@maarch.org> */ -class alert_engine extends dbquery +class alert_engine extends Database { /** * Redefinition of the alert_engine object constructor @@ -71,9 +71,11 @@ class alert_engine extends dbquery '11_11', '25_12' ); - $this->connect(); - $this->query("select * from parameters where id like 'alert_stop%'"); - while ($result = $this->fetch_object()) { + require_once 'core/class/class_db_pdo.php'; + + $db = new Database(); + $stmt = $db->query("select * from parameters where id like 'alert_stop%'"); + while ($result = $stmt->fetchObject()) { if ($result->param_value_date <> '') { $compare = $this->compare_date($result->param_value_date, date("d-m-Y")); //take the alert stop only if > now @@ -86,9 +88,9 @@ class alert_engine extends dbquery //var_dump($Hollidays); if (function_exists ('easter_date')) { - $WhenEasterCelebrates = easter_date ((int)date('Y'), $Date); + $WhenEasterCelebrates = easter_date((int)date('Y'), $Date); } else { - $WhenEasterCelebrates = $this->getEaster ((int)date('Y'), $Date); + $WhenEasterCelebrates = $this->getEaster((int)date('Y'), $Date); } $Hollidays[] = date ('j_n', $WhenEasterCelebrates); $Hollidays[] = date ('j_n', $WhenEasterCelebrates + (86400*39)); diff --git a/core/trunk/core/class/class_db_pdo.php b/core/trunk/core/class/class_db_pdo.php index a533e72753ef11bbff2a60d26dc314de667ca1fa..f1f82a549527838140206cd7c1c08d3b29e73edc 100644 --- a/core/trunk/core/class/class_db_pdo.php +++ b/core/trunk/core/class/class_db_pdo.php @@ -22,7 +22,7 @@ * * @package Core */ -class Database +class Database extends functions { /** * Prepared statements indexed by dsn and queryString @@ -49,39 +49,115 @@ class Database */ public function __construct() { - if (isset($_SESSION['config']['databaseserver'])) { - $this->server = $_SESSION['config']['databaseserver']; - } - if (isset($_SESSION['config']['databaseserverport'])) { - $this->port = $_SESSION['config']['databaseserverport']; - } - if (isset($_SESSION['config']['databaseuser'])) { - $this->user = $_SESSION['config']['databaseuser']; - } - if (isset($_SESSION['config']['databasepassword'])) { - $this->password = $_SESSION['config']['databasepassword']; - } - if (isset($_SESSION['config']['databasename'])) { - $this->database = $_SESSION['config']['databasename']; - } - if (isset($_SESSION['config']['databasetype'])) { - switch($_SESSION['config']['databasetype']) { - case 'POSTGRESQL': - $this->driver = 'pgsql'; - break; - case 'MYSQL': - $this->driver = 'mysql'; - break; + $args = func_get_args(); + if (count($args) < 1) { + if (isset($_SESSION['config']['databaseserver'])) { + $this->server = $_SESSION['config']['databaseserver']; + } + if (isset($_SESSION['config']['databaseserverport'])) { + $this->port = $_SESSION['config']['databaseserverport']; + } + if (isset($_SESSION['config']['databaseuser'])) { + $this->user = $_SESSION['config']['databaseuser']; + } + if (isset($_SESSION['config']['databasepassword'])) { + $this->password = $_SESSION['config']['databasepassword']; + } + if (isset($_SESSION['config']['databasename'])) { + $this->database = $_SESSION['config']['databasename']; + } + if (isset($_SESSION['config']['databasetype'])) { + switch($_SESSION['config']['databasetype']) { + case 'POSTGRESQL': + $this->driver = 'pgsql'; + break; + case 'MYSQL': + $this->driver = 'mysql'; + break; + + case 'ORACLE': + $this->driver = 'oci'; + break; + + default: + print_r('DRIVER ERROR: Unknown database driver ' + . $_SESSION['config']['databasetype']); + } + } + } else { + $errorArgs = true; + if (is_array($args[0])) { + if (!isset($args[0]['server'])) { + $this->server = '127.0.0.1'; + } else { + $this->server = $args[0]['server']; + } + switch($args[0]['databasetype']) { + case 'POSTGRESQL': + $this->driver = 'pgsql'; + break; + case 'MYSQL': + $this->driver = 'mysql'; + break; - case 'ORACLE': - $this->driver = 'oci'; - break; + case 'ORACLE': + $this->driver = 'oci'; + break; - default: - print_r('DRIVER ERROR: Unknown database driver ' . $_SESSION['config']['databasetype']); + default: + print_r('DRIVER ERROR: Unknown database driver ' + . $_SESSION['config']['databasetype']); + } + if (!isset($args[0]['port'])) { + $this->port = '5432'; + } else { + $this->port = $args[0]['port']; + } + if (!isset($args[0]['user'])) { + $this->user = 'postgres'; + } else { + $this->user = $args[0]['user']; + } + if (!isset($args[0]['password'])) { + $this->password = 'postgres'; + } else { + $this->password = $args[0]['pass']; + } + if (! isset($args[0]['base'])) { + $this->database = ''; + } else { + $this->database = $args[0]['base']; + } + $errorArgs = false; + } else if (is_string($args[0]) && file_exists($args[0])) { + $xmlconfig = simplexml_load_file($args[0]); + $config = $xmlconfig->CONFIG_BASE; + $this->server = (string) $config->databaseserver; + $this->port = (string) $config->databaseserverport; + $this->driver = (string) $config->databasetype; + switch($this->driver) { + case 'POSTGRESQL': + $this->driver = 'pgsql'; + break; + case 'MYSQL': + $this->driver = 'mysql'; + break; + + case 'ORACLE': + $this->driver = 'oci'; + break; + + default: + print_r('DRIVER ERROR: Unknown database driver ' + . $_SESSION['config']['databasetype']); + } + $this->database = (string) $config->databasename; + $this->user = (string) $config->databaseuser; + $this->password = (string) $config->databasepassword; + $errorArgs = false; } } - + // Set DSN $this->dsn = $this->driver . ':host=' . $this->server