Changeset 146


Ignore:
Timestamp:
Jun 5, 2006 1:14:51 AM (18 years ago)
Author:
scdev
Message:

Q - added persistant database storage to Prefs.inc.php. Modified getParam failure log type to LOG_DEBUG in all classes.

Location:
trunk/lib
Files:
16 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib/Auth_File.inc.php

    r141 r146  
    102102            return $this->_params[$param];
    103103        } else {
    104             $app->logMsg(sprintf('Parameter is not set: %s', $param), LOG_NOTICE, __FILE__, __LINE__);
     104            $app->logMsg(sprintf('Parameter is not set: %s', $param), LOG_DEBUG, __FILE__, __LINE__);
    105105            return null;
    106106        }
  • trunk/lib/Auth_SQL.inc.php

    r136 r146  
    135135
    136136            // The minimal columns for a table compatable with the Auth_SQL class.
    137             $db->query("CREATE TABLE IF NOT EXISTS " . $this->getParam('db_table') . " (
     137            $db->query("CREATE TABLE IF NOT EXISTS " . $db->escapeString($this->getParam('db_table')) . " (
    138138                " . $this->getParam('db_primary_key') . " smallint(11) NOT NULL auto_increment,
    139139                " . $this->getParam('db_username_column') . " varchar(255) NOT NULL default '',
     
    242242            return $this->_params[$param];
    243243        } else {
    244             $app->logMsg(sprintf('Parameter is not set: %s', $param), LOG_NOTICE, __FILE__, __LINE__);
     244            $app->logMsg(sprintf('Parameter is not set: %s', $param), LOG_DEBUG, __FILE__, __LINE__);
    245245            return null;
    246246        }
  • trunk/lib/AuthorizeNet.inc.php

    r136 r146  
    157157            return $this->_params[$param];
    158158        } else {
    159             $app->logMsg(sprintf('Parameter is not set: %s', $param), LOG_NOTICE, __FILE__, __LINE__);
     159            $app->logMsg(sprintf('Parameter is not set: %s', $param), LOG_DEBUG, __FILE__, __LINE__);
    160160            return null;
    161161        }
  • trunk/lib/CSS.inc.php

    r136 r146  
    5252            return $this->_params[$param];
    5353        } else {
    54             $app->logMsg(sprintf('Parameter is not set: %s', $param), LOG_NOTICE, __FILE__, __LINE__);
     54            $app->logMsg(sprintf('Parameter is not set: %s', $param), LOG_DEBUG, __FILE__, __LINE__);
    5555            return null;
    5656        }
  • trunk/lib/Cache.inc.php

    r137 r146  
    7474            return $this->_params[$param];
    7575        } else {
    76             $app->logMsg(sprintf('Parameter is not set: %s', $param), LOG_NOTICE, __FILE__, __LINE__);
     76            $app->logMsg(sprintf('Parameter is not set: %s', $param), LOG_DEBUG, __FILE__, __LINE__);
    7777            return null;
    7878        }
  • trunk/lib/DB.inc.php

    r136 r146  
    101101            return $this->_params[$param];
    102102        } else {
    103             $app->logMsg(sprintf('Parameter is not set: %s', $param), LOG_NOTICE, __FILE__, __LINE__);
     103            $app->logMsg(sprintf('Parameter is not set: %s', $param), LOG_DEBUG, __FILE__, __LINE__);
    104104            return null;
    105105        }
  • trunk/lib/DBSessionHandler.inc.php

    r136 r146  
    1515    var $_params = array(
    1616        'db_table' => 'session_tbl',
    17         'create_table' => true, // Automatically create table and verify columns. Better set to false after site launch.
     17
     18        // Automatically create table and verify columns. Better set to false after site launch.
     19        'create_table' => true,
    1820    );
    1921
  • trunk/lib/Email.inc.php

    r136 r146  
    122122            return $this->_params[$param];
    123123        } else {
    124             $app->logMsg(sprintf('Parameter is not set: %s', $param), LOG_NOTICE, __FILE__, __LINE__);
     124            $app->logMsg(sprintf('Parameter is not set: %s', $param), LOG_DEBUG, __FILE__, __LINE__);
    125125            return null;
    126126        }
  • trunk/lib/ImageThumb.inc.php

    r141 r146  
    135135            return $this->_params[$param];
    136136        } else {
    137             $app->logMsg(sprintf('Parameter is not set: %s', $param), LOG_NOTICE, __FILE__, __LINE__);
     137            $app->logMsg(sprintf('Parameter is not set: %s', $param), LOG_DEBUG, __FILE__, __LINE__);
    138138            return null;
    139139        }
  • trunk/lib/Lock.inc.php

    r141 r146  
    1717        'error_url' => '/lock.php',
    1818        'db_table' => 'lock_tbl',
    19         'create_table' => true, // Automatically create table and verify columns. Better set to false after site launch.
     19
     20        // Automatically create table and verify columns. Better set to false after site launch.
     21        'create_table' => true,
    2022    );
    2123
     
    8486                $app->logMsg(sprintf('Dropping and recreating table %s.', $this->getParam('db_table')), LOG_DEBUG, __FILE__, __LINE__);
    8587            }
    86             $db->query("CREATE TABLE IF NOT EXISTS " . $this->getParam('db_table') . " (
     88            $db->query("CREATE TABLE IF NOT EXISTS " . $db->escapeString($this->getParam('db_table')) . " (
    8789                lock_id int NOT NULL auto_increment,
    8890                record_table varchar(255) NOT NULL default '',
     
    141143            return $this->_params[$param];
    142144        } else {
    143             $app->logMsg(sprintf('Parameter is not set: %s', $param), LOG_NOTICE, __FILE__, __LINE__);
     145            $app->logMsg(sprintf('Parameter is not set: %s', $param), LOG_DEBUG, __FILE__, __LINE__);
    144146            return null;
    145147        }
     
    168170            // Get lock data by lock_id.
    169171            $qid = $db->query("
    170                 SELECT * FROM " . $this->getParam('db_table') . "
     172                SELECT * FROM " . $db->escapeString($this->getParam('db_table')) . "
    171173                WHERE lock_id = '" . $db->escapeString($record_table_or_lock_id) . "'
    172174            ");
     
    174176            // Get lock data by record specs
    175177            $qid = $db->query("
    176                 SELECT * FROM " . $this->getParam('db_table') . "
     178                SELECT * FROM " . $db->escapeString($this->getParam('db_table')) . "
    177179                WHERE record_table = '" . $db->escapeString($record_table_or_lock_id) . "'
    178180                AND record_key = '" . $db->escapeString($record_key) . "'
     
    214216
    215217        if (isset($this->data['lock_id'])) {
    216             $qid = $db->query("SELECT * FROM " . $this->getParam('db_table') . " WHERE lock_id = '" . $db->escapeString($this->data['lock_id']) . "'");
     218            $qid = $db->query("SELECT * FROM " . $db->escapeString($this->getParam('db_table')) . " WHERE lock_id = '" . $db->escapeString($this->data['lock_id']) . "'");
    217219            if ($lock = mysql_fetch_assoc($qid)) {
    218220                return ($lock['set_by_admin_id'] == $this->_auth->getVal('user_id'));
     
    246248        // Remove previous locks if exist. Is this better than using a REPLACE INTO?
    247249        $db->query("
    248             DELETE FROM " . $this->getParam('db_table') . "
     250            DELETE FROM " . $db->escapeString($this->getParam('db_table')) . "
    249251            WHERE record_table = '" . $db->escapeString($record_table) . "'
    250252            AND record_key = '" . $db->escapeString($record_key) . "'
     
    254256        // Set new lock.
    255257        $db->query("
    256             INSERT INTO " . $this->getParam('db_table') . " (
     258            INSERT INTO " . $db->escapeString($this->getParam('db_table')) . " (
    257259                record_table,
    258260                record_key,
     
    293295        // Delete a specific lock.
    294296        $db->query("
    295             DELETE FROM " . $this->getParam('db_table') . "
     297            DELETE FROM " . $db->escapeString($this->getParam('db_table')) . "
    296298            WHERE lock_id = '" . $db->escapeString($this->data['lock_id']) . "'
    297299        ");
     
    315317        if (isset($user_id)) {
    316318            // Delete specific user's locks.
    317             $db->query("DELETE FROM " . $this->getParam('db_table') . " WHERE set_by_admin_id = '" . $db->escapeString($user_id) . "'");
     319            $db->query("DELETE FROM " . $db->escapeString($this->getParam('db_table')) . " WHERE set_by_admin_id = '" . $db->escapeString($user_id) . "'");
    318320            $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__);
    319321        } else {
    320322            // Delete ALL locks.
    321             $db->query("DELETE FROM " . $this->getParam('db_table') . "");
     323            $db->query("DELETE FROM " . $db->escapeString($this->getParam('db_table')) . "");
    322324            $app->logMsg(sprintf('All record locks deleted by %s %s', $this->_auth->getVal('auth_name'), $this->_auth->getVal('username')), LOG_DEBUG, __FILE__, __LINE__);
    323325        }
     
    338340            // Delete all old locks.
    339341            $db->query("
    340                 DELETE FROM " . $this->getParam('db_table') . "
     342                DELETE FROM " . $db->escapeString($this->getParam('db_table')) . "
    341343                WHERE DATE_ADD(lock_datetime, INTERVAL '" . $this->getParam('auto_timeout') . "' SECOND) < NOW()
    342344            ");
  • trunk/lib/PEdit.inc.php

    r136 r146  
    125125            return $this->_params[$param];
    126126        } else {
    127             $app->logMsg(sprintf('Parameter is not set: %s', $param), LOG_NOTICE, __FILE__, __LINE__);
     127            $app->logMsg(sprintf('Parameter is not set: %s', $param), LOG_DEBUG, __FILE__, __LINE__);
    128128            return null;
    129129        }
  • trunk/lib/PayPal.inc.php

    r136 r146  
    240240            return $this->_params[$param];
    241241        } else {
    242             $app->logMsg(sprintf('Parameter is not set: %s', $param), LOG_NOTICE, __FILE__, __LINE__);
     242            $app->logMsg(sprintf('Parameter is not set: %s', $param), LOG_DEBUG, __FILE__, __LINE__);
    243243            return null;
    244244        }
  • trunk/lib/Prefs.inc.php

    r136 r146  
    44 * code by strangecode :: www.strangecode.com :: this document contains copyrighted information
    55 *
    6  * Prefs provides an API for saving arbitrary values in a user's session.
     6 * Prefs provides an API for saving arbitrary values in a user's session.
     7 * Session prefs can be stored into a database with the optional save() and load() methods.
    78 *
    89 * @author  Quinn Comendant <quinn@strangecode.com>
     
    1415    var $_ns;
    1516
     17    // Configuration of this object.
     18    var $_params = array(
     19       
     20        // Enable database storage.
     21        'enable_db' => true,
     22       
     23        // Name of database table to store prefs.
     24        'db_table' => 'prefs_tbl',
     25
     26        // Automatically create table and verify columns. Better set to false after site launch.
     27        'create_table' => true,
     28       
     29        // The current user_id for which to load/save preferences.
     30        'user_id' => null,
     31    );
     32
    1633    /**
    1734     * Prefs constructor.
     
    1936    function Prefs($namespace='')
    2037    {
     38        $app =& App::getInstance();
     39
    2140        $this->_ns = '_prefs_' . $namespace;
    2241       
    2342        // Initialized the prefs array.
    2443        if (!isset($_SESSION[$this->_ns])) {
    25             $_SESSION[$this->_ns] = array();
     44            $_SESSION[$this->_ns] = array('loaded' => false, 'data' => array());
     45        }
     46
     47        // Get create tables config from global context.
     48        if (!is_null($app->getParam('db_create_tables'))) {
     49            $this->setParam(array('create_table' => $app->getParam('db_create_tables')));
     50        }
     51    }
     52
     53    /**
     54     * Setup the database table for this class.
     55     *
     56     * @access  public
     57     * @author  Quinn Comendant <quinn@strangecode.com>
     58     * @since   04 Jun 2006 16:41:42
     59     */
     60    function initDB($recreate_db=false)
     61    {
     62        $app =& App::getInstance();
     63        $db =& DB::getInstance();
     64
     65        static $_db_tested = false;
     66
     67        if ($recreate_db || !$_db_tested && $this->getParam('create_table')) {
     68            if ($recreate_db) {
     69                $db->query("DROP TABLE IF EXISTS " . $this->getParam('db_table'));
     70                $app->logMsg(sprintf('Dropping and recreating table %s.', $this->getParam('db_table')), LOG_DEBUG, __FILE__, __LINE__);
     71            }
     72            $db->query("CREATE TABLE IF NOT EXISTS " . $db->escapeString($this->getParam('db_table')) . " (
     73                user_id VARCHAR(32) NOT NULL DEFAULT '',
     74                pref_namespace VARCHAR(32) NOT NULL DEFAULT '',
     75                pref_key VARCHAR(64) NOT NULL DEFAULT '',
     76                pref_value TEXT,
     77                PRIMARY KEY (user_id, pref_namespace, pref_key)
     78            )");
     79
     80            if (!$db->columnExists($this->getParam('db_table'), array(
     81                'user_id',
     82                'pref_namespace',
     83                'pref_key',
     84                'pref_value',
     85            ), false, false)) {
     86                $app->logMsg(sprintf('Database table %s has invalid columns. Please update this table manually.', $this->getParam('db_table')), LOG_ALERT, __FILE__, __LINE__);
     87                trigger_error(sprintf('Database table %s has invalid columns. Please update this table manually.', $this->getParam('db_table')), E_USER_ERROR);
     88            }
     89        }
     90        $_db_tested = true;
     91    }
     92
     93    /**
     94     * Set the params of this object.
     95     *
     96     * @param  array $params   Array of param keys and values to set.
     97     */
     98    function setParam($params=null)
     99    {
     100        if (isset($params) && is_array($params)) {
     101            // Merge new parameters with old overriding only those passed.
     102            $this->_params = array_merge($this->_params, $params);
     103        }
     104    }
     105
     106    /**
     107     * Return the value of a parameter, if it exists.
     108     *
     109     * @access public
     110     * @param string $param        Which parameter to return.
     111     * @return mixed               Configured parameter value.
     112     */
     113    function getParam($param)
     114    {
     115        $app =& App::getInstance();
     116   
     117        if (isset($this->_params[$param])) {
     118            return $this->_params[$param];
     119        } else {
     120            $app->logMsg(sprintf('Parameter is not set: %s', $param), LOG_DEBUG, __FILE__, __LINE__);
     121            return null;
    26122        }
    27123    }
     
    34130     * @param  string $val       The new value for this preference.
    35131     */
    36     function setDefault($key, $val)
    37     {
    38         // Set it only if not set already.
    39         if (!isset($_SESSION[$this->_ns][$key])) {
    40             $_SESSION[$this->_ns][$key] = $val;
     132    function setDefaults($defaults)
     133    {
     134        if (isset($defaults) && is_array($defaults)) {
     135            // Apply defaults to the session, setting only non-existing values.
     136            $_SESSION[$this->_ns]['data'] = array_merge($defaults, $_SESSION[$this->_ns]['data']);
    41137        }
    42138    }
     
    50146    function set($key, $val)
    51147    {
    52         $_SESSION[$this->_ns][$key] = $val;
     148        $_SESSION[$this->_ns]['data'][$key] = $val;
    53149    }
    54150
     
    62158    function get($key)
    63159    {
    64         return (isset($_SESSION[$this->_ns][$key])) ? $_SESSION[$this->_ns][$key] : null;
     160        return (isset($_SESSION[$this->_ns]['data'][$key])) ? $_SESSION[$this->_ns]['data'][$key] : null;
    65161    }
    66162
     
    75171    function exists($key)
    76172    {
    77         return isset($_SESSION[$this->_ns][$key]);
     173        return isset($_SESSION[$this->_ns]['data'][$key]);
    78174    }
    79175
     
    81177     * Clear a set preference value.
    82178     *
    83      * @param string $key       The name of the preference to check.
     179     * @param string $key       The name of the preference to delete.
    84180     */
    85181    function delete($key)
    86182    {
    87         if (isset($_SESSION[$this->_ns][$key])) {
    88             unset($_SESSION[$this->_ns][$key]);
    89         }
    90     }
    91 
    92     /**
    93      * Perform cleanup operations.
     183        unset($_SESSION[$this->_ns]['data'][$key]);
     184    }
     185
     186    /**
     187     * Empty the $_SESSION cache.
    94188     */
    95189    function clear()
     
    97191        $_SESSION[$this->_ns] = array();
    98192    }
     193   
     194    /*
     195    * Retreives all prefs from the database and stores them in the $_SESSION.
     196    *
     197    * @access   public
     198    * @return   bool    True if loading succeeded.
     199    * @author   Quinn Comendant <quinn@strangecode.com>
     200    * @version  1.0
     201    * @since    04 Jun 2006 16:56:53
     202    */
     203    function load()
     204    {
     205        $app =& App::getInstance();
     206        $db =& DB::getInstance();
     207       
     208        // Skip this method if not using the db.
     209        if (true !=== $this->getParam('enable_db')) {
     210            return true;
     211        }
     212
     213        // Prefs already loaded for this session.
     214        if ($this->_isLoaded()) {
     215            return true;
     216        }
     217
     218        // User_id must not be empty.
     219        if ('' == $this->getParam('user_id')) {
     220            $app->logMsg(sprintf('Cannot save prefs because user_id not set.', null), LOG_ERR, __FILE__, __LINE__);
     221            return false;
     222        }
     223
     224        $this->initDB();
     225       
     226        // Retreive all prefs for this user and namespace.
     227        $qid = $db->query("
     228            SELECT pref_key, pref_value
     229            FROM " . $db->escapeString($this->getParam('db_table')) . "
     230            WHERE user_id = '" . $db->escapeString($this->getParam('user_id')) . "'
     231            AND pref_namespace = '" . $db->escapeString($this->_ns) . "'
     232            LIMIT 10000
     233        ");
     234        while (list($key, $val) = mysql_fetch_row($qid)) {
     235            $_SESSION[$this->_ns]['data'][$key] = $val;
     236        }
     237       
     238        // Data loaded only once per session.
     239        $_SESSION[$this->_ns]['loaded'] = true;
     240       
     241        return true;
     242    }
     243   
     244    /*
     245    *   Returns true if the prefs had been loaded from the database into the $_SESSION.
     246    *
     247    * @access   private
     248    * @return   bool    True if prefs are loaded.
     249    * @author   Quinn Comendant <quinn@strangecode.com>
     250    * @version  1.0
     251    * @since    04 Jun 2006 17:12:44
     252    */
     253    function _isLoaded()
     254    {
     255        return isset($_SESSION[$this->_ns]['loaded']) && true === $_SESSION[$this->_ns]['loaded'];
     256    }
     257   
     258    /*
     259    * Saves all prefs stored in the $_SESSION into the database.
     260    *
     261    * @access   public
     262    * @return   bool    True if prefs exist and were saved.
     263    * @author   Quinn Comendant <quinn@strangecode.com>
     264    * @version  1.0
     265    * @since    04 Jun 2006 17:19:56
     266    */
     267    function save()
     268    {
     269        $app =& App::getInstance();
     270        $db =& DB::getInstance();
     271       
     272        // Skip this method if not using the db.
     273        if (true !=== $this->getParam('enable_db')) {
     274            return true;
     275        }
     276       
     277        // User_id must not be empty.
     278        if ('' == $this->getParam('user_id')) {
     279            $app->logMsg(sprintf('Cannot save prefs because user_id not set.', null), LOG_ERR, __FILE__, __LINE__);
     280            return false;
     281        }
     282
     283        $this->initDB();
     284
     285        if (isset($_SESSION[$this->_ns]['data']) && is_array($_SESSION[$this->_ns]['data'])) {
     286            // Delete old prefs from database.
     287            $db->query("
     288                DELETE FROM " . $db->escapeString($this->getParam('db_table')) . "
     289                WHERE user_id = '" . $db->escapeString($this->getParam('user_id')) . "'
     290                AND pref_namespace = '" . $db->escapeString($this->_ns) . "'
     291            ");
     292           
     293            // Insert new prefs.
     294            $insert_values = array();
     295            foreach ($_SESSION[$this->_ns]['data'] as $key => $val) {
     296                $insert_values[] = sprintf("('%s', '%s', '%s', '%s')", DB::escapeString($this->getParam('user_id')), DB::escapeString($this->_ns), DB::escapeString($key), DB::escapeString($val));
     297            }
     298            $db->query("
     299                INSERT LOW_PRIORITY INTO " . $db->escapeString($this->getParam('db_table')) . "
     300                (user_id, pref_namespace, pref_key, pref_value)
     301                VALUES " . join(', ', $insert_values) . "
     302            ");
     303           
     304            $app->logMsg(sprintf('Saved %s preferences to database.', sizeof($insert_values)), LOG_DEBUG, __FILE__, __LINE__);
     305            return true;
     306        }
     307       
     308        return false;
     309    }
    99310}
    100311
  • trunk/lib/SpellCheck.inc.php

    r136 r146  
    120120            return $this->_params[$param];
    121121        } else {
    122             $app->logMsg(sprintf('Parameter is not set: %s', $param), LOG_NOTICE, __FILE__, __LINE__);
     122            $app->logMsg(sprintf('Parameter is not set: %s', $param), LOG_DEBUG, __FILE__, __LINE__);
    123123            return null;
    124124        }
  • trunk/lib/Upload.inc.php

    r142 r146  
    100100            return $this->_params[$param];
    101101        } else {
    102             $app->logMsg(sprintf('Parameter is not set: %s', $param), LOG_NOTICE, __FILE__, __LINE__);
     102            $app->logMsg(sprintf('Parameter is not set: %s', $param), LOG_DEBUG, __FILE__, __LINE__);
    103103            return null;
    104104        }
  • trunk/lib/Version.inc.php

    r144 r146  
    2525        'min_days' => 7, // Keep ALL versions within this many days, even if MORE than min_qty.
    2626        'db_table' => 'version_tbl',
    27         'create_table' => true, // Automatically create table and verify columns. Better set to false after site launch.
     27
     28        // Automatically create table and verify columns. Better set to false after site launch.
     29        'create_table' => true,
    2830        'db_schema_strict' => true, // If true, makes an exact comparison of saved vs. live table schemas. If false, just checks that the saved columns are available.
    2931    );
     
    9092                $app->logMsg(sprintf('Dropping and recreating table %s.', $this->getParam('db_table')), LOG_DEBUG, __FILE__, __LINE__);
    9193            }
    92             $db->query("CREATE TABLE IF NOT EXISTS " . $this->getParam('db_table') . " (
     94            $db->query("CREATE TABLE IF NOT EXISTS " . $db->escapeString($this->getParam('db_table')) . " (
    9395                version_id int NOT NULL auto_increment,
    9496                record_table varchar(255) NOT NULL default '',
     
    151153            return $this->_params[$param];
    152154        } else {
    153             $app->logMsg(sprintf('Parameter is not set: %s', $param), LOG_NOTICE, __FILE__, __LINE__);
     155            $app->logMsg(sprintf('Parameter is not set: %s', $param), LOG_DEBUG, __FILE__, __LINE__);
    154156            return null;
    155157        }
     
    184186        // Save as new version.
    185187        $db->query("
    186             INSERT INTO " . $this->getParam('db_table') . " (
     188            INSERT INTO " . $db->escapeString($this->getParam('db_table')) . " (
    187189                record_table,
    188190                record_key,
     
    224226        // Get version data.
    225227        $qid = $db->query("
    226             SELECT * FROM " . $this->getParam('db_table') . "
     228            SELECT * FROM " . $db->escapeString($this->getParam('db_table')) . "
    227229            WHERE version_id = '" . $db->escapeString($version_id) . "'
    228230        ");
     
    284286        // Get total number of versions for this record.
    285287        $qid = $db->query("
    286             SELECT COUNT(*) FROM " . $this->getParam('db_table') . "
     288            SELECT COUNT(*) FROM " . $db->escapeString($this->getParam('db_table')) . "
    287289            WHERE record_table = '" . $db->escapeString($record_table) . "'
    288290            AND record_key = '" . $db->escapeString($record_key) . "'
     
    296298                // First query for oldest records, selecting enough to bring total number down to min_qty.
    297299                $qid = $db->query("
    298                     SELECT version_id FROM " . $this->getParam('db_table') . "
     300                    SELECT version_id FROM " . $db->escapeString($this->getParam('db_table')) . "
    299301                    WHERE record_table = '" . $db->escapeString($record_table) . "'
    300302                    AND record_key = '" . $db->escapeString($record_key) . "'
     
    307309                }
    308310                $db->query("
    309                     DELETE FROM " . $this->getParam('db_table') . "
     311                    DELETE FROM " . $db->escapeString($this->getParam('db_table')) . "
    310312                    WHERE version_id IN ('" . join("','", $old_versions) . "')
    311313                ");
     
    313315                // Delete versions older than min_days, while still keeping min_qty.
    314316                $qid = $db->query("
    315                     SELECT version_id FROM " . $this->getParam('db_table') . "
     317                    SELECT version_id FROM " . $db->escapeString($this->getParam('db_table')) . "
    316318                    WHERE record_table = '" . $db->escapeString($record_table) . "'
    317319                    AND record_key = '" . $db->escapeString($record_key) . "'
     
    326328                if (sizeof($old_versions) > 0) {
    327329                    $db->query("
    328                         DELETE FROM " . $this->getParam('db_table') . "
     330                        DELETE FROM " . $db->escapeString($this->getParam('db_table')) . "
    329331                        WHERE version_id IN ('" . join("','", $old_versions) . "')
    330332                    ");
     
    352354        $qid = $db->query("
    353355            SELECT version_id, saved_by_user_id, version_datetime, version_title
    354             FROM " . $this->getParam('db_table') . "
     356            FROM " . $db->escapeString($this->getParam('db_table')) . "
    355357            WHERE record_table = '" . $db->escapeString($record_table) . "'
    356358            AND record_key = '" . $db->escapeString($record_key) . "'
     
    382384        // Get version data.
    383385        $qid = $db->query("
    384             SELECT * FROM " . $this->getParam('db_table') . "
     386            SELECT * FROM " . $db->escapeString($this->getParam('db_table')) . "
    385387            WHERE version_id = '" . $db->escapeString($version_id) . "'
    386388        ");
     
    403405        // Get version data.
    404406        $qid = $db->query("
    405             SELECT * FROM " . $this->getParam('db_table') . "
     407            SELECT * FROM " . $db->escapeString($this->getParam('db_table')) . "
    406408            WHERE version_id = '" . $db->escapeString($version_id) . "'
    407409        ");
Note: See TracChangeset for help on using the changeset viewer.