From: vincent@cubedesigners.com Date: Wed, 21 Sep 2011 13:24:11 +0000 (+0000) Subject: (no commit message) X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=b9fbb397c6261a525c2849046775ecc97d755cf5;p=cubeextranet.git --- diff --git a/inc/commons/DAO/class.common.dao.utilisateur.php b/inc/commons/DAO/class.common.dao.utilisateur.php index 76d0b2b40..7dc2cdff4 100644 --- a/inc/commons/DAO/class.common.dao.utilisateur.php +++ b/inc/commons/DAO/class.common.dao.utilisateur.php @@ -1,7 +1,8 @@ rs)) { $utilisateur->rs = $r->rs; } + if (isset($r->ws_domains)) { + $utilisateur->ws_domains = explode(',', $r->ws_domains); + } if ($r->ws_settings != '') { $utilisateur->ws_settings = unserialize($r->ws_settings); } else { @@ -57,14 +61,13 @@ class commonDAOUtilisateur extends commonDAO { if (isset($r->ws_signatures)) { $utilisateur->ws_signatures = $r->ws_signatures; } - if(isset($r->ws_admin)){ - $utilisateur->ws_admin=$r->ws_admin; + if (isset($r->ws_admin)) { + $utilisateur->ws_admin = $r->ws_admin; } return $utilisateur; } - public function cree($utilisateur = null) - { + public function cree($utilisateur = null) { if (is_null($utilisateur)) { $utilisateur = new commonUtilisateur(); } @@ -89,8 +92,7 @@ class commonDAOUtilisateur extends commonDAO { return $utilisateur; } - public function creeFromEntreprise($entreprise_id) - { + public function creeFromEntreprise($entreprise_id) { $utilisateur = $this->cree(null); $utilisateur->entreprise = $entreprise_id; $daoEntreprise = new commonDAOEntreprise($this->con); @@ -102,14 +104,12 @@ class commonDAOUtilisateur extends commonDAO { return $utilisateur; } - public function selectById($utilisateur_id, $table = 'utilisateurs') - { + public function selectById($utilisateur_id, $table = 'utilisateurs') { $r = $this->con->select('SELECT * FROM `' . $table . '` WHERE utilisateur_id=\'' . $this->con->escape($utilisateur_id) . '\' LIMIT 1'); return $this->singleton($r); } - public function selectByLoginPassword($login, $password) - { + public function selectByLoginPassword($login, $password) { $sql = 'SELECT * FROM utilisateurs_entreprise WHERE (email=\'' . $this->con->escape($login) . '\' OR login=\'' . $this->con->escape($login) . '\') AND (password=\'' . $this->con->escape($password) . '\' OR ws_password=\'' . $this->con->escape($password) . '\') LIMIT 1'; $r = $this->con->select($sql); if ($r->count() == 0) { @@ -119,8 +119,7 @@ class commonDAOUtilisateur extends commonDAO { return $utilisateur; } - public function selectByEmail($email) - { + public function selectByEmail($email) { $r = $this->con->select('SELECT * FROM utilisateurs WHERE email=\'' . $this->con->escape($email) . '\''); if ($r->count()) { return $this->singleton($r); @@ -128,32 +127,28 @@ class commonDAOUtilisateur extends commonDAO { return null; } - public function selectWSRevendeursFacturables() - { + public function selectWSRevendeursFacturables() { $r = $this->con->select('SELECT * FROM utilisateurs_entreprise WHERE ws_grade BETWEEN 3 AND 4 AND utilisateur_id IN(SELECT facturable_id FROM ws_users_tree) ORDER BY rs'); return $this->factory($r); } - public function selectWSAdministrateursId() - { + public function selectWSAdministrateursId() { $r = $this->con->select('SELECT * FROM utilisateurs_entreprise WHERE ws_grade=5'); $liste = $this->factory($r); $res = array(); - foreach($liste as $u) { + foreach ($liste as $u) { $res[] = $u->utilisateur_id; } return $res; } - protected function getNextId() - { + protected function getNextId() { $r = $this->con->select('SELECT MAX(utilisateur_id) AS utilisateur_id FROM utilisateurs'); return $r->utilisateur_id + 1; } - protected function getQueryList($table, $orderby = null, $sens = null, $limit = null, $where = null, $limitedToUserRights = false) - { + protected function getQueryList($table, $orderby = null, $sens = null, $limit = null, $where = null, $limitedToUserRights = false) { $wherec = $where; $where = '('; if (!is_null($this->q)) { @@ -167,31 +162,28 @@ class commonDAOUtilisateur extends commonDAO { } $where .= ' ' . $wherec . ' )'; $where .= $this->limitToUserRights($limitedToUserRights); - $orderby = is_null($orderby)?'utilisateur_id':$orderby; - $sens = is_null($sens)?'DESC':$sens; - $limit = is_null($limit)?'':$this->con->limit($limit[0], $limit[1]); + $orderby = is_null($orderby) ? 'utilisateur_id' : $orderby; + $sens = is_null($sens) ? 'DESC' : $sens; + $limit = is_null($limit) ? '' : $this->con->limit($limit[0], $limit[1]); $sql = 'SELECT * FROM ' . $table . ' WHERE (' . $where . ') ORDER BY ' . $orderby . ' ' . $sens . ' ' . $limit; return $sql; } - protected function limitToUserRights($user) - { + protected function limitToUserRights($user) { if ($user) { return ' AND utilisateur_id IN (' . $user->ws_rights . ')'; } return ''; } - public function getListe($orderby = null, $sens = null, $limit = null, $where = null, $limitedToUserRights = false) - { + public function getListe($orderby = null, $sens = null, $limit = null, $where = null, $limitedToUserRights = false) { $sql = $this->getQueryList('utilisateurs_entreprise', $orderby, $sens, $limit, $where, $limitedToUserRights); $r = $this->con->select($sql); return $this->factory($r); } - public function whereSearchByName($q, $search_entreprise = true) - { + public function whereSearchByName($q, $search_entreprise = true) { $where = 'nom LIKE \'' . $this->con->escape($q) . '%\' OR '; $where .= 'prenom LIKE \'' . $this->con->escape($q) . '%\' OR '; $where .= 'CONCAT(prenom,\' \',nom) LIKE \'' . $this->con->escape($q) . '%\' OR '; @@ -203,8 +195,7 @@ class commonDAOUtilisateur extends commonDAO { return $where; } - public function sauve($data) - { + public function sauve($data) { $c = $this->con->openCursor('utilisateurs'); $c->grade = $data['grade']; $c->nom = $data['nom']; @@ -240,22 +231,19 @@ class commonDAOUtilisateur extends commonDAO { } } - public function sauveNotes($utilisateur_id, $notes) - { + public function sauveNotes($utilisateur_id, $notes) { $c = $this->con->openCursor('utilisateurs'); $c->notes = $notes; return $c->update('WHERE utilisateur_id=\'' . $this->con->escape($utilisateur_id) . '\''); } - public function sauveWSSettings($utilisateur_id, $datas) - { + public function sauveWSSettings($utilisateur_id, $datas) { $c = $this->con->openCursor('utilisateurs'); $c->ws_settings = serialize($datas); return $c->update('WHERE utilisateur_id=\'' . $this->con->escape($utilisateur_id) . '\''); } - public function sauvePreferences($utilisateur) - { + public function sauvePreferences($utilisateur) { if ($utilisateur) { $c = $this->con->openCursor('utilisateurs'); $c->settings = serialize($utilisateur->settings); @@ -264,38 +252,34 @@ class commonDAOUtilisateur extends commonDAO { return false; } - public function changeParametres($utilisateur_id, $langue, $login) - { + public function changeParametres($utilisateur_id, $langue, $login) { $c = $this->con->openCursor('utilisateurs'); $c->lang = $langue; $c->login = $login; return $c->update('WHERE utilisateur_id=\'' . $this->con->escape($utilisateur_id) . '\''); } - public function changeMotdepasse($utilisateur_id, $nouveau) - { + public function changeMotdepasse($utilisateur_id, $nouveau) { $c = $this->con->openCursor('utilisateurs'); $c->password = $nouveau; return $c->update('WHERE utilisateur_id=\'' . $this->con->escape($utilisateur_id) . '\''); } - public function supprime($utilisateur_id) - { + public function supprime($utilisateur_id) { $ok = $this->con->execute('DELETE FROM utilisateurs WHERE utilisateur_id=\'' . $this->con->escape($utilisateur_id) . '\''); $core->refreshWSUsersTree(); return $ok; } - public function count() - { + public function count() { $r = $this->con->select('SELECT COUNT(*) AS nb FROM utilisateurs WHERE ' . $this->makeWhereFromFiltres()); return $r->nb; } - protected function makeWhereFromFiltres() - { + protected function makeWhereFromFiltres() { return '1=1'; } + } ?> \ No newline at end of file diff --git a/inc/commons/Metier/class.common.utilisateur.php b/inc/commons/Metier/class.common.utilisateur.php index b8df4e7ff..da6f1fd60 100644 --- a/inc/commons/Metier/class.common.utilisateur.php +++ b/inc/commons/Metier/class.common.utilisateur.php @@ -28,6 +28,7 @@ class commonUtilisateur extends cubeMetier { protected $ws_settings; protected $ws_rights; protected $ws_signatures; + protected $ws_domains; public function getEmail() { diff --git a/inc/commons/class.common.core.php b/inc/commons/class.common.core.php index a313f92e5..1c0ebe9c8 100644 --- a/inc/commons/class.common.core.php +++ b/inc/commons/class.common.core.php @@ -142,6 +142,7 @@ class commonCore extends cubeCore { $db->utilisateurs->ws_password('varchar', 40, false); $db->utilisateurs->ws_settings('text', 0, false); $db->utilisateurs->ws_rights('text', 0, false); + $db->utilisateurs->ws_domains('text', 0, false); // Clés $db->utilisateurs->primary('pk_utilisateurs', 'utilisateur_id'); $db->utilisateurs->unique('unique_utilisateurs_email', 'email'); diff --git a/inc/ws/Controlleur/class.ws.ajax.php b/inc/ws/Controlleur/class.ws.ajax.php index 3ea748830..9858110c4 100644 --- a/inc/ws/Controlleur/class.ws.ajax.php +++ b/inc/ws/Controlleur/class.ws.ajax.php @@ -575,7 +575,7 @@ class wsAjax extends cubeAjax { $daoUtilisateur = new commonDAOUtilisateur($core->con); $demande = $dao->selectById($args[1]); - + if ($demande->administrateur != 0 && $demande->administrateur != $core->user->utilisateur_id) { $res = __("Cette demande est actuellement en cours d'édition par un autre administrateur"); } elseif ($demande->status > 1) { @@ -592,15 +592,30 @@ class wsAjax extends cubeAjax { $revendeur = $daoUtilisateur->selectById($demandeur->ws_admin, 'utilisateurs_entreprise'); $actions[__('Je confie la demande à') . ' ' . $revendeur->rs . ' (' . $revendeur->prenom . ' ' . $revendeur->nom . ')'] = $demandeur->ws_admin; } else { + $d = explode('@', $demandeur->email); + $domain = mb_strtolower($d[1]); + $liste = $daoUtilisateur->selectWSRevendeursFacturables(); $revendeurs = array(); + $revendeurs_prio = array(); foreach ($liste as $revendeur) { - $revendeurs[$revendeur->rs . '(' . $revendeur->prenom . ' ' . $revendeur->nom . ')'] = $revendeur->utilisateur_id; + $k = $revendeur->rs . '(' . $revendeur->prenom . ' ' . $revendeur->nom . ')'; + $v = $revendeur->utilisateur_id; + if (in_array($domain, $revendeur->ws_domains)) { + $revendeurs_prio[$k] = $v; + } else { + $revendeurs[$k] = $v; + } } $actions = array(__('Je vais me charger de cette demande') => $core->user->utilisateur_id); $actions[' '] = array(); - $actions[__('Je confie la demande à') . ' : '] = $revendeurs; + if (count($revendeurs_prio)) { + $actions[__('Je confie la demande à (liste suggérée) ') . ' : '] = $revendeurs_prio; + } + if (count($revendeurs)) { + $actions[__('Je confie la demande à ') . ' : '] = $revendeurs; + } } $res = form::combo('revendeur', $actions); } diff --git a/inc/ws/Controlleur/class.ws.users.tree.php b/inc/ws/Controlleur/class.ws.users.tree.php index c7530f582..af642cc31 100644 --- a/inc/ws/Controlleur/class.ws.users.tree.php +++ b/inc/ws/Controlleur/class.ws.users.tree.php @@ -23,6 +23,7 @@ class wsUsersTree { $this->admins = array(); $this->grades = array(); $this->entreprises = array(); + $this->domains = array(); $this->rights = array(); @@ -38,6 +39,8 @@ class wsUsersTree { $this->admins[$r->utilisateur_id] = array(); } $this->admins[$r->ws_admin][] = $r->utilisateur_id; + $d = explode('@', $r->email); + $this->domains[$r->utilisateur_id] = mb_strtolower($d[1]); } $this->facturables = $this->getFacturables(); @@ -100,14 +103,23 @@ class wsUsersTree { } } + $adom = array(); + foreach ($this->admins as $admin => $list) { $this->admins[$admin] = array_unique($list); sort($this->admins[$admin]); + + $adom[$admin] = array(); + foreach ($list as $id) { + $adom[$admin][] = $this->domains[$id]; + } + $adom[$admin] = array_unique($adom[$admin]); } $c = $this->con->openCursor('utilisateurs'); foreach ($this->admins as $admin => $list) { $c->ws_rights = implode(',', $list); + $c->ws_domains = implode(',', $adom[$admin]); $c->update('WHERE utilisateur_id=\'' . $this->con->escape($admin) . '\''); } }