2013-11-05 11:18:30 +00:00
< ? php
2014-09-12 14:57:26 +00:00
require_once 'framework/fwk.php' ;
require_once 'framework/mail/sendMail.php' ;
require_once 'Metier/insee/classMInsee.php' ;
require_once 'Metier/insee/classMSirene.php' ;
require_once 'Metier/partenaires/classMBilans.php' ;
require_once 'Metier/partenaires/classMBourse.php' ;
require_once 'Metier/partenaires/classMTva.php' ;
require_once 'Metier/partenaires/classMMap.php' ;
require_once 'Metier/partenaires/classMGreffes.php' ;
require_once 'Metier/partenaires/classMPrivileges.php' ;
require_once 'Metier/scores/classMFinancier.php' ;
require_once 'Metier/scores/classMSolvabilite.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
* @ return InfosLoginReturn
*/
public function getInfosLogin ( $login , $ipUtilisateur = '' )
{
$this -> authenticate ();
//Initialisation
if ( empty ( $ipUtilisateur )) $ipUtilisateur = $_SERVER [ 'REMOTE_ADDR' ];
$error = new ErrorType ();
$result = new InfosLogin ();
//Filtre IP
2014-08-06 20:27:01 +00:00
$filtre = trim ( $this -> User -> filtre_ip );
2013-11-05 11:18:30 +00:00
if ( ! empty ( $filtre ) && ! checkPlagesIp ( $filtre , $ipUtilisateur ) ){
debugLog ( 'I' , " getInfosLogin Adresse IP $ipUtilisateur non declaree pour le compte $login " , __LINE__ , __FILE__ , __FUNCTION__ , __CLASS__ );
$this -> sendError ( '0904' );
}
debugLog ( 'I' , " getInfosLogin pour $login (IP= $ipUtilisateur ) " , __LINE__ , __FILE__ , __FUNCTION__ , __CLASS__ );
//L'utilisateur qui demande les informations est différent
2014-08-06 20:27:01 +00:00
if ( $this -> User -> login <> $login
&& in_array ( $this -> User -> profil , array ( 'Administrateur' , 'SuperAdministrateur' ) )
2013-11-05 11:18:30 +00:00
) {
/** Un administrateur veut il des infos sur un login ? **/
$iDbCrm = new WDB ( 'sdv1' );
$rep = $iDbCrm -> select (
'utilisateurs u, clients c' ,
'u.login, u.id, u.email, u.password, u.idClient, u.typeCompte, u.actif, u.filtre_ip, u.civilite, u.nom, u.prenom, u.tel, u.fax, u.mobile, u.profil, u.raisonSociale, u.siret, u.adrNum, u.adrIndRep, u.adrTypeVoie, u.adrLibVoie, u.adrCp, u.adrVille, u.adrComp, u.tel, u.fax, u.mobile, u.pref, u.profil, u.dateInscription, u.dateValidation, u.nombreConnexions, u.dateDerniereConnexion, u.droits, u.referenceParDefaut, u.nbReponses, u.formatMail, u.dateDebutCompte, u.dateFinCompte, u.maxFicheId, c.droits AS droitsClients, c.test AS clientTest, c.timeout, c.typeScore AS typeScore' ,
" u.login=' $login ' AND u.idClient=c.id AND u.deleted=0 " ,
false , MYSQL_ASSOC
);
$tabRep = $rep [ 0 ];
if ( count ( $rep ) > 0 )
{
$timeOutSec = $tabRep [ 'timeout' ];
if ( $timeOutSec == 0 ) $timeOutSec = 1800 ;
$result -> login = $login ;
$result -> id = $tabRep [ 'id' ];
$result -> email = $tabRep [ 'email' ];
$result -> typeCompte = $tabRep [ 'typeCompte' ];
$result -> idClient = $tabRep [ 'idClient' ];
$result -> filtre_ip = $tabRep [ 'filtre_ip' ];
$result -> civilite = $tabRep [ 'civilite' ];
$result -> nom = $tabRep [ 'nom' ];
$result -> prenom = $tabRep [ 'prenom' ];
$result -> raisonSociale = $tabRep [ 'raisonSociale' ];
$result -> siret = $tabRep [ 'siret' ];
$result -> adrNum = $tabRep [ 'adrNum' ];
$result -> adrIndRep = $tabRep [ 'adrIndRep' ];
$result -> adrTypeVoie = $tabRep [ 'adrTypeVoie' ];
$result -> adrLibVoie = $tabRep [ 'adrLibVoie' ];
$result -> adrCp = $tabRep [ 'adrCp' ];
$result -> adrVille = $tabRep [ 'adrVille' ];
$result -> adrComp = $tabRep [ 'adrComp' ];
$result -> tel = $tabRep [ 'tel' ];
$result -> fax = $tabRep [ 'fax' ];
$result -> mobile = $tabRep [ 'mobile' ];
$result -> pref = $tabRep [ 'pref' ];
$result -> profil = $tabRep [ 'profil' ];
$result -> dateInscription = $tabRep [ 'dateInscription' ];
$result -> dateValidation = $tabRep [ 'dateValidation' ];
$result -> nombreConnexions = $tabRep [ 'nombreConnexions' ];
$result -> dateDerniereConnexion = $tabRep [ 'dateDerniereConnexion' ];
$result -> droits = $tabRep [ 'droits' ];
$result -> droitsClients = $tabRep [ 'droitsClients' ];
$result -> timeout = $timeOutSec ;
$result -> clientTest = $tabRep [ 'clientTest' ];
$result -> typeScore = $tabRep [ 'typeScore' ];
$result -> nbReponses = $tabRep [ 'nbReponses' ];
$result -> formatMail = $tabRep [ 'formatMail' ];
$result -> reference = $tabRep [ 'referenceParDefaut' ];
$result -> dateDebutCompte = $tabRep [ 'dateDebutCompte' ];
$result -> dateFinCompte = $tabRep [ 'dateFinCompte' ];
$result -> maxFicheId = $tabRep [ 'maxFicheId' ];
} else {
/** On log l'erreur d'authentification **/
$tabInsert = array (
'login' => $login ,
'page' => 'infosLogin' ,
'params' => 'Erreur Login/Password' ,
'ipClient' => $ipUtilisateur );
$iDbCrm -> insert ( 'logs' , $tabInsert );
}
}
//Authentification de l'utilisateur
else
{
$ref = 'OK' ;
//Identification utilisateur
$connected = true ;
$result -> connected = $connected ;
2014-08-06 20:27:01 +00:00
$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 ;
2013-11-05 11:18:30 +00:00
$result -> ipConnexion = $ipUtilisateur ;
2014-08-06 20:27:01 +00:00
$result -> civilite = $this -> User -> civilite ;
$result -> nom = $this -> User -> nom ;
$result -> prenom = $this -> User -> prenom ;
$result -> raisonSociale = $this -> User -> raisonSociale ;
$result -> siret = $this -> User -> siret ;
$result -> adrNum = $this -> User -> adrNum ;
$result -> adrIndRep = $this -> User -> adrIndRep ;
$result -> adrTypeVoie = $this -> User -> adrTypeVoie ;
$result -> adrLibVoie = $this -> User -> adrLibVoie ;
$result -> adrCp = $this -> User -> adrCp ;
$result -> adrVille = $this -> User -> adrVille ;
$result -> adrComp = $this -> User -> 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 ;
$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 -> formatMail = $this -> User -> formatMail ;
$result -> reference = $this -> User -> referenceParDefaut ;
$result -> dateDebutCompte = $this -> User -> dateDebutCompte ;
$result -> dateFinCompte = $this -> User -> dateFinCompte ;
$result -> maxFicheId = $this -> User -> maxFicheId ;
$result -> typeScore = $this -> User -> typeScore ;
$result -> acceptationCGU = $this -> User -> acceptationCGU ;
2013-11-05 11:18:30 +00:00
// On log l'accès à l'authentification
2014-08-06 20:27:01 +00:00
if ( $this -> User -> clientTest == 'Oui' || $this -> User -> typeCompte == 'TEST' ) {
2013-11-05 11:18:30 +00:00
$test = 1 ;
} else {
$test = 0 ;
}
$tabInsert = array (
2014-08-06 20:27:01 +00:00
'login' => $this -> User -> login ,
'idClient' => $this -> User -> idClient ,
2013-11-05 11:18:30 +00:00
'page' => 'infosLogin' ,
'params' => $ref ,
'test' => $test ,
'ipClient' => $ipUtilisateur
);
$iDbCrm = new WDB ( 'sdv1' );
$iDbCrm -> insert ( 'logs' , $tabInsert );
//Date de dernière connexion
$iDbCrm -> update ( 'utilisateurs' ,
array ( 'dateDerniereConnexion' => date ( 'Y-m-d H:i:s' )),
2014-08-06 20:27:01 +00:00
" idClient= " . $this -> User -> idClient . " AND login=' " . $this -> User -> login . " ' "
2013-11-05 11:18:30 +00:00
);
}
//Retour
$output = new InfosLoginReturn ();
$output -> error = $error ;
$output -> result = $result ;
return $output ;
}
/**
* 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 );
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' ) );
$iDbCrm = new WDB ( 'sdv1' );
if ( $iDbCrm -> update ( 'utilisateurs' , $tabUpdate , " login=' $login ' " )){
$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' ) );
$iDbCrm = new WDB ( 'sdv1' );
if ( $iDbCrm -> update ( 'utilisateurs' , $tabUpdate , " login=' $login ' " )){
$result = true ;
}
}
break ;
case 'changepwd' :
$tabUpdate = array (
'password' => stripslashes ( $infos [ 'password' ]),
'dateUpdate' => date ( 'Y-m-d H:i:s' )
);
$iDbCrm = new WDB ( 'sdv1' );
if ( $iDbCrm -> update ( 'utilisateurs' , $tabUpdate , " login=' $login ' " , true )){
$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
{
$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=' $idClinet ' " , 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' ];
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
$iDbCrm = new WDB ( 'sdv1' );
if ( $iDbCrm -> insert ( 'utilisateurs' , $tabUpdate )){
$result = true ;
}
}
break ;
case 'update' :
//Don't update password if nothind 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' ];
$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' );
$iDbCrm = new WDB ( 'sdv1' );
if ( $iDbCrm -> update ( 'utilisateurs' , $tabUpdate , " login=' $login ' " , true )){
$result = true ;
}
break ;
default : $result = false ; break ;
}
return $result ;
}
/**
* Obtention automatique d ' un nouveau login pour un client
* @ param string $login
* @ return NextLoginReturn
*/
public function getNextLogin ( $login )
{
$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 **/
$iDbCrm = new WDB ( 'sdv1' );
$rep = $iDbCrm -> select ( 'utilisateurs u, clients c' , 'u.idClient, c.racineLogin, c.droits' , " u.login=' $login ' AND u.idClient=c.id " );
$racine = $rep [ 0 ][ 'racineLogin' ];
$idClient = $rep [ 0 ][ 'idClient' ];
$droitsClients = $rep [ 0 ][ 'droits' ];
$rep = $iDbCrm -> select ( 'utilisateurs' , 'login, length(login) as taille' , " login like ' $racine %' group by login order by taille desc, login desc LIMIT 0,1 " );
if ( count ( $rep ) == 0 ) {
$racine .= '1' ;
} else {
$last_i = preg_replace ( " / \ D/ " , '' , $rep [ 0 ][ 'login' ]) * 1 ;
$racine .= $last_i + 1 ;
}
$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 ' " ;
$iDbCrm = new WDB ( 'sdv1' );
$rep = $iDbCrm -> select ( 'clients' ,
'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 ;
}
/**
* 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 ;
}
/**
* 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 {
$iDbCrm = new WDB ( 'sdv1' );
if ( ! isset ( $idClient )){
$rep = $iDbCrm -> select ( 'utilisateurs' , 'idClient' , " login=' $login ' " );
$idClient = $rep [ 0 ][ 0 ];
}
if ( $idClient ==- 1 ){
$error -> errnum = 1 ;
$error -> errmsg = 'idClient=0' ;
} else {
$rep = $iDbCrm -> select ( 'utilisateurs' , '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' );
$fichierCsv = $c -> profil -> path -> files . " /logs- $annee - $mois - $detail - $idClient - $login - $all .csv " ;
if ( file_exists ( $fichierCsv ) &&
date ( 'Ymd' , filemtime ( $fichierCsv )) == date ( 'Ymd' ) &&
filesize ( $fichierCsv ) > 60 ) {
$size = filesize ( $fichierCsv );
$erreur = false ;
$tabNom = array ();
$cache = 1 ;
} else {
@ unlink ( $fichierCsv );
$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 `logs` l , utilisateurs u , 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
GROUP BY l . login , l . siren , l . page , date ( dateHeure ), l . params
ORDER BY l . login ASC , l . dateHeure ASC " ;
$fp = fopen ( $c -> profil -> path -> cache . " /logs- $annee - $mois - $detail - $idClient - $login - $all .sql " , 'w' );
fwrite ( $fp , $sql . EOL );
fclose ( $fp );
exec ( " php " . $c -> profil -> path -> batch . " /sql2csv.php sdv1 " . $c -> profil -> path -> cache . " /logs- $annee - $mois - $detail - $idClient - $login - $all .sql $fichierCsv > /dev/null & " );
$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 ;
//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' :
$tabInfos [ 'filtres_ip' ] = $value ;
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 ;
}
}
$iDbCrm = new WDB ( 'sdv1' );
if ( empty ( $idClient )){
//Ajout
$tabInfos [ 'dateInsert' ] = date ( 'Y-m-d H:i:s' );
$result = $iDbCrm -> insert ( 'clients' , $tabInfos , true );
} else {
//Droits client actuel avant modification
if ( isset ( $tabInfos [ 'droits' ])){
$rep = $iDbCrm -> select ( 'clients' , 'droits' , " id=' $idClient ' " , false , MYSQL_ASSOC );
$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
$update = array ();
if ( count ( $droitsDiff ) > 0 ){
foreach ( $droitsDiff as $droit ){
$query = " UPDATE utilisateurs set droits=TRIM(REPLACE(droits, ' $droit ', '')) WHERE idClient=' $idClient ' " ;
$iDbCrm -> query ( $query , true );
}
}
}
}
//Modification
$tabInfos [ 'dateUpdate' ] = date ( 'Y-m-d H:i:s' );
if ( $iDbCrm -> update ( 'clients' , $tabInfos , " id=' $idClient ' " , true )){
$result = true ;
}
}
}
$output = new ClientReturn ();
$output -> error = $error ;
$output -> result = $result ;
return $output ;
}
/**
* Création d ' un modele pour le préremplisage des données utilisateurs
* @ param integer $idClient
* @ param string $nom
* @ param ModeleUtilisateur $infos
* @ return ModeleUtilisateurReturn
*/
protected function setUserModel ( $idClient , $nom , $infos )
{
$this -> authenticate ();
}
/**
* 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_Utilisateurs ();
$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 ());
}
}
/**
* Création / Modification d ' utilisateurs
* @ param integer $idClient
* @ param SetUtilisateurs [] $users
* @ return UtilisateursReturn
*/
protected function setUsers ( $idClient , $users )
{
$this -> authenticate ();
$error = new ErrorType ();
$result = false ;
//idClient existe
$iDbCrm = new WDB ( 'sdv1' );
$rep = $iDbCrm -> select ( 'clients' , 'id, nom, actif, test, racineLogin, siren, nic, droits, filtres_ip, typeAcces, typeScore, accesPieces, accesKbis, accesInvestigations, accesInternationnal, accesEnquetes, miseSousSurveillance' , " 1 AND id=' $idClient ' " , false , MYSQL_ASSOC );
if ( count ( $rep ) > 0 ){
$client = $rep [ 0 ];
$idClient = $client [ 'id' ];
if ( count ( $users ) > 0 ){
foreach ( $users as $user ){
$tabInfos = array ();
$tabInfos [ 'idClient' ] = $idClient ;
$tabInfos [ 'login' ] = $user -> login ;
$tabInfos [ 'email' ] = '' ;
$tabInfos [ 'password' ] = $user -> password ;
$tabInfos [ 'actif' ] = '' ;
//$tabInfos['deleted'] = '';
if ( in_array ( $user -> typeCompte , array ( 'TEST' , 'PROD' ))){
$tabInfos [ 'typeCompte' ] = $user -> typeCompte ;
} else {
$tabInfos [ 'typeCompte' ] = 'PROD' ;
}
//$tabInfos['filtre_ip'] = '';
//SetInfosLogin
$tabInfos [ 'civilite' ] = '' ;
$tabInfos [ 'nom' ] = '' ;
$tabInfos [ 'prenom' ] = '' ;
//Identique au client
$tabInfos [ 'raisonSociale' ] = '' ;
$tabInfos [ 'siret' ] = '' ;
$tabInfos [ 'adrNum' ] = '' ;
$tabInfos [ 'adrInRep' ] = '' ;
$tabInfos [ 'adrTypeVoie' ] = '' ;
$tabInfos [ 'adrLibVoie' ] = '' ;
$tabInfos [ 'adrCp' ] = '' ;
$tabInfos [ 'adrVille' ] = '' ;
$tabInfos [ 'adrComp' ] = '' ;
$tabInfos [ 'tel' ] = '' ;
$tabInfos [ 'fax' ] = '' ;
$tabInfos [ 'mobile' ] = '' ;
$tabInfos [ 'pref' ] = '' ;
if ( in_array ( $user -> typeCompte , array ( 'Administrateur' , 'Utilisateur' ))){
$tabInfos [ 'profil' ] = $user -> profil ;
} else {
$tabInfos [ 'profil' ] = 'Utilisateur' ;
}
/*
$tabInfos [ 'dateInscription' ] = '' ;
$tabInfos [ 'dateValidation' ] = '' ;
*/
if ( empty ( $user -> droits )){
$tabInfos [ 'droits' ] = $client -> droits ;
} else {
$tabInfos [ 'droits' ] = $user -> droits ;
}
$tabInfos [ 'referenceParDefaut' ] = '' ;
$tabInfos [ 'nbReponses' ] = '' ;
$tabInfos [ 'listeEven' ] = '' ;
$tabInfos [ 'maxFicheId' ] = $user -> maxFicheId ;
//$tabInfos['dateInsert'] = '';
if ( empty ( $user -> id )){
$iDbCrm -> insert ( 'utilisateurs' , $tabInfos );
} else {
$iDbCrm -> update ( 'utilisateurs' , $tabInfos , " id=' $user->id ' " );
}
}
} else {
$error -> errnum = 1 ;
$error -> errmsg = 'Aucun utilisateur' ;
}
} else {
$error -> errnum = 1 ;
$error -> errmsg = 'Identifiant client inconnu!' ;
}
$output = new UtilisateursReturn ();
$output -> error = $error ;
$output -> result = $result ;
return $output ;
}
/**
* Affecter aux utilisateurs les paramètres du client
* @ param integer $idClient
* @ param string $element
* @ param string [] $utilisateurs
* @ return boolean
*/
public function setClientsParamsOnUtilisateurs ( $idClient , $element = null , $utilisateurs = 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 ( '0901' );
}
if ( empty ( $element )){
throw new SoapFault ( 'Error' , 'Erreur dans les paramètres' );
}
switch ( strtolower ( $element )){
//Mettre à jour les ips des utilisateurs en fonction de celles du client
case 'ip' :
$iDbCrm = new WDB ( 'sdv1' );
$rep = $iDbCrm -> select ( 'clients' , 'filtre_ip' , " id=' $idClient ' " , false , MYSQL_ASSOC );
if ( count ( $rep ) == 0 ){
throw new SoapFault ( 'Error' , 'Client inexistant' );
}
$data = array (
'filtre_ip' => $rep [ 0 ][ 'filtre_ip' ],
'dateUpdate' => date ( 'Y-m-d H:i:s' ),
);
$where = ' WHERE idClient=' . $idClient ;
if ( ! empty ( $utilisateurs ) && is_array ( $utilisateurs -> item )){
$where .= ' AND login IN (' . join ( ',' , $utilisateurs -> item ) . ')' ;
}
if ( $iDbCrm -> update ( 'utilisateurs' , $data , $where )){
return true ;
}
return false ;
break ;
}
}
/**
* 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_Utilisateurs ();
$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 string $log Nom de l ' élément à facturer
* @ param ClientTarif $tarif Informations de facturation
* @ return boolean
*/
public function setClientTarif ( $log , $tarif )
{
/**
* Une tarification est toujours affecté à un élément $log .
* Celle ci est définie sur un compte client ( tous les utilisateurs ) ou un service ,
* voir un seul utilisateur .
* 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' );
}
$tarifM = new Application_Model_ClientsTarif ();
if ( ! in_array ( $tarif -> log , array_keys ( $this -> listeDroits ))) {
throw new SoapFault ( 'ClientTarif' , 'log inexistant' );
}
if ( ! in_array ( $tarif -> type , array ( 'Unitaire' , 'ForfaitLimit' , 'ForfaitIllimit' ))) {
throw new SoapFault ( 'ClientTarif' , 'Erreur type' );
}
if ( ! in_array ( $tarif -> terme , array ( 'fin' , 'debut' ))) {
throw new SoapFault ( 'ClientTarif' , 'Erreur terme' );
}
if ( ! in_array ( $tarif -> doublon , array ( 'jour' , 'mois' , 'period' ))) {
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' => $tarif -> idClient ,
'service' => $tarif -> service ,
'login' => $tarif -> login ,
'log' => $tarif -> log ,
'type' => $tarif -> type ,
'priceForfait' => $tarif -> priceForfait ,
'priceUnit' => $tarif -> priceUnit ,
'limit' => $tarif -> limit ,
'dateDebut' => date ( 'YmdHis' , $time ),
'duree' => $tarif -> duree ,
'terme' => $tarif -> terme ,
'doublon' => $tarif -> doublon ,
);
if ( $tarifM -> insert ( $data )) {
return true ;
}
return false ;
}
/**
* Retourne les tarifs
* @ param integer $id IdClient
* @ return ClientTarifReturn []
*/
protected function getClientTarif ( $id )
{
$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' );
}
$tarifM = new Application_Model_ClientsTarif ();
//Au client
$sql = $tarifM -> select ()
-> where ( 'idClient=?' , $id )
-> where ( " service='' " )
-> where ( " login='' " )
-> order ( 'dateDebut DESC' ) -> limit ( 1 );
//Au service
//Au login
}
}