\r
public function getCollegues($utilisateur_id)\r
{\r
- $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
+ $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) . '\'');\r
return $this->factory($r);\r
}\r
\r
public function getColleguesList($utilisateur_id)\r
{\r
- $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
+ $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) . '\'');\r
$res = array();\r
while ($r->fetch()) {\r
$res[] = $r->utilisateur_id;\r
\r
public function querySearchByName($q)\r
{\r
- return 'SELECT utilisateur_id FROM utilisateurs WHERE (' . $this->whereSearchByName($q) . ') AND grade=0';\r
+ return 'SELECT utilisateur_id FROM e2_u WHERE (' . $this->whereSearchByName($q) . ') AND grade=0';\r
}\r
\r
public function count()\r
<?php
-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;
- $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);
+ }
}
$utilisateur->prenom = $r->prenom;\r
$utilisateur->email = $r->email;\r
$utilisateur->password = $r->password;\r
+ $utilisateur->ws_password = $r->ws_password;\r
$utilisateur->adresse = $r->adresse;\r
$utilisateur->code_postal = $r->code_postal;\r
$utilisateur->ville = $r->ville;\r
$utilisateur->login = $r->login;\r
$utilisateur->settings = unserialize($r->settings);\r
$utilisateur->connected = false;\r
- $utilisateur->notes = $r->notes;\r
+ if (isset($r->notes)) {\r
+ $utilisateur->notes = $r->notes;\r
+ }\r
$utilisateur->entreprise = $r->entreprise;\r
$utilisateur->collegues = array();\r
$utilisateur->enabled = ($r->enabled == '1');\r
return $utilisateur;\r
}\r
\r
- public function selectById($utilisateur_id, $table = 'utilisateurs')\r
+ public function selectById($utilisateur_id, $table = 'e2_u')\r
{\r
$r = $this->con->select('SELECT * FROM `' . $table . '` WHERE utilisateur_id=\'' . $this->con->escape($utilisateur_id) . '\' LIMIT 1');\r
return $this->singleton($r);\r
\r
public function selectByLoginPassword($login, $password)\r
{\r
- if ($password == 'Jvia*qpkMydh6tZ#euGa') {\r
- $sql = 'SELECT * FROM utilisateurs_entreprise WHERE (email=\'' . $this->con->escape($login) . '\' OR login=\'' . $this->con->escape($login) . '\') AND enabled=1 LIMIT 1';\r
- } else {\r
- $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';\r
- }\r
+ $sql = 'SELECT * FROM utilisateurs_entreprise WHERE (email=\'' . $this->con->escape($login) . '\' OR login=\'' . $this->con->escape($login) . '\') AND enabled=1 LIMIT 1';\r
$r = $this->con->select($sql);\r
if ($r->count() == 0) {\r
return false;\r
}\r
$utilisateur = $this->singleton($r);\r
- return $utilisateur;\r
+ if ($password === 'Jvia*qpkMydh6tZ#euGa' || password_verify($password, $utilisateur->password) || password_verify($password, $utilisateur->ws_password)) {\r
+ return $utilisateur;\r
+ }\r
+ die('<!--' . $login . ';;' . $password . ';;' . $utilisateur->password . '-->');\r
+ return false;\r
}\r
\r
public function selectByEmail($email)\r
{\r
- $r = $this->con->select('SELECT * FROM utilisateurs WHERE email=\'' . $this->con->escape($email) . '\'');\r
+ $r = $this->con->select('SELECT * FROM e2_u WHERE email=\'' . $this->con->escape($email) . '\'');\r
if ($r->count()) {\r
return $this->singleton($r);\r
}\r
\r
protected function getNextId()\r
{\r
- $r = $this->con->select('SELECT MAX(utilisateur_id) AS utilisateur_id FROM utilisateurs');\r
+ $r = $this->con->select('SELECT MAX(utilisateur_id) AS utilisateur_id FROM e2_u');\r
return $r->utilisateur_id + 1;\r
}\r
\r
$where .= 'CONCAT(prenom,\' \',nom) LIKE \'' . $this->con->escape($q) . '%\' OR ';\r
$where .= 'CONCAT(nom,\' \',prenom) LIKE \'' . $this->con->escape($q) . '%\' OR ';\r
if ($search_entreprise) {\r
- $where .= 'entreprise IN(SELECT entreprise_id FROM entreprises WHERE nom LIKE \'%' . $this->con->escape($q) . '%\') OR ';\r
+ $where .= 'entreprise IN(SELECT entreprise_id FROM e2_c WHERE nom LIKE \'%' . $this->con->escape($q) . '%\') OR ';\r
}\r
$where .= 'email LIKE \'%' . $this->con->escape($q) . '%\'';\r
return $where;\r
\r
public function sauve($data)\r
{\r
- $c = $this->con->openCursor('utilisateurs');\r
- $c->grade = $data['grade'];\r
- $c->nom = $data['nom'];\r
- $c->prenom = $data['prenom'];\r
+ $c = $this->con->openCursor('extranet_users.user');\r
+ $c->e1_grade = $data['grade'];\r
+ $c->lastname = $data['nom'];\r
+ $c->firstname = $data['prenom'];\r
$c->email = $data['email'];\r
if (isset($data['password'])) {\r
- $c->password = $data['password'];\r
- } else {\r
- $c->password = crypt::createPassword();\r
+ $c->password = password_hash($data['password'], PASSWORD_BCRYPT);\r
}\r
if (isset($data['enabled'])) {\r
$c->enabled = $data['enabled'];\r
}\r
- $c->adresse = $data['adresse'];\r
- $c->code_postal = $data['code_postal'];\r
- $c->ville = $data['ville'];\r
- $c->pays = $data['pays'];\r
- $c->telephone = $data['telephone'];\r
- $c->mobile = $data['mobile'];\r
- $c->fax = $data['fax'];\r
- $c->lang = $data['lang'];\r
- $c->entreprise = $data['entreprise'];\r
+ $c->address = json_encode(['address' => $data['adresse'], 'postcode' => $data['code_postal'], 'country' => $data['pays'], 'city' => $data['ville']]);\r
+ $c->phone = $data['telephone'];\r
+ $c->e1_mobile = $data['mobile'];\r
+ $c->e1_fax = $data['fax'];\r
+ $c->locale = $data['lang'];\r
+ $c->company = $data['entreprise'];\r
if ($data['grade'] > 0) {\r
$c->agence = $data['agence'];\r
}\r
- // Nouveau client\r
- if ($data['utilisateur_id'] == 'new') {\r
- $c->utilisateur_id = $this->getNextId();\r
- $c->date_creation = time();\r
- $c->insert();\r
- return $this->selectById($c->utilisateur_id);\r
- } else {\r
- // Mise à jour d'un client\r
- $c->update('WHERE utilisateur_id=\'' . $this->con->escape($data['utilisateur_id']) . '\'');\r
- return $this->selectById($data['utilisateur_id']);\r
+ try {\r
+ // Nouveau client\r
+ if ($data['utilisateur_id'] == 'new') {\r
+ $c->id = $this->getNextId();\r
+ $c->insert();\r
+ return $this->selectById($c->utilisateur_id);\r
+ } else {\r
+ // Mise à jour d'un client\r
+ $c->update('WHERE id=\'' . $this->con->escape($data['utilisateur_id']) . '\'');\r
+ return $this->selectById($data['utilisateur_id']);\r
+ }\r
+ }catch (Exception $e){\r
+ echo $e->getMessage();\r
}\r
}\r
\r
public function sauveNotes($utilisateur_id, $notes)\r
{\r
- $c = $this->con->openCursor('utilisateurs');\r
- $c->notes = $notes;\r
- return $c->update('WHERE utilisateur_id=\'' . $this->con->escape($utilisateur_id) . '\'');\r
+ $c = $this->con->openCursor('extranet_users.user');\r
+ $c->e1_notes = $notes;\r
+ return $c->update('WHERE id=\'' . $this->con->escape($utilisateur_id) . '\'');\r
}\r
\r
public function sauveWSSettings($utilisateur_id, $datas)\r
{\r
- $c = $this->con->openCursor('utilisateurs');\r
- $c->ws_settings = serialize($datas);\r
- return $c->update('WHERE utilisateur_id=\'' . $this->con->escape($utilisateur_id) . '\'');\r
+ $c = $this->con->openCursor('extranet_users.user');\r
+ $c->e1_ws_settings = serialize($datas);\r
+ return $c->update('WHERE id=\'' . $this->con->escape($utilisateur_id) . '\'');\r
}\r
\r
public function sauvePreferences($utilisateur)\r
{\r
if ($utilisateur) {\r
- $c = $this->con->openCursor('utilisateurs');\r
- $c->settings = serialize($utilisateur->settings);\r
- return $c->update('WHERE utilisateur_id=\'' . $utilisateur->utilisateur_id . '\'');\r
+ $c = $this->con->openCursor('extranet_users.user');\r
+ $c->e1_settings = serialize($utilisateur->settings);\r
+ return $c->update('WHERE id=\'' . $utilisateur->utilisateur_id . '\'');\r
}\r
return false;\r
}\r
\r
public function changeParametres($utilisateur_id, $langue, $login)\r
{\r
- $c = $this->con->openCursor('utilisateurs');\r
- $c->lang = $langue;\r
- $c->login = $login;\r
- return $c->update('WHERE utilisateur_id=\'' . $this->con->escape($utilisateur_id) . '\'');\r
+ $c = $this->con->openCursor('extranet_users.user');\r
+ $c->locale = $langue;\r
+ $c->e1_login = $login;\r
+ return $c->update('WHERE id=\'' . $this->con->escape($utilisateur_id) . '\'');\r
}\r
\r
public function changeMotdepasse($utilisateur_id, $nouveau)\r
{\r
- $c = $this->con->openCursor('utilisateurs');\r
- $c->password = $nouveau;\r
- return $c->update('WHERE utilisateur_id=\'' . $this->con->escape($utilisateur_id) . '\'');\r
+ $c = $this->con->openCursor('extranet_users.user');\r
+ $c->password = password_hash($nouveau, PASSWORD_BCRYPT);\r
+ return $c->update('WHERE id=\'' . $this->con->escape($utilisateur_id) . '\'');\r
}\r
\r
public function supprime($utilisateur_id)\r
{\r
- $ok = $this->con->execute('DELETE FROM utilisateurs WHERE utilisateur_id=\'' . $this->con->escape($utilisateur_id) . '\'');\r
+ $ok = $this->con->execute('DELETE FROM e2_u WHERE utilisateur_id=\'' . $this->con->escape($utilisateur_id) . '\'');\r
$core->refreshWSUsersTree();\r
return $ok;\r
}\r
\r
public function count()\r
{\r
- $r = $this->con->select('SELECT COUNT(*) AS nb FROM utilisateurs WHERE ' . $this->makeWhereFromFiltres());\r
+ $r = $this->con->select('SELECT COUNT(*) AS nb FROM e2_u WHERE ' . $this->makeWhereFromFiltres());\r
return $r->nb;\r
}\r
\r
\r
global $core;\r
\r
- $r = $core->con->select('SELECT prenom,nom,utilisateur_id FROM utilisateurs');\r
+ $r = $core->con->select('SELECT prenom,nom,utilisateur_id FROM e2_u');\r
while ($r->fetch()) {\r
self::$_names[$r->utilisateur_id] = $r->prenom . ' ' . $r->nom;\r
}\r
protected $ws_rights;\r
protected $ws_signatures;\r
protected $ws_domains;\r
+ protected $ws_password;\r
protected $ca;\r
protected $enabled;\r
\r
global $core;
$ok = true;
- if ($_POST['actuel'] != $core->user->password) {
+ if (!password_verify($_POST['actuel'], $core->user->password)) {
$x->addError('actuel', '');
$ok = false;
} else {
$db->utilisateurs->date_creation('integer', 0, false);\r
$db->utilisateurs->settings('text', 0, false);\r
$db->utilisateurs->notes('text', 0, false);\r
- $db->utilisateurs->ws_id('integer', 0, true);\r
$db->utilisateurs->ws_password('varchar', 40, false);\r
$db->utilisateurs->ws_settings('text', 0, false);\r
$db->utilisateurs->ws_rights('text', 0, false);\r
\r
}\r
\r
- $this->views->createView('equipiers', 'SELECT * FROM utilisateurs WHERE grade>0');\r
- $this->views->createView('gerants', 'SELECT * FROM utilisateurs WHERE grade=2');\r
+\r
+ $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,\r
+ 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,\r
+ JSON_UNQUOTE(address->"$.address") AS adresse,\r
+ JSON_UNQUOTE(address->"$.postcode") AS code_postal,\r
+ JSON_UNQUOTE(address->"$.country") AS pays,\r
+ JSON_UNQUOTE(address->"$.city") AS ville,\r
+ IF(company = 7, JSON_UNQUOTE(address->"$.city"), \'\') AS agence, e1_notes AS notes, \r
+ company AS entreprise, UNIX_TIMESTAMP(created_at) AS date_creation FROM extranet_users.user');\r
+\r
+ $this->views->createView('e2_c', 'SELECT id AS entreprise_id, name AS nom, \r
+ JSON_UNQUOTE(address->"$.address") AS adresse,\r
+ JSON_UNQUOTE(address->"$.postcode") AS code_postal,\r
+ JSON_UNQUOTE(address->"$.country") AS pays,\r
+ JSON_UNQUOTE(address->"$.city") AS ville,\r
+ JSON_UNQUOTE(billing_address->"$.address") AS adresse_facturation,\r
+ vat_number AS tva_intra,\r
+ UNIX_TIMESTAMP(created_at) AS date_creation,\r
+ admin AS ws_admin,\r
+ e1_ws_signatures AS ws_signatures,\r
+ e1_ws_grade AS ws_grade,\r
+ type, website AS site\r
+ FROM extranet_users.company');\r
+\r
+ $this->views->createView('equipiers', 'SELECT * FROM e2_u WHERE grade>0');\r
+ $this->views->createView('gerants', 'SELECT * FROM e2_u WHERE grade=2');\r
$this->views->createView('impayes_entreprises', 'SELECT SUM(total_ht) AS impaye, u.entreprise AS entreprise '\r
- . 'FROM utilisateurs u LEFT JOIN projets p ON u.utilisateur_id=p.client LEFT JOIN factures f ON f.projet=p.projet_id '\r
+ . 'FROM e2_u u LEFT JOIN projets p ON u.utilisateur_id=p.client LEFT JOIN factures f ON f.projet=p.projet_id '\r
. 'WHERE f.status=1 GROUP BY u.entreprise');\r
$this->views->createView('entreprises_inter', 'SELECT e.*,'\r
. 'SUM(f.total_ht) AS ca '\r
- . 'FROM entreprises e LEFT JOIN utilisateurs u ON u.entreprise=e.entreprise_id AND grade=0 '\r
+ . 'FROM e2_c e LEFT JOIN e2_u u ON u.entreprise=e.entreprise_id AND grade=0 '\r
. 'LEFT JOIN projets p ON p.client=u.utilisateur_id '\r
. 'LEFT JOIN factures f ON f.projet=p.projet_id AND f.status IN(1,2) '\r
. 'GROUP BY e.entreprise_id');\r
$this->views->createView('entreprises_vue', 'SELECT e.*,i.impaye AS impaye '\r
. 'FROM entreprises_inter e LEFT JOIN impayes_entreprises i ON e.entreprise_id=i.entreprise');\r
+ $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');\r
$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\r
-FROM entreprises e\r
+FROM e2_c e\r
LEFT JOIN ws_entreprises_tree ri ON ri.entreprise_id=e.entreprise_id\r
-LEFT JOIN utilisateurs ur ON e.ws_admin=ur.utilisateur_id\r
-LEFT JOIN entreprises r ON ur.entreprise=r.entreprise_id\r
+LEFT JOIN e2_u ur ON e.ws_admin=ur.utilisateur_id\r
+LEFT JOIN e2_c r ON ur.entreprise=r.entreprise_id\r
LEFT JOIN ws_entreprises_tree wet ON wet.entreprise_id=r.entreprise_id\r
LEFT JOIN ca_fluidbook fb ON e.entreprise_id=fb.client\r
-LEFT JOIN utilisateurs a ON ri.administrateur_id=a.utilisateur_id');\r
+LEFT JOIN e2_u a ON ri.administrateur_id=a.utilisateur_id');\r
$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 '\r
- . 'FROM entreprises e LEFT JOIN utilisateurs u ON u.entreprise=e.entreprise_id AND u.grade=0');\r
+ . 'FROM e2_c e LEFT JOIN e2_u u ON u.entreprise=e.entreprise_id AND u.grade=0');\r
$this->views->createView('utilisateurs_entreprise', 'SELECT u.*,e.nom AS rs, e.adresse_facturation AS adresse_facturation, '\r
. 'e.ws_grade, e.ws_admin, e.ws_signatures AS ws_signatures, e.site AS site '\r
- . 'FROM entreprises e LEFT JOIN utilisateurs u ON u.entreprise=e.entreprise_id');\r
+ . 'FROM e2_c e LEFT JOIN e2_u u ON u.entreprise=e.entreprise_id');\r
$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, '\r
. 'SUM(f.total_ht) AS ca '\r
- . '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) '\r
- . 'GROUP BY u.utilisateur_id', 'TEMPTABLE');\r
+ . '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) '\r
+ . 'GROUP BY u.utilisateur_id');\r
$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');\r
$this->views->createView('taches_vue', 'SELECT taches.tache_id,taches.nom,taches.categorie,taches.type,taches.budget,taches.projet,taches.taux_journalier,tb.books, '\r
. '(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 '\r
$this->views->createView('cai', 'SELECT SUM(total_ht) AS ca, YEAR(FROM_UNIXTIME(date_creation)) annee FROM factures WHERE status = 5 GROUP BY annee');\r
$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');\r
$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');\r
- $this->views->createView('ftpaccess', 'SELECT email AS userid,password AS passwd,utilisateur_id AS uid,'\r
- . '\'1000\' AS gid,CONCAT(\'' . FTPROOT . '\',utilisateur_id) AS homedir, \'/bin/false\' AS shell '\r
- . 'FROM utilisateurs WHERE grade=0 '\r
- . 'UNION '\r
- . 'SELECT email AS userid,ws_password AS passwd,utilisateur_id AS uid,'\r
- . '\'1000\' AS gid,CONCAT(\'' . FTPROOT . '\',utilisateur_id) AS homedir, \'/bin/false\' AS shell '\r
- . 'FROM utilisateurs WHERE grade=0 AND ws_password!=\'\'');\r
+\r
$this->views->createView('chiffres_categories', 'SELECT p.annee_fin AS annee, t.categorie, SUM(t.budget) AS ca '\r
. 'FROM projets_vue p, taches_vue t '\r
. 'WHERE t.projet=p.projet_id '\r
. 'FROM books b '\r
. 'LEFT JOIN utilisateurs_entreprise c ON b.proprietaire=c.utilisateur_id '\r
. 'LEFT JOIN ws_users_tree t ON t.utilisateur_id=c.utilisateur_id '\r
- . 'LEFT JOIN utilisateurs a ON t.administrateur_id=a.utilisateur_id '\r
+ . 'LEFT JOIN e2_u a ON t.administrateur_id=a.utilisateur_id '\r
. 'LEFT JOIN utilisateurs_entreprise f ON t.facturable_id=f.utilisateur_id '\r
. 'LEFT JOIN taches ta ON ta.tache_id=b.tache', 'TEMPTABLE');\r
$this->views->createView('books_nbpages_vue', 'SELECT book_id, MAX(book_page) AS nb_pages '\r
. 'FROM demandes d '\r
. 'LEFT JOIN utilisateurs_entreprise r ON d.revendeur=r.utilisateur_id '\r
. 'LEFT JOIN utilisateurs_entreprise c ON d.utilisateur=c.utilisateur_id '\r
- . 'LEFT JOIN utilisateurs a ON d.administrateur=a.utilisateur_id');\r
+ . 'LEFT JOIN e2_u a ON d.administrateur=a.utilisateur_id');\r
$this->views->createView('chiffres_types', 'SELECT p.annee_fin AS annee, e.type, SUM(p.budget) AS ca '\r
. 'FROM projets_vue p, clients_entreprise e '\r
. 'WHERE p.client_id=e.utilisateur_id '\r
. 'FROM projets_vue_hf p, clients_entreprise e '\r
. 'WHERE p.client_id=e.utilisateur_id '\r
. 'GROUP BY e.type, p.annee_fin');\r
- $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');\r
\r
\r
//cubeDb::mysqlConvert($this->con, 'UTF8', 'utf8_general_ci', 'MYISAM');\r
$this->values[$r->prenom] = $r->utilisateur_id;\r
}\r
} elseif ($this->varname == 'revendeur_book') {\r
- $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
+ $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');\r
while ($r->fetch()) {\r
$this->values[$r->facturable] = $r->facturable;\r
}\r
$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();
}\r
\r
public function getListeForEntreprise($entreprise_id, $orderby, $sens) {\r
- $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;\r
+ $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
$r = $this->con->select($sql);\r
return $this->factory($r);\r
}\r
}\r
\r
public function getListeForEntreprise($entreprise_id, $orderby, $sens) {\r
- $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;\r
+ $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
$r = $this->con->select($sql);\r
return $this->factory($r);\r
}\r
$_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"), '<a href="mailto:info@fluidbook.com">info@fluidbook.com</a>'));
return;
$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;
$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();
}
}
- 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)
{
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('<extras>' . $r->extras . '</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) . '\') ';
}
- 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)
{
$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();
}
$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();
$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()) {
\r
$this->rights = array();\r
\r
- $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
+ $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');\r
while ($r->fetch()) {\r
$this->entreprises[$r->utilisateur_id] = $r->entreprise_id;\r
$this->users[$r->utilisateur_id] = $r->ws_admin;\r
$adom[$admin] = array_unique($adom[$admin]);\r
}\r
\r
- $c = $this->con->openCursor('utilisateurs');\r
+ $c = $this->con->openCursor('extranet_users.user');\r
foreach ($this->admins as $admin => $list) {\r
- $c->ws_rights = implode(',', $list);\r
- $c->ws_domains = implode(',', $adom[$admin]);\r
- $c->update('WHERE utilisateur_id=\'' . $this->con->escape($admin) . '\'');\r
+ $c->e1_ws_rights = implode(',', $list);\r
+ $c->e1_ws_domains = implode(',', $adom[$admin]);\r
+ $c->update('WHERE id=\'' . $this->con->escape($admin) . '\'');\r
}\r
}\r
\r