+++ /dev/null
-<?php
- class HistoriquesController extends AppController {
- public $helpers = array('Html', 'Form');
- public $components = array('RequestHandler');
-
- public function index() {
- $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'));
- }
-
- // GETTING THE CHANGELOG OF THE APPLIANCE
- $this->Historique->id = $id;
- $historique = $this->Historique->findById($id);
- if (!$historique) {
- throw new NotFoundException(__('Historique introuvable'));
- }
- $this->set('historique', $historique);
-
- // GETTING ALL WARNINGS FROM THE CHANGELOG
- 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);
- }
-
- // SENDING DATA TO VIEW
- $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 actionAlerte($id = null, $alerte_id = null, $valider = false, $ref_install = null) {
-
- // GETTING CHANGELOG
- $this->Historique->id = $id;
- $historique = $this->Historique->findById($id);
- if (!$historique) {
- throw new NotFoundException(__('Historique introuvable'));
- }
-
- // GETTING WARNINGS OF CHANGELOG
- App::import('Controller', 'Alertes');
- $alertesController = new AlertesController;
- $alerte = $alertesController->Alerte->findById($alerte_id);
- if (!$alerte) {
- throw new NotFoundException(__('Alerte introuvable'));
- }
-
- // ADDING VERSION AND DATE OF WARNING TO CHANGELOG
- $version = $alerte['Alerte']['version'];
- $date = $alerte['Alerte']['creation'];
- switch($alerte['Alerte']['nature']) {
- case 'version':
- if($this->Historique->value('versions')) {
- $versions = explode('|', $this->Historique->value('versions'));
- } else {
- $versions = array();
- }
- $versions[] = $version.";".$date;
- $this->Historique->value('versions', implode('|', $versions));
- break;
-
- case 'creation':
- $creation = $alerte['Alerte']['creation'];
- // TO-DO : CHANGE APPLIANCE STATE ?
- break;
-
- default:
- break;
-
- }
-
- // IN CASE OF VALIDATION => OPPORTUNITY CREATION IN SUGAR THROUGH ALLO SERVEUR CONNECTOR
- if($valider) {
- $reference = str_replace("SLASH", "\\/", $ref_install);
- $url = 'http://allo_serveur/?action=create_fiche_installation&nom='.$reference;
- $options = array("http" => array("method" => "GET"));
- $context = stream_context_create($options);
- $reponse = file_get_contents($url, false, $context);
- if(isset($reponse)) {
- // USE THE ID SENT ?
- }
- }
-
- // DELETING WARNING
- $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 TO APPLIANCES PAGE
- return $this->redirect(array('controller' => 'instances', 'action' => 'index'));
- }
- }
-?>