extranet/application/controllers/UserController.php

395 lines
12 KiB
PHP
Raw Normal View History

2010-11-22 12:50:12 +00:00
<?php
2011-05-03 12:49:43 +00:00
class UserController extends Zend_Controller_Action
{
2011-05-23 10:04:12 +00:00
/**
* Récupére les valeurs du profil depuis le webservice
* @param unknown_type $login
* @param unknown_type $password
*/
2011-05-03 12:49:43 +00:00
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;
2011-09-09 08:28:42 +00:00
$identity->password = $password;
2011-05-03 12:49:43 +00:00
$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()
{
require_once 'Web/Forms/Login.php';
require_once 'Web/WebAuthAdapter.php';
require_once 'Scores/Utilisateur.php';
require_once 'Scores/WsScores.php';
2011-05-23 10:04:12 +00:00
$this->view->headLink()->appendStylesheet('/themes/default/styles/user.css', 'all');
2011-05-03 15:58:48 +00:00
}
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-23 06:45:29 +00:00
$this->view->headLink()->appendStylesheet('/themes/default/styles/form.css', 'all');
$this->view->headScript()->appendFile('/themes/default/scripts/user.js', 'text/javascript');
2011-05-03 12:49:43 +00:00
$request = $this->getRequest();
$messages = '';
$isProfilUpdated = false;
$isPasswordUpdated = false;
2011-05-03 12:49:43 +00:00
$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
$login = $request->getParam('login', '');
$op = $request->getParam('op');
2011-05-03 12:49:43 +00:00
if ($request->isPost()) {
$options = $request->getParam('frmOptions', '');
$action = $options['action'];
2011-08-05 14:40:21 +00:00
if ($login=='') $login = $options['login'];
2011-05-03 12:49:43 +00:00
//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'];
$infos->profil = isset($options['profil']) ? $options['profil'] : 'Utilisateur';
$infos = $ws->setInfosLogin($login, $action, $infos);
2011-05-03 12:49:43 +00:00
$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();
2011-09-09 08:28:42 +00:00
$identity = $auth->getIdentity(); Zend_Registry::get('firebug')->info($identity);
if ($identity->idClient == $options['idClient'] && $identity->username == $login) {
//Modification lors du changement de mot de passe
if ($options['changepwd']==1 && $updateResult) {
2011-09-09 08:28:42 +00:00
Zend_Registry::get('firebug')->info('CHANGEPWD');
$auth = Zend_Auth::getInstance();
$identity = $auth->getIdentity();
$identity->password = md5($login.'|'.$options['password']);
$auth->getStorage()->write($identity);
}
//Mise à jour du profil
if ($isProfilUpdated && $updateResult) {
Zend_Registry::get('firebug')->info('MISE A JOUR PROFIL DANS SESSION');
$identity = $this->updateProfil($identity->username, $identity->password);
$auth->getStorage()->write($identity);
}
//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);
Zend_Registry::get('firebug')->info('MAJ MODE EDITION SESSION');
}
}
}
2011-05-03 12:49:43 +00:00
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;
}
$this->view->assign('isAdmin', $isAdmin);
$isSuperAdmin = false;
if ($identity->profil == 'SuperAdministrateur') {
$isSuperAdmin = true;
}
$this->view->assign('isSuperAdmin', $isSuperAdmin);
2011-09-09 08:28:42 +00:00
Zend_Registry::get('firebug')->info('action : '.$action);
2011-08-05 13:19:01 +00:00
if ($op=='new'){
Zend_Registry::get('firebug')->info('Gestion first user SD');
$idClient = $request->getParam('idClient');
$reponse = $ws->getListeClients($idClient);
$InfosClient = $reponse->result->item[0];
2011-08-05 14:40:21 +00:00
$options->idClient = $idClient;
$this->view->assign('options', $options);
2011-08-05 13:19:01 +00:00
$this->view->assign('loginNew', $InfosClient->racineLogin);
2011-08-05 13:43:39 +00:00
$this->view->assign('droitsClients', explode(' ', strtolower($InfosClient->droits)));
2011-08-05 13:19:01 +00:00
$this->view->assign('action', 'new');
$this->view->assign('pref', array());
}elseif (!empty($action) || $action!='new') {
if ( !empty($login) && $identity->username != $login ) {
Zend_Registry::get('firebug')->info('getInfosLogin');
$reponse = $ws->getInfosLogin($login);
$this->view->assign('options', $reponse->result);
$this->view->assign('loginVu', $reponse->result->login);
2011-08-05 13:43:39 +00:00
$this->view->assign('droits', explode(' ', strtolower($reponse->result->droits)));
$this->view->assign('droitsClients', explode(' ', $reponse->result->droitsClients));
} else {
$this->view->assign('options', $identity);
$this->view->assign('loginVu', $identity->username);
2011-08-05 13:43:39 +00:00
$this->view->assign('droits', explode(' ', strtolower($identity->droits)));
$this->view->assign('droitsClients', explode(' ', $identity->droitsClients));
}
2011-04-01 12:14:40 +00:00
$this->view->assign('loginNew', '');
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($identity->username);
2011-04-01 12:14:40 +00:00
$this->view->assign('loginNew', $reponse->result->racine);
2011-08-05 13:43:39 +00:00
$this->view->assign('droitsClients', explode(' ', strtolower($reponse->result->droitsClients)));
2011-04-01 12:14:40 +00:00
$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-06-27 12:56:19 +00:00
/**
* Renvoi vers le wiki
*/
public function documentationAction()
{
$user = new Utilisateur();
$login = $user->getLogin();
$password = $user->getPassword();
$url = 'http://infos.scores-decisions.com/?do=login&u='.$login.'&p='.$password;
$this->_redirect($url);
}
2011-05-23 10:04:12 +00:00
/**
* Téléchargement de la consommation au format CSV
*/
2011-05-23 06:45:29 +00:00
public function consoAction()
{
$this->view->headScript()->appendFile('/themes/default/scripts/conso.js', 'text/javascript');
2011-05-23 10:04:12 +00:00
$user = new Utilisateur();
$request = $this->getRequest();
$idClient = $request->getParam('idClient', $user->getIdClient());
$login = $request->getParam('login', '');
$this->view->assign('idClient', $idClient);
$this->view->assign('login', $login);
2011-05-23 10:04:12 +00:00
$this->view->assign('profil', $user->getProfil());
2011-05-23 06:45:29 +00:00
}
/**
* Renvoi vers le formulaire utilisateur avec les paramètres de la requete
*/
2011-05-03 15:58:48 +00:00
public function editAction()
{
$params = $this->getRequest()->getParams();
$this->_forward('index', 'user', null, $params);
2011-05-03 15:58:48 +00:00
}
/**
* Suppression d'un utilisateur
*/
2011-05-03 15:58:48 +00:00
public function deleteAction()
{
$request = $this->getRequest();
$login = $request->getParam('login');
$action = 'delete';
$ws = new WsScores();
$ws->setInfosLogin($login, $action);
//Redirect
$this->_forward('liste');
2011-05-03 15:58:48 +00:00
}
/**
* Activation d'un utilisateur
*/
2011-05-03 15:58:48 +00:00
public function activateAction()
{
$request = $this->getRequest();
$login = $request->getParam('login');
$action = 'actif';
$ws = new WsScores();
$ws->setInfosLogin($login, $action);
2011-05-04 13:24:26 +00:00
//Redirect
$this->_forward('liste');
2011-05-03 15:58:48 +00:00
}
/**
* Désactivation d'un utilisateur
*/
2011-05-03 15:58:48 +00:00
public function unactivateAction()
{
$request = $this->getRequest();
$login = $request->getParam('login');
$action = 'desactif';
$ws = new WsScores();
$ws->setInfosLogin($login, $action);
2011-05-04 13:24:26 +00:00
//Redirect
$this->_forward('liste');
2011-05-03 15:58:48 +00:00
}
/**
* Méthode AJAX pour modifier le password d'un utilisateur
*/
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-23 10:04:12 +00:00
/**
* Affiche la liste des utiliateurs
*/
public function listeAction()
2011-05-03 15:58:48 +00:00
{
$user = new Utilisateur();
$request = $this->getRequest();
$idClient = $request->getParam('idClient', $user->getIdClient());
2011-05-03 15:58:48 +00:00
if (!$user->isSuperAdmin() && !$user->isAdmin()) {
2011-09-06 09:12:50 +00:00
$this->renderScript('error/perms.phtml');
2011-05-03 15:58:48 +00:00
}
if ($user->isAdmin()){
$idClient = $user->getIdClient();
}
2011-05-03 15:58:48 +00:00
$ws = new WsScores();
$infos = $ws->getListeUtilisateurs($user->getLogin(), $idClient);
2011-05-03 15:58:48 +00:00
$utilisateurs = $infos->result->item;
$this->view->assign('utilisateurs', $utilisateurs);
$this->view->assign('idClient', $idClient);
2011-05-03 15:58:48 +00:00
}
2011-05-23 10:04:12 +00:00
/**
* Gestion de l'authentification
*/
2011-05-03 15:58:48 +00:00
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
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-09-07 14:14:25 +00:00
$authAdapter = new WebAuthAdapter($login, md5($login.'|'.$pass));
2010-11-22 12:50:12 +00:00
$result = $auth->authenticate($authAdapter);
if (!$result->isValid()){
$this->view->message = '';
Zend_Registry::get('firebug')->info($result);
2010-11-22 12:50:12 +00:00
foreach ($result->getMessages() as $message) {
$this->view->message.= $message."<br/>";
}
} else {
2011-01-06 11:22:26 +00:00
$timeout = $auth->getIdentity()->timeout;
//Ecrit un cookie persistant valide pendant le temps definit
Zend_Session::rememberMe($timeout);
2011-01-06 11:22:26 +00:00
$storage = new Zend_Auth_Storage_Session();
$sessionNamespace = new Zend_Session_Namespace($storage->getNamespace());
$sessionNamespace->setExpirationSeconds($timeout);
$auth->setStorage($storage);
$url = '';
if (Zend_Session::namespaceIsset('login')){
$session = new Zend_Session_Namespace('login');
if (isset($session->url)) {
$url = $session->url;
}
}
if (!empty($url) && $url!='/user/login' && $url!='/localauth'){
$this->_redirect($url);
}
2010-11-22 12:50:12 +00:00
$this->_redirect('/');
}
}
}
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
2011-05-23 10:04:12 +00:00
/**
* Gestion de la déconnexion
*/
2011-02-21 08:45:13 +00:00
public function logoutAction()
{
2010-11-22 12:50:12 +00:00
Zend_Auth::getInstance()->clearIdentity();
$this->_helper->layout()->disableLayout();
$url = 'http://www.scores-decisions.com/';
$refresh = 5;
if (APPLICATION_ENV != 'production'){
$url = 'http://'.$_SERVER['SERVER_NAME'].$this->view->url(array(
'controller' => 'user',
'action' => 'login',
));
2011-09-09 08:28:42 +00:00
}
2011-09-09 08:28:42 +00:00
$this->view->assign('url', $url);
$this->view->headMeta()->appendHttpEquiv('refresh', '5; url='.$url);
$this->render('logout');
2010-11-22 12:50:12 +00:00
}
}