コード例 #1
0
ファイル: index.php プロジェクト: AndrewWang996/courseroad
// A visible "?hash=" in the URL is unwanted, so we redirect to remove it,
// but first store the hash to make loading faster.
if (isset($_GET['hash'])) {
    redirectHash(urldecode($_GET['hash']));
}
// Store that we've been to index.php.
$_SESSION['wenttoindex'] = true;
// We originally add add_new_term to SESSION to protect over the redirect above.
// Now we read it into a variable and clear the SESSION version.
$add_new_term = false;
if (isset($_SESSION['add_new_term'])) {
    $add_new_term = $_SESSION['add_new_term'];
    unset($_SESSION['add_new_term']);
    $json = array();
    foreach ($add_new_term['classes'] as $classname) {
        $classdata = pullClass(rtrim($classname, 'J'), $add_new_term['year'], $add_new_term['term']);
        if (!isset($classdata['error'])) {
            $json[] = $classdata;
        }
    }
    $add_new_term = addslashes(json_encode($json));
}
// If we haven't tried to log in, then default to false.
if (!isset($_SESSION['triedcert'])) {
    $_SESSION['triedcert'] = false;
}
// SESSION.athena is only set within secure.php, so if it has a value then we've
// logged in sucessfully
$loggedin = isset($_SESSION['athena']);
$athena = $loggedin ? $_SESSION['athena'] : false;
// Without logging in, we don't have a user pref map, so this set the default.
コード例 #2
0
ファイル: ajax.php プロジェクト: AndrewWang996/courseroad
    $_POST = $_POST + $_GET;
}
require 'functions.php';
// Yields a JSON-encoded list of classes which match the autocompletion field
// in the Add Class tab.
if (isset($_POST['autocomplete'])) {
    $results = CourseRoadDB::getAutocompleteResults($_POST['autocomplete']);
    dieJSON($results);
}
// Loads class data from the database and serves up the JSON which CourseRoad
// requires to load that class.
if (isset($_POST['getClass'])) {
    requirePostDataFields('subjectId');
    $class = $_POST['subjectId'];
    $year = isset($_POST['year']) ? $_POST['year'] : false;
    dieJSON(pullClass($class, $year));
}
// Same, but for a custom class. These are used by the Add tab.
if (isset($_POST['getCustom'])) {
    requirePostDataFields('name');
    $units = isset($_POST['units']) ? floatval($_POST['units']) : false;
    dieJSON(pullCustom($_POST['name'], $units));
}
// Returns the desired hash's class and major data
if (isset($_POST['getHash'])) {
    requireCSRF();
    requirePostDataFields('hash');
    dieJSON(buildClassesArray($_POST['hash']));
}
// If we haven't tried to log in, then default to false.
if (!isset($_SESSION['triedcert'])) {
コード例 #3
0
function buildClassesArray($hash)
{
    $_SESSION['crhash'] = $hash;
    // Pull out the latest matching saved road's classes and majors
    $classdata = CourseRoadDB::getClassDataFromRoad($hash);
    if (!$classdata) {
        die;
    }
    $classes = json_decode(CourseRoadDB::decrypt($classdata['classes']), true);
    $majors = stripslashes(CourseRoadDB::decrypt($classdata['majors']));
    $majors = json_decode($majors, true);
    if (!$classes) {
        return array('error' => true, 'errorDesc' => 'No classes');
    }
    $classes_data = array();
    foreach ($classes as &$class) {
        if (!isset($class['override'])) {
            $class['override'] = false;
        }
        if (!isset($class['substitute'])) {
            $class['substitute'] = '';
        }
        if (isset($class['custom'])) {
            $classes_data[] = pullCustom($class['name'], $class['units'], $class['term'], $class['override'], $class['substitute']);
        } else {
            $classdata = pullClass($class['id'], $class['year'], $class['term'], $class['override'], $class['substitute']);
            if ($classdata !== 'noclass') {
                $classes_data[] = $classdata;
            }
        }
    }
    return array('classes' => $classes_data, 'majors' => $majors);
}