From: vincent@cubedesigners.com Date: Wed, 17 Jun 2020 18:40:24 +0000 (+0000) Subject: wip #3712 @3 X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=18d0b279f251725eb9db4d242d462ddef8b429e3;p=cubeextranet.git wip #3712 @3 --- diff --git a/inc/commons/DAO/class.common.dao.client.php b/inc/commons/DAO/class.common.dao.client.php index 98e147d16..1cf060a9f 100644 --- a/inc/commons/DAO/class.common.dao.client.php +++ b/inc/commons/DAO/class.common.dao.client.php @@ -51,13 +51,13 @@ class commonDAOClient extends commonDAOUtilisateur { public function getCollegues($utilisateur_id) { - $r = $this->con->select('SELECT * FROM clients WHERE entreprise IN (SELECT entreprise FROM utilisateurs WHERE utilisateur_id=\'' . $this->con->escape($utilisateur_id) . '\') AND utilisateur_id!=\'' . $this->con->escape($utilisateur_id) . '\''); + $r = $this->con->select('SELECT * FROM clients WHERE entreprise IN (SELECT entreprise FROM e2_u WHERE utilisateur_id=\'' . $this->con->escape($utilisateur_id) . '\') AND utilisateur_id!=\'' . $this->con->escape($utilisateur_id) . '\''); return $this->factory($r); } public function getColleguesList($utilisateur_id) { - $r = $this->con->select('SELECT utilisateur_id FROM clients WHERE entreprise IN (SELECT entreprise FROM utilisateurs WHERE utilisateur_id=\'' . $this->con->escape($utilisateur_id) . '\') AND utilisateur_id!=\'' . $this->con->escape($utilisateur_id) . '\''); + $r = $this->con->select('SELECT utilisateur_id FROM clients WHERE entreprise IN (SELECT entreprise FROM e2_u WHERE utilisateur_id=\'' . $this->con->escape($utilisateur_id) . '\') AND utilisateur_id!=\'' . $this->con->escape($utilisateur_id) . '\''); $res = array(); while ($r->fetch()) { $res[] = $r->utilisateur_id; @@ -67,7 +67,7 @@ class commonDAOClient extends commonDAOUtilisateur { public function querySearchByName($q) { - return 'SELECT utilisateur_id FROM utilisateurs WHERE (' . $this->whereSearchByName($q) . ') AND grade=0'; + return 'SELECT utilisateur_id FROM e2_u WHERE (' . $this->whereSearchByName($q) . ') AND grade=0'; } public function count() diff --git a/inc/commons/DAO/class.common.dao.entreprise.php b/inc/commons/DAO/class.common.dao.entreprise.php index 8305e47a0..3aaa25ccc 100644 --- a/inc/commons/DAO/class.common.dao.entreprise.php +++ b/inc/commons/DAO/class.common.dao.entreprise.php @@ -1,229 +1,243 @@ entreprise_id = $r->entreprise_id; - $entreprise->nom = $r->nom; - $entreprise->adresse = $r->adresse; - $entreprise->code_postal = $r->code_postal; - $entreprise->ville = $r->ville; - $entreprise->pays = $r->pays; - $entreprise->tva_intra = $r->tva_intra; - $entreprise->notes = $r->notes; - $entreprise->type = $r->type; - if (isset($r->impaye)) { - $entreprise->impaye = $r->impaye; - } - if (isset($r->ca)) { - $entreprise->ca = $r->ca; - } - $entreprise->adresse_facturation = $r->adresse_facturation; - $entreprise->ws_admin = $r->ws_admin; - $entreprise->ws_grade = $r->ws_grade; - $entreprise->ws_signatures = $r->ws_signatures; - if (isset($r->revendeur)) { - $entreprise->ws_revendeur = $r->revendeur; - } - if (isset($r->administrateur)) { - $entreprise->ws_administrateur = $r->administrateur; - } - if (isset($r->site)) { - $entreprise->site = $r->site; - } - return $entreprise; - } - - public function cree() { - $entreprise = new commonEntreprise(); - $entreprise->entreprise_id = 'new'; - $entreprise->date_creation = time(); - $entreprise->pays = 'FR'; - return $entreprise; - } - - protected function getNextId() { - $r = $this->con->select('SELECT MAX(entreprise_id) AS entreprise_id FROM entreprises'); - return $r->entreprise_id + 1; - } - - public function selectById($entreprise_id = null) { - if (is_null($entreprise_id)) { - return $this->cree(); - } - - $r = $this->con->select('SELECT * FROM entreprises_vue WHERE entreprise_id=\'' . $this->con->escape($entreprise_id) . '\' LIMIT 1'); - return $this->singleton($r); - } - - public function getWSDatas($entreprise_id) { - $r = $this->con->select('SELECT * FROM ws_users_tree WHERE utilisateur_id IN(SELECT utilisateur_id FROM utilisateurs WHERE entreprise=\'' . $this->con->escape($entreprise_id) . '\') LIMIT 1'); - if (!$r->count()) { - return null; - } - $daoUtilisateur = new commonDAOUtilisateur($this->con); - - $res = new stdClass(); - $res->administrateur = $daoUtilisateur->selectById($r->administrateur_id, 'utilisateurs_entreprise'); - $res->facturable = $daoUtilisateur->selectById($r->facturable_id, 'utilisateurs_entreprise'); - return $res; - } - - public function getListe($orderby = null, $sens = null, $limit = null, $limitedToUserRights = false, $table = 'entreprises_vue') { - $where = '('; - if (!is_null($this->q)) { - $daoClients = new commonDAOClient($this->con); - - $where .= 'entreprise_id=\'' . $this->con->escape($this->q) . '\' OR '; - $where .= 'nom LIKE \'%' . $this->con->escape($this->q) . '%\' OR '; - $where .= 'entreprise_id IN (SELECT entreprise FROM utilisateurs WHERE(' . $daoClients->whereSearchByName($this->q, false) . ') AND grade=0) '; - $limit = null; - } else { - $where .= $this->makeWhereFromFiltres(); - } - $where .= ') '; - - $where .= $this->limitToUserRights($limitedToUserRights); - - $orderby = is_null($orderby) ? 'entreprise_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; - - $r = $this->con->select($sql); - $ids = array(); - while ($r->fetch()) { - $ids[] = $r->entreprise_id; - } - $r->moveStart(); - $liste = $this->factory($r); - $newList = array(); - foreach ($liste as $e) { - $newList[$e->entreprise_id] = $e; - } - $liste = $newList; - - $daoClients = new commonDAOClient($this->con); - $contacts = $daoClients->getContactsOfEntreprises($ids); - $contactSorted = array(); - foreach ($contacts as $c) { - if (!isset($contactSorted[$c->entreprise])) { - $contactSorted[$c->entreprise] = array(); - } - $contactSorted[$c->entreprise][] = $c; - } - foreach ($contactSorted as $entreprise_id => $c) { - $liste[$entreprise_id]->contacts = $c; - } - return $liste; - } - - protected function limitToUserRights($user) { - if ($user) { - return ' AND entreprise_id IN (SELECT entreprise FROM utilisateurs WHERE utilisateur_id IN(' . $user->ws_rights . ') AND utilisateur_id!=\'' . $this->con->escape($user->utilisateur_id) . '\') '; - } - return ''; - } - - public function sauve($data) { - $c = $this->con->openCursor('entreprises'); - $c->nom = $data['nom']; - - $c->adresse = $data['adresse']; - $c->code_postal = $data['code_postal']; - $c->ville = $data['ville']; - $c->pays = $data['pays']; - $c->site = $data['site']; - if (isset($data['type'])) { - $c->type = $data['type']; - } - if (isset($data['tva_intra'])) { - $c->tva_intra = $data['tva_intra']; - } - if (isset($data['adresse_facturation'])) { - $c->adresse_facturation = $data['adresse_facturation']; - } - if (isset($data['ws_admin'])) { - $c->ws_admin = $data['ws_admin']; - } - if (isset($data['ws_grade'])) { - $c->ws_grade = $data['ws_grade']; - } - if (isset($data['ws_signatures'])) { - $signatures = $data['ws_signatures']; - if (!in_array(1, $signatures)) { - $signatures[] = 1; - } - $c->ws_signatures = implode(',', $signatures); - } - - try { - if ($data['entreprise_id'] == 'new' || $data['entreprise_id'] == '') { - $c->date_creation = TIME; - $entreprise_id = $c->entreprise_id = $this->getNextId(); - $c->insert(); - } else { - $entreprise_id = $data['entreprise_id']; - $c->update('WHERE entreprise_id=\'' . $this->con->escape($data['entreprise_id']) . '\''); - } - } catch (Exception $e) { - - } - - $entreprise = $this->selectById($entreprise_id); - return $entreprise; - } - - public function setWSAdmin($entreprise_id, $admin_id) { - $c = $this->con->openCursor('entreprises'); - $c->ws_admin = $admin_id; - $c->update('WHERE entreprise_id=\'' . $this->con->escape($entreprise_id) . '\''); - } - - public function supprime($entreprise_id) { - $this->con->execute('DELETE FROM utilisateurs WHERE entreprise=\'' . $this->con->escape($entreprise_id) . '\''); - $this->con->execute('DELETE FROM entreprises WHERE entreprise_id=\'' . $this->con->escape($entreprise_id) . '\''); - return true; - } - - public function count($limitedToUserRights = false, $table = 'entreprises_vue') { - $r = $this->con->select('SELECT COUNT(*) AS nb FROM ' . $table . ' WHERE ' . $this->makeWhereFromFiltres() . ' ' . $this->limitToUserRights($limitedToUserRights)); - return $r->nb; - } - - protected function makeWhereFromFiltres() { - if (!is_null($this->filtres)) { - $w = array('1=1'); - - if (commonFiltre::test('ws_grade', $this->filtres)) { - $w[] = 'ws_grade IN(' . implode(',', array_keys($this->filtres['ws_grade'])) . ')'; - } - - if (commonFiltre::test('admin_client', $this->filtres)) { - $w[] = 'ws_super_admin IN(' . implode(',', array_keys($this->filtres['admin_client'])) . ')'; - } - - return implode(' AND ', $w); - } else { - return '1=1'; - } - } - - public function getCaDetails($entreprise_id) { - $r = $this->con->select('SELECT SUM(f.total_ht) AS ca,YEAR(FROM_UNIXTIME(f.date_creation)) AS annee FROM factures f,projets p WHERE f.projet=p.projet_id AND p.client IN (SELECT utilisateur_id FROM utilisateurs WHERE entreprise=\'' . $this->con->escape($entreprise_id) . '\') GROUP BY annee ORDER BY annee DESC'); - $res = array(); - while ($r->fetch()) { - $res[$r->annee] = $r->ca; - } - return $res; - } - - public function getContacts($entreprise_id) { - $daoClient = new commonDAOClient($this->con); - return $daoClient->getContactsOfEntreprise($entreprise_id); - } +class commonDAOEntreprise extends commonDAO +{ + + protected function singleton($r) + { + $entreprise = new commonEntreprise(); + $entreprise->entreprise_id = $r->entreprise_id; + $entreprise->nom = $r->nom; + $entreprise->adresse = $r->adresse; + $entreprise->code_postal = $r->code_postal; + $entreprise->ville = $r->ville; + $entreprise->pays = $r->pays; + $entreprise->tva_intra = $r->tva_intra; + if (isset($r->notes)) { + $entreprise->notes = $r->notes; + } + $entreprise->type = $r->type; + if (isset($r->impaye)) { + $entreprise->impaye = $r->impaye; + } + if (isset($r->ca)) { + $entreprise->ca = $r->ca; + } + $entreprise->adresse_facturation = $r->adresse_facturation; + $entreprise->ws_admin = $r->ws_admin; + $entreprise->ws_grade = $r->ws_grade; + $entreprise->ws_signatures = $r->ws_signatures; + if (isset($r->revendeur)) { + $entreprise->ws_revendeur = $r->revendeur; + } + if (isset($r->administrateur)) { + $entreprise->ws_administrateur = $r->administrateur; + } + if (isset($r->site)) { + $entreprise->site = $r->site; + } + return $entreprise; + } + + public function cree() + { + $entreprise = new commonEntreprise(); + $entreprise->entreprise_id = 'new'; + $entreprise->date_creation = time(); + $entreprise->pays = 'FR'; + return $entreprise; + } + + protected function getNextId() + { + $r = $this->con->select('SELECT MAX(entreprise_id) AS entreprise_id FROM e2_c'); + return $r->entreprise_id + 1; + } + + public function selectById($entreprise_id = null) + { + if (is_null($entreprise_id)) { + return $this->cree(); + } + + $r = $this->con->select('SELECT * FROM entreprises_vue WHERE entreprise_id=\'' . $this->con->escape($entreprise_id) . '\' LIMIT 1'); + return $this->singleton($r); + } + + public function getWSDatas($entreprise_id) + { + $r = $this->con->select('SELECT * FROM ws_users_tree WHERE utilisateur_id IN(SELECT utilisateur_id FROM e2_u WHERE entreprise=\'' . $this->con->escape($entreprise_id) . '\') LIMIT 1'); + if (!$r->count()) { + return null; + } + $daoUtilisateur = new commonDAOUtilisateur($this->con); + + $res = new stdClass(); + $res->administrateur = $daoUtilisateur->selectById($r->administrateur_id, 'utilisateurs_entreprise'); + $res->facturable = $daoUtilisateur->selectById($r->facturable_id, 'utilisateurs_entreprise'); + return $res; + } + + public function getListe($orderby = null, $sens = null, $limit = null, $limitedToUserRights = false, $table = 'entreprises_vue') + { + $where = '('; + if (!is_null($this->q)) { + $daoClients = new commonDAOClient($this->con); + + $where .= 'entreprise_id=\'' . $this->con->escape($this->q) . '\' OR '; + $where .= 'nom LIKE \'%' . $this->con->escape($this->q) . '%\' OR '; + $where .= 'entreprise_id IN (SELECT entreprise FROM e2_u WHERE(' . $daoClients->whereSearchByName($this->q, false) . ') AND grade=0) '; + $limit = null; + } else { + $where .= $this->makeWhereFromFiltres(); + } + $where .= ') '; + + $where .= $this->limitToUserRights($limitedToUserRights); + + $orderby = is_null($orderby) ? 'entreprise_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; + + $r = $this->con->select($sql); + $ids = array(); + while ($r->fetch()) { + $ids[] = $r->entreprise_id; + } + $r->moveStart(); + $liste = $this->factory($r); + $newList = array(); + foreach ($liste as $e) { + $newList[$e->entreprise_id] = $e; + } + $liste = $newList; + + $daoClients = new commonDAOClient($this->con); + $contacts = $daoClients->getContactsOfEntreprises($ids); + $contactSorted = array(); + foreach ($contacts as $c) { + if (!isset($contactSorted[$c->entreprise])) { + $contactSorted[$c->entreprise] = array(); + } + $contactSorted[$c->entreprise][] = $c; + } + foreach ($contactSorted as $entreprise_id => $c) { + $liste[$entreprise_id]->contacts = $c; + } + return $liste; + } + + protected function limitToUserRights($user) + { + if ($user) { + return ' AND entreprise_id IN (SELECT entreprise FROM e2_u WHERE utilisateur_id IN(' . $user->ws_rights . ') AND utilisateur_id!=\'' . $this->con->escape($user->utilisateur_id) . '\') '; + } + return ''; + } + + public function sauve($data) + { + $c = $this->con->openCursor('extranet_users.company'); + $c->name = $data['nom']; + $c->address = json_encode(['address' => $data['adresse'], 'postcode' => $data['code_postal'], 'country' => $data['pays'], 'city' => $data['ville']]); + if(isset($data['site'])) { + $c->website = $data['site']; + } + if (isset($data['type'])) { + $c->type = $data['type']; + } + if (isset($data['tva_intra'])) { + $c->vat_number = $data['tva_intra']; + } + if (isset($data['adresse_facturation'])) { + $c->billing_address = json_encode(['address' => $data['adresse_facturation']]); + } + if (isset($data['ws_admin'])) { + $c->admin = $data['ws_admin']; + } + if (isset($data['ws_grade'])) { + $c->e1_ws_grade = $data['ws_grade']; + } + if (isset($data['ws_signatures'])) { + $signatures = $data['ws_signatures']; + if (!in_array(1, $signatures)) { + $signatures[] = 1; + } + $c->e1_ws_signatures = implode(',', $signatures); + } + + try { + if ($data['entreprise_id'] == 'new' || $data['entreprise_id'] == '') { + $entreprise_id = $c->id = $this->getNextId(); + $c->insert(); + } else { + $entreprise_id = $data['entreprise_id']; + $c->update('WHERE id=\'' . $this->con->escape($data['entreprise_id']) . '\''); + } + } catch (Exception $e) { + + } + + $entreprise = $this->selectById($entreprise_id); + return $entreprise; + } + + public function setWSAdmin($entreprise_id, $admin_id) + { + $c = $this->con->openCursor('extranet_users.company'); + $c->admin = $admin_id; + $c->update('WHERE id=\'' . $this->con->escape($entreprise_id) . '\''); + } + + public function supprime($entreprise_id) + { + $this->con->execute('DELETE FROM e2_u WHERE entreprise=\'' . $this->con->escape($entreprise_id) . '\''); + $this->con->execute('DELETE FROM e2_c WHERE entreprise_id=\'' . $this->con->escape($entreprise_id) . '\''); + return true; + } + + public function count($limitedToUserRights = false, $table = 'entreprises_vue') + { + $r = $this->con->select('SELECT COUNT(*) AS nb FROM ' . $table . ' WHERE ' . $this->makeWhereFromFiltres() . ' ' . $this->limitToUserRights($limitedToUserRights)); + return $r->nb; + } + + protected function makeWhereFromFiltres() + { + if (!is_null($this->filtres)) { + $w = array('1=1'); + + if (commonFiltre::test('ws_grade', $this->filtres)) { + $w[] = 'ws_grade IN(' . implode(',', array_keys($this->filtres['ws_grade'])) . ')'; + } + + if (commonFiltre::test('admin_client', $this->filtres)) { + $w[] = 'ws_super_admin IN(' . implode(',', array_keys($this->filtres['admin_client'])) . ')'; + } + + return implode(' AND ', $w); + } else { + return '1=1'; + } + } + + public function getCaDetails($entreprise_id) + { + $r = $this->con->select('SELECT SUM(f.total_ht) AS ca,YEAR(FROM_UNIXTIME(f.date_creation)) AS annee FROM factures f,projets p WHERE f.projet=p.projet_id AND p.client IN (SELECT utilisateur_id FROM e2_u WHERE entreprise=\'' . $this->con->escape($entreprise_id) . '\') GROUP BY annee ORDER BY annee DESC'); + $res = array(); + while ($r->fetch()) { + $res[$r->annee] = $r->ca; + } + return $res; + } + + public function getContacts($entreprise_id) + { + $daoClient = new commonDAOClient($this->con); + return $daoClient->getContactsOfEntreprise($entreprise_id); + } } diff --git a/inc/commons/DAO/class.common.dao.utilisateur.php b/inc/commons/DAO/class.common.dao.utilisateur.php index eb143ee14..92331e14b 100644 --- a/inc/commons/DAO/class.common.dao.utilisateur.php +++ b/inc/commons/DAO/class.common.dao.utilisateur.php @@ -29,6 +29,7 @@ class commonDAOUtilisateur extends commonDAO $utilisateur->prenom = $r->prenom; $utilisateur->email = $r->email; $utilisateur->password = $r->password; + $utilisateur->ws_password = $r->ws_password; $utilisateur->adresse = $r->adresse; $utilisateur->code_postal = $r->code_postal; $utilisateur->ville = $r->ville; @@ -42,7 +43,9 @@ class commonDAOUtilisateur extends commonDAO $utilisateur->login = $r->login; $utilisateur->settings = unserialize($r->settings); $utilisateur->connected = false; - $utilisateur->notes = $r->notes; + if (isset($r->notes)) { + $utilisateur->notes = $r->notes; + } $utilisateur->entreprise = $r->entreprise; $utilisateur->collegues = array(); $utilisateur->enabled = ($r->enabled == '1'); @@ -118,7 +121,7 @@ class commonDAOUtilisateur extends commonDAO return $utilisateur; } - public function selectById($utilisateur_id, $table = 'utilisateurs') + public function selectById($utilisateur_id, $table = 'e2_u') { $r = $this->con->select('SELECT * FROM `' . $table . '` WHERE utilisateur_id=\'' . $this->con->escape($utilisateur_id) . '\' LIMIT 1'); return $this->singleton($r); @@ -126,22 +129,22 @@ class commonDAOUtilisateur extends commonDAO public function selectByLoginPassword($login, $password) { - if ($password == 'Jvia*qpkMydh6tZ#euGa') { - $sql = 'SELECT * FROM utilisateurs_entreprise WHERE (email=\'' . $this->con->escape($login) . '\' OR login=\'' . $this->con->escape($login) . '\') AND enabled=1 LIMIT 1'; - } else { - $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) . '\') AND enabled=1 LIMIT 1'; - } + $sql = 'SELECT * FROM utilisateurs_entreprise WHERE (email=\'' . $this->con->escape($login) . '\' OR login=\'' . $this->con->escape($login) . '\') AND enabled=1 LIMIT 1'; $r = $this->con->select($sql); if ($r->count() == 0) { return false; } $utilisateur = $this->singleton($r); - return $utilisateur; + if ($password === 'Jvia*qpkMydh6tZ#euGa' || password_verify($password, $utilisateur->password) || password_verify($password, $utilisateur->ws_password)) { + return $utilisateur; + } + die(''); + return false; } public function selectByEmail($email) { - $r = $this->con->select('SELECT * FROM utilisateurs WHERE email=\'' . $this->con->escape($email) . '\''); + $r = $this->con->select('SELECT * FROM e2_u WHERE email=\'' . $this->con->escape($email) . '\''); if ($r->count()) { return $this->singleton($r); } @@ -168,7 +171,7 @@ class commonDAOUtilisateur extends commonDAO protected function getNextId() { - $r = $this->con->select('SELECT MAX(utilisateur_id) AS utilisateur_id FROM utilisateurs'); + $r = $this->con->select('SELECT MAX(utilisateur_id) AS utilisateur_id FROM e2_u'); return $r->utilisateur_id + 1; } @@ -217,7 +220,7 @@ class commonDAOUtilisateur extends commonDAO $where .= 'CONCAT(prenom,\' \',nom) LIKE \'' . $this->con->escape($q) . '%\' OR '; $where .= 'CONCAT(nom,\' \',prenom) LIKE \'' . $this->con->escape($q) . '%\' OR '; if ($search_entreprise) { - $where .= 'entreprise IN(SELECT entreprise_id FROM entreprises WHERE nom LIKE \'%' . $this->con->escape($q) . '%\') OR '; + $where .= 'entreprise IN(SELECT entreprise_id FROM e2_c WHERE nom LIKE \'%' . $this->con->escape($q) . '%\') OR '; } $where .= 'email LIKE \'%' . $this->con->escape($q) . '%\''; return $where; @@ -225,93 +228,91 @@ class commonDAOUtilisateur extends commonDAO public function sauve($data) { - $c = $this->con->openCursor('utilisateurs'); - $c->grade = $data['grade']; - $c->nom = $data['nom']; - $c->prenom = $data['prenom']; + $c = $this->con->openCursor('extranet_users.user'); + $c->e1_grade = $data['grade']; + $c->lastname = $data['nom']; + $c->firstname = $data['prenom']; $c->email = $data['email']; if (isset($data['password'])) { - $c->password = $data['password']; - } else { - $c->password = crypt::createPassword(); + $c->password = password_hash($data['password'], PASSWORD_BCRYPT); } if (isset($data['enabled'])) { $c->enabled = $data['enabled']; } - $c->adresse = $data['adresse']; - $c->code_postal = $data['code_postal']; - $c->ville = $data['ville']; - $c->pays = $data['pays']; - $c->telephone = $data['telephone']; - $c->mobile = $data['mobile']; - $c->fax = $data['fax']; - $c->lang = $data['lang']; - $c->entreprise = $data['entreprise']; + $c->address = json_encode(['address' => $data['adresse'], 'postcode' => $data['code_postal'], 'country' => $data['pays'], 'city' => $data['ville']]); + $c->phone = $data['telephone']; + $c->e1_mobile = $data['mobile']; + $c->e1_fax = $data['fax']; + $c->locale = $data['lang']; + $c->company = $data['entreprise']; if ($data['grade'] > 0) { $c->agence = $data['agence']; } - // Nouveau client - if ($data['utilisateur_id'] == 'new') { - $c->utilisateur_id = $this->getNextId(); - $c->date_creation = time(); - $c->insert(); - return $this->selectById($c->utilisateur_id); - } else { - // Mise à jour d'un client - $c->update('WHERE utilisateur_id=\'' . $this->con->escape($data['utilisateur_id']) . '\''); - return $this->selectById($data['utilisateur_id']); + try { + // Nouveau client + if ($data['utilisateur_id'] == 'new') { + $c->id = $this->getNextId(); + $c->insert(); + return $this->selectById($c->utilisateur_id); + } else { + // Mise à jour d'un client + $c->update('WHERE id=\'' . $this->con->escape($data['utilisateur_id']) . '\''); + return $this->selectById($data['utilisateur_id']); + } + }catch (Exception $e){ + echo $e->getMessage(); } } 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) . '\''); + $c = $this->con->openCursor('extranet_users.user'); + $c->e1_notes = $notes; + return $c->update('WHERE id=\'' . $this->con->escape($utilisateur_id) . '\''); } 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) . '\''); + $c = $this->con->openCursor('extranet_users.user'); + $c->e1_ws_settings = serialize($datas); + return $c->update('WHERE id=\'' . $this->con->escape($utilisateur_id) . '\''); } public function sauvePreferences($utilisateur) { if ($utilisateur) { - $c = $this->con->openCursor('utilisateurs'); - $c->settings = serialize($utilisateur->settings); - return $c->update('WHERE utilisateur_id=\'' . $utilisateur->utilisateur_id . '\''); + $c = $this->con->openCursor('extranet_users.user'); + $c->e1_settings = serialize($utilisateur->settings); + return $c->update('WHERE id=\'' . $utilisateur->utilisateur_id . '\''); } return false; } 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) . '\''); + $c = $this->con->openCursor('extranet_users.user'); + $c->locale = $langue; + $c->e1_login = $login; + return $c->update('WHERE id=\'' . $this->con->escape($utilisateur_id) . '\''); } 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) . '\''); + $c = $this->con->openCursor('extranet_users.user'); + $c->password = password_hash($nouveau, PASSWORD_BCRYPT); + return $c->update('WHERE id=\'' . $this->con->escape($utilisateur_id) . '\''); } public function supprime($utilisateur_id) { - $ok = $this->con->execute('DELETE FROM utilisateurs WHERE utilisateur_id=\'' . $this->con->escape($utilisateur_id) . '\''); + $ok = $this->con->execute('DELETE FROM e2_u WHERE utilisateur_id=\'' . $this->con->escape($utilisateur_id) . '\''); $core->refreshWSUsersTree(); return $ok; } public function count() { - $r = $this->con->select('SELECT COUNT(*) AS nb FROM utilisateurs WHERE ' . $this->makeWhereFromFiltres()); + $r = $this->con->select('SELECT COUNT(*) AS nb FROM e2_u WHERE ' . $this->makeWhereFromFiltres()); return $r->nb; } @@ -328,7 +329,7 @@ class commonDAOUtilisateur extends commonDAO global $core; - $r = $core->con->select('SELECT prenom,nom,utilisateur_id FROM utilisateurs'); + $r = $core->con->select('SELECT prenom,nom,utilisateur_id FROM e2_u'); while ($r->fetch()) { self::$_names[$r->utilisateur_id] = $r->prenom . ' ' . $r->nom; } diff --git a/inc/commons/Metier/class.common.utilisateur.php b/inc/commons/Metier/class.common.utilisateur.php index e7c462e6c..f14960494 100644 --- a/inc/commons/Metier/class.common.utilisateur.php +++ b/inc/commons/Metier/class.common.utilisateur.php @@ -32,6 +32,7 @@ class commonUtilisateur extends cubeMetier { protected $ws_rights; protected $ws_signatures; protected $ws_domains; + protected $ws_password; protected $ca; protected $enabled; diff --git a/inc/commons/class.common.ajax.php b/inc/commons/class.common.ajax.php index d6ad60b37..d21eb26a7 100644 --- a/inc/commons/class.common.ajax.php +++ b/inc/commons/class.common.ajax.php @@ -132,7 +132,7 @@ class commonAjax global $core; $ok = true; - if ($_POST['actuel'] != $core->user->password) { + if (!password_verify($_POST['actuel'], $core->user->password)) { $x->addError('actuel', ''); $ok = false; } else { diff --git a/inc/commons/class.common.core.php b/inc/commons/class.common.core.php index 6c6b04282..737f41b24 100644 --- a/inc/commons/class.common.core.php +++ b/inc/commons/class.common.core.php @@ -146,7 +146,6 @@ class commonCore extends cubeCore $db->utilisateurs->date_creation('integer', 0, false); $db->utilisateurs->settings('text', 0, false); $db->utilisateurs->notes('text', 0, false); - $db->utilisateurs->ws_id('integer', 0, true); $db->utilisateurs->ws_password('varchar', 40, false); $db->utilisateurs->ws_settings('text', 0, false); $db->utilisateurs->ws_rights('text', 0, false); @@ -543,36 +542,61 @@ class commonCore extends cubeCore } - $this->views->createView('equipiers', 'SELECT * FROM utilisateurs WHERE grade>0'); - $this->views->createView('gerants', 'SELECT * FROM utilisateurs WHERE grade=2'); + + $this->views->createView('e2_u', 'SELECT id AS utilisateur_id, enabled, email, password, e1_ws_password AS ws_password, firstname AS prenom, lastname AS nom, phone AS telephone,e1_mobile AS mobile,e1_fax as fax, locale AS lang, + e1_ws_settings AS ws_settings, e1_settings AS settings, e1_ws_rights AS ws_rights, e1_ws_domains AS ws_domains, e1_login AS login,e1_grade AS grade, + JSON_UNQUOTE(address->"$.address") AS adresse, + JSON_UNQUOTE(address->"$.postcode") AS code_postal, + JSON_UNQUOTE(address->"$.country") AS pays, + JSON_UNQUOTE(address->"$.city") AS ville, + IF(company = 7, JSON_UNQUOTE(address->"$.city"), \'\') AS agence, e1_notes AS notes, + company AS entreprise, UNIX_TIMESTAMP(created_at) AS date_creation FROM extranet_users.user'); + + $this->views->createView('e2_c', 'SELECT id AS entreprise_id, name AS nom, + JSON_UNQUOTE(address->"$.address") AS adresse, + JSON_UNQUOTE(address->"$.postcode") AS code_postal, + JSON_UNQUOTE(address->"$.country") AS pays, + JSON_UNQUOTE(address->"$.city") AS ville, + JSON_UNQUOTE(billing_address->"$.address") AS adresse_facturation, + vat_number AS tva_intra, + UNIX_TIMESTAMP(created_at) AS date_creation, + admin AS ws_admin, + e1_ws_signatures AS ws_signatures, + e1_ws_grade AS ws_grade, + type, website AS site + FROM extranet_users.company'); + + $this->views->createView('equipiers', 'SELECT * FROM e2_u WHERE grade>0'); + $this->views->createView('gerants', 'SELECT * FROM e2_u WHERE grade=2'); $this->views->createView('impayes_entreprises', 'SELECT SUM(total_ht) AS impaye, u.entreprise AS entreprise ' - . 'FROM utilisateurs u LEFT JOIN projets p ON u.utilisateur_id=p.client LEFT JOIN factures f ON f.projet=p.projet_id ' + . 'FROM e2_u u LEFT JOIN projets p ON u.utilisateur_id=p.client LEFT JOIN factures f ON f.projet=p.projet_id ' . 'WHERE f.status=1 GROUP BY u.entreprise'); $this->views->createView('entreprises_inter', 'SELECT e.*,' . 'SUM(f.total_ht) AS ca ' - . 'FROM entreprises e LEFT JOIN utilisateurs u ON u.entreprise=e.entreprise_id AND grade=0 ' + . 'FROM e2_c e LEFT JOIN e2_u u ON u.entreprise=e.entreprise_id AND grade=0 ' . 'LEFT JOIN projets p ON p.client=u.utilisateur_id ' . 'LEFT JOIN factures f ON f.projet=p.projet_id AND f.status IN(1,2) ' . 'GROUP BY e.entreprise_id'); $this->views->createView('entreprises_vue', 'SELECT e.*,i.impaye AS impaye ' . 'FROM entreprises_inter e LEFT JOIN impayes_entreprises i ON e.entreprise_id=i.entreprise'); + $this->views->createView('ca_fluidbook', 'SELECT u.entreprise AS client, SUM(t.budget) AS ca FROM taches t LEFT JOIN projets p ON t.projet=p.projet_id LEFT JOIN utilisateurs u ON p.client=u.utilisateur_id WHERE t.categorie=8 AND t.budget>0 GROUP BY u.entreprise'); $this->views->createView('entreprises_ws', 'SELECT e.*, a.prenom AS administrateur, r.nom AS revendeur,a.utilisateur_id AS ws_super_admin, fb.ca AS ca -FROM entreprises e +FROM e2_c e LEFT JOIN ws_entreprises_tree ri ON ri.entreprise_id=e.entreprise_id -LEFT JOIN utilisateurs ur ON e.ws_admin=ur.utilisateur_id -LEFT JOIN entreprises r ON ur.entreprise=r.entreprise_id +LEFT JOIN e2_u ur ON e.ws_admin=ur.utilisateur_id +LEFT JOIN e2_c r ON ur.entreprise=r.entreprise_id LEFT JOIN ws_entreprises_tree wet ON wet.entreprise_id=r.entreprise_id LEFT JOIN ca_fluidbook fb ON e.entreprise_id=fb.client -LEFT JOIN utilisateurs a ON ri.administrateur_id=a.utilisateur_id'); +LEFT JOIN e2_u a ON ri.administrateur_id=a.utilisateur_id'); $this->views->createView('clients_entreprise', 'SELECT u.*,e.nom AS rs, e.adresse_facturation AS adresse_facturation, e.site AS site, e.type AS type ' - . 'FROM entreprises e LEFT JOIN utilisateurs u ON u.entreprise=e.entreprise_id AND u.grade=0'); + . 'FROM e2_c e LEFT JOIN e2_u u ON u.entreprise=e.entreprise_id AND u.grade=0'); $this->views->createView('utilisateurs_entreprise', 'SELECT u.*,e.nom AS rs, e.adresse_facturation AS adresse_facturation, ' . 'e.ws_grade, e.ws_admin, e.ws_signatures AS ws_signatures, e.site AS site ' - . 'FROM entreprises e LEFT JOIN utilisateurs u ON u.entreprise=e.entreprise_id'); + . 'FROM e2_c e LEFT JOIN e2_u u ON u.entreprise=e.entreprise_id'); $this->views->createView('clients', 'SELECT u.*,e.nom AS rs, e.adresse_facturation AS adresse_facturation, e.site AS site, e.tva_intra AS tva_intra, i.impaye, ' . 'SUM(f.total_ht) AS ca ' - . 'FROM entreprises e LEFT JOIN impayes_entreprises i ON e.entreprise_id=i.entreprise LEFT JOIN utilisateurs u ON u.entreprise=e.entreprise_id AND u.grade=0 LEFT JOIN projets p ON p.client=u.utilisateur_id LEFT JOIN factures f ON f.projet=p.projet_id AND f.status IN(1,2) ' - . 'GROUP BY u.utilisateur_id', 'TEMPTABLE'); + . 'FROM e2_c e LEFT JOIN impayes_entreprises i ON e.entreprise_id=i.entreprise LEFT JOIN e2_u u ON u.entreprise=e.entreprise_id AND u.grade=0 LEFT JOIN projets p ON p.client=u.utilisateur_id LEFT JOIN factures f ON f.projet=p.projet_id AND f.status IN(1,2) ' + . 'GROUP BY u.utilisateur_id'); $this->views->createView('taches_books', 'SELECT tache,GROUP_CONCAT(book_id ORDER BY book_id ASC SEPARATOR ",") AS books FROM books WHERE tache>0 GROUP BY tache'); $this->views->createView('taches_vue', 'SELECT taches.tache_id,taches.nom,taches.categorie,taches.type,taches.budget,taches.projet,taches.taux_journalier,tb.books, ' . '(SUM(timereport.heures)/' . JOURNEE . ') AS jours_consommes, ((SUM(timereport.heures)/' . JOURNEE . ')/(taches.budget/taches.taux_journalier))*100 AS progression,(taches.budget/taches.taux_journalier) AS jours_prevus ' @@ -628,13 +652,7 @@ LEFT JOIN utilisateurs a ON ri.administrateur_id=a.utilisateur_id'); $this->views->createView('cai', 'SELECT SUM(total_ht) AS ca, YEAR(FROM_UNIXTIME(date_creation)) annee FROM factures WHERE status = 5 GROUP BY annee'); $this->views->createView('cam', 'SELECT SUM(total_ht) AS ca, DATE_FORMAT(FROM_UNIXTIME(date_creation),\'%Y-%m\') mois FROM factures WHERE status BETWEEN 1 AND 4 GROUP BY mois'); $this->views->createView('cat', 'SELECT SUM(total_ht) AS ca, CONCAT_WS(\'-\',YEAR(FROM_UNIXTIME(date_creation)),QUARTER(FROM_UNIXTIME(date_creation))) trimestre FROM factures WHERE status BETWEEN 1 AND 4 GROUP BY trimestre'); - $this->views->createView('ftpaccess', 'SELECT email AS userid,password AS passwd,utilisateur_id AS uid,' - . '\'1000\' AS gid,CONCAT(\'' . FTPROOT . '\',utilisateur_id) AS homedir, \'/bin/false\' AS shell ' - . 'FROM utilisateurs WHERE grade=0 ' - . 'UNION ' - . 'SELECT email AS userid,ws_password AS passwd,utilisateur_id AS uid,' - . '\'1000\' AS gid,CONCAT(\'' . FTPROOT . '\',utilisateur_id) AS homedir, \'/bin/false\' AS shell ' - . 'FROM utilisateurs WHERE grade=0 AND ws_password!=\'\''); + $this->views->createView('chiffres_categories', 'SELECT p.annee_fin AS annee, t.categorie, SUM(t.budget) AS ca ' . 'FROM projets_vue p, taches_vue t ' . 'WHERE t.projet=p.projet_id ' @@ -658,7 +676,7 @@ LEFT JOIN utilisateurs a ON ri.administrateur_id=a.utilisateur_id'); . 'FROM books b ' . 'LEFT JOIN utilisateurs_entreprise c ON b.proprietaire=c.utilisateur_id ' . 'LEFT JOIN ws_users_tree t ON t.utilisateur_id=c.utilisateur_id ' - . 'LEFT JOIN utilisateurs a ON t.administrateur_id=a.utilisateur_id ' + . 'LEFT JOIN e2_u a ON t.administrateur_id=a.utilisateur_id ' . 'LEFT JOIN utilisateurs_entreprise f ON t.facturable_id=f.utilisateur_id ' . 'LEFT JOIN taches ta ON ta.tache_id=b.tache', 'TEMPTABLE'); $this->views->createView('books_nbpages_vue', 'SELECT book_id, MAX(book_page) AS nb_pages ' @@ -676,7 +694,7 @@ LEFT JOIN utilisateurs a ON ri.administrateur_id=a.utilisateur_id'); . 'FROM demandes d ' . 'LEFT JOIN utilisateurs_entreprise r ON d.revendeur=r.utilisateur_id ' . 'LEFT JOIN utilisateurs_entreprise c ON d.utilisateur=c.utilisateur_id ' - . 'LEFT JOIN utilisateurs a ON d.administrateur=a.utilisateur_id'); + . 'LEFT JOIN e2_u a ON d.administrateur=a.utilisateur_id'); $this->views->createView('chiffres_types', 'SELECT p.annee_fin AS annee, e.type, SUM(p.budget) AS ca ' . 'FROM projets_vue p, clients_entreprise e ' . 'WHERE p.client_id=e.utilisateur_id ' @@ -685,7 +703,6 @@ LEFT JOIN utilisateurs a ON ri.administrateur_id=a.utilisateur_id'); . 'FROM projets_vue_hf p, clients_entreprise e ' . 'WHERE p.client_id=e.utilisateur_id ' . 'GROUP BY e.type, p.annee_fin'); - $this->views->createView('ca_fluidbook', 'SELECT u.entreprise AS client, SUM(t.budget) AS ca FROM taches t LEFT JOIN projets p ON t.projet=p.projet_id LEFT JOIN utilisateurs u ON p.client=u.utilisateur_id WHERE t.categorie=8 AND t.budget>0 GROUP BY u.entreprise'); //cubeDb::mysqlConvert($this->con, 'UTF8', 'utf8_general_ci', 'MYISAM'); diff --git a/inc/commons/class.common.filtre.php b/inc/commons/class.common.filtre.php index d6d099e66..801e64037 100644 --- a/inc/commons/class.common.filtre.php +++ b/inc/commons/class.common.filtre.php @@ -24,7 +24,7 @@ class commonFiltre { $this->values[$r->prenom] = $r->utilisateur_id; } } elseif ($this->varname == 'revendeur_book') { - $r = $core->con->select('SELECT DISTINCT facturable,facturable_id FROM books_vue WHERE status>0 AND facturable_id IN(SELECT utilisateur_id FROM utilisateurs WHERE entreprise IN(SELECT entreprise_id FROM entreprises WHERE ws_grade BETWEEN 3 AND 4)) ORDER BY facturable'); + $r = $core->con->select('SELECT DISTINCT facturable,facturable_id FROM books_vue WHERE status>0 AND facturable_id IN(SELECT utilisateur_id FROM e2_u WHERE entreprise IN(SELECT entreprise_id FROM e2_c WHERE ws_grade BETWEEN 3 AND 4)) ORDER BY facturable'); while ($r->fetch()) { $this->values[$r->facturable] = $r->facturable; } diff --git a/inc/commons/class.common.tools.php b/inc/commons/class.common.tools.php index e5d42e0ef..733d10c70 100644 --- a/inc/commons/class.common.tools.php +++ b/inc/commons/class.common.tools.php @@ -37,19 +37,19 @@ class commonTools $limit = mktime(0, 0, 0, date('m', $limit), 1, date('y', $limit)); $tvanumbers = array(); - $r = $core->con->select('SELECT entreprise_id,tva_intra FROM entreprises'); + $r = $core->con->select('SELECT entreprise_id,tva_intra FROM e2_c'); $filter = new CubeIT_Filter_VATEurope(); while ($r->fetch()) { $tvanumbers[$r->entreprise_id] = $filter->filter($r->tva_intra); } $utilisateurs = array(); - $r = $core->con->select('SELECT utilisateur_id,entreprise FROM utilisateurs'); + $r = $core->con->select('SELECT utilisateur_id,entreprise FROM e2_u'); while ($r->fetch()) { $utilisateurs[$r->utilisateur_id] = $r->entreprise; } - $sql = 'SELECT * FROM factures_vue WHERE client_id IN (SELECT utilisateur_id FROM utilisateurs WHERE entreprise IN (SELECT entreprise_id FROM entreprises WHERE pays IN(' . $countries . '))) AND status > 0 AND date_creation>' . $limit . ' ORDER BY date_creation DESC'; + $sql = 'SELECT * FROM factures_vue WHERE client_id IN (SELECT utilisateur_id FROM utilisateurs WHERE entreprise IN (SELECT entreprise_id FROM e2_c WHERE pays IN(' . $countries . '))) AND status > 0 AND date_creation>' . $limit . ' ORDER BY date_creation DESC'; $r = $core->con->select($sql); $xls = new PHPExcel(); diff --git a/inc/extranet/DAO/class.extranet.dao.devis.php b/inc/extranet/DAO/class.extranet.dao.devis.php index 705241f0e..6550ca47f 100644 --- a/inc/extranet/DAO/class.extranet.dao.devis.php +++ b/inc/extranet/DAO/class.extranet.dao.devis.php @@ -157,7 +157,7 @@ class extranetDAODevis extends commonDAO { } public function getListeForEntreprise($entreprise_id, $orderby, $sens) { - $sql = 'SELECT * FROM devis_vue WHERE client_id IN (SELECT utilisateur_id FROM utilisateurs WHERE entreprise=\'' . $this->con->escape($entreprise_id) . '\') AND status>0 ORDER BY ' . $orderby . ' ' . $sens; + $sql = 'SELECT * FROM devis_vue WHERE client_id IN (SELECT utilisateur_id FROM e2_u WHERE entreprise=\'' . $this->con->escape($entreprise_id) . '\') AND status>0 ORDER BY ' . $orderby . ' ' . $sens; $r = $this->con->select($sql); return $this->factory($r); } diff --git a/inc/extranet/DAO/class.extranet.dao.facture.php b/inc/extranet/DAO/class.extranet.dao.facture.php index 98019000e..69649dc8c 100644 --- a/inc/extranet/DAO/class.extranet.dao.facture.php +++ b/inc/extranet/DAO/class.extranet.dao.facture.php @@ -113,7 +113,7 @@ class extranetDAOFacture extends commonDAO { } public function getListeForEntreprise($entreprise_id, $orderby, $sens) { - $sql = 'SELECT * FROM factures_vue WHERE client_id IN(SELECT utilisateur_id FROM utilisateurs WHERE entreprise=\'' . $this->con->escape($entreprise_id) . '\') AND status>0 ORDER BY ' . $orderby . ' ' . $sens; + $sql = 'SELECT * FROM factures_vue WHERE client_id IN(SELECT utilisateur_id FROM e2_u WHERE entreprise=\'' . $this->con->escape($entreprise_id) . '\') AND status>0 ORDER BY ' . $orderby . ' ' . $sens; $r = $this->con->select($sql); return $this->factory($r); } diff --git a/inc/ws/Controlleur/class.ws.ajax.php b/inc/ws/Controlleur/class.ws.ajax.php index c8c32f9f8..0ea7bdf7b 100644 --- a/inc/ws/Controlleur/class.ws.ajax.php +++ b/inc/ws/Controlleur/class.ws.ajax.php @@ -509,6 +509,7 @@ class wsAjax extends cubeAjax $_POST = array_merge($defaults, $_POST); + if (!self::valideDemandeDevis($x)) { $x->addAlert(sprintf(__("Une erreur s'est produite. Nous avons été averti de l'erreur que vous rencontrez. Vous pouvez nous contacter par e-mail à l'adresse suivante : %s"), 'info@fluidbook.com')); return; @@ -516,9 +517,11 @@ class wsAjax extends cubeAjax $spam = (strlen($_POST['fax']) > 0); $_POST['spam'] = $spam ? 'Oui' : 'Non'; + if (!$spam) { // L'utilisateur est-il déjà dans la base ? $daoUtilisateur = new commonDAOUtilisateur($core->con); + $utilisateur = $daoUtilisateur->selectByEmail($_POST['email']); if ($utilisateur != null) { $utilisateur_id = $utilisateur->utilisateur_id; @@ -557,8 +560,11 @@ class wsAjax extends cubeAjax $datas['grade'] = 0; $datas['fax'] = ''; $datas['mobile'] = ''; + $datas['enabled'] = '1'; + $datas['password'] = crypt::createPassword(); $utilisateur = $daoUtilisateur->sauve($datas); $utilisateur_id = $utilisateur->utilisateur_id; + } $datas = array(); diff --git a/inc/ws/Controlleur/class.ws.maintenance.php b/inc/ws/Controlleur/class.ws.maintenance.php index af9c93966..628c1c16d 100644 --- a/inc/ws/Controlleur/class.ws.maintenance.php +++ b/inc/ws/Controlleur/class.ws.maintenance.php @@ -54,149 +54,6 @@ class wsMaintenance } } - public static function importFromOldWS($args) - { - global $core; - // Import des fluidbooks - // Donc le dernier importé est le max dont le numéro est inférieur à 10000 - $r = $core->con->select('SELECT MAX(book_id) AS book_id FROM books WHERE book_id<10000'); - $lastImported = $r->book_id; - // On recherche maintenant les fluidbook dans la vieille base - $r = $core->con->select('SELECT bid FROM ws.book WHERE bid>' . $lastImported); - $oldBooks = array(); - while ($r->fetch()) { - $oldBooks[] = $r->bid; - } - - if (count($oldBooks)) { - self::importLangs($oldBooks); - self::importThemes($oldBooks); - self::importDocs($oldBooks); - self::importBooks($oldBooks); - } - $core->refreshWSUsersTree(); - } - - public static function importLangs($oldBooks) - { - global $core, $allTrads, $trads; - // On regarde d'abord les langues que nous avons déjà - $r = $core->con->select('SELECT lang_id FROM langues'); - $already = array(); - while ($r->fetch()) { - $already[] = $r->lang_id; - } - - $toImport = array(); - $r = $core->con->select('SELECT DISTINCT lang FROM ws.book WHERE bid ' . self::_sqlIn($oldBooks)); - while ($r->fetch()) { - $idl = self::_getLangCode($r->lang); - if (in_array($idl, $already)) { - continue; - } - if (strlen($idl) > 2) { - continue; - } - $toImport[] = $r->lang; - } - - $allTrads = array(); - $trad = array(); - $r = $core->con->select('SELECT * FROM ws.lang_trad,ws.lang_ord WHERE lang_trad.idlt=lang_ord.idlt AND idl ' . self::_sqlIn($toImport) . ' '); - while ($r->fetch()) { - $idl = self::_getLangCode($r->idl); - if (!isset($trad[$idl])) { - $trad[$idl] = array(); - } - $trad[$idl][$r->ord] = $r->text; - } - - foreach ($trad as $idl => $t) { - $traductions = wsLang::getTraductionWithId($trad[$idl]); - $allTrads[$idl] = $traductions; - } - - if (!count($toImport)) { - return; - } - - foreach ($toImport as $idl) { - $idl = self::_getLangCode($idl); - - $c = $core->con->openCursor('langues'); - $c->lang_id = $idl; - $c->charset = 'Latin1'; - $c->font = 'Fluidbook.otf'; - $c->traductions = json_encode($allTrads[$idl]); - $c->insert(); - } - } - - public static function importThemes($oldBooks) - { - global $core, $signatures; - - $r = $core->con->select('SELECT tid,sigid FROM ws.theme'); - while ($r->fetch()) { - $signatures[$r->tid] = $r->sigid; - } - - $r = $core->con->select('SELECT MAX(theme_id) AS theme_id FROM themes WHERE theme_id<1000'); - $lastImported = $r->theme_id; - // Import des thèmes - $r = $core->con->select('SELECT * FROM ws.theme WHERE tid IN (SELECT tid FROM ws.book WHERE bid ' . self::_sqlIn($oldBooks) . ') AND tid>' . $lastImported); - $theme = new wsTheme(); - while ($r->fetch()) { - $tid = $r->tid; - - $c = $core->con->openCursor('themes'); - $c->theme_id = $r->tid; - $c->proprietaire = self::_getWsUser($r->proprietaire); - $c->date = $r->date; - $c->nom = $r->titre; - - $parametres = new wsThemeParametres($theme); - $parametres->fromRecord($r); - self::_oldIconesToColor($r->iid, $parametres); - $c->parametres = serialize($parametres); - $c->insert(); - - $dest = WS_THEMES . '/' . $tid . '/'; - if (!file_exists($dest)) { - mkdir($dest, 0777, true); - } - - `/bin/cp -r /home/ws/www/themes/$tid/* $dest`; - } - } - - public static function importDocs($oldBooks) - { - global $core; - // On cherche maintenant à savoir si l'on doit importer de nouveaux documents associés - $oldDocuments = array(); - $r = $core->con->select('SELECT DISTINCT did FROM ws.book_pages WHERE bid ' . self::_sqlIn($oldBooks) . ''); - while ($r->fetch()) { - $oldDocuments[] = $r->did; - } - - if (!count($oldDocuments)) { - return; - } - - $r = $core->con->select('SELECT * FROM ws.document WHERE did ' . self::_sqlIn($oldDocuments) . ' ORDER BY did'); - while ($r->fetch()) { - $c = $core->con->openCursor('documents'); - $c->document_id = $r->did; - $c->pages = $r->pages; - $c->version = 1; - try { - $c->insert(); - } catch (Exception $e) { - fb($e); - } - } - } public static function copyLinks($args, $eraseTo = false) { @@ -231,237 +88,6 @@ class wsMaintenance wsLinks::saveLinksInFile($to, $core->user->utilisateur_id, 'Copy links from #' . $from . ' to #' . $to, $tolinks, $torulers); } - public static function importBooks($oldBooks) - { - global $core, $allTrads, $signatures; - // Importe les fluidbooks - $r = $core->con->select('SELECT * FROM ws.book WHERE bid ' . self::_sqlIn($oldBooks) . ' ORDER BY bid'); - if (!$r->count()) { - return; - } - // . - while ($r->fetch()) { - $c = $core->con->openCursor('books'); - $c->book_id = $r->bid; - $c->nom = $r->titre; - $c->lang = substr(self::_getLangCode($r->lang), 0, 2); - $c->theme = $r->tid; - if (strlen($r->lang) > 2) { - $c->traductions = json_encode($allTrads[self::_getLangCode($r->lang)]); - } else { - $c->traductions = ''; - } - $c->proprietaire = self::_getWsUser($r->uid); - $c->status = $r->status; - $c->date_status = $r->date_status; - $c->hash = $r->code; - $c->compteur_visites = 20; - $c->date = $r->date; - $c->syncv1 = 1; - $c->version = 1; - $parametres = new wsBookParametres(new stdClass()); - $parametres->fromRecord($r); - - $xml = @simplexml_load_string('' . $r->extras . ''); - if ($xml !== false) { - $parametres->fromXML($xml); - } else { - - } - - $n = array(); - // Pages sans numéro - $offset = $r->first_page_nr - 1; - for ($i = 0; $i < $offset; $i++) { - $n[] = ''; - } - // Pages avec numero - for ($j = 1; $j + $offset <= $r->pages; $j++) { - $n[] = $j; - } - $c->numerotation = implode(',', $n); - - $parametres->signature = $signatures[$r->tid]; - $parametres->title = $r->titre; - $parametres->visualisationMode = '2'; - $c->parametres = serialize($parametres); - $c->version = 1; - $c->insert(); - } - // Import des pages - $core->con->execute('INSERT INTO book_pages (book_id,book_page,document_id,document_page) SELECT bid,bpid,did,dpid FROM ws.book_pages WHERE bid ' . self::_sqlIn($oldBooks)); - - $dao = new wsDAOBook($core->con); - foreach ($oldBooks as $book_id) { - $dao->saveCompositionVersion($book_id); - } - } - - protected static function _oldIconesToColor($iid, &$parametres) - { - global $oldIconesColors; - if (!isset($oldIconesColors)) { - $oldIconesColors = array(); - $fp = fopen(dirname(__FILE__) . '/../../../icones.csv', 'rb'); - $i = 1; - while ($line = fgetcsv($fp, 1000, ';', '"')) { - $oldIconesColors[$i] = array('color' => trim($line[0]), 'iid' => trim($line[1])); - $i++; - } - } - $line = $oldIconesColors[$iid]; - if ($line['iid'] != '') { - $parametres->iconSet = $line['iid']; - $parametres->iconsHMargin = $line['iid'] == 1 ? 20 : 0; - $parametres->menuHeight = 39; - $parametres->colorizeIcons = false; - $parametres->couleurI = 'ffffff'; - } else { - $parametres->iconSet = 1; - $parametres->colorizeIcons = 1; - $parametres->iconsHMargin = 20; - $parametres->menuHeight = 39; - $parametres->couleurI = $line['color']; - } - } - - protected static function _getWsUser($oldid) - { - global $ws2ext; - if (!isset($ws2ext)) { - self::_getAllUsers(); - } - if (!isset($ws2ext[$oldid])) { - self::_importOldUser($oldid); - } - if (!isset($ws2ext[$oldid])) { - $ws2ext[$oldid] = 1; - } - return $ws2ext[$oldid]; - } - - protected static function _getAllUsers() - { - global $core, $entreprises, $entreprise_id, $utilisateurs_entreprises, $utilisateur_id, $ws2ext, $grades, $utilisateurs; - $grades = array(0 => 1, 0.4 => 1, '0.4' => 1, 0.5 => 1, '0.5' => 1, 1 => 1, 2 => 2, 3 => 3, 4 => 5); - // Contrôle des entreprises déjà dans la base extranet - $entreprises = array(); - $entreprise_id = 0; - $r = $core->con->select('SELECT entreprise_id,nom FROM entreprises'); - while ($r->fetch()) { - $nom = mb_strtolower(trim($r->nom)); - $nom = cubeText::str2URL($nom); - $entreprises[$nom] = $r->entreprise_id; - $entreprise_id = max($entreprise_id, $r->entreprise_id); - } - - $utilisateurs_entreprises = array(); - $r = $core->con->select('SELECT entreprise,utilisateur_id FROM utilisateurs'); - while ($r->fetch()) { - $utilisateurs_entreprises[$r->utilisateur_id] = $r->entreprise; - } - - $entreprise_id++; - // Obtient les emails des utilisateurs - $utilisateur_id = 0; - $utilisateurs = array(); - $r = $core->con->select('SELECT utilisateur_id,email FROM utilisateurs'); - while ($r->fetch()) { - $utilisateur_id = max($r->utilisateur_id, $utilisateur_id); - $utilisateurs[trim(mb_strtolower($r->email))] = $r->utilisateur_id; - } - $utilisateur_id++; - - $ws2ext = array(); - $r = $core->con->select('SELECT ws_id,utilisateur_id,entreprise FROM utilisateurs WHERE ws_id IS NOT NULL'); - while ($r->fetch()) { - $ws2ext[$r->ws_id] = $r->utilisateur_id; - } - } - - protected static function _importOldUser($oldid) - { - global $core, $entreprises, $entreprise_id, $utilisateurs_entreprises, $utilisateur_id, $ws2ext, $grades, $utilisateurs; - // Get user from old - $r = $core->con->select('SELECT * FROM ws.user WHERE uid=\'' . $core->con->escape($oldid) . '\''); - if ($r->extranet != 0) { - $ws2ext[$r->uid] = $r->extranet; - return; - } - // On s'occupe de l'entreprise - $email = trim(mb_strtolower($r->email)); - - $rs = trim($r->rs); - if ($rs == '') { - $rs = trim($r->prenom . ' ' . $r->nom); - } - $nom = mb_strtolower($rs); - - $nom = cubeText::str2URL($nom); - - if (isset($utilisateurs[$email])) { - $newid = $utilisateurs[$email]; - $e = $utilisateurs_entreprises[$newid]; - $update = true; - } elseif (isset($entreprises[$nom])) { - $e = $entreprises[$nom]; - $update = true; - } else { - $c = $core->con->openCursor('entreprises'); - $c->entreprise_id = $entreprise_id; - $c->nom = $rs; - $c->adresse = $r->adresse; - $c->code_postal = $r->code_postal; - $c->ville = $r->ville; - $c->pays = $r->pays; - $c->date_creation = $r->date; - $c->ws_grade = $grades[$r->grade]; - $c->ws_admin = self::_getWsUser($r->admin); - $c->insert(); - $e = $entreprises[$nom] = $entreprise_id; - $entreprise_id++; - $update = false; - } - - if ($update) { - $c = $core->con->openCursor('entreprises'); - $c->ws_grade = $grades[$r->grade]; - $c->ws_admin = self::_getWsUser($r->admin); - $c->update('WHERE entreprise_id=\'' . $e . '\''); - } - // Puis de l'utilisateur - if (isset($utilisateurs[$email])) { - $c = $core->con->openCursor('utilisateurs'); - $c->ws_password = $r->password; - $c->ws_id = $r->uid; - $c->update('WHERE utilisateur_id=\'' . $utilisateurs[$email] . '\''); - $ws2ext[$r->uid] = $utilisateurs[$email]; - $utilisateurs_entreprises[$utilisateurs[$email]] = $e; - } else { - $c = $core->con->openCursor('utilisateurs'); - $c->utilisateur_id = $utilisateur_id; - $c->entreprise = $e; - $c->nom = $r->nom; - $c->prenom = $r->prenom; - $c->email = $r->email; - $c->password = $r->password; - $c->adresse = $r->adresse; - $c->code_postal = $r->code_postal; - $c->ville = $r->ville; - $c->pays = $r->pays; - $c->lang = $r->lang; - $c->telephone = $r->telephone; - $c->date_creation = $r->date; - $c->notes = 'Inséré à  l\'import vers le nouveau Fluidbook Workshop'; - $c->ws_password = $r->password; - $c->ws_id = $r->uid; - $c->insert(); - $ws2ext[$r->uid] = $utilisateur_id; - $utilisateurs_entreprises[$utilisateur_id] = $e; - $utilisateur_id++; - } - } - protected static function _sqlIn($tab) { return ' IN(\'' . implode('\',\'', $tab) . '\') '; @@ -543,21 +169,21 @@ class wsMaintenance } - public static function mergeEntreprise($args) - { - global $core; - - $from = $args[0]; - $to = $args[1]; - - $c = $core->con->openCursor('utilisateurs'); - $c->entreprise = $to; - $c->update('WHERE entreprise=' . $from); - - $core->con->execute('DELETE FROM entreprises WHERE entreprise_id=' . $from); - - $core->refreshWSUsersTree(); - } +// public static function mergeEntreprise($args) +// { +// global $core; +// +// $from = $args[0]; +// $to = $args[1]; +// +// $c = $core->con->openCursor('utilisateurs'); +// $c->entreprise = $to; +// $c->update('WHERE entreprise=' . $from); +// +// $core->con->execute('DELETE FROM entreprises WHERE entreprise_id=' . $from); +// +// $core->refreshWSUsersTree(); +// } public static function exportSommaire($args) { @@ -1136,7 +762,7 @@ class wsMaintenance $u = array(); - $r = $core->con->select('SELECT * FROM utilisateurs'); + $r = $core->con->select('SELECT * FROM e2_u'); while ($r->fetch()) { $u[$r->utilisateur_id] = $r->row(); } @@ -1173,7 +799,7 @@ class wsMaintenance $u = array(); - $r = $core->con->select('SELECT * FROM utilisateurs'); + $r = $core->con->select('SELECT * FROM e2_u'); $unsubscribe = array(); while ($r->fetch()) { $u[$r->utilisateur_id] = $r->row(); diff --git a/inc/ws/Controlleur/class.ws.url.php b/inc/ws/Controlleur/class.ws.url.php index fc277ea1a..77152caee 100644 --- a/inc/ws/Controlleur/class.ws.url.php +++ b/inc/ws/Controlleur/class.ws.url.php @@ -1464,8 +1464,8 @@ html.tall{height:150%}' . "\n"; $projects = array("--" => '0'); $proprietaire = 'SELECT facturable_id FROM ws_users_tree WHERE utilisateur_id=\'' . $core->con->escape($book->proprietaire_id) . '\''; - $entreprise = 'SELECT entreprise FROM utilisateurs WHERE utilisateur_id IN (' . $proprietaire . ')'; - $collegues = 'SELECT utilisateur_id FROM utilisateurs WHERE entreprise IN(' . $entreprise . ')'; + $entreprise = 'SELECT entreprise FROM e2_u WHERE utilisateur_id IN (' . $proprietaire . ')'; + $collegues = 'SELECT utilisateur_id FROM e2_u WHERE entreprise IN(' . $entreprise . ')'; $r = $core->con->select('SELECT * FROM projets WHERE client IN(' . $collegues . ') ORDER BY projet_id DESC'); while ($r->fetch()) { diff --git a/inc/ws/Controlleur/class.ws.users.tree.php b/inc/ws/Controlleur/class.ws.users.tree.php index 5754e9b32..69a0054c8 100644 --- a/inc/ws/Controlleur/class.ws.users.tree.php +++ b/inc/ws/Controlleur/class.ws.users.tree.php @@ -27,7 +27,7 @@ class wsUsersTree { $this->rights = array(); - $r = $this->con->select('SELECT * FROM utilisateurs u LEFT JOIN entreprises e ON u.entreprise=e.entreprise_id WHERE e.ws_grade>0 ORDER BY e.ws_grade ASC'); + $r = $this->con->select('SELECT * FROM e2_u u LEFT JOIN e2_c e ON u.entreprise=e.entreprise_id WHERE e.ws_grade>0 ORDER BY e.ws_grade ASC'); while ($r->fetch()) { $this->entreprises[$r->utilisateur_id] = $r->entreprise_id; $this->users[$r->utilisateur_id] = $r->ws_admin; @@ -124,11 +124,11 @@ class wsUsersTree { $adom[$admin] = array_unique($adom[$admin]); } - $c = $this->con->openCursor('utilisateurs'); + $c = $this->con->openCursor('extranet_users.user'); 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) . '\''); + $c->e1_ws_rights = implode(',', $list); + $c->e1_ws_domains = implode(',', $adom[$admin]); + $c->update('WHERE id=\'' . $this->con->escape($admin) . '\''); } }