/** * Show the profile of a group */ public function view($params) { $this->setView('view.php'); try { $group = $this->model->getInfoByName($params['group']); $this->set('group', $group); } catch (Exception $e) { throw new ActionException('Page', 'error404'); } $this->setTitle(__('GROUP_TITLE', array('group' => htmlspecialchars($group['name'])))); $is_logged = isset(User_Model::$auth_data); $is_student = $is_logged && isset(User_Model::$auth_data['student_number']); $is_admin = $is_logged && User_Model::$auth_data['admin'] == '1'; $category = isset($params['category']) ? $params['category'] : null; $category_model = new Category_Model(); $post_model = new Post_Model(); $this->set(array('is_logged' => $is_logged, 'is_student' => $is_student, 'is_admin' => $is_admin, 'categories' => $category_model->getAll(), 'current_category' => $category, 'posts' => $post_model->getPosts(array('restricted' => true, 'group_id' => (int) $group['id'], 'category_name' => $category, 'official' => $is_logged ? null : true, 'show_private' => $is_student), Config::POST_DISPLAYED))); // Events $event_model = new Event_Model(); $this->set(array('events' => $event_model->getByMonth((int) date('Y'), (int) date('n'), array('group_id' => (int) $group['id'], 'official' => $is_logged ? null : true, 'show_private' => $is_student)), 'calendar_month' => (int) date('n'), 'calendar_year' => (int) date('Y'))); // If the user is logged if ($is_logged) { $this->set(array('username' => User_Model::$auth_data['username'], 'groups_auth' => Group_Model::getAuth())); } if ($is_student) { $this->set(array('firstname' => User_Model::$auth_data['firstname'], 'lastname' => User_Model::$auth_data['lastname'], 'avatar_url' => User_Model::$auth_data['avatar_url'])); } }
/** * Show the profile of a student */ public function view($params) { $this->setView('view.php'); $is_logged = isset(User_Model::$auth_data); $is_student = $is_logged && isset(User_Model::$auth_data['student_number']); $is_admin = $is_logged && User_Model::$auth_data['admin'] == '1'; // If the user isn't logged in if (!$is_logged) { throw new ActionException('User', 'signin', array('redirect' => $_SERVER['REQUEST_URI'])); } try { $student = $this->model->getInfo($params['username']); $post_model = new Post_Model(); $this->setTitle(htmlspecialchars($student['firstname'] . ' ' . $student['lastname'])); $this->set(array('student' => $student, 'groups' => isset($student['id']) ? Group_Model::getAuth((int) $student['id']) : array(), 'is_owner' => User_Model::$auth_data['username'] == $student['username'], 'is_logged' => true, 'is_student' => $is_student, 'is_admin' => $is_admin, 'username' => User_Model::$auth_data['username'])); if ($is_student) { $this->set(array('firstname' => User_Model::$auth_data['firstname'], 'lastname' => User_Model::$auth_data['lastname'], 'avatar_url' => User_Model::$auth_data['avatar_url'])); } // If the student is a user, we show their posts if (isset($student['id'])) { $category = isset($params['category']) ? $params['category'] : null; $category_model = new Category_Model(); $this->set(array('posts' => $post_model->getPosts(array('restricted' => true, 'user_id' => (int) $student['id'], 'category_name' => $category, 'official' => false, 'show_private' => $is_student), Config::POST_DISPLAYED), 'categories' => $category_model->getAll(), 'current_category' => $category)); } } catch (Exception $e) { throw new ActionException('Page', 'error404'); } }
function update_action() { $post_Model = new Post_Model(); $post_Model->update_post_by_id(); $posts = $post_Model->get_all_posts(); require "view/template/post/admin.php"; }
function index() { $uid = Session::get('loggedIn'); require 'models/post_model.php'; $model = new Post_Model(); $posts = $model->viewall(); $this->view->posts = $posts; $this->view->render('index/index'); }
function create_profile_picture_post() { // need to require post model $model = new Post_Model(); $x = $model->create(Session::get('id')); if ($x == true) { echo 'successfuly created'; header("Location:" . URL . "/post"); exit; } else { echo 'error'; } exit; }
public static function getInstance() { if (self::$instance == null) { self::$instance = new Post_Model(); } return self::$instance; }
public static function attachmentDelete($post_id, $attach_id) { $id = DB::createQuery('post_comments')->fields('id')->where(array('attachment_id' => $attach_id, 'post_id' => $post_id))->select(); for ($i = 0; $i < count($id); $i++) { $id = $this->createQuery()->delete($id[$i]['id']); } Post_Model::clearCache(); }
/** * Add a vote in a survey * * @param int $id Id of the survey * @param array $id Ids of the answers * @param string $username User name * @return int Id of the corresponding post */ public function vote($id, $votes, $username) { if (count($votes) == 0) { throw new Exception('You should give at least one answer'); } $surveys = $this->createQuery()->select($id); if (!isset($surveys[0])) { throw new Exception('Survey not found'); } $survey = $surveys[0]; unset($surveys); if ($survey['multiple'] != '1' && count($votes) != 1) { throw new Exception('You must choose exactly one answer'); } if (strtotime($survey['date_end']) < time()) { throw new Exception('The survey is closed'); } $post_model = new Post_Model(); $post = $post_model->getRawPost((int) $survey['post_id']); $answers = DB::createQuery('survey_answers')->fields('id', 'votes')->where(array('survey_id' => $survey['id']))->select(); foreach ($answers as $answer) { $answer['votes'] = $answer['votes'] == '' ? array() : json_decode($answer['votes'], true); if (in_array($username, $answer['votes']) && !in_array((int) $answer['id'], $votes)) { array_splice($answer['votes'], array_search($username, $answer['votes']), 1); $weight = -1; } else { if (!in_array($username, $answer['votes']) && in_array((int) $answer['id'], $votes)) { $answer['votes'][] = $username; $weight = 1; } else { continue; } } DB::createQuery('survey_answers')->set(array('votes' => json_encode($answer['votes']), 'nb_votes = nb_votes' . ($weight == 1 ? '+1' : '-1')))->update((int) $answer['id']); } Post_Model::clearCache(); return (int) $post['id']; }
/** * Send votes in a survey */ public function vote($params) { $this->setView('vote.php'); if (!isset(User_Model::$auth_data)) { throw new Exception('You must be logged in'); } if (!isset(User_Model::$auth_data['student_number'])) { throw new Exception('You must be a student to vote'); } $votes = array(); foreach ($_POST as $key => $value) { if (strpos($key, 'answer') === 0 && ctype_digit($value)) { $votes[] = (int) $value; } } try { $post_id = $this->model->vote($params['id'], $votes, User_Model::$auth_data['username']); $post_model = new Post_Model(); $post = $post_model->getPost($post_id); $this->set(array('is_logged' => true, 'is_student' => true, 'is_admin' => User_Model::$auth_data['admin'] == '1', 'username' => User_Model::$auth_data['username'], 'firstname' => User_Model::$auth_data['firstname'], 'lastname' => User_Model::$auth_data['lastname'], 'avatar_url' => User_Model::$auth_data['avatar_url'], 'post' => $post)); } catch (Exception $e) { } }
/** * Search posts, groups, and students */ public function index($params) { $this->setView('index.php'); $is_logged = isset(User_Model::$auth_data); $is_student = $is_logged && isset(User_Model::$auth_data['student_number']); $is_admin = $is_logged && User_Model::$auth_data['admin'] == '1'; if (!isset($_GET['q'])) { throw new ActionException('Page', 'error404'); } $limit = 100; $results = $this->model->search($_GET['q'], null, $limit, !$is_logged, $is_student); $posts_ids = array(); $students_usernames = array(); $groups_ids = array(); foreach ($results as &$result) { switch ($result['_type']) { case 'student': $students_usernames[] = $result['_id']; break; case 'group': $groups_ids[] = (int) $result['_id']; break; case 'post': $posts_ids[] = (int) $result['_id']; break; } } $post_model = new Post_Model(); $this->setTitle(__('SEARCH_TITLE', array('query' => htmlspecialchars($_GET['q'])))); $this->set(array('query' => $_GET['q'], 'posts' => $post_model->getPosts(array('restricted' => true, 'ids' => $posts_ids, 'show_private' => $is_student), $limit), 'students' => Student_Model::getInfoByUsernames($students_usernames), 'groups' => Group_Model::getInfoByIds($groups_ids), 'is_logged' => true, 'is_student' => $is_student, 'is_admin' => $is_admin)); if ($is_logged) { $this->set(array('username' => User_Model::$auth_data['username'])); } if ($is_student) { $this->set(array('firstname' => User_Model::$auth_data['firstname'], 'lastname' => User_Model::$auth_data['lastname'], 'avatar_url' => User_Model::$auth_data['avatar_url'])); } }
} if (isset($_GET['install']) && $_GET['install'] == "true") { // Envoi des données de base pour l'installation sur l'appli $Categories = new Category_Model(); $tableauDesCategories = $Categories->getAll(); foreach ($tableauDesCategories as $cat) { $GroupXml = $xml->createElement('category'); $node = $xml->createElement('name', $cat['name']); $GroupXml->appendChild($node); $node = $xml->createElement('id', $cat['id']); $GroupXml->appendChild($node); $MainNode->appendChild($GroupXml); } } // Lecture des posts demandés et $model = new Post_Model(); // Parametres de base : $postParam = array('restricted' => true, 'show_private' => true); if (isset($_GET['id']) && $_GET['id'] != "-1") { $postParam['id'] = $_GET['id']; } if (isset($_GET['official']) && $_GET['official'] == "true") { $postParam['official'] = true; } elseif (isset($_GET['official']) && $_GET['official'] == "false") { $postParam['official'] = false; } if (isset($_GET['category']) && $_GET['category'] != "") { $postParam['category_id'] = $_GET['category']; } $posts = $model->getPosts($postParam, 5); foreach ($posts as $post) {
public function isepdorPage($param) { $this->setView('isepdor.php'); $questions = $this->model->getquestions(); for ($i = 0; $i < count($questions); $i++) { $type = explode(',', $questions[$i]["type"]); $tab = array("students", "associations", "employees", "events"); $result = array_intersect($type, $tab); if (in_array("students", $result)) { $questions[$i]["students"] = 1; } else { $questions[$i]["students"] = 0; } if (in_array("events", $result)) { $questions[$i]["events"] = 1; } else { $questions[$i]["events"] = 0; } if (in_array("associations", $result)) { $questions[$i]["associations"] = 1; } else { $questions[$i]["associations"] = 0; } if (in_array("employees", $result)) { $questions[$i]["employees"] = 1; } else { $questions[$i]["employees"] = 0; } if ($questions[$i]["extra"] == null) { $questions[$i]["extra"] = " "; } } $events = $this->model->getevents(); for ($i = 0; $i < count($events); $i++) { if ($events[$i]['extra'] == "soiree") { $events[$i]['extra'] = 1; } else { $events[$i]['extra'] = 0; } } $myFile = DATA_DIR . Config::DIR_DATA_STORAGE . Config::DIR_DATA_ADMIN . "/diplome.json"; $file = fopen($myFile, 'r'); $positions = fread($file, filesize($myFile)); fclose($file); $this->addJSCode(' Admin.loadjscssfile("' . Config::URL_STATIC . 'js/jqx/jqxcore.js","js"); Admin.loadjscssfile("' . Config::URL_STATIC . 'js/jqx/jqxdata.js","js"); Admin.loadjscssfile("' . Config::URL_STATIC . 'js/jqx/jqxbuttons.js","js"); Admin.loadjscssfile("' . Config::URL_STATIC . 'js/jqx/jqxscrollbar.js","js"); Admin.loadjscssfile("' . Config::URL_STATIC . 'js/jqx/jqxmenu.js","js"); Admin.loadjscssfile("' . Config::URL_STATIC . 'js/jqx/jqxgrid.js","js"); Admin.loadjscssfile("' . Config::URL_STATIC . 'js/jqx/jqxgrid.edit.js","js"); Admin.loadjscssfile("' . Config::URL_STATIC . 'js/jqx/jqxgrid.selection.js","js"); Admin.loadjscssfile("' . Config::URL_STATIC . 'js/jqx/jqxgrid.sort.js","js"); Admin.loadjscssfile("' . Config::URL_STATIC . 'js/jqx/jqxgrid.filter.js","js"); Admin.loadjscssfile("' . Config::URL_STATIC . 'js/jqx/jqxgrid.columnsresize.js","js"); Admin.loadjscssfile("' . Config::URL_STATIC . 'js/jqx/jqxlistbox.js","js"); Admin.loadjscssfile("' . Config::URL_STATIC . 'js/jqx/jqxdropdownlist.js","js"); Admin.loadjscssfile("' . Config::URL_STATIC . 'js/jqx/jqxcheckbox.js","js"); Admin.loadjscssfile("' . Config::URL_STATIC . 'js/jqx/jqxcombobox.js","js"); Admin.loadjscssfile("' . Config::URL_STATIC . 'js/jqx/jqxgrid.pager.js","js"); Admin.loadjscssfile("' . Config::URL_STATIC . 'js/jqx/jqxdragdrop.js","js"); Admin.loadjscssfile("' . Config::URL_STATIC . 'js/jqx/jqxcalendar.js","js"); Admin.loadjscssfile("' . Config::URL_STATIC . 'js/jqx/jqxtooltip.js","js"); Admin.loadjscssfile("' . Config::URL_STATIC . 'js/jqx/jqxdatetimeinput.js","js"); Admin.loadjscssfile("' . Config::URL_STATIC . 'js/jqx/jquery.global.js","js"); Admin.loadjscssfile("' . Config::URL_STATIC . 'js/jqx/jquery.glob.fr-FR.js","js"); Admin.loadjscssfile("' . Config::URL_STATIC . 'js/jqx/jqxtabs.js","js"); Admin.loadjscssfile("' . Config::URL_STATIC . 'js/crop/jquery.Jcrop.min.js","js"); Admin.loadjscssfile("' . Config::URL_STATIC . 'js/crop/jquery.color.js","js"); jQuery(document).ready(function () { diplomeData=new Array(); Admin.loadTab(); Admin.loadCrop(); Admin.loadCatGrid(' . json_encode($questions) . '); Admin.loadEventGrid(' . json_encode($events) . '); Admin.loadEmployGrid(' . json_encode($this->model->getemployees()) . '); Admin.loadDate(' . json_encode($this->model->getDate()) . '); jQuery(".jcrop-holder").ready(function () { Admin.loadDiplome(' . $positions . '); }); jQuery("#adminIsepdorTab").removeClass("hidden"); }); '); /* Code qui met à jour le questionnaire pour les ISEP D'or * */ if (isset($_POST['categories'])) { $id = array(); $post = json_decode($_POST['categories'], true); for ($i = 0; $i < count($post); $i++) { if (is_numeric($post[$i]['id'])) { array_push($id, $post[$i]['id']); } } $toDelete = $this->model->checkIsepdorQuestions($id); if (count($toDelete) > 0) { for ($i = 0; $i < count($toDelete); $i++) { $this->model->deleteQuestions($toDelete[$i]); } } for ($i = 0; $i < count($post); $i++) { if ($post[$i]['extra'] == "") { $post[$i]['extra'] = NULL; } if ($post[$i]['id'] != "") { $this->model->updateisepdor($post[$i]['type'], $post[$i]['extra'], $post[$i]['questions'], $post[$i]['id'], $post[$i]['position']); } elseif ($post[$i]['id'] == "") { $this->model->insertisepdor($post[$i]['type'], $post[$i]['extra'], $post[$i]['questions'], $post[$i]['position']); } } } /*Code qui met à jour la table isepdor_employees * */ if (isset($_POST['employees'])) { $id = array(); $post = json_decode($_POST['employees'], true); for ($i = 0; $i < count($post); $i++) { if (is_numeric($post[$i]['id'])) { array_push($id, $post[$i]['id']); } } $toDelete = $this->model->checkIsepdorEmployees($id); if (count($toDelete) > 0) { for ($i = 0; $i < count($toDelete); $i++) { $this->model->deleteEmployees($toDelete[$i]); } } for ($i = 0; $i < count($post); $i++) { $username = $this->makeusername($post[$i]['lastname'], $post[$i]['firstname']); if ($post[$i]['id'] != "") { $this->model->updateEmployees($post[$i]['lastname'], $post[$i]['firstname'], $post[$i]['id'], $username); } elseif ($post[$i]['id'] == "") { $this->model->insertemployees($post[$i]['lastname'], $post[$i]['firstname'], $username); } } } /*Code qui met à jour la table isepdor_event * */ if (isset($_POST['events'])) { $id = array(); $post = json_decode($_POST['events'], true); for ($i = 0; $i < count($post); $i++) { if (is_numeric($post[$i]['id'])) { array_push($id, $post[$i]['id']); } } $toDelete = $this->model->checkIsepdorEvents($id); if (count($toDelete) > 0) { for ($i = 0; $i < count($toDelete); $i++) { $this->model->deleteEvents($toDelete[$i]); } } for ($i = 0; $i < count($post); $i++) { if ($post[$i]['extra'] == 1) { $post[$i]['extra'] = "soiree"; } else { $post[$i]['extra'] = NULL; } if ($post[$i]['id'] != "") { $this->model->updateEvent($post[$i]['name'], $post[$i]['id'], $post[$i]['extra']); } elseif ($post[$i]['id'] == "") { $this->model->insertEvent($post[$i]['name'], $post[$i]['extra']); } } } /*Code qui met à jour les date de vote des isep d'or * */ if (isset($_POST['dates'])) { $post = json_decode($_POST['dates'], true); $this->model->insertDate($post[0][0], $post[0][1], $post[1][0], $post[1][1], $post[2][0], $post[2][1]); } /* * Change l'image diplome */ if (isset($_FILES['diplome']) && !is_array($_FILES['diplome']['name'])) { if ($_FILES['diplome']['size'] > Config::UPLOAD_MAX_SIZE_PHOTO) { throw new FormException('size'); } if ($avatarpath = File::upload('diplome')) { $uploaded_files[] = $avatarpath; try { $img = new Image(); $img->load($avatarpath); $type = $img->getType(); if ($type == IMAGETYPE_JPEG) { $ext = 'jpg'; } else { if ($type == IMAGETYPE_GIF) { $ext = 'gif'; } else { if ($type == IMAGETYPE_PNG) { $ext = 'png'; } else { throw new Exception(); } } } if ($img->getHeight() != 794 || $img->getWidth() != 1122) { throw new FormException('width'); } $img->setType($type); $img->save($avatarpath); unset($img); if (isset($avatarpath) && File::exists($avatarpath)) { $avatar_path = DATA_DIR . Config::DIR_DATA_STORAGE . Config::DIR_DATA_ADMIN . "diplomeIsepDOr9652.png"; $avatar_dir = File::getPath($avatar_path) . "/diplomeIsepDOr9652.png"; File::rename($avatarpath, $avatar_dir); } } catch (FormException $e) { $this->set('form_error', $e->getError()); } foreach ($uploaded_files as $uploaded_file) { File::delete($uploaded_file); } } Post_Model::clearCache(); } /* * Enregistre les coordonnées */ if (isset($_POST['diplomeData'])) { $post = $_POST['diplomeData']; $file = fopen($myFile, 'w'); fwrite($file, $post); fclose($file); } /* * Envoie les diplomes */ if (isset($_GET['getDiplome'])) { $template = DATA_DIR . Config::DIR_DATA_STORAGE . Config::DIR_DATA_ADMIN . "diplomeIsepDOr9652.png"; $font = DATA_DIR . Config::DIR_DATA_STORAGE . Config::DIR_DATA_ADMIN . "font2354.ttf"; $files = array(); $positions = json_decode($positions, true); //récupere les coordonnées précédament demandées for ($i = 0; $i < count($positions); $i++) { $coord[$positions[$i]['index']] = $positions[$i]; } $questions = IsepOr_Model::fetchQuestions(); foreach ($questions as $value) { if (strpos($value['type'], ',')) { $data = array(); foreach (explode(',', $value['type']) as $type) { $data = IsepOr_Controller::__array_rePad($data, IsepOr_Model::fetchFinals($value['id'], $type, 2)); } $finalList[$value['id']] = array_slice(IsepOr_Controller::__array_orderby($data, 'cmpt', SORT_DESC), 0, 3); } else { $finalList[$value['id']] = IsepOr_Model::fetchFinals($value['id'], $value['type'], 2); } } for ($i = 0; $i < count($questions); $i++) { for ($j = 0; $j < count($finalList[$questions[$i]['id']]); $j++) { File::copy($template, DATA_DIR . Config::DIR_DATA_TMP . "diplome" . $i . $j . ".png"); array_push($files, DATA_DIR . Config::DIR_DATA_TMP . "diplome" . $i . $j . ".png"); $im = ImageCreateFromPng(DATA_DIR . Config::DIR_DATA_TMP . "diplome" . $i . $j . ".png"); // Path Images $color = ImageColorAllocate($im, 0, 0, 0); // Text Color $champs[0] = $questions[$i]['questions']; $champs[1] = $finalList[$questions[$i]['id']][$j]["name"]; $champs[2] = ""; if (!is_numeric($finalList[$questions[$i]['id']][$j]["valid"])) { $champs[2] = $this->model->getBirthDay($finalList[$questions[$i]['id']][$j]["valid"]); } for ($a = 0; $a < 3; $a++) { $pxX = round($coord[$a]['x1']); // X $pxY = round($coord[$a]['y2']); // Y ImagettfText($im, round($coord[$a]['h']), 0, $pxX, $pxY, $color, $font, $champs[$a]); } imagePng($im, DATA_DIR . Config::DIR_DATA_TMP . "diplome" . $i . $j . ".png", 9); ImageDestroy($im); if ($finalList[$questions[$i]['id']][$j]['cmpt'] != $finalList[$questions[$i]['id']][$j + 1]['cmpt']) { break; } } } if (self::create_zip($files, DATA_DIR . Config::DIR_DATA_TMP . "diplomesIsepDor.zip", true)) { foreach ($files as $file) { File::delete($file); } header($_SERVER["SERVER_PROTOCOL"] . " 200 OK"); header("Cache-Control: public"); // needed for i.e. header("Content-Type: application/zip"); header("Content-Transfer-Encoding: Binary"); header("Content-Length:" . filesize(DATA_DIR . Config::DIR_DATA_TMP . "diplomesIsepDor.zip")); header("Content-Disposition: attachment; filename=diplomesIsepDor.zip"); readfile(DATA_DIR . Config::DIR_DATA_TMP . "diplomesIsepDor.zip"); File::delete(DATA_DIR . Config::DIR_DATA_TMP . "diplomesIsepDor.zip"); die; } foreach ($files as $file) { File::delete($file); } } /*Code qui export les résultats des isep d'or * */ if (isset($_GET['export'])) { $db = $this->model->getResult(); header('Content-Type: application/vnd.ms-excel'); header('Content-Disposition: filename=' . 'Résultats_Isepdor' . '.xls'); header('Pragma: no-cache'); header('Expires: 0'); print '<table border=1 > <!-- impression des titres de colonnes --> <TR> <TD bgcolor="#3366CC">Tour</TD> <TD bgcolor="#3366CC">Nom du votant</TD> <TD bgcolor="#3366CC">Catégorie</TD> <TD bgcolor="#3366CC">Réponse(student)</TD> <TD bgcolor="#3366CC">Réponse(admin)</TD> <TD bgcolor="#3366CC">Réponse(assoce)</TD> <TD bgcolor="#3366CC">Réponse(event)</TD> </TR> '; foreach ($db as $champs) { print '<TR>'; print '<TD>' . $champs['round'] . '</TD>'; print '<TD>' . $champs['username'] . '</TD>'; print '<TD>' . utf8_decode($champs['questions']) . '</TD>'; print '<TD>' . $champs['student_username'] . '</TD>'; print '<TD>' . utf8_decode($champs['admin']) . '</TD>'; print '<TD>' . utf8_decode($champs['assoce']) . '</TD>'; print '<TD>' . utf8_decode($champs['name']) . '</TD>'; print '</TR>'; } print '</table>'; exit; } /* * Ajout de la police */ if (isset($_FILES['font']) && $_FILES['font']['name'] != null) { if ($_FILES['font']['size'] > Config::UPLOAD_MAX_SIZE_FILE) { throw new Exception(__('POST_ADD_ERROR_FILE_SIZE', array('size' => File::humanReadableSize(Config::UPLOAD_MAX_SIZE_FILE)))); } if ($filepaths = File::upload('font')) { if (!preg_match('#\\.ttf$#i', $filepaths)) { throw new Exception(__('POST_ADD_ERROR_FILE_FORMAT')); } $avatar_path = DATA_DIR . Config::DIR_DATA_STORAGE . Config::DIR_DATA_ADMIN . "font2354.ttf"; $avatar_dir = File::getPath($avatar_path) . "/font2354.ttf"; File::rename($filepaths, $avatar_dir); } else { throw new Exception(__('ADMIN_UPLOAD_ERROR')); } } /*Code qui met supprime les champs de la table résultat des isep d'or * */ if (isset($_GET['delete_result'])) { $this->model->deleteresult(); header("Location: " . Config::URL_ROOT . Routes::getPage('admin', array("nav" => "isepdor"))); } }
/** * Delete a group * * @param int $id Id of the group */ public function delete($id) { $this->createQuery()->delete($id); self::clearCache(); Post_Model::clearCache(); // Delete the avatar File::delete(self::getAvatarPath($id, true)); File::delete(self::getAvatarPath($id, false)); // Delete from the search index $search_model = new Search_Model(); $search_model->delete('group', $id); }
public function addAttachment($param) { $this->setView('iframe_add.php'); $is_logged = isset(User_Model::$auth_data); $is_admin = $is_logged && User_Model::$auth_data['admin'] == '1'; @set_time_limit(0); $uploaded_files = array(); $attachments = array(); try { if ($is_admin && isset($param['id']) && isset($_FILES['attachment_photo']) && is_array($_FILES['attachment_photo']['name'])) { foreach ($_FILES['attachment_photo']['size'] as $size) { if ($size > Config::UPLOAD_MAX_SIZE_PHOTO) { throw new Exception(__('POST_ADD_ERROR_PHOTO_SIZE', array('size' => File::humanReadableSize(Config::UPLOAD_MAX_SIZE_PHOTO)))); } } if ($filepaths = File::upload('attachment_photo')) { foreach ($filepaths as $filepath) { $uploaded_files[] = $filepath; } foreach ($filepaths as $i => $filepath) { $name = isset($_FILES['attachment_photo']['name'][$i]) ? $_FILES['attachment_photo']['name'][$i] : ''; try { $img = new Image(); $img->load($filepath); $type = $img->getType(); if ($type == IMAGETYPE_JPEG) { $ext = 'jpg'; } else { if ($type == IMAGETYPE_GIF) { $ext = 'gif'; } else { if ($type == IMAGETYPE_PNG) { $ext = 'png'; } else { throw new Exception(); } } } if ($img->getWidth() > 800) { $img->setWidth(800, true); } $img->save($filepath); // Thumb $thumbpath = $filepath . '.thumb'; $img->thumb(Config::$THUMBS_SIZES[0], Config::$THUMBS_SIZES[1]); $img->setType(IMAGETYPE_JPEG); $img->save($thumbpath); unset($img); $attachments[] = array($filepath, $name, $thumbpath); $uploaded_files[] = $thumbpath; } catch (Exception $e) { throw new Exception(__('POST_ADD_ERROR_PHOTO_FORMAT')); } } } // Attach files foreach ($attachments as $attachment) { $this->model->attachFile($param['id'], $attachment[0], $attachment[1], isset($attachment[2]) ? $attachment[2] : null); } $this->addJSCode(' parent.location = "' . Config::URL_ROOT . Routes::getPage('post', array('id' => $param['id'])) . '"; '); } Post_Model::clearCache(); } catch (Exception $e) { // Delete all uploading files in tmp foreach ($uploaded_files as $uploaded_file) { File::delete($uploaded_file); } $this->addJSCode(' with(parent){ Post.errorForm(' . json_encode($e->getMessage()) . '); } '); } }
<?php require 'admin_init.php'; login(); require ADMIN_VIEW_PATH . 'header.php'; // default order by date $orderby = isset($_GET['orderby']) ? $_GET['orderby'] : 'date'; // title => asc order, time => desc order if (isset($_GET['order'])) { $order = $_GET['order']; } else { $order = $orderby == 'title' ? 'asc' : 'desc'; } $order_clause = "post_{$orderby} {$order}"; if (!isset($_GET['term_id'])) { $posts = Post_Model::getInstance()->getPostlist($order_clause); } else { $request_clause = 'term_id=' . $_GET['term_id'] . '&'; $posts = Post_Model::getInstance()->getPostsByTerm($_GET['term_id'], $order_clause); } $order = isset($_GET['order']) ? $_GET['order'] == 'asc' ? 'desc' : 'asc' : 'asc'; require ADMIN_VIEW_PATH . 'admin_log.php'; require ADMIN_VIEW_PATH . 'footer.php';
<?php require '../../../init.php'; $term_id = $_GET['term_id']; $posts = Post_Model::getInstance()->getPostsByTerm($term_id); $term_name = Category_Model::getInstance()->getTermName($term_id); $page_title = $term_name . ' | ' . SITE_TITLE; require TEMPLATE_PATH . 'header.php'; echo "<div id='main'>"; echo "<div id='term_name'><h1>{$term_name}</h1></div>"; require TEMPLATE_PATH . 'post_list.php'; widget_paging(); ?> </div> <!-- main end --> <?php require TEMPLATE_PATH . 'right_side.php'; require TEMPLATE_PATH . 'footer.php';
<?php $date = $_GET['y-m']; $posts = Post_Model::getInstance()->getPostsByArchive($date); $page_title = $date . ' | ' . SITE_TITLE; require TEMPLATE_PATH . 'header.php'; echo "<div id='main'>"; echo "<div id='term_name'><h1>{$date}</h1></div>"; require TEMPLATE_PATH . 'post_list.php'; widget_paging(); ?> </div> <!-- main end --> <?php require TEMPLATE_PATH . 'right_side.php'; require TEMPLATE_PATH . 'footer.php';
function widget_archive() { ?> <div class="widget"> <h3>文章存档</h3> <ul> <?php $posts = Post_Model::getInstance()->getPostlistByArchive(5); foreach ($posts as $post) { echo "<li><a href='" . SITE_URL . "archive.php?y-m={$post['post_date']}' title=''>{$post['post_date']} ({$post['post_count']})</a></li>"; } ?> </ul> </div> <?php }
/** * Save the data of a student * * @param string $username student's username * @param array $data student's data */ public function save($username, $data) { $student_data = array(); $old_data = DB::createQuery('students')->fields('firstname', 'lastname', 'student_number')->where(array('username' => $username))->select(); if (!$old_data[0]) { throw new Exception('Student not found'); } $old_data = $old_data[0]; $change_name = false; // Firstname if (isset($data['firstname']) && $old_data['firstname'] != trim($data['firstname'])) { if (trim($data['firstname']) == '') { throw new FormException('firstname'); } $student_data['firstname'] = trim($data['firstname']); $change_name = true; } // Lastname if (isset($data['lastname']) && $old_data['lastname'] != trim($data['lastname'])) { if (trim($data['lastname']) == '') { throw new FormException('lastname'); } $student_data['lastname'] = trim($data['lastname']); $change_name = true; } // Student number if (isset($data['student_number'])) { if (!ctype_digit(trim($data['student_number']))) { throw new FormException('student_number'); } $student_data['student_number'] = (int) trim($data['student_number']); // Moving the avatar if ($student_data['student_number'] != $old_data['student_number']) { // Thumb $avatar_path = self::getAvatarPath($student_data['student_number'], true); $avatar_dir = File::getPath($avatar_path); if (!is_dir($avatar_dir)) { File::makeDir($avatar_dir, 0777, true); } File::rename(self::getAvatarPath($old_data['student_number'], true), $avatar_path); // Big $avatar_path = self::getAvatarPath($student_data['student_number'], false); $avatar_dir = File::getPath($avatar_path); if (!is_dir($avatar_dir)) { File::makeDir($avatar_dir, 0777, true); } File::rename(self::getAvatarPath($old_data['student_number'], false), $avatar_path); } } // Promo if (isset($data['promo'])) { if (!ctype_digit(trim($data['promo'])) || (int) $data['promo'] < 2000) { throw new FormException('promo'); } $student_data['promo'] = (int) trim($data['promo']); } // Cesure if (isset($data['cesure'])) { $student_data['cesure'] = $data['cesure'] ? 1 : 0; } // Avatar if (isset($data['avatar_path']) && isset($data['student_number']) && File::exists($data['avatar_path'])) { $avatar_path = self::getAvatarPath((int) $data['student_number'], true); $avatar_dir = File::getPath($avatar_path); if (!is_dir($avatar_dir)) { File::makeDir($avatar_dir, 0777, true); } File::rename($data['avatar_path'], $avatar_path); } if (isset($data['avatar_big_path']) && isset($data['student_number']) && File::exists($data['avatar_big_path'])) { $avatar_path = self::getAvatarPath((int) $data['student_number'], false); $avatar_dir = File::getPath($avatar_path); if (!is_dir($avatar_dir)) { File::makeDir($avatar_dir, 0777, true); } File::rename($data['avatar_big_path'], $avatar_path); } // Update the DB $this->createQuery()->set($student_data)->where(array('username' => $username))->update(); if ($change_name) { Post_Model::clearCache(); // Update the search index $search_model = new Search_Model(); $search_model->index(array('username' => $username, 'firstname' => Search_Model::sanitize(isset($student_data['firstname']) ? $student_data['firstname'] : $old_data['firstname']), 'lastname' => Search_Model::sanitize(isset($student_data['lastname']) ? $student_data['lastname'] : $old_data['lastname'])), 'student', $username); } }
/** * Delete a comment * * @param int $id Id of the comment */ public function delete($id) { $id = $this->createQuery()->delete($id); Post_Model::clearCache(); }
<?php require TEMPLATE_PATH . 'header.php'; $page_title = SITE_TITLE; echo "<div id='main'>"; $Post_model = Post_Model::getInstance(); $paging_id = isset($_GET['paging_id']) ? $_GET['paging_id'] : null; $posts = $Post_model->getPostlist('post_date desc', $paging_id); require TEMPLATE_PATH . 'post_list.php'; widget_paging(); ?> </div> <!-- main end --> <?php require TEMPLATE_PATH . 'right_side.php'; require TEMPLATE_PATH . 'footer.php';
<?php require 'admin_init.php'; require TEMPLATE_PATH . 'header.php'; // 删除文章 if (isset($_GET['action']) && $_GET['action'] == 'del') { Post_Model::getInstance()->deleteLog($_GET['pid']); header("location:" . TEMPLATE_PATH . "log.php?del=true"); } // default order by title $order = isset($_GET['order']) ? $_GET['order'] : 'title'; // title => asc order, time and comment => desc order if (isset($_GET['sort'])) { $order = $_GET['sort']; } else { $order = $order == 'title' ? 'asc' : 'desc'; } switch ($order) { case 'time': $order_clause = "order by post_date {$order}"; break; // sort表示升降序 // sort表示升降序 case 'title': $order_clause = "order by post_title {$order}"; break; case 'comment': $order_clause = "order by comment_count {$order}"; break; } $query = "select post_id,post_date,post_title,post_status,term_name,comment_count from blog_posts {$order_clause}";
<?php $post_id = $_REQUEST['pageid']; $post = Post_Model::getInstance()->getPostById($post_id); //为了显示文章名,延迟加载 $page_title = $post['post_title'] . ' | ' . SITE_TITLE; require TEMPLATE_PATH . 'header.php'; /*// 获取评论 $Comment_model = Comment_Model::getInstance(); $comments = $Comment_model->getComments($post_id); $comments_num = $Comment_model->getCommentsNum($post_id);*/ require TEMPLATE_PATH . 'single_post.php'; require TEMPLATE_PATH . 'footer.php';
<?php require 'admin_init.php'; login(); //删除单个文章 if (isset($_GET['post_id'])) { $post_id = $_GET['post_id']; Post_Model::getInstance()->deleteLog($post_id); } elseif (isset($_GET['post_ids'])) { $ids = explode(',', $_GET['post_ids']); foreach ($ids as $id) { Post_Model::getInstance()->deleteLog($id); } } elseif (isset($_GET['term_id'])) { Category_Model::getInstance()->deleteTerm($_GET['term_id']); } elseif (isset($_GET['term_ids'])) { $ids = explode(',', $_GET['term_ids']); foreach ($ids as $id) { Category_Model::getInstance()->deleteTerm($id); } }
public function stats() { // get stats $u = new Post_Model($this->template, $this->router->query_string); $u->stats($this->router->id); }