2010-11-22 12:50:12 +00:00
|
|
|
<?php
|
2011-04-13 12:15:43 +00:00
|
|
|
require_once 'Web/Forms/Login.php';
|
2010-11-22 12:50:12 +00:00
|
|
|
require_once 'Web/WebAuthAdapter.php';
|
2011-05-03 12:49:43 +00:00
|
|
|
require_once 'Scores/Utilisateur.php';
|
|
|
|
require_once 'Scores/WsScores.php';
|
2010-11-22 12:50:12 +00:00
|
|
|
|
2011-05-03 12:49:43 +00:00
|
|
|
class UserController extends Zend_Controller_Action
|
|
|
|
{
|
|
|
|
|
|
|
|
protected function updateProfil($login, $password)
|
2011-01-05 09:59:49 +00:00
|
|
|
{
|
2011-05-03 12:49:43 +00:00
|
|
|
Zend_Registry::get('firebug')->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;
|
2011-01-07 17:16:07 +00:00
|
|
|
|
2011-05-03 12:49:43 +00:00
|
|
|
$identity->modeEdition = false;
|
|
|
|
return $identity;
|
2011-01-05 09:59:49 +00:00
|
|
|
}
|
2011-05-03 12:49:43 +00:00
|
|
|
|
2011-05-03 15:58:48 +00:00
|
|
|
public function init()
|
|
|
|
{
|
|
|
|
$this->view->headLink()
|
|
|
|
->appendStylesheet('/themes/default/styles/user.css', 'all');
|
|
|
|
}
|
2011-05-03 12:49:43 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Affiche le fomulaire d'edition des paramètres utilisateur
|
|
|
|
*/
|
2010-11-22 12:50:12 +00:00
|
|
|
public function indexAction()
|
|
|
|
{
|
2011-05-03 12:49:43 +00:00
|
|
|
$this->view->headLink()
|
|
|
|
->appendStylesheet('/themes/default/styles/form.css', 'all');
|
2011-05-03 15:58:48 +00:00
|
|
|
|
2011-05-03 12:49:43 +00:00
|
|
|
$this->view->headScript()
|
|
|
|
->appendFile('/themes/default/scripts/user.js', 'text/javascript');
|
|
|
|
|
|
|
|
$request = $this->getRequest();
|
|
|
|
|
|
|
|
$messages = '';
|
|
|
|
$isProfilUpdated = true;
|
|
|
|
$isPasswordUpdated = true;
|
|
|
|
$updateResult = false;
|
2011-04-18 14:36:06 +00:00
|
|
|
|
2011-04-01 12:14:40 +00:00
|
|
|
$ws = new WsScores();
|
2011-05-03 12:49:43 +00:00
|
|
|
|
|
|
|
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.';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-04-01 12:14:40 +00:00
|
|
|
//Liste de tous les droits
|
|
|
|
$listeDroits = $ws->getListeDroits();
|
|
|
|
$droitsLib = array();
|
|
|
|
foreach($listeDroits->item as $droit) {
|
2011-05-03 12:49:43 +00:00
|
|
|
$droitsLib[strtoupper($droit->code)] = $droit->desc;
|
2011-04-01 12:14:40 +00:00
|
|
|
}
|
|
|
|
$this->view->assign('droitsLib', $droitsLib);
|
2011-02-21 08:45:13 +00:00
|
|
|
|
2011-04-01 12:14:40 +00:00
|
|
|
//Liste de toutes les préférences
|
|
|
|
$listePrefs = $ws->getListePrefs();
|
|
|
|
$prefsLib = array();
|
|
|
|
foreach($listePrefs->item as $pref) {
|
2011-05-03 12:49:43 +00:00
|
|
|
$prefsLib[strtoupper($pref->code)] = $pref->desc;
|
2011-04-01 12:14:40 +00:00
|
|
|
}
|
|
|
|
$this->view->assign('prefsLib', $prefsLib);
|
2011-02-21 08:45:13 +00:00
|
|
|
|
2011-05-03 12:49:43 +00:00
|
|
|
//Récupération des informations de l'identité
|
2011-04-01 12:14:40 +00:00
|
|
|
$auth = Zend_Auth::getInstance();
|
|
|
|
$identity = $auth->getIdentity();
|
2011-05-03 12:49:43 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2011-02-21 08:45:13 +00:00
|
|
|
$isAdmin = false;
|
2011-04-01 12:14:40 +00:00
|
|
|
if ($identity->profil == 'Administrateur'
|
|
|
|
|| $identity->profil == 'SuperAdministrateur') {
|
2011-02-21 08:45:13 +00:00
|
|
|
$isAdmin = true;
|
|
|
|
}
|
2011-04-01 12:14:40 +00:00
|
|
|
$this->view->assign('options', $identity);
|
2011-02-21 08:45:13 +00:00
|
|
|
$this->view->assign('isAdmin', $isAdmin);
|
2011-04-01 12:14:40 +00:00
|
|
|
$this->view->assign('loginVu', $identity->username);
|
2011-05-03 12:49:43 +00:00
|
|
|
if (!empty($action) || $action!='new') {
|
2011-04-01 12:14:40 +00:00
|
|
|
$this->view->assign('loginNew', '');
|
|
|
|
$this->view->assign('droits', explode(' ', $identity->droits));
|
|
|
|
$this->view->assign('droitsClients', explode(' ', $identity->droitsClients));
|
2011-05-03 12:49:43 +00:00
|
|
|
$this->view->assign('action', 'update');
|
2011-04-01 12:14:40 +00:00
|
|
|
$this->view->assign('pref', explode(' ',$identity->pref));
|
|
|
|
} else {
|
|
|
|
$reponse = $ws->getNextLogin($loginVu);
|
|
|
|
$this->view->assign('loginNew', $reponse->result->racine);
|
|
|
|
$this->view->assign('droitsClients', explode(' ', $reponse->result->droitsClients));
|
|
|
|
$this->view->assign('action', 'new');
|
|
|
|
$this->view->assign('pref', array());
|
|
|
|
}
|
2010-11-22 12:50:12 +00:00
|
|
|
}
|
2011-04-01 12:14:40 +00:00
|
|
|
|
2011-05-03 15:58:48 +00:00
|
|
|
public function editAction()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
public function newAction()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
public function deleteAction()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
public function activateAction()
|
|
|
|
{
|
2011-05-04 13:24:26 +00:00
|
|
|
//Redirect
|
2011-05-03 15:58:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function unactivateAction()
|
|
|
|
{
|
2011-05-04 13:24:26 +00:00
|
|
|
//Redirect
|
2011-05-03 15:58:48 +00:00
|
|
|
}
|
|
|
|
|
2011-04-01 12:14:40 +00:00
|
|
|
public function changepwdAction()
|
|
|
|
{
|
2011-05-04 13:24:26 +00:00
|
|
|
//Redirect
|
2011-04-01 12:14:40 +00:00
|
|
|
}
|
|
|
|
|
2011-05-03 15:58:48 +00:00
|
|
|
public function listeAction()
|
|
|
|
{
|
|
|
|
$user = new Utilisateur();
|
|
|
|
Zend_Registry::get('firebug')->info($user->isSuperAdmin());
|
|
|
|
Zend_Registry::get('firebug')->info($user->isAdmin());
|
|
|
|
if (!$user->isSuperAdmin() && !$user->isAdmin()) {
|
|
|
|
$this->renderScript('error/error-perms.phtml');
|
|
|
|
}
|
|
|
|
$ws = new WsScores();
|
|
|
|
$infos = $ws->getListeUtilisateurs($user->getLogin(), $user->getIdClient());
|
|
|
|
$utilisateurs = $infos->result->item;
|
|
|
|
$this->view->assign('utilisateurs', $utilisateurs);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
public function loginAction()
|
2010-11-22 12:50:12 +00:00
|
|
|
{
|
2011-02-21 08:45:13 +00:00
|
|
|
//@todo : gestion des affichages particuliers pour les clients
|
2011-01-07 17:16:07 +00:00
|
|
|
$activeNav = $this->view->navigation();
|
|
|
|
$activeNav->removePages();
|
2010-11-24 10:55:21 +00:00
|
|
|
$this->view->headTitle()->append('Connexion');
|
2010-11-22 12:50:12 +00:00
|
|
|
$form = new Form_Login();
|
|
|
|
$this->view->form = $form;
|
|
|
|
$request = $this->getRequest();
|
|
|
|
if ($request->isPost()) {
|
|
|
|
$formData = $request->getPost ();
|
|
|
|
if ($form->isValid($formData)) {
|
|
|
|
$login = $form->getValue('login');
|
|
|
|
$pass = $form->getValue('pass');
|
|
|
|
|
|
|
|
$auth = Zend_Auth::getInstance();
|
2011-01-06 11:22:26 +00:00
|
|
|
$authAdapter = new WebAuthAdapter($login, $pass);
|
2010-11-22 12:50:12 +00:00
|
|
|
$result = $auth->authenticate($authAdapter);
|
|
|
|
if (!$result->isValid()){
|
|
|
|
$this->view->message = '';
|
|
|
|
foreach ($result->getMessages() as $message) {
|
|
|
|
$this->view->message.= $message."<br/>";
|
|
|
|
}
|
|
|
|
} else {
|
2011-01-06 11:22:26 +00:00
|
|
|
$timeout = $auth->getIdentity()->timeout;
|
|
|
|
$storage = new Zend_Auth_Storage_Session();
|
|
|
|
$sessionNamespace = new Zend_Session_Namespace($storage->getNamespace());
|
|
|
|
$sessionNamespace->setExpirationSeconds($timeout);
|
|
|
|
$auth->setStorage($storage);
|
2011-02-04 16:27:03 +00:00
|
|
|
$url = '';
|
|
|
|
if (Zend_Registry::isRegistered('URL')){
|
|
|
|
$url = Zend_Registry::get('URL');
|
|
|
|
}
|
2011-01-11 09:15:11 +00:00
|
|
|
if (!empty($url)){
|
|
|
|
$this->_redirect($url);
|
|
|
|
}
|
2010-11-22 12:50:12 +00:00
|
|
|
$this->_redirect('/');
|
|
|
|
}
|
2011-01-07 17:16:07 +00:00
|
|
|
|
2010-11-22 12:50:12 +00:00
|
|
|
}
|
|
|
|
}
|
2011-01-06 11:22:26 +00:00
|
|
|
$this->_helper->layout()->disableLayout();
|
|
|
|
$this->render('login');
|
2010-11-22 12:50:12 +00:00
|
|
|
}
|
2011-02-21 08:45:13 +00:00
|
|
|
|
|
|
|
public function logoutAction()
|
|
|
|
{
|
2011-01-07 17:16:07 +00:00
|
|
|
$activeNav = $this->view->navigation();
|
|
|
|
$activeNav->removePages();
|
2010-11-22 12:50:12 +00:00
|
|
|
Zend_Auth::getInstance()->clearIdentity();
|
2011-02-04 16:27:03 +00:00
|
|
|
$this->_helper->layout()->disableLayout();
|
|
|
|
$this->render('logout');
|
2010-11-22 12:50:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|