Ignore:
Timestamp:
Jun 3, 2006 7:47:48 PM (18 years ago)
Author:
scdev
Message:

Q - Merged branches/2.0singleton into trunk. Completed updating classes to use singleton methods. Implemented tests. Fixed some bugs. Changed some interfaces.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/bin/module_maker/skel/admin.php

    r111 r136  
    1111$auth->requireLogin();
    1212// $auth->requireAccessClearance(ZONE_ADMIN_%NAME_UPPER%);
    13 App::sslOn();
     13$app->sslOn();
    1414
    1515require_once 'codebase/lib/PageNumbers.inc.php';
     
    3333$fv = new FormValidator();
    3434
     35$cache =& SessionCache::getInstance();
     36
    3537%SORT_ORDER%
    3638
     
    4143
    4244// Search limiters retain their values between page requests.
    43 App::carryQuery('search_query');
    44 App::carryQuery('filter_<##>');
     45$app->carryQuery('search_query');
     46$app->carryQuery('filter_<##>');
    4547%ADMIN_UPLOAD_CONFIG%
    4648/******************************************************************************
     
    5153// allows us to remember which page we came from so we can go back there.
    5254if (getFormData('boomerang', false) && isset($_SERVER['HTTP_REFERER'])) {
    53     App::setBoomerangURL($_SERVER['HTTP_REFERER'], '%NAME_PLURAL%');
     55    $app->setBoomerangURL($_SERVER['HTTP_REFERER'], '%NAME_PLURAL%');
    5456}
    5557
    5658if (getFormData('break_list_cache', false)) {
    5759    // Break the cache because we are changing the list data.
    58     SessionCache::breakCache($_SERVER['PHP_SELF']);
     60    $cache->delete($_SERVER['PHP_SELF']);
    5961}
    6062
     
    8183//     $auth->requireAccessClearance(ZONE_ADMIN_%NAME_UPPER%_FUNC_DELETE);
    8284    deleteRecord(getFormData('%PRIMARY_KEY%'));%ADMIN_UPLOAD_DEL%
    83     if (App::validBoomerangURL('%NAME_PLURAL%')) {
     85    if ($app->validBoomerangURL('%NAME_PLURAL%')) {
    8486        // Display boomerang page.
    85         App::dieBoomerangURL('%NAME_PLURAL%');
     87        $app->dieBoomerangURL('%NAME_PLURAL%');
    8688    }
    8789    // Display default page.
    88     App::dieURL($_SERVER['PHP_SELF']);
     90    $app->dieURL($_SERVER['PHP_SELF']);
    8991    break;
    9092
     
    9294//     $auth->requireAccessClearance(ZONE_ADMIN_%NAME_UPPER%_FUNC_ADD);
    9395    if (getFormdata('cancel', false)) {
    94         if (App::validBoomerangURL('%NAME_PLURAL%')) {
     96        if ($app->validBoomerangURL('%NAME_PLURAL%')) {
    9597            // Display boomerang page.
    96             App::dieBoomerangURL('%NAME_PLURAL%');
     98            $app->dieBoomerangURL('%NAME_PLURAL%');
    9799        }
    98100        // Display default page.
    99         App::dieURL($_SERVER['PHP_SELF']);
     101        $app->dieURL($_SERVER['PHP_SELF']);
    100102    }
    101103    validateInput();
     
    109111        if (getFormdata('repeat', false)) {
    110112            // Display function again.
    111             App::dieURL($_SERVER['PHP_SELF'] . '?op=add');
    112         } else if (App::validBoomerangURL('%NAME_PLURAL%')) {
     113            $app->dieURL($_SERVER['PHP_SELF'] . '?op=add');
     114        } else if ($app->validBoomerangURL('%NAME_PLURAL%')) {
    113115            // Display boomerang page.
    114             App::dieBoomerangURL('%NAME_PLURAL%');
     116            $app->dieBoomerangURL('%NAME_PLURAL%');
    115117        }
    116118        // Display default page.
    117         App::dieURL($_SERVER['PHP_SELF']);
     119        $app->dieURL($_SERVER['PHP_SELF']);
    118120    }
    119121    break;
     
    122124//     $auth->requireAccessClearance(ZONE_ADMIN_%NAME_UPPER%_FUNC_EDIT);
    123125    if (getFormdata('reset', false)) {
    124         App::raiseMsg(_("Saved values have been reloaded."), MSG_NOTICE, __FILE__, __LINE__);
    125         App::dieURL($_SERVER['PHP_SELF'] . '?op=edit&%PRIMARY_KEY%=' . getFormData('%PRIMARY_KEY%'));
     126        $app->raiseMsg(_("Saved values have been reloaded."), MSG_NOTICE, __FILE__, __LINE__);
     127        $app->dieURL($_SERVER['PHP_SELF'] . '?op=edit&%PRIMARY_KEY%=' . getFormData('%PRIMARY_KEY%'));
    126128    }
    127129    if (getFormdata('cancel', false)) {
     
    129131        $lock->select('%DB_TBL%', '%PRIMARY_KEY%', getFormData('%PRIMARY_KEY%'));
    130132        $lock->remove();
    131         if (App::validBoomerangURL('%NAME_PLURAL%')) {
     133        if ($app->validBoomerangURL('%NAME_PLURAL%')) {
    132134            // Display boomerang page.
    133             App::dieBoomerangURL('%NAME_PLURAL%');
     135            $app->dieBoomerangURL('%NAME_PLURAL%');
    134136        }
    135137        // Display default page.
    136         App::dieURL($_SERVER['PHP_SELF']);
     138        $app->dieURL($_SERVER['PHP_SELF']);
    137139    }
    138140    validateInput();
     
    146148        if (getFormdata('repeat', false)) {
    147149            // 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");
     150            $qid = $db->query("SELECT %PRIMARY_KEY% FROM %DB_TBL% WHERE %PRIMARY_KEY% > '" . $db->escapeString(getFormData('%PRIMARY_KEY%')) . "' ORDER BY %PRIMARY_KEY% ASC LIMIT 1");
    149151            if (list($next_id) = mysql_fetch_row($qid)) {
    150                 App::dieURL($_SERVER['PHP_SELF'] . '?op=edit&%PRIMARY_KEY%=' . $next_id);
     152                $app->dieURL($_SERVER['PHP_SELF'] . '?op=edit&%PRIMARY_KEY%=' . $next_id);
    151153            } else {
    152                 App::raiseMsg(_("Cannot edit next, the end of the list was reached"), MSG_NOTICE, __FILE__, __LINE__);
     154                $app->raiseMsg(_("Cannot edit next, the end of the list was reached"), MSG_NOTICE, __FILE__, __LINE__);
    153155            }
    154         } else if (App::validBoomerangURL('%NAME_PLURAL%')) {
     156        } else if ($app->validBoomerangURL('%NAME_PLURAL%')) {
    155157            // Display boomerang page.
    156             App::dieBoomerangURL('%NAME_PLURAL%');
     158            $app->dieBoomerangURL('%NAME_PLURAL%');
    157159        }
    158160        // Display default page.
    159         App::dieURL($_SERVER['PHP_SELF']);
     161        $app->dieURL($_SERVER['PHP_SELF']);
    160162    }
    161163    break;
     
    164166//     $auth->requireAccessClearance(ZONE_ADMIN_PROGRAMS_FUNC_REORDER);
    165167    updateRank(getFormData('rank'));
    166     App::dieURL($_SERVER['PHP_SELF']);
     168    $app->dieURL($_SERVER['PHP_SELF']);
    167169    break;
    168170
     
    207209{
    208210    global $lock;
    209 
     211    $db =& DB::getInstance();
     212   
    210213    $lock->select('%DB_TBL%', '%PRIMARY_KEY%', $id);
    211214    if ($lock->isLocked() && !$lock->isMine()) {
     
    214217
    215218    // Get the information for the form.
    216     $qid = DB::query("
     219    $qid = $db->query("
    217220        SELECT *
    218221        FROM %DB_TBL%
    219         WHERE %PRIMARY_KEY% = '" . DB::escapeString($id) . "'
     222        WHERE %PRIMARY_KEY% = '" . $db->escapeString($id) . "'
    220223    ");
    221224    if (!$frm = mysql_fetch_assoc($qid)) {
    222         App::logMsg('Could not find record with %PRIMARY_KEY%: ' . $id, LOG_WARNING, __FILE__, __LINE__);
    223         App::raiseMsg(sprintf(_("The requested record %s could not be found."), $id), MSG_ERR, __FILE__, __LINE__);
    224         App::dieBoomerangURL();
     225        $app->logMsg('Could not find record with %PRIMARY_KEY%: ' . $id, LOG_WARNING, __FILE__, __LINE__);
     226        $app->raiseMsg(sprintf(_("The requested record %s could not be found."), $id), MSG_ERR, __FILE__, __LINE__);
     227        $app->dieBoomerangURL();
    225228    }
    226229
     
    246249{
    247250    global $lock;
    248 
     251    $db =& DB::getInstance();
     252    $cache =& SessionCache::getInstance();
     253   
    249254    $lock->select('%DB_TBL%', '%PRIMARY_KEY%', $id);
    250255    if ($lock->isLocked() && !$lock->isMine()) {
     
    253258
    254259    // Break the cache because we are changing the list data.
    255     SessionCache::breakCache($_SERVER['PHP_SELF']);
     260    $cache->delete($_SERVER['PHP_SELF']);
    256261
    257262    // Get the information for this object.
    258     $qid = DB::query("
     263    $qid = $db->query("
    259264        SELECT <##>
    260265        FROM %DB_TBL%
    261         WHERE %PRIMARY_KEY% = '" . DB::escapeString($id) . "'
     266        WHERE %PRIMARY_KEY% = '" . $db->escapeString($id) . "'
    262267    ");
    263268    if (! list($name) = mysql_fetch_row($qid)) {
    264         App::logMsg('Could not find record with %PRIMARY_KEY%: ' . $id, LOG_WARNING, __FILE__, __LINE__);
    265         App::raiseMsg(sprintf(_("The requested record %s could not be found."), $id), MSG_ERR, __FILE__, __LINE__);
    266         App::dieBoomerangURL();
     269        $app->logMsg('Could not find record with %PRIMARY_KEY%: ' . $id, LOG_WARNING, __FILE__, __LINE__);
     270        $app->raiseMsg(sprintf(_("The requested record %s could not be found."), $id), MSG_ERR, __FILE__, __LINE__);
     271        $app->dieBoomerangURL();
    267272    }
    268273
    269274    // Delete the record.
    270     DB::query("DELETE FROM %DB_TBL% WHERE %PRIMARY_KEY% = '" . DB::escapeString($id) . "'");
    271 
    272     App::raiseMsg(sprintf(_("The %ITEM_TITLE% <strong>%s</strong> has been deleted."), $name), MSG_SUCCESS, __FILE__, __LINE__);
     275    $db->query("DELETE FROM %DB_TBL% WHERE %PRIMARY_KEY% = '" . $db->escapeString($id) . "'");
     276
     277    $app->raiseMsg(sprintf(_("The %ITEM_TITLE% <strong>%s</strong> has been deleted."), $name), MSG_SUCCESS, __FILE__, __LINE__);
    273278
    274279    // Unlock record.
     
    279284{
    280285    global $auth;
    281 
     286    $db =& DB::getInstance();
     287    $cache =& SessionCache::getInstance();
     288   
    282289    // Break the cache because we are changing the list data.
    283     SessionCache::breakCache($_SERVER['PHP_SELF']);
     290    $cache->delete($_SERVER['PHP_SELF']);
    284291
    285292%INSERT%
    286     $last_insert_id = mysql_insert_id(DB::getDBH());
     293    $last_insert_id = mysql_insert_id($db->getDBH());
    287294
    288295    // Create version.
     
    290297    $version->create('%DB_TBL%', '%PRIMARY_KEY%', $last_insert_id, $frm['<##>']);
    291298
    292     App::raiseMsg(sprintf(_("The %ITEM_TITLE% <strong>%s</strong> has been added."), $frm['<##>']), MSG_SUCCESS, __FILE__, __LINE__);
     299    $app->raiseMsg(sprintf(_("The %ITEM_TITLE% <strong>%s</strong> has been added."), $frm['<##>']), MSG_SUCCESS, __FILE__, __LINE__);
    293300
    294301    return $last_insert_id;
     
    297304function updateRecord($frm)
    298305{
    299     global $auth, $lock;
    300 
     306    global $auth, $lock;
     307    $app =& App::getInstance();
     308    $cache =& SessionCache::getInstance();
     309   
    301310    $lock->select('%DB_TBL%', '%PRIMARY_KEY%', $frm['%PRIMARY_KEY%']);
    302311    if ($lock->isLocked() && !$lock->isMine()) {
     
    305314
    306315    // Break the cache because we are changing the list data.
    307     SessionCache::breakCache($_SERVER['PHP_SELF']);
     316    $cache->delete($_SERVER['PHP_SELF']);
    308317
    309318%UPDATE%
     
    313322    $version->create('%DB_TBL%', '%PRIMARY_KEY%', $frm['%PRIMARY_KEY%'], $frm['<##>']);
    314323
    315     App::raiseMsg(sprintf(_("The %ITEM_TITLE% <strong>%s</strong> has been updated."), $frm['<##>']), MSG_SUCCESS, __FILE__, __LINE__);
     324    $app->raiseMsg(sprintf(_("The %ITEM_TITLE% <strong>%s</strong> has been updated."), $frm['<##>']), MSG_SUCCESS, __FILE__, __LINE__);
    316325
    317326    // Unlock record.
     
    323332    global $page;
    324333    global $so;
    325 
     334    $db =& DB::getInstance();
     335    $prefs =& Prefs::getInstance();
     336    $cache =& SessionCache::getInstance();
     337   
    326338    $where_clause = '';
    327339
     
    336348    if (getFormData('filter_<##>', false)) {
    337349        // Limit by filter.
    338         $where_clause .= (empty($where_clause) ? 'WHERE' : 'AND') . " <##> = '" . DB::escapeString(getFormData('filter_<##>')) . "'";
     350        $where_clause .= (empty($where_clause) ? 'WHERE' : 'AND') . " <##> = '" . $db->escapeString(getFormData('filter_<##>')) . "'";
    339351    }
    340352
    341353    // Count the total number of records so we can do something about the page numbers.
    342     $qid = DB::query("
     354    $qid = $db->query("
    343355        SELECT COUNT(*)
    344356        FROM %DB_TBL%
     
    371383    // without knowing the hash.
    372384    $cache_hash = md5($sql . '|' . $page->total_items);
    373     if (Prefs::getValue('cache_hash', $_SERVER['PHP_SELF']) != $cache_hash) {
    374         SessionCache::breakCache($_SERVER['PHP_SELF']);
    375         Prefs::setValue('cache_hash', $cache_hash, $_SERVER['PHP_SELF']);
    376     }
    377 
    378     if (SessionCache::isCached($_SERVER['PHP_SELF'])) {
     385    if ($prefs->get('cache_hash', $_SERVER['PHP_SELF']) != $cache_hash) {
     386        $cache->delete($_SERVER['PHP_SELF']);
     387        $prefs->set('cache_hash', $cache_hash, $_SERVER['PHP_SELF']);
     388    }
     389
     390    if ($cache->exists($_SERVER['PHP_SELF'])) {
    379391        // Get the cached results.
    380         $list = SessionCache::getCache($_SERVER['PHP_SELF']);
     392        $list = $cache->get($_SERVER['PHP_SELF']);
    381393    } else {
    382394        // If the list is not already cached, query now.
    383         $qid = DB::query($sql);
     395        $qid = $db->query($sql);
    384396        // Fill an array with the items for this page.
    385397        while ($row = mysql_fetch_assoc($qid)) {
     
    389401        if (isset($list) && !empty($list)) {
    390402            // Cache the results.
    391             SessionCache::putCache($list, $_SERVER['PHP_SELF']);
     403            $cache->set($list, $_SERVER['PHP_SELF']);
    392404        }
    393405    }
     
    398410function updateRank($ranks)
    399411{
     412    $db =& DB::getInstance();
     413    $cache =& SessionCache::getInstance();
     414   
    400415    if (!is_array($ranks)) {
    401         App::logMsg('Saving rank failed, data posted is not an array: ' . $ranks, LOG_ERR, __FILE__, __LINE__);
     416        $app->logMsg('Saving rank failed, data posted is not an array: ' . $ranks, LOG_ERR, __FILE__, __LINE__);
    402417        return false;
    403418    }
    404419
    405420    // Break the cache because we are changing the list data.
    406     SessionCache::breakCache($_SERVER['PHP_SELF']);
     421    $cache->delete($_SERVER['PHP_SELF']);
    407422
    408423    // Count the ranks with invalid numbers
     
    416431            $unspecified_counter++;
    417432        }
    418         DB::query("
     433        $db->query("
    419434            UPDATE %DB_TBL% SET
    420                 rank = '" . DB::escapeString($new_rank) . "'
    421             WHERE %PRIMARY_KEY% = '" . DB::escapeString($id) . "'
     435                rank = '" . $db->escapeString($new_rank) . "'
     436            WHERE %PRIMARY_KEY% = '" . $db->escapeString($id) . "'
    422437        ");
    423438    }
    424439
    425     App::raiseMsg(_("Records have been reordered with the new rank."), MSG_SUCCESS, __FILE__, __LINE__);
     440    $app->raiseMsg(_("Records have been reordered with the new rank."), MSG_SUCCESS, __FILE__, __LINE__);
    426441    if ($unspecified_counter > 0) {
    427         App::raiseMsg(sprintf(_("%s items with unspecified ranks were automatically assigned a rank of 10000."), $unspecified_counter), MSG_NOTICE, __FILE__, __LINE__);
     442        $app->raiseMsg(sprintf(_("%s items with unspecified ranks were automatically assigned a rank of 10000."), $unspecified_counter), MSG_NOTICE, __FILE__, __LINE__);
    428443    }
    429444}
Note: See TracChangeset for help on using the changeset viewer.