2013-11-05 11:18:30 +00:00
< ? php
2014-09-12 14:57:26 +00:00
require_once 'framework/fwk.php' ;
2014-05-24 16:57:17 +00:00
require_once __DIR__ . '/Types.php' ;
2013-11-05 11:18:30 +00:00
2014-05-24 16:57:17 +00:00
class Gestion extends Scores_Ws_Server
2013-11-05 11:18:30 +00:00
{
/**
* Récupère les informations du profil connecté
* @ param string $login
* @ param string $ipUtilisateur
2015-07-06 14:03:16 +00:00
* @ param string $from
2013-11-05 11:18:30 +00:00
* @ return InfosLoginReturn
*/
2015-07-06 14:03:16 +00:00
public function getInfosLogin ( $login , $ipUtilisateur = '' , $from = null )
2013-11-05 11:18:30 +00:00
{
2015-07-06 14:03:16 +00:00
// --- Get User Ip
2014-10-13 09:45:43 +00:00
if ( empty ( $ipUtilisateur )) {
$ipUtilisateur = $_SERVER [ 'REMOTE_ADDR' ];
}
$this -> authIp = $ipUtilisateur ;
2015-07-06 14:03:16 +00:00
// --- Authenticate
2013-11-05 11:18:30 +00:00
$this -> authenticate ();
2015-07-06 14:03:16 +00:00
// --- Profil administrateur
$isAdmin = false ;
if ( in_array ( $this -> User -> profil , array ( 'Administrateur' , 'SuperAdministrateur' )) ) {
$isAdmin = true ;
}
// --- Consultation des infos d'un login
$isOtherUser = false ;
if ( ! empty ( $login ) && ! in_array ( $login , array ( $this -> User -> login , $this -> User -> email )) ) {
$isOtherUser = true ;
}
$error = new ErrorType ();
$result = new InfosLogin ();
if ( $isOtherUser && $isAdmin ) {
// --- Récupération des informations login
2015-10-02 09:12:27 +00:00
try {
$userM = new Application_Model_Sdv1Utilisateurs ();
$sql = $userM -> select ()
-> setIntegrityCheck ( false )
-> from ( array ( 'u' => 'utilisateurs' ), array (
'u.login' , 'u.id' , 'u.email' , 'u.password' , 'u.idClient' , 'u.typeCompte' , 'u.actif' ,
'u.filtre_ip' , 'u.profil' , 'u.civilite' , 'u.nom' , 'u.prenom' , 'u.tel' , 'u.fax' ,
'u.mobile' , 'u.pref' , 'u.rechRefType' , 'u.profil' , 'u.nombreConnexions' ,
'u.dateDerniereConnexion' , 'u.droits' , 'u.referenceParDefaut' , 'u.nbReponses' , 'u.lang' ,
'u.formatMail' , 'u.dateDebutCompte' , 'u.dateFinCompte' , 'u.accesWS' , 'u.acceptationCGU' ))
-> join ( array ( 'c' => 'clients' ), 'u.idClient = c.id' , array (
'c.droits AS droitsClients' , 'c.test AS clientTest' , 'c.typeScore' , 'c.timeout' ))
-> joinLeft ( array ( 's' => 'sdv1.utilisateurs_service' ), 'u.login=s.login' , array ( 'Service AS serviceCode' ))
-> joinLeft ( array ( 'v' => 'sdv1.clients_version' ), 'u.idClient=v.clientId' , array ( 'version' ))
-> where ( 'u.actif=?' , 1 )
-> where ( 'u.deleted=?' , 0 )
-> where ( 'c.actif=?' , 'Oui' ) -> where ( 'u.login=?' , $login );
$resultUser = $userM -> fetchRow ( $sql );
} catch ( Zend_Db_Exception $e ) {
if ( $this -> User -> id == 1 ) {
throw new SoapFault ( 'ERR' , $e -> getMessage ());
}
}
2015-07-06 14:03:16 +00:00
$timeOutSec = $resultUser -> timeout ;
if ( $timeOutSec == 0 ) $timeOutSec = 1800 ;
$result -> login = $resultUser -> login ;
$result -> id = $resultUser -> id ;
$result -> email = $resultUser -> email ;
$result -> typeCompte = $resultUser -> typeCompte ;
$result -> idClient = $resultUser -> idClient ;
$result -> filtre_ip = $resultUser -> filtre_ip ;
$result -> civilite = $resultUser -> civilite ;
$result -> nom = $resultUser -> nom ;
$result -> prenom = $resultUser -> prenom ;
2015-10-02 09:12:27 +00:00
$result -> raisonSociale = '' ;
$result -> siret = '' ;
$result -> adrNum = '' ;
$result -> adrIndRep = '' ;
$result -> adrTypeVoie = '' ;
$result -> adrLibVoie = '' ;
$result -> adrCp = '' ;
$result -> adrVille = '' ;
$result -> adrComp = '' ;
2015-07-06 14:03:16 +00:00
$result -> tel = $resultUser -> tel ;
$result -> fax = $resultUser -> fax ;
$result -> mobile = $resultUser -> mobile ;
$result -> pref = $resultUser -> pref ;
$result -> profil = $resultUser -> profil ;
2015-10-02 09:12:27 +00:00
$result -> dateInscription = '' ;
$result -> dateValidation = '' ;
2015-07-06 14:03:16 +00:00
$result -> nombreConnexions = $resultUser -> nombreConnexions ;
$result -> dateDerniereConnexion = $resultUser -> dateDerniereConnexion ;
$result -> droits = $resultUser -> droits ;
$result -> droitsClients = $resultUser -> droitsClients ;
$result -> timeout = $timeOutSec ;
$result -> clientTest = $resultUser -> clientTest ;
$result -> typeScore = $resultUser -> typeScore ;
$result -> nbReponses = $resultUser -> nbReponses ;
$result -> lang = $resultUser -> lang ;
$result -> formatMail = $resultUser -> formatMail ;
$result -> reference = $resultUser -> referenceParDefaut ;
$result -> dateDebutCompte = $resultUser -> dateDebutCompte ;
$result -> dateFinCompte = $resultUser -> dateFinCompte ;
2015-10-02 09:12:27 +00:00
$result -> maxFicheId = '' ;
2015-07-06 14:03:16 +00:00
}
// --- Récupération des données utilisateurs inscrite dans le server
else {
$result -> login = $this -> User -> login ;
$result -> id = $this -> User -> id ;
$result -> idClient = $this -> User -> idClient ;
$result -> email = $this -> User -> email ;
$result -> typeCompte = $this -> User -> typeCompte ;
$result -> filtre_ip = $this -> User -> filtre_ip ;
$result -> ipPasserelle = $this -> User -> ipConnexion ;
$result -> ipConnexion = $ipUtilisateur ;
$result -> civilite = $this -> User -> civilite ;
$result -> nom = $this -> User -> nom ;
$result -> prenom = $this -> User -> prenom ;
$result -> raisonSociale = '' ;
$result -> siret = '' ;
$result -> adrNum = '' ;
$result -> adrIndRep = '' ;
$result -> adrTypeVoie = '' ;
$result -> adrLibVoie = '' ;
$result -> adrCp = '' ;
$result -> adrVille = '' ;
$result -> adrComp = '' ;
$result -> tel = $this -> User -> tel ;
$result -> fax = $this -> User -> fax ;
$result -> mobile = $this -> User -> mobile ;
$result -> pref = $this -> User -> pref ;
$result -> profil = $this -> User -> profil ;
$result -> dateInscription = $this -> User -> dateInscription ;
$result -> dateValidation = $this -> User -> dateValidation ;
$result -> nombreConnexions = $this -> User -> nombreConnexions ;
$result -> dateDerniereConnexion = $this -> User -> dateDerniereConnexion ;
// v2 auth return an array
if ( is_array ( $this -> User -> droits ) ) {
$result -> droits = join ( ' ' , $this -> User -> droits );
} else {
$result -> droits = $this -> User -> droits ;
}
$result -> droitsClients = $this -> User -> droitsClients ;
$result -> timeout = $this -> User -> timeout ;
$result -> clientTest = $this -> User -> clientTest ;
$result -> typeScore = $this -> User -> typeScore ;
$result -> nbReponses = $this -> User -> nbReponses ;
$result -> lang = $this -> User -> lang ;
$result -> formatMail = $this -> User -> formatMail ;
$result -> reference = $this -> User -> referenceParDefaut ;
$result -> dateDebutCompte = $this -> User -> dateDebutCompte ;
$result -> dateFinCompte = $this -> User -> dateFinCompte ;
2015-10-02 09:12:27 +00:00
$result -> maxFicheId = '' ;
2015-07-06 14:03:16 +00:00
$result -> typeScore = $this -> User -> typeScore ;
$result -> acceptationCGU = $this -> User -> acceptationCGU ;
// --- On log l'accès à l'authentification
if ( $from == 'auth' ) {
$dateConnexion = date ( 'YmdHis' );
$data = array (
'login' => $this -> User -> login ,
'authenticate' => 'OK' ,
'ip' => $ipUtilisateur ,
'dateInsert' => $dateConnexion ,
);
try {
$authLogM = new Application_Model_Sdv1UtilisateursAuthLog ();
$authLogM -> insert ( $data );
} catch ( Zend_Db_Exception $e ) {
if ( $this -> User -> id == 1 ) {
throw new SoapFault ( 'ERR' , $e -> getMessage ());
}
}
// --- Date de dernière connexion
try {
$userM = new Application_Model_Sdv1Utilisateurs ();
$userM -> update ( array (
'dateDerniereConnexion' => $dateConnexion
), " id= " . $this -> User -> id );
} catch ( Zend_Db_Exception $e ) {
if ( $this -> User -> id == 1 ) {
throw new SoapFault ( 'ERR' , $e -> getMessage ());
}
}
}
}
// --- Retour
2013-11-05 11:18:30 +00:00
$output = new InfosLoginReturn ();
$output -> error = $error ;
$output -> result = $result ;
2015-07-06 14:03:16 +00:00
2013-11-05 11:18:30 +00:00
return $output ;
}
/**
* Recherche de login
* @ param string $idClient
* @ param string $query
* @ return string
*/
public function searchLogin ( $idClient , $query )
{
$this -> authenticate ();
$userM = new Application_Model_Sdv1Utilisateurs ();
$sql = $userM -> select ()
-> from ( $userM , array ( 'id' , 'login' , 'actif' , 'deleted' ))
-> where ( 'idClient=?' , $idClient )
-> where ( 'login LIKE "' . $query . '%"' )
-> limit ( 20 );
$result = $userM -> fetchAll ( $sql );
if ( $result -> count () > 0 ) {
return json_encode ( $result -> toArray ());
}
return false ;
}
/**
* Mise à jour des informations du profil connecté
* @ param string $login
* @ param string $action ( delete | enable | disable | changepwd | new | update )
* @ param string $infos
* @ return boolean
*/
public function setInfosLogin ( $login , $action , $infos = null )
{
$this -> authenticate ();
//Initialisation
$result = false ;
$infos = json_decode ( $infos , true );
//Get user infos
$userM = new Application_Model_Sdv1Utilisateurs ();
$row = $userM -> select () -> where ( 'login=?' , $login );
//isExist
if ( null === $row ) {
throw new SoapFault ( 'ERR' , " User doesn't exist " );
}
//isEditable
if ( $row -> accesWS == 1
2014-08-06 20:27:01 +00:00
&& ! in_array ( $this -> User -> profil , array ( 'Administrateur' , 'SuperAdministrateur' )) ) {
2013-11-05 11:18:30 +00:00
throw new SoapFault ( 'MSG' , " User not editable " );
}
//Make action
switch ( $action ) {
case 'delete' :
2014-08-06 20:27:01 +00:00
if ( $this -> User -> profil == 'Administrateur'
|| $this -> User -> profil == 'SuperAdministrateur' ) {
2013-11-05 11:18:30 +00:00
$tabUpdate = array ( 'deleted' => 1 , 'dateUpdate' => date ( 'Y-m-d H:i:s' ) );
2015-04-27 16:08:29 +00:00
$iDbCrm = new WDB ();
if ( $iDbCrm -> update ( 'sdv1.utilisateurs' , $tabUpdate , " login=' $login ' " )){
2013-11-05 11:18:30 +00:00
$result = true ;
}
}
break ;
case 'enable' :
case 'disable' :
2014-08-06 20:27:01 +00:00
if ( $this -> User -> profil == 'Administrateur'
|| $this -> User -> profil == 'SuperAdministrateur' ) {
2013-11-05 11:18:30 +00:00
$actif = 1 ;
if ( $action == 'disable' ) {
$actif = 0 ;
}
$tabUpdate = array ( 'actif' => $actif , 'dateUpdate' => date ( 'YmdHis' ) );
2015-04-27 16:08:29 +00:00
$iDbCrm = new WDB ();
if ( $iDbCrm -> update ( 'sdv1.utilisateurs' , $tabUpdate , " login=' $login ' " )){
2013-11-05 11:18:30 +00:00
$result = true ;
}
}
break ;
case 'changepwd' :
$tabUpdate = array (
'password' => stripslashes ( $infos [ 'password' ]),
'dateUpdate' => date ( 'Y-m-d H:i:s' )
);
2015-04-27 16:08:29 +00:00
$iDbCrm = new WDB ();
if ( $iDbCrm -> update ( 'sdv1.utilisateurs' , $tabUpdate , " login=' $login ' " , true )){
2013-11-05 11:18:30 +00:00
$result = true ;
}
break ;
case 'new' :
2014-08-06 20:27:01 +00:00
if ( $this -> User -> profil == 'Administrateur'
|| $this -> User -> profil == 'SuperAdministrateur' ) {
2013-11-05 11:18:30 +00:00
2015-04-27 16:08:29 +00:00
$iDbCrm = new WDB ();
$existLogin = $iDbCrm -> select ( 'sdv1.utilisateurs' , 'deleted' , 'login="' . $login . '"' , false , MYSQL_ASSOC );
2013-11-05 11:18:30 +00:00
if ( count ( $existLogin ) > 0 ) {
$message = " Utilisateur existant dans le référentiel " ;
if ( $existLogin [ 0 ][ 'deleted' ] == 1 ) {
$message .= " (supprimé) " ;
}
throw new SoapFault ( 'ERR' , $message );
}
$tabUpdate = array ();
2014-08-06 20:27:01 +00:00
$idClient = $this -> User -> idClient ;
if ( $this -> User -> profil == 'SuperAdministrateur' && $infos [ 'idClient' ] != '' ){
2013-11-05 11:18:30 +00:00
$idClient = $infos [ 'idClient' ];
}
$tabUpdate [ 'idClient' ] = $idClient ;
$tabUpdate [ 'login' ] = $login ;
$tabUpdate [ 'email' ] = strtolower ( stripslashes ( $infos [ 'email' ]));
$tabUpdate [ 'password' ] = stripslashes ( $infos [ 'password' ]);
$tabUpdate [ 'actif' ] = 0 ;
$tabUpdate [ 'deleted' ] = 0 ;
$typeCompte = 'PROD' ;
2014-08-06 20:27:01 +00:00
if ( $this -> User -> profil == 'SuperAdministrateur' && $infos [ 'typeCompte' ] == 'TEST' ){
2013-11-05 11:18:30 +00:00
$typeCompte = 'TEST' ;
}
$tabUpdate [ 'typeCompte' ] = $typeCompte ;
//@todo : See issue #0001209
/*
2014-08-06 20:27:01 +00:00
if ( $this -> User -> profil == 'SuperAdministrateur' && ! empty ( $infos [ 'filtre_ip' ])) {
2013-11-05 11:18:30 +00:00
$tabUpdate [ 'filtre_ip' ] = $infos [ 'filtre_ip' ];
} else {
$rep = $iDbCrm -> select ( 'clients' , 'filtre_ip' , " id=' $idClient ' " , false , MYSQL_ASSOC );
$tabUpdate [ 'filtre_ip' ] = $rep [ 0 ][ 'filtre_ip' ];
}
*/
//$tabUpdate['civilite'] = 'M';
$tabUpdate [ 'nom' ] = stripslashes ( $infos [ 'nom' ]);
$tabUpdate [ 'prenom' ] = stripslashes ( $infos [ 'prenom' ]);
//$tabUpdate['raisonSociale'] = '';
//$tabUpdate['siret'] = 00000000;
//adrNum
//adrIndRep
//adrTypeVoie
//adrLibVoie
//adrCp
//adrVille
//adrComp
$tabUpdate [ 'tel' ] = stripslashes ( $infos [ 'tel_fix' ]);
$tabUpdate [ 'fax' ] = stripslashes ( $infos [ 'tel_fax' ]);
$tabUpdate [ 'mobile' ] = stripslashes ( $infos [ 'tel_mob' ]);
$tabUpdate [ 'pref' ] = implode ( ' ' , $infos [ 'pref' ]);
$tabUpdate [ 'profil' ] = ( isset ( $infos [ 'profil' ])
|| ! in_array ( $infos -> profil , array ( 'SuperAdministrateur' , 'Administrateur' , 'Utilisateur' )) ) ?
$infos [ 'profil' ] : 'Utilisateur' ;
//dateInscription
//dateValidation
//nombreConnexions 0
//dateDerniereConnexion
$tabUpdate [ 'droits' ] = implode ( ' ' , $infos [ 'droits' ]);
$tabUpdate [ 'referenceParDefaut' ] = stripslashes ( $infos [ 'reference' ]);
$tabUpdate [ 'nbReponses' ] = $infos [ 'nbReponses' ];
$tabUpdate [ 'lang' ] = $infos [ 'lang' ];
2014-08-06 20:27:01 +00:00
if ( $this -> User -> profil == 'SuperAdministrateur' ) {
2013-11-05 11:18:30 +00:00
$tabUpdate [ 'formatMail' ] = $infos [ 'formatMail' ];
$tabUpdate [ 'lienExtranetMail' ] = $infos [ 'lienExtranetMail' ];
$tabUpdate [ 'listeEven' ] = $infos [ 'listeEven' ];
$tabUpdate [ 'dateDebutCompte' ] = $infos [ 'dateDebutCompte' ];
$tabUpdate [ 'dateFinCompte' ] = $infos [ 'dateFinCompte' ];
$tabUpdate [ 'accesWS' ] = $infos [ 'accesWS' ];
$tabUpdate [ 'rechRefType' ] = $infos [ 'rechRefType' ];
}
//lienSurvFic
//idSurvFic
//loginCptSurvFic
$tabUpdate [ 'dateInsert' ] = date ( 'YmdHis' );
//dateUpdate => MySql automatic update
2015-04-27 16:08:29 +00:00
$iDbCrm = new WDB ();
if ( $iDbCrm -> insert ( 'sdv1.utilisateurs' , $tabUpdate )){
2013-11-05 11:18:30 +00:00
$result = true ;
}
}
break ;
case 'update' :
//Don't update password if nothing is send
if ( ! empty ( $infos [ 'password' ])){
$tabUpdate [ 'password' ] = stripslashes ( $infos [ 'password' ]);
}
//Only this data could be updated by the user himself
$tabUpdate [ 'email' ] = stripslashes ( $infos [ 'email' ]);
$tabUpdate [ 'tel' ] = stripslashes ( $infos [ 'tel_fix' ]);
$tabUpdate [ 'fax' ] = stripslashes ( $infos [ 'tel_fax' ]);
$tabUpdate [ 'mobile' ] = stripslashes ( $infos [ 'tel_mb' ]);
$tabUpdate [ 'nbReponses' ] = $infos [ 'nbReponses' ];
if ( ! empty ( $infos [ 'lang' ])) {
$tabUpdate [ 'lang' ] = $infos [ 'lang' ];
}
$tabUpdate [ 'pref' ] = implode ( ' ' , $infos [ 'pref' ]);
//User with Administrateur or SuperAdministrateur can update these data
2014-08-06 20:27:01 +00:00
if ( $this -> User -> profil == 'Administrateur'
|| $this -> User -> profil == 'SuperAdministrateur' )
2013-11-05 11:18:30 +00:00
{
$tabUpdate [ 'droits' ] = implode ( ' ' , $infos [ 'droits' ]);
$tabUpdate [ 'nom' ] = stripslashes ( $infos [ 'nom' ]);
$tabUpdate [ 'prenom' ] = stripslashes ( $infos [ 'prenom' ]);
$tabUpdate [ 'referenceParDefaut' ] = stripslashes ( $infos [ 'reference' ]);
$tabUpdate [ 'profil' ] = isset ( $infos [ 'profil' ]) ? $infos [ 'profil' ] : 'Utilisateur' ;
}
//Only update as SuperAdministrateur
2014-08-06 20:27:01 +00:00
if ( $this -> User -> profil == 'SuperAdministrateur' )
2013-11-05 11:18:30 +00:00
{
$typeCompte = 'PROD' ;
2014-08-06 20:27:01 +00:00
if ( $this -> User -> profil == 'SuperAdministrateur' && $infos [ 'typeCompte' ] == 'TEST' ){
2013-11-05 11:18:30 +00:00
$typeCompte = 'TEST' ;
}
$tabUpdate [ 'typeCompte' ] = $typeCompte ;
$formatMail = 'txt1' ;
if ( ! empty ( $infos [ 'formatMail' ]) ) {
$formatMail = $infos [ 'formatMail' ];
}
$tabUpdate [ 'formatMail' ] = $formatMail ;
if ( array_key_exists ( 'lienExtranetMail' , $infos ) && ! empty ( $infos [ 'lienExtranetMail' ])) {
$tabUpdate [ 'lienExtranetMail' ] = $infos [ 'lienExtranetMail' ];
}
if ( array_key_exists ( 'listeEven' , $infos ) && ! empty ( $infos [ 'listeEven' ])) {
$tabUpdate [ 'listeEven' ] = $infos [ 'listeEven' ];
}
if ( array_key_exists ( 'dateDebutCompte' , $infos ) && ! empty ( $infos [ 'dateDebutCompte' ])) {
$tabUpdate [ 'dateDebutCompte' ] = $infos [ 'dateDebutCompte' ];
}
if ( array_key_exists ( 'dateFinCompte' , $infos ) && ! empty ( $infos [ 'dateFinCompte' ])) {
$tabUpdate [ 'dateFinCompte' ] = $infos [ 'dateFinCompte' ];
}
if ( array_key_exists ( 'accesWS' , $infos ) && ! empty ( $infos [ 'accesWS' ])) {
$tabUpdate [ 'accesWS' ] = $infos [ 'accesWS' ];
}
$rechRefType = 'UTI' ;
if ( array_key_exists ( 'rechRefType' , $infos ) && ! empty ( $infos [ 'rechRefType' ])) {
$rechRefType = $infos [ 'rechRefType' ];
}
$tabUpdate [ 'rechRefType' ] = $rechRefType ;
}
$tabUpdate [ 'dateUpdate' ] = date ( 'YmdHis' );
2015-04-27 16:08:29 +00:00
$iDbCrm = new WDB ();
if ( $iDbCrm -> update ( 'sdv1.utilisateurs' , $tabUpdate , " login=' $login ' " , true )){
2013-11-05 11:18:30 +00:00
$result = true ;
}
break ;
default : $result = false ; break ;
}
return $result ;
}
/**
* Obtention automatique d ' un nouveau login pour un client
* @ param int idClient
* @ return NextLoginReturn
*/
public function getNextLogin ( $idClient )
{
$this -> authenticate ();
//Initialisation
$error = new ErrorType ();
2014-08-06 20:27:01 +00:00
if ( $this -> User -> profil == 'Administrateur'
|| $this -> User -> profil == 'SuperAdministrateur' )
2013-11-05 11:18:30 +00:00
{
/** Un administrateur veut créer un nouveau login **/
2015-04-27 16:08:29 +00:00
$iDbCrm = new WDB ();
$rep = $iDbCrm -> select ( 'sdv1.clients c' , 'c.racineLogin, c.droits' , " c.id=' $idClient ' " );
2013-11-05 11:18:30 +00:00
$racine = $rep [ 0 ][ 'racineLogin' ];
$droitsClients = $rep [ 0 ][ 'droits' ];
2015-04-27 16:08:29 +00:00
$rep = $iDbCrm -> select ( 'sdv1.utilisateurs' , 'login' , " idClient=' $idClient ' " );
2013-11-05 11:18:30 +00:00
if ( count ( $rep ) == 0 ) {
$racine .= '1' ;
} else {
$last_i = count ( $rep );
$cpt = 1 ;
while ( true ) {
$racine .= $last_i + $cpt ;
2015-04-27 16:08:29 +00:00
$rep = $iDbCrm -> select ( 'sdv1.utilisateurs' , 'login' , " idClient=' $idClient ' AND login=' $racine ' " );
2013-11-05 11:18:30 +00:00
if ( count ( $rep ) == 0 ) break ;
$cpt ++ ;
}
}
$result = new NextLoginResult ();
$result -> racine = $racine ;
$result -> idClient = $idClient ;
$result -> droitsClients = $droitsClients ;
} else {
$error -> errnum = 0 ;
$error -> errmsg = 'Acces non authorisé!' ;
}
$output = new NextLoginReturn ();
$output -> error = $error ;
$output -> result = $result ;
return $output ;
}
/**
* Récupère la liste des clients ou les informations d ' un client
* @ param integer | boolean $idClient
* @ param ClientFiltre $filtre
* @ return ListeClientsReturn
*/
public function getListeClients ( $idClient = false , $filtre = null )
{
$this -> authenticate ();
//Initialisation
$error = new ErrorType ();
if ( empty ( $idClient )) $idClient = false ;
$isAuthorized = false ;
2014-08-06 20:27:01 +00:00
if ( $this -> User -> profil == 'Administrateur' &&
( $idClient == 'false' || $idClient == $this -> User -> idClient )){
$idClient = $this -> User -> idClient ;
2013-11-05 11:18:30 +00:00
$isAuthorized = true ;
}
2014-08-06 20:27:01 +00:00
if ( $this -> User -> profil <> 'SuperAdministrateur' ){
2013-11-05 11:18:30 +00:00
$error -> errnum = 1 ;
$error -> errmsg = 'Profil non administrateur' ;
} else {
$isAuthorized = true ;
}
if ( $isAuthorized )
{
$strClient = '' ;
if ( is_numeric ( $idClient )) $strClient .= " AND id=' $idClient ' " ;
2015-04-27 16:08:29 +00:00
$iDbCrm = new WDB ();
$rep = $iDbCrm -> select ( 'sdv1.clients' ,
2013-11-05 11:18:30 +00:00
'id, nom, actif, test, racineLogin, siren, nic, tva, editerFacture, fact_detail, fac_dest, fac_adr1, fac_adr2, fac_adr3, fac_email, fac_tel, fact_rib, liv_dest, liv_adr1, liv_adr2, liv_adr3, liv_email, liv_tel, droits, filtres_ip, dateInsert, dateUpdate, respComSD, typeContrat, dateSignature, typeAcces, typeScore, timeout, accesPieces, accesKbis, accesInvestigations, accesInternationnal, accesEnquetes, miseSousSurveillance, forfaitExtranetPeriode, forfaitExtranetMontant, reconductionAuto, remarque, forfaitPiecesNb, forfaitPiecesMt, forfaitPiecesDep, forfaitInvestigNb, forfaitInvestigMt, forfaitInvestigDep, tarifIndiscore' ,
" 1 $strClient " ,
false ,
MYSQL_ASSOC );
$tabRet = array ();
foreach ( $rep as $uti )
{
$client = new Client ();
$client -> idClient = $uti [ 'id' ];
$client -> nom = $uti [ 'nom' ];
$client -> actif = $uti [ 'actif' ];
$client -> test = $uti [ 'test' ];
$client -> racineLogin = $uti [ 'racineLogin' ];
$client -> siren = $uti [ 'siren' ];
$client -> nic = $uti [ 'nic' ];
$client -> tva = $uti [ 'tva' ];
$client -> editerFacture = $uti [ 'editerFacture' ];
$client -> fact_detail = $uti [ 'fact_detail' ];
$client -> fac_dest = $uti [ 'fac_dest' ];
$client -> fac_adr1 = $uti [ 'fac_adr1' ];
$client -> fac_adr2 = $uti [ 'fac_adr2' ];
$client -> fac_adr3 = $uti [ 'fac_adr3' ];
$client -> fac_email = $uti [ 'fac_email' ];
$client -> fac_tel = $uti [ 'fac_tel' ];
$client -> fact_rib = $uti [ 'fact_rib' ];
$client -> liv_dest = $uti [ 'liv_dest' ];
$client -> liv_adr1 = $uti [ 'liv_adr1' ];
$client -> liv_adr2 = $uti [ 'liv_adr2' ];
$client -> liv_adr3 = $uti [ 'liv_adr3' ];
$client -> liv_email = $uti [ 'liv_email' ];
$client -> liv_tel = $uti [ 'liv_tel' ];
$client -> droits = strtolower ( $uti [ 'droits' ]);
$client -> timeout = $uti [ 'timeout' ];
$client -> filtres_ip = $uti [ 'filtres_ip' ];
$client -> dateInsert = $uti [ 'dateInsert' ];
$client -> dateUpdate = $uti [ 'dateUpdate' ];
$client -> respComSD = $uti [ 'respComSD' ];
$client -> typeContrat = $uti [ 'typeContrat' ];
$client -> dateSignature = $uti [ 'dateSignature' ];
$client -> typeAcces = $uti [ 'typeAcces' ];
$client -> typeScore = $uti [ 'typeScore' ];
$client -> accesPieces = $uti [ 'accesPieces' ];
$client -> accesKbis = $uti [ 'accesKbis' ];
$client -> accesInvestigations = $uti [ 'accesInvestigations' ];
$client -> accesInternationnal = $uti [ 'accesInternationnal' ];
$client -> accesEnquetes = $uti [ 'accesEnquetes' ];
$client -> miseSousSurveillance = $uti [ 'miseSousSurveillance' ];
$client -> forfaitExtranetPeriode = $uti [ 'forfaitExtranetPeriode' ];
$client -> forfaitExtranetMontant = $uti [ 'forfaitExtranetMontant' ];
$client -> reconductionAuto = $uti [ 'reconductionAuto' ];
$client -> remarque = $uti [ 'remarque' ];
$client -> forfaitPiecesNb = $uti [ 'forfaitPiecesNb' ];
$client -> forfaitPiecesMt = $uti [ 'forfaitPiecesMt' ];
$client -> forfaitPiecesDep = $uti [ 'forfaitPiecesDep' ];
$client -> forfaitInvestigNb = $uti [ 'forfaitInvestigNb' ];
$client -> forfaitInvestigMt = $uti [ 'forfaitInvestigMt' ];
$client -> forfaitInvestigDep = $uti [ 'forfaitInvestigDep' ];
$client -> tarifIndiscore = $uti [ 'tarifIndiscore' ];
$tabRet [] = $client ;
}
}
$output = new ListeClientsReturn ();
$output -> error = $error ;
$output -> result = $tabRet ;
return $output ;
}
/**
* Retourne la liste des droits
* @ return ListeDroitsReturn []
*/
public function getListeDroits ()
{
$tabRet = array ();
foreach ( $this -> listeDroits as $code => $desc ){
$droit = new ListeDroitsReturn ();
$droit -> code = $code ;
$droit -> desc = $desc ;
$tabRet [] = $droit ;
}
return $tabRet ;
}
/**
* Catégorie des accès
* @ param string $code
* @ return ListCategoryReturn []
*/
public function getCategory ( $code = null )
{
$tabRet = array ();
foreach ( $this -> listeCategory as $code => $desc ){
$c = new ListCategoryReturn ();
$c -> code = $code ;
$c -> desc = $desc [ 'label' ];
$c -> droits = $desc [ 'droits' ];
$tabRet [] = $c ;
}
return $tabRet ;
}
/**
* Retourne la liste des préférences
* @ return ListePrefsReturn []
*/
public function getListePrefs ()
{
$tabRet = array ();
foreach ( $this -> listePrefs as $code => $desc ) {
$pref = new ListePrefsReturn ();
$pref -> code = $code ;
$pref -> desc = $desc ;
$tabRet [] = $pref ;
}
return $tabRet ;
}
/**
* Retourne la liste des logs
* @ return ListeLogsReturn []
*/
public function getLogs ()
{
$tabRet = array ();
foreach ( $this -> logs as $code => $desc ) {
$log = new ListeLogsReturn ();
$log -> code = $code ;
$log -> desc = $desc [ 'label' ];
$tabRet [] = $log ;
}
return $tabRet ;
}
/**
* Récupère les informations du profil connecté
* @ param string $login
* @ param int $idClient
* @ return ListeUtilisateursReturn
*/
public function getListeUtilisateurs ( $login , $idClient = null )
{
$this -> authenticate ();
//Initialisation
$error = new ErrorType ();
$tabRet = array ();
2014-08-06 20:27:01 +00:00
if ( $this -> User -> profil <> 'Administrateur' &&
$this -> User -> profil <> 'SuperAdministrateur' )
2013-11-05 11:18:30 +00:00
{
$error -> errnum = 1 ;
$error -> errmsg = 'Profil non administrateur' ;
} else {
2015-04-27 16:08:29 +00:00
$iDbCrm = new WDB ();
2013-11-05 11:18:30 +00:00
if ( ! isset ( $idClient )){
2015-04-27 16:08:29 +00:00
$rep = $iDbCrm -> select ( 'sdv1.utilisateurs' , 'idClient' , " login=' $login ' " );
2013-11-05 11:18:30 +00:00
$idClient = $rep [ 0 ][ 0 ];
}
if ( $idClient ==- 1 ) {
$error -> errnum = 1 ;
$error -> errmsg = 'idClient=0' ;
} else {
$rep = $iDbCrm -> select (
2015-04-27 16:08:29 +00:00
'sdv1.utilisateurs' ,
2013-11-05 11:18:30 +00:00
'id, idClient, login, email, actif, nom, prenom, referenceParDefaut' ,
" idClient=' $idClient ' AND deleted=0 ORDER BY login ASC " ,
false , MYSQL_ASSOC );
foreach ( $rep as $uti ){
$utilisateur = new Utilisateur ();
$utilisateur -> idUti = $uti [ 'id' ];
$utilisateur -> idClient = $uti [ 'idClient' ];
$utilisateur -> login = $uti [ 'login' ];
$utilisateur -> email = $uti [ 'email' ];
$utilisateur -> actif = $uti [ 'actif' ];
$utilisateur -> nom = $uti [ 'nom' ];
$utilisateur -> prenom = $uti [ 'prenom' ];
$utilisateur -> reference = $uti [ 'referenceParDefaut' ];
$tabRet [] = $utilisateur ;
}
}
}
$output = new ListeUtilisateursReturn ();
$output -> error = $error ;
$output -> result = $tabRet ;
return $output ;
}
/**
* getLogsClients
* @ param string $mois ( Format : AAAA - MM ou AAAA / MM )
* @ param int $detail
* @ param int $idClient
* @ param string $login
* @ param int $all
* @ return LogsClientsReturn
*/
public function getLogsClients ( $mois , $detail = 0 , $idClient = 0 , $login = '' , $all = 0 )
{
$this -> authenticate ();
//Initialisation
$error = new ErrorType ();
if ( empty ( $detail )) $detail = 0 ;
if ( empty ( $idClient )) $idClient = 0 ;
if ( empty ( $login )) $login = '' ;
if ( empty ( $all )) $all = 0 ;
$strDetail = $strClient = $strLogin = '' ;
// Vue détaillée ou uniquement les infos payantes
if ( $detail == 0 ) {
$detail = 'Non' ;
//$strDetail=" AND (page LIKE 'greffe_%' OR page LIKE 'inpi_%' OR page='kbis' OR page LIKE 'indiscore%' OR page='privileges' OR page='commandeAsso') AND (params<>'' OR page LIKE 'indiscore%' AND tarifIndiscore<>0) AND (params NOT LIKE '%erreur%' OR params LIKE '%erreur 17%') ";
$strDetail = ' AND ( ' ;
$pages = array ( 'greffe_actes' , 'greffe_bilans' , 'kbis' , 'indiscore' , 'indiscore2' , 'indiscore3' , 'rapport2' , 'rapport3' , 'privileges' , 'privcumul' );
$totalPages = count ( $pages );
$i = 0 ;
foreach ( $pages as $page ) {
switch ( $page )
{
case 'greffe_actes' :
case 'greffe_bilans' :
$strDetail .= " (l.page = ' " . $page . " ' AND l.params<>'' AND (l.params NOT LIKE '%erreur%' OR l.params LIKE '%erreur 17%')) " ;
break ;
case 'kbis' :
$strDetail .= " (l.page = ' " . $page . " ' AND l.params<>'' AND l.params<>'1/1/0//' AND l.params<>'0/1/0//') " ;
break ;
default :
$strDetail .= " (l.page = ' " . $page . " ') " ;
break ;
}
$i ++ ;
if ( $i < $totalPages ) {
$strDetail .= ' OR ' ;
}
}
$strDetail .= ' ) ' ;
} elseif ( $detail == 1 ) {
$detail = 'Oui' ;
}
// On veut uniquement le client précis
2014-08-06 20:27:01 +00:00
if ( $all && $this -> User -> profil == 'SuperAdministrateur' ) {
2013-11-05 11:18:30 +00:00
$all = 'Oui' ;
} else {
$all = 'Non' ;
}
// Pas d'idClient mentionné ou tentative sur autre client et non SAD
2014-08-06 20:27:01 +00:00
if ( $idClient == 0 || ( $idClient != $this -> User -> idClient && $this -> User -> profil != 'SuperAdministrateur' ) ){
$idClient = $this -> User -> idClient ;
2013-11-05 11:18:30 +00:00
}
$strClient = " AND u.idClient= $idClient " ;
// On veut uniquement le login précis
if ( $login != '' ) {
$strLogin = " AND l.login=' $login ' " ;
} else {
$login = 'Non' ;
}
// Dates de début et de fin
$mois = strtr ( $mois , array ( '-' => '' , '/' => '' ));
$annee = substr ( $mois , 0 , 4 );
$mois = substr ( $mois , 4 , 2 );
$dateDeb = date ( 'Y-m-d' , mktime ( 0 , 0 , 0 , $mois , 1 , $annee ));
$dateFin = date ( 'Y-m-t' , mktime ( 0 , 0 , 0 , $mois , 15 , $annee ));
$c = Zend_Registry :: get ( 'config' );
2016-01-25 14:51:07 +00:00
$fichierCsv = $c -> profil -> path -> shared . " /files/logs- $annee - $mois - $detail - $idClient - $login - $all .csv " ;
2013-11-05 11:18:30 +00:00
if ( file_exists ( $fichierCsv )
&& date ( 'Ymd' , filemtime ( $fichierCsv )) == date ( 'Ymd' )
&& filesize ( $fichierCsv ) > 60 ) {
$size = filesize ( $fichierCsv );
$erreur = false ;
$tabNom = array ();
$cache = 1 ;
} else {
2014-11-07 15:04:02 +00:00
$sql = " SELECT LOWER(l.login) as loginUti, page, l.siren, l.nic, l.params, l.dateHeure, u.idClient, c.nom, u.referenceParDefaut AS refUti
FROM sdv1 . logs l , sdv1 . utilisateurs u , sdv1 . clients c
WHERE 1 $strDetail $strClient $strLogin
AND dateHeure BETWEEN '$dateDeb 00:00:00' AND '$dateFin 23:59:59'
AND l . login = u . login AND u . idClient = c . id
2013-11-05 11:18:30 +00:00
ORDER BY l . login ASC , l . dateHeure ASC " ;
2016-01-25 14:51:07 +00:00
file_put_contents ( $c -> profil -> path -> shared . " /files/logs- $annee - $mois - $detail - $idClient - $login - $all .sql " , $sql );
exec ( " php " . APPLICATION_PATH . " /../scripts/jobs/sql2csv.php --sqlfile " . $c -> profil -> path -> shared . " /files/logs- $annee - $mois - $detail - $idClient - $login - $all .sql --csvfile $fichierCsv > /dev/null & " );
2013-11-05 11:18:30 +00:00
$size = $cache = 0 ;
}
$hostname = 'http://' . $_SERVER [ 'SERVER_NAME' ];
if ( $_SERVER [ 'SERVER_PORT' ] != '80' ){
$hostname .= ':' . $_SERVER [ 'SERVER_PORT' ];
}
$result = new LogsClients ();
$result -> Url = $hostname . " /fichier/logs/logs- $annee - $mois - $detail - $idClient - $login - $all .csv " ;
$result -> Taille = $size ;
$result -> Cache = $cache ;
$output = new LogsClientsReturn ();
$output -> error = $error ;
$output -> result = $result ;
return $output ;
}
/**
* Création / Modification d ' un client
* @ param string $infos
* @ return ClientReturn
*/
public function setClient ( $infos )
{
$this -> authenticate ();
$result = false ;
2015-07-06 14:03:16 +00:00
$nb = 0 ;
2013-11-05 11:18:30 +00:00
//Pas SuperAdministrateur
2014-08-06 20:27:01 +00:00
if ( $this -> User -> profil != 'SuperAdministrateur' ) {
2013-11-05 11:18:30 +00:00
throw new SoapFault ( 1 , 'Profil insuffisant pour cette méthode' );
} else {
$infos = json_decode ( $infos );
/**
* - Protéger les chaines de caractères
* - Gérer les champs select
*/
$idClient = null ;
$tabInfos = array ();
foreach ( $infos as $nom => $value )
{
switch ( $nom )
{
case 'idClient' :
$idClient = $value ;
break ;
case 'nom' :
$tabInfos [ 'nom' ] = $value ;
break ;
case 'actif' :
$tabInfos [ 'actif' ] = ( $value == 'Oui' ) ? 'Oui' : 'Non' ;
break ;
case 'test' :
$tabInfos [ 'test' ] = ( $value == 'Oui' ) ? 'Oui' : 'Non' ;
break ;
case 'racineLogin' :
$tabInfos [ 'racineLogin' ] = $infos -> racineLogin ;
break ;
case 'siren' :
$tabInfos [ 'siren' ] = ( int ) $value ;
break ;
case 'nic' :
$tabInfos [ 'nic' ] = ( int ) $value ;
break ;
case 'tva' :
$tabInfos [ 'tva' ] = $value ;
break ;
case 'idClientFacture' :
$tabInfos [ 'idClientFacture' ] = $value ;
break ;
case 'editerFacture' :
$tabInfos [ 'editerFacture' ] = ( $value == 'Non' ) ? 'Non' : 'Oui' ;
break ;
case 'fact_detail' :
$tabInfos [ 'fact_detail' ] = ( $value == 'Oui' ) ? 'Oui' : 'Non' ;
break ;
case 'fac_dest' :
$tabInfos [ 'fac_dest' ] = $value ;
break ;
case 'fac_adr1' :
$tabInfos [ 'fac_adr1' ] = $value ;
break ;
case 'fac_adr2' :
$tabInfos [ 'fac_adr2' ] = $value ;
break ;
case 'fac_adr3' :
$tabInfos [ 'fac_adr3' ] = $value ;
break ;
case 'fac_email' :
$tabInfos [ 'fac_email' ] = $value ;
break ;
case 'fac_tel' :
$tabInfos [ 'fac_tel' ] = $value ;
break ;
case 'fact_rib' :
if ( in_array ( $value , array ( 'BPOSTALE' , 'CCOOP' , 'CDNORD' ))){
$tabInfos [ 'fact_rib' ] = $value ;
}
break ;
case 'liv_dest' :
$tabInfos [ 'liv_dest' ] = $value ;
break ;
case 'liv_adr1' :
$tabInfos [ 'liv_adr1' ] = $value ;
break ;
case 'liv_adr2' :
$tabInfos [ 'liv_adr2' ] = $value ;
break ;
case 'liv_adr3' :
$tabInfos [ 'liv_adr3' ] = $value ;
break ;
case 'liv_email' :
$tabInfos [ 'liv_email' ] = $value ;
break ;
case 'liv_tel' :
$tabInfos [ 'liv_tel' ] = $value ;
break ;
case 'droits' :
if ( count ( $value ) > 0 ){
$tabInfos [ 'droits' ] = strtolower ( implode ( ' ' , $value ));
} else {
$tabInfos [ 'droits' ] = array ();
}
break ;
case 'filtres_ip' :
2015-04-09 14:45:46 +00:00
$tabInfos [ 'filtres_ip' ] = trim ( $value , ';' );
2013-11-05 11:18:30 +00:00
break ;
case 'typeContrat' :
if ( in_array ( $value , array ( 'Contrat' , 'Marché' ))){
$tabInfos [ 'typeContrat' ] = $value ;
}
break ;
case 'typeAcces' :
if ( in_array ( $value , array ( 'userPassword' , 'userPasswordIP' , 'IP' ))){
$tabInfos [ 'typeAcces' ] = $value ;
}
break ;
case 'typeScore' :
if ( in_array ( $value , array ( '20' , '100' ))){
$tabInfos [ 'typeScore' ] = $value ;
}
break ;
case 'timeout' :
if ( ! empty ( $value )){
$tabInfos [ 'timeout' ] = $value ;
}
break ;
case 'accesPieces' :
$tabInfos [ 'accesPieces' ] = ( $value == 'Oui' ) ? 'Oui' : 'Non' ;
break ;
case 'accesKbis' :
$tabInfos [ 'accesKbis' ] = ( $value == 'Oui' ) ? 'Oui' : 'Non' ;
break ;
case 'accesInvestigations' :
$tabInfos [ 'value' ] = ( $value == 'Oui' ) ? 'Oui' : 'Non' ;
break ;
case 'accesInternationnal' :
$tabInfos [ 'accesInternationnal' ] = ( $value == 'Oui' ) ? 'Oui' : 'Non' ;
break ;
case 'accesEnquetes' :
$tabInfos [ 'accesEnquetes' ] = ( $value == 'Oui' ) ? 'Oui' : 'Non' ;
break ;
case 'miseSousSurveillance' :
$tabInfos [ 'miseSousSurveillance' ] = ( $value == 'Oui' ) ? 'Oui' : 'Non' ;
break ;
case 'forfaitExtranetPeriode' :
if ( in_array ( $value , array ( 'Mensuel' , 'Trimestriel' , 'Semestriel' , 'Annuel' ))){
$tabInfos [ 'forfaitExtranetPeriode' ] = $value ;
}
break ;
case 'forfaitExtranetMontant' :
$tabInfos [ 'forfaitExtranetMontant' ] = $value ;
break ;
case 'reconductionAuto' :
if ( $value == 'Non' ) {
$tabInfos [ 'reconductionAuto' ] = 'Non' ;
}
break ;
case 'remarque' :
$tabInfos [ 'remarque' ] = $value ;
break ;
case 'forfaitPiecesNb' :
$tabInfos [ 'forfaitPiecesNb' ] = $value ;
break ;
case 'forfaitPiecesMt' :
$tabInfos [ 'forfaitPiecesMt' ] = $value ;
break ;
case 'forfaitPiecesDep' :
$tabInfos [ 'forfaitPiecesDep' ] = $value ;
break ;
case 'forfaitInvestigNb' :
$tabInfos [ 'forfaitInvestigNb' ] = $value ;
break ;
case 'forfaitInvestigMt' :
$tabInfos [ 'forfaitInvestigMt' ] = $value ;
break ;
case 'forfaitInvestigDep' :
$tabInfos [ 'forfaitInvestigDep' ] = $value ;
break ;
case 'tarifIndiscore' :
$tabInfos [ 'tarifIndiscore' ] = $value ;
break ;
case 'InterSudLogin' :
$tabInfos [ 'InterSudLogin' ] = $value ;
break ;
case 'InterSudPass' :
$tabInfos [ 'InterSudPass' ] = $value ;
break ;
}
}
2015-04-27 16:08:29 +00:00
$iDbCrm = new WDB ();
2013-11-05 11:18:30 +00:00
if ( empty ( $idClient )){
2015-07-06 14:03:16 +00:00
// --- Ajout
2013-11-05 11:18:30 +00:00
$tabInfos [ 'dateInsert' ] = date ( 'Y-m-d H:i:s' );
2015-07-06 14:03:16 +00:00
try {
$clientM = new Application_Model_Sdv1Clients ();
$nb = $clientM -> insert ( $tabInfos );
} catch ( Zend_Db_Exception $e ) {
if ( $this -> User -> id == 1 ) {
throw new SoapFault ( 'ERR' , $e -> getMessage ());
} else {
throw new SoapFault ( 'ERR' , " Création impossible " );
}
}
2013-11-05 11:18:30 +00:00
} else {
2015-07-06 14:03:16 +00:00
// --- Droits client actuel avant modification
2013-11-05 11:18:30 +00:00
if ( isset ( $tabInfos [ 'droits' ]) ) {
2015-04-27 16:08:29 +00:00
$rep = $iDbCrm -> select ( 'sdv1.clients' , 'droits' , " id=' $idClient ' " , false , MYSQL_ASSOC );
2013-11-05 11:18:30 +00:00
$droitsPre = explode ( ' ' , $rep [ 0 ][ 'droits' ]);
$droitsSui = explode ( ' ' , $tabInfos [ 'droits' ]);
//Détection suppression d'un droit client
if ( count ( $droitsSui ) < count ( $droitsPre ) ) {
$droitsDiff = array_diff ( $droitsPre , $droitsSui );
//Modification sur les droits utilisateurs
if ( count ( $droitsDiff ) > 0 ){
$this -> _deleteAccess ( $droitsDiff , $idClient );
}
}
}
2015-07-06 14:03:16 +00:00
// --- Modification
2013-11-05 11:18:30 +00:00
$tabInfos [ 'dateUpdate' ] = date ( 'Y-m-d H:i:s' );
2015-07-06 14:03:16 +00:00
try {
$clientM = new Application_Model_Sdv1Clients ();
$nb = $clientM -> update ( $tabInfos , " id=' $idClient ' " );
} catch ( Zend_Db_Exception $e ) {
if ( $this -> User -> id == 1 ) {
throw new SoapFault ( 'ERR' , $e -> getMessage ());
} else {
throw new SoapFault ( 'ERR' , " Création impossible " );
}
2013-11-05 11:18:30 +00:00
}
}
}
2015-07-06 14:03:16 +00:00
if ( $nb > 0 ) {
$result = true ;
}
2013-11-05 11:18:30 +00:00
$output = new ClientReturn ();
$output -> error = $error ;
$output -> result = $result ;
return $output ;
}
/**
* Get all user params ( only for admin )
* @ param string $login
* @ return string
*/
public function getUser ( $login )
{
$this -> authenticate ();
2014-08-06 20:27:01 +00:00
if ( $this -> User -> profil != 'SuperAdministrateur' ) {
2013-11-05 11:18:30 +00:00
$this -> sendError ( '0901' );
}
try {
$userM = new Application_Model_Sdv1Utilisateurs ();
$sql = $userM -> select () -> where ( 'login = ?' , $login );
$rowset = $userM -> fetchRow ( $sql );
if ( $rowset ) {
$user = $rowset -> toArray ();
return json_encode ( $user );
} else {
throw new SoapFault ( '1' , 'Erreur' );
}
} catch ( Zend_Db_Exception $e ) {
throw new SoapFault ( 'Database' , $e -> getMessage ());
}
}
/**
* Enregistre l ' acceptation des CGU pour une application
* @ param string $application Nom de l ' outil utilisé
* @ return boolean
*/
public function setCGU ( $application = null )
{
$this -> authenticate ();
2014-08-06 20:27:01 +00:00
$idUser = $this -> User -> id ;
2013-11-05 11:18:30 +00:00
try {
$userM = new Application_Model_Sdv1Utilisateurs ();
$data = array ( 'acceptationCGU' => date ( 'YmdHis' ));
$result = $userM -> update ( $data , 'id=' . $idUser );
} catch ( Zend_Db_Exception $e ) {
throw new SoapFault ( 'Erreur' , $e -> getMessage ());
} catch ( Zend_Exception $e ) {
throw new SoapFault ( 'Erreur' , $e -> getMessage ());
}
if ( 1 == $result ) {
return true ;
}
return false ;
}
/**
* Definir la méthode de tarification
* @ param int $idClient Nom de l ' élément à facturer
* @ param ClientTarif $tarif Informations de facturation
* @ param int $id Identifiant pour l ' update
* @ return int
*/
public function setClientTarif ( $idClient , $tarif , $id = null )
{
/**
* Une tarification est toujours affecté à un élément $log .
* Celle ci est définie sur un compte client ( tous les utilisateurs ) ou un service ,
* Pour un type de facturation
* - Unitaire : Chaque élement est à facturer
* - Forfait limité : Si tarif unitaire > 0 alors on applique le prix unitaire pour chaque
* dépassement , sinon on coupe
* - Forfait illimité :
*/
$this -> authenticate ();
2014-08-06 20:27:01 +00:00
if ( $this -> User -> profil != 'SuperAdministrateur' ) {
2013-11-05 11:18:30 +00:00
$this -> sendError ( '0902' );
}
if ( ! in_array ( $tarif -> log , array_keys ( $this -> logs ))) {
throw new SoapFault ( 'ClientTarif' , 'log inexistant' );
}
if ( ! in_array ( $tarif -> type , array ( 'Unitaire' , 'ForfaitLimit' , 'ForfaitNoLimit' ))) {
throw new SoapFault ( 'ClientTarif' , 'Erreur type' );
}
if ( ! in_array ( $tarif -> doublon , array ( 'jour' , 'mois' , 'period' , 'none' ))) {
throw new SoapFault ( 'ClientTarif' , 'Erreur doublon' );
}
$time = mktime ( 0 , 0 , 0 , substr ( $tarif -> date , 4 , 2 ), substr ( $tarif -> date , 6 , 2 ), substr ( $tarif -> date , 0 , 4 ));
$data = array (
'idClient' => $idClient ,
'service' => $tarif -> service ,
'log' => $tarif -> log ,
'type' => $tarif -> type ,
'priceUnit' => $tarif -> priceUnit ,
'limit' => $tarif -> limit ,
'dateDebut' => date ( 'Y-m-d H:i:s' , $time ),
'duree' => $tarif -> duree ,
'doublon' => $tarif -> doublon ,
);
try {
$tarifM = new Application_Model_Sdv1ClientsTarifs ();
if ( null === $id ) {
$result = $tarifM -> insert ( $data );
} else {
$result = $tarifM -> update ( $data , 'id=' . $id );
}
} catch ( Zend_Db_Adapter_Exception $e ) {
2014-08-06 20:27:01 +00:00
if ( $this -> User -> idClient == 1 ) {
2013-11-05 11:18:30 +00:00
throw new SoapFault ( 'ERR' , $e -> getMessage ());
} else {
throw new SoapFault ( 'ERR' , " Application error " );
}
} catch ( Zend_Exception $e ) {
throw new SoapFault ( 'ERR' , " Application error " );
}
return $result ;
}
/**
* Get list of tarif
* @ param int $idClient
* @ param string $service
* @ throws SoapFault
* @ return ClientContrat []
*/
public function getClientTarifs ( $idClient , $service = null )
{
$this -> authenticate ();
if ( null === $service ) {
$service = 'DEFAULT' ;
}
//Liste dateDebut-duree disponible
$tarifM = new Application_Model_Sdv1ClientsTarifs ();
try {
$sql = $tarifM -> select () -> from ( $tarifM , array (
'dateDebut' ,
'duree'
))
-> where ( 'service=?' , $service )
-> order ( 'dateDebut DESC' )
-> group ( array ( 'dateDebut' , 'duree' ));
$contrats = $tarifM -> fetchAll ( $sql );
} catch ( Zend_Db_Exception $e ) {
2014-08-06 20:27:01 +00:00
if ( $this -> User -> idClient == 1 ) {
2013-11-05 11:18:30 +00:00
throw new SoapFault ( 'ERR' , $e -> getMessage ());
} else {
throw new SoapFault ( 'ERR' , " Application error " );
}
}
$listeContrat = array ();
//Retrouver les éléments à facturer
if ( count ( $contrats ) > 0 ) {
foreach ( $contrats as $contrat ) {
try {
$sql = $tarifM -> select ()
-> where ( 'idClient=?' , $idClient )
-> where ( 'service=?' , $service )
-> where ( 'dateDebut=?' , $contrat -> dateDebut )
-> where ( 'duree=?' , $contrat -> duree );
$rows = $tarifM -> fetchAll ( $sql );
} catch ( Zend_Db_Exception $e ) {
2014-08-06 20:27:01 +00:00
if ( $this -> User -> idClient == 1 ) {
2013-11-05 11:18:30 +00:00
throw new SoapFault ( 'ERR' , $e -> getMessage ());
} else {
throw new SoapFault ( 'ERR' , " Application error " );
}
}
$output = array ();
if ( $rows -> count () > 0 ) {
foreach ( $rows as $row ) {
$item = new ClientTarif ();
$item -> id = $row -> id ;
$item -> idClient = $row -> idClient ;
$item -> service = $row -> service ;
$item -> log = $row -> log ;
$item -> type = $row -> type ;
$item -> priceUnit = $row -> priceUnit ;
$item -> limit = $row -> limit ;
$item -> date = substr ( $row -> dateDebut , 0 , 10 );
$item -> duree = $row -> duree ;
$item -> doublon = $row -> doublon ;
$output [] = $item ;
}
}
$date = new Zend_Date ( $contrat -> dateDebut , false );
$dateBegin = $date -> toString ( 'Y-MM-dd' );
$dateEnd = $date -> add ( $contrat -> duree , Zend_Date :: DAY ) -> toString ( 'YYYY-MM-dd' );
$ElementContrat = new ClientContrat ();
$ElementContrat -> dateBegin = $dateBegin ;
$ElementContrat -> dateEnd = $dateEnd ;
$ElementContrat -> tarifs = $output ;
$listeContrat [] = $ElementContrat ;
}
}
return $listeContrat ;
}
/**
* Get a tarif and his details by date
* @ param string $log
* @ param int $idClient
* @ param string $service
* @ param string $date
* @ throws SoapFault
* @ return ClientTarif
*/
public function getClientTarif ( $log , $idClient , $service = 'default' , $date = null )
{
$this -> authenticate ();
if ( empty ( $service ) ) {
$service = 'default' ;
}
//Date not define, looks for the actual price
if ( empty ( $date ) ) {
}
try {
$tarifM = new Application_Model_Sdv1ClientsTarifs ();
$sql = $tarifM -> select ()
-> from ( $tarifM , array (
'id' , 'idClient' , 'service' , 'log' , 'type' , 'priceUnit' , 'limit' , 'dateDebut' ,
'duree' , 'doublon' , 'DATE_ADD(dateDebut, INTERVAL duree DAY) AS dateFin'
))
-> where ( 'log=?' , $log )
-> where ( 'idClient=?' , $idClient )
-> where ( 'service=?' , $service );
//->where('dateDebut<=?', $date);
//->where('dateFin>?',$date);
//@todo : get date between
$row = $tarifM -> fetchRow ( $sql );
} catch ( Zend_Db_Adapter_Exception $e ) {
2014-08-06 20:27:01 +00:00
if ( $this -> User -> idClient == 1 ) {
2013-11-05 11:18:30 +00:00
throw new SoapFault ( 'ERR' , $e -> getMessage ());
} else {
throw new SoapFault ( 'ERR' , " Application error " );
}
} catch ( Zend_Exception $e ) {
throw new SoapFault ( 'ERR' , " Application error " );
}
return $row ;
}
/**
* Liste des prestations pour un client
* @ param int $idClient
* @ return ClientPrestation []
* @ throws SoapFault
*/
public function getPrestations ( $idClient )
{
$this -> authenticate ();
//Read prestations
try {
$prestationsM = new Application_Model_Sdv1Prestations ();
$sql = $prestationsM -> select ()
-> from ( $prestationsM , array ( 'id' , 'typeprestation' , 'datemiseenplace' ,
'datefinprestation' , 'identifiantPrestation' , 'prestationactive' ))
-> where ( 'idClient=?' , $idClient );
$result = $prestationsM -> fetchAll ( $sql );
} catch ( Zend_Db_Exception $e ) {
2014-08-06 20:27:01 +00:00
if ( $this -> User -> idClient != 1 ) {
2013-11-05 11:18:30 +00:00
throw new SoapFault ( 'ERR' , " Application error " );
} else {
throw new SoapFault ( 'ERR' , $e -> getMessage ());
}
}
$output = array ();
if ( $result -> count () > 0 ) {
foreach ( $result as $item ) {
$clientprestation = new ClientPrestation ();
$clientprestation -> id = $item -> id ;
$clientprestation -> type = $item -> typeprestation ;
$clientprestation -> identifiant = $item -> identifiantPrestation ;
$clientprestation -> active = $item -> prestationactive ;
$clientprestation -> dateDebut = $item -> datemiseenplace ;
$clientprestation -> dateFin = $item -> datefinprestation ;
$output [] = $clientprestation ;
}
}
return $output ;
}
/**
* Liste des paramètres d ' une prestation
* @ param int $id
* @ return string
* @ throws SoapFault
*/
public function getPrestation ( $id )
{
$this -> authenticate ();
//Read prestations
try {
$prestationsM = new Application_Model_Sdv1Prestations ();
$sql = $prestationsM -> select () -> where ( 'id=?' , $id );
$result = $prestationsM -> fetchRow ( $sql );
if ( $result !== null ) {
return json_encode ( $result -> toArray ());
} else {
return '' ;
}
} catch ( Zend_Db_Exception $e ) {
2014-08-06 20:27:01 +00:00
if ( $this -> User -> idClient != 1 ) {
2013-11-05 11:18:30 +00:00
throw new SoapFault ( 'ERR' , " Application error " );
} else {
throw new SoapFault ( 'ERR' , $e -> getMessage ());
}
}
}
/**
* Enregistre les paramètres des la prestation
* @ param int $idClient
* @ param string $prestation
* @ return int
* @ throws SoapFault
*/
public function setPrestation ( $idClient , $prestation )
{
$this -> authenticate ();
2014-08-06 20:27:01 +00:00
if ( $this -> User -> profil != 'SuperAdministrateur' ) {
2013-11-05 11:18:30 +00:00
$this -> sendError ( '0902' );
}
$prestationParameters = json_decode ( $prestation , true );
//Insert or update a prestation
try {
$prestationsM = new Application_Model_Sdv1Prestations ();
//Update
if ( ! empty ( $prestationParameters [ 'id' ])) {
$id = $prestationParameters [ 'id' ];
unset ( $prestationParameters [ 'id' ]);
$result = $prestationsM -> update ( $prestationParameters , 'id=' . $id );
}
//Insert
else {
//@todo : Some control before save
$result = $prestationsM -> insert ( $prestationParameters );
}
} catch ( Zend_Db_Exception $e ) {
2014-08-06 20:27:01 +00:00
if ( $this -> User -> idClient != 1 ) {
2013-11-05 11:18:30 +00:00
throw new SoapFault ( 'ERR' , " Application error " );
} else {
throw new SoapFault ( 'ERR' , $e -> getMessage ());
}
}
return $result ;
}
/**
* Define a Service in Client
* @ param int $idClient
* @ param string $infos
* @ throws SoapFault
* @ return int
*/
public function setService ( $idClient , $infos = null )
{
$this -> authenticate ();
2014-08-06 20:27:01 +00:00
if ( $this -> User -> profil != 'SuperAdministrateur' ) {
2013-11-05 11:18:30 +00:00
$this -> sendError ( '0902' );
}
try {
$serviceM = new Application_Model_Sdv1ClientsServices ();
$dataIn = json_decode ( $infos , true );
$code = $dataIn [ 'code' ];
$label = $dataIn [ 'label' ];
$droits = $dataIn [ 'droits' ];
//Check if code exist in idClient
$sql = $serviceM -> select ()
-> where ( 'idClient=?' , $idClient )
-> where ( 'code=?' , $code );
$row = $serviceM -> fetchAll ( $sql );
if ( $row -> count () > 0 ) {
$data = array (
'label' => $label ,
'droits' => $droits
);
$result = $serviceM -> update ( $data , array ( 'idClient=' . $idClient , 'code=' . $code ));
//Delete
if ( isset ( $row -> droits ) ) {
$droitsPre = explode ( ' ' , $row -> droits );
$droitsSui = explode ( ' ' , $droits );
//Détection suppression d'un droit client
if ( count ( $droitsSui ) < count ( $droitsPre ) ) {
$droitsDiff = array_diff ( $droitsPre , $droitsSui );
//Modification sur les droits utilisateurs
if ( count ( $droitsDiff ) > 0 ){
$this -> _deleteAccess ( $droitsDiff , $idClient , $code );
}
}
}
} else {
$data = array (
'code' => $code ,
'label' => $label ,
'droits' => $droits ,
'idClient' => $idClient
);
$result = $serviceM -> insert ( $data );
}
} catch ( Zend_Db_Exception $e ) {
2014-08-06 20:27:01 +00:00
if ( $this -> User -> idClient == 1 ) {
2013-11-05 11:18:30 +00:00
throw new SoapFault ( 'ERR' , $e -> getMessage ());
} else {
throw new SoapFault ( 'ERR' , " Application error " );
}
}
return $result ;
}
/**
* Set a User in a Service
* @ param string $login
* @ param string $code
* @ throws SoapFault
* @ return int
*/
public function setUserService ( $login , $code )
{
$this -> authenticate ();
2014-08-06 20:27:01 +00:00
if ( $this -> User -> profil != 'SuperAdministrateur' ) {
2013-11-05 11:18:30 +00:00
$this -> sendError ( '0902' );
}
try {
$serviceM = new Application_Model_Sdv1UtilisateursService ();
//Check if a login exist
$sql = $serviceM -> select () -> where ( 'login=?' , $login );
$row = $serviceM -> fetchAll ( $sql );
if ( $row -> count () > 0 ) {
$data = array (
'serviceCode' => $code ,
);
$result = $serviceM -> update ( $data , 'login=' . $login );
} else {
$data = array (
'login' => $login ,
'serviceCode' => $code ,
);
$result = $serviceM -> insert ( $data );
}
} catch ( Zend_Db_Exception $e ) {
2014-08-06 20:27:01 +00:00
if ( $this -> User -> idClient == 1 ) {
2013-11-05 11:18:30 +00:00
throw new SoapFault ( 'ERR' , $e -> getMessage ());
} else {
throw new SoapFault ( 'ERR' , " Application error " );
}
}
//Override login right access - always
$serviceM = new Application_Model_Sdv1ClientsServices ();
$sql = $serviceM -> select () -> where ( 'code=?' , $code );
$serviceInfo = $serviceM -> fetchRow ( $sql );
if ( null !== $serviceInfo ) {
$userM = new Application_Model_Sdv1Utilisateurs ();
$userM -> update ( array ( 'droits' => $serviceInfo -> droits ), 'login=' . $login );
}
return $result ;
}
/**
* List Services
* @ param int $idClient
* @ throws SoapFault
* @ return Service []
*/
public function getServices ( $idClient )
{
$this -> authenticate ();
2014-08-06 20:27:01 +00:00
if ( $this -> User -> profil != 'SuperAdministrateur' ) {
2013-11-05 11:18:30 +00:00
$this -> sendError ( '0902' );
}
try {
$serviceM = new Application_Model_Sdv1ClientsServices ();
$sql = $serviceM -> select ()
-> where ( 'idClient=?' , $idClient )
-> order ( 'label ASC' );
$rows = $serviceM -> fetchAll ( $sql );
} catch ( Zend_Db_Adapter_Exception $e ) {
2014-08-06 20:27:01 +00:00
if ( $this -> User -> idClient == 1 ) {
2013-11-05 11:18:30 +00:00
throw new SoapFault ( 'ERR' , $e -> getMessage ());
} else {
throw new SoapFault ( 'ERR' , " Application error " );
}
} catch ( Zend_Exception $e ) {
throw new SoapFault ( 'ERR' , " Application error " );
}
$output = array ();
if ( $rows -> count () > 0 ) {
foreach ( $rows as $item ) {
$service = new Service ();
$service -> code = $item -> code ;
$service -> label = $item -> label ;
$output [] = $service ;
}
}
return $output ;
}
/**
* Get service parameters
* @ param int $idClient
* @ param string $code
* @ throws SoapFault
* @ return string | boolean
*/
public function getService ( $idClient , $code )
{
$this -> authenticate ();
2014-08-06 20:27:01 +00:00
if ( $this -> User -> profil != 'SuperAdministrateur' ) {
2013-11-05 11:18:30 +00:00
$this -> sendError ( '0902' );
}
try {
$serviceM = new Application_Model_Sdv1ClientsServices ();
$sql = $serviceM -> select ()
-> where ( 'idClient=?' , $idClient )
-> where ( 'serviceCode=?' , $code );
$row = $serviceM -> fetchRow ( $sql );
} catch ( Zend_Db_Adapter_Exception $e ) {
2014-08-06 20:27:01 +00:00
if ( $this -> User -> idClient == 1 ) {
2013-11-05 11:18:30 +00:00
throw new SoapFault ( 'ERR' , $e -> getMessage ());
} else {
throw new SoapFault ( 'ERR' , " Application error " );
}
} catch ( Zend_Exception $e ) {
throw new SoapFault ( 'ERR' , " Application error " );
}
if ( null !== $row ) {
return json_encode ( $row -> toArray ());
}
return false ;
}
/**
* Retourne la liste des utilisateurs par service
* @ param int $idClient
* @ param string $serviceCode
* @ throws SoapFault
* @ return Utilisateur []
*/
public function getServiceUsers ( $idClient , $serviceCode = null )
{
$this -> authenticate ();
if ( null === $serviceCode ) {
$serviceCode = 'DEFAULT' ;
}
2014-08-06 20:27:01 +00:00
if ( $this -> User -> profil != 'SuperAdministrateur' ) {
2013-11-05 11:18:30 +00:00
$this -> sendError ( '0902' );
}
$output = array ();
//Login by service
if ( $serviceCode != 'DEFAULT' ) {
//Check if service exist
try {
$servicesM = new Application_Model_Sdv1ClientsServices ();
$sql = $servicesM -> select ()
-> from ( $servicesM , array ( 'code' ))
-> where ( 'idClient=?' , $idClient );
$result = $servicesM -> fetchAll ( $sql );
if ( $result -> count () == 0 ) {
throw new SoapFault ( 'ERR' , 'Service inexistant' );
}
} catch ( Zend_Db_Adapter_Exception $e ) {
2014-08-06 20:27:01 +00:00
if ( $this -> User -> idClient == 1 ) {
2013-11-05 11:18:30 +00:00
throw new SoapFault ( 'ERR' , $e -> getMessage ());
} else {
throw new SoapFault ( 'ERR' , " Application error " );
}
} catch ( Zend_Exception $e ) {
throw new SoapFault ( 'ERR' , " Application error " );
}
//List login
try {
$userserviceM = new Application_Model_Sdv1UtilisateursService ();
$sql = $userserviceM -> select ()
-> where ( 'serviceCode=?' , $serviceCode )
-> order ( 'login ASC' );
$logins = $userserviceM -> fetchAll ( $sql );
} catch ( Zend_Db_Adapter_Exception $e ) {
2014-08-06 20:27:01 +00:00
if ( $this -> User -> idClient == 1 ) {
2013-11-05 11:18:30 +00:00
throw new SoapFault ( 'ERR' , $e -> getMessage ());
} else {
throw new SoapFault ( 'ERR' , " Application error " );
}
} catch ( Zend_Exception $e ) {
throw new SoapFault ( 'ERR' , " Application error " );
}
//Get login informations
$userM = new Application_Model_Sdv1Utilisateurs ();
if ( $logins -> count () > 0 ) {
foreach ( $logins as $login ) {
$sql = $userM -> select ()
-> where ( 'login=?' , $login -> login )
-> where ( 'deleted=0' );
$result = $userM -> fetchRow ( $sql );
$utilisateur = new Utilisateur ();
$utilisateur -> idUti = $result -> id ;
$utilisateur -> login = $result -> login ;
$utilisateur -> actif = $result -> actif ;
$utilisateur -> nom = $result -> nom ;
$utilisateur -> prenom = $result -> prenom ;
$utilisateur -> email = $result -> email ;
$utilisateur -> reference = $result -> reference ;
$output [] = $utilisateur ;
}
}
}
//Select all logins which have service to display only login without service
else {
$servicesM = new Application_Model_Sdv1ClientsServices ();
$sql = $servicesM -> select ()
-> from ( $servicesM , array ( 'code' ))
-> where ( 'idClient=?' , $idClient );
$result = $servicesM -> fetchAll ( $sql );
$codes = array ();
$notlogins = array ();
if ( $result -> count () > 0 ) {
foreach ( $result as $item ) {
$codes [] = $item -> code ;
}
}
if ( count ( $codes ) > 0 ) {
try {
$userserviceM = new Application_Model_Sdv1UtilisateursService ();
$sql = $userserviceM -> select ()
-> where ( 'serviceCode IN ("' . join ( ',' , $codes ) . '")' );
$result = $userserviceM -> fetchAll ( $sql );
} catch ( Zend_Exception $e ) {
2014-08-06 20:27:01 +00:00
if ( $this -> User -> idClient == 1 ) {
2013-11-05 11:18:30 +00:00
throw new SoapFault ( 'ERR' , $e -> getMessage ());
} else {
throw new SoapFault ( 'ERR' , " Application error " );
}
}
if ( $result -> count () > 0 ) {
foreach ( $result as $item ) {
$notlogins [] = $item -> login ;
}
}
}
$userM = new Application_Model_Sdv1Utilisateurs ();
if ( count ( $notlogins ) > 0 ) {
$sql = $userM -> select ()
-> from ( $userM , array ( 'id' , 'login' , 'actif' , 'nom' , 'prenom' , 'email' , 'referenceParDefaut' ))
-> where ( 'login NOT IN(' . join ( ',' , $notlogins ) . ')' )
-> where ( 'idClient=?' , $idClient )
-> where ( 'deleted=0' )
-> order ( 'login ASC' );
} else {
$sql = $userM -> select ()
-> from ( $userM , array ( 'id' , 'login' , 'actif' , 'nom' , 'prenom' , 'email' , 'referenceParDefaut' ))
-> where ( 'idClient=?' , $idClient )
-> where ( 'deleted=0' )
-> order ( 'login ASC' );
}
$logins = $userM -> fetchAll ( $sql );
if ( $logins -> count () > 0 ) {
foreach ( $logins as $result ) {
$utilisateur = new Utilisateur ();
$utilisateur -> idUti = $result -> id ;
$utilisateur -> login = $result -> login ;
$utilisateur -> actif = $result -> actif ;
$utilisateur -> nom = $result -> nom ;
$utilisateur -> prenom = $result -> prenom ;
$utilisateur -> email = $result -> email ;
$utilisateur -> reference = $result -> referenceParDefaut ;
$output [] = $utilisateur ;
}
}
}
return $output ;
}
/**
* Override user params
* @ param string $element
* @ param int $idClient
* @ param string $service
* @ param string $login
* @ throws SoapFault
* @ return boolean
*/
public function setParam ( $element , $idClient , $service , $login = null )
{
$this -> authenticate ();
$element = strtoupper ( $element );
if ( ! in_array ( $element , array ( 'IP' , 'ACCESS' )) ) {
throw new SoapFault ( 'ERR' , 'Invalid parameters' );
}
switch ( $element ) {
case 'IP' :
break ;
case 'ACCESS' :
$logins = $this -> _serviceLogins ( $idClient , $service );
if ( $login !== null ) {
if ( ! in_array ( $login , $logins ) ) {
throw new SoapFault ( 'ERR' , " Login not found " );
} else {
$logins = array ( $login );
}
}
if ( count ( $logins ) > 0 ) {
//Get access
if ( $service == 'DEFAULT' ) {
$clientM = new Application_Model_Sdv1Clients ();
$sql = $clientM -> select () -> where ( 'idClient=?' , $idClient );
$row = $clientM -> fetchRow ( $sql );
$droits = $row -> droits ;
} else {
$serviceM = new Application_Model_Sdv1ClientsServices ();
$sql = $serviceM -> select () -> where ( 'code=?' , $service );
$row = $serviceM -> fetchRow ( $sql );
$droits = $row -> droits ;
}
//Override access
$userM = new Application_Model_Sdv1Utilisateurs ();
$result = $userM -> update ( array ( 'droits' => $droits ), 'login IN (' . join ( ',' , $logins ) . ')' );
}
break ;
}
if ( empty ( $result )) {
return false ;
}
return true ;
}
/**
* Override email ( s ) in surveillances
* @ param string $login
* @ param string $email
* @ throws SoapFault
* @ return int
*/
public function setSurveillancesMail ( $login , $email )
{
$this -> authenticate ();
try {
$surveillanceM = new Application_Model_JoSurveillancesSite ();
$result = $surveillanceM -> update ( array ( 'email' => $email ), " login=' $login ' " );
} catch ( Zend_Exception $e ) {
2014-08-06 20:27:01 +00:00
if ( $this -> User -> idClient == 1 ) {
2013-11-05 11:18:30 +00:00
throw new SoapFault ( 'ERR' , $e -> getMessage ());
} else {
throw new SoapFault ( 'ERR' , " Application error " );
}
}
return $result ;
}
2014-04-02 12:37:46 +00:00
/**
* Set secondary email
* @ param string $email
* @ param string $login
* @ param string $id Id pour edition ( set ) ou suppression ( del )
* @ param string $action ( set | del )
* @ throws SoapFault
* @ return int
*/
public function setEmail ( $email , $login , $id = null , $action = 'set' )
{
$this -> authenticate ();
2014-08-06 20:27:01 +00:00
$idClient = $this -> User -> idClient ;
2014-04-02 12:37:46 +00:00
if ( $action == 'set' ) {
if ( $id === null ) {
try {
$emailsM = new Application_Model_Sdv1UtilisateursEmails ();
$data = array (
'email' => $email ,
'login' => $login ,
'idClient' => $idClient ,
);
$result = $emailsM -> insert ( $data );
} catch ( Zend_Exception $e ) {
2014-08-06 20:27:01 +00:00
if ( $this -> User -> idClient == 1 ) {
2014-04-02 12:37:46 +00:00
throw new SoapFault ( 'ERR' , $e -> getMessage ());
} else {
throw new SoapFault ( 'ERR' , " Application error " );
}
}
} else {
try {
$emailsM = new Application_Model_Sdv1UtilisateursEmails ();
$data = array (
'email' => $email ,
);
$result = $emailsM -> update ( $data , array (
'login="' . $login . '"' ,
'idClient=' . $idClient ,
'id=' . $id ,
));
} catch ( Zend_Exception $e ) {
2014-08-06 20:27:01 +00:00
if ( $this -> User -> idClient == 1 ) {
2014-04-02 12:37:46 +00:00
throw new SoapFault ( 'ERR' , $e -> getMessage ());
} else {
throw new SoapFault ( 'ERR' , " Application error " );
}
}
}
} elseif ( $action == 'del' ) {
try {
$emailsM = new Application_Model_Sdv1UtilisateursEmails ();
$result = $emailsM -> delete ( array (
'login="' . $login . '"' ,
'idClient=' . $idClient ,
'id=' . $id ,
));
} catch ( Zend_Exception $e ) {
2014-08-06 20:27:01 +00:00
if ( $this -> User -> idClient == 1 ) {
2014-04-02 12:37:46 +00:00
throw new SoapFault ( 'ERR' , $e -> getMessage ());
} else {
throw new SoapFault ( 'ERR' , " Application error " );
}
}
}
return $result ;
}
/**
* Secondary Emails
* @ param string $login
* @ param int $id
* @ throws SoapFault
* @ return Email []
*/
public function getEmail ( $login , $id = null )
{
$this -> authenticate ();
2014-08-06 20:27:01 +00:00
$idClient = $this -> User -> idClient ;
2014-04-02 12:37:46 +00:00
try {
$emailsM = new Application_Model_Sdv1UtilisateursEmails ();
$sql = $emailsM -> select ()
-> where ( 'login=?' , $login )
-> where ( 'idClient=?' , $idClient );
$result = $emailsM -> fetchAll ( $sql );
} catch ( Zend_Exception $e ) {
2014-08-06 20:27:01 +00:00
if ( $this -> User -> idClient == 1 ) {
2014-04-02 12:37:46 +00:00
throw new SoapFault ( 'ERR' , $e -> getMessage ());
} else {
throw new SoapFault ( 'ERR' , " Application error " );
}
}
$emails = array ();
if ( count ( $result ) > 0 ) {
foreach ( $result as $item ) {
$email = new Email ();
$email -> id = $item -> id ;
$email -> value = $item -> email ;
$emails [] = $email ;
}
}
return $emails ;
}
2013-11-05 11:18:30 +00:00
/**
* Remove access to the children
* @ param array $toDelete
* @ param int $idClient
* @ param string $service
*/
protected function _deleteAccess ( $toDelete , $idClient , $service = null )
{
2015-04-27 16:08:29 +00:00
$iDbCrm = new WDB ();
2013-11-05 11:18:30 +00:00
$strLogin = '' ;
//Modification sur les droits des services
2015-04-09 14:45:46 +00:00
/* if ( count ( toDelete ) > 0 ) {
2013-11-05 11:18:30 +00:00
foreach ( $toDelete as $droit ) {
$query = " UPDATE clients_services SET droits=TRIM(REPLACE(droits, ' $droit ', ' ')) WHERE idClient=' $idClient ' " ;
$iDbCrm -> query ( $query );
}
2015-04-09 14:45:46 +00:00
} */
2013-11-05 11:18:30 +00:00
if ( null !== $service ) {
//Récupération des logins utilisateurs du service
$logins = $this -> _serviceLogins ( $idClient , $service );
if ( count ( $logins ) > 0 ) {
$strLogin = ' AND login IN(' . join ( ',' , $logins -> toArray ()) . ')' ;
}
}
//Modification sur les droits utilisateurs
if ( count ( toDelete ) > 0 ) {
foreach ( $toDelete as $droit ) {
2015-04-24 15:41:42 +00:00
$query = " UPDATE sdv1.utilisateurs set droits=TRIM(REPLACE(droits, ' $droit ', ' ')) WHERE idClient=' $idClient ' " ;
2013-11-05 11:18:30 +00:00
$query .= $strLogin ;
$iDbCrm -> query ( $query );
}
}
}
/**
* Give a list of logins in a service
* @ param int $idClient
* @ param string $serviceCode
* @ return array
*/
protected function _serviceLogins ( $idClient , $serviceCode )
{
$serviceCode = strtoupper ( $serviceCode );
$userM = new Application_Model_Sdv1Utilisateurs ();
$sql = $userM -> select ()
-> from ( array ( 'u' => 'utilisateurs' ), array ( 'login' ))
-> join ( array ( 's' => 'utilisateurs_service' ), 'u.login=s.login' );
if ( $serviceCode == 'DEFAULT' ) {
$sql -> where ( 'serviceCode=?' , null );
} else {
$sql -> where ( 'serviceCode=?' , $serviceCode );
}
$logins = $userM -> fetchAll ( $sql ) -> toArray ();
return $logins ;
}
}