Changeset 130


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

finished updating DB:: to $db->

Location:
branches/2.0singleton
Files:
22 edited

Legend:

Unmodified
Added
Removed
  • branches/2.0singleton/bin/file_importer.php

    r127 r130  
    99
    1010$app =& App::getInstance();
     11$db =& DB::getInstance();
     12   
    1113
    1214// Test arguments.
     
    3335            preg_match('/BALANCE:\s*\$([\.\d]+)/', $file_text, $amt);
    3436            $file_date = date('Y-m-d', strtotime(preg_replace('|[^_]*_|', '', basename($file))));
    35 //             DB::query("
     37//             $db->query("
    3638//                 INSERT INTO invoice_tbl (
    3739//                     client_id,
     
    4547//                     added_datetime
    4648//                 ) VALUES (
    47 //                     '" . DB::escapeString(0) . "',
    48 //                     '" . DB::escapeString('hosting') . "',
    49 //                     '" . DB::escapeString($file_date) . "',
    50 //                     '" . DB::escapeString($amt[1]) . "',
    51 //                     '" . DB::escapeString('Paid') . "',
    52 //                     '" . DB::escapeString('') . "',
    53 //                     '" . DB::escapeString($file_text) . "',
    54 //                     '" . DB::escapeString($file_date) . "',
     49//                     '" . $db->escapeString(0) . "',
     50//                     '" . $db->escapeString('hosting') . "',
     51//                     '" . $db->escapeString($file_date) . "',
     52//                     '" . $db->escapeString($amt[1]) . "',
     53//                     '" . $db->escapeString('Paid') . "',
     54//                     '" . $db->escapeString('') . "',
     55//                     '" . $db->escapeString($file_text) . "',
     56//                     '" . $db->escapeString($file_date) . "',
    5557//                     NOW()
    5658//                 )
  • branches/2.0singleton/bin/module_maker/form_template.cli.php

    r127 r130  
    1717
    1818// Get DB tables.
    19 $qid = DB::query("SHOW TABLES");
     19$qid = $db->query("SHOW TABLES");
    2020while (list($row) = mysql_fetch_row($qid)) {
    2121    $tables[] = $row;
     
    2828
    2929// Get DB table column info.
    30 $qid = DB::query("DESCRIBE " . DB::escapeString($db_tbl));
     30$qid = $db->query("DESCRIBE " . $db->escapeString($db_tbl));
    3131while ($row = mysql_fetch_row($qid)) {
    3232    $cols[] = $row;
  • branches/2.0singleton/bin/module_maker/list_template.cli.php

    r127 r130  
    3030
    3131// Get DB tables.
    32 $qid = DB::query("SHOW TABLES");
     32$qid = $db->query("SHOW TABLES");
    3333while (list($row) = mysql_fetch_row($qid)) {
    3434    $tables[] = $row;
     
    4141
    4242// Get DB table column info.
    43 $qid = DB::query("DESCRIBE " . DB::escapeString($db_tbl));
     43$qid = $db->query("DESCRIBE " . $db->escapeString($db_tbl));
    4444while ($row = mysql_fetch_row($qid)) {
    4545    $cols[] = $row;
  • branches/2.0singleton/bin/module_maker/module.cli.php

    r127 r130  
    129129
    130130// Get DB tables.
    131 $qid = DB::query("SHOW TABLES");
     131$qid = $db->query("SHOW TABLES");
    132132while (list($row) = mysql_fetch_row($qid)) {
    133133    $tables[] = $row;
     
    141141// Ensure requested table contains columns.
    142142// Get DB table column info.
    143 $qid = DB::query("DESCRIBE " . DB::escapeString($db_tbl));
     143$qid = $db->query("DESCRIBE " . $db->escapeString($db_tbl));
    144144while ($row = mysql_fetch_row($qid)) {
    145145    $cols[] = $row;
  • branches/2.0singleton/bin/module_maker/skel/admin.php

    r127 r130  
    146146        if (getFormdata('repeat', false)) {
    147147            // Display edit function with next available ID.
    148             $qid = DB::query("SELECT %PRIMARY_KEY% FROM %DB_TBL% WHERE %PRIMARY_KEY% > '" . DB::escapeString(getFormData('%PRIMARY_KEY%')) . "' ORDER BY %PRIMARY_KEY% ASC LIMIT 1");
     148            $qid = $db->query("SELECT %PRIMARY_KEY% FROM %DB_TBL% WHERE %PRIMARY_KEY% > '" . $db->escapeString(getFormData('%PRIMARY_KEY%')) . "' ORDER BY %PRIMARY_KEY% ASC LIMIT 1");
    149149            if (list($next_id) = mysql_fetch_row($qid)) {
    150150                $app->dieURL($_SERVER['PHP_SELF'] . '?op=edit&%PRIMARY_KEY%=' . $next_id);
     
    207207{
    208208    global $lock;
    209 
     209    $db =& DB::getInstance();
     210   
    210211    $lock->select('%DB_TBL%', '%PRIMARY_KEY%', $id);
    211212    if ($lock->isLocked() && !$lock->isMine()) {
     
    214215
    215216    // Get the information for the form.
    216     $qid = DB::query("
     217    $qid = $db->query("
    217218        SELECT *
    218219        FROM %DB_TBL%
    219         WHERE %PRIMARY_KEY% = '" . DB::escapeString($id) . "'
     220        WHERE %PRIMARY_KEY% = '" . $db->escapeString($id) . "'
    220221    ");
    221222    if (!$frm = mysql_fetch_assoc($qid)) {
     
    246247{
    247248    global $lock;
    248 
     249    $db =& DB::getInstance();
     250   
    249251    $lock->select('%DB_TBL%', '%PRIMARY_KEY%', $id);
    250252    if ($lock->isLocked() && !$lock->isMine()) {
     
    256258
    257259    // Get the information for this object.
    258     $qid = DB::query("
     260    $qid = $db->query("
    259261        SELECT <##>
    260262        FROM %DB_TBL%
    261         WHERE %PRIMARY_KEY% = '" . DB::escapeString($id) . "'
     263        WHERE %PRIMARY_KEY% = '" . $db->escapeString($id) . "'
    262264    ");
    263265    if (! list($name) = mysql_fetch_row($qid)) {
     
    268270
    269271    // Delete the record.
    270     DB::query("DELETE FROM %DB_TBL% WHERE %PRIMARY_KEY% = '" . DB::escapeString($id) . "'");
     272    $db->query("DELETE FROM %DB_TBL% WHERE %PRIMARY_KEY% = '" . $db->escapeString($id) . "'");
    271273
    272274    $app->raiseMsg(sprintf(_("The %ITEM_TITLE% <strong>%s</strong> has been deleted."), $name), MSG_SUCCESS, __FILE__, __LINE__);
     
    279281{
    280282    global $auth;
    281 
     283    $db =& DB::getInstance();
     284   
    282285    // Break the cache because we are changing the list data.
    283286    SessionCache::breakCache($_SERVER['PHP_SELF']);
    284287
    285288%INSERT%
    286     $last_insert_id = mysql_insert_id(DB::getDBH());
     289    $last_insert_id = mysql_insert_id($db->getDBH());
    287290
    288291    // Create version.
     
    323326    global $page;
    324327    global $so;
    325 
     328    $db =& DB::getInstance();
     329   
    326330    $where_clause = '';
    327331
     
    336340    if (getFormData('filter_<##>', false)) {
    337341        // Limit by filter.
    338         $where_clause .= (empty($where_clause) ? 'WHERE' : 'AND') . " <##> = '" . DB::escapeString(getFormData('filter_<##>')) . "'";
     342        $where_clause .= (empty($where_clause) ? 'WHERE' : 'AND') . " <##> = '" . $db->escapeString(getFormData('filter_<##>')) . "'";
    339343    }
    340344
    341345    // Count the total number of records so we can do something about the page numbers.
    342     $qid = DB::query("
     346    $qid = $db->query("
    343347        SELECT COUNT(*)
    344348        FROM %DB_TBL%
     
    381385    } else {
    382386        // If the list is not already cached, query now.
    383         $qid = DB::query($sql);
     387        $qid = $db->query($sql);
    384388        // Fill an array with the items for this page.
    385389        while ($row = mysql_fetch_assoc($qid)) {
     
    398402function updateRank($ranks)
    399403{
     404    $db =& DB::getInstance();
     405   
    400406    if (!is_array($ranks)) {
    401407        $app->logMsg('Saving rank failed, data posted is not an array: ' . $ranks, LOG_ERR, __FILE__, __LINE__);
     
    416422            $unspecified_counter++;
    417423        }
    418         DB::query("
     424        $db->query("
    419425            UPDATE %DB_TBL% SET
    420                 rank = '" . DB::escapeString($new_rank) . "'
    421             WHERE %PRIMARY_KEY% = '" . DB::escapeString($id) . "'
     426                rank = '" . $db->escapeString($new_rank) . "'
     427            WHERE %PRIMARY_KEY% = '" . $db->escapeString($id) . "'
    422428        ");
    423429    }
  • branches/2.0singleton/bin/module_maker/skel/public.php

    r127 r130  
    3434
    3535    // Get requested record.
    36     $qid = DB::query("
     36    $qid = $db->query("
    3737        SELECT * FROM %DB_TBL%
    38         WHERE %PRIMARY_KEY% = '" . DB::escapeString(getFormData('%PRIMARY_KEY%')) . "'
     38        WHERE %PRIMARY_KEY% = '" . $db->escapeString(getFormData('%PRIMARY_KEY%')) . "'
    3939        AND publish = 'true'
    4040        <##>AND (publish_date <= CURDATE() OR publish_date = '0000-00-00')
     
    4747
    4848    // Update the hit counter for this record.
    49     DB::query("
     49    $db->query("
    5050        UPDATE %DB_TBL%
    5151        SET hit_count = hit_count + 1
    52         WHERE %PRIMARY_KEY% = '" . DB::escapeString(getFormData('%PRIMARY_KEY%')) . "'
     52        WHERE %PRIMARY_KEY% = '" . $db->escapeString(getFormData('%PRIMARY_KEY%')) . "'
    5353    ");
    5454
     
    6161    // Get the DEFAULT list.
    6262    $%NAME_SINGULAR%_list = array();
    63     $qid = DB::query("
     63    $qid = $db->query("
    6464        SELECT *
    6565        FROM %DB_TBL%
     
    7979    // Get the FEATURED list.
    8080    $featured_list = array();
    81     $qid = DB::query("
     81    $qid = $db->query("
    8282        SELECT *
    8383        FROM %DB_TBL%
     
    9292    // Get the POPULAR list.
    9393    $popular_list = array();
    94     $qid = DB::query("
     94    $qid = $db->query("
    9595        SELECT *
    9696        FROM %DB_TBL%
     
    104104    // Get the RECENT list.
    105105    $recent_list = array();
    106     $qid = DB::query("
     106    $qid = $db->query("
    107107        SELECT *
    108108        FROM %DB_TBL%
  • branches/2.0singleton/bin/module_maker/sql.cli.php

    r127 r130  
    3030
    3131// Get DB tables.
    32 $qid = DB::query("SHOW TABLES");
     32$qid = $db->query("SHOW TABLES");
    3333while (list($row) = mysql_fetch_row($qid)) {
    3434    $tables[] = $row;
     
    4646
    4747// Get DB table column info.
    48 $qid = DB::query("DESCRIBE " . DB::escapeString($db_tbl));
     48$qid = $db->query("DESCRIBE " . $db->escapeString($db_tbl));
    4949while ($row = mysql_fetch_row($qid)) {
    5050    $cols[] = $row;
     
    7676        } else if ('added_by_user_id' == $field || 'modified_by_user_id' == $field) {
    7777            // Toggle types.
    78             $c[$field] = "'\" . DB::escapeString(\$auth->getVal('user_id')) . \"'";
     78            $c[$field] = "'\" . \$db->escapeString(\$auth->getVal('user_id')) . \"'";
    7979        } else if ('added_datetime' == $field || 'modified_datetime' == $field) {
    8080            // DB record insertion datetime.
     
    8282        } else {
    8383            // Default. Just insert data.
    84             $c[$field] = "'\" . DB::escapeString(\$frm['$field']) . \"'";
     84            $c[$field] = "'\" . \$db->escapeString(\$frm['$field']) . \"'";
    8585        }
    8686    }
     
    107107echo <<<E_O_F
    108108    // Insert record data.
    109     DB::query("
     109    \$db->query("
    110110        INSERT INTO $db_tbl (
    111111            $db_keys
     
    133133echo <<<E_O_F
    134134    // Update record data.
    135     DB::query("
     135    \$db->query("
    136136        UPDATE $db_tbl SET$key_eq_val
    137         WHERE $primary_key = '" . DB::escapeString(\$frm['$primary_key']) . "'
     137        WHERE $primary_key = '" . \$db->escapeString(\$frm['$primary_key']) . "'
    138138    ");
    139139E_O_F;
     
    148148$delim = 'WHERE';
    149149if (!empty($primary_key)) {
    150     $where_clause = "            $delim $primary_key = '\" . DB::escapeString(\$frm['$primary_key']) . \"'\n";
     150    $where_clause = "            $delim $primary_key = '\" . \$db->escapeString(\$frm['$primary_key']) . \"'\n";
    151151    $delim = 'AND';
    152152}
     
    155155        continue;
    156156    }
    157     $where_clause .= "            $delim $k = '\" . DB::escapeString(\$frm['$k']) . \"'\n";
     157    $where_clause .= "            $delim $k = '\" . \$db->escapeString(\$frm['$k']) . \"'\n";
    158158    $delim = 'AND';
    159159}
    160160echo <<<E_O_F
    161161        // Delete record data.
    162         DB::query("
     162        \$db->query("
    163163            DELETE FROM $db_tbl
    164164$where_clause        ");
     
    183183if (!isset($op) || 'search' == $op) {
    184184$search_skip_columns = array('added_datetime', 'added_by_user_id', 'modified_datetime', 'modified_by_user_id', 'publish', 'featured');
    185 $search_columns = $db_tbl . '.' . join(" LIKE '%\" . DB::escapeString(\$qry_words[\$i]) . \"%'\n                    OR $db_tbl.", array_diff(array_keys($c), $search_skip_columns));
     185$search_columns = $db_tbl . '.' . join(" LIKE '%\" . \$db->escapeString(\$qry_words[\$i]) . \"%'\n                    OR $db_tbl.", array_diff(array_keys($c), $search_skip_columns));
    186186echo <<<E_O_F
    187187            \$where_clause .= (empty(\$where_clause) ? 'WHERE' : 'AND') . "
    188188                (
    189                     $search_columns LIKE '%" . DB::escapeString(\$qry_words[\$i]) . "%'
     189                    $search_columns LIKE '%" . \$db->escapeString(\$qry_words[\$i]) . "%'
    190190                )
    191191            ";
  • branches/2.0singleton/bin/module_maker/validation.cli.php

    r127 r130  
    1717
    1818// Get DB tables.
    19 $qid = DB::query("SHOW TABLES");
     19$qid = $db->query("SHOW TABLES");
    2020while (list($row) = mysql_fetch_row($qid)) {
    2121    $tables[] = $row;
     
    2828
    2929// Get DB table column info.
    30 $qid = DB::query("DESCRIBE " . DB::escapeString($db_tbl));
     30$qid = $db->query("DESCRIBE " . $db->escapeString($db_tbl));
    3131while ($row = mysql_fetch_row($qid)) {
    3232    $cols[] = $row;
  • branches/2.0singleton/docs/coding_standards.txt

    r127 r130  
    214214    function getSetEnumFieldValues()
    215215    {
    216         $qid = DB::query("SHOW COLUMNS FROM $db_table LIKE '$db_col'",false);
     216        $db =& DB::getInstance();
     217       
     218        $qid = $db->query("SHOW COLUMNS FROM $db_table LIKE '$db_col'",false);
    217219
    218220        $row = mysql_fetch_row($qid);
  • 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}
  • branches/2.0singleton/services/admins.php

    r129 r130  
    154154        if (getFormdata('repeat', false)) {
    155155            // Display edit function with next available ID.
    156             $qid = DB::query("SELECT admin_id FROM admin_tbl WHERE admin_id > '" . DB::escapeString(getFormData('admin_id')) . "' ORDER BY admin_id ASC LIMIT 1");
     156            $qid = $db->query("SELECT admin_id FROM admin_tbl WHERE admin_id > '" . $db->escapeString(getFormData('admin_id')) . "' ORDER BY admin_id ASC LIMIT 1");
    157157            if (list($next_id) = mysql_fetch_row($qid)) {
    158158                $app->dieURL($_SERVER['PHP_SELF'] . '?op=edit&admin_id=' . $next_id);
     
    259259    global $lock;
    260260    $app =& App::getInstance();
    261 
     261    $db =& DB::getInstance();
     262   
    262263    $lock->select('admin_tbl', 'admin_id', $id);
    263264    if ($lock->isLocked() && !$lock->isMine()) {
     
    266267
    267268    // Get the information for the form.
    268     $qid = DB::query("
     269    $qid = $db->query("
    269270        SELECT *
    270271        FROM admin_tbl
    271         WHERE admin_id = '" . DB::escapeString($id) . "'
     272        WHERE admin_id = '" . $db->escapeString($id) . "'
    272273    ");
    273274    if (!$frm = mysql_fetch_assoc($qid)) {
     
    315316    global $auth, $lock;
    316317    $app =& App::getInstance();
    317 
     318    $db =& DB::getInstance();
     319   
    318320    $lock->select('admin_tbl', 'admin_id', $id);
    319321    if ($lock->isLocked() && !$lock->isMine()) {
     
    325327
    326328    // Get the information for this object.
    327     $qid = DB::query("
     329    $qid = $db->query("
    328330        SELECT username, user_type from admin_tbl
    329         WHERE admin_id = '" . DB::escapeString($id) . "'
     331        WHERE admin_id = '" . $db->escapeString($id) . "'
    330332    ");
    331333    if (! list($name, $user_type) = mysql_fetch_row($qid)) {
     
    336338
    337339    // Get the information for this object.
    338     $qid = DB::query("SELECT COUNT(*) from admin_tbl");
     340    $qid = $db->query("SELECT COUNT(*) from admin_tbl");
    339341    list($num_admins) = mysql_fetch_row($qid);
    340342    if ('root' == $user_type && 'root' != $auth->getVal('user_type')) {
     
    349351    } else {
    350352        // Delete the record.
    351         DB::query("DELETE FROM admin_tbl WHERE admin_id = '" . DB::escapeString($id) . "'");
     353        $db->query("DELETE FROM admin_tbl WHERE admin_id = '" . $db->escapeString($id) . "'");
    352354        $app->raiseMsg(sprintf(_("The admin <strong>%s</strong> has been deleted."), $name), MSG_SUCCESS, __FILE__, __LINE__);
    353355    }
     
    361363    global $auth;
    362364    $app =& App::getInstance();
    363 
     365    $db =& DB::getInstance();
     366   
    364367    // Break the cache because we are changing the list data.
    365368    SessionCache::breakCache($_SERVER['PHP_SELF']);
    366369
    367370    // Insert record data.
    368     DB::query("
     371    $db->query("
    369372        INSERT INTO admin_tbl (
    370373            username,
     
    376379            added_datetime
    377380        ) VALUES (
    378             '" . DB::escapeString($frm['username']) . "',
    379             '" . DB::escapeString($frm['first_name']) . "',
    380             '" . DB::escapeString($frm['last_name']) . "',
    381             '" . DB::escapeString($frm['email']) . "',
    382             '" . DB::escapeString($frm['user_type']) . "',
    383             '" . DB::escapeString($auth->getVal('user_id')) . "',
     381            '" . $db->escapeString($frm['username']) . "',
     382            '" . $db->escapeString($frm['first_name']) . "',
     383            '" . $db->escapeString($frm['last_name']) . "',
     384            '" . $db->escapeString($frm['email']) . "',
     385            '" . $db->escapeString($frm['user_type']) . "',
     386            '" . $db->escapeString($auth->getVal('user_id')) . "',
    384387            NOW()
    385388        )
    386389    ");
    387     $last_insert_id = mysql_insert_id(DB::getDBH());
     390    $last_insert_id = mysql_insert_id($db->getDBH());
    388391
    389392    // Set admin password.
     
    403406    global $auth, $lock;
    404407    $app =& App::getInstance();
    405 
     408    $db =& DB::getInstance();
     409   
    406410    $lock->select('admin_tbl', 'admin_id', $frm['admin_id']);
    407411    if ($lock->isLocked() && !$lock->isMine()) {
     
    419423
    420424    // Update record data.
    421     DB::query("
     425    $db->query("
    422426        UPDATE admin_tbl SET
    423             username = '" . DB::escapeString($frm['username']) . "',
    424             first_name = '" . DB::escapeString($frm['first_name']) . "',
    425             last_name = '" . DB::escapeString($frm['last_name']) . "',
    426             email = '" . DB::escapeString($frm['email']) . "',
    427             user_type = '" . DB::escapeString($frm['user_type']) . "',
    428             modified_by_user_id = '" . DB::escapeString($auth->getVal('user_id')) . "',
     427            username = '" . $db->escapeString($frm['username']) . "',
     428            first_name = '" . $db->escapeString($frm['first_name']) . "',
     429            last_name = '" . $db->escapeString($frm['last_name']) . "',
     430            email = '" . $db->escapeString($frm['email']) . "',
     431            user_type = '" . $db->escapeString($frm['user_type']) . "',
     432            modified_by_user_id = '" . $db->escapeString($auth->getVal('user_id')) . "',
    429433            modified_datetime = NOW()
    430         WHERE admin_id = '" . DB::escapeString($frm['admin_id']) . "'
     434        WHERE admin_id = '" . $db->escapeString($frm['admin_id']) . "'
    431435    ");
    432436
     
    445449    global $page;
    446450    global $so;
     451    $db =& DB::getInstance();
     452   
    447453
    448454    $where_clause = '';
     
    454460            $where_clause .= (empty($where_clause) ? 'WHERE' : 'AND') . "
    455461                (
    456                     admin_tbl.username LIKE '%" . DB::escapeString($qry_words[$i]) . "%'
    457                     OR admin_tbl.first_name LIKE '%" . DB::escapeString($qry_words[$i]) . "%'
    458                     OR admin_tbl.last_name LIKE '%" . DB::escapeString($qry_words[$i]) . "%'
    459                     OR admin_tbl.email LIKE '%" . DB::escapeString($qry_words[$i]) . "%'
     462                    admin_tbl.username LIKE '%" . $db->escapeString($qry_words[$i]) . "%'
     463                    OR admin_tbl.first_name LIKE '%" . $db->escapeString($qry_words[$i]) . "%'
     464                    OR admin_tbl.last_name LIKE '%" . $db->escapeString($qry_words[$i]) . "%'
     465                    OR admin_tbl.email LIKE '%" . $db->escapeString($qry_words[$i]) . "%'
    460466                )
    461467            ";
     
    464470
    465471    // Count the total number of records so we can do something about the page numbers.
    466     $qid = DB::query("
     472    $qid = $db->query("
    467473        SELECT COUNT(*)
    468474        FROM admin_tbl
     
    505511    } else {
    506512        // If the list is not already cached, query now.
    507         $qid = DB::query($sql);
     513        $qid = $db->query($sql);
    508514        // Fill an array with the items for this page.
    509515        while ($row = mysql_fetch_assoc($qid)) {
  • branches/2.0singleton/tests/AppTest.php

    r129 r130  
    7171    function test_dbquery()
    7272    {
    73         $qid = DB::query("SELECT 2 + 2");
     73        $db =& DB::getInstance();
     74   
     75        $qid = $db->query("SELECT 2 + 2");
    7476        list($result) = mysql_fetch_row($qid);
    7577        $this->assertEquals('4', $result);
  • branches/2.0singleton/tests/Auth_SQLTest.php

    r42 r130  
    2121    function setUp()
    2222    {
    23         require dirname(__FILE__) . '/_config.inc.php';
     23        $db =& DB::getInstance();
     24   
     25        require dirname(__FILE__) . '/_config.inc.php';
    2426        require_once '../lib/Auth_SQL.inc.php';
    2527        $this->Auth_SQL =& new Auth_SQL('testauth');
     
    3638
    3739        // Insert test data.
    38         DB::query("
     40        $db->query("
    3941            INSERT INTO test_user_tbl (
    4042                username,
     
    5860    function tearDown()
    5961    {
    60         unset($this->Auth_SQL);
    61         DB::query("DROP TABLE IF EXISTS test_user_tbl");
    62         DB::query("DROP TABLE IF EXISTS test_login_tbl");
     62        $db =& DB::getInstance();
     63   
     64        unset($this->Auth_SQL);
     65        $db->query("DROP TABLE IF EXISTS test_user_tbl");
     66        $db->query("DROP TABLE IF EXISTS test_login_tbl");
    6367    }
    6468
     
    140144    function test_blockaccount()
    141145    {
     146        $db =& DB::getInstance();
     147   
    142148        $this->Auth_SQL->login('testuser', 'testpass');
    143149        $this->Auth_SQL->blockaccount(null, 'blocktestuser');
    144         $qid = DB::query("
     150        $qid = $db->query("
    145151            SELECT blocked_reason
    146152            FROM test_user_tbl
     
    152158    function test_unblockaccount()
    153159    {
    154         DB::query("
     160        $db =& DB::getInstance();
     161   
     162        $db->query("
    155163            UPDATE test_user_tbl SET blocked_reason = 'blocktestuser'
    156164        ");
    157165        $this->Auth_SQL->unblockaccount();
    158166
    159         $qid = DB::query("
     167        $qid = $db->query("
    160168            SELECT blocked_reason
    161169            FROM test_user_tbl
     
    191199    function test_setpassword()
    192200    {
     201        $db =& DB::getInstance();
     202   
    193203        $this->Auth_SQL->setpassword(null, '123');
    194         $qid = DB::query("
     204        $qid = $db->query("
    195205            SELECT userpass
    196206            FROM test_user_tbl
  • branches/2.0singleton/tests/RecordLockTest.php

    r42 r130  
    2222    function setUp()
    2323    {
     24        $db =& DB::getInstance();
     25   
    2426        require dirname(__FILE__) . '/_config.inc.php';
    2527        require_once '../lib/RecordLock.inc.php';
     
    3941
    4042        // Insert test data.
    41         DB::query("
     43        $db->query("
    4244            INSERT INTO test_user_tbl (
    4345                username,
     
    6769    function tearDown()
    6870    {
     71        $db =& DB::getInstance();
     72   
    6973        unset($this->RecordLock);
    7074        unset($this->Auth_SQL);
    71         DB::query("DROP TABLE IF EXISTS test_user_tbl");
    72         DB::query("DROP TABLE IF EXISTS test_login_tbl");
    73         DB::query("DROP TABLE IF EXISTS test_lock_tbl");
     75        $db->query("DROP TABLE IF EXISTS test_user_tbl");
     76        $db->query("DROP TABLE IF EXISTS test_login_tbl");
     77        $db->query("DROP TABLE IF EXISTS test_lock_tbl");
    7478    }
    7579
  • branches/2.0singleton/tests/RecordVersionTest.php

    r42 r130  
    2222    function setUp()
    2323    {
     24        $db =& DB::getInstance();
     25   
    2426        require dirname(__FILE__) . '/_config.inc.php';
    2527        require_once '../lib/RecordVersion.inc.php';
     
    3941
    4042        // Insert test data.
    41         DB::query("
     43        $db->query("
    4244            INSERT INTO test_user_tbl (
    4345                username,
     
    6870    function tearDown()
    6971    {
     72        $db =& DB::getInstance();
     73   
    7074        unset($this->RecordVersion);
    7175        unset($this->Auth_SQL);
    72         DB::query("DROP TABLE IF EXISTS test_user_tbl");
    73         DB::query("DROP TABLE IF EXISTS test_login_tbl");
    74         DB::query("DROP TABLE IF EXISTS test_version_tbl");
     76        $db->query("DROP TABLE IF EXISTS test_user_tbl");
     77        $db->query("DROP TABLE IF EXISTS test_login_tbl");
     78        $db->query("DROP TABLE IF EXISTS test_version_tbl");
    7579    }
    7680
Note: See TracChangeset for help on using the changeset viewer.