Changeset 136 for trunk/bin/module_maker/skel/admin.php
- Timestamp:
- Jun 3, 2006 7:47:48 PM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/bin/module_maker/skel/admin.php
r111 r136 11 11 $auth->requireLogin(); 12 12 // $auth->requireAccessClearance(ZONE_ADMIN_%NAME_UPPER%); 13 App::sslOn();13 $app->sslOn(); 14 14 15 15 require_once 'codebase/lib/PageNumbers.inc.php'; … … 33 33 $fv = new FormValidator(); 34 34 35 $cache =& SessionCache::getInstance(); 36 35 37 %SORT_ORDER% 36 38 … … 41 43 42 44 // 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_<##>'); 45 47 %ADMIN_UPLOAD_CONFIG% 46 48 /****************************************************************************** … … 51 53 // allows us to remember which page we came from so we can go back there. 52 54 if (getFormData('boomerang', false) && isset($_SERVER['HTTP_REFERER'])) { 53 App::setBoomerangURL($_SERVER['HTTP_REFERER'], '%NAME_PLURAL%');55 $app->setBoomerangURL($_SERVER['HTTP_REFERER'], '%NAME_PLURAL%'); 54 56 } 55 57 56 58 if (getFormData('break_list_cache', false)) { 57 59 // Break the cache because we are changing the list data. 58 SessionCache::breakCache($_SERVER['PHP_SELF']);60 $cache->delete($_SERVER['PHP_SELF']); 59 61 } 60 62 … … 81 83 // $auth->requireAccessClearance(ZONE_ADMIN_%NAME_UPPER%_FUNC_DELETE); 82 84 deleteRecord(getFormData('%PRIMARY_KEY%'));%ADMIN_UPLOAD_DEL% 83 if ( App::validBoomerangURL('%NAME_PLURAL%')) {85 if ($app->validBoomerangURL('%NAME_PLURAL%')) { 84 86 // Display boomerang page. 85 App::dieBoomerangURL('%NAME_PLURAL%');87 $app->dieBoomerangURL('%NAME_PLURAL%'); 86 88 } 87 89 // Display default page. 88 App::dieURL($_SERVER['PHP_SELF']);90 $app->dieURL($_SERVER['PHP_SELF']); 89 91 break; 90 92 … … 92 94 // $auth->requireAccessClearance(ZONE_ADMIN_%NAME_UPPER%_FUNC_ADD); 93 95 if (getFormdata('cancel', false)) { 94 if ( App::validBoomerangURL('%NAME_PLURAL%')) {96 if ($app->validBoomerangURL('%NAME_PLURAL%')) { 95 97 // Display boomerang page. 96 App::dieBoomerangURL('%NAME_PLURAL%');98 $app->dieBoomerangURL('%NAME_PLURAL%'); 97 99 } 98 100 // Display default page. 99 App::dieURL($_SERVER['PHP_SELF']);101 $app->dieURL($_SERVER['PHP_SELF']); 100 102 } 101 103 validateInput(); … … 109 111 if (getFormdata('repeat', false)) { 110 112 // 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%')) { 113 115 // Display boomerang page. 114 App::dieBoomerangURL('%NAME_PLURAL%');116 $app->dieBoomerangURL('%NAME_PLURAL%'); 115 117 } 116 118 // Display default page. 117 App::dieURL($_SERVER['PHP_SELF']);119 $app->dieURL($_SERVER['PHP_SELF']); 118 120 } 119 121 break; … … 122 124 // $auth->requireAccessClearance(ZONE_ADMIN_%NAME_UPPER%_FUNC_EDIT); 123 125 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%')); 126 128 } 127 129 if (getFormdata('cancel', false)) { … … 129 131 $lock->select('%DB_TBL%', '%PRIMARY_KEY%', getFormData('%PRIMARY_KEY%')); 130 132 $lock->remove(); 131 if ( App::validBoomerangURL('%NAME_PLURAL%')) {133 if ($app->validBoomerangURL('%NAME_PLURAL%')) { 132 134 // Display boomerang page. 133 App::dieBoomerangURL('%NAME_PLURAL%');135 $app->dieBoomerangURL('%NAME_PLURAL%'); 134 136 } 135 137 // Display default page. 136 App::dieURL($_SERVER['PHP_SELF']);138 $app->dieURL($_SERVER['PHP_SELF']); 137 139 } 138 140 validateInput(); … … 146 148 if (getFormdata('repeat', false)) { 147 149 // 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"); 149 151 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); 151 153 } 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__); 153 155 } 154 } else if ( App::validBoomerangURL('%NAME_PLURAL%')) {156 } else if ($app->validBoomerangURL('%NAME_PLURAL%')) { 155 157 // Display boomerang page. 156 App::dieBoomerangURL('%NAME_PLURAL%');158 $app->dieBoomerangURL('%NAME_PLURAL%'); 157 159 } 158 160 // Display default page. 159 App::dieURL($_SERVER['PHP_SELF']);161 $app->dieURL($_SERVER['PHP_SELF']); 160 162 } 161 163 break; … … 164 166 // $auth->requireAccessClearance(ZONE_ADMIN_PROGRAMS_FUNC_REORDER); 165 167 updateRank(getFormData('rank')); 166 App::dieURL($_SERVER['PHP_SELF']);168 $app->dieURL($_SERVER['PHP_SELF']); 167 169 break; 168 170 … … 207 209 { 208 210 global $lock; 209 211 $db =& DB::getInstance(); 212 210 213 $lock->select('%DB_TBL%', '%PRIMARY_KEY%', $id); 211 214 if ($lock->isLocked() && !$lock->isMine()) { … … 214 217 215 218 // Get the information for the form. 216 $qid = DB::query("219 $qid = $db->query(" 217 220 SELECT * 218 221 FROM %DB_TBL% 219 WHERE %PRIMARY_KEY% = '" . DB::escapeString($id) . "'222 WHERE %PRIMARY_KEY% = '" . $db->escapeString($id) . "' 220 223 "); 221 224 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(); 225 228 } 226 229 … … 246 249 { 247 250 global $lock; 248 251 $db =& DB::getInstance(); 252 $cache =& SessionCache::getInstance(); 253 249 254 $lock->select('%DB_TBL%', '%PRIMARY_KEY%', $id); 250 255 if ($lock->isLocked() && !$lock->isMine()) { … … 253 258 254 259 // Break the cache because we are changing the list data. 255 SessionCache::breakCache($_SERVER['PHP_SELF']);260 $cache->delete($_SERVER['PHP_SELF']); 256 261 257 262 // Get the information for this object. 258 $qid = DB::query("263 $qid = $db->query(" 259 264 SELECT <##> 260 265 FROM %DB_TBL% 261 WHERE %PRIMARY_KEY% = '" . DB::escapeString($id) . "'266 WHERE %PRIMARY_KEY% = '" . $db->escapeString($id) . "' 262 267 "); 263 268 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(); 267 272 } 268 273 269 274 // 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__); 273 278 274 279 // Unlock record. … … 279 284 { 280 285 global $auth; 281 286 $db =& DB::getInstance(); 287 $cache =& SessionCache::getInstance(); 288 282 289 // Break the cache because we are changing the list data. 283 SessionCache::breakCache($_SERVER['PHP_SELF']);290 $cache->delete($_SERVER['PHP_SELF']); 284 291 285 292 %INSERT% 286 $last_insert_id = mysql_insert_id( DB::getDBH());293 $last_insert_id = mysql_insert_id($db->getDBH()); 287 294 288 295 // Create version. … … 290 297 $version->create('%DB_TBL%', '%PRIMARY_KEY%', $last_insert_id, $frm['<##>']); 291 298 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__); 293 300 294 301 return $last_insert_id; … … 297 304 function updateRecord($frm) 298 305 { 299 global $auth, $lock; 300 306 global $auth, $lock; 307 $app =& App::getInstance(); 308 $cache =& SessionCache::getInstance(); 309 301 310 $lock->select('%DB_TBL%', '%PRIMARY_KEY%', $frm['%PRIMARY_KEY%']); 302 311 if ($lock->isLocked() && !$lock->isMine()) { … … 305 314 306 315 // Break the cache because we are changing the list data. 307 SessionCache::breakCache($_SERVER['PHP_SELF']);316 $cache->delete($_SERVER['PHP_SELF']); 308 317 309 318 %UPDATE% … … 313 322 $version->create('%DB_TBL%', '%PRIMARY_KEY%', $frm['%PRIMARY_KEY%'], $frm['<##>']); 314 323 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__); 316 325 317 326 // Unlock record. … … 323 332 global $page; 324 333 global $so; 325 334 $db =& DB::getInstance(); 335 $prefs =& Prefs::getInstance(); 336 $cache =& SessionCache::getInstance(); 337 326 338 $where_clause = ''; 327 339 … … 336 348 if (getFormData('filter_<##>', false)) { 337 349 // 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_<##>')) . "'"; 339 351 } 340 352 341 353 // Count the total number of records so we can do something about the page numbers. 342 $qid = DB::query("354 $qid = $db->query(" 343 355 SELECT COUNT(*) 344 356 FROM %DB_TBL% … … 371 383 // without knowing the hash. 372 384 $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'])) { 379 391 // Get the cached results. 380 $list = SessionCache::getCache($_SERVER['PHP_SELF']);392 $list = $cache->get($_SERVER['PHP_SELF']); 381 393 } else { 382 394 // If the list is not already cached, query now. 383 $qid = DB::query($sql);395 $qid = $db->query($sql); 384 396 // Fill an array with the items for this page. 385 397 while ($row = mysql_fetch_assoc($qid)) { … … 389 401 if (isset($list) && !empty($list)) { 390 402 // Cache the results. 391 SessionCache::putCache($list, $_SERVER['PHP_SELF']);403 $cache->set($list, $_SERVER['PHP_SELF']); 392 404 } 393 405 } … … 398 410 function updateRank($ranks) 399 411 { 412 $db =& DB::getInstance(); 413 $cache =& SessionCache::getInstance(); 414 400 415 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__); 402 417 return false; 403 418 } 404 419 405 420 // Break the cache because we are changing the list data. 406 SessionCache::breakCache($_SERVER['PHP_SELF']);421 $cache->delete($_SERVER['PHP_SELF']); 407 422 408 423 // Count the ranks with invalid numbers … … 416 431 $unspecified_counter++; 417 432 } 418 DB::query("433 $db->query(" 419 434 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) . "' 422 437 "); 423 438 } 424 439 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__); 426 441 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__); 428 443 } 429 444 }
Note: See TracChangeset
for help on using the changeset viewer.