diff --git a/application/controllers/UserController.php b/application/controllers/UserController.php index e56d566bf..188fe69db 100644 --- a/application/controllers/UserController.php +++ b/application/controllers/UserController.php @@ -1,25 +1,116 @@ info('updateProfil'); + $ws = new WsScores(); + $InfosLogin = $ws->getInfosLogin($login); + $identity = new stdClass; + $identity->username = $login; + $identity->password = $password; // @todo : Hash ? + $identity->email = $InfosLogin->result->email; + $identity->profil = $InfosLogin->result->profil; + $identity->pref = $InfosLogin->result->pref; + $identity->droits = $InfosLogin->result->droits; + $identity->droitsClients = $InfosLogin->result->droitsClients; + $identity->nom = $InfosLogin->result->nom; + $identity->prenom = $InfosLogin->result->prenom; + $identity->tel = $InfosLogin->result->tel; + $identity->fax = $InfosLogin->result->fax; + $identity->mobile = $InfosLogin->result->mobile; + $identity->id = $InfosLogin->result->id; + $identity->idClient = $InfosLogin->result->idClient; + $identity->reference = $InfosLogin->result->reference; + $identity->nbReponses = $InfosLogin->result->nbReponses; + $identity->typeScore = $InfosLogin->result->typeScore; + $identity->timeout = (!empty($InfosLogin->result->timeout)) ? + $InfosLogin->result->timeout : 1800; + + $identity->modeEdition = false; + return $identity; } - + + public function init(){} + + /** + * Affiche le fomulaire d'edition des paramètres utilisateur + */ public function indexAction() { - $this->view->headLink()->appendStylesheet('/themes/default/styles/form.css', 'all'); + $this->view->headLink() + ->appendStylesheet('/themes/default/styles/user.css', 'all') + ->appendStylesheet('/themes/default/styles/form.css', 'all'); + $this->view->headScript() + ->appendFile('/themes/default/scripts/user.js', 'text/javascript'); + + $request = $this->getRequest(); + $action = $request->getParam('action', ''); + + $messages = ''; + $isProfilUpdated = true; + $isPasswordUpdated = true; + $updateResult = false; - require_once 'Scores/WsScores.php'; $ws = new WsScores(); + + if ($request->isPost()) { + $login = $request->getParam('login', ''); + $options = $request->getParam('frmOptions', ''); + $action = $options['action']; + + //Gestion mode edition en SESSION + if ($action=='update') { + $modeEdition = $request->getParam('modeEdition', false); + if ($modeEdition){ + $auth = Zend_Auth::getInstance(); + $identity = $auth->getIdentity(); + $identity->modeEdition = true; + $auth->getStorage()->write($identity); + } + } + + //Enregistrement des données new & update + if (in_array($action, array('new','update'))) { + $infos = new stdClass(); + $infos->idClient = $options['idClient']; + $infos->nom = $options['nom']; + $infos->prenom = $options['prenom']; + $infos->reference = $options['reference']; + $infos->email = $options['email']; + $infos->tel_fix = $options['tel_fix']; + $infos->tel_fax = $options['tel_fax']; + $infos->tel_mob = $options['tel_mob']; + $infos->rech_nbrep = $options['rech_nbrep']; + $infos->formatMail = $options['formatMail']; + $infos->password = ''; + if ($options['changepwd']==1){ + $infos->password = $options['password']; + } + $infos->droits = $options['droits']; + $infos->pref = $options['pref']; + $ws = new WsScores(); + $infos = $ws->setInfosLogin($login, $action, $infos); + $isProfilUpdated = true; + $message = 'Erreur lors de la mise à jour du compte !'; + if ($infos->result){ + $updateResult = true; + $message = 'Compte mis à jour.'; + } + } + } + //Liste de tous les droits $listeDroits = $ws->getListeDroits(); $droitsLib = array(); foreach($listeDroits->item as $droit) { - $droitsLib[$droit->code] = $droit->desc; + $droitsLib[strtoupper($droit->code)] = $droit->desc; } $this->view->assign('droitsLib', $droitsLib); @@ -27,12 +118,23 @@ class UserController extends Zend_Controller_Action { $listePrefs = $ws->getListePrefs(); $prefsLib = array(); foreach($listePrefs->item as $pref) { - $prefsLib[$pref->code] = $pref->desc; + $prefsLib[strtoupper($pref->code)] = $pref->desc; } $this->view->assign('prefsLib', $prefsLib); + //Récupération des informations de l'identité $auth = Zend_Auth::getInstance(); $identity = $auth->getIdentity(); + if ($isProfilUpdated && $updateResult) { + $identity = $this->updateProfil($identity->username, $identity->password); + $auth->getStorage()->write($identity); + } + Zend_Registry::get('firebug')->info($identity); + + if ($isProfilUpdated || $isPasswordUpdated) { + $this->view->assign('message', $message); + } + $isAdmin = false; if ($identity->profil == 'Administrateur' || $identity->profil == 'SuperAdministrateur') { @@ -41,11 +143,11 @@ class UserController extends Zend_Controller_Action { $this->view->assign('options', $identity); $this->view->assign('isAdmin', $isAdmin); $this->view->assign('loginVu', $identity->username); - if (!isset($_REQUEST['action']) || $_REQUEST['action']!='new') { + if (!empty($action) || $action!='new') { $this->view->assign('loginNew', ''); $this->view->assign('droits', explode(' ', $identity->droits)); $this->view->assign('droitsClients', explode(' ', $identity->droitsClients)); - $this->view->assign('action', 'edit'); + $this->view->assign('action', 'update'); $this->view->assign('pref', explode(' ',$identity->pref)); } else { $reponse = $ws->getNextLogin($loginVu); @@ -54,14 +156,7 @@ class UserController extends Zend_Controller_Action { $this->view->assign('action', 'new'); $this->view->assign('pref', array()); } - - } - - public function saveAction() - { - - } public function changepwdAction() { diff --git a/application/views/default/scripts/user/index.phtml b/application/views/default/scripts/user/index.phtml index a6be99627..399f56d3d 100644 --- a/application/views/default/scripts/user/index.phtml +++ b/application/views/default/scripts/user/index.phtml @@ -1,13 +1,18 @@
+=$this->message?> +