917 lines
27 KiB
PHP
917 lines
27 KiB
PHP
<?php
|
|
require_once __DIR__ . '/Types.php';
|
|
|
|
class Gestion extends Scores_Ws_Server
|
|
{
|
|
/**
|
|
* Authentication
|
|
* @param string $app
|
|
* Application name (extranet | odea | starlinks)
|
|
* @param string $ip
|
|
* IPv4 ou IPv6
|
|
* @param string $browser
|
|
* User agent string
|
|
*/
|
|
public function loginAuthenticate($app, $ip = null, $browser = null)
|
|
{
|
|
switch ($app) {
|
|
case 'extranet':
|
|
$this->authApp = 'extranet';
|
|
$this->authIp = $ip;
|
|
break;
|
|
case 'odea':
|
|
$this->authApp = 'odea';
|
|
$this->authIp = $ip;
|
|
break;
|
|
}
|
|
|
|
//Authentification des applications par login
|
|
$this->authenticate();
|
|
|
|
//Check App authorization - Find Service parameters
|
|
$serviceM = new Application_Model_Sdv1ClientsServices();
|
|
$sql = $serviceM->select()
|
|
->where('IdClient=?', $this->User->idClient)
|
|
->where('Code=?', $this->User->serviceCode);
|
|
$serviceParams = $serviceM->fetchRow($sql);
|
|
|
|
//Save information in database
|
|
//id, clientId, userId, login, ip, userAgent, dateLogin
|
|
|
|
//Retourne un minimum d'information pour les applications
|
|
//login
|
|
//civilite
|
|
//nom
|
|
//prenom
|
|
//email
|
|
//profil
|
|
//pref
|
|
//droits
|
|
//typeScore
|
|
//acceptationCGU
|
|
|
|
}
|
|
|
|
/**
|
|
* Authentication by key
|
|
* @param string $app
|
|
*/
|
|
protected function keyAuthenticate($app)
|
|
{
|
|
//Authentification par clé - @define
|
|
$this->authApp = 'extranet';
|
|
|
|
//Reception du login
|
|
|
|
//Reception de la clé (key:md5(login + '|' + key))
|
|
|
|
//Vérification nécessaire : application - enable - date debut - date fin
|
|
|
|
|
|
|
|
}
|
|
|
|
/**
|
|
* Liste des clients
|
|
* @throws SoapFault
|
|
* @return Client[]
|
|
*/
|
|
public function getClients()
|
|
{
|
|
$this->authenticate();
|
|
|
|
if ( $this->User->idClient != 1 ) {
|
|
throw new SoapFault('ERR', 'Accès non authorisé');
|
|
}
|
|
|
|
$clientM = new Application_Model_Sdv1Clients();
|
|
$sql = $clientM->select(true)->columns(array(
|
|
'nom AS Nom',
|
|
'LPAD(siren,9,0) AS Siren',
|
|
'LPAD(nic,5,0) AS Nic',
|
|
'IF(actif="Oui",1,0) AS Actif',
|
|
'IF(test="Oui",1,0) AS Test'
|
|
))->where('actif=?', 'Oui');
|
|
$result = $clientM->fetchAll($sql);
|
|
|
|
if ( count($result) > 0 ) {
|
|
foreach ( $result as $item ) {
|
|
$client = new Client();
|
|
$client->Nom = $item->Nom;
|
|
$client->Siren = $item->Siren;
|
|
$client->Nic = $item->Nic;
|
|
$client->Actif = $item->Actif;
|
|
$client->Test = $item->Test;
|
|
|
|
$clients[] = $client;
|
|
}
|
|
}
|
|
|
|
return $clients;
|
|
}
|
|
|
|
/**
|
|
* Information client
|
|
* @param int $id
|
|
* ID du client
|
|
* @throws SoapFault
|
|
* @return Client
|
|
*/
|
|
public function getClient($id = null)
|
|
{
|
|
$this->authenticate();
|
|
|
|
if ( $id === null || $this->User->idClient != 1 ) {
|
|
$id = $this->User->idClient;
|
|
}
|
|
|
|
$clientM = new Application_Model_Sdv1Clients();
|
|
$sql = $clientM->select(true)->columns(array(
|
|
'nom AS Nom',
|
|
'LPAD(siren,9,0) AS Siren',
|
|
'LPAD(nic,5,0) AS Nic',
|
|
'IF(actif="Oui",1,0) AS Actif',
|
|
'IF(test="Oui",1,0) AS Test'
|
|
))->where('id=?', $id);
|
|
$result = $clientM->fetchRow($sql);
|
|
|
|
if ( $result === null ) {
|
|
throw new SoapFault('ERR', 'Information client introuvable.');
|
|
}
|
|
|
|
$client = new Client();
|
|
$client->Nom = $result->Nom;
|
|
$client->Siren = $result->Siren;
|
|
$client->Nic = $result->Nic;
|
|
$client->Actif = $result->Actif;
|
|
$client->Test = $result->Test;
|
|
|
|
return $client;
|
|
}
|
|
|
|
/**
|
|
* Information client avec la liste des services
|
|
* @param int $id
|
|
* ID du client
|
|
* @throws SoapFault
|
|
* @return ClientServices
|
|
*/
|
|
public function getClientServices($id = null)
|
|
{
|
|
$this->authenticate();
|
|
|
|
if ( $id === null || $this->User->idClient != 1 ) {
|
|
$id = $this->User->idClient;
|
|
}
|
|
|
|
$clientM = new Application_Model_Sdv1Clients();
|
|
$sql = $clientM->select()->from($clientM, array(
|
|
'nom AS Nom',
|
|
'LPAD(siren,9,0) AS Siren',
|
|
'LPAD(nic,5,0) AS Nic',
|
|
'IF(actif="Oui",1,0) AS Actif',
|
|
'IF(test="Oui",1,0) AS Test'
|
|
))->where('id=?', $id);
|
|
$result = $clientM->fetchRow($sql);
|
|
|
|
if ( $result === null ) {
|
|
throw new SoapFault('ERR', 'Information client introuvable.');
|
|
}
|
|
|
|
$client = new ClientServices();
|
|
$client->Nom = $result->Nom;
|
|
$client->Siren = $result->Siren;
|
|
$client->Nic = $result->Nic;
|
|
$client->Actif = $result->Actif;
|
|
$client->Test = $result->Test;
|
|
|
|
//Get Services
|
|
$serviceM = new Application_Model_Sdv1ClientsServices();
|
|
$sql = $serviceM->select()
|
|
->from($serviceM, array('id', 'Code', 'Label', 'Editable', 'Active'))
|
|
->where('Deleted=?', 0)
|
|
->where('IdClient=?', $id);
|
|
$result = $serviceM->fetchAll($sql);
|
|
$services = array();
|
|
if (count($result) > 0) {
|
|
foreach ($result as $item) {
|
|
$clientService = new ClientServicesList();
|
|
$clientService->id = $item->id;
|
|
$clientService->Code = $item->Code;
|
|
$clientService->Label = $item->Label;
|
|
$clientService->Editable = $item->Editable;
|
|
$clientService->Active = $item->Active;
|
|
$services[] = $clientService;
|
|
}
|
|
}
|
|
$client->Services = $services;
|
|
|
|
return $client;
|
|
}
|
|
|
|
protected function getContrats()
|
|
{
|
|
//Liste des contrats, par service résumé
|
|
|
|
//Vérification des droits d'utilisation
|
|
if ( $this->User->profil != 'Administrateur' ) {
|
|
throw new SoapFault('ERR', 'Accès non authorisé');
|
|
}
|
|
|
|
}
|
|
|
|
protected function getContrat($id)
|
|
{
|
|
//Détail d'un contrat
|
|
|
|
//Vérification des droits d'utilisation
|
|
if ( $this->User->profil != 'Administrateur' ) {
|
|
throw new SoapFault('ERR', 'Accès non authorisé');
|
|
}
|
|
|
|
}
|
|
|
|
/**
|
|
* Liste des services
|
|
* @param string $client
|
|
* Id client
|
|
* @return ServiceList[]
|
|
*/
|
|
public function getServices($client = null)
|
|
{
|
|
//Liste des services
|
|
$this->authenticate();
|
|
|
|
if ( $client === null ) {
|
|
$client = $this->User->idClient;
|
|
}
|
|
|
|
//Uniquement si l'utilisateur est administrateur et dans le service DEFAULT
|
|
if ( $this->User->profil != 'Administrateur' ) {
|
|
throw new SoapFault('ERR', 'Accès non authorisé');
|
|
}
|
|
|
|
$serviceM = new Application_Model_Sdv1ClientsServices();
|
|
$sql = $serviceM->select()
|
|
->where('IdClient=?', $client)
|
|
->where('Deleted=0');
|
|
|
|
$result = $serviceM->fetchAll($sql);
|
|
|
|
$services = array();
|
|
if ( count($result) > 0 ) {
|
|
foreach ( $result as $item ) {
|
|
$service = new ServiceList();
|
|
$service->id = $item->id;
|
|
$service->IdClient = $item->IdClient;
|
|
$service->Code = $item->Code;
|
|
$service->Label = $item->Label;
|
|
$service->TypeCompte = $item->TypeCompte;
|
|
$service->TypeAcces = $item->TypeAcces;
|
|
$service->TypeScore = $item->TypeScore;
|
|
$service->Timeout = $item->Timeout;
|
|
$service->Editable = $item->Editable;
|
|
$service->Active = $item->Active;
|
|
$service->DateInsert = $item->DateInsert;
|
|
$service->DateUpdate = $item->DateUpdate;
|
|
|
|
$services[] = $service;
|
|
}
|
|
}
|
|
|
|
return $services;
|
|
}
|
|
|
|
/**
|
|
* Détail d'un service
|
|
* @param int $id
|
|
* @throws SoapFault
|
|
* @return Service
|
|
*/
|
|
public function getService($id)
|
|
{
|
|
$this->authenticate();
|
|
|
|
$client = $this->User->idClient;
|
|
|
|
//Détail d'un service
|
|
$serviceM = new Application_Model_Sdv1ClientsServices();
|
|
$sql = $serviceM->select()
|
|
->where('IdClient=?', $client)
|
|
->where('Deleted=?', 0)
|
|
->where('id=?', $id);
|
|
$result = $serviceM->fetchRow($sql);
|
|
|
|
if ( $result === null ) {
|
|
throw new SoapFault('ERR', 'Service introuvable.');
|
|
}
|
|
|
|
$output = new Service();
|
|
$output->id = $result->id;
|
|
$output->Code = $result->Code;
|
|
$output->Label = $result->Label;
|
|
$output->TypeCompte = $result->TypeCompte;
|
|
$output->TypeAcess = $result->TypeAcess;
|
|
$output->TypeScore = $result->TypeScore;
|
|
$output->Timeout = $result->Timeout;
|
|
$output->Editable = $result->Editable;
|
|
$output->Active = $result->Active;
|
|
$output->DateInsert = $result->DateInsert;
|
|
$output->DateUpdate = $result->DateUpdate;
|
|
|
|
//Droits
|
|
$output->Acces = array();
|
|
$serviceDroitsM = new Application_Model_Sdv1ClientsServicesDroits();
|
|
$sql = $serviceDroitsM->select()
|
|
->where('IdClient=?', $client)
|
|
->where('Service=?', $serviceCode);
|
|
$result = $serviceDroitsM->fetchAll($sql);
|
|
if ( count($result)>0 ) {
|
|
foreach ( $result as $item ) {
|
|
$acces = new AccesDetails();
|
|
$acces->Code = $item->Acces;
|
|
$acces->Label = $this->listeDroits[$item->Acces];
|
|
$output->Acces[] = $acces;
|
|
}
|
|
}
|
|
|
|
//IP
|
|
$output->IP = array();
|
|
$serviceIPM = new Application_Model_Sdv1ClientsServicesIP();
|
|
$sql = $serviceIPM->select()
|
|
->where('IdClient=?', $client)
|
|
->where('Service=?', $serviceCode);
|
|
$result = $serviceDroitsM->fetchAll($sql);
|
|
if ( count($result)>0 ) {
|
|
foreach ( $result as $item ) {
|
|
$output->IP[] = $item->IP;
|
|
}
|
|
}
|
|
|
|
return $output;
|
|
}
|
|
|
|
protected function getServiceConso($id){}
|
|
|
|
protected function getServiceLogByFile(){}
|
|
|
|
/**
|
|
* Modification des éléments d'un service par un administrateur
|
|
* @param string $code Element à modifier (label | active | delete)
|
|
* @param mixed $value Valeur
|
|
* @param string $id Id du service
|
|
* @throws SoapFault
|
|
* @return boolean
|
|
*/
|
|
public function setService($code, $value, $id)
|
|
{
|
|
$this->authenticate();
|
|
|
|
//Vérification des droits d'utilisation
|
|
if ( $this->User->profil != 'Administrateur' ) {
|
|
throw new SoapFault('ERR', 'Accès non authorisé');
|
|
}
|
|
|
|
$client = $this->User->idClient;
|
|
|
|
//Définir les éléments du service
|
|
$serviceM = new Application_Model_Sdv1ClientsServices();
|
|
$sql = $serviceM->select()
|
|
->where('IdClient=?', $client)
|
|
->where('Deleted=?', 0)
|
|
->where('id=?', $id);
|
|
$result = $serviceM->fetchRow($sql);
|
|
|
|
if ( $result === null ) {
|
|
throw new SoapFault('ERR', 'Service introuvable.');
|
|
}
|
|
|
|
if ( $result->Editable == 0) {
|
|
throw new SoapFault('MSG', "Impossible d'éditer le service");
|
|
}
|
|
|
|
$data = json_decode($data);
|
|
$dataToUpdate = array();
|
|
|
|
//Suppression d'un service
|
|
if ( $code == 'delete' && $value==1 ) {
|
|
$dataToUpdate = array('Deleted'=>1);
|
|
}
|
|
|
|
if ( $code == 'active' && in_array($value,array(0,1)) ) {
|
|
$dataToUpdate = array('Active'=>$value);
|
|
}
|
|
|
|
if ( $code == 'label' && is_string($value) ) {
|
|
$dataToUpdate = array('Label'=>$value);
|
|
}
|
|
|
|
if ( count($dataToUpdate) > 0 ) {
|
|
$dataToUpdate['DateUpdate'] = date('Y-m-d H:i:s');
|
|
try {
|
|
$serviceM->update($dataToUpdate, 'id='.$id);
|
|
return true;
|
|
} catch (Zend_Db_Exception $e) {
|
|
if ($this->User->idClient==1) {
|
|
throw new SoapFault('ERR', $e->getMessage());
|
|
} else {
|
|
throw new SoapFault('ERR', "Application error");
|
|
}
|
|
}
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
/**
|
|
* Définit les paramètres d'un service
|
|
* @param string $type
|
|
* @param string $value
|
|
* @param string $id
|
|
* @throws SoapFault
|
|
* @return boolean
|
|
*/
|
|
public function setServiceParam($type, $value, $id, $delete = false)
|
|
{
|
|
//Définir un paramètre du service
|
|
$this->authenticate();
|
|
|
|
//Vérification des droits d'utilisation
|
|
if ( $this->User->profil != 'Administrateur' ) {
|
|
throw new SoapFault('ERR', 'Accès non authorisé');
|
|
}
|
|
|
|
$client = $this->User->idClient;
|
|
|
|
$serviceM = new Application_Model_Sdv1ClientsServices();
|
|
$sql = $serviceM->select()
|
|
->where('IdClient=?', $client)
|
|
->where('Deleted=?', 0)
|
|
->where('id=?', $id);
|
|
$result = $serviceM->fetchRow($sql);
|
|
|
|
if ( $result === null ) {
|
|
throw new SoapFault('ERR', 'Service introuvable.');
|
|
}
|
|
|
|
if ( $result->Editable == 0) {
|
|
throw new SoapFault('MSG', "Impossible d'éditer le service");
|
|
}
|
|
|
|
//Acces
|
|
if ( $type == 'acces' ) {
|
|
|
|
if ( in_array($value, $this->listeDroits) ) {
|
|
|
|
}
|
|
}
|
|
|
|
//IP
|
|
if ( $type == 'ip' ) {
|
|
|
|
if ( $delete ) {
|
|
|
|
|
|
} else {
|
|
//Control de la plage IP ou de l'IP
|
|
$validate = new Zend_Validate_Ip();
|
|
if ( $validate->isValid($value) ) {
|
|
|
|
}
|
|
}
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
/**
|
|
* Liste des utilisateurs
|
|
* @param int $actif (0|1)
|
|
* @param string $service Code du service
|
|
* @param string $client Id du client
|
|
* @return UserList[]
|
|
*/
|
|
public function getUsers($actif = null, $service = null, $client = null)
|
|
{
|
|
//Liste des utilisateurs - filtre au service
|
|
$this->authenticate();
|
|
|
|
if ( $client === null ) {
|
|
$client = $this->User->idClient;
|
|
}
|
|
|
|
//Administrateur
|
|
if ( !in_array($this->User->profil, array('Administrateur', 'SuperAdministrateur')) ) {
|
|
throw new SoapFault('ERR', 'Accès non authorisé');
|
|
}
|
|
|
|
//Administrateur d'un service
|
|
if ( $this->User->Service != '' && $this->User->Service !== null && $this->User->Service !== 'DEFAULT' ) {
|
|
$service = $this->User->Service;
|
|
}
|
|
|
|
try {
|
|
$userM = new Application_Model_Sdv1Utilisateurs();
|
|
$sql = $userM->select()
|
|
->setIntegrityCheck(false)
|
|
->from(array('u'=>'sdv1.utilisateurs'), array('id','idClient','login','email','civilite','nom','prenom','actif','deleted'))
|
|
->joinLeft(array('s'=>'sdv1.utilisateurs_service'), 'u.login=s.login', array('Service'))
|
|
->joinLeft(array('sd'=>'sdv1.clients_services'), 'sd.Code=s.Service', array('Label'))
|
|
->where('u.idClient=?',$client);
|
|
|
|
if ( $actif !== null && in_array($actif, array(0,1)) ) {
|
|
$sql->where('u.actif=?', $actif);
|
|
}
|
|
$sql->where('u.deleted=?',0);
|
|
|
|
if ($service == 'DEFAULT') {
|
|
$sql->where('(s.Service IS NULL AND u.idClient='.$client.') OR (s.Service IS NOT NULL AND u.idClient='.$client.' AND u.idClient='.$client.' AND sd.idClient='.$client.') OR sd.Code="'.$service.'"');
|
|
} else if ( $service !== null ) {
|
|
$sql->where('s.Service=?', $service);
|
|
}
|
|
|
|
$result = $userM->fetchAll($sql);
|
|
} catch (Zend_Db_Exception $e) {
|
|
if ($this->User->idClient == 1) {
|
|
throw new SoapFault('ERR', $e->getMessage());
|
|
} else {
|
|
throw new SoapFault('ERR', "Application error");
|
|
}
|
|
}
|
|
|
|
$users = array();
|
|
if (count($result) > 0) {
|
|
foreach ($result as $item) {
|
|
$user = new UserList();
|
|
$user->id = $item->id;
|
|
$user->IdClient = $item->idClient;
|
|
$user->ServiceCode = $item->Service;
|
|
$user->ServiceLabel = $item->Label;
|
|
$user->Login = $item->login;
|
|
$user->Email = $item->email;
|
|
$user->Civilite = $item->civilite;
|
|
$user->Nom = $item->nom;
|
|
$user->Prenom = $item->prenom;
|
|
$user->Enable = $item->actif;
|
|
$user->Delete = $item->deleted;
|
|
|
|
$users[] = $user;
|
|
|
|
}
|
|
}
|
|
|
|
return $users;
|
|
}
|
|
|
|
protected function getUsersByFile($actif = null, $service = null, $client = null)
|
|
{
|
|
|
|
}
|
|
|
|
/**
|
|
* Information Utilisateur
|
|
* @param string $id
|
|
* ID de l'utilisateur
|
|
* @throws SoapFault
|
|
* @return User
|
|
*/
|
|
public function getUser($id = null)
|
|
{
|
|
//Détail d'un utilisateur
|
|
$this->authenticate();
|
|
|
|
$idClient = $this->User->idClient;
|
|
|
|
if ( $id === null ) {
|
|
$id = $this->User->id;
|
|
}
|
|
|
|
// Get Data
|
|
try {
|
|
$userM = new Application_Model_Sdv1Utilisateurs();
|
|
$sql = $userM->select()->from(array('u'=>'utilisateurs'))
|
|
->setIntegrityCheck(false)
|
|
->joinLeft(array('s'=>'sdv1.utilisateurs_service'), 'u.login=s.login', array('Service'))
|
|
->joinLeft(array('sd'=>'sdv1.clients_services'), 'sd.Code=s.Service', array('Label AS ServiceLabel'))
|
|
->where('u.id=?', $id);
|
|
|
|
$user = $userM->fetchRow($sql);
|
|
} catch (Zend_Db_Exception $e) {
|
|
if ($this->User->idClient == 1) {
|
|
throw new SoapFault('ERR', $e->getMessage());
|
|
} else {
|
|
throw new SoapFault('ERR', "Application error");
|
|
}
|
|
}
|
|
|
|
if ( $user === null ) {
|
|
throw new SoapFault('ERR', 'Utilisateur inexistant !');
|
|
}
|
|
|
|
// Service
|
|
if ( $user->Service === null ) {
|
|
$service = 'DEFAULT';
|
|
}
|
|
|
|
$output = new User();
|
|
$output->id = $user->id;
|
|
$output->IdClient = $user->idClient;
|
|
$output->ServiceCode = $user->Service;
|
|
$output->ServiceLabel = $user->ServiceLabel;
|
|
$output->Login = $user->login;
|
|
$output->Email = $user->email;
|
|
$output->Civilite = $user->civilite;
|
|
$output->Nom = $user->nom;
|
|
$output->Prenom = $user->prenom;
|
|
$output->Enable = $user->actif;
|
|
$output->Delete = $user->deleted;
|
|
|
|
// Service - Droits
|
|
$acces = array();
|
|
try {
|
|
$droitsM = new Application_Model_Sdv1ClientsServicesDroits();
|
|
$sql = $droitsM->select()->where('IdClient=?', $idClient)->where('Service=?', $service);
|
|
$droits = $droitsM->fetchAll($sql);
|
|
} catch (Zend_Db_Exception $e) {
|
|
if ($this->User->idClient == 1) {
|
|
throw new SoapFault('ERR', $e->getMessage());
|
|
} else {
|
|
throw new SoapFault('ERR', "Application error");
|
|
}
|
|
}
|
|
if ( count($droits) > 0 ) {
|
|
foreach ($droits as $item) {
|
|
$acces = new Acces();
|
|
$acces->Code = $item->Acces;
|
|
$acces->Label = $this->listeDroits[$item->Acces];
|
|
$output->Acces[] = $acces;
|
|
}
|
|
}
|
|
|
|
// Si l'utilisateur a pour Service = DEFAULT et pas de service DEFAULT alors droits de l'utilisateur
|
|
if ( count($droits) == 0 ) {
|
|
$droits = explode(' ', $user->droits);
|
|
foreach ($droits as $item) {
|
|
$acces = new Acces();
|
|
$acces->Code = $item;
|
|
$acces->Label = $this->listeDroits[strtoupper($item)];
|
|
$output->Acces[] = $acces;
|
|
}
|
|
}
|
|
|
|
|
|
// Service - IP
|
|
try {
|
|
$ipM = new Application_Model_Sdv1ClientsServicesIP();
|
|
$sql = $ipM->select()->where('IdClient=?', $idClient)->where('Service=?', $service);
|
|
$ips = $ipM->fetchAll($sql);
|
|
} catch (Zend_Db_Exception $e) {
|
|
if ($this->User->idClient == 1) {
|
|
throw new SoapFault('ERR', $e->getMessage());
|
|
} else {
|
|
throw new SoapFault('ERR', "Application error");
|
|
}
|
|
}
|
|
if ( count($ips) > 0 ) {
|
|
foreach ($ips as $item) {
|
|
$output->IP[] = $item;
|
|
}
|
|
}
|
|
|
|
return $output;
|
|
}
|
|
|
|
protected function getUserActivity($id = null)
|
|
{
|
|
//Retourner la liste des dernières connexions
|
|
}
|
|
|
|
/**
|
|
* Emails secondaires
|
|
* @param int $id
|
|
* @throws SoapFault
|
|
* @return string[]
|
|
*/
|
|
public function getUserEmail($id)
|
|
{
|
|
$this->authenticate();
|
|
|
|
$idClient = $this->User->idClient;
|
|
|
|
try {
|
|
$emailsM = new Application_Model_Sdv1UtilisateursEmails();
|
|
$sql = $emailsM->select()
|
|
->where('id=?', $id)
|
|
->where('idClient=?', $idClient);
|
|
$result = $emailsM->fetchAll($sql);
|
|
} catch (Zend_Db_Exception $e) {
|
|
if ($this->User->idClient==1) {
|
|
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;
|
|
}
|
|
|
|
protected function getUserLogByFile($id){}
|
|
|
|
public function setUser($data, $id = null)
|
|
{
|
|
$this->authenticate();
|
|
|
|
//Vérification des droits de création d'utilisateur
|
|
if ( $this->User->id!=$id || !in_array($this->User->profil, array('SuperAdministrateur', 'Administrateur')) ) {
|
|
throw new SoapFault('ERR', 'Accès non authorisé');
|
|
}
|
|
|
|
//Détecter si l'on change l'email => Renvoi email de validation
|
|
|
|
//Définir un utilisateur
|
|
//idClient
|
|
|
|
//login
|
|
//email
|
|
//password => generate automatically and send email on activation
|
|
//actif = 0
|
|
//deleted
|
|
//typeCompte
|
|
//civilite
|
|
//Nom
|
|
//Prenom
|
|
//tel
|
|
//mobile
|
|
//profil
|
|
//dateInscription
|
|
//dateValidation
|
|
//lang
|
|
//dateDebutCompte
|
|
//dateFinCompte
|
|
//dateInsert
|
|
//dateUpdate
|
|
|
|
//Service
|
|
|
|
}
|
|
|
|
protected function setUserService($service, $id)
|
|
{
|
|
//Déplacer un utilisateur de service - ne pas activer tout de suite
|
|
|
|
}
|
|
|
|
public function setUserEmail($id, $email, $op = null)
|
|
{
|
|
//Which operation
|
|
switch ( $op ) {
|
|
//Ajouter un email secondaire
|
|
case null:
|
|
case 'add':
|
|
break;
|
|
//Supprimer un email secondaire
|
|
case 'del':
|
|
break;
|
|
}
|
|
|
|
|
|
}
|
|
|
|
/**
|
|
* Change password
|
|
* @param string $password
|
|
* @param int $id
|
|
* @throws SoapFault
|
|
* @return boolean
|
|
*/
|
|
public function setUserPassword($password, $id = null)
|
|
{
|
|
$this->authenticate();
|
|
|
|
if ( $id === null ) {
|
|
$id = $this->User->id;
|
|
} elseif ( $id !== null && $this->User->profil != 'Administrateur' ) {
|
|
throw new SoapFault('ERR', 'Accès non authorisé');
|
|
}
|
|
|
|
//Changer le mot de passe
|
|
$userM = new Application_Model_Sdv1Utilisateurs();
|
|
$result = $userM->update(array('password'=>$password), 'id='.$id);
|
|
if ( $result == 1 ) {
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
public function getCategory()
|
|
{
|
|
$output = array();
|
|
foreach ( $this->listeCategory as $code => $desc ) {
|
|
$c = new AccesCategory();
|
|
$c->Code = $code;
|
|
$c->Label = $desc['label'];
|
|
$c->Acces = $desc['droits'];
|
|
$output[] = $c;
|
|
}
|
|
return $output;
|
|
}
|
|
|
|
protected function getAccess()
|
|
{
|
|
//Liste des accès - Code, Label, Category, Description,
|
|
}
|
|
|
|
protected function getPref()
|
|
{
|
|
//Liste des préférences - Code, Label, Description, Values
|
|
}
|
|
|
|
protected function setPref(){}
|
|
|
|
/**
|
|
* Acceptation des CGUs
|
|
* @param string $app
|
|
* @throws SoapFault
|
|
* @return boolean
|
|
*/
|
|
public function setCGU($app = null)
|
|
{
|
|
$this->authenticate();
|
|
|
|
$id = $this->User->id;
|
|
|
|
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;
|
|
}
|
|
|
|
protected function setUserEnable($id)
|
|
{
|
|
//Un administrateur force l'activation d'un utilisateur ?
|
|
$userM = new Application_Model_Sdv1Utilisateurs();
|
|
//actif = 1
|
|
|
|
/**
|
|
* L'utilisateur n'a pas reçu ou a perdu l'email avec son mot de passe, vous pouvez activez sont compte
|
|
* (attention son email ne sera pas validé, et certaines prestations nécessitant un email valide ne peuvent fonctionner)
|
|
*/
|
|
|
|
}
|
|
|
|
protected function setUserValidation($id)
|
|
{
|
|
//Un utilisateur valide son compte pour la première connexion et déclenche l'envoi de validation de l'email
|
|
//Doit-on demander un nouveau mot de passe ? Est ce que le mot de passe a été générer et envoyé par email .
|
|
$userM = new Application_Model_Sdv1Utilisateurs();
|
|
//actif = 0
|
|
//dateValidation pour email
|
|
|
|
//Envoi email de validation
|
|
//lien + email + login + date + hash ('sha256', string ) => string {idClient}{login}{email}{AAAAMMJJ}
|
|
}
|
|
|
|
protected function setUserEmailValidation($id)
|
|
{
|
|
//Validation d'un email
|
|
//Email secondaire ajouté marqueur dateValidation
|
|
}
|
|
|
|
/**
|
|
* Un SuperAdministrateur devenir un utilisateur (pour les tests)
|
|
* @param int $id
|
|
* @throws SoapFault
|
|
*/
|
|
protected function setAdminAs($id)
|
|
{
|
|
$this->authenticate();
|
|
|
|
//Vérification des droits d'utilisation
|
|
if ( $this->User->profil != 'SuperAdministrateur' ) {
|
|
throw new SoapFault('ERR', 'Accès non authorisé');
|
|
}
|
|
|
|
// Pour les SuperAdministrateur, voir l'application comme un login (id)
|
|
|
|
}
|
|
} |