--- /dev/null
+<?php
+ class HistoriquesController extends AppController {
+ public $helpers = array('Html', 'Form');
+ public $components = array('RequestHandler');
+
+ public function index() {
+ //$this->set('historiques', $this->Historique->find('all'));
+ $historiques = $this->Historique->find('all');
+ $this->set(array(
+ 'historiques' => $historiques,
+ '_serialize' => array('historiques')
+ ));
+ }
+
+ public function view($id = null) {
+ if (!$id) {
+ throw new NotFoundException(__('Mauvais historique'));
+ }
+
+ $historique = $this->Historique->findById($id);
+ if (!$historique) {
+ throw new NotFoundException(__('Mauvais historique'));
+ }
+ $this->set('historique', $historique);
+ }
+
+ public function add() {
+ if ($this->request->is('historique')) {
+ $this->Historique->create();
+ if ($this->Historique->save($this->request->data)) {
+ $this->Session->setFlash(__("L'historique a été enregistré."));
+ return $this->redirect(array('action' => 'index'));
+ }
+ $this->Session->setFlash(__("Enregistrement de l'historique impossible."));
+ }
+ }
+
+ public function edit($id = null) {
+ if (!$id) {
+ throw new NotFoundException(__('Historique introuvable'));
+ }
+
+ $this->Historique->id = $id;
+ $historique = $this->Historique->findById($id);
+ if (!$historique) {
+ throw new NotFoundException(__('Historique introuvable'));
+ }
+ $this->set('historique', $historique);
+
+ // Récupération des alertes de l'historique
+ if($this->Historique->value('alertes')) {
+ $alertes_id = explode('|', $this->Historique->value('alertes'));
+ App::import('Controller', 'Alertes');
+ $alertesController = new AlertesController;
+ $alertes = array();
+ foreach ($alertes_id as $alerte_id) {
+ $alertes[] = $alertesController->Alerte->findById($alerte_id);
+ }
+ //$this->set('alertes', $alertes);
+ $this->set(array(
+ 'alertes' => $alertes,
+ '_serialize' => array('alertes')
+ ));
+ }
+
+ if ($this->request->is(array('historique', 'put'))) {
+ $this->Historique->id = $id;
+ if ($this->Historique->save($this->request->data)) {
+ $this->Session->setFlash(__("L'historique a été mis à jour."));
+ return $this->redirect(array('action' => 'index'));
+ }
+ $this->Session->setFlash(__("Mise à jour de l'historique impossible."));
+ }
+
+ if (!$this->request->data) {
+ $this->request->data = $historique;
+ }
+ }
+
+ public function delete($id) {
+ if ($this->request->is('get')) {
+ throw new MethodNotAllowedException();
+ }
+
+ if ($this->Historique->delete($id)) {
+ $this->Session->setFlash(
+ __("L'historique d'id: %s a été supprimé.", h($id))
+ );
+ return $this->redirect(array('action' => 'index'));
+ }
+ }
+
+ public function validerAlerte($id = null, $alerte_id = null) {
+ // Récupération de l'historique
+ $this->Historique->id = $id;
+ $historique = $this->Historique->findById($id);
+ if (!$historique) {
+ throw new NotFoundException(__('Historique introuvable'));
+ }
+
+ // Récupération de l'alerte
+ App::import('Controller', 'Alertes');
+ $alertesController = new AlertesController;
+ $alerte = $alertesController->Alerte->findById($alerte_id);
+ if (!$alerte) {
+ throw new NotFoundException(__('Alerte introuvable'));
+ }
+
+ // Ajout de la version à l'historique
+ $version = $alerte['Alerte']['version'];
+ $creation = $alerte['Alerte']['creation'];
+ switch($alerte['Alerte']['nature']) {
+ case 'patch':
+ if($this->Historique->value('patches')) {
+ $patches = explode('|', $this->Historique->value('patches'));
+ } else {
+ $patches = array();
+ }
+ $patches[] = "{".$version.",".$creation.",".true."}";
+ $this->Historique->value('patches', implode('|', $patches));
+ break;
+
+ case 'maj':
+ break;
+
+ case 'creation':
+ // To-do : Modification état produit
+ break;
+
+ default:
+ break;
+
+ }
+
+ // Suppression de l'alerte
+ $alertesController->Alerte->delete($alerte_id);
+ $alertes_id = explode('|', $this->Historique->value('alertes'));
+ if(($key = array_search($alerte_id, $alertes_id)) !== false) {
+ unset($alertes_id[$key]);
+ }
+ $this->Historique->value('alertes', implode('|', $alertes_id));
+
+ // Redirection
+ return $this->redirect(array('controller' => 'instances', 'action' => 'index'));
+ }
+
+ public function refuserAlerte($id = null, $alerte_id = null) {
+ // Récupération de l'historique
+ $this->Historique->id = $id;
+ $historique = $this->Historique->findById($id);
+ if (!$historique) {
+ throw new NotFoundException(__('Historique introuvable'));
+ }
+
+ // Récupération de l'alerte
+ App::import('Controller', 'Alertes');
+ $alertesController = new AlertesController;
+ $alerte = $alertesController->Alerte->findById($alerte_id);
+ if (!$alerte) {
+ throw new NotFoundException(__('Alerte introuvable'));
+ }
+
+ // Ajout de la version à l'historique
+ $version = $alerte['Alerte']['version'];
+ $creation = $alerte['Alerte']['creation'];
+ switch($alerte['Alerte']['nature']) {
+ case 'patch':
+ if($this->Historique->value('patches')) {
+ $patches = explode('|', $this->Historique->value('patches'));
+ } else {
+ $patches = array();
+ }
+ $patches[] = "{".$version.",".$creation.",".false."}";
+ $this->Historique->value('patches', implode('|', $patches));
+ break;
+
+ case 'maj':
+ break;
+
+ case 'creation':
+ // To-do : Modification état produit
+ break;
+
+ default:
+ break;
+
+ }
+
+ // Suppression de l'alerte
+ $alertesController->Alerte->delete($alerte_id);
+ $alertes_id = explode('|', $this->Historique->value('alertes'));
+ if(($key = array_search($alerte_id, $alertes_id)) !== false) {
+ unset($alertes_id[$key]);
+ }
+ if($alertes_id !== ""){
+ $this->Historique->value('alertes', implode('|', $alertes_id));
+ } else {
+ $this->Historique->value('alertes', null);
+ }
+
+ // Redirection
+ return $this->redirect(array('controller' => 'instances', 'action' => 'index'));
+ }
+ }
+?>