GET['type']; // get media-type $real_path = MEDIA_STORAGE_ROOT . $file_path; // construct real path if (!file_exists($real_path)) { Render::view('error/404'); } else { Render::file($real_path, $media_type); } } else { Render::view('error/404', [ 'error_code' => 403, 'moto' => 'Forbidden', 'message' => '' ]); } } /** get_file_attributes * * returns attributes of a file * (medias are proxied for speed optimization) * * @param $path (string) : file path * @return $file attributes --or-- false */ private static function get_file_attributes($path) { $medias = Cache_service::files_attributes(); foreach($medias as $key => $medi) { if ($medi['path'] == $path) { return $medi; } } return false; } ## PETITIONS ## ------------------------------------------------------------------------- ## secretarial support / teachers' requests and applications /** (any) petition * * check if user is authorized to view the content; * if so, prepare and render the petition view * * @param $petition_type (string): [common|penalty] */ public static function request_petition($petition_tag) { // get current user $manager = new App_manager(); if (!$manager->hasUserToken()) { // if user is not connected Render::view('error/404', [ 'error_code' => 403, // serve forbidden 'moto' => 'Forbidden', 'message' => 'Για να έχετε πρόσβαση, θα πρέπει πρώτα να συνδεθείτε' ]); die(); // then end; } $token = $manager->getUserToken(); // from token $user = $token->getUser(); // create user $id = $user->getID(); // keep id user switch ($petition_tag) { // route to specific type of petition case 'application': self::render_application_form(['user' => $user]); break; case 'penalty': self::render_penalty_form(['user' => $user]); break; default: // if not a known petition type Render::view('error/404', [ // then serve not-found 'message' => 'Δεν βρέθηκε το είδος της αίτησης ή του εγγράφου που ζητήσατε.' ]); } } /** render application form * */ private static function render_application_form($opts) { // #1: user-id --------------------------------------------------------- $user_id = $opts['user']->getID(); // #2: form template --------------------------------------------------- $form_setup = json_decode(json_encode(APPLICATION_FORM, JSON_UNESCAPED_UNICODE)); // #3: inject default values ------------------------------------------- $userData = Auth::user_data(); // #3.1: inject user data $form_setup->defaults = json_decode( json_encode( $userData, JSON_UNESCAPED_UNICODE )); // #3.2 inject `sector` and `position`