[Hastymail-cvs] SF.net SVN: hastymail:[2147] trunk/hastymail2
Brought to you by:
sailfrog,
slushpupie
From: <ben...@us...> - 2013-02-03 08:42:02
|
Revision: 2147 http://hastymail.svn.sourceforge.net/hastymail/?rev=2147&view=rev Author: benthepoet Date: 2013-02-03 08:41:54 +0000 (Sun, 03 Feb 2013) Log Message: ----------- Added: Renamed the old db.php to db_pear.php for legacy support. The new db.php uses PDO. Added: Generic is_error functions for the db libraries and a limit function. Added: SQL scripts for both SQLite and Firebird. Updated: Modified pear_type config option to now be db_adapter in the example config file. Updated: utility_classes.php now loads the appropriate db file based on which adapter is selected. Updated: Added date formatting for calendar plugin, this was necessary for cross db compatibility (doesn't break the old db code). Fixed: Found a bug with the 'This Week' link in calendar plugin. On any calendar page that isn't month-level or lower this was getting the wrong week because the first_week_day variable defaulted to false and never got set in these cases. Set the default to be the current date. Modified Paths: -------------- trunk/hastymail2/db/db.php trunk/hastymail2/hastymail2.conf.example trunk/hastymail2/lib/utility_classes.php trunk/hastymail2/plugins/calendar/cal_include.php trunk/hastymail2/plugins/calendar/page.php Added Paths: ----------- trunk/hastymail2/db/contacts.firebird.sql trunk/hastymail2/db/contacts.sqlite.sql trunk/hastymail2/db/db_pear.php trunk/hastymail2/db/user_setting.firebird.sql trunk/hastymail2/db/user_setting.sqlite.sql trunk/hastymail2/plugins/calendar/calendar.firebird.sql trunk/hastymail2/plugins/calendar/calendar.sqlite.sql trunk/hastymail2/plugins/logger/log.firebird.sql trunk/hastymail2/plugins/logger/log.sqlite.sql trunk/hastymail2/plugins/login_alias/login_alias_table.firebird.sql trunk/hastymail2/plugins/login_alias/login_alias_table.sqlite.sql Added: trunk/hastymail2/db/contacts.firebird.sql =================================================================== --- trunk/hastymail2/db/contacts.firebird.sql (rev 0) +++ trunk/hastymail2/db/contacts.firebird.sql 2013-02-03 08:41:54 UTC (rev 2147) @@ -0,0 +1,27 @@ +CREATE TABLE CONTACTS +( + ID integer PRIMARY KEY NOT NULL, + USERNAME varchar(250), + CONTACTS blob sub_type 1 +); + +CREATE GENERATOR GEN_CONTACTS_ID; + +SET TERM ^ ; +CREATE TRIGGER CONTACTS_BI FOR CONTACTS ACTIVE +BEFORE INSERT POSITION 0 +as +declare variable tmp decimal(18,0); +begin + if (new.id is null) then + new.id = gen_id(gen_contacts_id, 1); + else + begin + tmp = gen_id(gen_contacts_id, 0); + if (tmp < new.id) then + tmp = gen_id(gen_contacts_id, new.id-tmp); + end +end^ +SET TERM ; ^ + + Added: trunk/hastymail2/db/contacts.sqlite.sql =================================================================== --- trunk/hastymail2/db/contacts.sqlite.sql (rev 0) +++ trunk/hastymail2/db/contacts.sqlite.sql 2013-02-03 08:41:54 UTC (rev 2147) @@ -0,0 +1,5 @@ +CREATE TABLE contacts ( + id integer primary key autoincrement not null, + username varchar(250), + contacts text +); Modified: trunk/hastymail2/db/db.php =================================================================== --- trunk/hastymail2/db/db.php 2013-01-17 14:55:02 UTC (rev 2146) +++ trunk/hastymail2/db/db.php 2013-02-03 08:41:54 UTC (rev 2147) @@ -30,19 +30,21 @@ function add_read_server($user, $pass, $host, $db) { $this->read_servers[] = array($user, $pass, $host, $db); } + function build_dsn($host, $db) { + if ($this->db_type == 'sqlite') { + $dsn = $this->db_type.':'.$db; + } + else { + $dsn = $this->db_type.':dbname='.$db.';host='.$host; + } + return $dsn; + } function connect() { global $user; global $db_include_path; - if ($this->pear_type == 'MDB2') { - require_once($db_include_path.'MDB2.php'); - $this->mode = 'MDB2'; - $this->fetch_mode = MDB2_FETCHMODE_ASSOC; - } - else { - require_once($db_include_path.'DB.php'); - $this->mode = 'DB'; - $this->fetch_mode = DB_FETCHMODE_ASSOC; - } + + $this->fetch_mode = PDO::FETCH_ASSOC; + if ($this->db_split) { $this->debug[] = 'configuration: db_split is set to true, both read and write servers required'; } @@ -69,24 +71,26 @@ shuffle($this->read_servers); } foreach ($this->read_servers as $v) { - $dsn = $this->db_type.'://'.$v[0].':'.$v[1].'@'.$v[2].'/'.$v[3]; - if ($this->pear_type == 'MDB2') { - $db_read =& MDB2::Connect($dsn, array('persistent' => $this->persistent)); + $dsn = $this->build_dsn($v[2], $v[3]); + + try { + $db_read = new PDO($dsn, $v[0], $v[1]); + $db_read->setAttribute(PDO::ATTR_CASE, PDO::CASE_LOWER); + } catch (PDOException $e) { + $db_read = $e; } - else { - $db_read = DB::Connect($dsn, $this->persistent); - } + $this->db_read = $db_read; - if (PEAR::isError($this->db_read) || !($this->db_read)) { - $this->debug[] = 'connecting: UNABLE TO CONNECT to read DB: '.$v[2].' ('.$this->db_type.') as '.$v[0].' using PEAR '.$this->pear_type; + if ($this->is_error($this->db_read)) { + $this->debug[] = 'connecting: UNABLE TO CONNECT to read DB: '.$v[2].' ('.$this->db_type.') as '.$v[0].' using PDO'; } else { - $this->debug[] = 'connecting: Connected to read DB: '.$v[2].' ('.$this->db_type.') as '.$v[0].' using PEAR '.$this->pear_type; + $this->debug[] = 'connecting: Connected to read DB: '.$v[2].' ('.$this->db_type.') as '.$v[0].' using PDO'; $this->current_read = $v; break; } } - if (!$this->db_read || PEAR::isError($this->db_read)) { + if ($this->is_error($this->db_read)) { $this->debug[] = 'connecting: Could not connect to any configured read servers'; } else { @@ -99,23 +103,25 @@ shuffle($this->write_servers); } foreach ($this->write_servers as $v) { - $dsn = $this->db_type.'://'.$v[0].':'.$v[1].'@'.$v[2].'/'.$v[3]; - if ($this->pear_type == 'MDB2') { - $this->db_write =& MDB2::Connect($dsn, true); + $dsn = $this->build_dsn($v[2], $v[3]); + + try { + $this->db_write = new PDO($dsn, $v[0], $v[1]); + $this->db_write->setAttribute(PDO::ATTR_CASE, PDO::CASE_LOWER); + } catch (PDOException $e) { + $this->db_write = $e; } - else { - $this->db_write =& DB::Connect($dsn, true); - } - if (PEAR::isError($this->db_write) || !($this->db_write)) { + + if ($this->is_error($this->db_write)) { $this->debug[] = 'connecting: Unable to connect to write DB: '.$v[2].' as '.$v[0]; } else { - $this->debug[] = 'connecting: Connected to write DB: '.$v[2].' ('.$this->db_type.') as '.$v[0].' using PEAR '.$this->pear_type; + $this->debug[] = 'connecting: Connected to write DB: '.$v[2].' ('.$this->db_type.') as '.$v[0].' using PDO'; $this->current_write = $v; break; } } - if (!$this->db_write || PEAR::isError($this->db_write)) { + if ($this->is_error($this->db_write)) { $this->debug[] = 'connecting: Could not connect to any configured write servers'; } } @@ -131,9 +137,9 @@ $user->notices[] = 'Could not establish a connection to the database'; } function disconnect() { - if ($this->db_split && is_object($this->db_write) && !PEAR::isError($this->db_read) && $this->db_write != $this->db_read) { + if ($this->db_split && is_object($this->db_write) && !($this->is_error($this->db_write)) && $this->db_write != $this->db_read) { $this->debug[] = 'disconnecting: disconnecting from write handle'; - $this->db_write->disconnect(); + $this->db_write = null; } if ($this->db_split) { $this->debug[] = 'disconnecting: disconnecting from read handle'; @@ -141,8 +147,8 @@ else { $this->debug[] = 'disconnecting: disconnecting from read/write handle'; } - if (is_object($this->db_read) && !PEAR::isError($this->db_read)) { - $this->db_read->disconnect(); + if (is_object($this->db_read) && !($this->is_error($this->db_read))) { + $this->db_read = null; } $this->debug[] = 'disconnecting: all db connections terminated'; } @@ -163,11 +169,11 @@ $res =& $this->db_read->query($sql); } $this->sql_list[] = $src.': '.$sql; - if (PEAR::isError($res)) { + if (!$res) { $this->debug[] = $src.': sql id: '.(count($this->sql_list) - 1).' : '.str_replace('**', "\n **", $res->userinfo); } else { - while ($row =& $res->fetchRow($this->fetch_mode)) { + while ($row =& $res->fetch($this->fetch_mode)) { $result_set[] = $row; } if ($explain) { @@ -182,28 +188,17 @@ return 0; } $result = 0; - if ($this->pear_type == 'MDB2') { - $sth = $this->db_write->prepare($sql); - if (method_exists($sth, 'execute')) { - $res = $sth->execute(); - $result = $res; - } - else { - $res = $sth; - } + $sth = $this->db_write->prepare($sql); + $res = $sth->execute(); + if ($res) { + $result = $sth->rowCount(); } - else { - $res =& $this->db_write->query($sql); - } $src = 'write handle'; $this->sql_list[] = $src.': '.$sql; - if (PEAR::isError($res)) { + if (!$res) { $this->debug[] = $src.': '.(count($this->sql_list) - 1).' : '.str_replace('**', "\n **", $res->userinfo); } else { - if ($this->pear_type == 'DB') { - $result = $this->db_write->affectedRows(); - } } return $result; } @@ -217,18 +212,16 @@ return $this->write($sql, $ses); } function single($sql, $force=false, $explain=false, $ses=false) { - if ($this->pear_type == 'MDB2') { - $cmd = 'queryOne'; - } - else { - $cmd = 'getOne'; - } if ($force) { - $res = $this->db_write->$cmd($sql); + $sth = $this->db_write->prepare($sql); + $sth->execute(); + $res = $sth->fetchColumn(); $src = 'write handle'; } else { - $res = $this->db_read->$cmd($sql); + $sth = $this->db_read->prepare($sql); + $sth->execute(); + $res = $sth->fetchColumn(); $src = 'read handle'; } $this->sql_list[] = $src.': '.$sql; @@ -249,6 +242,18 @@ return $res; } } + function limit($sql, $count=1) { + if ($this->db_type == 'firebird') { + $ptn = '/^(SELECT)(.*)$/i'; + preg_match($ptn, $sql, $matches); + array_splice($matches, 2, 0, 'FIRST '.$count); + $limit_sql = implode(' ', array_slice($matches, 1)); + } + else { + $limit_sql = $sql.' LIMIT '.$count; + } + return $limit_sql; + } function last_insert($force=true) { if ($this->read_only) { return 0; @@ -272,7 +277,7 @@ $res =& $this->db_write->query($sql); } $this->sql_list[] = $src.': '.$sql; - if (PEAR::isError($res)) { + if (!$res) { $this->debug[] = $src.': sql id: '.(count($this->sql_list) - 1).' : '.str_replace('**', "\n **", $res->userinfo); return false; } @@ -291,7 +296,7 @@ $res =& $this->db_write->query($sql); } $this->sql_list[] = $src.': '.$sql; - if (PEAR::isError($res)) { + if (!$res) { $this->debug[] = $src.': sql id: '.(count($this->sql_list) - 1).' : '.str_replace('**', "\n **", $res->userinfo); return false; } @@ -333,6 +338,9 @@ die; } } + function is_error($db_error) { + return $db_error instanceof PDOException; + } } /* myql db wrapper requires fw_sql_commands and fw_db_connections */ @@ -350,16 +358,15 @@ var $current_read; var $current_write; var $session_server; - var $mode; var $db_type; - var $pear_type; + var $adapter; var $fetch_mode; var $persistent; function db_wrap() { $this->db_type = 'mysql'; $this->fetch_mode = false; - $this->pear_type = 'DB'; + $this->adapter = 'PDO'; $this->current_read = array(); $this->current_write = array(); $this->db_split = false; Added: trunk/hastymail2/db/db_pear.php =================================================================== --- trunk/hastymail2/db/db_pear.php (rev 0) +++ trunk/hastymail2/db/db_pear.php 2013-02-03 08:41:54 UTC (rev 2147) @@ -0,0 +1,386 @@ +<?php + +/* db.php: Database wrapper + Copyright (C) 2002-2013 Hastymail Development group + + This file is part of Hastymail. + + Hastymail is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + Hastymail is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with Hastymail; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +* $Id:$ +*/ +$db_include_path = ''; +/* connect/disconnect and setup sql servers for */ +class fw_db_connections { + function add_write_server($user, $pass, $host, $db) { + $this->write_servers[] = array($user, $pass, $host, $db); + } + function add_read_server($user, $pass, $host, $db) { + $this->read_servers[] = array($user, $pass, $host, $db); + } + function connect() { + global $user; + global $db_include_path; + if ($this->adapter == 'MDB2') { + require_once($db_include_path.'MDB2.php'); + $this->mode = 'MDB2'; + $this->fetch_mode = MDB2_FETCHMODE_ASSOC; + } + else { + require_once($db_include_path.'DB.php'); + $this->mode = 'DB'; + $this->fetch_mode = DB_FETCHMODE_ASSOC; + } + if ($this->db_split) { + $this->debug[] = 'configuration: db_split is set to true, both read and write servers required'; + } + else { + $this->debug[] = 'configuration: db_split is set to false, only one server for read/write required'; + } + if ($this->random_connect_read) { + $this->debug[] = 'configuration: Read server order being randomized'; + } + else { + $this->debug[] = 'configuration: Maintaining read server order'; + } + if ($this->random_connect_write) { + $this->debug[] = 'configuration: Write server order being randomized'; + } + else { + $this->debug[] = 'configuration: Maintaining write server order'; + } + if (empty($this->read_servers)) { + $this->debug[] = 'connecting: No sql read servers defined'; + } + else { + if ($this->random_connect_read) { + shuffle($this->read_servers); + } + foreach ($this->read_servers as $v) { + $dsn = $this->db_type.'://'.$v[0].':'.$v[1].'@'.$v[2].'/'.$v[3]; + if ($this->adapter == 'MDB2') { + $db_read =& MDB2::Connect($dsn, array('persistent' => $this->persistent)); + } + else { + $db_read = DB::Connect($dsn, $this->persistent); + } + $this->db_read = $db_read; + if ($this->is_error($this->db_read) || !($this->db_read)) { + $this->debug[] = 'connecting: UNABLE TO CONNECT to read DB: '.$v[2].' ('.$this->db_type.') as '.$v[0].' using PEAR '.$this->adapter; + } + else { + $this->debug[] = 'connecting: Connected to read DB: '.$v[2].' ('.$this->db_type.') as '.$v[0].' using PEAR '.$this->adapter; + $this->current_read = $v; + break; + } + } + if (!$this->db_read || $this->is_error($this->db_read)) { + $this->debug[] = 'connecting: Could not connect to any configured read servers'; + } + else { + if ($this->db_split) { + if (empty($this->write_servers)) { + $this->debug[] = 'connecting: No sql write servers defined'; + } + else { + if ($this->random_connect_write) { + shuffle($this->write_servers); + } + foreach ($this->write_servers as $v) { + $dsn = $this->db_type.'://'.$v[0].':'.$v[1].'@'.$v[2].'/'.$v[3]; + if ($this->adapter == 'MDB2') { + $this->db_write =& MDB2::Connect($dsn, true); + } + else { + $this->db_write =& DB::Connect($dsn, true); + } + if ($this->is_error($this->db_write) || !($this->db_write)) { + $this->debug[] = 'connecting: Unable to connect to write DB: '.$v[2].' as '.$v[0]; + } + else { + $this->debug[] = 'connecting: Connected to write DB: '.$v[2].' ('.$this->db_type.') as '.$v[0].' using PEAR '.$this->adapter; + $this->current_write = $v; + break; + } + } + if (!$this->db_write || $this->is_error($this->db_write)) { + $this->debug[] = 'connecting: Could not connect to any configured write servers'; + } + } + } + else { + $this->db_write = $this->db_read; + $this->debug[] = 'connection: db_split is set to false, using current read server as read/write'; + $this->debug[] = 'connecting: Successfully connnected to required sql servers'; + return true; + } + } + } + $user->notices[] = 'Could not establish a connection to the database'; + } + function disconnect() { + if ($this->db_split && is_object($this->db_write) && !$this->is_error($this->db_read) && $this->db_write != $this->db_read) { + $this->debug[] = 'disconnecting: disconnecting from write handle'; + $this->db_write->disconnect(); + } + if ($this->db_split) { + $this->debug[] = 'disconnecting: disconnecting from read handle'; + } + else { + $this->debug[] = 'disconnecting: disconnecting from read/write handle'; + } + if (is_object($this->db_read) && !$this->is_error($this->db_read)) { + $this->db_read->disconnect(); + } + $this->debug[] = 'disconnecting: all db connections terminated'; + } +} + +/* sql command wrappers */ +class fw_sql_commands extends fw_db_connections { + function fw_sql_commands() { + } + function select($sql, $force=false, $explain=false, $ses=false) { + $result_set = array(); + if ($force) { + $src = 'write handle'; + $res =& $this->db_write->query($sql); + } + else { + $src = 'read handle'; + $res =& $this->db_read->query($sql); + } + $this->sql_list[] = $src.': '.$sql; + if ($this->is_error($res)) { + $this->debug[] = $src.': sql id: '.(count($this->sql_list) - 1).' : '.str_replace('**', "\n **", $res->userinfo); + } + else { + while ($row =& $res->fetchRow($this->fetch_mode)) { + $result_set[] = $row; + } + if ($explain) { + $res = $this->select('explain '.$sql); + $this->debug[] = array('EXPLAIN output for sql id '.(count($this->sql_list) - 1) => $res); + } + } + return $result_set; + } + function write($sql, $ses=false) { + if ($this->read_only) { + return 0; + } + $result = 0; + if ($this->adapter == 'MDB2') { + $sth = $this->db_write->prepare($sql); + if (method_exists($sth, 'execute')) { + $res = $sth->execute(); + $result = $res; + } + else { + $res = $sth; + } + } + else { + $res =& $this->db_write->query($sql); + } + $src = 'write handle'; + $this->sql_list[] = $src.': '.$sql; + if ($this->is_error($res)) { + $this->debug[] = $src.': '.(count($this->sql_list) - 1).' : '.str_replace('**', "\n **", $res->userinfo); + } + else { + if ($this->adapter == 'DB') { + $result = $this->db_write->affectedRows(); + } + } + return $result; + } + function delete($sql, $ses=false) { + return $this->write($sql, $ses); + } + function update($sql, $ses=false) { + return $this->write($sql, $ses); + } + function insert($sql, $ses=false) { + return $this->write($sql, $ses); + } + function single($sql, $force=false, $explain=false, $ses=false) { + if ($this->adapter == 'MDB2') { + $cmd = 'queryOne'; + } + else { + $cmd = 'getOne'; + } + if ($force) { + $res = $this->db_write->$cmd($sql); + $src = 'write handle'; + } + else { + $res = $this->db_read->$cmd($sql); + $src = 'read handle'; + } + $this->sql_list[] = $src.': '.$sql; + if (is_object($res)) { + if (isset($res->userinfo)) { + $this->debug[] = $src.': '.(count($this->sql_list) - 1).' : '.str_replace('**', "\n **", $res->userinfo); + } + else { + $this->debug[] = $src.': '.(count($this->sql_list) - 1).' : Unkown Error'; + } + return false; + } + else { + if ($explain) { + $exp = $this->select('explain '.$sql); + $this->debug[] = array('EXPLAIN output for sql id '.(count($this->sql_list) - 1) => $exp); + } + return $res; + } + } + function limit($sql, $count=1) { + $limit_sql = $sql.' LIMIT '.$count; + return $limit_sql; + } + function last_insert($force=true) { + if ($this->read_only) { + return 0; + } + $sql = 'select last_insert_id()'; + return $this->single($sql, $force); + } + function calc_rows($force=false) { + $sql = 'select FOUND_ROWS()'; + return $this->single($sql, $force); + } + function lock_table($table, $lock_type, $read=false) { + $sql = 'lock table '.$table.' '.$lock_type; + $result_set = array(); + if (!$read) { + $src = 'write handle'; + $res =& $this->db_write->query($sql); + } + else { + $src = 'read handle'; + $res =& $this->db_write->query($sql); + } + $this->sql_list[] = $src.': '.$sql; + if ($this->is_error($res)) { + $this->debug[] = $src.': sql id: '.(count($this->sql_list) - 1).' : '.str_replace('**', "\n **", $res->userinfo); + return false; + } + else { + return true; + } + } + function unlock_table($read=false) { + $sql = 'unlock tables'; + if (!$read) { + $src = 'write handle'; + $res =& $this->db_write->query($sql); + } + else { + $src = 'read handle'; + $res =& $this->db_write->query($sql); + } + $this->sql_list[] = $src.': '.$sql; + if ($this->is_error($res)) { + $this->debug[] = $src.': sql id: '.(count($this->sql_list) - 1).' : '.str_replace('**', "\n **", $res->userinfo); + return false; + } + else { + return true; + } + } + function get_tables() { + $sql = 'show tables'; + $res = $this->select($sql); + $clean = array(); + foreach ($res as $vals) { + $indexes = array_keys($vals); + foreach ($indexes as $v) { + $clean[] = $vals[$v]; + } + } + return $clean; + } + function qt($string, $wc=false) { + if (!$string && !is_int($string)) { + return "''"; + } + else { + if ($wc) { + $string = '%'.$string.'%'; + } + return $this->db_read->quote($string); + } + } + function puke($continue=false) { + if (!$continue) { + $this->disconnect(); + } + $data = '<div class="debug"><h4>SQL DEBUG<br /></h4><pre>'.print_r($this->sql_list, true)."\n". + print_r($this->debug, true)."\n</pre></div>"; + return $data; + if (!$continue) { + die; + } + } + function is_error($db_res) { + return PEAR::isError($db_res); + } +} + +/* myql db wrapper requires fw_sql_commands and fw_db_connections */ +class db_wrap extends fw_sql_commands { + var $db_write; + var $db_read; + var $debug; + var $sql_list; + var $db_split; + var $read_servers; + var $write_servers; + var $random_connect_read; + var $random_connect_write; + var $read_only; + var $current_read; + var $current_write; + var $session_server; + var $mode; + var $db_type; + var $adapter; + var $fetch_mode; + var $persistent; + + function db_wrap() { + $this->db_type = 'mysql'; + $this->fetch_mode = false; + $this->adapter = 'DB'; + $this->current_read = array(); + $this->current_write = array(); + $this->db_split = false; + $this->session_server = array(); + $this->read_servers = array(); + $this->write_servers = array(); + $this->debug = array('db_wrap DEBUG MESSAGES'); + $this->sql_list = array('SQL STATEMENTS IN ORDER'); + $this->random_connect_read = false; + $this->random_connect_write = false; + $this->read_only = false; + $this->persistent = false; + } +} + + +?> Added: trunk/hastymail2/db/user_setting.firebird.sql =================================================================== --- trunk/hastymail2/db/user_setting.firebird.sql (rev 0) +++ trunk/hastymail2/db/user_setting.firebird.sql 2013-02-03 08:41:54 UTC (rev 2147) @@ -0,0 +1,27 @@ +CREATE TABLE USER_SETTING +( + ID integer PRIMARY KEY NOT NULL, + USERNAME varchar(250), + SETTINGS blob sub_type 1 +); + +CREATE GENERATOR GEN_USER_SETTING_ID; + +SET TERM ^ ; +CREATE TRIGGER USER_SETTING_BI FOR USER_SETTING ACTIVE +BEFORE INSERT POSITION 0 +as +declare variable tmp decimal(18,0); +begin + if (new.id is null) then + new.id = gen_id(gen_user_setting_id, 1); + else + begin + tmp = gen_id(gen_user_setting_id, 0); + if (tmp < new.id) then + tmp = gen_id(gen_user_setting_id, new.id-tmp); + end +end^ +SET TERM ; ^ + + Added: trunk/hastymail2/db/user_setting.sqlite.sql =================================================================== --- trunk/hastymail2/db/user_setting.sqlite.sql (rev 0) +++ trunk/hastymail2/db/user_setting.sqlite.sql 2013-02-03 08:41:54 UTC (rev 2147) @@ -0,0 +1,5 @@ +CREATE TABLE user_setting ( + id integer primary key autoincrement not null, + username varchar(250), + settings text +); Modified: trunk/hastymail2/hastymail2.conf.example =================================================================== --- trunk/hastymail2/hastymail2.conf.example 2013-01-17 14:55:02 UTC (rev 2146) +++ trunk/hastymail2/hastymail2.conf.example 2013-02-03 08:41:54 UTC (rev 2147) @@ -324,17 +324,17 @@ db_database = hastymail - # db_pear_type + # db_adapter # ------------ - # This can be set to DB to use the older pear DB support or MDB2 to use - # the newer pear DB library. + # This can be set to PDO to use PHP Data Objects, DB to use the older pear + # DB support, MDB2 to use the newer pear DB library. -db_pear_type = DB +db_adapter = DB # db_type # ------- - # This can be set to mysql for Mysql db support or pgsql for Postgres - # support + # With PDO this can be set to mysql, pgsql, sqlite, or firebird + # With DB or MDB2 this can be set to mysql or pgsql db_type = mysql Modified: trunk/hastymail2/lib/utility_classes.php =================================================================== --- trunk/hastymail2/lib/utility_classes.php 2013-01-17 14:55:02 UTC (rev 2146) +++ trunk/hastymail2/lib/utility_classes.php 2013-02-03 08:41:54 UTC (rev 2147) @@ -1423,12 +1423,16 @@ global $include_path; global $conf; global $fd; - require_once($include_path.'db'.$fd.'db.php'); - if (isset($conf['db_type']) && isset($conf['db_pear_type']) && isset($conf['db_username']) && + if (isset($conf['db_type']) && isset($conf['db_adapter']) && isset($conf['db_username']) && isset($conf['db_password']) && isset($conf['db_hostname']) && isset($conf['db_database'])) { + $db_lib = 'db'; + if ($conf['db_adapter'] != 'PDO') { + $db_lib = 'db_pear'; + } + require_once($include_path.'db'.$fd.$db_lib.'.php'); $dbase = hm_new('db_wrap'); $dbase->db_type = $conf['db_type']; - $dbase->pear_type = $conf['db_pear_type']; + $dbase->adapter = $conf['db_adapter']; if (isset($conf['db_persistent'])) { $dbase->persistent = $conf['db_persistent']; } @@ -1982,7 +1986,7 @@ /* db functions */ function get_db() { global $dbase; - if (!is_object($dbase) || PEAR::isError($dbase->db_read)) { + if (!is_object($dbase) || $dbase->is_error($dbase->db_read)) { $res = false; } else { @@ -2009,6 +2013,12 @@ return $dbase->select($sql); } } + function db_limit($sql) { + global $dbase; + if ($this->db) { + return $dbase->limit($sql); + } + } function db_quote($sql) { global $dbase; if ($this->db) { Modified: trunk/hastymail2/plugins/calendar/cal_include.php =================================================================== --- trunk/hastymail2/plugins/calendar/cal_include.php 2013-01-17 14:55:02 UTC (rev 2146) +++ trunk/hastymail2/plugins/calendar/cal_include.php 2013-02-03 08:41:54 UTC (rev 2147) @@ -180,24 +180,28 @@ if ($tools->get_db()) { $date_sql = ''; $repeat_sql = ''; + $base = strtotime(($year?$year:1).'-'.($month?$month:1).'-'.($day?$day:1)); + $next_year = strtotime('next year', $base); + $next_month = strtotime('next month', $base); + $next_day = strtotime('next day', $base); switch ($dsp_page) { case 'all': - $date_sql = "(datetime > '0001-01-01 00:00:00')"; + $date_sql = "(datetime > '".date('Y-m-d 00:00:00', $base)."')"; break; case 'calendar_year': - $date_sql = "(datetime > '".intval($year)."-01-01 00:00:00' and datetime < '".(intval($year) + 1)."-01-01 00:00:00')"; + $date_sql = "(datetime > '".date('Y-01-01 00:00:00', $base)."' and datetime < '".date('Y-01-01 00:00:00', $next_year)."')"; break; case 'calendar_week': case 'calendar_month': if ($month == 12) { - $date_sql = "(datetime > '".intval($year)."-".intval($month)."-01 00:00:00' and datetime < '".(intval($year) + 1)."-01-01 00:00:00')"; + $date_sql = "(datetime > '".date('Y-m-01 00:00:00', $base)."' and datetime < '".date('Y-01-01 00:00:00', $next_year)."')"; } else { - $date_sql = "(datetime > '".intval($year)."-".intval($month)."-01 00:00:00' and datetime < '".intval($year)."-".(intval($month) + 1)."-01 00:00:00')"; + $date_sql = "(datetime > '".date('Y-m-01 00:00:00', $base)."' and datetime < '".date('Y-m-01 00:00:00', $next_month)."')"; } break; case 'calendar_day': - $date_sql = "(datetime > '".intval($year)."-".intval($month)."-".intval($day)." 00:00:00' and datetime < '".intval($year)."-".intval($month)."-".intval($day)." 24:00:00')"; + $date_sql = "(datetime > '".date('Y-m-d 00:00:00', $base)."' and datetime < '".date('Y-m-d 00:00:00', $next_day)."')"; break; } if ($date_sql) { @@ -206,10 +210,11 @@ $res = $tools->db_query($sql); foreach ($res as $vals) { if (strpos($vals['datetime'], ' ')) { - $date = substr($vals['datetime'], 0, strpos($vals['datetime'], ' ')); - $time = substr($vals['datetime'], (strpos($vals['datetime'], ' ') + 1)); - $hour_time = substr($time, 0, 2); - $min_time = substr($time, 3, 2); + $timestamp = strtotime($vals['datetime']); + $date = date('Y-m-d', $timestamp); + $time = date('H:i:s', $timestamp); + $hour_time = date('H', $timestamp); + $min_time = date('i', $timestamp); $vals['repeat'] = $vals['repeat_val']; $events[$date][$hour_time][$min_time][] = $vals; } @@ -326,7 +331,7 @@ function add_cal_event($atts, $tools) { $id = 0; if ($tools->get_db()) { - $date_str = intval($atts['year']).'-'.intval($atts['month']).'-'.intval($atts['day']).' '.intval($atts['event_time']).':'.intval($atts['event_time2']).':00'; + $date_str = date('Y-m-d H:i:s', strtotime($atts['year'].'-'.$atts['month'].'-'.$atts['day'].' '.$atts['event_time'].':'.$atts['event_time2'].':00')); if ($atts['duration']) { if ($atts['duration2']) { $duration = intval($atts['duration']) + ($atts['duration2']/60); @@ -338,7 +343,7 @@ else { $duration = 0; } - $sql = 'insert into calendar values(default, '. + $sql = 'insert into calendar values(null, '. $tools->db_quote($tools->username).', '. $tools->db_quote($date_str).', '. floatval($duration).', '. @@ -347,7 +352,7 @@ intval($atts['repeat']).')'; $res = $tools->db_insert($sql); if ($res) { - $sql = 'select id from calendar order by id DESC limit 1'; + $sql = $tools->db_limit('select id from calendar order by id DESC'); $id = $tools->db_query_one($sql); } } @@ -410,7 +415,7 @@ function update_event($tools, $atts) { $res = false; if ($tools->get_db()) { - $date_str = intval($atts['year']).'-'.intval($atts['month']).'-'.intval($atts['day']).' '.intval($atts['event_time']).':'.intval($atts['event_time2']).':00'; + $date_str = date('Y-m-d H:i:s', strtotime($atts['year'].'-'.$atts['month'].'-'.$atts['day'].' '.$atts['event_time'].':'.$atts['event_time2'].':00')); if ($atts['duration']) { if ($atts['duration2']) { $duration = intval($atts['duration']) + ($atts['duration2']/60); Added: trunk/hastymail2/plugins/calendar/calendar.firebird.sql =================================================================== --- trunk/hastymail2/plugins/calendar/calendar.firebird.sql (rev 0) +++ trunk/hastymail2/plugins/calendar/calendar.firebird.sql 2013-02-03 08:41:54 UTC (rev 2147) @@ -0,0 +1,31 @@ +CREATE TABLE CALENDAR +( + ID integer PRIMARY KEY NOT NULL, + USERNAME varchar(250), + DATETIME timestamp, + DURATION double precision, + TITLE varchar(250), + DESCRIPTION blob sub_type 1, + REPEAT_VAL integer +); + +CREATE GENERATOR GEN_CALENDAR_ID; + +SET TERM ^ ; +CREATE TRIGGER CALENDAR_BI FOR CALENDAR ACTIVE +BEFORE INSERT POSITION 0 +as +declare variable tmp decimal(18,0); +begin + if (new.id is null) then + new.id = gen_id(gen_calendar_id, 1); + else + begin + tmp = gen_id(gen_calendar_id, 0); + if (tmp < new.id) then + tmp = gen_id(gen_calendar_id, new.id-tmp); + end +end^ +SET TERM ; ^ + + Added: trunk/hastymail2/plugins/calendar/calendar.sqlite.sql =================================================================== --- trunk/hastymail2/plugins/calendar/calendar.sqlite.sql (rev 0) +++ trunk/hastymail2/plugins/calendar/calendar.sqlite.sql 2013-02-03 08:41:54 UTC (rev 2147) @@ -0,0 +1,9 @@ +CREATE TABLE calendar ( + id integer primary key autoincrement not null, + username varchar(250), + `datetime` datetime, + duration float, + title varchar(250), + description text, + repeat_val integer +); Modified: trunk/hastymail2/plugins/calendar/page.php =================================================================== --- trunk/hastymail2/plugins/calendar/page.php 2013-01-17 14:55:02 UTC (rev 2146) +++ trunk/hastymail2/plugins/calendar/page.php 2013-02-03 08:41:54 UTC (rev 2147) @@ -55,7 +55,7 @@ $duration2 = ''; $event_time = ''; $event_time2 = ''; - $first_week_day = false; + $first_week_day = date('w', mktime(0, 0, 0, date('m'), 1, date('Y')));; $all_events = array(); $edit_id = 0; $dsp_page = 'calendar_month'; Added: trunk/hastymail2/plugins/logger/log.firebird.sql =================================================================== --- trunk/hastymail2/plugins/logger/log.firebird.sql (rev 0) +++ trunk/hastymail2/plugins/logger/log.firebird.sql 2013-02-03 08:41:54 UTC (rev 2147) @@ -0,0 +1,32 @@ +CREATE TABLE event_log ( + id integer primary key not null, + ts timestamp NOT NULL, + username varchar(250) default NULL, + server_name varchar(250) default NULL, + server_port varchar(250) default NULL, + remote_address varchar(250) default NULL, + remote_port varchar(250) default NULL, + query_string varchar(250) default NULL, + php_self varchar(250) default NULL, + referer varchar(250) default NULL, + user_agent varchar(250) default NULL +); + +CREATE GENERATOR GEN_EVENT_LOG_ID; + +SET TERM ^ ; +CREATE TRIGGER EVENT_LOG_BI FOR EVENT_LOG ACTIVE +BEFORE INSERT POSITION 0 +as +declare variable tmp decimal(18,0); +begin + if (new.id is null) then + new.id = gen_id(gen_event_log_id, 1); + else + begin + tmp = gen_id(gen_event_log_id, 0); + if (tmp < new.id) then + tmp = gen_id(gen_event_log_id, new.id-tmp); + end +end^ +SET TERM ; ^ \ No newline at end of file Added: trunk/hastymail2/plugins/logger/log.sqlite.sql =================================================================== --- trunk/hastymail2/plugins/logger/log.sqlite.sql (rev 0) +++ trunk/hastymail2/plugins/logger/log.sqlite.sql 2013-02-03 08:41:54 UTC (rev 2147) @@ -0,0 +1,13 @@ +CREATE TABLE event_log ( + id integer primary key autoincrement not null, + ts date NOT NULL, + username varchar(250) default NULL, + server_name varchar(250) default NULL, + server_port varchar(250) default NULL, + remote_address varchar(250) default NULL, + remote_port varchar(250) default NULL, + query_string varchar(250) default NULL, + php_self varchar(250) default NULL, + referer varchar(250) default NULL, + user_agent varchar(250) default NULL +); Added: trunk/hastymail2/plugins/login_alias/login_alias_table.firebird.sql =================================================================== --- trunk/hastymail2/plugins/login_alias/login_alias_table.firebird.sql (rev 0) +++ trunk/hastymail2/plugins/login_alias/login_alias_table.firebird.sql 2013-02-03 08:41:54 UTC (rev 2147) @@ -0,0 +1,4 @@ +CREATE TABLE login_alias ( + login_name varchar(250) PRIMARY KEY, + imap_name varchar(250) +); \ No newline at end of file Added: trunk/hastymail2/plugins/login_alias/login_alias_table.sqlite.sql =================================================================== --- trunk/hastymail2/plugins/login_alias/login_alias_table.sqlite.sql (rev 0) +++ trunk/hastymail2/plugins/login_alias/login_alias_table.sqlite.sql 2013-02-03 08:41:54 UTC (rev 2147) @@ -0,0 +1,4 @@ +CREATE TABLE login_alias ( + login_name varchar(250) PRIMARY KEY, + imap_name varchar(250) +); \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |