public function statistiques($action, $id, $vars) { switch ($action) { /**** GET ****/ case 'get': $vars['titrePage'] = 'Statistiques'; // <h1> de la page $vars['visites'] = Visite::getStat(); $vars['membres'] = Membre::getStat(); $vars['technotes'] = Technote::getStat(); $vars['commentaires'] = Commentaire::getStat(); $vars['questions'] = Question::getStat(); $vars['reponses'] = Reponse::getStat(); $vars['motsCles'] = MotCle::getStat(); $this->vue->display('admin/statistiques.twig', $vars); exit; default: $this->vue->display('404.twig', $vars); exit; } }
/** * Vérifie les attributs d'une technote * @param array $param Les attributs à vérifier * @return object 2 attributs, bool success et array string msg * @static */ private static function checkTechnote(&$param, &$files, $typeCheck) { $std = (object) array('success' => false, 'msg' => array()); if (($res = Technote::checkDescription($param['description'])) !== true) { $std->msg[] = $res; } if (($res = Technote::checkPublie($param['publie'])) !== true) { $std->msg[] = $res; } if (($res = Technote::checkTitre($param['titre'])) !== true) { $std->msg[] = $res; } if (($res = Technote::checkContenu($param['contenu'])) !== true) { $std->msg[] = $res; } // Si on ajoute une technote, ou que c'est une édition avec modification de l'image if ($typeCheck == 'add' || !empty($files['image'])) { if (($res = Technote::checkImage($files['image'])) !== true) { $std->msg[] = $res; } // On génère un nom aléatoire do { $gen = uniqid(rand()); $nom = pathinfo($files['image']['name'], PATHINFO_FILENAME); $extension = pathinfo($files['image']['name'], PATHINFO_EXTENSION); $base = dirname(__FILE__) . '/..'; $chemin = '/assets/images/uploads/' . $nom . $gen . '.' . $extension; } while (file_exists($base . $chemin)); if (move_uploaded_file($files['image']['tmp_name'], $base . $chemin)) { $param['url_image'] = $chemin; } else { $std->msg[] = 'Problème de déplacement de l\'image sur le serveur, veuillez contacter un admin'; } } else { if (($res = Technote::checkURLImage($param['url_image'])) !== true) { $std->msg[] = $res; } } if (!empty($param['id_mot_cle'])) { foreach ($param['id_mot_cle'] as $id_mot_cle) { if (($res = MotCle::checkExiste($id_mot_cle)) !== true) { $std->msg[] = $res; } } } if (empty($std->msg)) { $std->success = true; } return $std; }
public function technotes($action, $id, $vars) { $technoteDAO = new TechnoteDAO(BDD::getInstancePDO()); switch ($action) { /**** GET ****/ case 'get': $vars['active_technotes'] = 1; // Active le style dans le menu technotes // Si on veut voir une technote précise if (!empty($id)) { // On récupère la technote $vars['technote'] = $technoteDAO->getOne($id); // Si la technote existe if ($vars['technote'] !== false && $vars['technote']->visible && ($vars['technote']->publie || $vars['technote']->id_auteur == $_SESSION['user']->id_membre || $_SESSION['user']->groupe == 'Administrateur' || $_SESSION['user']->groupe == 'Modérateur')) { $vars['titrePage'] = $vars['technote']->titre; // <h1> de la page $this->vue->display('technotes_get_one.twig', $vars); } else { $this->vue->display('404.twig', $vars); } } else { // On récupère la page $page = !empty($_GET['page']) ? $_GET['page'] : 1; $technoteDAO = new TechnoteDAO(BDD::getInstancePDO()); // Si on veut faire une recherche de technotes if (isset($_GET['recherche'])) { $vars['titrePage'] = 'Chercher une technote'; // <h1> de la page // on recupère la page $page = !empty($_GET['page']) ? $_GET['page'] : 1; // On essaye de récupèrer les technotes avec les critères de recherche $res = Technote::recherche($_GET, $page); if ($res->success) { $vars['pagination'] = $res->pagination; $vars['technotes'] = $res->technotes; } else { $vars['res'] = $res; } } elseif (isset($_GET['nonpublie'])) { $vars['titrePage'] = 'Mes technotes non publié'; // <h1> de la page $vars['active_technotes_non_publie'] = 1; // Active le style dans le sous menu toutes les technotes // On récupère le nombre total de technotes non publié par l' $count = $technoteDAO->getNbRedige($_SESSION['user']->id_membre, 0); // On créé la pagination $vars['pagination'] = new Pagination($page, $count, NB_TECHNOTES_PAGE, '/technotes/get?nonpublie&page='); // On récupère les technotes $vars['technotes'] = $technoteDAO->getLastNTechnotes(NB_TECHNOTES_PAGE, $vars['pagination']->debut, 0, $_SESSION['user']->id_membre); $vars['getNonPublie'] = true; } else { $vars['titrePage'] = 'Toutes les technotes'; // <h1> de la page $vars['active_technotes_all'] = 1; // Active le style dans le sous menu toutes les technotes // On récupère le nombre total de technotes $count = $technoteDAO->getCount(); // On créé la pagination $vars['pagination'] = new Pagination($page, $count, NB_TECHNOTES_PAGE, '/technotes/get?page='); // On récupère les technotes $vars['technotes'] = $technoteDAO->getLastNTechnotes(NB_TECHNOTES_PAGE, $vars['pagination']->debut); } $this->vue->display('technotes_get_all.twig', $vars); } exit; /**** ADD ****/ /**** ADD ****/ case 'add': $vars['active_technotes'] = 1; // Active le style dans le menu technotes $vars['active_technotes_add'] = 1; // Active le style dans le sous menu ajout de technote $vars['titrePage'] = 'Ajouter une technote'; // <h1> de la page // On récupère tous les mots clés $motCleDAO = new MotCleDAO(BDD::getInstancePDO()); $vars['motsCles'] = $motCleDAO->getAllActif(); // Si un formulaire a été envoyé if (!empty($_POST)) { // Si le formulaire est valide au niveau faille CSRF if (!empty($_POST['jetonCSRF']) && $_POST['jetonCSRF'] == $_SESSION['jetonCSRF']) { // On essaye d'enregistrer la technote $res = Technote::addTechnote($_POST, $_FILES); if ($res->success) { $res->redirect = "/technotes/get/{$res->id_technote}"; } echo json_encode($res); exit; } } $this->vue->display('technotes_add.twig', $vars); exit; /**** EDIT ****/ /**** EDIT ****/ case 'edit': $vars['active_technotes'] = 1; // Active le style dans le menu technotes $vars['titrePage'] = 'Modifier une technote'; // <h1> de la page $vars['technote'] = $technoteDAO->getOne($id); // On récupère tous les mots clés $motCleDAO = new MotCleDAO(BDD::getInstancePDO()); $vars['motsCles'] = $motCleDAO->getAllActif(); // Si un formulaire a été envoyé if (!empty($_POST)) { // Si le formulaire est valide au niveau faille CSRF if (!empty($_POST['jetonCSRF']) && $_POST['jetonCSRF'] == $_SESSION['jetonCSRF']) { // On essaye d'enregistrer la technote $res = Technote::editTechnote($_POST, $_FILES, $id); if ($res->success) { $res->redirect = "/technotes/get/{$id}"; } echo json_encode($res); exit; } } $this->vue->display('technotes_edit.twig', $vars); exit; /**** DROP ****/ /**** DROP ****/ case 'drop': if (!empty($_POST)) { // Si le formulaire est valide au niveau faille CSRF if (!empty($_POST['jetonCSRF']) && $_POST['jetonCSRF'] == $_SESSION['jetonCSRF']) { // On essaye d'enregistrer le commentaire $res = Technote::dropTechnote($id); if ($res->success) { $res->redirect = "/technotes"; } echo json_encode($res); } } exit; default: $this->vue->display('404.twig', $vars); exit; } }