コード例 #1
0
require_once "ControllerFunctions.php";
// We do includes based on rInfo; ensure that the only way to set it
// is internally.
$rInfo['renderer'] = '';
$rInfo['content'] = '';
// This will be used to find out our intended action
$opMap = buildOpMap();
$operation = getOperation($_SERVER['REQUEST_URI']);
// Get the Action for this operation, or a PageNotFoundAction if there's
// no match.
$action = new PageErrorAction();
if (isset($opMap[$operation])) {
    $action = $opMap[$operation];
}
// Defined in Init.php
if (SITE_MAINTANENCE && getRemoteIp() != DEBUG_IP) {
    $action = new SiteMaintanenceAction();
}
// There's one special case to worry about: the action requires
// authentication, and we're not logged in. Handle that and perform the
// Action.
if ($action->isAuthenticationRequired() && !isLoggedIn()) {
    $action = new LoginFormAction();
}
if ($action->isAdminRequired() && !isAdmin()) {
    $action = new PageErrorAction();
}
$rInfo = $action->perform();
$rInfo = fixRenderDefaults($rInfo);
// And dispatch the request to the view...
include $rInfo['renderer'];
コード例 #2
0
 function perform()
 {
     // Get the resources we need to do this update
     $db = $_REQUEST['db'];
     $userFinder = new UserFinder($db);
     $user = $userFinder->findById($_SESSION['userId']);
     $questionFinder = new QuestionFinder($db);
     // Grok all the relevant data from the form
     $qHash = array();
     $qHash['library_id'] = $user['library_id'];
     $qHash['location_id'] = gpwd('location', null);
     $qHash['question_type_id'] = gpwd('questionType', null);
     $qHash['question_type_other'] = gpwd('questionTypeOther');
     $qHash['time_spent_id'] = gpwd('timeSpent', null);
     $qHash['patron_type_id'] = gpwd('patronType', null);
     $qHash['question_format_id'] = gpwd('questionFormat', null);
     $qHash['initials'] = gpwd('initials');
     $qHash['client_ip'] = getRemoteIp();
     $qHash['user_id'] = $_SESSION['userId'];
     $qHash['question'] = gpwd('question');
     $qHash['answer'] = gpwd('answer');
     $qHash['question'] = trim($qHash['question']);
     $qHash['answer'] = trim($qHash['answer']);
     $qHash['hide'] = 0;
     if ($qHash['question'] == '' && $qHash['answer'] == '') {
         $qHash['hide'] = 1;
     }
     // Do the date
     $qHash['question_date'] = trim(gpwd('mydate', 'now'));
     if ($qHash['question_date'] == '') {
         $qHash['question_date'] = 'now';
     }
     $stamp = strtotime($qHash['question_date']);
     if ($stamp != -1) {
         $qHash['question_date'] = date('Y-m-d H:i:s', $stamp);
     } else {
         $qHash['question_date'] = null;
     }
     $qHash['date_added'] = date('Y-m-d H:i:s');
     // Clean up qHash; make numbers really numeric. The dirty little
     // trick: add 0 to non-null values names .*_id
     foreach ($qHash as $key => $val) {
         if (strpos($key, '_id')) {
             if ($val != null) {
                 $qHash[$key] = $val + 0;
             }
         }
     }
     $target = "questionAddForm.do";
     $res = $questionFinder->addQuestion($qHash);
     if (!DB::isError($res)) {
         // Use a Location: header to fly back; we don't want to
         // be able to double-enter by mistake.... I think.
         $url = "http://{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}";
         $url = substr($url, 0, -strrchr($url, '/')) . $target;
         header("Location: {$url}");
         exit;
     } else {
         // A page error occurred!
         $_REQUEST['dbResult'] = $res;
         $act = new PageErrorAction();
         return $act->perform();
     }
 }
コード例 #3
0
ファイル: Init.php プロジェクト: ncpltechnology/libstats
    foreach (glob($pattern) as $file) {
        require_once $file;
    }
}
if (STRIP_PORT) {
    // Pull the port number off $_SERVER['HTTP_HOST']
    $portPos = strpos($_SERVER['HTTP_HOST'], ":");
    if ($portPos) {
        $_SERVER['HTTP_HOST'] = substr($_SERVER['HTTP_HOST'], 0, $portPos);
    }
}
require_once 'DB.php';
require_once 'Utils.php';
//loop through subclasses--tight code! San Dimas High-School Football rules!
registerAll('actions/*Action.php');
registerAll('reports/*Report.php');
registerAll('finders/*Finder.php');
// Clear this, in case PageErrorAction somehow doesn't set it.
$rInfo['renderer'] = '';
$db = DB::connect(DSN);
$_REQUEST['db'] = $db;
if (DB::isError($db)) {
    // This will be a fatal error, head to a bad page
    $act = new PageErrorAction();
    $rInfo = $act->perform();
    include $rInfo['renderer'];
    die;
}
// Let's try and share the database connection throughout the application;
// reopening it all the time is a HUGE PAIN.
$_REQUEST['db']->setFetchMode(DB_FETCHMODE_ASSOC);