1075 lines
34 KiB
PHP
1075 lines
34 KiB
PHP
<?php
|
|
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';
|
|
|
|
require_once __DIR__ . '/Types.php';
|
|
|
|
class Gestion extends Scores_Ws_Server
|
|
{
|
|
/**
|
|
* 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
|
|
$filtre = trim($this->User->filtre_ip);
|
|
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
|
|
if ( $this->User->login<>$login
|
|
&& in_array($this->User->profil, array('Administrateur', 'SuperAdministrateur') )
|
|
) {
|
|
/** 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;
|
|
$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 = $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;
|
|
|
|
// On log l'accès à l'authentification
|
|
if ( $this->User->clientTest=='Oui' || $this->User->typeCompte=='TEST' ) {
|
|
$test = 1;
|
|
} else {
|
|
$test = 0;
|
|
}
|
|
$tabInsert = array(
|
|
'login' => $this->User->login,
|
|
'idClient' => $this->User->idClient,
|
|
'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')),
|
|
"idClient=".$this->User->idClient." AND login='".$this->User->login."'"
|
|
);
|
|
}
|
|
|
|
//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|actif|desactif|changepwd|new|update)
|
|
* @param InfosLoginData $infos
|
|
* @return SetInfosLoginReturn
|
|
*/
|
|
public function setInfosLogin($login, $action, $infos = null)
|
|
{
|
|
$this->authenticate();
|
|
//Initialisation
|
|
$error = new ErrorType();
|
|
$result = false;
|
|
|
|
switch($action)
|
|
{
|
|
case 'delete':
|
|
|
|
if ($this->User->profil=='Administrateur'
|
|
|| $this->User->profil=='SuperAdministrateur') {
|
|
$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;
|
|
} else {
|
|
$error->errnum = 1;
|
|
$error->errmsg = 'Mise a jour impossible';
|
|
}
|
|
}
|
|
break;
|
|
|
|
case 'actif':
|
|
case 'desactif':
|
|
if ($this->User->profil=='Administrateur'
|
|
|| $this->User->profil=='SuperAdministrateur'){
|
|
if ($action=='actif') $actif = 1;
|
|
if ($action=='desactif') $actif = 0;
|
|
$tabUpdate = array( 'actif' => $actif, 'dateUpdate' => date('Y-m-d H:i:s') );
|
|
$iDbCrm = new WDB('sdv1');
|
|
if ($iDbCrm->update('utilisateurs', $tabUpdate, "login='$login'")){
|
|
$result = true;
|
|
} else {
|
|
$error->errnum = 1;
|
|
$error->errmsg = 'Mise a jour impossible';
|
|
}
|
|
}
|
|
|
|
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;
|
|
} else {
|
|
$error->errnum = 1;
|
|
$error->errmsg = 'Mise a jour impossible';
|
|
}
|
|
|
|
break;
|
|
|
|
case 'new':
|
|
|
|
if ($this->User->profil=='Administrateur'
|
|
|| $this->User->profil=='SuperAdministrateur') {
|
|
|
|
$idClient = $this->User->idClient;
|
|
if ( $this->User->profil=='SuperAdministrateur' && $infos->idClient!=''){
|
|
$idClient = $infos->idClient;
|
|
}
|
|
|
|
$typeCompte = 'PROD';
|
|
if ( $this->User->profil=='SuperAdministrateur' && $infos->typeCompte=='TEST'){
|
|
$typeCompte = 'TEST';
|
|
}
|
|
|
|
$tabUpdate = array(
|
|
'idClient' => $idClient,
|
|
'login' => $login,
|
|
'password' => stripslashes($infos->password),
|
|
'nom' => stripslashes($infos->nom),
|
|
'prenom' => stripslashes($infos->prenom),
|
|
'referenceParDefaut' => stripslashes($infos->reference),
|
|
'email' => strtolower(stripslashes($infos->email)),
|
|
'tel' => stripslashes($infos->tel_fix),
|
|
'fax' => stripslashes($infos->tel_fax),
|
|
'mobile' => stripslashes($infos->tel_mob),
|
|
'nbReponses' => $infos->rech_nbrep,
|
|
//'formatMail' => $infos->formatMail,
|
|
'profil' => (isset($infos->profil) || !in_array($infos->profil, array('SuperAdministrateur','Administrateur', 'Utilisateur')) ) ? $infos->profil : 'Utilisateur',
|
|
'pref' => implode(' ',$infos->pref->item),
|
|
'droits' => implode(' ', $infos->droits->item),
|
|
'typeCompte' => $typeCompte,
|
|
'dateInsert' => date('Y-m-d H:i:s'),
|
|
);
|
|
$iDbCrm = new WDB('sdv1');
|
|
if ($iDbCrm->insert('utilisateurs', $tabUpdate)){
|
|
$result = true;
|
|
} else {
|
|
$error->errnum = 1;
|
|
$error->errmsg = 'Création impossible';
|
|
}
|
|
}
|
|
|
|
break;
|
|
|
|
case 'update':
|
|
|
|
if (!empty($infos->password)){
|
|
$tabUpdate['password'] = stripslashes($infos->password);
|
|
}
|
|
$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->rech_nbrep;
|
|
//$tabUpdate['formatMail'] = $infos->formatMail;
|
|
$tabUpdate['pref'] = implode(' ',$infos->pref->item);
|
|
$tabUpdate['dateUpdate'] = date('Y-m-d H:i:s');
|
|
if ($this->User->profil=='Administrateur' ||
|
|
$this->User->profil=='SuperAdministrateur') {
|
|
$tabUpdate['droits'] = implode(' ', $infos->droits->item);
|
|
$tabUpdate['nom'] = stripslashes($infos->nom);
|
|
$tabUpdate['prenom'] = stripslashes($infos->prenom);
|
|
$tabUpdate['referenceParDefaut'] = stripslashes($infos->reference);
|
|
$tabUpdate['profil'] = isset($infos->profil) ? $infos->profil : 'Utilisateur';
|
|
}
|
|
|
|
$iDbCrm = new WDB('sdv1');
|
|
if ($iDbCrm->update('utilisateurs', $tabUpdate, "login='$login'", true)){
|
|
$result = true;
|
|
} else {
|
|
$error->errnum = 1;
|
|
$error->errmsg = 'Mise a jour impossible';
|
|
}
|
|
|
|
break;
|
|
default;
|
|
$result = false;
|
|
break;
|
|
}
|
|
|
|
$output = new SetInfosLoginReturn();
|
|
$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();
|
|
|
|
if ($this->User->profil!='SuperAdministrateur') {
|
|
$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;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Obtention automatique d'un nouveau login pour un client
|
|
* @param string $login
|
|
* @return NextLoginReturn
|
|
*/
|
|
public function getNextLogin( $login )
|
|
{
|
|
$this->authenticate();
|
|
//Initialisation
|
|
$error = new ErrorType();
|
|
|
|
if ($this->User->profil=='Administrateur' ||
|
|
$this->User->profil=='SuperAdministrateur') {
|
|
|
|
/** 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;
|
|
|
|
if ($this->User->profil=='Administrateur' &&
|
|
($idClient=='false' || $idClient==$this->User->idClient)){
|
|
$idClient = $this->User->idClient;
|
|
$isAuthorized = true;
|
|
}
|
|
|
|
if ($this->User->profil<>'SuperAdministrateur'){
|
|
$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();
|
|
|
|
if ($this->User->profil<>'Administrateur' &&
|
|
$this->User->profil<>'SuperAdministrateur')
|
|
{
|
|
$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
|
|
if ($all && $this->User->profil=='SuperAdministrateur') {
|
|
$all = 'Oui';
|
|
} else {
|
|
$all = 'Non';
|
|
}
|
|
// Pas d'idClient mentionné ou tentative sur autre client et non SAD
|
|
if ($idClient==0 || ($idClient!=$this->User->idClient && $this->User->profil!='SuperAdministrateur') ){
|
|
$idClient = $this->User->idClient;
|
|
}
|
|
$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
|
|
if ($this->User->profil!='SuperAdministrateur') {
|
|
throw new SoapFault(1, 'Profil insuffisant pour cette méthode');
|
|
} else {
|
|
$infos = json_decode($infos);
|
|
|
|
/**
|
|
* - Protégé 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 setModeleUtilisateur($idClient, $nom, $infos)
|
|
{
|
|
$this->authenticate();
|
|
}
|
|
|
|
/**
|
|
* Création/Modification d'utilisateurs
|
|
* @param integer $idClient
|
|
* @param SetUtilisateurs[] $users
|
|
* @return UtilisateursReturn
|
|
*/
|
|
protected function setUtilisateurs($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;
|
|
}
|
|
} |