--- /dev/null
+<?php
+ class ConfigurationsController extends AppController {
+ public $helpers = array('Html', 'Form');
+ public $components = array('RequestHandler');
+
+ public function index() {
+ $configuration = $this->Configuration->find('first');
+
+ // IF NO CONFIGURATION EXISTS, WE CREATE A NEW ONE
+ if (!$configuration) {
+ $this->Configuration->create();
+ $this->Configuration->set(array(
+ 'as_fqdn' => 'Vide',
+ 'sugar_fqdn' => 'Vide',
+ 'sugar_login' => ''
+ ));
+ $this->Configuration->save();
+ $this->redirect(array('action' => 'index'));
+ }
+
+ // SENDING DATA TO VIEW
+ $this->set('configuration', $configuration);
+ }
+
+ public function edit($id = null) {
+ if (!$id) {
+ throw new NotFoundException(__('Configuration introuvable'));
+ }
+
+ // GETTING THE CONFIGURATION
+ $this->Configuration->id = $id;
+ $configuration = $this->Configuration->findById($id);
+ if (!$configuration) {
+ throw new NotFoundException(__('Configuration introuvable'));
+ }
+
+ // IN CASE OF A POST REQUEST
+ if ($this->request->is('put')) {
+ $this->Configuration->save($this->request->data);
+ $login = $_POST['login'];
+ //$pass = md5($_POST['pass']);
+ $pass = $_POST['pass'];
+ $this->Configuration->read(null, $id);
+ $this->Configuration->set(array(
+ 'sugar_login' => $login,
+ 'sugar_passwd' => $pass
+ ));
+ $this->Configuration->save();
+ if (isset($this->Configuration)) {
+ $this->redirect(array('action' => 'index'));
+ }
+ }
+
+ // SENDING DATA TO VIEW
+ $this->set('configuration', $configuration);
+ if (!$this->request->data) {
+ $this->request->data = $configuration;
+ }
+ }
+ }