|
From: Benjamin C. <bc...@us...> - 2002-03-17 01:47:07
|
Update of /cvsroot/phpbt/phpbt
In directory usw-pr-cvs1:/tmp/cvs-serv5718
Modified Files:
include.php
Log Message:
Switching to PEAR::DB
Index: include.php
===================================================================
RCS file: /cvsroot/phpbt/phpbt/include.php,v
retrieving revision 1.98
retrieving revision 1.99
diff -u -r1.98 -r1.99
--- include.php 14 Mar 2002 19:36:00 -0000 1.98
+++ include.php 17 Mar 2002 01:47:04 -0000 1.99
@@ -39,83 +39,15 @@
// Grab the global functions
include (INSTALL_PATH.'/inc/functions.php');
-class dbclass extends DB_Sql {
- var $classname = 'dbclass';
- var $Host = DB_HOST;
- var $Database = DB_DATABASE;
- var $User = DB_USER;
- var $Password = DB_PASSWORD;
- var $Seq_Table = TBL_DB_SEQUENCE;
- var $Seq_ID_Col = "nextid";
- var $Seq_Name_Col = "seq_name";
-
- // Attempt to handle different limit syntax
- function limit_query($q_string, $limit, $offset = 0) {
- if ($offset) {
- if (DB_TYPE == 'pgsql') {
- $this->query("$q_string limit $limit offset $offset");
- } else {
- $this->query("$q_string limit $offset, $limit");
- }
- } else {
- $this->query("$q_string limit $limit");
- }
- }
-
- // Handle the different types of concats
- function concat() {
- $pieces = func_get_args();
- if (DB_TYPE == 'pgsql') {
- return delimit_list(' || ', $pieces);
- } else {
- return 'concat('. delimit_list(', ', $pieces).')';
- }
- }
-
- function grab($q_string = '') {
- if ($q_string) $this->query($q_string);
- $this->next_record();
- return $this->Record;
- }
-
- function grab_field($q_string = '') {
- list($retval) = $this->grab($q_string);
- return $retval;
- }
-
- function grab_set($q_string = '') {
- $retary = array();
- if ($q_string) $this->query($q_string);
- while ($row = $this->grab()) { $retary[] = $row; }
- return $retary;
- }
-
- function grab_field_set($q_string = '') {
- $retary = array();
- if ($q_string) $this->query($q_string);
- while ($item = $this->grab_field()) { $retary[] = $item; }
- return $retary;
- }
- function nextid($seq_name) {
- global $auth;
-
- if ($seq_name == TBL_SAVED_QUERY) {
- if ($id = $this->grab_field("select max(saved_query_id)+1 from ".TBL_SAVED_QUERY." where user_id = ".$auth->auth['uid'])) {
- return $id;
- } else {
- return 1;
- }
- } else {
- return DB_Sql::nextid($seq_name);
- }
- }
-}
+// PEAR::DB
+require_once('DB.php');
+$db = DB::Connect(DB_TYPE.'://'.DB_USER.':'.DB_PASSWORD.'@'.DB_HOST.'/'.DB_DATABASE);
+$db->setFetchMode(DB_FETCHMODE_ASSOC);
-$q = new dbclass;
// Set up the configuration variables
-$q->query('select varname, varvalue from '.TBL_CONFIGURATION);
-while (list($k, $v) = $q->grab()) {
+$rs = $db->query('select varname, varvalue from '.TBL_CONFIGURATION);
+while (list($k, $v) = $rs->fetchRow(DB_FETCHMODE_ORDERED)) {
define($k, $v);
}
@@ -157,19 +89,21 @@
class templateclass extends Template {
function pparse($target, $handle, $append = false) {
- global $auth, $perm, $q;
+ global $auth, $perm, $db;
$u = isset($auth->auth['uid']) ? $auth->auth['uid'] : 0;
$this->set_block('wrap', 'logoutblock', 'loblock');
$this->set_block('wrap', 'loginblock', 'liblock');
$this->set_block('wrap', 'adminnavblock', 'anblock');
if ($u) {
- list($owner_open, $owner_closed) = $q->grab("SELECT sum(CASE WHEN status_name in ('Unconfirmed','New','Assigned','Reopened') THEN 1 ELSE 0 END ) ,"
+ list($owner_open, $owner_closed) = $db->getRow("SELECT sum(CASE WHEN status_name in ('Unconfirmed','New','Assigned','Reopened') THEN 1 ELSE 0 END ) ,"
."sum(CASE WHEN status_name not in ('Unconfirmed','New','Assigned','Reopened') THEN 1 ELSE 0 END )"
- ."from ".TBL_BUG." b left join ".TBL_STATUS." s using(status_id) where assigned_to = $u");
- list($reporter_open, $reporter_closed) = $q->grab("SELECT sum(CASE WHEN status_name in ('Unconfirmed','New','Assigned','Reopened') THEN 1 ELSE 0 END ) ,"
+ ."from ".TBL_BUG." b left join ".TBL_STATUS." s using(status_id) where assigned_to = $u",
+ DB_FETCHMODE_ORDERED);
+ list($reporter_open, $reporter_closed) = $db->getRow("SELECT sum(CASE WHEN status_name in ('Unconfirmed','New','Assigned','Reopened') THEN 1 ELSE 0 END ) ,"
."sum(CASE WHEN status_name not in ('Unconfirmed','New','Assigned','Reopened') THEN 1 ELSE 0 END )"
- ."from ".TBL_BUG." b left join ".TBL_STATUS." s using(status_id) where created_by = $u");
+ ."from ".TBL_BUG." b left join ".TBL_STATUS." s using(status_id) where created_by = $u",
+ DB_FETCHMODE_ORDERED);
$this->set_var(array(
'loggedinas' => $auth->auth['uname'],
'liblock' => '',
@@ -225,14 +159,14 @@
// Check to see if the user is trying to login
if (isset($_pv['dologin'])) {
if (isset($_pv['sendpass'])) {
- list($email, $password) = $q->grab("select email, password from ".TBL_AUTH_USER." where login = '{$_pv['username']}' and active > 0");
- if (!$q->num_rows()) {
+ list($email, $password) = $db->getRow("select email, password from ".TBL_AUTH_USER." where login = '{$_pv['username']}' and active > 0");
+ if (!$email) {
$t->set_var('loginerror', '<div class="error">Invalid login</div>');
} else {
if (ENCRYPT_PASS) {
$password = genpassword(10);
$mpassword = md5($password);
- $q->query("update ".TBL_AUTH_USER." set password = '$mpassword' where login = '$username'");
+ $db->query("update ".TBL_AUTH_USER." set password = '$mpassword' where login = '$username'");
}
mail($email, $STRING['newacctsubject'], sprintf($STRING['newacctmessage'],
$password), sprintf("From: %s\nContent-Type: text/plain; charset=%s\nContent-Transfer-Encoding: 8bit\n",ADMIN_EMAIL, $STRING['lang_charset']));
@@ -253,11 +187,11 @@
$restricted_projects = '0';
if (!$perm->have_perm('Admin')) {
$viewable_projects = delimit_list(',',
- $q->grab_field_set("select project_id from ".TBL_PROJECT_GROUP.
+ $db->getCol("select project_id from ".TBL_PROJECT_GROUP.
" where group_id in (".delimit_list(',', $auth->auth['group_ids']).")"));
$viewable_projects = $viewable_projects ? $viewable_projects : '0';
$matching_projects = delimit_list(',',
- $q->grab_field_set("select project_id from ".TBL_PROJECT_GROUP.
+ $db->getCol("select project_id from ".TBL_PROJECT_GROUP.
" where project_id not in ($viewable_projects) group by project_id"));
if ($matching_projects) {
$restricted_projects .= ",$matching_projects";
|