338 lines
7.3 KiB
PHP
338 lines
7.3 KiB
PHP
<?php
|
|
class Scores_Utilisateur
|
|
{
|
|
/**
|
|
* Identity
|
|
* @var stdClass
|
|
*/
|
|
protected $identity = null;
|
|
|
|
public function __construct()
|
|
{
|
|
$auth = Zend_Auth::getInstance();
|
|
if ( $auth->hasIdentity() ) {
|
|
$this->identity = $auth->getIdentity();
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Récupére les valeurs du profil depuis le webservice
|
|
* @param stdClass $InfosLogin
|
|
* @params string $password
|
|
* @return stdClass
|
|
*/
|
|
public function updateProfil($InfosLogin, $password = null)
|
|
{
|
|
$identity = new stdClass;
|
|
$identity->username = $InfosLogin->result->login;
|
|
if ($password === null) {
|
|
$identity->password = $this->identity->password;
|
|
} else {
|
|
$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->dateValidation = $InfosLogin->result->dateValidation;
|
|
$identity->nombreConnexions = $InfosLogin->result->nombreConnexions;
|
|
$identity->dateDerniereConnexion = $InfosLogin->result->dateDerniereConnexion;
|
|
$identity->dateDebutCompte = $InfosLogin->result->dateDebutCompte;
|
|
$identity->dateFinCompte = $InfosLogin->result->dateFinCompte;
|
|
$identity->ip = $_SERVER['REMOTE_ADDR'];
|
|
$identity->timeout = (!empty($InfosLogin->result->timeout)) ?
|
|
$InfosLogin->result->timeout : 1800;
|
|
$identity->time = time() + $identity->timeout;
|
|
$identity->modeEdition = false;
|
|
$identity->acceptationCGU = $InfosLogin->result->acceptationCGU;
|
|
$lang = in_array($InfosLogin->result->lang,array('fr','en')) ? $InfosLogin->result->lang : 'fr';
|
|
$identity->lang = $lang;
|
|
$identity->langtmp = $lang;
|
|
$identity->browser = $this->getBrowserInfo();
|
|
|
|
$this->identity = $identity;
|
|
|
|
return $identity;
|
|
}
|
|
|
|
/**
|
|
* Check if user is log in
|
|
* @return boolean
|
|
*/
|
|
public function isLog()
|
|
{
|
|
if ( $this->identity === null ) {
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
/**
|
|
* Détermine si l'utilisateur est Administrateur
|
|
*/
|
|
public function isAdmin()
|
|
{
|
|
if ($this->identity->profil == 'Administrateur'){
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
/**
|
|
* Détermine si l'utilisateur est SuperAdministrateur
|
|
*/
|
|
public function isSuperAdmin()
|
|
{
|
|
if ($this->identity->profil == 'SuperAdministrateur'){
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
/**
|
|
* Retourne le profile utilisateur
|
|
*/
|
|
public function getProfil()
|
|
{
|
|
return $this->identity->profil;
|
|
}
|
|
|
|
/**
|
|
* Retourne l'identifiant client
|
|
*/
|
|
public function getIdClient()
|
|
{
|
|
return $this->identity->idClient;
|
|
}
|
|
|
|
/**
|
|
* Retourne l'identifiant de l'utilisateur
|
|
*/
|
|
public function getId()
|
|
{
|
|
return $this->identity->id;
|
|
}
|
|
|
|
/**
|
|
* Retourne le login de l'utiliateur
|
|
*/
|
|
public function getLogin()
|
|
{
|
|
return $this->identity->username;
|
|
}
|
|
|
|
/**
|
|
* Retourne le password de l'utilisateur
|
|
*/
|
|
public function getPassword()
|
|
{
|
|
return $this->identity->password;
|
|
}
|
|
|
|
/**
|
|
* Retourne le nom de l'utiliateur
|
|
*/
|
|
public function getNom()
|
|
{
|
|
return $this->identity->nom;
|
|
}
|
|
|
|
/**
|
|
* Retourne le prénom de l'utiliateur
|
|
*/
|
|
public function getPrenom()
|
|
{
|
|
return $this->identity->prenom;
|
|
}
|
|
|
|
/**
|
|
* Retourne l'email de l'utilisateur
|
|
*/
|
|
public function getEmail()
|
|
{
|
|
return $this->identity->email;
|
|
}
|
|
|
|
/**
|
|
* Retourne le téléphone de l'utilisateur
|
|
*/
|
|
public function getTel()
|
|
{
|
|
return $this->identity->tel;
|
|
}
|
|
|
|
/**
|
|
* Retourne le fax de l'utilisateur
|
|
*/
|
|
public function getFax()
|
|
{
|
|
return $this->identity->fax;
|
|
}
|
|
|
|
/**
|
|
* Retourne le type de score
|
|
*/
|
|
public function getTypeScore()
|
|
{
|
|
if (isset($this->identity->typeScore)
|
|
&& !empty($this->identity->typeScore)){
|
|
return $this->identity->typeScore;
|
|
}
|
|
return '100';
|
|
}
|
|
|
|
/**
|
|
* Retourne le nombre de réponse
|
|
*/
|
|
public function getNbRep()
|
|
{
|
|
return $this->identity->nbReponses;
|
|
}
|
|
|
|
/**
|
|
* Retourne l'adresse Ip de l'utilisateur
|
|
*/
|
|
public function getIpAddress()
|
|
{
|
|
if ( !isset($this->identity->ip) || empty($this->identity->ip) ){
|
|
return $_SERVER['REMOTE_ADDR'];
|
|
}
|
|
return $this->identity->ip;
|
|
}
|
|
|
|
/**
|
|
* Retourne la date de dernière connexion
|
|
*/
|
|
public function getDateDerniereConnexion()
|
|
{
|
|
return $this->identity->dateDerniereConnexion;
|
|
}
|
|
|
|
/**
|
|
* Vérifie que l'utiliasteur a le mode edition
|
|
* @return boolean
|
|
*/
|
|
public function checkModeEdition()
|
|
{
|
|
//On vérfie le mode edition dans les permissions
|
|
if ( $this->checkPerm('edition') ) {
|
|
return true;
|
|
}
|
|
//On vérfie le mode edition dans la session
|
|
if ( $this->identity->modeEdition ) {
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
|
|
/**
|
|
* Vérifie que l'utilisateur possède bien un droits
|
|
* @param string $perm
|
|
* Le code de la permission
|
|
* @return boolean
|
|
*/
|
|
public function checkPerm($perm)
|
|
{
|
|
$hasPerm = false;
|
|
if (preg_match('/\b'.$perm.'\b/i', $this->identity->droits)){
|
|
$hasPerm = true;
|
|
}
|
|
return $hasPerm;
|
|
}
|
|
|
|
/**
|
|
* Vérifie que l'utilisateur à cocher cette préférence
|
|
* @param string $pref
|
|
*/
|
|
public function checkPref($pref)
|
|
{
|
|
$hasPref = false;
|
|
if (preg_match('/\b'.$pref.'\b/i', $this->identity->pref)){
|
|
$hasPref = true;
|
|
}
|
|
return $hasPref;
|
|
}
|
|
|
|
/**
|
|
* Retourne la langue par défaut du client
|
|
*/
|
|
public function getLang()
|
|
{
|
|
return $this->identity->lang;
|
|
}
|
|
|
|
/**
|
|
* Retourne la langue de l'interface du client
|
|
*/
|
|
public function getLangTmp()
|
|
{
|
|
return $this->identity->langtmp;
|
|
}
|
|
|
|
/**
|
|
* Sets interface's language new value
|
|
* @param $langtmp
|
|
*/
|
|
public function setLangTmp($langtmp)
|
|
{
|
|
$this->identity->langtmp = $langtmp;
|
|
}
|
|
|
|
/**
|
|
* Get browser information
|
|
*/
|
|
public function getBrowserInfo()
|
|
{
|
|
return $this->identity->browser;
|
|
}
|
|
|
|
/**
|
|
* Set browser information
|
|
* @param string $name
|
|
* @param string $version
|
|
* @param int $mobile
|
|
* @param string $screenSize
|
|
*/
|
|
public function setBrowserInfo($platform, $name, $version, $mobile, $screenSize = 'unknow')
|
|
{
|
|
//Save info to session
|
|
$browserInfo = new stdClass();
|
|
$browserInfo->platform = $platform;
|
|
$browserInfo->name = $name;
|
|
$browserInfo->version = $version;
|
|
$browserInfo->mobile = $mobile;
|
|
$browserInfo->screenSize = $screenSize;
|
|
$this->identity->browser = $browserInfo;
|
|
$auth = Zend_Auth::getInstance();
|
|
$auth->getStorage()->write($this->identity);
|
|
|
|
//Save info to database
|
|
$data = array(
|
|
'idClient' => $this->getIdClient(),
|
|
'login' => $this->getLogin(),
|
|
'dateInsert' => date('Y-m-d H:i:s'),
|
|
'platform' => $platform,
|
|
'browserName' => $name,
|
|
'browserVersion' => $version,
|
|
'isMobile' => $mobile,
|
|
'screenSize' => $screenSize
|
|
);
|
|
$clientstatM = new Application_Model_ClientStat();
|
|
$id = $clientstatM->insert($data);
|
|
Zend_Registry::get('firebug')->info('Insertion : '.$id);
|
|
}
|
|
|
|
} |