public function loginAction() { $langue = $this->getEvent()->getRouteMatch()->getParam('langue'); $token = VerifUser::tokenAction(); if ($token != null) { $this->redirect()->toRoute('admin', array('action' => 'index', 'langue' => $langue)); } $listeRubrique = SendLayout::fetchAllRubriques($this, 'login', $langue, $token); $form = new AdminForm(); //formulaire de connexion $adminModel = new AdminModel(); $request = $this->getRequest(); if ($request->isPost()) { $admin = new Admin(); $form->setInputFilter($admin->getInputFilter()); $form->setData($request->getPost()); if ($form->isValid()) { $admin->exchangeArray($form->getData()); try { $token = $adminModel->verifyUser($admin->login, $admin->password); } catch (\Exception $e) { $token = null; SendLayout::sendGeneral($this, $listeRubrique, 'login', $langue, $token); return new ViewModel(array('form' => $form, 'listeRubrique' => $listeRubrique, 'langue' => $this->getEvent()->getRouteMatch()->getParam('langue'), 'exception' => $e->getMessage())); } $session = new Container('user'); $session->token = $token; //Redirection vers l'interface d'administration $this->redirect()->toRoute('admin', array('action' => 'index', 'langue' => $langue)); //echo $token; } } SendLayout::sendGeneral($this, $listeRubrique, 'login', $langue, $token); return new ViewModel(array('form' => $form, 'listeRubrique' => $listeRubrique, 'langue' => $langue)); }
public function indexAction() { VerifUser::setTokenToDisconnect(); $rubriqueModel = new RubriqueModel(); $data = null; $cptActif = 0; $data = SendLayout::fetchAllRubriques($this, 'autre', 'fr', null); $this->layout()->setVariable('listeRubrique', $data); $this->layout()->setVariable('langue', 'fr'); $this->layout()->setVariable('token', null); if (!empty($this->getRequest()->getQuery('erreur', false))) { return new ViewModel(array('langue' => 'fr', 'erreur' => $this->getRequest()->getQuery('erreur', false))); } else { //affichage de la vue //return new ViewModel(array('rubrique'=>$data[0],'langue'=>'fr')); if (!empty($data)) { foreach ($data as $d) { if ($d['actif'] == 1) { $cptActif++; $this->layout()->setVariable('menu_id', $d['menu_id']); return new ViewModel(array('rubrique' => $d, 'langue' => 'fr')); } } } if (empty($data) || $cptActif == 0) { $this->layout()->setVariable('menu_id', 'pbm'); $this->redirect()->toRoute('publications', array('langue' => 'fr')); } } }
public function afficherPublicationAction() { //Vérification token $token = VerifUser::tokenAction(); $langue = $this->getEvent()->getRouteMatch()->getParam('langue'); $rubriqueModel = new RubriqueModel(); $categorieModel = new CategorieModel(); $publicationModel = new PublicationModel(); //try catch du fetchAll des rubriques $listeRubriques = SendLayout::fetchAllRubriques($this, 'pbm', $langue, $token); if ($this->getEvent()->getRouteMatch()->getParam('trie') == 'categ') { $listeSup = $categorieModel->fetchAll(); } elseif ($this->getEvent()->getRouteMatch()->getParam('trie') == 'date') { $listeSup = $publicationModel->fetchAllByDate(); } SendLayout::sendGeneral($this, $listeRubriques, 'pbm', $langue, $token); return new ViewModel(array('trie' => $this->getEvent()->getRouteMatch()->getParam('trie'), 'listePubli' => $publicationModel->fetchAll(), 'listeSup' => $listeSup, 'langue' => $langue)); }
public function rubriqueselectAction() { //Vérification token $token = VerifUser::tokenAction(); $langue = $this->getEvent()->getRouteMatch()->getParam('langue'); $rubriqueModel = new RubriqueModel(); $data = null; $rubrique = null; //try catch du fetchAll des rubriques $listeRubriques = SendLayout::fetchAllRubriques($this, 0, $langue, $token); try { $rubrique = $rubriqueModel->findOne($this->getEvent()->getRouteMatch()->getParam('menu_id')); } catch (\Exception $e) { SendLayout::traiteExceptionsOneRubrique($this, $data, $this->getEvent()->getRouteMatch()->getParam('menu_id'), $this->getEvent()->getRouteMatch()->getParam('langue'), $token, $e->getMessage()); return new ViewModel(array('rubrique' => null, 'langue' => $this->getEvent()->getRouteMatch()->getParam('langue'), $this->getEvent()->getRouteMatch()->getParam('langue'), 'exception' => $e->getMessage())); } SendLayout::sendGeneral($this, $listeRubriques, $rubrique['menu_id'], $langue, $token); return new ViewModel(array('rubrique' => $rubrique, 'langue' => $this->getEvent()->getRouteMatch()->getParam('langue'))); }
public function deleteRubriqueAction() { $token = VerifUser::tokenAction(); if ($token == null) { $this->redirect()->toRoute('home'); } $adminModel = new AdminModel(); $langue = $this->getEvent()->getRouteMatch()->getParam('langue'); $msgSuccess = null; //try catch du fetchAll des rubriques $listeRubriques = SendLayout::fetchAllRubriques($this, 'admin', $langue, $token); try { $adminModel->deleteRubrique($token, $this->getEvent()->getRouteMatch()->getParam('id_menu')); } catch (\Exception $e) { $this->redirect()->toRoute('admin', array('action' => 'index', 'langue' => $langue, 'exSuppRubrique' => $e->getMessage())); } //Envoi des variables au layout SendLayout::sendGeneral($this, $listeRubriques, 'admin', $langue, $token); $msgSuccess = 'deleterubrique'; $this->redirect()->toRoute('admin', array('action' => 'index', 'langue' => $langue), array('query' => array('successDltR' => $msgSuccess))); }
public function deletePublicationAction() { $token = VerifUser::tokenAction(); if ($token == null) { $this->redirect()->toRoute('home'); } $rubriqueModel = new RubriqueModel(); $adminModel = new AdminModel(); $langue = $this->getEvent()->getRouteMatch()->getParam('langue'); $listeRubrique = null; $msgSuccess = null; $msgError = null; $listeRubrique = SendLayout::fetchAllRubriques($this, 'admin', $langue, $token); try { $adminModel->deletePublication($token, $this->getEvent()->getRouteMatch()->getParam('id_publication')); } catch (\Exception $e) { $msgError = 'errordeletepublication'; } //Envoi des variables au layout SendLayout::sendGeneral($this, $listeRubrique, 'admin', $langue, $token); if (isset($msgError)) { $this->redirect()->toRoute('admin', array('action' => 'index', 'langue' => $langue), array('query' => array('errorDltP' => $msgError))); } else { $msgSuccess = 'deletepublication'; $this->redirect()->toRoute('admin', array('langue' => $langue), array('query' => array('successDltP' => $msgSuccess))); } }
public function modifPublicationAction() { $token = VerifUser::tokenAction(); if ($token == null) { $this->redirect()->toRoute('home'); } $langue = $this->getEvent()->getRouteMatch()->getParam('langue'); $idPublication = $this->getEvent()->getRouteMatch()->getParam('id_publication'); //récupère id de la publication correspondante $adminModel = new AdminModel(); $publicationModel = new PublicationModel(); $form = new PublicationForm(); //formulaire de modification de rubrique $publicationToModif = null; $msgSuccess = null; $errorExt = null; $listeRubriques = SendLayout::fetchAllRubriques($this, 'modifpubli', $langue, $token); try { $publicationToModif = $publicationModel->findOne($token, $idPublication); } catch (\Exception $e) { SendLayout::traiteExceptionsOnePublication($this, $listeRubriques, 'modifpubli', $idPublication, $langue, $token, $e->getMessage()); } $request = $this->getRequest(); if ($request->isPost()) { $publicationModif = new Publication(); $form->setInputFilter($publicationModif->getInputFilter()); $other = $request->getPost()->toArray(); $file = $this->params()->fromFiles('pdf'); $data = array_merge($other, array('pdf' => $file['name'])); $form->setData($data); if ($form->isValid()) { $publicationModif->exchangeArray($form->getData()); $publicationModif->id = $idPublication; $valid = new ValidationUploadedFile(); if ($file['name'] != '') { if ($valid->validatorsFile($file, 'pdf') == true) { $valid->moveFile($file); $publicationModif->pdf = 'useruploads/files/' . $file['name']; } else { $publicationModif->pdf = null; $errorExt = 'error extension'; } } else { $publicationModif->pdf = null; } try { $adminModel->modifPublication($token, $publicationModif); } catch (\Exception $e) { return new ViewModel(array('form' => $form, 'publicationToModif' => $publicationToModif, 'listeCategories' => $this->getCategories(), 'langue' => $langue, 'exModifPublication' => $e->getMessage())); } if (!isset($errorExt)) { $msgSuccess = 'modifpublication'; $this->redirect()->toRoute('admin', array('langue' => $langue), array('query' => array('successMdfP' => $msgSuccess))); } } } //Envoi des variables au layout SendLayout::sendGeneral($this, $listeRubriques, 'modifpubli', $langue, $token); $this->layout()->setVariable('id_publication', $idPublication); if (!isset($errorExt)) { return new ViewModel(array('form' => $form, 'langue' => $langue, 'publicationToModif' => $publicationToModif, 'listeCategories' => $this->getCategories())); } return new ViewModel(array('form' => $form, 'publicationToModif' => $publicationToModif, 'listeCategories' => $this->getCategories(), 'errorMsgExtension' => 'L\'extension du fichier doit être pdf.', 'langue' => $langue)); }