420 lines
13 KiB
PHP
420 lines
13 KiB
PHP
<?php
|
|
class UserController extends Zend_Controller_Action
|
|
{
|
|
/**
|
|
* Récupére les valeurs du profil depuis le webservice
|
|
* @param unknown_type $login
|
|
* @param unknown_type $password
|
|
*/
|
|
protected function updateProfil($login, $password)
|
|
{
|
|
Zend_Registry::get('firebug')->info('updateProfil');
|
|
$ws = new WsScores();
|
|
$InfosLogin = $ws->getInfosLogin($login);
|
|
$identity = new stdClass;
|
|
$identity->username = $login;
|
|
$identity->password = $password;
|
|
$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()
|
|
{
|
|
require_once 'Web/Forms/Login.php';
|
|
require_once 'Web/WebAuthAdapter.php';
|
|
require_once 'Scores/Utilisateur.php';
|
|
require_once 'Scores/WsScores.php';
|
|
|
|
$this->view->headLink()->appendStylesheet('/themes/default/styles/user.css', 'all');
|
|
}
|
|
|
|
/**
|
|
* Affiche le fomulaire d'edition des paramètres utilisateur
|
|
*/
|
|
public function indexAction()
|
|
{
|
|
$this->view->headLink()->appendStylesheet('/themes/default/styles/form.css', 'all');
|
|
$this->view->headScript()->appendFile('/themes/default/scripts/user.js', 'text/javascript');
|
|
|
|
$request = $this->getRequest();
|
|
|
|
$messages = '';
|
|
$isProfilUpdated = false;
|
|
$isPasswordUpdated = false;
|
|
$updateResult = false;
|
|
|
|
$ws = new WsScores();
|
|
|
|
$login = $request->getParam('login', '');
|
|
$op = $request->getParam('op');
|
|
|
|
if ($request->isPost()) {
|
|
$options = $request->getParam('frmOptions', '');
|
|
$action = $options['action'];
|
|
|
|
if ($login=='') $login = $options['login'];
|
|
|
|
//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 = strtolower($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);
|
|
$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[strtoupper($droit->code)] = $droit->desc;
|
|
}
|
|
$this->view->assign('droitsLib', $droitsLib);
|
|
|
|
//Liste de toutes les préférences
|
|
$listePrefs = $ws->getListePrefs();
|
|
$prefsLib = array();
|
|
foreach($listePrefs->item as $pref) {
|
|
$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(); 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) {
|
|
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');
|
|
}
|
|
}
|
|
}
|
|
|
|
if ($isProfilUpdated || $isPasswordUpdated) {
|
|
$this->view->assign('message', $message);
|
|
}
|
|
|
|
$isAdmin = false;
|
|
if ($identity->profil == 'Administrateur'
|
|
|| $identity->profil == 'SuperAdministrateur') {
|
|
$isAdmin = true;
|
|
}
|
|
$this->view->assign('isAdmin', $isAdmin);
|
|
|
|
$isSuperAdmin = false;
|
|
if ($identity->profil == 'SuperAdministrateur') {
|
|
$isSuperAdmin = true;
|
|
}
|
|
$this->view->assign('isSuperAdmin', $isSuperAdmin);
|
|
|
|
Zend_Registry::get('firebug')->info('action : '.$action);
|
|
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];
|
|
$options->idClient = $idClient;
|
|
$this->view->assign('options', $options);
|
|
$this->view->assign('loginNew', $InfosClient->racineLogin);
|
|
$this->view->assign('droitsClients', explode(' ', strtolower($InfosClient->droits)));
|
|
$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);
|
|
$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);
|
|
$this->view->assign('droits', explode(' ', strtolower($identity->droits)));
|
|
$this->view->assign('droitsClients', explode(' ', $identity->droitsClients));
|
|
}
|
|
$this->view->assign('loginNew', '');
|
|
$this->view->assign('action', 'update');
|
|
$this->view->assign('pref', explode(' ',$identity->pref));
|
|
} else {
|
|
$reponse = $ws->getNextLogin($identity->username);
|
|
$this->view->assign('loginNew', $reponse->result->racine);
|
|
$this->view->assign('droitsClients', explode(' ', strtolower($reponse->result->droitsClients)));
|
|
$this->view->assign('action', 'new');
|
|
$this->view->assign('pref', array());
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 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);
|
|
}
|
|
|
|
/**
|
|
* Téléchargement de la consommation au format CSV
|
|
*/
|
|
public function consoAction()
|
|
{
|
|
$this->view->headScript()->appendFile('/themes/default/scripts/conso.js', 'text/javascript');
|
|
|
|
$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);
|
|
$this->view->assign('profil', $user->getProfil());
|
|
}
|
|
|
|
/**
|
|
* Renvoi vers le formulaire utilisateur avec les paramètres de la requete
|
|
*/
|
|
public function editAction()
|
|
{
|
|
$params = $this->getRequest()->getParams();
|
|
$this->_forward('index', 'user', null, $params);
|
|
}
|
|
|
|
/**
|
|
* Suppression d'un utilisateur
|
|
*/
|
|
public function deleteAction()
|
|
{
|
|
$request = $this->getRequest();
|
|
$login = $request->getParam('login');
|
|
$action = 'delete';
|
|
$ws = new WsScores();
|
|
$ws->setInfosLogin($login, $action);
|
|
//Redirect
|
|
$this->_forward('liste');
|
|
}
|
|
|
|
/**
|
|
* Activation d'un utilisateur
|
|
*/
|
|
public function activateAction()
|
|
{
|
|
$request = $this->getRequest();
|
|
$login = $request->getParam('login');
|
|
$action = 'actif';
|
|
$ws = new WsScores();
|
|
$ws->setInfosLogin($login, $action);
|
|
//Redirect
|
|
$this->_forward('liste');
|
|
}
|
|
|
|
/**
|
|
* Désactivation d'un utilisateur
|
|
*/
|
|
public function unactivateAction()
|
|
{
|
|
$request = $this->getRequest();
|
|
$login = $request->getParam('login');
|
|
$action = 'desactif';
|
|
$ws = new WsScores();
|
|
$ws->setInfosLogin($login, $action);
|
|
//Redirect
|
|
$this->_forward('liste');
|
|
}
|
|
|
|
/**
|
|
* Méthode AJAX pour modifier le password d'un utilisateur
|
|
*/
|
|
public function changepwdAction()
|
|
{
|
|
//Redirect
|
|
}
|
|
|
|
/**
|
|
* Affiche la liste des utiliateurs
|
|
*/
|
|
public function listeAction()
|
|
{
|
|
$user = new Utilisateur();
|
|
|
|
$request = $this->getRequest();
|
|
$idClient = $request->getParam('idClient', $user->getIdClient());
|
|
|
|
if (!$user->isSuperAdmin() && !$user->isAdmin()) {
|
|
$this->renderScript('error/perms.phtml');
|
|
}
|
|
if ($user->isAdmin()){
|
|
$idClient = $user->getIdClient();
|
|
}
|
|
$ws = new WsScores();
|
|
$infos = $ws->getListeUtilisateurs($user->getLogin(), $idClient);
|
|
$utilisateurs = $infos->result->item;
|
|
$this->view->assign('utilisateurs', $utilisateurs);
|
|
$this->view->assign('idClient', $idClient);
|
|
}
|
|
|
|
/**
|
|
* Gestion de l'authentification
|
|
*/
|
|
public function loginAction()
|
|
{
|
|
//@todo : gestion des affichages particuliers pour les clients
|
|
$this->view->headTitle()->append('Connexion');
|
|
$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();
|
|
$authAdapter = new WebAuthAdapter($login, md5($login.'|'.$pass));
|
|
$result = $auth->authenticate($authAdapter);
|
|
if (!$result->isValid()){
|
|
$this->view->message = '';
|
|
Zend_Registry::get('firebug')->info($result);
|
|
foreach ($result->getMessages() as $message) {
|
|
$this->view->message.= $message."<br/>";
|
|
}
|
|
} else {
|
|
$timeout = $auth->getIdentity()->timeout;
|
|
|
|
//Ecrit un cookie persistant valide pendant le temps definit
|
|
Zend_Session::rememberMe($timeout);
|
|
|
|
$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);
|
|
}
|
|
$this->_redirect('/');
|
|
}
|
|
}
|
|
}
|
|
$this->_helper->layout()->disableLayout();
|
|
$this->render('login');
|
|
}
|
|
|
|
/**
|
|
* Gestion de la déconnexion
|
|
*/
|
|
public function logoutAction()
|
|
{
|
|
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',
|
|
));
|
|
}
|
|
|
|
$this->view->assign('url', $url);
|
|
$this->view->headMeta()->appendHttpEquiv('refresh', '5; url='.$url);
|
|
$this->render('logout');
|
|
}
|
|
|
|
/**
|
|
* Mettre à jour le mode edition en session sans refresh de la page
|
|
*/
|
|
public function editionsessionAction()
|
|
{
|
|
$this->_helper->layout()->disableLayout();
|
|
$this->_helper->viewRenderer->setNoRender(true);
|
|
$request = $this->getRequest();
|
|
$mode = $request->getParam('mode', 'false');
|
|
$auth = Zend_Auth::getInstance();
|
|
$identity = $auth->getIdentity();
|
|
if ($identity->idClient == 1) {
|
|
if ($mode == 'false') {
|
|
$identity->modeEdition = false;
|
|
echo 0;
|
|
} else {
|
|
$identity->modeEdition = true;
|
|
echo 1;
|
|
}
|
|
$auth->getStorage()->write($identity);
|
|
} else {
|
|
echo 0;
|
|
}
|
|
}
|
|
|
|
} |