// Ruta al registre d'usuaris Ruta::qualsevol('/', array('com' => 'index', 'usa' => 'estatic@index')); Ruta::qualsevol('cerca', array('com' => 'cerca', 'usa' => 'cercador@index')); Ruta::qualsevol('graus/{id}', array('com' => 'cerca', 'usa' => 'grau@detall')); /**************************************************** * AJAX * ****************************************************/ Ruta::get('ajax/graus/tots', function () { $return = array(); foreach (Grau::llistar() as $grau) { $grau['value'] = $grau['nom']; $return[] = $grau; } dieJSON($return); }); Ruta::get('ajax/llocs/comunitatsautonomes/totes', function () { $return = array(); foreach (ComunitatAutonoma::llistar() as $comunitatAutonoma) { $comunitatAutonoma['value'] = $comunitatAutonoma['nom']; $return[] = $comunitatAutonoma; } dieJSON($return); }); Ruta::get('ajax/llocs/universitats/totes', function () { $return = array(); foreach (Universitat::llistar() as $universitat) { $universitat['value'] = $universitat['nom']; $return[] = $universitat; } dieJSON($return); });
function requirePostDataFields() { $post_fields = func_get_args(); foreach ($post_fields as $field) { if (!isset($_POST[$field])) { dieJSON(array('error' => true, 'errorDesc' => "Missing {$field} value")); } } }
if (isset($_POST['deleteRoad'])) { requireCSRF(); requirePostDataFields('hash'); $hash = $_POST['hash']; if (!$loggedin) { dieJSON(array('error' => true, 'errorDesc' => 'Not logged in', 'hash' => $oldhash)); } if ($athena !== hashOwner($hash) && $hash !== 'null') { dieJSON(array('error' => true, 'errorDesc' => 'Bad owner or hash', 'hash' => $oldhash)); } if ($hash !== 'null') { CourseRoadDB::deleteRoad($hash, $athena); } dieJSON(array('success' => true, 'hash' => $hash)); } // When the user saves changes to their user prefs, we update their prefs if // they're logged in and redisplay the userprefs HTML. if (isset($_POST['viewUserSettings'])) { requireCSRF(); $_SESSION['user']['class_year'] = intval($_POST['class_year']); $_SESSION['user']['view_req_lines'] = $_POST['toggle_view_req_lines'] === '1' ? 1 : 0; $_SESSION['user']['autocomplete'] = $_POST['toggle_autocomplete'] === '1' ? 1 : 0; $_SESSION['user']['edited'] = $loggedin ? 0 : 1; if ($loggedin) { CourseRoadDB::updateUserPrefs($athena, $_SESSION['user']); } dieJSON(array('success' => true, 'html' => makeUserSettingsHTML())); } if (__DEV__ && isset($_GET['dev'])) { dieJSON(array('debug' => true, '$_POST' => @$_POST, '$_SESSION' => @$_SESSION, '$_SERVER' => @$_SERVER)); }