--- /dev/null
+<?php
+ class AdministratorsController extends AppController {
+ public $helpers = array('Html', 'Form');
+ public $components = array('RequestHandler');
+
+ public function index() {
+ $administrators = $this->Administrator->find('all');
+ $this->set(array(
+ 'administrators' => $administrators,
+ '_serialize' => array('administrators')
+ ));
+ }
+
+ public function login() {
+ if ($this->request->is('POST')) {
+ $administrators = $this->Administrator->find('all');
+ $success = false;
+ $login = $_POST['login'];
+ $pass = md5($_POST['pass']);
+ foreach($administrators as $administrator) {
+ if($administrator['Administrator']['login'] === $login && $administrator['Administrator']['pass'] == $pass) {
+ $success = true;
+ break;
+ }
+ }
+ if ($success) {
+ $this->Session->setFlash(__("Login OK."));
+ $this->redirect(array(/*'controller' => 'instances', */'action' => 'index'));
+
+ } else {
+ $this->Session->setFlash(__("Login FAIL."));
+ $this->redirect(array('action' => 'login'));
+ }
+ }
+ }
+
+ public function register() {
+ if ($this->request->is('POST')) {
+ $login = $_POST['login'];
+
+ // CHECKING IF LOGIN IS ALREADY TAKEN
+ $administrators = $this->Administrator->find('all');
+ $isLoginAvailable = true;
+ foreach($administrators as $administrator) {
+ if($administrator['Administrator']['login'] === $login) {
+ $isLoginAvailable = false;
+ break;
+ }
+ }
+ if($isLoginAvailable) {
+ $pass = md5($_POST['pass']);
+ $this->Administrator->create();
+ $this->Administrator->value('login', $login);
+ $this->Administrator->value('pass', $pass);
+ $this->Administrator->save();
+ if (isset($this->Administrator)) {
+ $this->Session->setFlash(__("Register OK."));
+ $this->redirect(array(/*'controller' => 'instances', */'action' => 'index'));
+ }
+ $this->Session->setFlash(__("Register FAIL."));
+ } else {
+ $this->Session->setFlash(__("Ce pseudo est déjà utilisé."));
+ }
+ }
+ }
+ }
--- /dev/null
+<?php
+ class AppliancesController extends AppController {
+ public $helpers = array('Html', 'Form');
+ public $components = array('RequestHandler');
+ public $uses = array('Appliance', 'Changelog');
+
+ public function index() {
+
+ // GETTING CONTROLLERS
+ App::import('Controller', 'Warnings');
+ $warningsController = new WarningsController;
+ App::import('Controller', 'Changelogs');
+ $changelogsController = new ChangelogsController;
+ App::import('Controller', 'Customers');
+ $customersController = new CustomersController;
+
+ // GETTING ALL APPLIANCES
+ $appliances = $this->Appliance->find('all');
+
+ // GETTING ALL CUSTOMERS
+ $customers = $customersController->Customer->find('all');
+
+ // GETTING INFORMATION FOR EACH APPLIANCE
+ $changelogsArray = array();
+ $warningsArray = array();
+ $customersArray = array();
+ $lastUpdates = array();
+ foreach($appliances as $appliance) {
+
+ // GETTING CHANGELOG
+ $changelog = $changelogsController->Changelog->findById($appliance['Appliance']['changelog']);
+ if ($changelog) {
+
+ // GETTING WARNINGS OF CHANGELOG
+ if($changelog['Changelog']['warnings']) {
+ $warnings_id = explode('|', $changelog['Changelog']['warnings']);
+ $warnings = array();
+ foreach ($warnings_id as $warning_id) {
+ $warnings[] = $warningsController->Warning->findById($warning_id);
+ }
+
+ // ADDING WARNINGS TO LIST
+ $warningsArray[$changelog['Changelog']['id']] = $warnings;
+ }
+
+ // GETTING LAST DECLARED VERSION IN CHANGELOG
+ if($changelog['Changelog']['versions']) {
+ $changelogVersions = explode('|', $changelog['Changelog']['versions']);
+ foreach ($changelogVersions as $changelogVersion) {
+ $changelogVersionArray = explode(';', $changelogVersion);
+ if(isset($changelogVersionArray[1])) {
+ $update = $changelogVersionArray[1];
+ if(!isset($lastUpdate) || $update > $lastUpdate) {
+ $lastUpdate = $update;
+ }
+ }
+ }
+
+ // ADDING UPDATE DATE TO LIST
+ if(isset($lastUpdate)) {
+ $lastUpdates[$appliance['Appliance']['id']] = $lastUpdate;
+ }
+ }
+
+ // ADDING CHANGELOG TO LIST
+ $changelogsArray[$appliance['Appliance']['id']] = $changelog;
+ }
+
+ // GETTING CUSTOMER
+ $applianceReferenceArray = explode("/",$appliance['Appliance']['reference']);
+ $customerAPId = substr($applianceReferenceArray[1],0,-11);
+ foreach($customers as $customer) {
+
+ // ADDING CUSTOMER TO LIST
+ if($customer['Customer']['ap_id'] === $customerAPId) {
+ $customersArray[$appliance['Appliance']['id']] = $customer;
+ }
+ }
+ }
+
+ // SENDING DATA TO VIEW
+ $this->set(array(
+ 'appliances' => $appliances,
+ '_serialize' => array('appliances')
+ ));
+ $this->set(array(
+ 'changelogsArray' => $changelogsArray,
+ '_serialize' => array('changelogsArray')
+ ));
+ $this->set(array(
+ 'customersArray' => $customersArray,
+ '_serialize' => array('customersArray')
+ ));
+ $this->set(array(
+ 'warningsArray' => $warningsArray,
+ '_serialize' => array('warningsArray')
+ ));
+ $this->set(array(
+ 'lastUpdates' => $lastUpdates,
+ '_serialize' => array('lastUpdates')
+ ));
+ }
+
+ public function view($id = null) {
+ if (!$id) {
+ throw new NotFoundException(__('Mauvaise instance applicative'));
+ }
+
+ $appliance = $this->Appliance->findById($id);
+ if (!$appliance) {
+ throw new NotFoundException(__('Mauvaise instance applicative'));
+ }
+ $this->set('appliance', $appliance);
+ }
+
+ public function add() {
+ if ($this->request->is('POST')) {
+ $this->Appliance->create();
+ if ($this->Appliance->save($this->request->data)) {
+ $this->Session->setFlash(__("L'instance applicative a été enregistrée."));
+ $this->redirect(array('action' => 'index'));
+ }
+ $this->Session->setFlash(__("Enregistrement de l'instance applicative impossible."));
+ }
+ }
+
+ public function edit($id = null) {
+ if (!$id) {
+ throw new NotFoundException(__('Instance applicative introuvable'));
+ }
+
+ $appliance = $this->Appliance->findById($id);
+ if (!$appliance) {
+ throw new NotFoundException(__('Instance applicative introuvable'));
+ }
+ $this->Appliance->id = $id;
+
+ // GETTING VERSION CONTROLLER AND VERSIONS
+ App::import('Controller', 'Versions');
+ $versionsController = new VersionsController;
+ $versions = $versionsController->Version->find('all');
+
+ // GETTING ALL AVAILABLE VERSIONS FOR THIS PRODUCT
+ $possibleVersions = array();
+ foreach($versions as $version) {
+ if($version['Version']['product'] == $this->Appliance->value('product')) {
+ $possibleVersions[$version['Version']['id']] = $version['Version']['value'];
+ }
+ }
+
+ // SENDING DATA TO VIEW
+ $this->set(array(
+ 'possibleVersions' => $possibleVersions,
+ '_serialize' => array('possibleVersions')
+ ));
+
+ // IN CASE OF A PUT REQUEST
+ if ($this->request->is(array('appliance', 'put'))) {
+
+ // GETTING CHANGELOG
+ $changelog = $this->Changelog->findById($this->Appliance->value('changelog'));
+ if (!$changelog) {
+ throw new NotFoundException(__('Changelog introuvable'));
+ }
+ $this->Changelog->id = $this->Appliance->value('changelog');
+
+ // GETTING VERSIONS OF APPLIANCE
+ if($this->Changelog->value('versions')) {
+ $changelogVersions = explode('|', $this->Changelog->value('versions'));
+ } else {
+ $changelogVersions = array();
+ }
+
+ // SAVING APPLIANCE
+ if ($this->Appliance->save($this->request->data)) {
+
+ // CHECKING VERSION ID TO ADD TO CHANGELOG
+ $possibleVersionsId = array_keys($possibleVersions);
+ if(in_array($this->request->data['Appliance']['version'], $possibleVersionsId)) {
+ $versionId = $this->request->data['Appliance']['version'];
+ }
+
+ // CHANGING AND SAVING CHANGELOG
+ if(isset($versionId)) {
+ $changelogVersions[] = $versionId.";".date('Y-m-d');
+ $this->Changelog->value('versions', implode('|', $changelogVersions));
+ $this->Changelog->save();
+ }
+
+ // REDIRECTION
+ $this->Session->setFlash(__("L'instance applicative a été mise à jour."));
+ $this->redirect(array('action' => 'index'));
+ }
+ $this->Session->setFlash(__("Mise à jour de l'instance applicative impossible."));
+ }
+
+ if (!$this->request->data) {
+ $this->request->data = $appliance;
+ }
+ }
+
+ public function delete($id) {
+
+ // DISABLE GET ACCESS ?
+ /*if ($this->request->is('get')) {
+ throw new MethodNotAllowedException();
+ }*/
+ $appliance = $this->Appliance->findById($id);
+ if (!$appliance) {
+ throw new NotFoundException(__('Instance applicative introuvable'));
+ }
+ if ($this->Appliance->delete($id)) {
+ $this->Session->setFlash(
+ __("L'instance applicative %s a été supprimée.", h($appliance['Appliance']['reference']))
+ );
+ $this->redirect(array('action' => 'index'));
+ }
+ }
+
+ // REST API
+ // TO-DO : DELETE OR USE, BUT DON'T LET IT ROT THERE
+
+ /*public function rest_get_all() {
+ $appliances = $this->Appliance->find('all');
+ $this->set(array(
+ 'appliances' => $appliances,
+ '_serialize' => array('appliances')
+ ));
+ }
+
+ public function rest_get($reference) {
+ $appliance = $this->Appliance->findByReference($reference);
+ $this->set(array(
+ 'appliance' => $appliance,
+ '_serialize' => array('appliance')
+ ));
+ }
+
+ public function rest_create() {
+ if ($this->Appliance->save($this->request->data)) {
+ $message = array(
+ 'text' => __('Saved'),
+ 'type' => 'success'
+ );
+ } else {
+ $message = array(
+ 'text' => __('Error'),
+ 'type' => 'error'
+ );
+ }
+ $this->set(array(
+ 'message' => $message,
+ '_serialize' => array('message')
+ ));
+ }
+
+ public function rest_update($reference) {
+ $this->Appliance->reference = $reference;
+ if ($this->Appliance->save($this->request->data)) {
+ $message = array(
+ 'text' => __('Saved'),
+ 'type' => 'success'
+ );
+ } else {
+ $message = array(
+ 'text' => __('Error'),
+ 'type' => 'error'
+ );
+ }
+ $this->set(array(
+ 'message' => $message,
+ '_serialize' => array('message')
+ ));
+ }
+
+ public function rest_delete($reference) {
+ if ($this->Appliance->delete($reference)) {
+ $message = array(
+ 'text' => __('Deleted'),
+ 'type' => 'success'
+ );
+ } else {
+ $message = array(
+ 'text' => __('Error'),
+ 'type' => 'error'
+ );
+ }
+ $this->set(array(
+ 'message' => $message,
+ '_serialize' => array('message')
+ ));
+ }*/
+ }
--- /dev/null
+<?php
+ class ChangelogsController extends AppController {
+ public $helpers = array('Html', 'Form');
+ public $components = array('RequestHandler');
+
+ public function index() {
+ $changelogs = $this->Changelog->find('all');
+ $this->set(array(
+ 'changelogs' => $changelogs,
+ '_serialize' => array('changelogs')
+ ));
+ }
+
+ public function view($id = null) {
+ if (!$id) {
+ throw new NotFoundException(__('Mauvais historique'));
+ }
+
+ $changelog = $this->Changelog->findById($id);
+ if (!$changelog) {
+ throw new NotFoundException(__('Mauvais historique'));
+ }
+ $this->set('changelog', $changelog);
+ }
+
+ public function add() {
+ if ($this->request->is('changelog')) {
+ $this->Changelog->create();
+ if ($this->Changelog->save($this->request->data)) {
+ $this->Session->setFlash(__("L'historique a été enregistré."));
+ $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->Changelog->id = $id;
+ $changelog = $this->Changelog->findById($id);
+ if (!$changelog) {
+ throw new NotFoundException(__('Historique introuvable'));
+ }
+ $this->set('changelog', $changelog);
+
+ // GETTING ALL WARNINGS FROM THE CHANGELOG
+ if($this->Changelog->value('warnings')) {
+ $warnings_id = explode('|', $this->Changelog->value('warnings'));
+ App::import('Controller', 'Warnings');
+ $warningsController = new WarningsController;
+ $warnings = array();
+ foreach ($warnings_id as $warning_id) {
+ $warnings[] = $warningsController->Warning->findById($warning_id);
+ }
+
+ // SENDING DATA TO VIEW
+ $this->set(array(
+ 'warnings' => $warnings,
+ '_serialize' => array('warnings')
+ ));
+ }
+
+ if ($this->request->is(array('changelog', 'put'))) {
+ $this->Changelog->id = $id;
+ if ($this->Changelog->save($this->request->data)) {
+ $this->Session->setFlash(__("L'historique a été mis à jour."));
+ $this->redirect(array('action' => 'index'));
+ }
+ $this->Session->setFlash(__("Mise à jour de l'historique impossible."));
+ }
+
+ if (!$this->request->data) {
+ $this->request->data = $changelog;
+ }
+ }
+
+ public function delete($id) {
+
+ // DISABLE GET ACCESS ?
+ /*if ($this->request->is('get')) {
+ throw new MethodNotAllowedException();
+ }
+ */
+ if ($this->Changelog->delete($id)) {
+ $this->Session->setFlash(
+ __("L'historique d'id: %s a été supprimé.", h($id))
+ );
+ $this->redirect(array('action' => 'index'));
+ }
+ }
+
+ public function acknowledgeWarning($id = null, $warning_id = null, $validate = false, $escapedApplianceReference = null) {
+
+ // GETTING CHANGELOG
+ $this->Changelog->id = $id;
+ $changelog = $this->Changelog->findById($id);
+ if (!$changelog) {
+ throw new NotFoundException(__('Historique introuvable'));
+ }
+
+ // GETTING WARNINGS OF CHANGELOG
+ App::import('Controller', 'Warnings');
+ $warningsController = new WarningsController;
+ $warning = $warningsController->Warning->findById($warning_id);
+ if (!$warning) {
+ throw new NotFoundException(__('Alerte introuvable'));
+ }
+
+ // ADDING VERSION AND DATE OF WARNING TO CHANGELOG IF NATURE OF WARNING IS EITHER CREATION OR VERSION
+ if(in_array($warning['Warning']['nature'], array('version', 'creation'))) {
+ $version = $warning['Warning']['version'];
+ $date = $warning['Warning']['creation'];
+ $versions = array();
+ if($this->Changelog->value('versions')) {
+ $versions = explode('|', $this->Changelog->value('versions'));
+ }
+ $versions[] = $version.";".$date;
+ $this->Changelog->value('versions', implode('|', $versions));
+ }
+
+ // IN CASE OF VALIDATION => OPPORTUNITY CREATION IN SUGAR THROUGH ALLO SERVEUR CONNECTOR
+ if($validate) {
+ $applianceReference = str_replace("SLASH", "\\/", $escapedApplianceReference);
+ $url = 'http://allo_serveur/?action=create_opportunity&appliance_reference='.$applianceReference;
+ $options = array("http" => array("method" => "GET"));
+ $context = stream_context_create($options);
+ $response = file_get_contents($url, false, $context);
+ if(isset($response)) {
+ // USE THE ID SENT ?
+ }
+ }
+
+ // DELETING WARNING
+ $warningsController->Warning->delete($warning_id);
+ $warnings_id = explode('|', $this->Changelog->value('warnings'));
+ if(($key = array_search($warning_id, $warnings_id)) !== false) {
+ unset($warnings_id[$key]);
+ }
+ $this->Changelog->value('warnings', implode('|', $warnings_id));
+ $this->Changelog->save();
+
+ // REDIRECTION TO APPLIANCES PAGE
+ $this->redirect(array('controller' => 'appliances', 'action' => 'index'));
+ }
+ }
+?>
--- /dev/null
+<?php
+ class CustomersController extends AppController {
+ public $helpers = array('Html', 'Form');
+ public $components = array('RequestHandler');
+
+ public function index() {
+ $customers = $this->Customer->find('all');
+ $this->set(array(
+ 'customers' => $customers,
+ '_serialize' => array('customers')
+ ));
+ }
+ }
+?>
--- /dev/null
+<?php
+ class ManagersController extends AppController {
+ public $helpers = array('Html', 'Form');
+ public $components = array('RequestHandler');
+
+ public function index() {
+ $managers = $this->Manager->find('all');
+ $this->set(array(
+ 'managers' => $managers,
+ '_serialize' => array('managers')
+ ));
+ }
+
+ public function view($id = null) {
+ if (!$id) {
+ throw new NotFoundException(__('Mauvais exploitant'));
+ }
+
+ $manager = $this->Manager->findById($id);
+ if (!$manager) {
+ throw new NotFoundException(__('Mauvais exploitant'));
+ }
+ $this->set('manager', $manager);
+ }
+
+ public function add() {
+ if ($this->request->is('manager')) {
+ $this->Manager->create();
+ if ($this->Manager->save($this->request->data)) {
+ $this->Session->setFlash(__("L'exploitant a été enregistré."));
+ $this->redirect(array('action' => 'index'));
+ }
+ $this->Session->setFlash(__("Enregistrement de l'exploitant impossible."));
+ }
+ }
+
+ public function edit($id = null) {
+ if (!$id) {
+ throw new NotFoundException(__('Exploitant introuvable'));
+ }
+
+ $manager = $this->Manager->findById($id);
+ if (!$manager) {
+ throw new NotFoundException(__('Exploitant introuvable'));
+ }
+ $this->set('manager', $manager);
+
+ // GETTING ALL APPLIANCES OF THIS MANAGER
+ $appliances_id = explode('|', $this->Manager->value('appliances'));
+ App::import('Controller', 'Appliances');
+ $appliancesController = new AppliancesController;
+ $appliances = array();
+ foreach ($appliances_id as $appliance_id) {
+ $appliances[] = $appliancesController->Appliance->findById($appliance_id);
+ }
+ $this->set('appliances', $appliances);
+
+ if ($this->request->is(array('manager', 'put'))) {
+ $this->Manager->id = $id;
+ if ($this->Manager->save($this->request->data)) {
+ $this->Session->setFlash(__("L'exploitant a été mis à jour."));
+ $this->redirect(array('action' => 'index'));
+ }
+ $this->Session->setFlash(__("Mise à jour de l'exploitant impossible."));
+ }
+
+ if (!$this->request->data) {
+ $this->request->data = $manager;
+ }
+ }
+
+ public function delete($id) {
+ if ($this->request->is('get')) {
+ throw new MethodNotAllowedException();
+ }
+
+ if ($this->Manager->delete($id)) {
+ $this->Session->setFlash(
+ __("L'exploitant d'id: %s a été supprimé.", h($id))
+ );
+ $this->redirect(array('action' => 'index'));
+ }
+ }
+ }
+?>
--- /dev/null
+<?php
+ class ProductsController extends AppController {
+ public $helpers = array('Html', 'Form');
+ public $components = array('RequestHandler');
+
+ public function index() {
+
+ // GETTING ALL PRODUCTS
+ $products = $this->Product->find('all');
+
+ // GETTING VERSION CONTROLLER AND ALL VERSIONS
+ App::import('Controller', 'Versions');
+ $versionsController = new VersionsController;
+ $versions = $versionsController->Version->find('all');
+
+ // SENDING DATA TO VIEW
+ $this->set(array(
+ 'products' => $products,
+ '_serialize' => array('products')
+ ));
+ $this->set(array(
+ 'versions' => $versions,
+ '_serialize' => array('versions')
+ ));
+ }
+
+ public function add() {
+ if ($this->request->is('POST')) {
+ $this->Product->create();
+ if ($this->Product->save($this->request->data)) {
+ $this->Session->setFlash(__("Le produit a été enregistré."));
+ $this->redirect(array('action' => 'index'));
+ }
+ $this->Session->setFlash(__("Enregistrement du produit impossible."));
+ }
+ }
+
+ public function edit($id = null) {
+ if (!$id) {
+ throw new NotFoundException(__('Produit introuvable'));
+ }
+
+ $product = $this->Product->findById($id);
+ if (!$product) {
+ throw new NotFoundException(__('Produit introuvable'));
+ }
+
+ if ($this->request->is(array('product', 'put'))) {
+ $this->Product->id = $id;
+ if ($this->Product->save($this->request->data)) {
+ $this->Session->setFlash(__("La produit a été mis à jour."));
+ $this->redirect(array('action' => 'index'));
+ }
+ $this->Session->setFlash(__("Mise à jour du produit impossible."));
+ }
+
+ if (!$this->request->data) {
+ $this->request->data = $product;
+ }
+ }
+
+ public function delete($id) {
+ if ($this->request->is('get')) {
+ throw new MethodNotAllowedException();
+ }
+
+ if ($this->Product->delete($id)) {
+ $this->Session->setFlash(
+ __("La produit d'id: %s a été supprimé.", h($id))
+ );
+ $this->redirect(array('action' => 'index'));
+ }
+ }
+ }
+?>
public $components = array('RequestHandler');
public function index() {
+
// GETTING ALL VERSIONS
$versions = $this->Version->find('all');
));
}
- public function view($id = null) {
- if (!$id) {
- throw new NotFoundException(__('Mauvaise version'));
- }
-
- $version = $this->Version->findById($id);
- if (!$version) {
- throw new NotFoundException(__('Mauvaise version'));
- }
- $this->set('version', $version);
- }
-
- public function add($produit_id = null) {
+ public function add($product_id = null) {
if ($this->request->is('POST')) {
$this->Version->create();
- $this->Version->value('valeur', $_POST['valeur']);
+ $this->Version->value('value', $_POST['value']);
$this->Version->value('nature', $_POST['nature']);
- $this->Version->value('produit', $_POST['produit']);
+ $this->Version->value('product', $_POST['product']);
if ($this->Version->save($this->request->data)) {
$this->Session->setFlash(__("La version a été enregistrée."));
- return $this->redirect(array('action' => 'index'));
+ $this->redirect(array('action' => 'index'));
}
$this->Session->setFlash(__("Enregistrement de la version impossible."));
} else {
- // RECUPÉRATION DU / DES PRODUITS LIÉS
- App::import('Controller', 'Produits');
- $produitsController = new ProduitsController;
- if(isset($produit_id)) {
- $produit = $produitsController->Produit->findById($produit_id);
- $this->set('produit', $produit);
+
+ // GETTING PRODUCT IF ITS ID IS SET IN REQUEST, IF NOT ALL PRODUCTS
+ App::import('Controller', 'Products');
+ $productsController = new ProductsController;
+ if(isset($product_id)) {
+ $product = $productsController->Product->findById($product_id);
+ $this->set('product', $product);
} else {
- $produits = $produitsController->Produit->find('all');
+ $products = $productsController->Product->find('all');
$this->set(array(
- 'produits' => $produits,
- '_serialize' => array('produits')
+ 'products' => $products,
+ '_serialize' => array('products')
));
}
}
$this->Version->id = $id;
if ($this->Version->save($this->request->data)) {
$this->Session->setFlash(__("La version a été mise à jour."));
+
// REDIRECTION
- return $this->redirect(array('controller' => 'produits', 'action' => 'index'));
+ $this->redirect(array('controller' => 'products', 'action' => 'index'));
}
$this->Session->setFlash(__("Mise à jour de la version impossible."));
}
$this->Session->setFlash(
__("La version d'id: %s a été supprimée.", h($id))
);
+
// REDIRECTION
- return $this->redirect(array('controller' => 'produits', 'action' => 'index'));
+ $this->redirect(array('controller' => 'products', 'action' => 'index'));
}
}
}
--- /dev/null
+<?php
+ class WarningsController extends AppController {
+ public $helpers = array('Html', 'Form');
+ public $components = array('RequestHandler');
+
+ public function index() {
+ $warnings = $this->Warning->find('all');
+ $this->set(array(
+ 'warnings' => $warnings,
+ '_serialize' => array('warnings')
+ ));
+ }
+
+ public function view($id = null) {
+ if (!$id) {
+ throw new NotFoundException(__('Mauvaise alerte'));
+ }
+
+ $warning = $this->Warning->findById($id);
+ if (!$warning) {
+ throw new NotFoundException(__('Mauvaise alerte'));
+ }
+ $this->set('warning', $warning);
+ }
+
+ public function add() {
+ if ($this->request->is('warning')) {
+ $this->Warning->create();
+ if ($this->Warning->save($this->request->data)) {
+ $this->Session->setFlash(__("L'alerte a été enregistrée."));
+ $this->redirect(array('action' => 'index'));
+ }
+ $this->Session->setFlash(__("Enregistrement de l'alerte impossible."));
+ }
+ }
+
+ public function edit($id = null) {
+ if (!$id) {
+ throw new NotFoundException(__('Alerte introuvable'));
+ }
+
+ $warning = $this->Warning->findById($id);
+ if (!$warning) {
+ throw new NotFoundException(__('Alerte introuvable'));
+ }
+ $this->set('warning', $warning);
+
+ if ($this->request->is(array('warning', 'put'))) {
+ $this->Warning->id = $id;
+ if ($this->Warning->save($this->request->data)) {
+ $this->Session->setFlash(__("L'alerte a été mise à jour."));
+ $this->redirect(array('action' => 'index'));
+ }
+ $this->Session->setFlash(__("Mise à jour de l'alerte impossible."));
+ }
+
+ if (!$this->request->data) {
+ $this->request->data = $warning;
+ }
+ }
+
+ public function delete($id) {
+ if ($this->request->is('get')) {
+ throw new MethodNotAllowedException();
+ }
+
+ if ($this->Warning->delete($id)) {
+ $this->Session->setFlash(
+ __("L'alerte d'id: %s a été supprimée.", h($id))
+ );
+ $this->redirect(array('action' => 'index'));
+ }
+ }
+ }
+?>
--- /dev/null
+<?php
+ class Administrator extends AppModel {
+ public function value($field, $value = null) {
+ if(func_num_args() === 1){
+ $result = $this->field($field);
+ if($result){
+ return $result;
+ }
+ } else {
+ if($this->saveField($field, $value)) {
+ return true;
+ }
+ }
+ return false;
+ }
+ }
+?>
--- /dev/null
+<?php
+ class Appliance extends AppModel {
+ public $validate = array(
+ 'version' => array(
+ 'rule' => 'notEmpty'
+ )
+ );
+
+ public function value($field, $value = null) {
+ if(func_num_args() === 1){
+ $result = $this->field($field);
+ if($result){
+ return $result;
+ }
+ } else {
+ if($this->saveField($field, $value)) {
+ return true;
+ }
+ }
+ return false;
+ }
+ }
+?>
--- /dev/null
+<?php
+ class Changelog extends AppModel {
+ public function value($field, $value = null) {
+ if(func_num_args() === 1){
+ $result = $this->field($field);
+ if($result){
+ return $result;
+ }
+ } else {
+ if($this->saveField($field, $value)) {
+ return true;
+ }
+ }
+ return false;
+ }
+ }
+?>
--- /dev/null
+<?php
+ class Customer extends AppModel {
+ public function value($field, $value = null) {
+ if(func_num_args() === 1){
+ $result = $this->field($field);
+ if($result){
+ return $result;
+ }
+ } else {
+ if($this->saveField($field, $value)) {
+ return true;
+ }
+ }
+ return false;
+ }
+ }
+?>
--- /dev/null
+<?php
+ class Manager extends AppModel {
+ public function value($field, $value = null) {
+ if(func_num_args() === 1){
+ $result = $this->field($field);
+ if($result){
+ return $result;
+ }
+ } else {
+ if($this->saveField($field, $value)) {
+ return true;
+ }
+ }
+ return false;
+ }
+ }
+?>
--- /dev/null
+<?php
+ class Product extends AppModel {
+ public function value($field, $value = null) {
+ if(func_num_args() === 1){
+ $result = $this->field($field);
+ if($result){
+ return $result;
+ }
+ } else {
+ if($this->saveField($field, $value)) {
+ return true;
+ }
+ }
+ return false;
+ }
+ }
+?>
<?php
class Version extends AppModel {
public $validate = array(
- 'valeur' => array(
+ 'value' => array(
'rule' => 'notEmpty'
)
);
--- /dev/null
+<?php
+ class Warning extends AppModel {
+
+ public function value($field, $value = null) {
+ if(func_num_args() === 1){
+ $result = $this->field($field);
+ if($result){
+ return $result;
+ }
+ } else {
+ if($this->saveField($field, $value)) {
+ return true;
+ }
+ }
+ return false;
+ }
+ }
+?>
--- /dev/null
+<h1>Liste des administrateurs</h1>
+<table>
+ <tr>
+ <th>Login</th>
+ </tr>
+
+ <?php if(isset($administrators)) { foreach ($administrators as $administrator): ?>
+ <tr>
+ <td><?php echo $administrator['Administrator']['login'] ?></td>
+ </tr>
+ <?php endforeach; ?>
+ <?php unset($administrator); } ?>
+</table>
--- /dev/null
+<h1>Merci de vous authentifier en tant qu'administrateur</h1>
+<?php
+echo $this->Form->create('Administrator');
+echo $this->Form->input('login', array('name' => 'login'));
+echo $this->Form->input('pass', array('name' => 'pass'));
+echo $this->Form->end("Login");
+?>
--- /dev/null
+<h1>Enregistrement d'un nouvel administrateur</h1>
+<?php
+echo $this->Form->create('Administrator');
+echo $this->Form->input('login', array('name' => 'login'));
+echo $this->Form->input('pass', array('name' => 'pass'));
+echo $this->Form->end("Login");
+?>
--- /dev/null
+<h1>Ajout d'une instance applicative</h1>
+<?php
+echo $this->Form->create('Appliance');
+echo $this->Form->input('reference');
+// TO-DO : LINK TO THE RIGHT PRODUCT AND CHANGE VERSIONS ACCORDINGLY
+echo $this->Form->input('internal_fqdn');
+echo $this->Form->input('external_fqdn');
+echo $this->Form->input('manager');
+echo $this->Form->end("Enregistrer l'instance applicative");
+?>
\ No newline at end of file
--- /dev/null
+<h1>Editer l'instance applicative</h1>
+<?php
+echo $this->Form->create('Appliance');
+// TO-DO : DISPLAY AND EDIT PRODUCT LINKED TO THIS APPLIANCE
+echo $this->Form->input('reference');
+if(isset($possibleVersions)) {
+ echo $this->Form->input('version', array('options' => $possibleVersions));
+}
+echo $this->Form->input('internal_fqdn');
+echo $this->Form->input('external_fqdn');
+echo $this->Form->input('os');
+echo $this->Form->input('manager');
+echo $this->Form->input('maintained', array('type' => 'radio', 'options' => array('0' => 'Faux', '1' => 'Vrai')));
+echo $this->Form->input('disc_infos');
+echo $this->Form->input('id', array('type' => 'hidden'));
+echo $this->Form->end("Mettre à jour l'instance applicative");
+?>
\ No newline at end of file
--- /dev/null
+<h1>
+ <?php echo $this->Html->link(
+ 'Nouvelle instance applicative',
+ array('controller' => 'appliances', 'action' => 'add')
+); ?>
+</h1>
+<button onclick="checkAppliancesInformation();">Vérifier ces informations avec Sugar</button>
+<table>
+ <tr>
+ <th>Référence d'instance applicative</th>
+ <th>Client</th>
+ <th>Canal</th>
+ <?php if(isset($warningsArray) && count($warningsArray) > 0) { ?>
+ <th>Alertes</th>
+ <?php } ?>
+ <th>Actions</th>
+ </tr>
+
+ <?php
+ if(isset($appliances)) { foreach ($appliances as $appliance): ?>
+ <tr>
+ <td><?php echo $appliance['Appliance']['reference']; ?></td>
+
+ <?php
+
+ // CHECKING CUSTOMER EXISTENCE / FINDABILITY FOR THIS APPLIANCE
+ if(isset($customersArray) && array_key_exists($appliance['Appliance']['id'], $customersArray)) {
+ $customer = $customersArray[$appliance['Appliance']['id']]; ?>
+ <td>
+ <?php
+
+ // DISPLAYING CUSTOMER AP ID (ADD / CHANGE TO ITS NAME ?)
+ echo $customer['Customer']['ap_id'];
+ ?>
+ </td>
+
+ <?php
+
+ // DISPLAYING ERROR MESSAGE IF NO CUSTOMER IS FOUND
+ } else { ?>
+ <td>Client pour cette instance applicative inexistant ou introuvable</td>
+ <?php } ?>
+
+ <!-- TO-DO : DISPLAY PRODUCT NAME -->
+
+ <!-- TO-DO : DISPLAY LAST VERSION DECLARED FROM CHANGELOG
+
+ if(array_key_exists($appliance['Appliance']['id'], $lastUpdates)) {
+ $lastUpdate = $lastUpdates[$appliance['Appliance']['id']];
+ echo $appliance['Appliance']['version']." le ".$lastUpdate;
+ } else {
+ echo $appliance['Appliance']['version'];
+ }
+ -->
+
+
+ <td><?php echo strtoupper($appliance['Appliance']['channel']); ?></td>
+
+ <?php
+
+ // CHECKING CHANGELOG EXISTENCE FOR THIS APPLIANCE
+ if(isset($changelogsArray) && array_key_exists($appliance['Appliance']['id'], $changelogsArray)) {
+ $changelog = $changelogsArray[$appliance['Appliance']['id']];
+
+ // CHECKING WARNING EXISTENCE
+ if(isset($warningsArray) && count($warningsArray) > 0) {
+ ?>
+ <td>
+ <table>
+ <tr>
+ <?php if(array_key_exists($changelog['Changelog']['id'], $warningsArray)) { ?>
+ <th>Message</th>
+ <th>Actions</th>
+ <?php } ?>
+ </tr>
+ <?php
+
+ // CHECKING WARNING EXISTENCE FOR THIS CHANGELOG AND APPLIANCE
+ if(array_key_exists($changelog['Changelog']['id'], $warningsArray)) {
+ foreach ($warningsArray[$changelogsArray[$appliance['Appliance']['id']]['Changelog']['id']] as $warning): ?>
+ <tr>
+ <td>
+ <?php
+
+ // DISPLAYING WARNING MESSAGE
+ echo $warning['Warning']['message'] ?>
+ </td>
+ <td>
+ <?php
+ $escapedApplianceReference = str_replace("/", "SLASH", $appliance['Appliance']['reference']);
+
+ // WARNING VALIDATION ACTION
+ echo $this->Html->link(
+ $this->Html->image('validate.png', array('class' => 'button')),
+ array('controller' => 'changelogs', 'action' => 'acknowledgeWarning', $changelog['Changelog']['id'], $warning['Warning']['id'], true, $escapedApplianceReference),
+ array('escape' => false)
+ )
+ .' '.
+
+ // WARNING REFUSAL ACTION
+ $this->Html->link(
+ $this->Html->image('delete.png', array('class' => 'button')), '#',
+ array('escape' => false,
+ 'onclick' => 'keepMaintained('.$appliance['Appliance']['id'].', '.$changelog['Changelog']['id'].', '.$warning['Warning']['id'].')'
+ )
+ );
+ ?>
+ </td>
+ </tr>
+ <?php endforeach; } ?>
+ </table>
+ </td>
+ <?php } ?>
+ <td>
+ <?php echo $this->Html->link(
+ $this->Html->image('edit.jpg', array('class' => 'button')),
+ array('controller' => 'appliances', 'action' => 'edit', $appliance['Appliance']['id']),
+ array('escape' => false)
+ ).' '.
+ $this->Html->link(
+ $this->Html->image('delete.png', array('class' => 'button')), '#',
+ array('escape' => false,
+ 'onclick' => 'deleteAppliance('.$appliance['Appliance']['id'].', '.$changelog['Changelog']['id'].')'
+ )
+ );
+ ?>
+ </td>
+ <?php
+
+ // DISPLAYING ERROR MESSAGE IF NO CHANGELOG IS FOUND
+ } else { ?>
+ <td>Historique pour cette instance applicative inexistant ou introuvable</td>
+ <td>
+ <?php
+
+ // APPLIANCE EDIT ACTION
+ echo $this->Html->link(
+ $this->Html->image('edit.jpg', array('class' => 'button')),
+ array('controller' => 'appliances', 'action' => 'edit', $appliance['Appliance']['id']),
+ array('escape' => false)
+ ).' '.
+
+ // APPLIANCE DELETE ACTION
+ $this->Form->postLink(
+ $this->Html->image('delete.png', array('class' => 'button')),
+ array('controller' => 'appliances', 'action' => 'delete', $appliance['Appliance']['id']),
+ array('escape' => false, 'confirm' => 'Etes-vous certain ?')
+ );
+ ?>
+ </td>
+ <?php } ?>
+ </tr>
+ <?php endforeach; unset($appliances); } ?>
+</table>
+<script>
+
+ // JS FUNCTIONS FOR CONFIRMATION POP-UPS AND AJAX CALLS
+ var keepMaintained = function (appliance_id, changelog_id, warning_id) {
+ var acknowledgeWarningUrl = "/changelogs/acknowledgeWarning/"+changelog_id+"/"+warning_id+"/false",
+ isStillMaintained = confirm("Conserver le maintien de l'appliance ?");
+ if(isStillMaintained) {
+ alert('Maintien conservé');
+ location.href = acknowledgeWarningUrl;
+ } else {
+ alert('Maintien supprimé');
+ $.ajax({
+ url: "http://allo_serveur?action=disable_maintained&id="+appliance_id,
+ beforeSend: function(xhr) {
+ xhr.overrideMimeType("text/plain; charset=x-user-defined");
+ }
+ })
+ .done(function(data) {
+ location.href = acknowledgeWarningUrl;
+ });
+ }
+ };
+
+ var deleteAppliance = function (appliance_id, changelog_id) {
+ var confirmAction = confirm("Etes-vous certain ?");
+ if (confirmAction) {
+ var isChangelogKept = confirm("Conserver l'historique de l'instance applicative ?");
+ if(isChangelogKept) {
+ alert('historique conservé');
+ location.href = "/appliances/delete/"+appliance_id;
+ } else {
+ alert('historique supprimé');
+ $.ajax({
+ url: "http://allo_webadmin/changelogs/delete/"+changelog_id,
+ beforeSend: function(xhr) {
+ xhr.overrideMimeType("text/plain; charset=x-user-defined");
+ }
+ })
+ .done(function(data) {
+ location.href = "/appliances/delete/"+appliance_id;
+ });
+ }
+ }
+ };
+
+ var checkAppliancesInformation = function () {
+ $.ajax({
+ url: "http://allo_serveur/?action=check_appliances_infos",
+ beforeSend: function(xhr) {
+ xhr.overrideMimeType("text/plain; charset=x-user-defined");
+ }
+ })
+ .done(function( data ) {
+ location.href = "/appliances";
+ });
+ };
+</script>
\ No newline at end of file
--- /dev/null
+<h1>Editer l'historique</h1>
+<?php
+ echo $this->Form->create('Changelog');
+ //TO-DO : DISPLAY VERSION LIST OF CHANGELOG AND POSSIBILITY TO ADD A NEW ONE
+ if(isset($alertes)) {
+ echo "Alertes :";
+?>
+<table>
+ <tr>
+ <th>Date</th>
+ <th>Version</th>
+ <th>Type</th>
+ </tr>
+ <?php foreach ($alertes as $alerte) { ?>
+ <tr>
+ <td><?php echo $alerte['Alerte']['creation']; ?></td>
+ <td><?php echo $alerte['Alerte']['version']; ?></td>
+ <td><?php echo $alerte['Alerte']['nature']; ?></td>
+ </tr>
+<?php } ?>
+</table>
+<?php
+ }
+ echo $this->Form->input('id', array('type' => 'hidden'));
+ echo $this->Form->end("Mettre à jour l'historique");
+?>
\ No newline at end of file
--- /dev/null
+<h1>Liste des clients</h1>
+<button onclick="synchronizeCustomersInformation();">Synchronisation</button>
+<table>
+ <tr>
+ <th>Nom</th>
+ <th>Identifiant AP</th>
+ </tr>
+
+ <?php if(isset($customers)) { foreach ($customers as $customer): ?>
+ <tr>
+ <td><?php echo $customer['Customer']['name'] ?></td>
+ <td><?php echo $customer['Customer']['ap_id']; ?></td>
+ </tr>
+ <?php endforeach; ?>
+ <?php unset($customer); } ?>
+</table>
+
+<script>
+ var synchronizeCustomersInformation = function () {
+ $.ajax({
+ url: "http://allo_serveur/?action=synchronize_customers_info",
+ beforeSend: function(xhr) {
+ xhr.overrideMimeType("text/plain; charset=x-user-defined");
+ }
+ })
+ .done(function(data) {
+ location.href = "/customers";
+ });
+ };
+</script>
\ No newline at end of file
<h1>ALLO Webadmin</h1>
</div>
<div id="menu">
- <a href="/instances">INSTANCES</a>
- <a href="/alertes">ALERTES</a>
- <a href="/produits">PRODUITS</a>
- <a href="/clients">CLIENTS</a>
+ <a href="/appliances">INSTANCES</a>
+ <a href="/warnings">ALERTES</a>
+ <a href="/products">PRODUITS</a>
+ <a href="/customers">CLIENTS</a>
</div>
</div>
<div id="content">
--- /dev/null
+<h1>Ajout d'un exploitant</h1>
+<?php
+ echo $this->Form->create('Manager');
+ echo $this->Form->input('name');
+ echo $this->Form->input('ap_id');
+ // TO-DO : DISPLAY APPLIANCES LIST THAT CAN BE LINKED TO THIS MANAGER
+ echo $this->Form->end("Enregistrer l'exploitant");
+?>
\ No newline at end of file
--- /dev/null
+<h1>Editer l'exploitant</h1>
+<?php
+ echo $this->Form->create('Manager');
+ echo $this->Form->input('name');
+ echo $this->Form->input('ap_id');
+ echo "Instances applicatives liées :";
+ if(isset($appliances)) {
+ foreach ($appliances as $appliance) {
+ ?><p><?php
+ echo $this->Html->link(
+ $appliance['Appliance']['reference'],
+ array('controller' => 'appliances', 'action' => 'edit', $appliance['Appliance']['id'])
+ );
+ ?></p><?php
+ }
+ // TO-DO : POSSIBILITY TO LINK NEW INSTANCES
+ }
+ echo $this->Form->input('id', array('type' => 'hidden'));
+ echo $this->Form->end("Mettre à jour l'exploitant");
+?>
\ No newline at end of file
--- /dev/null
+<h1>Liste d'exploitants</h1>
+<table>
+ <tr>
+ <th>Nom</th>
+ <th>Identifiant AP</th>
+ </tr>
+
+ <?php if(isset($managers)) { foreach ($managers as $manager): ?>
+ <tr>
+ <td>
+ <?php echo $this->Html->link(
+ $manager['Manager']['name'],
+ array('controller' => 'managers', 'action' => 'edit', $manager['Manager']['id'])
+ );
+ ?>
+ </td>
+ <td><?php echo $manager['Manager']['ap_id']; ?></td>
+ <td>
+ <?php
+ echo $this->Form->postLink(
+ 'Supprimer',
+ array('action' => 'delete', $manager['Manager']['id']),
+ array('confirm' => 'Etes-vous certain ?')
+ );
+ ?>
+ </td>
+ </tr>
+ <?php endforeach; } ?>
+ <?php echo $this->Html->link(
+ 'Ajouter un exploitant',
+ array('controller' => 'managers', 'action' => 'add')
+ ); ?>
+</table>
--- /dev/null
+<h1>Ajout d'un produit</h1>
+<?php
+echo $this->Form->create('Product');
+echo $this->Form->input('name');
+echo $this->Form->end("Enregistrer le produit");
+?>
\ No newline at end of file
--- /dev/null
+<h1>Editer le produit</h1>
+<?php
+echo $this->Form->create('Product');
+echo $this->Form->input('name');
+echo $this->Form->input('id', array('type' => 'hidden'));
+echo $this->Form->end("Mettre à jour le produit");
+?>
\ No newline at end of file
--- /dev/null
+<h1>
+ <?php echo $this->Html->link(
+ 'Nouveau produit',
+ array('controller' => 'products', 'action' => 'add')
+); ?>
+</h1>
+<table>
+ <tr>
+ <th>Nom</th>
+ <th>Versions</th>
+ <th>Actions</th>
+ </tr>
+
+ <?php if(isset($products)) { foreach ($products as $product): ?>
+ <tr>
+ <td><?php echo $product['Product']['name']; ?></td>
+ <td>
+ <?php echo $this->Html->link(
+ 'Nouvelle version',
+ array('controller' => 'versions', 'action' => 'add', $product['Product']['id'])
+ ); ?>
+ <table>
+ <tr>
+ <th>Valeur</th>
+ <th>Type</th>
+ <th>Actions</th>
+ </tr>
+ <?php if(isset($versions)) { foreach ($versions as $version): if($version['Version']['product'] == $product['Product']['id']) { ?>
+ <tr>
+ <td><?php echo $version['Version']['value']; ?></td>
+ <td><?php echo $version['Version']['nature']; ?></td>
+ <td>
+ <?php echo $this->Html->link(
+ $this->Html->image('edit.jpg', array('class' => 'button')),
+ array('controller' => 'versions', 'action' => 'edit', $version['Version']['id']),
+ array('escape' => false)
+ ).' '.
+ $this->Form->postLink(
+ $this->Html->image('delete.png', array('class' => 'button')),
+ array('action' => 'delete', $version['Version']['id']),
+ array('escape' => false, 'confirm' => 'Etes-vous certain ?')
+ );
+ ?>
+ </td>
+ </tr>
+ <?php } endforeach; } ?>
+ </table>
+ </td>
+ <td>
+ <?php echo $this->Html->link(
+ $this->Html->image('edit.jpg', array('class' => 'button')),
+ array('controller' => 'products', 'action' => 'edit', $product['Product']['id']),
+ array('escape' => false)
+ ).' '.
+ $this->Form->postLink(
+ $this->Html->image('delete.png', array('class' => 'button')),
+ array('action' => 'delete', $product['Product']['id']),
+ array('escape' => false, 'confirm' => 'Etes-vous certain ?')
+ );
+ ?>
+ </td>
+ </tr>
+ <?php endforeach; }?>
+</table>
<h1>Ajout d'une version</h1>
<?php
echo $this->Form->create('Version');
-echo $this->Form->input('valeur');
+echo $this->Form->input('value');
echo $this->Form->input('nature', array('options' => array('patch' => 'Patch', 'majmin' => 'Mise à jour mineure', 'majmaj' => 'Mise à jour majeure')));
-if(isset($produit)) {
- echo 'Produit : '.$produit['Produit']['nom'];
- echo $this->Form->input('produit', array('type' => 'hidden', 'value' => $produit['Produit']['id']));
-} else if (isset($produits)) {
+if(isset($product)) {
+ echo 'Produit : '.$product['Product']['name'];
+ echo $this->Form->input('product', array('type' => 'hidden', 'value' => $product['Product']['id']));
+} else if (isset($products)) {
$options = array();
- foreach($produits as $produit) {
- $options[$produit['Produit']['id']] = $produit['Produit']['nom'];
+ foreach($products as $product) {
+ $options[$product['Product']['id']] = $product['Product']['name'];
}
- echo $this->Form->input('produit', array('options' => $options));
+ echo $this->Form->input('product', array('options' => $options));
}
echo $this->Form->end("Enregistrer la version");
?>
\ No newline at end of file
<h1>Editer la version</h1>
<?php
echo $this->Form->create('Version');
-echo $this->Form->input('valeur');
+echo $this->Form->input('value');
echo $this->Form->input('id', array('type' => 'hidden'));
echo $this->Form->end("Mettre à jour la version");
?>
\ No newline at end of file
<th>Actions</th>
</tr>
- <?php foreach ($versions as $version): ?>
+ <?php if(isset($versions)) { foreach ($versions as $version): ?>
<tr>
- <td><?php echo $version['Version']['valeur']; ?></td>
+ <td><?php echo $version['Version']['value']; ?></td>
<td>
<?php echo $this->Html->link(
'Editer',
?>
</td>
</tr>
- <?php endforeach; ?>
- <?php unset($version); ?>
+ <?php endforeach; } ?>
</table>
--- /dev/null
+<table>
+ <tr>
+ <th>Date de d'émission</th>
+ <th>Type</th>
+ <th>Message</th>
+ </tr>
+
+ <?php foreach ($warnings as $warning): ?>
+ <tr>
+ <td><?php echo $warning['Warning']['creation']; ?></td>
+ <td><?php echo $warning['Warning']['nature']; ?></td>
+ <td><?php echo $warning['Warning']['message']; ?></td>
+ </tr>
+ <?php endforeach; ?>
+ <?php unset($warning); ?>
+</table>
-HTTP/1.1 200 OK\r
-Date: Mon, 27 Apr 2015 14:48:51 GMT\r
-Server: Apache/2.2.22 (Ubuntu)\r
-X-Powered-By: PHP/5.3.10-1ubuntu3.17\r
-Access-Control-Allow-Origin: *\r
-Vary: Accept-Encoding\r
-Content-Length: 0\r
-Content-Type: text/html; charset=utf-8\r
-\r
+L'application a renvoyé une erreur :
+Aucune réponse de l'application
curl --max-time 10 -k -X GET -H "Accept: application/json" "http://${fqdn_interne}/api/rest/allo/version/" --output "response.json" 2> /dev/null
produit="$(jq -r '.produit' response.json)"
- echo "Produit : "${produit}
+ echo "Produit : ""${produit}"
case "${produit}" in
"i-Parapheur")
prefixe="AS"
;;
*)
- echo "Produit non reconnu" 2>&1 | tee -a $log_file
+ echo "Produit non reconnu" 2>&1 | tee -a "$log_file"
;;
esac
validation_ref_client=true
fi
done
- echo "FQDN interne : "${fqdn_interne}
- echo "FQDN externe : "${fqdn_externe}
- echo "Canal de mise à jour : "${canal}
- echo "Référence client : "${reference_client}
+ echo "FQDN interne : ""${fqdn_interne}"
+ echo "FQDN externe : ""${fqdn_externe}"
+ echo "Canal de mise à jour : ""${canal}"
+ echo "Référence client : ""${reference_client}"
read -p "Ces informations sont-elles correctes [O/n] ? "
rm "${configuration}"
fi
touch "${configuration}"
-echo "###### CONFIGURATION ALLO AGENT ######" >> $configuration
-echo "" >> $configuration
-echo "# Référence de l'instance sur ALLO" >> $configuration
-echo 'instance_reference="'${prefixe}'/'${reference_client}'_'${now}'"' >> $configuration
-echo "# Type d'usager (exploitant|client)" >> $configuration
-echo 'usager_type="client"' >> $configuration
-echo "# Type d'instance (qualif|prod)" >> $configuration
-echo 'instance_canal="'${canal}'"' >> $configuration
-echo "# Fqdn interne" >> $configuration
-echo 'instance_fqdn_interne="'${fqdn_interne}'"' >> $configuration
-echo "# Fqdn externe" >> $configuration
-echo 'instance_fqdn_externe="'${fqdn_externe}'"' >> $configuration
-echo "# ALLO Serveur" >> $configuration
-echo 'allo_serveur_url="allo_serveur"' >> $configuration
-echo "# Type de données acceptées" >> $configuration
-echo 'response_accept="Accept: application/json"' >> $configuration
-echo "# Type de données envoyées" >> $configuration
-echo 'request_type="Content-Type: application/json"' >> $configuration
-echo "# Logs" >> $configuration
-echo 'log_file="allo_agent.log"' >> $configuration
+{
+ echo "###### CONFIGURATION ALLO AGENT ######"
+ echo ""
+ echo "# Référence de l'instance sur ALLO"
+ echo 'instance_reference="'"${prefixe}"'/'"${reference_client}"'_'"${now}"'"'
+ echo "# Type d'usager (exploitant|client)"
+ echo 'usager_type="client"'
+ echo "# Type d'instance (qualif|prod)"
+ echo 'instance_canal="'"${canal}"'"'
+ echo "# Fqdn interne"
+ echo 'instance_fqdn_interne="'"${fqdn_interne}"'"'
+ echo "# Fqdn externe"
+ echo 'instance_fqdn_externe="'"${fqdn_externe}"'"'
+ echo "# ALLO Serveur"
+ echo 'allo_serveur_url="allo_serveur"'
+ echo "# Type de données acceptées"
+ echo 'response_accept="Accept: application/json"'
+ echo "# Type de données envoyées"
+ echo 'request_type="Content-Type: application/json"'
+ echo "# Logs"
+ echo 'log_file="allo_agent.log"'
+} >> $configuration
echo 'Initialisation de ALLO réussie !'
# FICHIER DE CONFIGURATION
source ./allo_agent.conf
+# VÉRIFICATION DE L'ATTRIBUTION DES VARIABLES
+verification=true
+if [ -z "${log_file}" ]
+then
+ verification=false
+ echo "Configuration incomplète, merci de vérifier les paramètres."
+fi
+
# CLEAN DES LOGS
if [ -e "${log_file}" ]
then
#echo "$(cat response.json)" 2>&1 | tee -a $log_file
# VALIDATION DU JSON (nécessite outil de validation json)
- isJSONCorrupted=$(cat response.json | module/json -nq)
+ isJSONCorrupted=$(module/json -nq response.json)
# SI LA VARIABLE EST INITIALISEE MAIS VIDE => PAS D'ERREUR
if [[ -z $isJSONCorrupted && ${isJSONCorrupted+x} ]]
disques=$(blkid /dev/sd* | sed 's/\"//g')
# SYSTEME D'EXPLOITATION
- systeme=$(cat /etc/issue | sed 's/\\n\ \\l//g')
+ systeme=$(sed 's/\\n\ \\l//g' /etc/issue)
# AJOUT DE LA REFERENCE PRODUIT (nécessite package jq)
jq '. + { "reference": "'"${instance_reference}"'" }' response.json > tmp1.json
curl --cert bma.pem --key bma.key -X POST -H "${request_type}" --data-binary "@request.json" -i "https://${allo_serveur_url}/?action=upload_info" --output "response_server" 2> /dev/null
if [ -e ./response_server ]
then
- echo "$(cat response_server)" 2>&1 | tee -a $log_file
+ tee response_server -a "$log_file" 2>&1
else
- echo "Aucune réponse du serveur !" 2>&1 | tee -a $log_file
+ echo "Aucune réponse du serveur !" 2>&1 | tee -a "$log_file"
fi
rm response*
rm request.json
rm tmp*.json
else
- echo "Les données récupérées sont illisibles" 2>&1 | tee -a $log_file
+ echo "Les données récupérées sont illisibles" 2>&1 | tee -a "$log_file"
fi
else
- echo "L'application a renvoyé une erreur : " 2>&1 | tee -a $log_file
+ echo "L'application a renvoyé une erreur : " 2>&1 | tee -a "$log_file"
case "${code}" in
"500")
- echo "Erreur interne du serveur" 2>&1 | tee -a $log_file
+ echo "Erreur interne du serveur" 2>&1 | tee -a "$log_file"
;;
"400" | "404")
- echo "Mauvaise requete" 2>&1 | tee -a $log_file
+ echo "Mauvaise requete" 2>&1 | tee -a "$log_file"
;;
"403")
- echo "Accès refusé" 2>&1 | tee -a $log_file
+ echo "Accès refusé" 2>&1 | tee -a "$log_file"
;;
*)
- echo "Aucune réponse de l'application" 2>&1 | tee -a $log_file
+ echo "Aucune réponse de l'application" 2>&1 | tee -a "$log_file"
;;
esac
fi
--- /dev/null
+<?php
+
+ require_once('protected/required.php');
+
+ class PdoApplianceManager extends AbstractPdoManager {
+
+ public function createAppliance($appliance) {
+
+ $query = $this -> pdo -> prepare(
+ 'INSERT INTO appliances (
+ product,
+ manager,
+ reference,
+ changelog,
+ maintained,
+ internal_fqdn,
+ external_fqdn,
+ os,
+ disc_infos,
+ channel
+ ) VALUES (
+ :product,
+ :manager,
+ :reference,
+ :changelog,
+ :maintained,
+ :internal_fqdn,
+ :external_fqdn,
+ :os,
+ :disc_infos,
+ :channel
+ )'
+ );
+ $query -> bindValue(':product', $appliance -> getProduct());
+ $query -> bindValue(':manager', $appliance -> getManager());
+ $query -> bindValue(':reference', $appliance -> getReference());
+ $query -> bindValue(':changelog', $appliance -> getChangelog());
+ $query -> bindValue(':maintained', $appliance -> isMaintained());
+ $query -> bindValue(':internal_fqdn', $appliance -> getInternalFqdn());
+ $query -> bindValue(':external_fqdn', $appliance -> getExternalFqdn());
+ $query -> bindValue(':os', $appliance -> getOs());
+ $query -> bindValue(':disc_infos', $appliance -> getDiscInfos());
+ $query -> bindValue(':channel', $appliance -> getChannel());
+ $query -> execute();
+ $query -> closeCursor();
+
+ }
+
+ public function updateAppliance($appliance) {
+
+ $query = $this -> pdo -> prepare(
+ 'UPDATE appliances
+ SET product = :product,
+ manager = :manager,
+ reference = :reference,
+ changelog = :changelog,
+ maintained = :maintained,
+ internal_fqdn = :internal_fqdn,
+ external_fqdn = :external_fqdn,
+ os = :os,
+ disc_infos = :disc_infos,
+ channel = :channel
+ WHERE id = :id'
+ );
+ $query -> bindValue(':id', $appliance -> getId());
+ $query -> bindValue(':product', $appliance -> getProduct());
+ $query -> bindValue(':manager', $appliance -> getManager());
+ $query -> bindValue(':reference', $appliance -> getReference());
+ $query -> bindValue(':changelog', $appliance -> getChangelog());
+ $query -> bindValue(':maintained', $appliance -> isMaintained());
+ $query -> bindValue(':internal_fqdn', $appliance -> getFqdnInterne());
+ $query -> bindValue(':external_fqdn', $appliance -> getFqdnExterne());
+ $query -> bindValue(':os', $appliance -> getOs());
+ $query -> bindValue(':disc_infos', $appliance -> getDiscInfos());
+ $query -> bindValue(':channel', $appliance -> getChannel());
+ $query -> execute();
+ $query -> closeCursor();
+ }
+
+ public function updateApplianceInfos($array) {
+ $appliance = $this -> getApplianceByReference($array['reference']);
+
+ // IF APPLIANCE EXISTS
+ if(isset($appliance) && $appliance -> getId() > 0) {
+
+ // IF APPLIANCE IS MAINTAINED
+ if(!$appliance -> isMaintained()) {
+ echo "Votre application n'est plus maintainue par nos services, merci de vous renseigner auprès de votre contact ADULLACT Projet pour plus d'informations.";
+ } else {
+
+ // IN CASE OF MANAGER
+ if($array['usager_type'] === "exploitant") {
+
+ // GETTING MANAGER OF APPLIANCE
+ $managerManager = new PdoManagerManager();
+ $manager = $managerManager -> getManagerByAPId($appliance -> getManager());
+
+ // UPDATING ALL APPLIANCES OF THIS MANAGER
+ $array['usager_type'] = "client";
+ $appliances_id = $manager -> getAppliances();
+ foreach ($appliances_id as $appliance_id) {
+ $array['reference'] = $this -> getAppliance($appliance_id) -> getReference();
+ $this -> updateApplianceInfos($array);
+ }
+
+ // IN CASE OF CUSTOMER
+ } else if($array['usager_type'] === "client") {
+
+ // CHECKING APPLIANCE NAME
+ if ($array['produit'] === $appliance -> getProduct()) {
+
+ // IF VERSION DIFFERS FROM DB
+ // TO-DO : GET CURRENT VERSION OF APPLIANCE VIA CHANGELOG
+ //if($array['version'] != $appliance -> getVersion()) {
+
+ // GETTING PDO MANAGERS
+ $versionManager = new PdoVersionManager();
+ $productManager = new PdoProductManager();
+ $warningManager = new PdoWarningManager();
+
+ // GETTING VERSION ID
+ $version_id = $versionManager -> getIdByValueAndProductId($array['version'], $productManager->getProductByName($array['produit'])->getId());
+
+ // NEW WARNING CREATION, VERSION TYPE
+ $warningMessage = "Version declaree ".$array['version']." sans mise à jour par ALLO.";
+ $warning = new Warning(null, null, "version", $warningMessage, $version_id);
+ $warningManager -> createWarning($warning);
+
+ // SENDING MAIL TO ADMIN
+ $to = 'david.calmel@adullact-projet.coop';
+ $subject = 'ALLO - Nouvelle warning';
+ $message = $warningMessage;
+ $headers = 'From: ne-pas-repondre@allo-serveur';
+ mail($to, $subject, $message, $headers);
+
+ // GETTING CHANGELOG OF APPLIANCE
+ $changelogManager = new PdoChangelogManager();
+ $changelog = $changelogManager -> getChangelog($appliance -> getChangelog());
+
+ // IF CHANGELOG EXISTS, ADDING NEW WARNING TO IT
+ if(isset($changelog) && $changelog -> getId() > 0) {
+ $warnings = $changelog -> getWarnings();
+ if((array_search("", $warnings)) !== false) {
+ $warnings = array($warningManager -> getLastWarning() -> getId());
+ } else {
+ $warnings[] = $warningManager -> getLastWarning() -> getId();
+ }
+ $changelog -> setWarnings($warnings);
+ $changelogManager -> updateChangelog($changelog);
+
+ // IF CHANGELOG DOES NOT EXIST, CREATING NEW ONE
+ } else {
+ $changelog = new Changelog(null, array($warningManager -> getLastWarning() -> getId()), array(""));
+ $changelogManager -> createChangelog($changelog);
+ $appliance -> setChangelog($changelogManager -> getLastChangelog() -> getId());
+ $this -> updateAppliance($appliance);
+ }
+ //}
+
+ // USELESS ?
+ // UPDATING APPLIANCE INFORMATION
+ /*$query = $this -> pdo -> prepare(
+ 'UPDATE appliances SET version = :version WHERE reference = :reference'
+ );
+ $query -> bindValue(':reference', $array['reference']);
+ $query -> bindValue(':version', $array['version']);
+ $query -> execute();*/
+ } else {
+ echo "Le nom de l'instance applicative est incorrect";
+ }
+ } else {
+ echo "Le type d'usager est inconnu, merci de corriger la configuration.";
+ }
+ }
+
+ // IF APPLIANCE DOES NOT EXISTS
+ } else {
+
+ // GETTING PDO MANAGERS
+ $versionManager = new PdoVersionManager();
+ $productManager = new PdoProductManager();
+ $warningManager = new PdoWarningManager();
+
+ // GETTING PRODUCT ID
+ $product_id = $productManager->getProductByName($array['produit'])->getId();
+
+ // GETTING VERSION ID
+ $version_id = $versionManager->getIdByValueAndProductId($array['version'], $product_id);
+
+ // NEW WARNING CREATION, CREATION TYPE
+ $warning = new Warning(null, null, "creation",
+ "Nouvelle instance applicative declaree : ".$array['produit']." ; version : ".$array['version'], $version_id);
+ $warningManager -> createWarning($warning);
+
+ // NEW CHANGELOG CREATION
+ $changelogManager = new PdoChangelogManager();
+ $changelog = new Changelog(null, array($warningManager -> getLastWarning() -> getId()), array(""));
+ $changelogManager -> createChangelog($changelog);
+
+ // NEW APPLIANCE CREATION
+ // TO-DO : MANAGE APPLIANCE CREATION WITH MANAGER TYPE
+ $appliance = new Appliance(
+ // ID
+ null,
+ // PRODUCT
+ $product_id,
+ // MANAGER
+ null,
+ // REFERENCE
+ $array['reference'],
+ // CHANGELOG
+ $changelogManager -> getLastChangelog() -> getId(),
+ // IS MAINTAINED
+ true,
+ // FQDNs
+ $array['fqdn_interne'],
+ $array['fqdn_externe'],
+ // OS
+ $array['systeme'],
+ // UUIDs
+ $array['disques'],
+ // CHANNEL
+ $array['canal']
+ );
+ $this->createAppliance($appliance);
+ }
+
+
+ }
+
+ public function getAppliance($id) {
+
+ $query = $this -> pdo -> prepare('SELECT * FROM appliances WHERE id = :id');
+ $query -> bindValue(':id', $id);
+ $query -> execute();
+
+ $result = $query -> fetch(PDO::FETCH_ASSOC);
+ $appliance = new Appliance(
+ $result['id'],
+ $result['product'],
+ $result['manager'],
+ $result['reference'],
+ $result['changelog'],
+ $result['maintained'],
+ $result['internal_fqdn'],
+ $result['external_fqdn'],
+ $result['os'],
+ $result['disc_infos'],
+ $result['channel']
+ );
+
+ $query->closeCursor();
+
+ return $appliance;
+ }
+
+ public function getApplianceByReference($reference) {
+
+ $query = $this -> pdo -> prepare('SELECT * FROM appliances WHERE reference = :reference');
+ $query -> bindValue(':reference', $reference);
+ $query -> execute();
+
+ $result = $query -> fetch(PDO::FETCH_ASSOC);
+ $appliance = new Appliance(
+ $result['id'],
+ $result['product'],
+ $result['manager'],
+ $result['reference'],
+ $result['changelog'],
+ $result['maintained'],
+ $result['internal_fqdn'],
+ $result['external_fqdn'],
+ $result['os'],
+ $result['disc_infos'],
+ $result['channel']
+ );
+
+ $query->closeCursor();
+
+ return $appliance;
+ }
+
+ public function getAppliances() {
+
+ $query = $this -> pdo -> prepare('SELECT * FROM appliances');
+ $query -> execute();
+
+ $results = $query -> fetchAll(PDO::FETCH_ASSOC);
+ $appliances = array();
+ foreach ($results as $result) {
+ $appliances[] = new Appliance(
+ $result['id'],
+ $result['product'],
+ $result['manager'],
+ $result['reference'],
+ $result['changelog'],
+ $result['maintained'],
+ $result['internal_fqdn'],
+ $result['external_fqdn'],
+ $result['os'],
+ $result['disc_infos'],
+ $result['channel']
+ );
+ }
+
+ $query->closeCursor();
+
+ return $appliances;
+ }
+
+ public function removeAppliance($appliance) {
+
+ $query = $this -> pdo -> prepare('DELETE FROM appliances WHERE id = :id');
+ $query -> bindValue('id', $appliance -> getId());
+ $query -> execute();
+
+ }
+
+ public function checkUploadInfoValidity($array) {
+
+ // CHECKING REFERENCE FORMAT
+ $regex = '#^[A-Z]{2}/[A-Z0-9]+_[0-9]{5}_[0-9]{10}$#';
+ if (preg_match($regex, $array['reference'])) {
+
+ // CHECKING PRODUCT EXISTENCE
+ $productManager = new PdoProductManager();
+ $products = $productManager -> getNamesOfProducts();
+ if(in_array($array['produit'], $products)) {
+
+ // CHECKING VERSION VALIDITY
+ $versionManager = new PdoVersionManager();
+ $versions = $versionManager->findValuesOfVersionsByProductId($productManager->getProductByName($array['produit'])->getId());
+ if(in_array($array['version'], $versions)) {
+ $returnMsg = "ok";
+ } else {
+ $returnMsg = "Cette version n'est pas disponible pour ce produit";
+ }
+ } else {
+ $returnMsg = "Le produit n'est pas valide";
+ }
+ } else {
+ $returnMsg = 'Le format de la référence est incorrect.';
+ }
+ return $returnMsg;
+ }
+
+ public function disableMaintainedById($id) {
+ $query = $this -> pdo -> prepare(
+ 'UPDATE appliances SET maintained = :maintained WHERE id = :id'
+ );
+ $query -> bindValue(':id', $id);
+ $query -> bindValue(':maintained', false);
+ $query -> execute();
+ $query -> closeCursor();
+ }
+ }
+
--- /dev/null
+<?php
+
+ require_once('protected/required.php');
+
+ class PdoChangelogManager extends AbstractPdoManager {
+
+ public function createChangelog($changelog) {
+
+ $query = $this -> pdo -> prepare(
+ 'INSERT INTO changelogs (warnings, versions) VALUES (:warnings, :versions)'
+ );
+ $query -> bindValue(':warnings', implode("|", $changelog -> getWarnings()));
+ $query -> bindValue(':versions', implode("|", $changelog -> getVersions()));
+ $query -> execute();
+ $query -> closeCursor();
+ }
+
+ public function updateChangelog($changelog) {
+
+ $query = $this -> pdo -> prepare(
+ 'UPDATE changelogs SET
+ warnings = :warnings,
+ versions = :versions
+ WHERE id = :id'
+ );
+ $query -> bindValue(':id', $changelog -> getId());
+ $query -> bindValue(':warnings', implode("|", $changelog -> getWarnings()));
+ $query -> bindValue(':versions', implode("|", $changelog -> getVersions()));
+ $query -> execute();
+ $query -> closeCursor();
+ }
+
+ public function getChangelog($id) {
+
+ $query = $this -> pdo -> prepare('SELECT * FROM changelogs WHERE id = :id');
+ $query -> bindValue(':id', $id);
+ $query -> execute();
+
+ $result = $query -> fetch(PDO::FETCH_ASSOC);
+ $changelog = new Changelog($result['id'], explode("|", $result['warnings']), explode("|", $result['versions']));
+
+ $query->closeCursor();
+
+ return $changelog;
+ }
+
+ public function getLastChangelog() {
+
+ $query = $this -> pdo -> prepare('SELECT * FROM changelogs WHERE id = LAST_INSERT_ID()');
+ $query -> execute();
+
+ $result = $query -> fetch(PDO::FETCH_ASSOC);
+ $changelog = new Changelog($result['id'], explode("|", $result['warnings']), explode("|", $result['versions']));
+
+ $query->closeCursor();
+
+ return $changelog;
+ }
+
+ public function getChangelogs() {
+
+ $query = $this -> pdo -> prepare('SELECT * FROM changelogs');
+ $query -> execute();
+
+ $results = $query -> fetchAll(PDO::FETCH_ASSOC);
+ $changelogs = array();
+ foreach ($results as $result) {
+ $changelogs[] = new Changelog($result['id'], explode("|", $result['warnings']), explode("|", $result['versions']));
+ }
+
+ $query->closeCursor();
+
+ return $changelogs;
+ }
+
+ public function removeChangelog($changelog) {
+
+ $query = $this -> pdo -> prepare('DELETE FROM changelog WHERE id = :id');
+ $query -> bindValue('id', $changelog -> getId());
+ $query -> execute();
+
+ }
+
+ public function findLastVersion() {
+
+ $query = $this -> pdo -> prepare('SELECT versions FROM changelogs');
+ $query -> execute();
+
+ // GETTING LAST DECLARED VERSION ID
+ $lastVersionId = null;
+ $results = $query -> fetchAll(PDO::FETCH_ASSOC);
+ foreach ($results as $result) {
+ $versionArray = explode(';',$result['versions']);
+ $versionId = $versionArray[0];
+ $versionDeclaration = $versionArray[1];
+ if(!isset($lastVersionDeclaration) || $versionDeclaration > $lastVersionDeclaration) {
+ $lastVersionDeclaration = $versionDeclaration;
+ $lastVersionId = $versionId;
+ }
+ }
+ $query->closeCursor();
+
+ // GETTING VERSION
+ $versionManager = new PdoVersionManager();
+ if(isset($lastVersionId)) {
+ $version = $versionManager->getVersion($lastVersionId);
+ } else {
+ $version = new Version();
+ }
+ return $version;
+ }
+
+ public function findLastVersionDeclaration() {
+
+ $query = $this -> pdo -> prepare('SELECT versions FROM changelogs');
+ $query -> execute();
+
+ // GETTING LAST VERSION DECLARATION
+ $lastVersionDeclaration = null;
+ $results = $query -> fetchAll(PDO::FETCH_ASSOC);
+ foreach ($results as $result) {
+ $versionArray = explode(';',$result['versions']);
+ $versionDeclaration = $versionArray[1];
+ if(!isset($lastVersionDeclaration) || $versionDeclaration > $lastVersionDeclaration) {
+ $lastVersionDeclaration = $versionDeclaration;
+ }
+ }
+ $query->closeCursor();
+
+ return $lastVersionDeclaration;
+ }
+
+ }
+
--- /dev/null
+<?php
+
+ require_once('protected/required.php');
+
+ class PdoCustomerManager extends AbstractPdoManager {
+
+ public function createCustomer($customer) {
+
+ $query = $this -> pdo -> prepare(
+ 'INSERT INTO customers (
+ ap_id,
+ name
+ ) VALUES (
+ :ap_id,
+ :name
+ );'
+ );
+ $query -> bindValue(':ap_id', $customer -> getAPId());
+ $query -> bindValue(':name', $customer -> getName());
+ $query -> execute();
+ }
+
+ public function updateCustomer($customer) {
+
+ $query = $this -> pdo -> prepare(
+ 'UPDATE customers
+ SET ap_id = :ap_id,
+ name = :name
+ WHERE id = :id'
+ );
+ $query -> bindValue(':id', $customer -> getId());
+ $query -> bindValue(':ap_id', $customer -> getAPId());
+ $query -> bindValue(':name', $customer -> getName());
+ $query -> execute();
+ }
+
+ public function getCustomer($id) {
+
+ $query = $this -> pdo -> prepare('SELECT * FROM customers WHERE id = :id');
+ $query -> bindValue(':id', $id);
+ $query -> execute();
+
+ $result = $query -> fetch(PDO::FETCH_ASSOC);
+ $customer = new Customer($result['id'], $result['ap_id'], $result['name']);
+
+ $query->closeCursor();
+
+ return $customer;
+ }
+
+ public function getCustomerByAPId($identifiantAP) {
+
+ $query = $this -> pdo -> prepare('SELECT * FROM customers WHERE ap_id = :ap_id');
+ $query -> bindValue(':ap_id', $identifiantAP);
+ $query -> execute();
+
+ $result = $query -> fetch(PDO::FETCH_ASSOC);
+ $customer = new Customer($result['id'], $result['ap_id'], $result['name']);
+
+ $query->closeCursor();
+
+ return $customer;
+ }
+
+ public function getCustomers() {
+
+ $query = $this -> pdo -> prepare('SELECT * FROM customers');
+ $query -> execute();
+
+ $results = $query -> fetchAll(PDO::FETCH_ASSOC);
+ $customers = array();
+ foreach ($results as $result) {
+ $customers[] = new Customer($result['id'], $result['ap_id'], $result['name']);
+ }
+
+ $query->closeCursor();
+
+ return $customers;
+ }
+
+ public function removeCustomer($customer) {
+
+ $query = $this -> pdo -> prepare('DELETE FROM customers WHERE id = :id');
+ $query -> bindValue('id', $customer -> getId());
+ $query -> execute();
+ }
+
+ }
+
--- /dev/null
+<?php
+
+ require_once('protected/required.php');
+
+ class PdoManagerManager extends AbstractPdoManager {
+
+ public function createManager($manager) {
+
+ $query = $this -> pdo -> prepare(
+ 'INSERT INTO managers (name, ap_id, appliances) VALUES (:name, :ap_id, :appliances)'
+ );
+ $query -> bindValue(':name', $manager -> getName());
+ $query -> bindValue(':ap_id', $manager -> getAPId());
+ $query -> bindValue(':appliances', implode("|", $manager -> getAppliances()));
+ $query -> execute();
+ $query -> closeCursor();
+
+ }
+
+ public function updateManager($manager) {
+
+ $query = $this -> pdo -> prepare(
+ 'UPDATE managers SET name = :name, ap_id = :ap_id, appliances = :appliances WHERE id = :id'
+ );
+ $query -> bindValue(':id', $manager -> getId());
+ $query -> bindValue(':name', $manager -> getName());
+ $query -> bindValue(':ap_id', $manager -> getAPId());
+ $query -> bindValue(':appliances', implode("|", $manager -> getAppliances()));
+ $query -> execute();
+ $query -> closeCursor();
+ }
+
+ public function getManager($id) {
+
+ $query = $this -> pdo -> prepare('SELECT * FROM managers WHERE id = :id');
+ $query -> bindValue(':id', $id);
+ $query -> execute();
+
+ $result = $query -> fetch(PDO::FETCH_ASSOC);
+ $manager = new Manager($result['id'], $result['name'], $result['ap_id'], explode("|", $result['appliances']));
+
+ $query->closeCursor();
+
+ return $manager;
+ }
+
+ public function getManagers() {
+
+ $query = $this -> pdo -> prepare('SELECT * FROM managers');
+ $query -> execute();
+
+ $results = $query -> fetchAll(PDO::FETCH_ASSOC);
+ $managers = array();
+ foreach ($results as $result) {
+ $managers[] = new Manager($result['id'], $result['name'], $result['ap_id'], explode("|", $result['appliances']));
+ }
+
+ $query->closeCursor();
+
+ return $managers;
+ }
+
+ public function getManagerByAp_id($ap_id) {
+
+ $query = $this -> pdo -> prepare('SELECT * FROM managers WHERE ap_id = :ap_id');
+ $query -> bindValue(':ap_id', $ap_id);
+ $query -> execute();
+
+ $result = $query -> fetch(PDO::FETCH_ASSOC);
+ $manager = new Manager($result['id'], $result['name'], $result['ap_id'], explode("|", $result['appliances']));
+
+ $query->closeCursor();
+
+ return $manager;
+ }
+
+ public function removeManager($manager) {
+
+ $query = $this -> pdo -> prepare('DELETE FROM manager WHERE id = :id');
+ $query -> bindValue('id', $manager -> getId());
+ $query -> execute();
+
+ }
+
+ }
+
+?>
--- /dev/null
+<?php
+
+ require_once('protected/required.php');
+
+ class PdoProductManager extends AbstractPdoManager {
+
+ public function createProduct($product) {
+
+ $query = $this -> pdo -> prepare(
+ 'INSERT INTO products (name) VALUES (:name);'
+ );
+ $query -> bindValue(':name', $product -> getName());
+ $query -> execute();
+ }
+
+ public function updateProduct($product) {
+
+ $query = $this -> pdo -> prepare(
+ 'UPDATE products
+ SET name = :name
+ WHERE id = :id'
+ );
+ $query -> bindValue(':id', $product -> getId());
+ $query -> bindValue(':name', $product -> getName());
+ $query -> execute();
+ }
+
+ public function getProduct($id) {
+
+ $query = $this -> pdo -> prepare('SELECT * FROM products WHERE id = :id');
+ $query -> bindValue(':id', $id);
+ $query -> execute();
+
+ $result = $query -> fetch(PDO::FETCH_ASSOC);
+ $product = new Product($result['id'], $result['name']);
+
+ $query->closeCursor();
+
+ return $product;
+ }
+
+ public function getProductByName($name) {
+
+ $query = $this -> pdo -> prepare('SELECT * FROM products WHERE name = :name');
+ $query -> bindValue(':name', $name);
+ $query -> execute();
+
+ $result = $query -> fetch(PDO::FETCH_ASSOC);
+ $product = new Product($result['id'], $result['name']);
+
+ $query->closeCursor();
+
+ return $product;
+ }
+
+ public function getProducts() {
+
+ $query = $this -> pdo -> prepare('SELECT * FROM products');
+ $query -> execute();
+
+ $results = $query -> fetchAll(PDO::FETCH_ASSOC);
+ $products = array();
+ foreach ($results as $result) {
+ $products[] = new Product($result['id'], $result['name']);
+ }
+
+ $query->closeCursor();
+
+ return $products;
+ }
+
+ public function getNamesOfProducts() {
+
+ $query = $this -> pdo -> prepare('SELECT name FROM products');
+ $query -> execute();
+
+ $results = $query -> fetchAll(PDO::FETCH_ASSOC);
+ $names = array();
+ foreach ($results as $result) {
+ $names[] = $result['name'];
+ }
+
+ $query->closeCursor();
+
+ return $names;
+ }
+
+ public function removeProduct($product) {
+
+ $query = $this -> pdo -> prepare('DELETE FROM products WHERE id = :id');
+ $query -> bindValue('id', $product -> getId());
+ $query -> execute();
+ }
+
+ }
+
+?>
public function createVersion($version) {
$query = $this -> pdo -> prepare(
- 'INSERT INTO versions (valeur, produit, nature) VALUES (:valeur, :produit, :nature);'
+ 'INSERT INTO versions (value, product, nature) VALUES (:value, :product, :nature);'
);
- $query -> bindValue(':valeur', $version -> getValeur());
- $query -> bindValue(':produit', $version -> getProduit());
+ $query -> bindValue(':value', $version -> getValue());
+ $query -> bindValue(':product', $version -> getProduct());
$query -> bindValue(':nature', $version -> getNature());
$query -> execute();
}
$query = $this -> pdo -> prepare(
'UPDATE versions
- SET valeur = :valeur,
- produit = :produit,
+ SET value = :value,
+ product = :product,
nature = :nature
WHERE id = :id'
);
$query -> bindValue(':id', $version -> getId());
- $query -> bindValue(':valeur', $version -> getValeur());
- $query -> bindValue(':produit', $version -> getProduit());
+ $query -> bindValue(':value', $version -> getValue());
+ $query -> bindValue(':product', $version -> getProduct());
$query -> bindValue(':nature', $version -> getNature());
$query -> execute();
}
$query -> execute();
$result = $query -> fetch(PDO::FETCH_ASSOC);
- $version = new Version($result['id'], $result['valeur'], $result['produit'], $result['nature']);
+ $version = new Version($result['id'], $result['value'], $result['product'], $result['nature']);
$query->closeCursor();
$results = $query -> fetchAll(PDO::FETCH_ASSOC);
$versions = array();
foreach ($results as $result) {
- $versions[] = new Version($result['id'], $result['valeur'], $result['produit'], $result['nature']);
+ $versions[] = new Version($result['id'], $result['value'], $result['product'], $result['nature']);
}
$query->closeCursor();
return $versions;
}
- public function findValeursOfVersionsByProduitId($produit_id) {
+ public function findValuesOfVersionsByProductId($product_id) {
- $query = $this -> pdo -> prepare('SELECT valeur FROM versions WHERE produit = :produit');
- $query -> bindValue('produit', $produit_id);
+ $query = $this -> pdo -> prepare('SELECT value FROM versions WHERE product = :product');
+ $query -> bindValue('product', $product_id);
$query -> execute();
$results = $query -> fetchAll(PDO::FETCH_ASSOC);
- $valeurs = array();
+ $values = array();
foreach ($results as $result) {
- $valeurs[] = $result['valeur'];
+ $values[] = $result['value'];
}
$query->closeCursor();
- return $valeurs;
+ return $values;
}
- public function getIdByValeurAndProduitId($valeur, $produit_id) {
+ public function getIdByValueAndProductId($value, $product_id) {
- $query = $this -> pdo -> prepare('SELECT * FROM versions WHERE valeur = :valeur AND produit = :produit');
- $query -> bindValue('valeur', $valeur);
- $query -> bindValue('produit', $produit_id);
+ $query = $this -> pdo -> prepare('SELECT * FROM versions WHERE value = :value AND product = :product');
+ $query -> bindValue('value', $value);
+ $query -> bindValue('product', $product_id);
$query -> execute();
$result = $query -> fetch(PDO::FETCH_ASSOC);
}
}
-
-?>
--- /dev/null
+<?php
+
+ require_once('protected/required.php');
+
+ class PdoWarningManager extends AbstractPdoManager {
+
+ public function createWarning($warning) {
+
+ $query = $this -> pdo -> prepare(
+ 'INSERT INTO warnings (creation, nature, message, version) VALUES (NOW(), :nature, :message, :version);'
+ );
+ $query -> bindValue(':nature', $warning -> getNature());
+ $query -> bindValue(':message', $warning -> getMessage());
+ $query -> bindValue(':version', $warning -> getVersion());
+ $query -> execute();
+ }
+
+ public function updateWarning($warning) {
+
+ $query = $this -> pdo -> prepare(
+ 'UPDATE warnings
+ SET creation = :creation,
+ nature = :nature,
+ message = :message,
+ version = :version
+ WHERE id = :id'
+ );
+ $query -> bindValue(':id', $warning -> getId());
+ $query -> bindValue(':creation', $warning -> getCreation());
+ $query -> bindValue(':nature', $warning -> getNature());
+ $query -> bindValue(':message', $warning -> getMessage());
+ $query -> bindValue(':version', $warning -> getVersion());
+ $query -> execute();
+ }
+
+ public function getWarning($id) {
+
+ $query = $this -> pdo -> prepare('SELECT * FROM warnings WHERE id = :id');
+ $query -> bindValue(':id', $id);
+ $query -> execute();
+
+ $result = $query -> fetch(PDO::FETCH_ASSOC);
+ $warning = new Warning($result['id'], $result['creation'], $result['nature'], $result['message'], $result['version']);
+
+ $query->closeCursor();
+
+ return $warning;
+ }
+
+ public function getLastWarning() {
+
+ $query = $this -> pdo -> prepare('SELECT * FROM warnings WHERE id = LAST_INSERT_ID()');
+ $query -> execute();
+
+ $result = $query -> fetch(PDO::FETCH_ASSOC);
+ $warning = new Warning($result['id'], $result['creation'], $result['nature'], $result['message'], $result['version']);
+
+ $query->closeCursor();
+
+ return $warning;
+ }
+
+ public function getWarnings() {
+
+ $query = $this -> pdo -> prepare('SELECT * FROM warnings');
+ $query -> execute();
+
+ $results = $query -> fetchAll(PDO::FETCH_ASSOC);
+ $warnings = array();
+ foreach ($results as $result) {
+ $warnings[] = new Warning($result['id'], $result['creation'], $result['nature'], $result['message'], $result['version']);
+ }
+
+ $query->closeCursor();
+
+ return $warnings;
+ }
+
+ public function removeWarning($warning) {
+
+ $query = $this -> pdo -> prepare('DELETE FROM warnings WHERE id = :id');
+ $query -> bindValue('id', $warning -> getId());
+ $query -> execute();
+ }
+
+ }
--- /dev/null
+<?php
+
+ require_once('protected/required.php');
+
+ class Appliance {
+
+ protected $id, $product, $manager, $reference, $changelog, $maintained, $internalFqdn, $externalFqdn, $os, $discInfos, $channel;
+
+ /// CONSTRUCTOR
+ function __construct($id = null, $product = null, $manager = null, $reference = null, $changelog = null,
+ $maintained = null, $internalFqdn = null, $externalFqdn = null, $os = null, $discInfos = null, $channel = null) {
+
+ $this -> id = $id;
+ $this -> product = $product;
+ // MANAGER REFERENCE
+ $this -> manager = $manager;
+ // APPLIANCE REFERENCE
+ $this -> reference = $reference;
+ // CHANGELOG ID
+ $this -> changelog = $changelog;
+ // APPLIANCE MAINTENANCE STATE
+ $this -> maintained = $maintained;
+ // FQDNs
+ $this -> internalFqdn = $internalFqdn;
+ $this -> externalFqdn = $externalFqdn;
+ // OS
+ $this -> os = $os;
+ // UUIDS
+ $this -> discInfos = $discInfos;
+ // CHANNEL
+ $this -> channel = $channel;
+ }
+
+ public function getJSON() {
+ return json_encode(get_object_vars($this));
+ }
+
+ public function getJSONP() {
+ $array["id"] = $this -> id;
+ $array["product"] = $this -> product;
+ $array["manager"] = $this -> manager;
+ $array["reference"] = $this -> reference;
+ $array["changelog"] = $this -> changelog;
+ $array["maintained"] = $this -> maintained;
+ $array["internalFqdn"] = $this -> internalFqdn;
+ $array["externalFqdn"] = $this -> externalFqdn;
+ $array["os"] = $this -> os;
+ $array["discInfos"] = $this -> discInfos;
+ $array["channel"] = $this -> channel;
+
+ return json_encode($array);
+ }
+
+ /// GETTERS
+ public function getId() { return $this -> id; }
+ public function getProduct() { return $this->product; }
+ public function getManager() { return $this->manager; }
+ public function getReference() { return $this->reference; }
+ public function getChangelog() { return $this->changelog; }
+ public function isMaintained() { return $this->maintained; }
+ public function getInternalFqdn() { return $this->internalFqdn; }
+ public function getExternalFqdn() { return $this->externalFqdn; }
+ public function getOs() { return $this->os; }
+ public function getDiscInfos() { return $this->discInfos; }
+ public function getChannel() { return $this->channel; }
+
+ /// SETTERS
+ public function setId($id) { $this -> id = $id; }
+ public function setProduct($product) { $this->product = $product; }
+ public function setManager($manager) { $this->manager = $manager; }
+ public function setReference($reference) { $this->reference = $reference; }
+ public function setChangelog($changelog) { $this->changelog = $changelog; }
+ public function setMaintained($maintained) { $this->maintained = $maintained; }
+ public function setInternalFqdn($internalFqdn) { $this->internalFqdn = $internalFqdn; }
+ public function setExternalFqdn($externalFqdn) { $this->externalFqdn = $externalFqdn; }
+ public function setOs($os) { $this->os = $os; }
+ public function setDiscinfos($discInfos) { $this->discInfos = $discInfos; }
+ public function setChannel($channel) { $this->channel = $channel; }
+
+ }
+
+?>
\ No newline at end of file
--- /dev/null
+<?php
+
+ require_once('protected/required.php');
+
+ class Changelog {
+
+ protected $id, $warnings, $versions;
+
+ /// CONSTRUCTOR
+ function __construct($id = null, $warnings = null, $versions = null) {
+
+ $this -> id = $id;
+ $this -> warnings = $warnings;
+ $this -> versions = $versions;
+
+ }
+
+ public function getJSON() {
+ return json_encode(get_object_vars($this));
+ }
+
+ public function getJSONP() {
+ $array["id"] = $this -> id;
+ $array["warnings"] = $this -> warnings;
+ $array["versions"] = $this -> versions;
+
+ return json_encode($array);
+ }
+
+ /// GETTERS
+ public function getId() { return $this -> id; }
+ public function getWarnings() { return $this->warnings; }
+ public function getVersions() { return $this->versions; }
+
+ /// SETTERS
+ public function setId($id) { $this -> id = $id; }
+ public function setWarnings($warnings) { $this->warnings = $warnings; }
+ public function setVersions($versions) { $this->versions = $versions; }
+
+ }
--- /dev/null
+<?php
+
+ require_once('protected/required.php');
+
+ class Customer {
+
+ protected $id, $APId, $name;
+
+ /// CONSTRUCTOR
+ function __construct($id = null, $APId = null, $name = null) {
+
+ $this -> id = $id;
+ $this -> APId = $APId;
+ $this -> name = $name;
+
+ }
+
+ public function getJSON() {
+ return json_encode(get_object_vars($this));
+ }
+
+ public function getJSONP() {
+ $array["id"] = $this -> id;
+ $array["aPId"] = $this -> APId;
+ $array["name"] = $this -> name;
+
+ return json_encode($array);
+ }
+
+ /// GETTERS
+ public function getId() { return $this -> id; }
+ public function getAPId() { return $this->APId; }
+ public function getName() { return $this->name; }
+
+ /// SETTERS
+ public function setId($id) { $this -> id = $id; }
+ public function setAPId($APId) { $this->APId = $APId; }
+ public function setName($name) { $this->name = $name; }
+
+ }
+
+?>
\ No newline at end of file
--- /dev/null
+<?php
+
+ require_once('protected/required.php');
+
+ class Manager {
+
+ protected $id, $name, $APId, $appliances;
+
+ /// CONSTRUCTOR
+ function __construct($id = null, $name = null, $APId = null, $appliances = null) {
+
+ $this -> id = $id;
+ $this -> name = $name;
+ $this -> APId = $APId;
+ $this -> appliances = $appliances;
+
+ }
+
+ public function getJSON() {
+ return json_encode(get_object_vars($this));
+ }
+
+ public function getJSONP() {
+ $array["id"] = $this -> id;
+ $array["name"] = $this -> name;
+ $array["APId"] = $this -> APId;
+ $array["appliances"] = $this -> appliances;
+
+ return json_encode($array);
+ }
+
+ /// GETTERS
+ public function getId() { return $this -> id; }
+ public function getName() { return $this->name; }
+ public function getAPId() { return $this->APId; }
+ public function getAppliances() { return $this->appliances; }
+
+ /// SETTERS
+ public function setId($id) { $this -> id = $id; }
+ public function setName($name) { $this->name = $name; }
+ public function setAPId($APId) { $this->APId = $APId; }
+ public function setAppliances($appliances) { $this->appliances = $appliances; }
+
+ }
+
+?>
\ No newline at end of file
--- /dev/null
+<?php
+
+ require_once('protected/required.php');
+
+ class Product {
+
+ protected $id, $name;
+
+ /// CONSTRUCTOR
+ function __construct($id = null, $name = null) {
+
+ $this -> id = $id;
+ $this -> name = $name;
+
+ }
+
+ public function getJSON() {
+ return json_encode(get_object_vars($this));
+ }
+
+ public function getJSONP() {
+ $array["id"] = $this -> id;
+ $array["name"] = $this -> name;
+
+ return json_encode($array);
+ }
+
+ /// GETTERS
+ public function getId() { return $this -> id; }
+ public function getName() { return $this->name; }
+
+ /// SETTERS
+ public function setId($id) { $this -> id = $id; }
+ public function setName($name) { $this->name = $name; }
+
+ }
+
+?>
\ No newline at end of file
class Version {
- protected $id, $valeur, $produit, $nature;
+ protected $id, $value, $product, $nature;
/// CONSTRUCTOR
- function __construct($id = null, $valeur = null, $produit = null, $nature = null) {
+ function __construct($id = null, $value = null, $product = null, $nature = null) {
$this -> id = $id;
- $this -> valeur = $valeur;
- $this -> produit = $produit;
+ $this -> value = $value;
+ $this -> product = $product;
$this -> nature = $nature;
}
public function getJSONP() {
$array["id"] = $this -> id;
- $array["valeur"] = $this -> valeur;
- $array["produit"] = $this -> produit;
+ $array["value"] = $this -> value;
+ $array["product"] = $this -> product;
$array["nature"] = $this -> nature;
return json_encode($array);
/// GETTERS
public function getId() { return $this -> id; }
- public function getValeur() { return $this->valeur; }
- public function getProduit() { return $this->produit; }
+ public function getValue() { return $this->value; }
+ public function getProduct() { return $this->product; }
public function getNature() { return $this->nature; }
/// SETTERS
public function setId($id) { $this -> id = $id; }
- public function setValeur($valeur) { $this->valeur = $valeur; }
- public function setProduit($produit) { $this->produit = $produit; }
+ public function setValue($value) { $this->value = $value; }
+ public function setProduct($product) { $this->product = $product; }
public function setNature($nature) { $this->nature = $nature; }
}
--- /dev/null
+<?php
+
+ require_once('protected/required.php');
+
+ class Warning {
+
+ protected $id, $creation, $nature, $message, $version;
+
+ /// CONSTRUCTOR
+ function __construct($id = null, $creation = null, $nature = null, $message = null, $version = null) {
+
+ $this -> id = $id;
+ $this -> creation = $creation;
+ $this -> nature = $nature;
+ $this -> message = $message;
+ $this -> version = $version;
+
+ }
+
+ public function getJSON() {
+ return json_encode(get_object_vars($this));
+ }
+
+ public function getJSONP() {
+ $array["id"] = $this -> id;
+ $array["creation"] = $this -> creation;
+ $array["nature"] = $this -> nature;
+ $array["message"] = $this -> message;
+ $array["version"] = $this -> version;
+
+ return json_encode($array);
+ }
+
+ /// GETTERS
+ public function getId() { return $this -> id; }
+ public function getCreation() { return $this->creation; }
+ public function getNature() { return $this->nature; }
+ public function getMessage() { return $this->message; }
+ public function getVersion() { return $this->version; }
+
+ /// SETTERS
+ public function setId($id) { $this -> id = $id; }
+ public function setCreation($creation) { $this->creation = $creation; }
+ public function setNature($nature) { $this->nature = $nature; }
+ public function setMessage($message) { $this->message = $message; }
+ public function setVersion($version) { $this->version = $version; }
+
+ }
+
+?>
\ No newline at end of file
<?php\r
\r
+ // TO-DO : DECIDE TO DELETE THIS OR USE IT\r
function api_delete() {\r
$exploitantManager = new PdoExploitantManager();\r
$instanceManager = new PdoInstanceManager();\r
<?php\r
\r
function api_get() {\r
- $exploitantManager = new PdoExploitantManager();\r
- $clientManager = new PdoClientManager();\r
- $instanceManager = new PdoInstanceManager();\r
- $historiqueManager = new PdoHistoriqueManager();\r
- $alerteManager = new PdoAlerteManager();\r
+ $managerManager = new PdoManagerManager();\r
+ $customerManager = new PdoCustomerManager();\r
+ $applianceManager = new PdoApplianceManager();\r
+ $changelogManager = new PdoChangelogManager();\r
+ $warningManager = new PdoWarningManager();\r
$versionManager = new PdoVersionManager();\r
+ $productManager = new PdoProductManager();\r
\r
if($_GET['action']) {\r
switch ($_GET['action']) {\r
- case 'get_exploitant' :\r
- echo $exploitantManager -> getExploitant($_GET['id']) -> getJSONP();\r
+ case 'get_manager' :\r
+ echo $managerManager -> getManager($_GET['id']) -> getJSONP();\r
break;\r
\r
- case 'get_exploitants' :\r
- $exploitants = $exploitantManager -> getExploitants();\r
- if (!empty($exploitants)) {\r
+ case 'get_managers' :\r
+ $managers = $managerManager -> getManagers();\r
+ if (!empty($managers)) {\r
$i = 0;\r
echo '[';\r
- foreach ($exploitants as $exploitant) {\r
- echo $exploitant -> getJSON();\r
- if ($i != sizeof($exploitants) - 1) {\r
+ foreach ($managers as $manager) {\r
+ echo $manager -> getJSON();\r
+ if ($i != sizeof($managers) - 1) {\r
echo ',';\r
}\r
$i++;\r
}\r
break;\r
\r
- case 'get_instance' :\r
- echo $instanceManager -> getInstance($_GET['id']) -> getJSON();\r
+ case 'get_appliance' :\r
+ echo $applianceManager -> getAppliance($_GET['id']) -> getJSON();\r
break;\r
\r
- case 'get_instances' :\r
- $instances = $instanceManager -> getInstances();\r
- if (!empty($instances)) {\r
+ case 'get_appliances' :\r
+ $appliances = $applianceManager -> getAppliances();\r
+ if (!empty($appliances)) {\r
$i = 0;\r
echo '[';\r
- foreach ($instances as $instance) {\r
- echo $instance -> getJSON();\r
- if ($i != sizeof($instances) - 1) {\r
+ foreach ($appliances as $appliance) {\r
+ echo $appliance -> getJSON();\r
+ if ($i != sizeof($appliances) - 1) {\r
echo ',';\r
}\r
$i++;\r
}\r
break;\r
\r
- case 'disable_maintien' :\r
- $instanceManager -> desactiverMaintienById($_GET['id']);\r
+ case 'disable_maintained' :\r
+ $applianceManager -> disableMaintainedById($_GET['id']);\r
break;\r
\r
- case 'get_historique' :\r
- echo $historiqueManager -> getHistorique($_GET['id']) -> getJSON();\r
+ case 'get_changelog' :\r
+ echo $changelogManager -> getChangelog($_GET['id']) -> getJSON();\r
break;\r
\r
- case 'get_historiques' :\r
- $historiques = $historiqueManager -> getHistoriques();\r
- if (!empty($historiques)) {\r
+ case 'get_changelogs' :\r
+ $changelogs = $changelogManager -> getChangelogs();\r
+ if (!empty($changelogs)) {\r
$i = 0;\r
echo '[';\r
- foreach ($historiques as $historique) {\r
- echo $historique -> getJSONP();\r
- if ($i != sizeof($historiques) - 1) {\r
+ foreach ($changelogs as $changelog) {\r
+ echo $changelog -> getJSONP();\r
+ if ($i != sizeof($changelogs) - 1) {\r
echo ',';\r
}\r
$i++;\r
}\r
break;\r
\r
- case 'get_alerte' :\r
- echo $alerteManager -> getAlerte($_GET['id']) -> getJSON();\r
+ case 'get_warning' :\r
+ echo $warningManager -> getWarning($_GET['id']) -> getJSON();\r
break;\r
\r
- case 'get_alertes' :\r
- $alertes = $alerteManager -> getAlertes();\r
- if (!empty($alertes)) {\r
+ case 'get_warnings' :\r
+ $warnings = $warningManager -> getWarnings();\r
+ if (!empty($warnings)) {\r
$i = 0;\r
echo '[';\r
- foreach ($alertes as $alerte) {\r
- echo $alerte -> getJSON();\r
- if ($i != sizeof($alertes) - 1) {\r
+ foreach ($warnings as $warning) {\r
+ echo $warning -> getJSON();\r
+ if ($i != sizeof($warnings) - 1) {\r
echo ',';\r
}\r
$i++;\r
}\r
break;\r
\r
- case 'synchroniser_infos_clients' :\r
+ case 'synchronize_customers_info' :\r
\r
// LOGIN\r
$sugarConnector = new SugarConnector();\r
'phone_office',\r
'officenumber_c'\r
);\r
- $client_infos = json_decode($sugarConnector -> getInfosModule($moduleName, $requestedInfos));\r
+ $customer_infos = json_decode($sugarConnector -> getInfosModule($moduleName, $requestedInfos));\r
\r
- foreach($client_infos->entry_list as $client_info) {\r
+ foreach($customer_infos->entry_list as $customer_info) {\r
\r
// CHECKING RESULTS\r
- if(isset($client_info)) {\r
- $identifiantAP = $client_info->name_value_list->officenumber_c->value;\r
- $nom = $client_info->name_value_list->name->value;\r
+ if(isset($customer_info)) {\r
+ $cusomerAPId = $customer_info->name_value_list->officenumber_c->value;\r
+ $customerName = $customer_info->name_value_list->name->value;\r
\r
// IF AP ID IS NOT EMPTY\r
- if(isset($identifiantAP) && $identifiantAP != "") {\r
+ if(isset($cusomerAPId) && $cusomerAPId != "") {\r
\r
// GETTING CUSTOMER IN DB\r
- $client = $clientManager -> getClientByIdentifiantAP($identifiantAP);\r
+ $customer = $customerManager -> getCustomerByAPId($cusomerAPId);\r
\r
// IF CUSTOMER EXISTS, UPDATING INFORMATION\r
- if(isset($client) && $client->getId() > 0) {\r
- $client -> setIdentifiantAP($identifiantAP);\r
- $client -> setNom($nom);\r
- $clientManager -> updateClient($client);\r
+ if(isset($customer) && $customer->getId() > 0) {\r
+ $customer -> setAPId($cusomerAPId);\r
+ $customer -> setName($customerName);\r
+ $customerManager -> updateCustomer($customer);\r
\r
// IF CUSTOMER DOES NOT EXIST, CREATING A NEW ONE\r
} else {\r
- $client = new Client(null, $identifiantAP, $nom);\r
- $clientManager -> createClient($client);\r
+ $customer = new Customer(null, $cusomerAPId, $customerName);\r
+ $customerManager -> createCustomer($customer);\r
}\r
}\r
}\r
\r
break;\r
\r
- case 'check_synchro_info_version' :\r
+ case 'check_appliances_infos' :\r
\r
// LOGIN\r
$sugarConnector = new SugarConnector();\r
'id',\r
'name'\r
);\r
- $instances_infos = json_decode($sugarConnector -> getInfosModule($moduleName, $requestedInfos));\r
+ $appliances_infos = json_decode($sugarConnector -> getInfosModule($moduleName, $requestedInfos));\r
\r
- foreach($instances_infos->entry_list as $instance_infos) {\r
+ foreach($appliances_infos->entry_list as $appliance_infos) {\r
\r
// IF APPLIANCE EXISTS IN SUGAR\r
- if(isset($instance_infos)) {\r
- $refInstance = $instance_infos->name_value_list->name->value;\r
- $refInstanceArray = explode("/",$refInstance);\r
- $refClient = substr($refInstanceArray[1],0,-11);\r
- $refInstall = $refInstanceArray[0]."/".substr($refClient,0,-6);\r
+ if(isset($appliance_infos)) {\r
+ $applianceReference = $appliance_infos->name_value_list->name->value;\r
+ $applianceReferenceArray = explode("/",$applianceReference);\r
+ $customerAPId = substr($applianceReferenceArray[1],0,-11);\r
+ $opportunityReference = $applianceReferenceArray[0]."/".substr($customerAPId,0,-6);\r
\r
// GETTING APPLIANCE IN DB\r
- $instance = $instanceManager -> getInstanceByReference($refInstance);\r
+ $appliance = $applianceManager -> getApplianceByReference($applianceReference);\r
\r
// IF APPLIANCE EXISTS ON BOTH SIDES, COMPARING INFORMATIONS\r
- if(isset($instance) && $instance->getId() > 0) {\r
+ if(isset($appliance) && $appliance->getId() > 0) {\r
\r
// GETTING CHANGELOG OF APPLIANCE\r
- $historique = $historiqueManager -> getHistorique($instance -> getHistorique());\r
- $versions = $historique -> getVersions();\r
+ $changelog = $changelogManager -> getChangelog($appliance -> getChangelog());\r
+ $versions = $changelog -> getVersions();\r
\r
// CHECKING OPPORTUNITY EXISTENCE FOR EACH VERSION OF CHANGELOG\r
foreach($versions as $version) {\r
\r
// GETTING VALUE OF EACH VERSION OF CHANGELOG, AND ITS DECLARATION DATE\r
$versionArray = explode(';',$version);\r
- if(isset($versionArray[1])) {\r
- $versionId = $versionArray[0];\r
- $declaration = $versionArray[1];\r
- } else {\r
- $versionId = $version;\r
- $declaration = $historique -> getInstallation();\r
- }\r
- $versionValeur = $versionManager -> getVersion($versionId) -> getValeur();\r
- $refVersion = $refInstanceArray[0].' '.$versionValeur;\r
+ $versionId = $versionArray[0];\r
+ $versionDeclaration = $versionArray[1];\r
+ $versionValue = $versionManager -> getVersion($versionId) -> getValue();\r
+ $versionReference = $applianceReferenceArray[0].' '.$versionValue;\r
\r
// GETTING VERSION ID ON SUGAR\r
$moduleName = 'adul__Produits';\r
'id',\r
'name'\r
);\r
- $sqlWhereClause = "adul__produits.name = '".$refVersion."'";\r
+ $sqlWhereClause = "adul__produits.name = '".$versionReference."'";\r
$version_infos = json_decode($sugarConnector -> getInfosModule($moduleName, $requestedInfos, $sqlWhereClause));\r
if(isset($version_infos->entry_list[0])) {\r
- $idVersion = $version_infos->entry_list[0]->id;\r
+ $versionSugarId = $version_infos->entry_list[0]->id;\r
}\r
\r
// GETTING OPPORTUNITIES LINKED TO THE VERSION IN SUGAR\r
- if(isset($idVersion)) {\r
+ if(isset($versionSugarId)) {\r
$moduleName = 'adul__Produits';\r
$parameters = array(\r
"link_name" => "adul__prits_opportunities",\r
- "primary_module_id" => $idVersion,\r
+ "primary_module_id" => $versionSugarId,\r
);\r
$requestedInfos = array(\r
'id',\r
'name',\r
'date_opened_c'\r
);\r
- $sqlWhereClause = "opportunities.name = '".$refInstall."'";\r
+ $sqlWhereClause = "opportunities.name = '".$opportunityReference."'";\r
$result = json_decode($sugarConnector -> getRelationships($moduleName, $parameters, $requestedInfos, $sqlWhereClause));\r
\r
// COMPARING INFORMATIONS IN ORDER TO FIND A CONCORDANCE : DATES, CHANNEL, et cetera\r
- $testRecherche = false;\r
- foreach($result->entry_list as $fiche_install_info) {\r
+ $opportunityFoundInSugar = false;\r
+ foreach($result->entry_list as $opportunity_info) {\r
\r
// IF OPPORTUNITY EXISTS IN SUGAR\r
- if(isset($fiche_install_info->id)) {\r
- if($fiche_install_info->name_value_list->date_opened_c->value == $declaration) {\r
- $testRecherche = true;\r
+ if(isset($opportunity_info->id)) {\r
+ if($opportunity_info->name_value_list->date_opened_c->value == $versionDeclaration) {\r
+ $opportunityFoundInSugar = true;\r
break;\r
}\r
}\r
}\r
\r
// IF NO OPPORTUNITY IS FOUND FOR THE VERSION\r
- if(!$testRecherche) {\r
+ if(!$opportunityFoundInSugar) {\r
\r
// CREATING NEW WARNING, VERSION TYPE\r
- $alerte = new Alerte(null, $declaration, "version",\r
- "Version declaree ".$versionValeur." n'a pas de fiche d'installation sur Sugar pour cette instance.", $versionId);\r
- $alerteManager -> createAlerte($alerte);\r
+ $warningMessage = "Version declaree ".$versionValue." n'a pas de fiche d'installation sur Sugar pour cette instance applicative.";\r
+ $warning = new Warning(null, $versionDeclaration, "synchro", $warningMessage, $versionId);\r
+ $warningManager -> createWarning($warning);\r
\r
// GETTING APPLIANCE CHANGELOG\r
- $historiqueManager = new PdoHistoriqueManager();\r
- $historique = $historiqueManager -> getHistorique($instance -> getHistorique());\r
+ $changelogManager = new PdoChangelogManager();\r
+ $changelog = $changelogManager -> getChangelog($appliance -> getChangelog());\r
\r
// ADDING WARNING TO CHANGELOG\r
- $alertes = $historique -> getAlertes();\r
- if((array_search("", $alertes)) !== false) {\r
- $alertes = array($alerteManager -> getLastAlerte() -> getId());\r
+ $warnings = $changelog -> getWarnings();\r
+ if((array_search("", $warnings)) !== false) {\r
+ $warnings = array($warningManager -> getLastWarning() -> getId());\r
} else {\r
- $alertes[] = $alerteManager -> getLastAlerte() -> getId();\r
+ $warnings[] = $warningManager -> getLastWarning() -> getId();\r
}\r
- $historique -> setAlertes($alertes);\r
- $historiqueManager -> updateHistorique($historique);\r
+ $changelog -> setWarnings($warnings);\r
+ $changelogManager -> updateChangelog($changelog);\r
}\r
}\r
}\r
} else {\r
- echo "Instance d'application existante sur Sugar introuvable sur ALLO Serveur.";\r
+ echo "Instance applicative existante sur Sugar introuvable sur ALLO Serveur.";\r
}\r
}\r
}\r
break;\r
\r
- case 'create_fiche_installation' :\r
-\r
- // GETTING REFERENCES\r
- $refInstance = str_replace("\\", "", $_GET['nom']);\r
- $instance = $instanceManager -> getInstanceByReference($refInstance);\r
- $historique = $historiqueManager -> getHistorique($instance -> getHistorique());\r
- $refInstanceArray = explode("/",$refInstance);\r
- $refClient = substr($refInstanceArray[1],0,-11);\r
- $refContrat = $refInstanceArray[0]."/".$refClient."/20".substr($refInstanceArray[1],19,-4);\r
- $refInstall = $refInstanceArray[0]."/".substr($refClient,0,-6);\r
- $refVersion = $refInstanceArray[0].' '.$instance -> getVersion();\r
-\r
- /*\r
- echo "REF INSTANCE = ".$refInstance."<br/>";\r
- echo "REF CLIENT = ".$refClient."<br/>";\r
- echo "REF CONTRAT = ".$refContrat."<br/>";\r
- echo "REF INSTALL = ".$refInstall."<br/>";\r
- echo "REF VERSION = ".$refVersion."<br/>";\r
- */\r
+ case 'create_opportunity' :\r
+\r
+ // GETTING REFERENCES AND OBJECTS :\r
+ // APPLIANCE\r
+ $applianceReference = str_replace("\\", "", $_GET['appliance_reference']);\r
+ $appliance = $applianceManager -> getApplianceByReference($applianceReference);\r
+ $applianceReferenceArray = explode("/",$applianceReference);\r
+ // PRODUCT\r
+ $product = $productManager -> getProduct($appliance -> getProduct());\r
+ $productAcronym = $applianceReferenceArray[0];\r
+ // VERSION\r
+ $lastVersion = $changelogManager -> findLastVersion();\r
+ $lastVersionDeclaration = $changelogManager -> findLastVersionDeclaration();\r
+ $lastVersionReference = $productAcronym.' '.$lastVersion -> getValue();\r
+ // CUSTOMER\r
+ $customerAPId = substr($applianceReferenceArray[1],0,-11);\r
+ // CONTRACT\r
+ $contractReference = $productAcronym."/".$customerAPId."/20".substr($applianceReferenceArray[1],19,-4);\r
+ // OPPORTUNITY\r
+ $opportunityReference = $productAcronym."/".substr($customerAPId,0,-6);\r
\r
// LOGIN\r
$sugarConnector = new SugarConnector();\r
// GETTING APPLIANCE IN SUGAR\r
$moduleName = 'allo_Instances';\r
$requestedInfos = array('name');\r
- $sqlWhereClause = "allo_instances.name = '".$refInstance."'";\r
- $instance_infos = json_decode($sugarConnector -> getInfosModule($moduleName, $requestedInfos, $sqlWhereClause));\r
- if(isset($instance_infos->entry_list[0])) {\r
- $idInstance = $instance_infos->entry_list[0]->id;\r
+ $sqlWhereClause = "allo_instances.name = '".$applianceReference."'";\r
+ $appliance_infos = json_decode($sugarConnector -> getInfosModule($moduleName, $requestedInfos, $sqlWhereClause));\r
+ if(isset($appliance_infos->entry_list[0])) {\r
+ $applianceSugarId = $appliance_infos->entry_list[0]->id;\r
}\r
\r
// GETTING THE MAINTENANCE CONTRACT\r
'name',\r
'etat_contrat_c'\r
);\r
- $sqlWhereClause = "maint_contrat_maintenance.name = '".$refContrat."'";\r
- $contrat_infos = json_decode($sugarConnector -> getInfosModule($moduleName, $requestedInfos, $sqlWhereClause));\r
- if(isset($contrat_infos->entry_list[0])) {\r
- $idContrat = $contrat_infos->entry_list[0]->id;\r
+ $sqlWhereClause = "maint_contrat_maintenance.name = '".$contractReference."'";\r
+ $contract_infos = json_decode($sugarConnector -> getInfosModule($moduleName, $requestedInfos, $sqlWhereClause));\r
+ if(isset($contract_infos->entry_list[0])) {\r
+ $contractSugarId = $contract_infos->entry_list[0]->id;\r
}\r
\r
// QUESTIONING ITS VALIDITY STATE\r
- $etatContrat = $contrat_infos->entry_list[0]->name_value_list->etat_contrat_c->value;\r
+ $contractState = $contract_infos->entry_list[0]->name_value_list->etat_contrat_c->value;\r
\r
// IF NOT VALID OR DOES NOT EXIST, ERROR\r
- if(!isset($idContrat) || $etatContrat != "^encours^") {\r
- echo "Erreur : Contrat de maintenance inexistant ou invalide pour cette instance<br/>";\r
+ if(!isset($contractSugarId) || $contractState != "^encours^") {\r
+ echo "Erreur : Contrat de maintenance inexistant ou invalide pour cette appliance<br/>";\r
} else {\r
\r
// IF APPLIANCE DOES NOT EXIST, CREATING NEW ONE\r
- if(!isset($idInstance)) {\r
- // CRÉATION D'INSTANCE\r
+ if(!isset($applianceSugarId)) {\r
$moduleName = 'allo_Instances';\r
$parameters = array(\r
- 'name' => $refInstance\r
+ 'name' => $applianceReference\r
);\r
- $instance_infos = json_decode($sugarConnector -> updateOrCreateEntryModule($moduleName, $parameters));\r
- $idInstance = $instance_infos->id;\r
+ $appliance_infos = json_decode($sugarConnector -> updateOrCreateEntryModule($moduleName, $parameters));\r
+ $applianceSugarId = $appliance_infos->id;\r
\r
// LINKING IT TO MAINTENANCE CONTRACT\r
- if(isset($idInstance) && isset($idContrat)) {\r
+ if(isset($applianceSugarId)) {\r
$moduleName = 'maint_contrat_maintenance';\r
$parameters = array(\r
'link_name' => 'maint_contrat_maintenance_allo_instances_1',\r
- 'primary_module_id' => $idContrat,\r
- 'related_module_id' => $idInstance\r
+ 'primary_module_id' => $contractSugarId,\r
+ 'related_module_id' => $applianceSugarId\r
);\r
$sugarConnector -> createRelationship($moduleName, $parameters);\r
}\r
}\r
\r
// GETTING OPPORTUNITIES OF APPLIANCE\r
- $moduleName = 'Opportunities';\r
- $requestedInfos = array('id');\r
- $sqlWhereClause = "opportunities.name = '".$refInstall."'";\r
- $fiche_install_infos = json_decode($sugarConnector -> getInfosModule($moduleName, $requestedInfos, $sqlWhereClause));\r
- $idInstall = $fiche_install_infos->entry_list[0]->id;\r
- if(isset($idInstall)) {\r
+ $moduleName = 'allo_Instances';\r
+ $parameters = array(\r
+ "link_name" => "allo_instances_opportunities_1",\r
+ "primary_module_id" => $applianceSugarId,\r
+ );\r
+ $requestedInfos = array(\r
+ 'id',\r
+ 'name',\r
+ 'date_closed',\r
+ 'date_entered',\r
+ 'liste_hebergement_c',\r
+ 'type_exploitation_c'\r
+ );\r
+ $sqlWhereClause = "opportunities.name = '".$opportunityReference."'";\r
+ $opportunity_infos = json_decode($sugarConnector -> getRelationships($moduleName, $parameters, $requestedInfos, $sqlWhereClause));\r
+\r
+ $opportunitySugarId = $opportunity_infos->entry_list[0]->id;\r
+ if(isset($opportunitySugarId)) {\r
\r
// GETTING MOST RECENT OPPORTUNITY\r
- $lastFI = $fiche_install_infos->entry_list[0];\r
- foreach($fiche_install_infos->entry_list as $fiche_install_info) {\r
+ $lastOpportunity = $opportunity_infos->entry_list[0];\r
+ foreach($opportunity_infos->entry_list as $opportunity_info) {\r
\r
// RESEARCH CRITERION : NO CLOSING DATE AND LAST ADDED\r
- if(!isset($fiche_install_info->name_value_list->date_closed->value) &&\r
- $fiche_install_info->name_value_list->date_entered->value > $lastFI->name_value_list->date_entered->value) {\r
- $lastFI = $fiche_install_info;\r
- }\r
- }\r
- $versions = $historique -> getVersions();\r
- $lastDeclaration = $historique -> getInstallation();\r
- $lastVersion = $instance -> getVersion();\r
-\r
- // GETTING DATE OF THE LAST VERSION DECLARATION\r
- foreach($versions as $version) {\r
- $versionArray = explode(';',$version);\r
- if(isset($versionArray[1])) {\r
- $declaration = $versionArray[1];\r
- if($declaration > $lastDeclaration) {\r
- $lastDeclaration = $declaration;\r
- $lastVersionId = $versionArray[0];\r
- }\r
+ if(!isset($opportunity_info->name_value_list->date_closed->value) &&\r
+ $opportunity_info->name_value_list->date_entered->value > $lastOpportunity->name_value_list->date_entered->value) {\r
+ $lastOpportunity = $opportunity_info;\r
}\r
}\r
\r
- // LAST VERSION DECLARED\r
- if(isset($lastVersionId)) {\r
- $lastVersion = $versionManager -> getVersion($lastVersionId) -> getValeur();\r
- }\r
-\r
// UPDATING LAST OPPORTUNITY IN SUGAR : ADDING CLOSING DATE\r
- $idLastFi = $lastFI->id;\r
- $moduleName = 'Opportunities';\r
- $parameters = array(\r
- 'id' => $idLastFi,\r
- 'date_closed' => $lastDeclaration\r
- );\r
- $sugarConnector -> updateOrCreateEntryModule($moduleName, $parameters);\r
-\r
- // CREATING NEW OPPORTUNITY\r
- $moduleName = 'Opportunities';\r
- $parameters = array(\r
- 'name' => $refInstall,\r
- 'type_exploitation_c' => $instance->getCanal(),\r
- 'date_opened_c' => $lastDeclaration,\r
- 'systeme_d_exploitation_c' => $instance->getSysteme(),\r
- 'liste_hebergement_c' => 'CLIENT',\r
- 'description' => 'Création par ALLO'\r
- );\r
- $fiche_install_infos = json_decode($sugarConnector -> updateOrCreateEntryModule($moduleName, $parameters));\r
- $idInstall = $fiche_install_infos->id;\r
+ $lastOpportunitySugarId = $lastOpportunity->id;\r
+ if(isset($lastVersionDeclaration)) {\r
+ $moduleName = 'Opportunities';\r
+ $parameters = array(\r
+ 'id' => $lastOpportunitySugarId,\r
+ 'date_closed' => $lastVersionDeclaration\r
+ );\r
+ $sugarConnector -> updateOrCreateEntryModule($moduleName, $parameters);\r
\r
- // CHANGING VERSION REFERENCE TO LINK TO THE OPPORTUNITY\r
- $refVersion = $refInstanceArray[0].' '.$lastVersion;\r
+ // CREATING NEW OPPORTUNITY\r
+ $moduleName = 'Opportunities';\r
+ $parameters = array(\r
+ 'name' => $lastOpportunity->name_value_list->name->value,\r
+ 'type_exploitation_c' => $lastOpportunity->name_value_list->type_exploitation_c->value,\r
+ 'date_opened_c' => $lastVersionDeclaration,\r
+ 'systeme_d_exploitation_c' => $appliance->getOs(),\r
+ 'liste_hebergement_c' => $lastOpportunity->name_value_list->liste_hebergement_c->value,\r
+ 'description' => 'Création par ALLO'\r
+ );\r
+ $opportunity_infos = json_decode($sugarConnector -> updateOrCreateEntryModule($moduleName, $parameters));\r
+ $opportunitySugarId = $opportunity_infos->id;\r
+ }\r
\r
// IF NO OPPORTUNITY IS FOUND ON SUGAR FOR THIS APPLIANCE, CREATING NEW ONE\r
} else {\r
$moduleName = 'Opportunities';\r
$parameters = array(\r
- 'name' => $refInstall,\r
- 'type_exploitation_c' => $instance->getCanal(),\r
- 'date_opened_c' => $historique->getInstallation(),\r
- 'systeme_d_exploitation_c' => $instance->getSysteme(),\r
+ 'name' => $opportunityReference,\r
+ 'type_exploitation_c' => $appliance->getChannel(),\r
+ // TO-DO : GET THE INSTALLATION DATE FROM CHANGELOG\r
+ /*'date_opened_c' => $changelog->getInstallation(),*/\r
+ 'systeme_d_exploitation_c' => $appliance->getOs(),\r
+ // TO-DO : CHANGE THIS VALUE FOR EACH MANAGEMENT TYPE\r
'liste_hebergement_c' => 'CLIENT',\r
'description' => 'Création par ALLO'\r
);\r
- $fiche_install_infos = json_decode($sugarConnector -> updateOrCreateEntryModule($moduleName, $parameters));\r
- $idInstall = $fiche_install_infos->id;\r
+ $opportunity_infos = json_decode($sugarConnector -> updateOrCreateEntryModule($moduleName, $parameters));\r
+ $opportunitySugarId = $opportunity_infos->id;\r
}\r
\r
// LINKING OPPORTUNITY TO APPLIANCE\r
- if(isset($idInstance) && isset($idInstall)) {\r
+ if(isset($applianceSugarId) && isset($opportunitySugarId)) {\r
$moduleName = 'allo_Instances';\r
$parameters = array(\r
'link_name' => 'allo_instances_opportunities_1',\r
- 'primary_module_id' => $idInstance,\r
- 'related_module_id' => $idInstall\r
+ 'primary_module_id' => $applianceSugarId,\r
+ 'related_module_id' => $opportunitySugarId\r
);\r
$sugarConnector -> createRelationship($moduleName, $parameters);\r
}\r
// GETTING VERSION ID IN SUGAR\r
$moduleName = 'adul__Produits';\r
$requestedInfos = array('name');\r
- $sqlWhereClause = "adul__produits.name = '".$refVersion."'";\r
+ $sqlWhereClause = "adul__produits.name = '".$lastVersionReference."'";\r
$version_infos = json_decode($sugarConnector -> getInfosModule($moduleName, $requestedInfos, $sqlWhereClause));\r
if(isset($version_infos->entry_list[0])) {\r
- $idVersion = $version_infos->entry_list[0]->id;\r
+ $versionSugarId = $version_infos->entry_list[0]->id;\r
}\r
\r
// LINKING OPPORTUNITY TO VERSION\r
- if(isset($idVersion) && isset($idInstall)) {\r
+ if(isset($versionSugarId) && isset($opportunitySugarId)) {\r
$moduleName = 'adul__Produits';\r
$parameters = array(\r
'link_name' => 'adul__prits_opportunities',\r
- 'primary_module_id' => $idVersion,\r
- 'related_module_id' => $idInstall\r
+ 'primary_module_id' => $versionSugarId,\r
+ 'related_module_id' => $opportunitySugarId\r
+ );\r
+ $sugarConnector -> createRelationship($moduleName, $parameters);\r
+ }\r
+\r
+ // GETTING PRODUCT CATALOG ID IN SUGAR\r
+ $moduleName = 'maint_catalogue_produits';\r
+ $requestedInfos = array('name');\r
+ $sqlWhereClause = "maint_catalogue_produits.name = '".$product -> getName()."'";\r
+ $catalog_infos = json_decode($sugarConnector -> getInfosModule($moduleName, $requestedInfos, $sqlWhereClause));\r
+ if(isset($catalog_infos->entry_list[0])) {\r
+ $catalogSugarId = $catalog_infos->entry_list[0]->id;\r
+ }\r
+\r
+ // LINKING OPPORTUNITY TO PRODUCT CATALOG\r
+ if(isset($catalogSugarId) && isset($opportunitySugarId)) {\r
+ $moduleName = 'maint_catalogue_produits';\r
+ $parameters = array(\r
+ 'link_name' => 'maint_caits_opportunities',\r
+ 'primary_module_id' => $catalogSugarId,\r
+ 'related_module_id' => $opportunitySugarId\r
);\r
$sugarConnector -> createRelationship($moduleName, $parameters);\r
}\r
'id',\r
'officenumber_c'\r
);\r
- $sqlWhereClause = "accounts_cstm.officenumber_c = '".$refClient."'";\r
- $client_infos = json_decode($sugarConnector -> getInfosModule($moduleName, $requestedInfos, $sqlWhereClause));\r
- if(isset($client_infos->entry_list[0])) {\r
- $idClient = $client_infos->entry_list[0]->id;\r
+ $sqlWhereClause = "accounts_cstm.officenumber_c = '".$customerAPId."'";\r
+ $customer_infos = json_decode($sugarConnector -> getInfosModule($moduleName, $requestedInfos, $sqlWhereClause));\r
+ if(isset($customer_infos->entry_list[0])) {\r
+ $customerSugarId = $customer_infos->entry_list[0]->id;\r
}\r
\r
- // LINKING OPPORTUNITY TO CUSTOMER\r
- if(isset($idClient) && isset($idInstall)) {\r
+ // LINKING OPPORTUNITY TO CUSTOMER (FOR N-N RELATIONS, IT GOES BOTH WAYS)\r
+ if(isset($customerSugarId) && isset($opportunitySugarId)) {\r
$moduleName = 'Accounts';\r
$parameters = array(\r
'link_name' => 'opportunities',\r
- 'primary_module_id' => $idClient,\r
- 'related_module_id' => $idInstall\r
+ 'primary_module_id' => $customerSugarId,\r
+ 'related_module_id' => $opportunitySugarId\r
);\r
$sugarConnector -> createRelationship($moduleName, $parameters);\r
$moduleName = 'Opportunities';\r
$parameters = array(\r
'link_name' => 'accounts',\r
- 'primary_module_id' => $idInstall,\r
- 'related_module_id' => $idClient\r
+ 'primary_module_id' => $opportunitySugarId,\r
+ 'related_module_id' => $opportunitySugarId\r
);\r
$sugarConnector -> createRelationship($moduleName, $parameters);\r
}\r
+\r
+ // TO-DO : LINK OPPORTUNITY TO MAINTENANCE CONTRACT\r
}\r
break;\r
}\r
- } else { echo "Welcome sur ALLO Serveur !"; }\r
+ } else { echo "C'est plutôt vide par ici."; }\r
}\r
\r
?>
\ No newline at end of file
\r
// CHECKING IF ARRAY IS VALID\r
if (!is_null($array) && assert($array)) {\r
- $instanceManager = new PdoInstanceManager();\r
+ $applianceManager = new PdoApplianceManager();\r
\r
// CHEKING INFORMATION\r
- $retour = $instanceManager->testInformationsAvantUpload($array);\r
- if($retour === 'ok') {\r
+ $validityTestResponse = $applianceManager->checkUploadInfoValidity($array);\r
+ if($validityTestResponse === 'ok') {\r
\r
// UPADATING APPLIANCE INFORMATION\r
- $instanceManager -> updateInstanceInfos($array);\r
+ $applianceManager -> updateApplianceInfos($array);\r
} else {\r
- echo $retour;\r
+ echo $validityTestResponse;\r
}\r
} else {\r
var_dump($data);\r
<?php\r
\r
+ // DELETE OR KEEP ?\r
function api_put() {\r
// RÉCUPÉRATION DES DONNÉES\r
/*$data = file_get_contents("php://input");\r
header('Content-Type: text/html; charset=utf-8');\r
\r
// MODELS\r
- require_once('classes/models/Exploitant.class.php');\r
- require_once('classes/models/Instance.class.php');\r
- require_once('classes/models/Historique.class.php');\r
- require_once('classes/models/Alerte.class.php');\r
- require_once('classes/models/Produit.class.php');\r
+ require_once('classes/models/Manager.class.php');\r
+ require_once('classes/models/Appliance.class.php');\r
+ require_once('classes/models/Changelog.class.php');\r
+ require_once('classes/models/Warning.class.php');\r
+ require_once('classes/models/Product.class.php');\r
require_once('classes/models/Version.class.php');\r
- require_once('classes/models/Client.class.php');\r
+ require_once('classes/models/Customer.class.php');\r
\r
// MANAGERS\r
require_once('classes/manager/pdo/AbstractPdoManager.php');\r
- require_once('classes/manager/pdo/PdoExploitantManager.php');\r
- require_once('classes/manager/pdo/PdoInstanceManager.php');\r
- require_once('classes/manager/pdo/PdoHistoriqueManager.php');\r
- require_once('classes/manager/pdo/PdoAlerteManager.php');\r
- require_once('classes/manager/pdo/PdoProduitManager.php');\r
+ require_once('classes/manager/pdo/PdoManagerManager.php');\r
+ require_once('classes/manager/pdo/PdoApplianceManager.php');\r
+ require_once('classes/manager/pdo/PdoChangelogManager.php');\r
+ require_once('classes/manager/pdo/PdoWarningManager.php');\r
+ require_once('classes/manager/pdo/PdoProductManager.php');\r
require_once('classes/manager/pdo/PdoVersionManager.php');\r
- require_once('classes/manager/pdo/PdoClientManager.php');\r
+ require_once('classes/manager/pdo/PdoCustomerManager.php');\r
\r
// SUGAR CONNECTOR\r
require_once('classes/SugarHttpClient.php');\r