Changeset 21


Ignore:
Timestamp:
Nov 17, 2005 7:37:40 AM (19 years ago)
Author:
scdev
Message:

More random updates. Improved self-instantiation pattern in SessionCache? to match that of App. More little tweaks.

Location:
trunk
Files:
11 edited
1 moved

Legend:

Unmodified
Added
Removed
  • trunk/bin/module_maker/skel/adm_list.ihtml

    r20 r21  
    1212        <?php // printSelectForm('<##>_tbl', "CONCAT(<##>_id, '&mdash;', city, '&mdash;', title)", '<##>_id', getFormData('filter_<##>'), array('Any <##>'), 'ORDER BY <##> ASC'); ?>
    1313    </select>
    14     <input type="submit" name="list" value="<?php echo _("Search"); ?>" />
     14    <input type="submit" value="<?php echo _("Search"); ?>" />
    1515</div>
    1616</form>
  • trunk/bin/module_maker/skel/admin.php

    r20 r21  
    216216    if (!$frm = mysql_fetch_assoc($qid)) {
    217217        App::logMsg('Could not find record with %PRIMARY_KEY%: ' . $id, LOG_WARNING, __FILE__, __LINE__);
    218         App::raiseMsg(sprintf(_("The requested record %s could not be found"), $id), MSG_ERR, __FILE__, __LINE__);
     218        App::raiseMsg(sprintf(_("The requested record %s could not be found."), $id), MSG_ERR, __FILE__, __LINE__);
    219219        App::dieBoomerangURL();
    220220    }
     
    244244    if ($lock->isLocked() && !$lock->isMine()) {
    245245        $lock->dieErrorPage();
    246     } else {
    247         // Break the cache because we are changing the list data.
    248         SessionCache::breakCache($_SERVER['PHP_SELF']);
    249        
    250         // Get the information for this object.
    251         $qid = DB::query("
    252             SELECT <##>
    253             FROM %DB_TBL%
    254             WHERE %PRIMARY_KEY% = '" . addslashes($id) . "'
    255         ");
    256         if (! list($name) = mysql_fetch_row($qid)) {
    257             App::logMsg('Could not find record with %PRIMARY_KEY%: ' . $id, LOG_WARNING, __FILE__, __LINE__);
    258             App::raiseMsg(sprintf(_("The requested record %s could not be found"), $id), MSG_ERR, __FILE__, __LINE__);
    259             App::dieBoomerangURL();
    260         }
    261        
    262         // Delete the record.
    263         DB::query("DELETE FROM %DB_TBL% WHERE %PRIMARY_KEY% = '" . addslashes($id) . "'");
    264        
    265         App::raiseMsg(sprintf(_("The %ITEM_TITLE% <strong>%s</strong> has been deleted."), $name), MSG_SUCCESS, __FILE__, __LINE__);
    266 
    267         // Unlock record.
    268         $lock->remove();
    269     }
     246    }
     247
     248    // Break the cache because we are changing the list data.
     249    SessionCache::breakCache($_SERVER['PHP_SELF']);
     250   
     251    // Get the information for this object.
     252    $qid = DB::query("
     253        SELECT <##>
     254        FROM %DB_TBL%
     255        WHERE %PRIMARY_KEY% = '" . addslashes($id) . "'
     256    ");
     257    if (! list($name) = mysql_fetch_row($qid)) {
     258        App::logMsg('Could not find record with %PRIMARY_KEY%: ' . $id, LOG_WARNING, __FILE__, __LINE__);
     259        App::raiseMsg(sprintf(_("The requested record %s could not be found."), $id), MSG_ERR, __FILE__, __LINE__);
     260        App::dieBoomerangURL();
     261    }
     262   
     263    // Delete the record.
     264    DB::query("DELETE FROM %DB_TBL% WHERE %PRIMARY_KEY% = '" . addslashes($id) . "'");
     265   
     266    App::raiseMsg(sprintf(_("The %ITEM_TITLE% <strong>%s</strong> has been deleted."), $name), MSG_SUCCESS, __FILE__, __LINE__);
     267
     268    // Unlock record.
     269    $lock->remove();
    270270}
    271271
     
    297297    if ($lock->isLocked() && !$lock->isMine()) {
    298298        $lock->dieErrorPage();
    299     } else {
    300         // Break the cache because we are changing the list data.
    301         SessionCache::breakCache($_SERVER['PHP_SELF']);
     299    }
     300
     301    // Break the cache because we are changing the list data.
     302    SessionCache::breakCache($_SERVER['PHP_SELF']);
    302303
    303304%UPDATE%
    304        
    305         // Create version.
    306         $version = RecordVersion::getInstance($GLOBALS['auth']);
    307         $version->create('%DB_TBL%', '%PRIMARY_KEY%', $frm['%PRIMARY_KEY%'], $frm['<##>']);
    308    
    309         App::raiseMsg(sprintf(_("The %ITEM_TITLE% <strong>%s</strong> has been updated."), $frm['<##>']), MSG_SUCCESS, __FILE__, __LINE__);
    310 
    311         // Unlock record.
    312         $lock->remove();
    313     }
     305   
     306    // Create version.
     307    $version = RecordVersion::getInstance($GLOBALS['auth']);
     308    $version->create('%DB_TBL%', '%PRIMARY_KEY%', $frm['%PRIMARY_KEY%'], $frm['<##>']);
     309
     310    App::raiseMsg(sprintf(_("The %ITEM_TITLE% <strong>%s</strong> has been updated."), $frm['<##>']), MSG_SUCCESS, __FILE__, __LINE__);
     311
     312    // Unlock record.
     313    $lock->remove();
    314314}
    315315
  • trunk/bin/module_maker/sql.cli.php

    r20 r21  
    127127        continue;
    128128    }
    129     $key_eq_val .= $comma . "\n                $k = $v";
     129    $key_eq_val .= $comma . "\n            $k = $v";
    130130    $comma = ',';
    131131}
    132132echo <<<E_O_F
    133         // Update record data.
    134         DB::query("
    135             UPDATE $db_tbl SET$key_eq_val
    136             WHERE $primary_key = '" . addslashes(\$frm['$primary_key']) . "'
    137         ");
     133    // Update record data.
     134    DB::query("
     135        UPDATE $db_tbl SET$key_eq_val
     136        WHERE $primary_key = '" . addslashes(\$frm['$primary_key']) . "'
     137    ");
    138138E_O_F;
    139139}
  • trunk/css/admin.inc.css

    r20 r21  
    115115    float: left;
    116116    width: 9em;
    117     margin: 0;
     117    margin: 0 0 10px 0;
    118118    border-right: 1px solid gray;
    119119    padding: 0;
     
    142142    text-decoration: none;
    143143    padding: 1px;
     144}
     145
     146#leftnav #navlist li.label
     147{
     148    color: #999;
     149    padding-top: 10px;
     150    font-size: 75%;
     151    font-weight: bold;
    144152}
    145153
  • trunk/css/utilities.inc.css

    r20 r21  
    4141input.tiny, textarea.tiny
    4242{
    43     width: 5em;
     43    width: 4.75em;
    4444}
    4545
  • trunk/docs/revision_history.txt

    r20 r21  
    2323    - RecordVersion
    2424    - SessionCache
     25    - Upload
    2526
    2627One application will always have distinct:
     
    5354    - do not need to be set in any specific order
    5455    - missing vars are dynamically accounted for.
    55      
     56
     57Auth_SQL object:
     58    - Modified to set the auth-type within the object. We needed to use one object name ($auth) for all instances so we can use template that use this variable name commonly. login.php, lock.php, versions.php, password.php -- all in the codebase services will be used globally on multiple sites and need this variable name set.
     59
    5660DB object:
    5761    - Self contained class for DB functions. db::query is the only necessary function. Maintains connections and state independent of App.
  • trunk/lib/SessionCache.inc.php

    r20 r21  
    1313{
    1414    var $_params = array(
     15        'enabled' => true,
    1516        'soft_limit' => 204800,
    1617        'hard_limit' => 4194304,
     
    4344    function setParam($params)
    4445    {
     46        if (!isset($this) || !is_a($this, 'SessionCache')) {
     47            $this =& SessionCache::getInstance();
     48        }
     49
    4550        if (isset($params) && is_array($params)) {
    4651            // Merge new parameters with old overriding only those passed.
     
    6065    function getParam($param)
    6166    {
     67        if (!isset($this) || !is_a($this, 'SessionCache')) {
     68            $this =& SessionCache::getInstance();
     69        }
     70
    6271        if (isset($this->_params[$param])) {
    6372            return $this->_params[$param];
     
    8695    function putCache($var, $var_id, $force_it_in=false)
    8796    {
    88         $cache =& SessionCache::getInstance();
     97        if (!isset($this) || !is_a($this, 'SessionCache')) {
     98            $this =& SessionCache::getInstance();
     99        }
     100
     101        if (!$this->getParam('enabled')) {
     102            return false;
     103        }
    89104
    90105        $var_id = md5($var_id);
     
    92107        $serialized_var_len = strlen($serialized_var);
    93108       
    94         if ($serialized_var_len >= $cache->getParam('soft_limit') && !$force_it_in) {
    95             App::logMsg(sprintf('Serialized variable (%s bytes) more than soft_limit (%s bytes).', $serialized_var_len, $cache->getParam('soft_limit')), LOG_NOTICE, __FILE__, __LINE__);
    96             return false;
    97         }
    98        
    99         if ($serialized_var_len >= $cache->getParam('hard_limit')) {
    100             App::logMsg(sprintf('Serialized variable (%s bytes) more than hard_limit (%s bytes).', $serialized_var_len, $cache->getParam('hard_limit')), LOG_NOTICE, __FILE__, __LINE__);
     109        if ($serialized_var_len >= $this->getParam('soft_limit') && !$force_it_in) {
     110            App::logMsg(sprintf('Serialized variable (%s bytes) more than soft_limit (%s bytes).', $serialized_var_len, $this->getParam('soft_limit')), LOG_NOTICE, __FILE__, __LINE__);
     111            return false;
     112        }
     113       
     114        if ($serialized_var_len >= $this->getParam('hard_limit')) {
     115            App::logMsg(sprintf('Serialized variable (%s bytes) more than hard_limit (%s bytes).', $serialized_var_len, $this->getParam('hard_limit')), LOG_NOTICE, __FILE__, __LINE__);
    101116            return false;
    102117        }
     
    107122            unset($_SESSION['_session_cache'][$var_id]);
    108123            // Continue to prune the cache if it's length is too long for the new variable to fit, but keep at least MIN_ITEMS at least.
    109             while (strlen(serialize($_SESSION['_session_cache'])) + $serialized_var_len >= $cache->getParam('soft_limit')
    110             && sizeof($_SESSION['_session_cache']) >= $cache->getParam('min_items')) {
     124            while (strlen(serialize($_SESSION['_session_cache'])) + $serialized_var_len >= $this->getParam('soft_limit')
     125            && sizeof($_SESSION['_session_cache']) >= $this->getParam('min_items')) {
    111126                array_shift($_SESSION['_session_cache']);
    112127            }
     
    133148    function getCache($var_id)
    134149    {
     150        if (!isset($this) || !is_a($this, 'SessionCache')) {
     151            $this =& SessionCache::getInstance();
     152        }
     153
     154        if (!$this->getParam('enabled')) {
     155            return false;
     156        }
     157       
    135158        $var_id = md5($var_id);
    136159        if (isset($_SESSION['_session_cache'][$var_id])) {
     
    155178    function isCached($var_id)
    156179    {
     180        if (!isset($this) || !is_a($this, 'SessionCache')) {
     181            $this =& SessionCache::getInstance();
     182        }
     183
     184        if (!$this->getParam('enabled')) {
     185            return false;
     186        }
     187
    157188        $var_id = md5($var_id);
    158189        return isset($_SESSION['_session_cache'][$var_id]);
  • trunk/lib/TemplateGlue.inc.php

    r20 r21  
    7272        return $enum[1];
    7373    } else {
     74        App::logMsg(sprintf('No set or enum fields found.', null), LOG_DEBUG, __FILE__, __LINE__);
    7475        return false;
    7576    }
     
    8788    $values = getSetEnumFieldValues($db_table, $db_col);
    8889    if ($values === false) {
    89         ?><option value=""><?php echo _("n/a"); ?></option>
     90        ?><option value="">&nbsp;</option>
    9091        <?php
    9192        return false;
  • trunk/services/admins.php

    r20 r21  
    196196    }
    197197
    198     // If the username was changed during edit, verify.
    199198    if (getFormData('user_type') == 'root' && 'root' != $auth->getVal('user_type')) {
    200199        $fv->addError('user_type', sprintf(_("You do not have clearance to create a user with root privileges."), null));
     
    267266    if (!$frm = mysql_fetch_assoc($qid)) {
    268267        App::logMsg('Could not find record with admin_id: ' . $id, LOG_WARNING, __FILE__, __LINE__);
    269         App::raiseMsg(sprintf(_("The requested record %s could not be found"), $id), MSG_ERR, __FILE__, __LINE__);
     268        App::raiseMsg(sprintf(_("The requested record %s could not be found."), $id), MSG_ERR, __FILE__, __LINE__);
    270269        App::dieBoomerangURL();
    271270    }
     
    312311    if ($lock->isLocked() && !$lock->isMine()) {
    313312        $lock->dieErrorPage();
     313    }
     314
     315    // Break the cache because we are changing the list data.
     316    SessionCache::breakCache($_SERVER['PHP_SELF']);
     317   
     318    // Get the information for this object.
     319    $qid = DB::query("
     320        SELECT username, user_type from admin_tbl
     321        WHERE admin_id = '" . addslashes($id) . "'
     322    ");
     323    if (! list($name, $user_type) = mysql_fetch_row($qid)) {
     324        App::logMsg('Could not find record with admin_id: ' . $id, LOG_WARNING, __FILE__, __LINE__);
     325        App::raiseMsg(sprintf(_("The requested record %s could not be found."), $id), MSG_ERR, __FILE__, __LINE__);
     326        App::dieBoomerangURL();
     327    }
     328   
     329    // Get the information for this object.
     330    $qid = DB::query("SELECT COUNT(*) from admin_tbl");
     331    list($num_admins) = mysql_fetch_row($qid);
     332    if ('root' == $user_type && 'root' != $auth->getVal('user_type')) {
     333        // Only root users can delete root users!
     334        App::raiseMsg(_("You do not have clearance to delete a root administrator."), MSG_NOTICE, __FILE__, __LINE__);
     335    } else if ($num_admins <= 1) {
     336        // There must always be at least one admnistrator!
     337        App::raiseMsg(_("You cannot delete the only administrator in the database. There must be at least one to log in and create other users."), MSG_NOTICE, __FILE__, __LINE__);
     338    } else if ($auth->getVal('user_id') == $id) {
     339        // Do not delete yourself!
     340        App::raiseMsg(_("You cannot delete yourself."), MSG_NOTICE, __FILE__, __LINE__);
    314341    } else {
    315         // Break the cache because we are changing the list data.
    316         SessionCache::breakCache($_SERVER['PHP_SELF']);
    317        
    318         // Get the information for this object.
    319         $qid = DB::query("
    320             SELECT username, user_type from admin_tbl
    321             WHERE admin_id = '" . addslashes($id) . "'
    322         ");
    323         if (! list($name, $user_type) = mysql_fetch_row($qid)) {
    324             App::logMsg('Could not find record with admin_id: ' . $id, LOG_WARNING, __FILE__, __LINE__);
    325             App::raiseMsg(sprintf(_("The requested record %s could not be found"), $id), MSG_ERR, __FILE__, __LINE__);
    326             App::dieBoomerangURL();
    327         }
    328        
    329         // Get the information for this object.
    330         $qid = DB::query("SELECT COUNT(*) from admin_tbl");
    331         list($num_admins) = mysql_fetch_row($qid);
    332         if ('root' == $user_type && 'root' != $auth->getVal('user_type')) {
    333             // Only root users can delete root users!
    334             App::raiseMsg(_("You do not have clearance to delete a root administrator."), MSG_NOTICE, __FILE__, __LINE__);
    335         } else if ($num_admins <= 1) {
    336             // There must always be at least one admnistrator!
    337             App::raiseMsg(_("You cannot delete the only administrator in the database. There must be at least one to log in and create other users."), MSG_NOTICE, __FILE__, __LINE__);
    338         } else if ($auth->getVal('user_id') == $id) {
    339             // Do not delete yourself!
    340             App::raiseMsg(_("You cannot delete yourself."), MSG_NOTICE, __FILE__, __LINE__);
    341         } else {
    342             // Delete the record.
    343             DB::query("DELETE FROM admin_tbl WHERE admin_id = '" . addslashes($id) . "'");
    344             App::raiseMsg(sprintf(_("The admin <strong>%s</strong> has been deleted."), $name), MSG_SUCCESS, __FILE__, __LINE__);
    345         }
    346 
    347         // Unlock record.
    348         $lock->remove();
    349     }
     342        // Delete the record.
     343        DB::query("DELETE FROM admin_tbl WHERE admin_id = '" . addslashes($id) . "'");
     344        App::raiseMsg(sprintf(_("The admin <strong>%s</strong> has been deleted."), $name), MSG_SUCCESS, __FILE__, __LINE__);
     345    }
     346
     347    // Unlock record.
     348    $lock->remove();
    350349}
    351350
     
    399398    if ($lock->isLocked() && !$lock->isMine()) {
    400399        $lock->dieErrorPage();
    401     } else {
    402         // Break the cache because we are changing the list data.
    403         SessionCache::breakCache($_SERVER['PHP_SELF']);
    404        
    405         // If the userpass is left blank or with the filler **** characters, we don't want to update it.
    406         if (!empty($frm['userpass']) && !preg_match('/[\*]{4,}/', $frm['userpass'])) {
    407             // Set user password.
    408             $auth->setPassword($frm['admin_id'], $frm['userpass']);
    409         }
    410        
    411         // Update record data.
    412         DB::query("
    413             UPDATE admin_tbl SET
    414                 username = '" . addslashes($frm['username']) . "',
    415                 first_name = '" . addslashes($frm['first_name']) . "',
    416                 last_name = '" . addslashes($frm['last_name']) . "',
    417                 email = '" . addslashes($frm['email']) . "',
    418                 user_type = '" . addslashes($frm['user_type']) . "',
    419                 modified_by_user_id = '" . addslashes($auth->getVal('user_id')) . "',
    420                 modified_datetime = NOW()
    421             WHERE admin_id = '" . addslashes($frm['admin_id']) . "'
    422         ");
    423 
    424         // Create version.
    425         $version = RecordVersion::getInstance($GLOBALS['auth']);
    426         $version->create('admin_tbl', 'admin_id', $frm['admin_id'], $frm['username']);
    427    
    428         App::raiseMsg(sprintf(_("The Admin <strong>%s</strong> has been updated."), $frm['username']), MSG_SUCCESS, __FILE__, __LINE__);
    429 
    430         // Unlock record.
    431         $lock->remove();
    432     }
     400    }
     401
     402    // Break the cache because we are changing the list data.
     403    SessionCache::breakCache($_SERVER['PHP_SELF']);
     404   
     405    // If the userpass is left blank or with the filler **** characters, we don't want to update it.
     406    if (!empty($frm['userpass']) && !preg_match('/[\*]{4,}/', $frm['userpass'])) {
     407        // Set user password.
     408        $auth->setPassword($frm['admin_id'], $frm['userpass']);
     409    }
     410   
     411    // Update record data.
     412    DB::query("
     413        UPDATE admin_tbl SET
     414            username = '" . addslashes($frm['username']) . "',
     415            first_name = '" . addslashes($frm['first_name']) . "',
     416            last_name = '" . addslashes($frm['last_name']) . "',
     417            email = '" . addslashes($frm['email']) . "',
     418            user_type = '" . addslashes($frm['user_type']) . "',
     419            modified_by_user_id = '" . addslashes($auth->getVal('user_id')) . "',
     420            modified_datetime = NOW()
     421        WHERE admin_id = '" . addslashes($frm['admin_id']) . "'
     422    ");
     423
     424    // Create version.
     425    $version = RecordVersion::getInstance($GLOBALS['auth']);
     426    $version->create('admin_tbl', 'admin_id', $frm['admin_id'], $frm['username']);
     427
     428    App::raiseMsg(sprintf(_("The Admin <strong>%s</strong> has been updated."), $frm['username']), MSG_SUCCESS, __FILE__, __LINE__);
     429
     430    // Unlock record.
     431    $lock->remove();
    433432}
    434433
  • trunk/services/templates/admin_list.ihtml

    r20 r21  
    88   
    99    <input type="text" class="small" size="20" name="search_query" value="<?php echo getFormData('search_query'); ?>" title="<?php echo oTxt(_("Fields searched: Admin id, Username, Userpass, First name, Last name, Email, User type, Login abuse exempt, Blocked, Blocked reason, Abuse warning level, Seconds online, Last login datetime, Last access datetime, Last login ip, Added by user id, Modified by user id, Added datetime, Modified datetime.")); ?>" />
    10     <input type="submit" name="list" value="<?php echo _("Search"); ?>" />
     10    <input type="submit" value="<?php echo _("Search"); ?>" />
    1111</div>
    1212
  • trunk/services/versions.php

    r20 r21  
    7979    if ($lock->isLocked() && !$lock->isMine()) {
    8080        $lock->dieErrorPage();
     81    }
     82
     83    if ($v = $version->restore($version_id)) {
     84        // Create version of this restored record as the "current" version.
     85        $version->create($record_table, $record_key, $record_val, $v['version_title']);
     86        App::raiseMsg(sprintf(_("The record <strong>%s</strong> has been replaced with <strong>%s</strong> version <strong>%s</strong> from <strong>%s</strong>."), getFormData('version_title'), $v['version_title'], $version_id, $v['version_datetime']), MSG_SUCCESS, __FILE__, __LINE__);
     87        App::dieBoomerangURL('versions', array('break_list_cache'=>'true', false));
    8188    } else {
    82         if ($v = $version->restore($version_id)) {
    83             // Create version of this restored record as the "current" version.
    84             $version->create($record_table, $record_key, $record_val, $v['version_title']);
    85             App::raiseMsg(sprintf(_("The record <strong>%s</strong> has been replaced with <strong>%s</strong> version <strong>%s</strong> from <strong>%s</strong>."), getFormData('version_title'), $v['version_title'], $version_id, $v['version_datetime']), MSG_SUCCESS, __FILE__, __LINE__);
    86             App::dieBoomerangURL('versions', array('break_list_cache'=>'true', false));
    87         } else {
    88             App::raiseMsg(_("Version restoration failed."), MSG_ERR, __FILE__, __LINE__);
    89             App::dieURL($_SERVER['PHP_SELF']);
    90         }
     89        App::raiseMsg(_("Version restoration failed."), MSG_ERR, __FILE__, __LINE__);
     90        App::dieURL($_SERVER['PHP_SELF']);
    9191    }
    9292    break;
Note: See TracChangeset for help on using the changeset viewer.