From: Benjamin C. <bc...@us...> - 2002-03-29 18:25:40
|
Update of /cvsroot/phpbt/phpbt In directory usw-pr-cvs1:/tmp/cvs-serv20053 Modified Files: bug.php config-dist.php config.php include.php index.php query.php report.php Log Message: Database independence... ooo-eee! Index: bug.php =================================================================== RCS file: /cvsroot/phpbt/phpbt/bug.php,v retrieving revision 1.89 retrieving revision 1.90 diff -u -r1.89 -r1.90 --- bug.php 26 Mar 2002 17:27:48 -0000 1.89 +++ bug.php 29 Mar 2002 18:25:37 -0000 1.90 @@ -121,15 +121,14 @@ /// /// Show the activity for a bug function show_history($bugid) { - global $db, $t, $STRING; + global $db, $t, $STRING, $QUERY; if (!is_numeric($bugid)) { show_text($STRING['nobughistory']); return; } - $rs = $db->query('select bh.*, login from '.TBL_BUG_HISTORY.' bh left join '. - TBL_AUTH_USER." on bh.created_by = user_id where bug_id = $bugid"); + $rs = $db->query(sprintf($QUERY['bug-history'], $bugid)); if (!$rs->numRows()) { show_text($STRING['nobughistory']); return; @@ -155,7 +154,7 @@ /// /// Send the email about changes to the bug and log the changes in the DB function do_changedfields($userid, &$buginfo, $cf = array(), $comments = '') { - global $db, $t, $u, $select, $now, $STRING; + global $db, $t, $u, $select, $now, $STRING, $QUERY; // It's a new bug if the changedfields array is empty and there are no comments $newbug = (!count($cf) and !$comments); @@ -274,10 +273,7 @@ $maillist[] = $assignedto; // Collect the CCs - if ($ccs = $db->getCol('select email from '.TBL_BUG_CC.' left join '. - TBL_AUTH_USER." u using(user_id), ".TBL_USER_PREF." p ". - "where bug_id = {$buginfo['bug_id']} and u.user_id = p.user_id ". - "and email_notices = 1")) { + if ($ccs = $db->getCol(sprintf($QUERY['bug-cc-list'], $buginfo['bug_id']))) { array_push($maillist, $ccs); } @@ -602,22 +598,10 @@ } function show_bug_printable($bugid) { - global $db, $me, $t, $select, $TITLE; + global $db, $me, $t, $select, $TITLE, $QUERY; if (!is_numeric($bugid) or - !$row = $db->getRow('select b.*, reporter.login as reporter, - owner.login as owner, project_name, component_name, version_name, - severity_name, os_name, status_name, resolution_name - from '.TBL_BUG.' b - left join '.TBL_AUTH_USER.' owner on b.assigned_to = owner.user_id - left join '.TBL_AUTH_USER.' reporter on b.created_by = reporter.user_id - left join '.TBL_RESOLUTION.' r on b.resolution_id = r.resolution_id,'. - TBL_SEVERITY.' sv, '.TBL_STATUS.' st, '.TBL_OS.' os, '. - TBL_VERSION.' v, '.TBL_COMPONENT.' c, '.TBL_PROJECT." p - where bug_id = '$bugid' and b.severity_id = sv.severity_id - and b.os_id = os.os_id and b.version_id = v.version_id - and b.component_id = c.component_id and b.project_id = p.project_id - and b.status_id = st.status_id")) { + !$row = $db->getRow(sprintf($QUERY['bug-printable'], $bugid))) { show_text($STRING['bugbadnum'],true); exit; } @@ -673,7 +657,7 @@ /// /// Grab the links for the previous and next bugs in the list function prev_next_links($bugid, $pos) { - global $db, $_sv, $STRING; + global $db, $_sv, $STRING, $QUERY; if (!isset($_sv['queryinfo']['query']) || !$_sv['queryinfo']['query']) { return array('', ''); @@ -687,19 +671,9 @@ $offset = $pos; $limit = 1; } - $rs = $db->limitQuery('select bug_id, reporter.login as reporter, owner.login as owner - from '.TBL_BUG.' b - left join '.TBL_AUTH_USER.' owner on b.assigned_to = owner.user_id - left join '.TBL_AUTH_USER.' reporter on b.created_by = reporter.user_id - left join '.TBL_AUTH_USER.' lastmodifier on b.last_modified_by = lastmodifier.user_id - left join '.TBL_RESOLUTION.' resolution on b.resolution_id = resolution.resolution_id, '. - TBL_SEVERITY.' severity, '.TBL_STATUS.' status, '.TBL_OS.' os, '. - TBL_VERSION.' version, '.TBL_COMPONENT.' component, '.TBL_PROJECT.' project - where b.severity_id = severity.severity_id and b.status_id = status.status_id - and b.os_id = os.os_id and b.version_id = version.version_id - and b.component_id = component.component_id and b.project_id = project.project_id '. - "and {$_sv['queryinfo']['query']} and bug_id <> $bugid - order by {$_sv['queryinfo']['order']} {$_sv['queryinfo']['sort']}, bug_id asc", $offset, $limit); + $rs = $db->limitQuery(sprintf($QUERY['bug-prev-next'], + $_sv['queryinfo']['query'], $bugid, $_sv['queryinfo']['order'], + $_sv['queryinfo']['sort']), $offset, $limit); list($firstid, $chunks) = $rs->fetchRow(DB_FETCHMODE_ORDERED); list($secondid, $chunks) = $rs->fetchRow(DB_FETCHMODE_ORDERED); @@ -724,17 +698,10 @@ } function show_bug($bugid = 0, $error = array()) { - global $db, $me, $t, $STRING, $TITLE, $u, $perm, $_gv; + global $db, $me, $t, $STRING, $TITLE, $u, $perm, $_gv, $QUERY; if (!ereg('^[0-9]+$',$bugid) or - !$row = $db->getRow('select b.*, reporter.login as reporter, owner.login as owner, status_name, resolution_name - from '.TBL_BUG.' b - left join '.TBL_AUTH_USER.' owner on b.assigned_to = owner.user_id - left join '.TBL_AUTH_USER.' reporter on b.created_by = reporter.user_id - left join '.TBL_RESOLUTION.' r on b.resolution_id = r.resolution_id,'. - TBL_SEVERITY.' sv, '.TBL_STATUS." st - where bug_id = '$bugid' and b.severity_id = sv.severity_id - and b.status_id = st.status_id")) { + !$row = $db->getRow(sprintf($QUERY['bug-show-bug'], $bugid))) { show_text($STRING['bugbadnum'],true); return; } Index: config-dist.php =================================================================== RCS file: /cvsroot/phpbt/phpbt/config-dist.php,v retrieving revision 1.10 retrieving revision 1.11 diff -u -r1.10 -r1.11 --- config-dist.php 21 Mar 2002 13:44:54 -0000 1.10 +++ config-dist.php 29 Mar 2002 18:25:37 -0000 1.11 @@ -62,6 +62,7 @@ define ('ONEDAY', 86400); +require_once (INSTALL_PATH.'/inc/db/'.DB_TYPE.'.php'); require_once (INSTALL_PATH.'/inc/auth.php'); require_once (INSTALL_PATH.'/inc/template.php'); Index: config.php =================================================================== RCS file: /cvsroot/phpbt/phpbt/config.php,v retrieving revision 1.26 retrieving revision 1.27 diff -u -r1.26 -r1.27 --- config.php 21 Mar 2002 13:44:54 -0000 1.26 +++ config.php 29 Mar 2002 18:25:37 -0000 1.27 @@ -64,6 +64,7 @@ define ('ONEDAY', 86400); +require_once (INSTALL_PATH.'/inc/db/'.DB_TYPE.'.php'); require_once (INSTALL_PATH.'/inc/auth.php'); require_once (INSTALL_PATH.'/inc/template.php'); Index: include.php =================================================================== RCS file: /cvsroot/phpbt/phpbt/include.php,v retrieving revision 1.104 retrieving revision 1.105 diff -u -r1.104 -r1.105 --- include.php 28 Mar 2002 22:14:44 -0000 1.104 +++ include.php 29 Mar 2002 18:25:37 -0000 1.105 @@ -97,21 +97,19 @@ class templateclass extends Template { function pparse($target, $handle, $append = false) { - global $_sv, $perm, $db, $HTTP_COOKIE_VARS; + global $_sv, $perm, $db, $HTTP_COOKIE_VARS, $QUERY; $u = isset($_sv['uid']) ? $_sv['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) = $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", - 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", - DB_FETCHMODE_ORDERED); + list($owner_open, $owner_closed) = + $db->getRow(sprintf($QUERY['include-template-owner'], $u), + DB_FETCHMODE_ORDERED); + list($reporter_open, $reporter_closed) = + $db->getRow(sprintf($QUERY['include-template-reporter'], $u), + DB_FETCHMODE_ORDERED); $this->set_var(array( 'loggedinas' => $_sv['uname'], 'liblock' => '', Index: index.php =================================================================== RCS file: /cvsroot/phpbt/phpbt/index.php,v retrieving revision 1.26 retrieving revision 1.27 diff -u -r1.26 -r1.27 --- index.php 28 Mar 2002 22:26:06 -0000 1.26 +++ index.php 29 Mar 2002 18:25:37 -0000 1.27 @@ -125,24 +125,22 @@ $t->set_block('projectsummaryblock', 'projectrow', 'prows'); $t->set_block('projectrow', 'col', 'cols'); if (SHOW_PROJECT_SUMMARIES) { - $querystring = 'select project_name as "Project", sum(case when resolution_id = 0 then 1 else 0 end) as "Open"'; + $querystring = $QUERY['index-projsummary-1']; $resfields = array('Project','Open'); // Grab the resolutions from the database - $rs = $db->query("select resolution_name, ". - db_concat("', sum(case when resolution_id = '", 'resolution_id', - "' then 1 else 0 end) as \"'", 'resolution_name' ,"'\"'"). - " from ".TBL_RESOLUTION); + $rs = $db->query($QUERY['index-projsummary-2']. + db_concat($QUERY['index-projsummary-3'], 'resolution_id', + $QUERY['index-projsummary-4'], 'resolution_name' ,"'\"'"). + $QUERY['index-projsummary-5']); while (list($fieldname, $countquery) = $rs->fetchRow(DB_FETCHMODE_ORDERED)) { $resfields[] = $fieldname; $querystring .= $countquery; } $resfields[] = 'Total'; - $rs = $db->query("$querystring, count(bug_id) as \"Total\" from ".TBL_BUG. - " b left join ".TBL_PROJECT." p using (project_id)". - " where b.project_id not in ($restricted_projects) group by b.project_id,". - " project_name order by project_name"); + $rs = $db->query(sprintf($QUERY['index-projsummary-6'], $querystring, + $restricted_projects)); if (!$rs->numRows()) { $t->set_var('projblock', ''); } else { Index: query.php =================================================================== RCS file: /cvsroot/phpbt/phpbt/query.php,v retrieving revision 1.64 retrieving revision 1.65 diff -u -r1.64 -r1.65 --- query.php 28 Mar 2002 19:13:21 -0000 1.64 +++ query.php 29 Mar 2002 18:25:37 -0000 1.65 @@ -156,7 +156,8 @@ function list_items($assignedto = 0, $reportedby = 0, $open = 0) { global $me, $db, $t, $select, $TITLE, $STRING, $_gv, $u, - $default_db_fields, $all_db_fields, $HTTP_SESSION_VARS, $HTTP_SERVER_VARS; + $default_db_fields, $all_db_fields, $HTTP_SESSION_VARS, $HTTP_SERVER_VARS, + $QUERY; $t->set_file('content','buglist.html'); $t->set_block('content','row','rows'); @@ -196,10 +197,9 @@ $HTTP_SESSION_VARS['queryinfo'] = array(); } - $nr = $db->getOne('select count(*) from '.TBL_BUG.' b - left join '.TBL_AUTH_USER.' owner on b.assigned_to = owner.user_id - left join '.TBL_AUTH_USER.' reporter on b.created_by = reporter.user_id '. - (!empty($HTTP_SESSION_VARS['queryinfo']['query']) ? "where {$HTTP_SESSION_VARS['queryinfo']['query']}": '')); + $nr = $db->getOne($QUERY['query-list-bugs-count']. + (!empty($HTTP_SESSION_VARS['queryinfo']['query']) + ? "where {$HTTP_SESSION_VARS['queryinfo']['query']}": '')); $HTTP_SESSION_VARS['queryinfo']['numrows'] = $nr; list($selrange, $llimit, $npages, $pages) = multipages($nr,$page, @@ -213,20 +213,10 @@ 'project' => build_select('project'), 'TITLE' => $TITLE['buglist'])); - $rs = $db->limitQuery('select b.*, reporter.login as reporter, owner.login as owner, - lastmodifier.login as lastmodifier, project_name, severity_name, severity_color, status_name, - os_name, version_name, component_name, resolution_name from '.TBL_BUG.' b - left join '.TBL_AUTH_USER.' owner on b.assigned_to = owner.user_id - left join '.TBL_AUTH_USER.' reporter on b.created_by = reporter.user_id - left join '.TBL_AUTH_USER.' lastmodifier on b.last_modified_by = lastmodifier.user_id - left join '.TBL_RESOLUTION.' resolution on b.resolution_id = resolution.resolution_id, '. - TBL_SEVERITY.' severity, '.TBL_STATUS.' status, '.TBL_OS.' os, '. - TBL_VERSION.' version, '.TBL_COMPONENT.' component, '.TBL_PROJECT.' project - where b.severity_id = severity.severity_id and b.status_id = status.status_id - and b.os_id = os.os_id and b.version_id = version.version_id - and b.component_id = component.component_id and b.project_id = project.project_id '. - (!empty($HTTP_SESSION_VARS['queryinfo']['query']) ? "and {$HTTP_SESSION_VARS['queryinfo']['query']} " : ''). - "order by $order $sort, bug_id asc", $llimit, $selrange); + $rs = $db->limitQuery(sprintf($QUERY['query-list-bugs'], + (!empty($HTTP_SESSION_VARS['queryinfo']['query']) + ? "and {$HTTP_SESSION_VARS['queryinfo']['query']} " : ''), + $order, $sort), $llimit, $selrange); $headers = array( 'bug_id' => 'bug_id', Index: report.php =================================================================== RCS file: /cvsroot/phpbt/phpbt/report.php,v retrieving revision 1.21 retrieving revision 1.22 diff -u -r1.21 -r1.22 --- report.php 27 Mar 2002 18:01:33 -0000 1.21 +++ report.php 29 Mar 2002 18:25:37 -0000 1.22 @@ -25,21 +25,21 @@ include 'include.php'; function resolution_by_engineer($projectid = 0) { - global $db, $t, $restricted_projects, $perm; + global $db, $t, $restricted_projects, $perm, $QUERY; $t->set_block('content', 'row', 'rows'); $t->set_block('row', 'col', 'cols'); $t->set_var('reporttitle', 'Bug resolutions'); // Start off our query - $querystring = 'select email as "Assigned To", sum(case when resolution_id = 0 then 1 else 0 end) as "Open"'; + $querystring = $QUERY['report-resbyeng-1']; $resfields = array('Assigned To','Open'); // Grab the resolutions from the database - $rs = $db->query("select resolution_name, ". - db_concat("', sum(case when resolution_id = '", 'resolution_id', - "' then 1 else 0 end) as \"'", 'resolution_name' ,"'\"'"). - " from ".TBL_RESOLUTION); + $rs = $db->query($QUERY['report-resbyeng-2']. + db_concat($QUERY['report-resbyeng-3'], 'resolution_id', + $QUERY['report-resbyeng-4'], 'resolution_name' ,"'\"'"). + $QUERY['report-resbyeng-5']); while (list($fieldname, $countquery) = $rs->fetchRow(DB_FETCHMODE_ORDERED)) { $resfields[] = $fieldname; $querystring .= $countquery; @@ -47,16 +47,16 @@ $resfields[] = 'Total'; if ($projectid && is_numeric($projectid)) { - $projectquery = "where project_id = $projectid"; + $projectquery = $QUERY['report-resbyeng-where']." project_id = $projectid"; } elseif (!$perm->have_perm('Admin')) { - $projectquery = "where project_id not in ($restricted_projects)"; + $projectquery = $QUERY['report-resbyeng-where']. + " project_id not in ($restricted_projects)"; } else { $projectquery = ''; } - $rs = $db->query("$querystring, count(bug_id) as \"Total\" from ".TBL_BUG. - " b left join ".TBL_AUTH_USER." u on assigned_to = user_id $projectquery ". - "group by assigned_to, u.email"); + $rs = $db->query(sprintf($QUERY['report-resbyeng-6'], $querystring, + $projectquery)); if (!$rs->numRows()) { $t->set_var('rows', 'No data to display'); } else { |