Ignore:
Timestamp:
May 30, 2006 9:30:35 PM (18 years ago)
Author:
scdev
Message:

finished updating DB:: to $db->

Location:
branches/2.0singleton/lib
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • branches/2.0singleton/lib/Auth_SQL.inc.php

    r127 r130  
    118118    {
    119119        $app =& App::getInstance();
     120        $db =& DB::getInstance();
     121   
    120122   
    121123        static $_db_tested = false;
     
    125127            // User table.
    126128            if ($recreate_db) {
    127                 DB::query("DROP TABLE IF EXISTS " . $this->getParam('db_table'));
     129                $db->query("DROP TABLE IF EXISTS " . $this->getParam('db_table'));
    128130                $app->logMsg(sprintf('Dropping and recreating table %s.', $this->getParam('db_table')), LOG_DEBUG, __FILE__, __LINE__);
    129131            }
    130132
    131133            // The minimal columns for a table compatable with the Auth_SQL class.
    132             DB::query("CREATE TABLE IF NOT EXISTS " . $this->getParam('db_table') . " (
     134            $db->query("CREATE TABLE IF NOT EXISTS " . $this->getParam('db_table') . " (
    133135                " . $this->getParam('db_primary_key') . " smallint(11) NOT NULL auto_increment,
    134136                " . $this->getParam('db_username_column') . " varchar(255) NOT NULL default '',
     
    156158            )");
    157159
    158             if (!DB::columnExists($this->getParam('db_table'), array(
     160            if (!$db->columnExists($this->getParam('db_table'), array(
    159161                $this->getParam('db_primary_key'),
    160162                $this->getParam('db_username_column'),
     
    184186            if ($this->getParam('abuse_detection')) {
    185187                if ($recreate_db) {
    186                     DB::query("DROP TABLE IF EXISTS " . $this->getParam('db_login_table'));
     188                    $db->query("DROP TABLE IF EXISTS " . $this->getParam('db_login_table'));
    187189                    $app->logMsg(sprintf('Dropping and recreating table %s.', $this->getParam('db_login_table')), LOG_DEBUG, __FILE__, __LINE__);
    188190                }
    189                 DB::query("CREATE TABLE IF NOT EXISTS " . $this->getParam('db_login_table') . " (
     191                $db->query("CREATE TABLE IF NOT EXISTS " . $this->getParam('db_login_table') . " (
    190192                    " . $this->getParam('db_primary_key') . " smallint(11) NOT NULL default '0',
    191193                    login_datetime datetime NOT NULL default '0000-00-00 00:00:00',
     
    196198                )");
    197199
    198                 if (!DB::columnExists($this->getParam('db_login_table'), array(
     200                if (!$db->columnExists($this->getParam('db_login_table'), array(
    199201                    $this->getParam('db_primary_key'),
    200202                    'login_datetime',
     
    249251    function clearAuth()
    250252    {
     253        $db =& DB::getInstance();
     254   
    251255        $this->initDB();
    252256
    253         DB::query("
     257        $db->query("
    254258            UPDATE " . $this->_params['db_table'] . " SET
    255259            seconds_online = seconds_online + (UNIX_TIMESTAMP() - UNIX_TIMESTAMP(last_access_datetime)),
     
    305309    {
    306310        $app =& App::getInstance();
    307    
     311        $db =& DB::getInstance();
     312
    308313        $this->initDB();
    309314
    310315        // Query DB for user matching credentials.
    311316        // FIXME: Cannot compare crypt style passwords this way.
    312         $qid = DB::query("
     317        $qid = $db->query("
    313318            SELECT *, " . $this->_params['db_primary_key'] . " AS user_id
    314319            FROM " . $this->_params['db_table'] . "
    315             WHERE " . $this->_params['db_username_column'] . " = '" . DB::escapeString($username) . "'
    316             AND BINARY userpass = '" . DB::escapeString($this->encryptPassword($password)) . "'
     320            WHERE " . $this->_params['db_username_column'] . " = '" . $db->escapeString($username) . "'
     321            AND BINARY userpass = '" . $db->escapeString($this->encryptPassword($password)) . "'
    317322        ");
    318323
     
    338343    {
    339344        $app =& App::getInstance();
    340    
     345        $db =& DB::getInstance();
     346   
    341347        $this->initDB();
    342348
     
    390396        **/
    391397        if ($this->getParam('abuse_detection') && !$this->getVal('login_abuse_exempt')) {
    392             $qid = DB::query("
     398            $qid = $db->query("
    393399                SELECT COUNT(DISTINCT LEFT(remote_ip_binary, " . $this->_params['login_abuse_ip_bitmask'] . "))
    394400                FROM " . $this->_params['db_login_table'] . "
     
    410416                }
    411417                // Increment user's warning level.
    412                 DB::query("UPDATE " . $this->_params['db_table'] . " SET abuse_warning_level = abuse_warning_level + 1 WHERE " . $this->_params['db_primary_key'] . " = '" . $this->getVal('user_id') . "'");
     418                $db->query("UPDATE " . $this->_params['db_table'] . " SET abuse_warning_level = abuse_warning_level + 1 WHERE " . $this->_params['db_primary_key'] . " = '" . $this->getVal('user_id') . "'");
    413419                // Reset the login counter for this user.
    414                 DB::query("DELETE FROM " . $this->_params['db_login_table'] . " WHERE " . $this->_params['db_primary_key'] . " = '" . $this->getVal('user_id') . "'");
     420                $db->query("DELETE FROM " . $this->_params['db_login_table'] . " WHERE " . $this->_params['db_primary_key'] . " = '" . $this->getVal('user_id') . "'");
    415421                // No login: reset password because of account abuse!
    416422                $this->clearAuth();
     
    419425
    420426            // Update the login counter table with this login access. Convert IP to binary.
    421             DB::query("
     427            $db->query("
    422428                INSERT INTO " . $this->_params['db_login_table'] . " (
    423429                    " . $this->_params['db_primary_key'] . ",
     
    433439
    434440        // Update user table with this login.
    435         DB::query("
     441        $db->query("
    436442            UPDATE " . $this->_params['db_table'] . " SET
    437443                last_login_datetime = '" . $this->getVal('login_datetime') . "',
     
    458464    {
    459465        $app =& App::getInstance();
    460    
     466        $db =& DB::getInstance();
     467   
    461468        $this->initDB();
    462469
    463470        if (isset($user_id)) {
    464471            // Check the login status of a specific user.
    465             $qid = DB::query("
     472            $qid = $db->query("
    466473                SELECT 1 FROM " . $this->_params['db_table'] . "
    467                 WHERE " . $this->_params['db_primary_key'] . " = '" . DB::escapeString($user_id) . "'
     474                WHERE " . $this->_params['db_primary_key'] . " = '" . $db->escapeString($user_id) . "'
    468475                AND DATE_ADD(last_login_datetime, INTERVAL '" . $this->_params['login_timeout'] . "' SECOND) > NOW()
    469476                AND DATE_ADD(last_access_datetime, INTERVAL '" . $this->_params['idle_timeout'] . "' SECOND) > NOW()
     
    510517
    511518            // Update the DB with the last_access_datetime and increment the seconds_online.
    512             DB::query("
     519            $db->query("
    513520                UPDATE " . $this->_params['db_table'] . " SET
    514521                seconds_online = seconds_online + (UNIX_TIMESTAMP() - UNIX_TIMESTAMP(last_access_datetime)) + 1,
     
    516523                WHERE " . $this->_params['db_primary_key'] . " = '" . $this->getVal('user_id') . "'
    517524            ");
    518             if (mysql_affected_rows(DB::getDBH()) > 0) {
     525            if (mysql_affected_rows($db->getDBH()) > 0) {
    519526                // User record still exists in DB. Do this to ensure user was not delete from DB between accesses. Notice "+ 1" in SQL above to ensure record is modified.
    520527                return true;
     
    584591    {
    585592        $app =& App::getInstance();
    586    
     593        $db =& DB::getInstance();
     594   
    587595        $this->initDB();
    588596
    589597        if ($this->getParam('blocking')) {
    590             if (strlen(DB::escapeString($reason)) > 255) {
     598            if (strlen($db->escapeString($reason)) > 255) {
    591599                // blocked_reason field is varchar(255).
    592600                $app->logMsg(sprintf('Blocked reason provided is greater than 255 characters: %s', $reason), LOG_WARNING, __FILE__, __LINE__);
     
    595603            // Get user_id if specified.
    596604            $user_id = isset($user_id) ? $user_id : $this->getVal('user_id');
    597             DB::query("
     605            $db->query("
    598606                UPDATE " . $this->_params['db_table'] . " SET
    599607                blocked = 'true',
    600                 blocked_reason = '" . DB::escapeString($reason) . "'
    601                 WHERE " . $this->_params['db_primary_key'] . " = '" . DB::escapeString($user_id) . "'
     608                blocked_reason = '" . $db->escapeString($reason) . "'
     609                WHERE " . $this->_params['db_primary_key'] . " = '" . $db->escapeString($user_id) . "'
    602610            ");
    603611        }
     
    609617    function unblockAccount($user_id=null)
    610618    {
     619        $db =& DB::getInstance();
     620   
    611621        $this->initDB();
    612 
     622   
    613623        if ($this->getParam('blocking')) {
    614624            // Get user_id if specified.
    615625            $user_id = isset($user_id) ? $user_id : $this->getVal('user_id');
    616             DB::query("
     626            $db->query("
    617627                UPDATE " . $this->_params['db_table'] . " SET
    618628                blocked = '',
    619629                blocked_reason = ''
    620                 WHERE " . $this->_params['db_primary_key'] . " = '" . DB::escapeString($user_id) . "'
     630                WHERE " . $this->_params['db_primary_key'] . " = '" . $db->escapeString($user_id) . "'
    621631            ");
    622632        }
     
    631641    function usernameExists($username)
    632642    {
     643        $db =& DB::getInstance();
     644   
    633645        $this->initDB();
    634646
    635         $qid = DB::query("
     647        $qid = $db->query("
    636648            SELECT 1
    637649            FROM " . $this->_params['db_table'] . "
    638             WHERE " . $this->_params['db_username_column'] . " = '" . DB::escapeString($username) . "'
     650            WHERE " . $this->_params['db_username_column'] . " = '" . $db->escapeString($username) . "'
    639651        ");
    640652        return (mysql_num_rows($qid) > 0);
     
    649661    function getUsername($user_id)
    650662    {
     663        $db =& DB::getInstance();
     664   
    651665        $this->initDB();
    652666
    653         $qid = DB::query("
     667        $qid = $db->query("
    654668            SELECT " . $this->_params['db_username_column'] . "
    655669            FROM " . $this->_params['db_table'] . "
    656             WHERE " . $this->_params['db_primary_key'] . " = '" . DB::escapeString($user_id) . "'
     670            WHERE " . $this->_params['db_primary_key'] . " = '" . $db->escapeString($user_id) . "'
    657671        ");
    658672        if (list($username) = mysql_fetch_row($qid)) {
     
    726740    {
    727741        $app =& App::getInstance();
    728    
     742        $db =& DB::getInstance();
     743   
    729744        $this->initDB();
    730745
     
    733748
    734749        // Issue the password change query.
    735         DB::query("
     750        $db->query("
    736751            UPDATE " . $this->_params['db_table'] . "
    737             SET userpass = '" . DB::escapeString($this->encryptPassword($password)) . "'
    738             WHERE " . $this->_params['db_primary_key'] . " = '" . DB::escapeString($user_id) . "'
     752            SET userpass = '" . $db->escapeString($this->encryptPassword($password)) . "'
     753            WHERE " . $this->_params['db_primary_key'] . " = '" . $db->escapeString($user_id) . "'
    739754        ");
    740755       
    741         if (mysql_affected_rows(DB::getDBH()) != 1) {
     756        if (mysql_affected_rows($db->getDBH()) != 1) {
    742757            $app->logMsg(sprintf('setPassword failed to update password for user %s', $user_id), LOG_NOTICE, __FILE__, __LINE__);
    743758        }
     
    754769    {
    755770        $app =& App::getInstance();
    756    
     771        $db =& DB::getInstance();
     772   
    757773        $this->initDB();
    758774
     
    761777
    762778        // Reset password of a specific user.
    763         $qid = DB::query("
     779        $qid = $db->query("
    764780            SELECT * FROM " . $this->_params['db_table'] . "
    765             WHERE " . $this->_params['db_primary_key'] . " = '" . DB::escapeString($user_id) . "'
     781            WHERE " . $this->_params['db_primary_key'] . " = '" . $db->escapeString($user_id) . "'
    766782        ");
    767783        if (!$user_data = mysql_fetch_assoc($qid)) {
  • branches/2.0singleton/lib/Hierarchy.inc.php

    r127 r130  
    152152    {
    153153        $app =& App::getInstance();
     154        $db =& DB::getInstance();
    154155   
    155156        if (!isset($child_type) || !isset($child_id)) {
     
    194195        foreach ($parents as $parent_string) {
    195196            $parent = $this->toArrayID($parent_string);
    196             DB::query("
     197            $db->query("
    197198                INSERT INTO node_tbl (
    198199                    parent_type,
     
    203204                    title
    204205                ) VALUES (
    205                     '" . DB::escapeString($parent['node_type']) . "',
    206                     '" . DB::escapeString($parent['node_id']) . "',
    207                     '" . DB::escapeString($child_type) . "',
    208                     '" . DB::escapeString($child_id) . "',
    209                     " . (is_null($relationship_type) ? "NULL" : "'" . DB::escapeString($relationship_type) . "'") . ",
    210                     '" . DB::escapeString($title) . "'
     206                    '" . $db->escapeString($parent['node_type']) . "',
     207                    '" . $db->escapeString($parent['node_id']) . "',
     208                    '" . $db->escapeString($child_type) . "',
     209                    '" . $db->escapeString($child_id) . "',
     210                    " . (is_null($relationship_type) ? "NULL" : "'" . $db->escapeString($relationship_type) . "'") . ",
     211                    '" . $db->escapeString($title) . "'
    211212                )
    212213            ");
     
    230231    {
    231232        $app =& App::getInstance();
     233        $db =& DB::getInstance();
    232234   
    233235        if (!isset($child_type) || !isset($child_id)) {
     
    251253        }
    252254
    253         DB::query("
     255        $db->query("
    254256            DELETE FROM node_tbl
    255             WHERE child_type = '" . DB::escapeString($child_type) . "'
    256             AND child_id = '" . DB::escapeString($child_id) . "'
     257            WHERE child_type = '" . $db->escapeString($child_type) . "'
     258            AND child_id = '" . $db->escapeString($child_id) . "'
    257259        ");
    258260        $app->logMsg(sprintf('deleteNode: Deleted node %s %s.', $child_type, $child_id), LOG_DEBUG, __FILE__, __LINE__);
     
    279281    {
    280282            $app =& App::getInstance();
    281    
     283            $db =& DB::getInstance();
     284
    282285            if (!isset($child_type) || !isset($child_id)) {
    283286            if ($this->node_init) {
     
    319322        if (empty($title)) {
    320323            // Select the title of the node we are moving, so we can add it again with the same info.
    321             $qid = DB::query("
     324            $qid = $db->query("
    322325                SELECT title FROM node_tbl
    323                 WHERE child_type = '" . DB::escapeString($child_type) . "'
    324                 AND child_id = '" . DB::escapeString($child_id) . "'
    325                 AND relationship_type " . (is_null($relationship_type) ? "IS NULL" : "= '" . DB::escapeString($relationship_type) . "'") . "
     326                WHERE child_type = '" . $db->escapeString($child_type) . "'
     327                AND child_id = '" . $db->escapeString($child_id) . "'
     328                AND relationship_type " . (is_null($relationship_type) ? "IS NULL" : "= '" . $db->escapeString($relationship_type) . "'") . "
    326329            ");
    327330            list($title) = mysql_fetch_row($qid);
     
    329332
    330333        // Delete the nodes with the old parents.
    331         DB::query("
     334        $db->query("
    332335            DELETE FROM node_tbl
    333             WHERE child_type = '" . DB::escapeString($child_type) . "'
    334             AND child_id = '" . DB::escapeString($child_id) . "'
    335             AND relationship_type " . (is_null($relationship_type) ? "IS NULL" : "= '" . DB::escapeString($relationship_type) . "'") . "
     336            WHERE child_type = '" . $db->escapeString($child_type) . "'
     337            AND child_id = '" . $db->escapeString($child_id) . "'
     338            AND relationship_type " . (is_null($relationship_type) ? "IS NULL" : "= '" . $db->escapeString($relationship_type) . "'") . "
    336339        ");
    337340        $app->logMsg(sprintf('moveNode: Deleted node %s %s.', $child_type, $child_id), LOG_DEBUG, __FILE__, __LINE__);
     
    355358    {
    356359        $app =& App::getInstance();
     360        $db =& DB::getInstance();
    357361   
    358362        if (!isset($child_type) || !isset($child_id)) {
     
    374378        }
    375379
    376         $qid = DB::query("
     380        $qid = $db->query("
    377381            SELECT parent_type, parent_id
    378382            FROM node_tbl
    379             WHERE child_type = '" . DB::escapeString($child_type) . "'
    380             AND child_id = '" . DB::escapeString($child_id) . "'
     383            WHERE child_type = '" . $db->escapeString($child_type) . "'
     384            AND child_id = '" . $db->escapeString($child_id) . "'
    381385            $in_clause
    382             " . DB::escapeString($order) . "
     386            " . $db->escapeString($order) . "
    383387        ");
    384388
     
    405409    {
    406410        $app =& App::getInstance();
     411        $db =& DB::getInstance();
    407412   
    408413        if (!isset($child_type) || !isset($child_id)) {
     
    416421        }
    417422
    418         $qid = DB::query("
     423        $qid = $db->query("
    419424            SELECT child_type, child_id, title, subnode_quantity
    420425            FROM node_tbl
    421             WHERE child_type = '" . DB::escapeString($child_type) . "'
    422             AND child_id = '" . DB::escapeString($child_id) . "'
     426            WHERE child_type = '" . $db->escapeString($child_type) . "'
     427            AND child_id = '" . $db->escapeString($child_id) . "'
    423428        ");
    424429
     
    448453    {
    449454        $app =& App::getInstance();
     455        $db =& DB::getInstance();
    450456   
    451457        if (!isset($child_type) || !isset($child_id)) {
     
    467473        }
    468474
    469         $qid = DB::query("
     475        $qid = $db->query("
    470476            SELECT *
    471477            FROM node_tbl
    472             WHERE parent_type = '" . DB::escapeString($child_type) . "'
    473             AND parent_id = '" . DB::escapeString($child_id) . "'
     478            WHERE parent_type = '" . $db->escapeString($child_type) . "'
     479            AND parent_id = '" . $db->escapeString($child_id) . "'
    474480            $in_clause
    475             " . DB::escapeString($order) . "
     481            " . $db->escapeString($order) . "
    476482        ");
    477483
     
    499505    {
    500506        $app =& App::getInstance();
    501    
     507        $db =& DB::getInstance();
     508
    502509        if (!isset($child_type) || !isset($child_id)) {
    503510            if ($this->node_init) {
     
    518525        }
    519526
    520         $qid = DB::query("
     527        $qid = $db->query("
    521528            SELECT COUNT(*)
    522529            FROM node_tbl
    523             WHERE parent_type = '" . DB::escapeString($child_type) . "'
    524             AND parent_id = '" . DB::escapeString($child_id) . "'
     530            WHERE parent_type = '" . $db->escapeString($child_type) . "'
     531            AND parent_id = '" . $db->escapeString($child_id) . "'
    525532            $in_clause
    526533        ");
     
    599606    function getAllAncestors($child_type, $child_id, $go_linear=false, $_return_flag=true)
    600607    {
     608        $db =& DB::getInstance();
     609   
    601610        static $output = array();
    602611        static $return_flag;
    603612
    604         $qid = DB::query("
     613        $qid = $db->query("
    605614            SELECT parent_type, parent_id, child_type, child_id, title, subnode_quantity
    606615            FROM node_tbl
    607             WHERE child_type = '" . DB::escapeString($child_type) . "'
    608             AND child_id = '" . DB::escapeString($child_id) . "'
     616            WHERE child_type = '" . $db->escapeString($child_type) . "'
     617            AND child_id = '" . $db->escapeString($child_id) . "'
    609618        ");
    610619        while ($row = mysql_fetch_assoc($qid)) {
     
    652661    {
    653662        $app =& App::getInstance();
     663        $db =& DB::getInstance();
    654664   
    655665        if (!isset($child_type) || !isset($child_id)) {
     
    664674
    665675        if (isset($parent_type) && isset($parent_id)) {
    666             $qid = DB::query("
     676            $qid = $db->query("
    667677                SELECT 1 FROM node_tbl
    668                 WHERE parent_type = '" . DB::escapeString($parent_type) . "'
    669                 AND parent_id = '" . DB::escapeString($parent_id) . "'
    670                 AND child_type = '" . DB::escapeString($child_type) . "'
    671                 AND child_id = '" . DB::escapeString($child_id) . "'
    672                 AND relationship_type " . (is_null($relationship_type) ? "IS NULL" : "= '" . DB::escapeString($relationship_type) . "'") . "
     678                WHERE parent_type = '" . $db->escapeString($parent_type) . "'
     679                AND parent_id = '" . $db->escapeString($parent_id) . "'
     680                AND child_type = '" . $db->escapeString($child_type) . "'
     681                AND child_id = '" . $db->escapeString($child_id) . "'
     682                AND relationship_type " . (is_null($relationship_type) ? "IS NULL" : "= '" . $db->escapeString($relationship_type) . "'") . "
    673683            ");
    674684        } else {
    675             $qid = DB::query("
     685            $qid = $db->query("
    676686                SELECT 1 FROM node_tbl
    677                 WHERE child_type = '" . DB::escapeString($child_type) . "'
    678                 AND child_id = '" . DB::escapeString($child_id) . "'
     687                WHERE child_type = '" . $db->escapeString($child_type) . "'
     688                AND child_id = '" . $db->escapeString($child_id) . "'
    679689            ");
    680690        }
     
    775785    function rebuildSubnodeQty($type_constraint=null)
    776786    {
     787        $db =& DB::getInstance();
     788   
    777789        // Reset all the category counters to zero.
    778         DB::query("UPDATE node_tbl SET subnode_quantity = 0");
     790        $db->query("UPDATE node_tbl SET subnode_quantity = 0");
    779791
    780792        // Get all the nodes.
    781         $qid = DB::query("SELECT DISTINCT child_type, child_id FROM node_tbl");
     793        $qid = $db->query("SELECT DISTINCT child_type, child_id FROM node_tbl");
    782794
    783795        // For each node count the number of children...
     
    797809    function setSubnodeQtyToParents($child_type, $child_id, $num_children)
    798810    {
    799         DB::query("
     811        $db =& DB::getInstance();
     812   
     813        $db->query("
    800814            UPDATE node_tbl
    801             SET subnode_quantity = subnode_quantity + '" . DB::escapeString($num_children) . "'
    802             WHERE child_type = '" . DB::escapeString($child_type) . "'
    803             AND child_id = '" . DB::escapeString($child_id) . "'
     815            SET subnode_quantity = subnode_quantity + '" . $db->escapeString($num_children) . "'
     816            WHERE child_type = '" . $db->escapeString($child_type) . "'
     817            AND child_id = '" . $db->escapeString($child_id) . "'
    804818        ",false);
    805         $qid = DB::query("
     819        $qid = $db->query("
    806820            SELECT parent_type, parent_id
    807821            FROM node_tbl
    808             WHERE child_type = '" . DB::escapeString($child_type) . "'
    809             AND child_id = '" . DB::escapeString($child_id) . "'
     822            WHERE child_type = '" . $db->escapeString($child_type) . "'
     823            AND child_id = '" . $db->escapeString($child_id) . "'
    810824        ",false);
    811825        while ((list($parent_type, $parent_id) = mysql_fetch_row($qid)) && $parent_id > 0) {
  • branches/2.0singleton/lib/PageNumbers.inc.php

    r128 r130  
    192192    {
    193193        $app =& App::getInstance();
     194        $db =& DB::getInstance();
    194195
    195196        if (is_numeric($this->first_item) && is_numeric($this->_per_page)) {
    196             return ' LIMIT ' . DB::escapeString($this->first_item) . ', ' . DB::escapeString($this->_per_page) . ' ';
     197            return ' LIMIT ' . $db->escapeString($this->first_item) . ', ' . $db->escapeString($this->_per_page) . ' ';
    197198        } else {
    198199            $app->logMsg(sprintf('Could not find SQL to LIMIT by %s %s.', $this->first_item, $this->_per_page), LOG_WARNING, __FILE__, __LINE__);
  • branches/2.0singleton/lib/RecordLock.inc.php

    r128 r130  
    7272    {
    7373        $app =& App::getInstance();
     74        $db =& DB::getInstance();
    7475
    7576        static $_db_tested = false;
     
    7778        if ($recreate_db || !$_db_tested && $this->getParam('create_table')) {
    7879            if ($recreate_db) {
    79                 DB::query("DROP TABLE IF EXISTS " . $this->getParam('db_table'));
     80                $db->query("DROP TABLE IF EXISTS " . $this->getParam('db_table'));
    8081                $app->logMsg(sprintf('Dropping and recreating table %s.', $this->getParam('db_table')), LOG_DEBUG, __FILE__, __LINE__);
    8182            }
    82             DB::query("CREATE TABLE IF NOT EXISTS " . $this->getParam('db_table') . " (
     83            $db->query("CREATE TABLE IF NOT EXISTS " . $this->getParam('db_table') . " (
    8384                lock_id int NOT NULL auto_increment,
    8485                record_table varchar(255) NOT NULL default '',
     
    9495            )");
    9596
    96             if (!DB::columnExists($this->getParam('db_table'), array(
     97            if (!$db->columnExists($this->getParam('db_table'), array(
    9798                'lock_id',
    9899                'record_table',
     
    154155    {
    155156        $app =& App::getInstance();
     157        $db =& DB::getInstance();
    156158
    157159        $this->initDB();
     
    162164        if (is_numeric($record_table_or_lock_id) && !isset($record_key) && !isset($record_val)) {
    163165            // Get lock data by lock_id.
    164             $qid = DB::query("
     166            $qid = $db->query("
    165167                SELECT * FROM " . $this->getParam('db_table') . "
    166                 WHERE lock_id = '" . DB::escapeString($record_table_or_lock_id) . "'
     168                WHERE lock_id = '" . $db->escapeString($record_table_or_lock_id) . "'
    167169            ");
    168170        } else {
    169171            // Get lock data by record specs
    170             $qid = DB::query("
     172            $qid = $db->query("
    171173                SELECT * FROM " . $this->getParam('db_table') . "
    172                 WHERE record_table = '" . DB::escapeString($record_table_or_lock_id) . "'
    173                 AND record_key = '" . DB::escapeString($record_key) . "'
    174                 AND record_val = '" . DB::escapeString($record_val) . "'
     174                WHERE record_table = '" . $db->escapeString($record_table_or_lock_id) . "'
     175                AND record_key = '" . $db->escapeString($record_key) . "'
     176                AND record_val = '" . $db->escapeString($record_val) . "'
    175177            ");
    176178        }
     
    204206    function isMine()
    205207    {
     208        $db =& DB::getInstance();
     209   
    206210        $this->initDB();
    207211
    208212        if (isset($this->data['lock_id'])) {
    209             $qid = DB::query("SELECT * FROM " . $this->getParam('db_table') . " WHERE lock_id = '" . DB::escapeString($this->data['lock_id']) . "'");
     213            $qid = $db->query("SELECT * FROM " . $this->getParam('db_table') . " WHERE lock_id = '" . $db->escapeString($this->data['lock_id']) . "'");
    210214            if ($lock = mysql_fetch_assoc($qid)) {
    211215                return ($lock['set_by_admin_id'] == $this->_auth->getVal('user_id'));
     
    230234    function set($record_table, $record_key, $record_val, $title='')
    231235    {
     236        $db =& DB::getInstance();
     237   
    232238        $this->initDB();
    233239
     
    236242
    237243        // Remove previous locks if exist. Is this better than using a REPLACE INTO?
    238         DB::query("
     244        $db->query("
    239245            DELETE FROM " . $this->getParam('db_table') . "
    240             WHERE record_table = '" . DB::escapeString($record_table) . "'
    241             AND record_key = '" . DB::escapeString($record_key) . "'
    242             AND record_val = '" . DB::escapeString($record_val) . "'
     246            WHERE record_table = '" . $db->escapeString($record_table) . "'
     247            AND record_key = '" . $db->escapeString($record_key) . "'
     248            AND record_val = '" . $db->escapeString($record_val) . "'
    243249        ");
    244250
    245251        // Set new lock.
    246         DB::query("
     252        $db->query("
    247253            INSERT INTO " . $this->getParam('db_table') . " (
    248254                record_table,
     
    253259                lock_datetime
    254260            ) VALUES (
    255                 '" . DB::escapeString($record_table) . "',
    256                 '" . DB::escapeString($record_key) . "',
    257                 '" . DB::escapeString($record_val) . "',
    258                 '" . DB::escapeString($title) . "',
    259                 '" . DB::escapeString($this->_auth->getVal('user_id')) . "',
     261                '" . $db->escapeString($record_table) . "',
     262                '" . $db->escapeString($record_key) . "',
     263                '" . $db->escapeString($record_val) . "',
     264                '" . $db->escapeString($title) . "',
     265                '" . $db->escapeString($this->_auth->getVal('user_id')) . "',
    260266                NOW()
    261267            )
    262268        ");
    263         $lock_id = mysql_insert_id(DB::getDBH());
     269        $lock_id = mysql_insert_id($db->getDBH());
    264270
    265271        // Must register this locked record as the current.
     
    275281    {
    276282        $app =& App::getInstance();
     283        $db =& DB::getInstance();
    277284
    278285        $this->initDB();
     
    282289
    283290        // Delete a specific lock.
    284         DB::query("
     291        $db->query("
    285292            DELETE FROM " . $this->getParam('db_table') . "
    286             WHERE lock_id = '" . DB::escapeString($this->data['lock_id']) . "'
     293            WHERE lock_id = '" . $db->escapeString($this->data['lock_id']) . "'
    287294        ");
    288295
     
    296303    {
    297304        $app =& App::getInstance();
     305        $db =& DB::getInstance();
    298306
    299307        $this->initDB();
     
    304312        if (isset($user_id)) {
    305313            // Delete specific user's locks.
    306             DB::query("DELETE FROM " . $this->getParam('db_table') . " WHERE set_by_admin_id = '" . DB::escapeString($user_id) . "'");
     314            $db->query("DELETE FROM " . $this->getParam('db_table') . " WHERE set_by_admin_id = '" . $db->escapeString($user_id) . "'");
    307315            $app->logMsg(sprintf('Record locks owned by %s %s have been deleted', $this->_auth->getVal('auth_name'), $this->_auth->getUsername($user_id)), LOG_DEBUG, __FILE__, __LINE__);
    308316        } else {
    309317            // Delete ALL locks.
    310             DB::query("DELETE FROM " . $this->getParam('db_table') . "");
     318            $db->query("DELETE FROM " . $this->getParam('db_table') . "");
    311319            $app->logMsg(sprintf('All record locks deleted by %s %s', $this->_auth->getVal('auth_name'), $this->_auth->getVal('username')), LOG_DEBUG, __FILE__, __LINE__);
    312320        }
     
    318326    function _auto_timeout()
    319327    {
     328        $db =& DB::getInstance();
     329   
    320330        static $_timeout_run = false;
    321331
     
    324334        if (!$_timeout_run) {
    325335            // Delete all old locks.
    326             DB::query("
     336            $db->query("
    327337                DELETE FROM " . $this->getParam('db_table') . "
    328338                WHERE DATE_ADD(lock_datetime, INTERVAL '" . $this->getParam('auto_timeout') . "' SECOND) < NOW()
  • branches/2.0singleton/lib/RecordVersion.inc.php

    r128 r130  
    7979    {
    8080        $app =& App::getInstance();
     81        $db =& DB::getInstance();
    8182
    8283        static $_db_tested = false;
     
    8485        if ($recreate_db || !$_db_tested && $this->getParam('create_table')) {
    8586            if ($recreate_db) {
    86                 DB::query("DROP TABLE IF EXISTS " . $this->getParam('db_table'));
     87                $db->query("DROP TABLE IF EXISTS " . $this->getParam('db_table'));
    8788                $app->logMsg(sprintf('Dropping and recreating table %s.', $this->getParam('db_table')), LOG_DEBUG, __FILE__, __LINE__);
    8889            }
    89             DB::query("CREATE TABLE IF NOT EXISTS " . $this->getParam('db_table') . " (
     90            $db->query("CREATE TABLE IF NOT EXISTS " . $this->getParam('db_table') . " (
    9091                version_id int NOT NULL auto_increment,
    9192                record_table varchar(255) NOT NULL default '',
     
    103104            )");
    104105
    105             if (!DB::columnExists($this->getParam('db_table'), array(
     106            if (!$db->columnExists($this->getParam('db_table'), array(
    106107                'version_id',
    107108                'record_table',
     
    166167    {
    167168        $app =& App::getInstance();
     169        $db =& DB::getInstance();
    168170
    169171        $this->initDB();
     
    179181
    180182        // Save as new version.
    181         DB::query("
     183        $db->query("
    182184            INSERT INTO " . $this->getParam('db_table') . " (
    183185                record_table,
     
    190192                version_datetime
    191193            ) VALUES (
    192                 '" . DB::escapeString($record_table) . "',
    193                 '" . DB::escapeString($record_key) . "',
    194                 '" . DB::escapeString($record_val) . "',
    195                 '" . DB::escapeString(gzcompress(serialize($record), 9)) . "',
    196                 '" . DB::escapeString($title) . "',
    197                 '" . DB::escapeString($notes) . "',
    198                 '" . DB::escapeString($this->_auth->getVal('user_id')) . "',
     194                '" . $db->escapeString($record_table) . "',
     195                '" . $db->escapeString($record_key) . "',
     196                '" . $db->escapeString($record_val) . "',
     197                '" . $db->escapeString(gzcompress(serialize($record), 9)) . "',
     198                '" . $db->escapeString($title) . "',
     199                '" . $db->escapeString($notes) . "',
     200                '" . $db->escapeString($this->_auth->getVal('user_id')) . "',
    199201                NOW()
    200202            )
    201203        ");
    202204
    203         return mysql_insert_id(DB::getDBH());
     205        return mysql_insert_id($db->getDBH());
    204206    }
    205207
     
    214216    {
    215217        $app =& App::getInstance();
     218        $db =& DB::getInstance();
    216219
    217220        $this->initDB();
    218221
    219222        // Get version data.
    220         $qid = DB::query("
     223        $qid = $db->query("
    221224            SELECT * FROM " . $this->getParam('db_table') . "
    222             WHERE version_id = '" . DB::escapeString($version_id) . "'
     225            WHERE version_id = '" . $db->escapeString($version_id) . "'
    223226        ");
    224227        if (!$record = mysql_fetch_assoc($qid)) {
     
    230233
    231234        // Ensure saved db columns match current table schema.
    232         if (!DB::columnExists($record['record_table'], array_keys($data), $this->getParam('db_schema_strict'))) {
     235        if (!$db->columnExists($record['record_table'], array_keys($data), $this->getParam('db_schema_strict'))) {
    233236            $app->raiseMsg(sprintf(_("Version ID %s%s is not compatible with the current database table."), $version_id, (empty($record['version_title']) ? '' : ' (' . $record['version_title'] . ')')), MSG_ERR, __FILE__, __LINE__);
    234237            $app->logMsg(sprintf(_("Version ID %s%s restoration failed, DB schema does not match for table %s."), $version_id, (empty($record['version_title']) ? '' : ' (' . $record['version_title'] . ')'), $record['record_table']), LOG_ALERT, __FILE__, __LINE__);
     
    243246        $comma = '';
    244247        foreach ($data as $v) {
    245             $replace_values .= is_null($v) ? "$comma\nNULL" : "$comma\n'" . DB::escapeString($v) . "'";
     248            $replace_values .= is_null($v) ? "$comma\nNULL" : "$comma\n'" . $db->escapeString($v) . "'";
    246249            $comma = ',';
    247250        }
    248251
    249252        // Replace current record with specified versioned record.
    250         DB::query("
     253        $db->query("
    251254            REPLACE INTO " . $record['record_table'] . " (
    252255                $replace_keys
     
    273276    function deleteOld($record_table, $record_key, $record_val)
    274277    {
     278        $db =& DB::getInstance();
     279   
    275280        $this->initDB();
    276281
    277282        // Get total number of versions for this record.
    278         $qid = DB::query("
     283        $qid = $db->query("
    279284            SELECT COUNT(*) FROM " . $this->getParam('db_table') . "
    280             WHERE record_table = '" . DB::escapeString($record_table) . "'
    281             AND record_key = '" . DB::escapeString($record_key) . "'
    282             AND record_val = '" . DB::escapeString($record_val) . "'
     285            WHERE record_table = '" . $db->escapeString($record_table) . "'
     286            AND record_key = '" . $db->escapeString($record_key) . "'
     287            AND record_val = '" . $db->escapeString($record_val) . "'
    283288        ");
    284289        list($v_count) = mysql_fetch_row($qid);
     
    288293                // To prevent a record bomb, limit max number of versions to max_qty.
    289294                // First query for oldest records, selecting enough to bring total number down to min_qty.
    290                 $qid = DB::query("
     295                $qid = $db->query("
    291296                    SELECT version_id FROM " . $this->getParam('db_table') . "
    292                     WHERE record_table = '" . DB::escapeString($record_table) . "'
    293                     AND record_key = '" . DB::escapeString($record_key) . "'
    294                     AND record_val = '" . DB::escapeString($record_val) . "'
     297                    WHERE record_table = '" . $db->escapeString($record_table) . "'
     298                    AND record_key = '" . $db->escapeString($record_key) . "'
     299                    AND record_val = '" . $db->escapeString($record_val) . "'
    295300                    ORDER BY version_datetime ASC
    296301                    LIMIT " . ($v_count - $this->getParam('min_qty')) . "
     
    299304                    $old_versions[] = $old_id;
    300305                }
    301                 DB::query("
     306                $db->query("
    302307                    DELETE FROM " . $this->getParam('db_table') . "
    303308                    WHERE version_id IN ('" . join("','", $old_versions) . "')
     
    305310            } else {
    306311                // Delete versions older than min_days, while still keeping min_qty.
    307                 $qid = DB::query("
     312                $qid = $db->query("
    308313                    SELECT version_id FROM " . $this->getParam('db_table') . "
    309                     WHERE record_table = '" . DB::escapeString($record_table) . "'
    310                     AND record_key = '" . DB::escapeString($record_key) . "'
    311                     AND record_val = '" . DB::escapeString($record_val) . "'
     314                    WHERE record_table = '" . $db->escapeString($record_table) . "'
     315                    AND record_key = '" . $db->escapeString($record_key) . "'
     316                    AND record_val = '" . $db->escapeString($record_val) . "'
    312317                    AND DATE_ADD(version_datetime, INTERVAL '" . $this->getParam('min_days') . "' DAY) < NOW()
    313318                    ORDER BY version_datetime ASC
     
    318323                }
    319324                if (sizeof($old_versions) > 0) {
    320                     DB::query("
     325                    $db->query("
    321326                        DELETE FROM " . $this->getParam('db_table') . "
    322327                        WHERE version_id IN ('" . join("','", $old_versions) . "')
     
    338343    function getList($record_table, $record_key, $record_val)
    339344    {
     345        $db =& DB::getInstance();
     346   
    340347        $this->initDB();
    341348
    342349        // Get versions of this record.
    343         $qid = DB::query("
     350        $qid = $db->query("
    344351            SELECT version_id, saved_by_admin_id, version_datetime, version_title
    345352            FROM " . $this->getParam('db_table') . "
    346             WHERE record_table = '" . DB::escapeString($record_table) . "'
    347             AND record_key = '" . DB::escapeString($record_key) . "'
    348             AND record_val = '" . DB::escapeString($record_val) . "'
     353            WHERE record_table = '" . $db->escapeString($record_table) . "'
     354            AND record_key = '" . $db->escapeString($record_key) . "'
     355            AND record_val = '" . $db->escapeString($record_val) . "'
    349356            ORDER BY version_datetime DESC
    350357        ");
     
    367374    function getVerson($version_id)
    368375    {
     376        $db =& DB::getInstance();
     377   
    369378        $this->initDB();
    370379
    371380        // Get version data.
    372         $qid = DB::query("
     381        $qid = $db->query("
    373382            SELECT * FROM " . $this->getParam('db_table') . "
    374             WHERE version_id = '" . DB::escapeString($version_id) . "'
     383            WHERE version_id = '" . $db->escapeString($version_id) . "'
    375384        ");
    376385        return mysql_fetch_assoc($qid);
     
    386395    function getData($version_id)
    387396    {
     397        $db =& DB::getInstance();
     398   
    388399        $this->initDB();
    389400
    390401        // Get version data.
    391         $qid = DB::query("
     402        $qid = $db->query("
    392403            SELECT * FROM " . $this->getParam('db_table') . "
    393             WHERE version_id = '" . DB::escapeString($version_id) . "'
     404            WHERE version_id = '" . $db->escapeString($version_id) . "'
    394405        ");
    395406        $record = mysql_fetch_assoc($qid);
     
    410421    function getCurrent($record_table, $record_key, $record_val)
    411422    {
    412         $this->initDB();
    413 
    414         $qid = DB::query("
    415             SELECT * FROM " . DB::escapeString($record_table) . "
    416             WHERE " . DB::escapeString($record_key) . " = '" . DB::escapeString($record_val) . "'
     423        $db =& DB::getInstance();
     424   
     425        $this->initDB();
     426
     427        $qid = $db->query("
     428            SELECT * FROM " . $db->escapeString($record_table) . "
     429            WHERE " . $db->escapeString($record_key) . " = '" . $db->escapeString($record_val) . "'
    417430        ");
    418431        if ($record = mysql_fetch_assoc($qid)) {
  • branches/2.0singleton/lib/SortOrder.inc.php

    r128 r130  
    129129    {
    130130        $app =& App::getInstance();
     131        $db =& DB::getInstance();
    131132
    132133        if (!isset($this->_columns[strtolower($this->sort_by)])) {
     
    139140
    140141        if (!empty($this->_columns[strtolower($this->sort_by)][strtolower($this->order)])) {
    141             return sprintf(' ORDER BY %s ', DB::escapeString($this->_columns[strtolower($this->sort_by)][strtolower($this->order)]));
     142            return sprintf(' ORDER BY %s ', $db->escapeString($this->_columns[strtolower($this->sort_by)][strtolower($this->order)]));
    142143        } else {
    143144            $app->logMsg(sprintf('Could not find SQL to sort by %s %s.', $this->sort_by, $this->order), LOG_WARNING, __FILE__, __LINE__);
  • branches/2.0singleton/lib/TemplateGlue.inc.php

    r128 r130  
    6767{
    6868    $app =& App::getInstance();
    69 
    70     $qid = DB::query("SHOW COLUMNS FROM " . DB::escapeString($db_table) . " LIKE '" . DB::escapeString($db_col) . "'",false);
     69    $db =& DB::getInstance();
     70   
     71    $qid = $db->query("SHOW COLUMNS FROM " . $db->escapeString($db_table) . " LIKE '" . $db->escapeString($db_col) . "'",false);
    7172
    7273    $row = mysql_fetch_row($qid);
     
    296297function printSelectForm($db_table, $key_column, $val_column, $preselected, $blank=false, $extra_clause='')
    297298{
     299    $db =& DB::getInstance();
     300   
    298301    // Sometimes preselected comes as a comma list.
    299302    if (!is_array($preselected)) {
     
    316319        }
    317320    }
    318     $qid = DB::query("SELECT $key_column, $val_column FROM $db_table $extra_clause",false);
     321    $qid = $db->query("SELECT $key_column, $val_column FROM $db_table $extra_clause",false);
    319322    while ($row = mysql_fetch_assoc($qid)) {
    320323        $selected = in_array($row[$val_column], $preselected) ? ' selected="selected"' : '';
     
    337340function printDBCheckboxes($db_table, $key_column, $val_column, $preselected, $columns=1, $extra_clause='', $vert_columns=false)
    338341{
     342    $db =& DB::getInstance();
     343   
    339344    // Sometimes preselected comes as a comma list.
    340345    if (!is_array($preselected)) {
     
    350355    }
    351356
    352     $qid = DB::query("SELECT $key_column, $val_column FROM $db_table $extra_clause",false);
     357    $qid = $db->query("SELECT $key_column, $val_column FROM $db_table $extra_clause",false);
    353358    while ($row = mysql_fetch_assoc($qid)) {
    354359        $values[] = $row;
  • branches/2.0singleton/lib/Utilities.inc.php

    r123 r130  
    476476function escapedList($in)
    477477{
     478    $db =& DB::getInstance();
     479   
    478480    if (is_array($in) && !empty($in)) {
    479481        return "'" . join("', '", array_map(array('DB', 'escapeString'), $in)) . "'";
    480482    } else {
    481         return DB::escapeString($in);
     483        return $db->escapeString($in);
    482484    }
    483485}
Note: See TracChangeset for help on using the changeset viewer.