<?php\r
\r
-class commonDAOUtilisateur extends commonDAO {\r
+class commonDAOUtilisateur extends commonDAO\r
+{\r
\r
- protected function singleton($r, $utilisateur = null) {\r
- if (!$r) {\r
- return null;\r
- }\r
- if (is_null($utilisateur)) {\r
- if ($r->grade == 0) {\r
- $utilisateur = new commonClient();\r
- if (isset($r->ca)) {\r
- $utilisateur->ca = $r->ca;\r
- }\r
- if (isset($r->rs)) {\r
- $utilisateur->rs = $r->rs;\r
- }\r
- } else {\r
- $utilisateur = new commonEquipier();\r
- $utilisateur->agence = $r->agence;\r
- }\r
- }\r
- $utilisateur->utilisateur_id = $r->utilisateur_id;\r
- $utilisateur->nom = $r->nom;\r
- $utilisateur->prenom = $r->prenom;\r
- $utilisateur->email = $r->email;\r
- $utilisateur->password = $r->password;\r
- $utilisateur->adresse = $r->adresse;\r
- $utilisateur->code_postal = $r->code_postal;\r
- $utilisateur->ville = $r->ville;\r
- $utilisateur->pays = $r->pays;\r
- $utilisateur->telephone = $r->telephone;\r
- $utilisateur->mobile = $r->mobile;\r
- $utilisateur->fax = $r->fax;\r
- $utilisateur->date_creation = $r->date_creation;\r
- $utilisateur->grade = $r->grade;\r
- $utilisateur->lang = $r->lang;\r
- $utilisateur->login = $r->login;\r
- $utilisateur->settings = unserialize($r->settings);\r
- $utilisateur->connected = false;\r
- $utilisateur->notes = $r->notes;\r
- $utilisateur->entreprise = $r->entreprise;\r
- $utilisateur->collegues = array();\r
- $utilisateur->enabled = ($r->enabled == '1');\r
- if (isset($r->rs)) {\r
- $utilisateur->rs = $r->rs;\r
- }\r
- if (isset($r->ws_domains)) {\r
- $utilisateur->ws_domains = explode(',', $r->ws_domains);\r
- }\r
- if ($r->ws_settings != '') {\r
- $utilisateur->ws_settings = unserialize($r->ws_settings);\r
- } else {\r
- $utilisateur->ws_settings = array('resolution' => 150, 'method' => 0, 'quality' => 85, 'objects' => 1800);\r
- }\r
- if (isset($r->ws_grade)) {\r
- $utilisateur->ws_grade = $r->ws_grade;\r
- }\r
- if (isset($r->ws_rights)) {\r
- $utilisateur->ws_rights = $r->ws_rights;\r
- }\r
- if (isset($r->ws_signatures)) {\r
- $utilisateur->ws_signatures = $r->ws_signatures;\r
- }\r
- if (isset($r->ws_admin)) {\r
- $utilisateur->ws_admin = $r->ws_admin;\r
- }\r
- if (isset($r->site)) {\r
- $utilisateur->site = $r->site;\r
- }\r
- if (isset($r->tva_intra)) {\r
- $utilisateur->tva_intra = $r->tva_intra;\r
- }\r
- return $utilisateur;\r
- }\r
+ protected static $_names = null;\r
\r
- public function cree($utilisateur = null) {\r
- if (is_null($utilisateur)) {\r
- $utilisateur = new commonUtilisateur();\r
- }\r
- $utilisateur->utilisateur_id = 'new';\r
- $utilisateur->nom = '';\r
- $utilisateur->prenom = '';\r
- $utilisateur->email = '';\r
- $utilisateur->password = crypt::createPassword();\r
- $utilisateur->adresse = '';\r
- $utilisateur->code_postal = '';\r
- $utilisateur->ville = '';\r
- $utilisateur->telephone = '+33';\r
- $utilisateur->mobile = '+33';\r
- $utilisateur->fax = '+33';\r
- $utilisateur->date_creation = time();\r
- $utilisateur->pays = 'FR';\r
- $utilisateur->lang = 'fr';\r
- $utilisateur->settings = array();\r
- $utilisateur->notes = '';\r
- $utilisateur->entreprise = 0;\r
- $utilisateur->enabled = 1;\r
- $utilisateur->ws_settings = array('resolution' => 150, 'method' => 0, 'quality' => 85, 'objects' => 1800);\r
- return $utilisateur;\r
- }\r
+ protected function singleton($r, $utilisateur = null)\r
+ {\r
+ if (!$r) {\r
+ return null;\r
+ }\r
+ if (is_null($utilisateur)) {\r
+ if ($r->grade == 0) {\r
+ $utilisateur = new commonClient();\r
+ if (isset($r->ca)) {\r
+ $utilisateur->ca = $r->ca;\r
+ }\r
+ if (isset($r->rs)) {\r
+ $utilisateur->rs = $r->rs;\r
+ }\r
+ } else {\r
+ $utilisateur = new commonEquipier();\r
+ $utilisateur->agence = $r->agence;\r
+ }\r
+ }\r
+ $utilisateur->utilisateur_id = $r->utilisateur_id;\r
+ $utilisateur->nom = $r->nom;\r
+ $utilisateur->prenom = $r->prenom;\r
+ $utilisateur->email = $r->email;\r
+ $utilisateur->password = $r->password;\r
+ $utilisateur->adresse = $r->adresse;\r
+ $utilisateur->code_postal = $r->code_postal;\r
+ $utilisateur->ville = $r->ville;\r
+ $utilisateur->pays = $r->pays;\r
+ $utilisateur->telephone = $r->telephone;\r
+ $utilisateur->mobile = $r->mobile;\r
+ $utilisateur->fax = $r->fax;\r
+ $utilisateur->date_creation = $r->date_creation;\r
+ $utilisateur->grade = $r->grade;\r
+ $utilisateur->lang = $r->lang;\r
+ $utilisateur->login = $r->login;\r
+ $utilisateur->settings = unserialize($r->settings);\r
+ $utilisateur->connected = false;\r
+ $utilisateur->notes = $r->notes;\r
+ $utilisateur->entreprise = $r->entreprise;\r
+ $utilisateur->collegues = array();\r
+ $utilisateur->enabled = ($r->enabled == '1');\r
+ if (isset($r->rs)) {\r
+ $utilisateur->rs = $r->rs;\r
+ }\r
+ if (isset($r->ws_domains)) {\r
+ $utilisateur->ws_domains = explode(',', $r->ws_domains);\r
+ }\r
+ if ($r->ws_settings != '') {\r
+ $utilisateur->ws_settings = unserialize($r->ws_settings);\r
+ } else {\r
+ $utilisateur->ws_settings = array('resolution' => 150, 'method' => 0, 'quality' => 85, 'objects' => 1800);\r
+ }\r
+ if (isset($r->ws_grade)) {\r
+ $utilisateur->ws_grade = $r->ws_grade;\r
+ }\r
+ if (isset($r->ws_rights)) {\r
+ $utilisateur->ws_rights = $r->ws_rights;\r
+ }\r
+ if (isset($r->ws_signatures)) {\r
+ $utilisateur->ws_signatures = $r->ws_signatures;\r
+ }\r
+ if (isset($r->ws_admin)) {\r
+ $utilisateur->ws_admin = $r->ws_admin;\r
+ }\r
+ if (isset($r->site)) {\r
+ $utilisateur->site = $r->site;\r
+ }\r
+ if (isset($r->tva_intra)) {\r
+ $utilisateur->tva_intra = $r->tva_intra;\r
+ }\r
+ return $utilisateur;\r
+ }\r
\r
- public function creeFromEntreprise($entreprise_id) {\r
- $utilisateur = $this->cree(null);\r
- $utilisateur->entreprise = $entreprise_id;\r
- $daoEntreprise = new commonDAOEntreprise($this->con);\r
- $entreprise = $daoEntreprise->selectById($entreprise_id);\r
- $utilisateur->adresse = $entreprise->adresse;\r
- $utilisateur->code_postal = $entreprise->code_postal;\r
- $utilisateur->ville = $entreprise->ville;\r
- $utilisateur->pays = $entreprise->pays;\r
- return $utilisateur;\r
- }\r
+ public function cree($utilisateur = null)\r
+ {\r
+ if (is_null($utilisateur)) {\r
+ $utilisateur = new commonUtilisateur();\r
+ }\r
+ $utilisateur->utilisateur_id = 'new';\r
+ $utilisateur->nom = '';\r
+ $utilisateur->prenom = '';\r
+ $utilisateur->email = '';\r
+ $utilisateur->password = crypt::createPassword();\r
+ $utilisateur->adresse = '';\r
+ $utilisateur->code_postal = '';\r
+ $utilisateur->ville = '';\r
+ $utilisateur->telephone = '+33';\r
+ $utilisateur->mobile = '+33';\r
+ $utilisateur->fax = '+33';\r
+ $utilisateur->date_creation = time();\r
+ $utilisateur->pays = 'FR';\r
+ $utilisateur->lang = 'fr';\r
+ $utilisateur->settings = array();\r
+ $utilisateur->notes = '';\r
+ $utilisateur->entreprise = 0;\r
+ $utilisateur->enabled = 1;\r
+ $utilisateur->ws_settings = array('resolution' => 150, 'method' => 0, 'quality' => 85, 'objects' => 1800);\r
+ return $utilisateur;\r
+ }\r
\r
- public function selectById($utilisateur_id, $table = 'utilisateurs') {\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 creeFromEntreprise($entreprise_id)\r
+ {\r
+ $utilisateur = $this->cree(null);\r
+ $utilisateur->entreprise = $entreprise_id;\r
+ $daoEntreprise = new commonDAOEntreprise($this->con);\r
+ $entreprise = $daoEntreprise->selectById($entreprise_id);\r
+ $utilisateur->adresse = $entreprise->adresse;\r
+ $utilisateur->code_postal = $entreprise->code_postal;\r
+ $utilisateur->ville = $entreprise->ville;\r
+ $utilisateur->pays = $entreprise->pays;\r
+ return $utilisateur;\r
+ }\r
\r
- public function selectByLoginPassword($login, $password) {\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
- $r = $this->con->select($sql);\r
- if ($r->count() == 0) {\r
- return false;\r
- }\r
- $utilisateur = $this->singleton($r);\r
- return $utilisateur;\r
- }\r
+ public function selectById($utilisateur_id, $table = 'utilisateurs')\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
\r
- public function selectByEmail($email) {\r
- $r = $this->con->select('SELECT * FROM utilisateurs WHERE email=\'' . $this->con->escape($email) . '\'');\r
- if ($r->count()) {\r
- return $this->singleton($r);\r
- }\r
- return null;\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
+ $r = $this->con->select($sql);\r
+ if ($r->count() == 0) {\r
+ return false;\r
+ }\r
+ $utilisateur = $this->singleton($r);\r
+ return $utilisateur;\r
+ }\r
\r
- public function selectWSRevendeursFacturables() {\r
- $r = $this->con->select('SELECT * FROM utilisateurs_entreprise WHERE ws_grade BETWEEN 3 AND 4 AND utilisateur_id IN(SELECT facturable_id FROM ws_users_tree) ORDER BY rs');\r
- return $this->factory($r);\r
- }\r
+ public function selectByEmail($email)\r
+ {\r
+ $r = $this->con->select('SELECT * FROM utilisateurs WHERE email=\'' . $this->con->escape($email) . '\'');\r
+ if ($r->count()) {\r
+ return $this->singleton($r);\r
+ }\r
+ return null;\r
+ }\r
\r
- public function selectWSAdministrateursId() {\r
- $r = $this->con->select('SELECT * FROM utilisateurs_entreprise WHERE ws_grade=5');\r
- $liste = $this->factory($r);\r
+ public function selectWSRevendeursFacturables()\r
+ {\r
+ $r = $this->con->select('SELECT * FROM utilisateurs_entreprise WHERE ws_grade BETWEEN 3 AND 4 AND utilisateur_id IN(SELECT facturable_id FROM ws_users_tree) ORDER BY rs');\r
+ return $this->factory($r);\r
+ }\r
\r
- $res = array();\r
- foreach ($liste as $u) {\r
- $res[] = $u->utilisateur_id;\r
- }\r
- return $res;\r
- }\r
+ public function selectWSAdministrateursId()\r
+ {\r
+ $r = $this->con->select('SELECT * FROM utilisateurs_entreprise WHERE ws_grade=5');\r
+ $liste = $this->factory($r);\r
\r
- protected function getNextId() {\r
- $r = $this->con->select('SELECT MAX(utilisateur_id) AS utilisateur_id FROM utilisateurs');\r
- return $r->utilisateur_id + 1;\r
- }\r
+ $res = array();\r
+ foreach ($liste as $u) {\r
+ $res[] = $u->utilisateur_id;\r
+ }\r
+ return $res;\r
+ }\r
\r
- protected function getQueryList($table, $orderby = null, $sens = null, $limit = null, $where = null, $limitedToUserRights = false) {\r
- $wherec = $where;\r
- $where = '(';\r
- if (!is_null($this->q)) {\r
- if ($this->search_id) {\r
- $where .= 'utilisateur_id=\'' . $this->con->escape($this->q) . '\' OR ';\r
- }\r
- $where .= $this->whereSearchByName($this->q);\r
- $limit = null;\r
- } else {\r
- $where .= $this->makeWhereFromFiltres();\r
- }\r
- $where .= ' ' . $wherec . ' )';\r
- $where .= $this->limitToUserRights($limitedToUserRights);\r
- $orderby = is_null($orderby) ? 'utilisateur_id' : $orderby;\r
- $sens = is_null($sens) ? 'DESC' : $sens;\r
- $limit = is_null($limit) ? '' : $this->con->limit($limit[0], $limit[1]);\r
+ protected function getNextId()\r
+ {\r
+ $r = $this->con->select('SELECT MAX(utilisateur_id) AS utilisateur_id FROM utilisateurs');\r
+ return $r->utilisateur_id + 1;\r
+ }\r
\r
- $sql = 'SELECT * FROM ' . $table . ' WHERE (' . $where . ') ORDER BY ' . $orderby . ' ' . $sens . ' ' . $limit;\r
- return $sql;\r
- }\r
+ protected function getQueryList($table, $orderby = null, $sens = null, $limit = null, $where = null, $limitedToUserRights = false)\r
+ {\r
+ $wherec = $where;\r
+ $where = '(';\r
+ if (!is_null($this->q)) {\r
+ if ($this->search_id) {\r
+ $where .= 'utilisateur_id=\'' . $this->con->escape($this->q) . '\' OR ';\r
+ }\r
+ $where .= $this->whereSearchByName($this->q);\r
+ $limit = null;\r
+ } else {\r
+ $where .= $this->makeWhereFromFiltres();\r
+ }\r
+ $where .= ' ' . $wherec . ' )';\r
+ $where .= $this->limitToUserRights($limitedToUserRights);\r
+ $orderby = is_null($orderby) ? 'utilisateur_id' : $orderby;\r
+ $sens = is_null($sens) ? 'DESC' : $sens;\r
+ $limit = is_null($limit) ? '' : $this->con->limit($limit[0], $limit[1]);\r
\r
- protected function limitToUserRights($user) {\r
- if ($user) {\r
- return ' AND utilisateur_id IN (' . $user->ws_rights . ')';\r
- }\r
- return '';\r
- }\r
+ $sql = 'SELECT * FROM ' . $table . ' WHERE (' . $where . ') ORDER BY ' . $orderby . ' ' . $sens . ' ' . $limit;\r
+ return $sql;\r
+ }\r
\r
- public function getListe($orderby = null, $sens = null, $limit = null, $where = null, $limitedToUserRights = false) {\r
- $sql = $this->getQueryList('utilisateurs_entreprise', $orderby, $sens, $limit, $where, $limitedToUserRights);\r
- $r = $this->con->select($sql);\r
- return $this->factory($r);\r
- }\r
+ protected function limitToUserRights($user)\r
+ {\r
+ if ($user) {\r
+ return ' AND utilisateur_id IN (' . $user->ws_rights . ')';\r
+ }\r
+ return '';\r
+ }\r
\r
- public function whereSearchByName($q, $search_entreprise = true) {\r
- $where = 'nom LIKE \'' . $this->con->escape($q) . '%\' OR ';\r
- $where .= 'prenom LIKE \'' . $this->con->escape($q) . '%\' OR ';\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
- }\r
- $where .= 'email LIKE \'%' . $this->con->escape($q) . '%\'';\r
- return $where;\r
- }\r
+ public function getListe($orderby = null, $sens = null, $limit = null, $where = null, $limitedToUserRights = false)\r
+ {\r
+ $sql = $this->getQueryList('utilisateurs_entreprise', $orderby, $sens, $limit, $where, $limitedToUserRights);\r
+ $r = $this->con->select($sql);\r
+ return $this->factory($r);\r
+ }\r
\r
- public function sauve($data) {\r
- $c = $this->con->openCursor('utilisateurs');\r
- $c->grade = $data['grade'];\r
- $c->nom = $data['nom'];\r
- $c->prenom = $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
- }\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
- 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
- }\r
- }\r
+ public function whereSearchByName($q, $search_entreprise = true)\r
+ {\r
+ $where = 'nom LIKE \'' . $this->con->escape($q) . '%\' OR ';\r
+ $where .= 'prenom LIKE \'' . $this->con->escape($q) . '%\' OR ';\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
+ }\r
+ $where .= 'email LIKE \'%' . $this->con->escape($q) . '%\'';\r
+ return $where;\r
+ }\r
\r
- public function sauveNotes($utilisateur_id, $notes) {\r
- $c = $this->con->openCursor('utilisateurs');\r
- $c->notes = $notes;\r
- return $c->update('WHERE utilisateur_id=\'' . $this->con->escape($utilisateur_id) . '\'');\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->email = $data['email'];\r
+ if (isset($data['password'])) {\r
+ $c->password = $data['password'];\r
+ } else {\r
+ $c->password = crypt::createPassword();\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
+ 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
+ }\r
+ }\r
\r
- public function sauveWSSettings($utilisateur_id, $datas) {\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
- }\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
+ }\r
\r
- public function sauvePreferences($utilisateur) {\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
- }\r
- return false;\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
+ }\r
\r
- public function changeParametres($utilisateur_id, $langue, $login) {\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
- }\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
+ }\r
+ return false;\r
+ }\r
\r
- public function changeMotdepasse($utilisateur_id, $nouveau) {\r
- $c = $this->con->openCursor('utilisateurs');\r
- $c->password = $nouveau;\r
- return $c->update('WHERE utilisateur_id=\'' . $this->con->escape($utilisateur_id) . '\'');\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
+ }\r
\r
- public function supprime($utilisateur_id) {\r
- $ok = $this->con->execute('DELETE FROM utilisateurs WHERE utilisateur_id=\'' . $this->con->escape($utilisateur_id) . '\'');\r
- $core->refreshWSUsersTree();\r
- return $ok;\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
+ }\r
\r
- public function count() {\r
- $r = $this->con->select('SELECT COUNT(*) AS nb FROM utilisateurs WHERE ' . $this->makeWhereFromFiltres());\r
- return $r->nb;\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
+ $core->refreshWSUsersTree();\r
+ return $ok;\r
+ }\r
\r
- protected function makeWhereFromFiltres() {\r
- return '1=1';\r
- }\r
+ public function count()\r
+ {\r
+ $r = $this->con->select('SELECT COUNT(*) AS nb FROM utilisateurs WHERE ' . $this->makeWhereFromFiltres());\r
+ return $r->nb;\r
+ }\r
+\r
+ protected function makeWhereFromFiltres()\r
+ {\r
+ return '1=1';\r
+ }\r
+\r
+ public static function getNameById($user_id)\r
+ {\r
+\r
+ if (null === self::$_names) {\r
+ self::$_names = [];\r
+\r
+ global $core;\r
+\r
+ $r = $core->con->select('SELECT prenom,nom,utilisateur_id FROM utilisateurs');\r
+ while ($r->fetch()) {\r
+ self::$_names[$r->utilisateur_id] = $r->prenom . ' ' . $r->nom;\r
+ }\r
+ self::$_names[0] = '-';\r
+ }\r
+ return self::$_names[$user_id];\r
+ }\r
\r
}
\ No newline at end of file
protected static function _importLinksAsExcel($book_id)
{
global $core;
+
$xls = new PHPExcel();
$reader = new PHPExcel_Reader_Excel2007();
$xls = $reader->load($_FILES['file']['tmp_name']);
wsLinks::getLinksFromExcel($xls, $links, $rulers);
+ $comments = 'Import from excel';
+
+ // New Way
+ wsLinks::saveLinksInFile($book_id, $core->user->utilisateur_id, $comments, $links, $rulers);
+
+ // Old way
$dao = new wsDAODocument($core->con);
- $dao->setLinksAndRulers($book_id, json_encode($links), json_encode($rulers), 'Import from excel', $core->user->utilisateur_id);
+ $dao->setLinksAndRulers($book_id, json_encode($links), json_encode($rulers), $comments, $core->user->utilisateur_id);
}
protected function _importLinksAsAutobookmarkText($book_id)
<?php\r
\r
-class wsConversionSession {\r
-\r
- protected $documentsId = array();\r
- protected $documentsPages = array();\r
- protected $documents = array();\r
- protected $guid;\r
- protected $progress = 0;\r
- protected $processing = false;\r
- protected $inited = false;\r
- protected $complete = false;\r
- protected $totalPages = null;\r
- protected $currentDoc = null;\r
- protected $currentDocPage = 0;\r
- protected $totalDocPage = 0;\r
- protected $totalDoc = 0;\r
- protected $processedPages = 0;\r
- protected $processedDoc = 0;\r
- protected $bookId = null;\r
- public $reload = false;\r
- protected $nb_threads = 8;\r
- protected $threads;\r
-\r
- public function __construct($guid) {\r
- $this->guid = $guid;\r
- }\r
-\r
- public function getGUID() {\r
- return $this->guid;\r
- }\r
-\r
- public function setDocuments($documents) {\r
- $this->documentsId = array_keys($documents);\r
- $this->documentsPages = $documents;\r
- }\r
-\r
- public function setBook($book_id) {\r
- $this->bookId = $book_id;\r
- }\r
-\r
- public function initDocuments() {\r
- global $core;\r
-\r
- $dao = new wsDAODocument($core->con);\r
- $docs = $dao->selectInList($this->documentsId);\r
-\r
- foreach ($docs as $doc) {\r
- $this->documents[$doc->document_id] = $doc;\r
- }\r
- $inited = true;\r
- }\r
-\r
- public function getDocumentById($id) {\r
- return $this->documents[$id];\r
- }\r
-\r
- protected function initThreads() {\r
- if (!cubeThread::available() || $this->nb_threads <= 1) {\r
- return;\r
- }\r
- $this->threads = array();\r
- for ($i = 0; $i < $this->nb_threads; $i++) {\r
- $this->threads[] = new cubeThread();\r
- }\r
- }\r
-\r
- public function process() {\r
- global $core;\r
-\r
- $this->initThreads();\r
-\r
- $this->processing = true;\r
- $this->initDocuments();\r
- $this->serialize();\r
- $dao = new wsDAODocument($core->con);\r
- $daoBook = new wsDAOBook($core->con);\r
-\r
- foreach ($this->documents as $doc) {\r
- $this->currentDoc = $doc;\r
- $this->serialize();\r
- if (!$this->reload) {\r
- $this->currentDoc->resetLog();\r
- $this->currentDoc->globalOperations();\r
- } else if ($this->documentsPages[$doc->document_id] == 'all') {\r
- $this->currentDoc->resetLog();\r
- $this->currentDoc->globalOperations();\r
- }\r
- if ($this->documentsPages[$doc->document_id] == 'all') {\r
- $docPages = range(1, $doc->generalInfos['pages']);\r
- } else {\r
- $docPages = $this->documentsPages[$doc->document_id];\r
- }\r
-\r
- $this->updateCountPages();\r
- $this->currentDoc = $dao->updateFromObject($this->currentDoc);\r
- $doc_serialized = serialize($this->currentDoc);\r
-\r
- foreach ($docPages as $i => $page) {\r
- $this->currentDocPage = $i + 1;\r
- $this->totalDocPage = count($docPages);\r
-\r
- $this->setProgress(($this->processedPages / $this->totalPages) * 100);\r
-\r
- if (cubeThread::available() && $this->nb_threads > 1) {\r
- $t = $this->threads[$i % $this->nb_threads];\r
- while ($t->isAlive()) {\r
- usleep(100000);\r
- }\r
- $t->setRunnable(array('wsConversionSession', 'processPage'));\r
- $t->start($doc_serialized, $page);\r
- } else {\r
- $this->currentDoc->processOnePage($page, true);\r
- }\r
- $this->processedPages++;\r
- }\r
-\r
- if (cubeThread::available() && $this->nb_threads > 1) {\r
- foreach ($this->threads as $t) {\r
- while ($t->isAlive()) {\r
- usleep(100000);\r
- }\r
- }\r
- }\r
-\r
- $this->currentDoc = unserialize($doc_serialized);\r
-\r
- $core->reloadDBConnection();\r
- $dao = new wsDAODocument($core->con);\r
- $daoBook = new wsDAOBook($core->con);\r
-\r
- if (!$this->reload) {\r
- // On n'ajoute les fichiers à la fin du fluidbook que si l'on\r
- // n'est pas en train de recharger le fluidbook\r
- $daoBook->appendDocument($this->bookId, $this->currentDoc->document_id);\r
- }\r
-\r
- if (!$this->reload) {\r
- $log = $dao->putLinksFromCSV($this->currentDoc->document_id);\r
- $this->currentDoc->addToLog($log);\r
- }\r
- $this->processedDoc++;\r
-\r
-\r
- ob_flush();\r
- }\r
-\r
- usleep(100000);\r
-\r
- $this->complete = true;\r
- $this->processing = false;\r
- $this->setProgress(100);\r
- }\r
-\r
- public static function processPage($doc_serialized, $page) {\r
- $doc = unserialize($doc_serialized);\r
- $doc->processOnePage($page, true);\r
- }\r
-\r
- public function updateCountPages() {\r
- $this->totalPages = 0;\r
- foreach ($this->documentsPages as $id => $pages) {\r
- if ($pages == 'all') {\r
- $doc = $this->getDocumentById($id);\r
- $this->totalPages += $doc->generalInfos['pages'];\r
- } else {\r
- $this->totalPages += count($pages);\r
- }\r
- }\r
- $this->totalDoc = count($this->documents);\r
- }\r
-\r
- public function getProgress() {\r
- $res = array("progress" => $this->progress,\r
- 'totalDoc' => $this->totalDoc,\r
- 'currentDocPage' => $this->currentDocPage,\r
- 'totalDocPage' => $this->totalDocPage,\r
- 'totalPages' => $this->totalPages,\r
- 'processedPages' => $this->processedPages,\r
- 'processedDoc' => max($this->processedDoc + 1, $this->totalDoc));\r
- if ($this->currentDoc) {\r
- $res['currentDoc'] = $this->currentDoc->file;\r
- }\r
- return $res;\r
- }\r
-\r
- public function setProgress($i) {\r
- $this->progress = $i;\r
- $this->serialize();\r
- }\r
-\r
- public function getTotalPages() {\r
- return $this->totalPages;\r
- }\r
-\r
- public function getProcessedPages() {\r
- return $this->processedPages;\r
- }\r
-\r
- public function serialize() {\r
- file_put_contents(self::getCachePath($this->guid), serialize($this));\r
- }\r
-\r
- public function destroy() {\r
- if (file_exists(self::getCachePath($this->guid))) {\r
- // unlink(self::getCachePath($this->guid));\r
- }\r
- }\r
-\r
- public function __destruct() {\r
-\r
- }\r
-\r
- public static function openFromGUID($guid) {\r
- $serializedObject = self::getCachePath($guid);\r
- if (file_exists($serializedObject)) {\r
- return unserialize(file_get_contents($serializedObject));\r
- } else {\r
- return new wsConversionSession($guid);\r
- }\r
- }\r
-\r
- public static function getCachePath($guid) {\r
- return CACHE . '/conversionSessions/' . $guid . '.obj';\r
- }\r
+class wsConversionSession\r
+{\r
+\r
+ protected $documentsId = array();\r
+ protected $documentsPages = array();\r
+ protected $documents = array();\r
+ protected $guid;\r
+ protected $progress = 0;\r
+ protected $processing = false;\r
+ protected $inited = false;\r
+ protected $complete = false;\r
+ protected $totalPages = null;\r
+ protected $currentDoc = null;\r
+ protected $currentDocPage = 0;\r
+ protected $totalDocPage = 0;\r
+ protected $totalDoc = 0;\r
+ protected $processedPages = 0;\r
+ protected $processedDoc = 0;\r
+ protected $bookId = null;\r
+ public $reload = false;\r
+ protected $nb_threads = 8;\r
+ protected $threads;\r
+\r
+ public function __construct($guid)\r
+ {\r
+ $this->guid = $guid;\r
+ }\r
+\r
+ public function getGUID()\r
+ {\r
+ return $this->guid;\r
+ }\r
+\r
+ public function setDocuments($documents)\r
+ {\r
+ $this->documentsId = array_keys($documents);\r
+ $this->documentsPages = $documents;\r
+ }\r
+\r
+ public function setBook($book_id)\r
+ {\r
+ $this->bookId = $book_id;\r
+ }\r
+\r
+ public function initDocuments()\r
+ {\r
+ global $core;\r
+\r
+ $dao = new wsDAODocument($core->con);\r
+ $docs = $dao->selectInList($this->documentsId);\r
+\r
+ foreach ($docs as $doc) {\r
+ $this->documents[$doc->document_id] = $doc;\r
+ }\r
+ $inited = true;\r
+ }\r
+\r
+ public function getDocumentById($id)\r
+ {\r
+ return $this->documents[$id];\r
+ }\r
+\r
+ protected function initThreads()\r
+ {\r
+ if (!cubeThread::available() || $this->nb_threads <= 1) {\r
+ return;\r
+ }\r
+ $this->threads = array();\r
+ for ($i = 0; $i < $this->nb_threads; $i++) {\r
+ $this->threads[] = new cubeThread();\r
+ }\r
+ }\r
+\r
+ public function process()\r
+ {\r
+ global $core;\r
+\r
+ $this->initThreads();\r
+\r
+ $this->processing = true;\r
+ $this->initDocuments();\r
+ $this->serialize();\r
+ $dao = new wsDAODocument($core->con);\r
+\r
+ foreach ($this->documents as $doc) {\r
+ $this->currentDoc = $doc;\r
+ $this->serialize();\r
+ if (!$this->reload) {\r
+ $this->currentDoc->resetLog();\r
+ $this->currentDoc->globalOperations();\r
+ } else if ($this->documentsPages[$doc->document_id] == 'all') {\r
+ $this->currentDoc->resetLog();\r
+ $this->currentDoc->globalOperations();\r
+ }\r
+ if ($this->documentsPages[$doc->document_id] == 'all') {\r
+ $docPages = range(1, $doc->generalInfos['pages']);\r
+ } else {\r
+ $docPages = $this->documentsPages[$doc->document_id];\r
+ }\r
+\r
+ $this->updateCountPages();\r
+ $this->currentDoc = $dao->updateFromObject($this->currentDoc);\r
+ $doc_serialized = serialize($this->currentDoc);\r
+\r
+ foreach ($docPages as $i => $page) {\r
+ $this->currentDocPage = $i + 1;\r
+ $this->totalDocPage = count($docPages);\r
+\r
+ $this->setProgress(($this->processedPages / $this->totalPages) * 100);\r
+\r
+ if (cubeThread::available() && $this->nb_threads > 1) {\r
+ $t = $this->threads[$i % $this->nb_threads];\r
+ while ($t->isAlive()) {\r
+ usleep(100000);\r
+ }\r
+ $t->setRunnable(array('wsConversionSession', 'processPage'));\r
+ $t->start($doc_serialized, $page);\r
+ } else {\r
+ $this->currentDoc->processOnePage($page, true);\r
+ }\r
+ $this->processedPages++;\r
+ }\r
+\r
+ if (cubeThread::available() && $this->nb_threads > 1) {\r
+ foreach ($this->threads as $t) {\r
+ while ($t->isAlive()) {\r
+ usleep(100000);\r
+ }\r
+ }\r
+ }\r
+\r
+ $this->currentDoc = unserialize($doc_serialized);\r
+\r
+ $core->reloadDBConnection();\r
+ $dao = new wsDAODocument($core->con);\r
+ $daoBook = new wsDAOBook($core->con);\r
+\r
+ if (!$this->reload) {\r
+ // On n'ajoute les fichiers à la fin du fluidbook que si l'on\r
+ // n'est pas en train de recharger le fluidbook\r
+ $daoBook->appendDocument($this->bookId, $this->currentDoc->document_id);\r
+ }\r
+\r
+ if (!$this->reload) {\r
+ wsLinks::addLinksFromPDF($this->bookId);\r
+ $log = $dao->putLinksFromCSV($this->currentDoc->document_id);\r
+ $this->currentDoc->addToLog($log);\r
+ }\r
+ $this->processedDoc++;\r
+\r
+\r
+ ob_flush();\r
+ }\r
+\r
+ usleep(100000);\r
+\r
+ $this->complete = true;\r
+ $this->processing = false;\r
+ $this->setProgress(100);\r
+ }\r
+\r
+ public static function processPage($doc_serialized, $page)\r
+ {\r
+ $doc = unserialize($doc_serialized);\r
+ $doc->processOnePage($page, true);\r
+ }\r
+\r
+ public function updateCountPages()\r
+ {\r
+ $this->totalPages = 0;\r
+ foreach ($this->documentsPages as $id => $pages) {\r
+ if ($pages == 'all') {\r
+ $doc = $this->getDocumentById($id);\r
+ $this->totalPages += $doc->generalInfos['pages'];\r
+ } else {\r
+ $this->totalPages += count($pages);\r
+ }\r
+ }\r
+ $this->totalDoc = count($this->documents);\r
+ }\r
+\r
+ public function getProgress()\r
+ {\r
+ $res = array("progress" => $this->progress,\r
+ 'totalDoc' => $this->totalDoc,\r
+ 'currentDocPage' => $this->currentDocPage,\r
+ 'totalDocPage' => $this->totalDocPage,\r
+ 'totalPages' => $this->totalPages,\r
+ 'processedPages' => $this->processedPages,\r
+ 'processedDoc' => max($this->processedDoc + 1, $this->totalDoc));\r
+ if ($this->currentDoc) {\r
+ $res['currentDoc'] = $this->currentDoc->file;\r
+ }\r
+ return $res;\r
+ }\r
+\r
+ public function setProgress($i)\r
+ {\r
+ $this->progress = $i;\r
+ $this->serialize();\r
+ }\r
+\r
+ public function getTotalPages()\r
+ {\r
+ return $this->totalPages;\r
+ }\r
+\r
+ public function getProcessedPages()\r
+ {\r
+ return $this->processedPages;\r
+ }\r
+\r
+ public function serialize()\r
+ {\r
+ file_put_contents(self::getCachePath($this->guid), serialize($this));\r
+ }\r
+\r
+ public function destroy()\r
+ {\r
+ if (file_exists(self::getCachePath($this->guid))) {\r
+ // unlink(self::getCachePath($this->guid));\r
+ }\r
+ }\r
+\r
+ public function __destruct()\r
+ {\r
+\r
+ }\r
+\r
+ public static function openFromGUID($guid)\r
+ {\r
+ $serializedObject = self::getCachePath($guid);\r
+ if (file_exists($serializedObject)) {\r
+ return unserialize(file_get_contents($serializedObject));\r
+ } else {\r
+ return new wsConversionSession($guid);\r
+ }\r
+ }\r
+\r
+ public static function getCachePath($guid)\r
+ {\r
+ return CACHE . '/conversionSessions/' . $guid . '.obj';\r
+ }\r
\r
}
\ No newline at end of file
}
- $daoDoc->getLinksAndRulers($this->args['book_id'], $links, $rulers);
+ $daoDoc->getLinksAndRulersFromFile($this->args['book_id'], $links, $rulers);
- $this->json = false;
$this->json = true;
$types = array(1, 2, 3, 4, 5, 6, 7, 11, 13, 14, 15, 16, 17, 18, 19, 24, 25);
$comments = isset($this->args['comments']) ? $this->args['comments'] : 'Saved from editor';
+ //
$dao = new wsDAODocument($core->con);
$dao->setLinksAndRulers($this->args['book_id'], $this->args['links'], $this->args['rulers'], $comments, $core->user->utilisateur_id, false);
$daoBook = new wsDAOBook($core->con);
$daoBook->setSpecialLinksAndRulers($this->args['book_id'], $this->args['specialLinks'], $this->args['specialRulers']);
+ wsLinks::saveLinksInFile($this->args['book_id'], $core->user->utilisateur_id, $comments,
+ $this->args['links'], $this->args['rulers'],
+ $this->args['specialLinks'], $this->args['specialRulers']);
+
if (isset($this->args['getLinks'])) {
$this->getLinks();
}
CubeIT_Util_PHP::neverStop();
global $core;
- $r = $core->con->select('SELECT * FROM books ORDER BY book_id DESC');
- $k = (int)$args[0];
-
- $books = [];
- while ($r->fetch()) {
- if ($r->book_id % 8 === $k) {
+ if (isset($args[0]) && $args[0]) {
+ $books = [$args[0]];
+ } else {
+ $r = $core->con->select('SELECT * FROM books ORDER BY book_id DESC');
+ $books = [];
+ while ($r->fetch()) {
$books[] = $r->book_id;
}
}
+
foreach ($books as $id) {
- $dir = WS_BOOKS . '/links/' . $id;
- if (!file_exists($dir)) {
- mkdir($dir, 0777, true);
- }
+ $dir = wsLinks::getLinksDir($id);
/** @var $book wsBook */
$dao = new wsDAODocument($core->con);
$updates = $dao->getLinksVersions($id);
+ $max = 0;
foreach ($updates as $time => $update) {
- $file = $dir . '/' . $time . '.links';
- $gzfile = $file . '.gz';
- $meta = $dir . '/' . $time . '.meta';
- if (file_exists($file) || file_exists($gzfile)) {
- continue;
- }
-
- $links = [];
- $rulers = [];
+ $max = max($max, $time);
+ self::_writeLinks($id, $dir, $time, $update);
+ }
+ self::_writeLinks($id, $dir, $max, $updates[$max], 'latest');
+ }
+ }
- wsLinks::getLinksAndRulers($id, $links, $rulers, $time);
+ protected static function _writeLinks($book_id, $dir, $time, $data, $version = 'time')
+ {
+ if ($version === 'time') {
+ $version = $time;
+ }
- $res = ['links' => $links, 'rulers' => $rulers];
- file_put_contents($file, json_encode($res));
- file_put_contents($meta, json_encode($update));
- }
+ $file = $dir . '/' . $version . '.links.gz';
+ $meta = $dir . '/' . $version . '.meta.gz';
+ if (file_exists($file)) {
+ return;
}
+
+ $links = [];
+ $rulers = [];
+
+ wsLinks::getLinksAndRulers($book_id, $links, $rulers, $time);
+
+ $res = ['links' => $links, 'rulers' => $rulers];
+ file_put_contents($file, gzencode(json_encode($res)));
+ file_put_contents($meta, gzencode(json_encode($data)));
}
}
$args = cubePage::getArgs($args);
$book_id = $args[0];
-
- $dao = new wsDAODocument($core->con);
- $updates = $dao->getLinksVersions($book_id);
- krsort($updates);
+ $updates = wsLinks::getLinksVersions($book_id);
$res = '<html><head>';
$res .= '<title>' . __('Restauration des liens de la publication') . ' #' . $args[0] . '</title>';
$res .= '<td>' . date('Y-m-d H:i:s', $time) . '</td>';
$res .= '<td class="center">' . $infos['links'] . '</td>';
$res .= '<td class="center">' . $infos['rulers'] . '</td>';
- $res .= '<td class="center">' . $infos['user'] . '</td>';
+ $res .= '<td class="center">' . commonDAOUtilisateur::getNameById($infos['user']) . '</td>';
$res .= '<td class="center">' . $infos['comments'] . '</td>';
$res .= '<td><a href="#" rel="' . $book_id . '/' . $time . '" class="restoreLink">' . __('Restaurer') . '</a></td>';
$res .= '<td><a href="' . SITE_PATH . 'exportLinksAsExcel/' . $book_id . '/' . $time . '">' . str_replace(' ', ' ', __('Export Excel')) . '</a></td>';
echo $res;
}
+
public static function exportLinksAsExcel($args)
{
global $core;
$book_id = $args[1];
$time = $args[2];
- $dao = new wsDAODocument($core->con);
- $dao->getLinksAndRulers($book_id, $links, $rulers, $time);
- $xls = $dao->getLinksAsExcel($links, $rulers);
+ wsLinks::getLinksAndRulersFromFile($book_id, $links, $rulers, $time);
+ $xls = wsLinks::linksToExcel($links, $rulers);
ob_end_clean();
files::registerMimeTypes(array('xlsx' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'));
public function setSpecialLinksAndRulers($book_id, $links, $rulers)
{
- $c1 = $this->con->openCursor('special_links_versions');
- $c = $this->con->openCursor('books');
-
- if (is_string($links)) {
- $links = json_encode(json_decode($links, false));
- }
- if (is_string($rulers)) {
- $rulers = json_encode(json_decode($rulers, false));
- }
-
-
- $links = wsLinks::encryptLinks(json_decode($links));
-
-
- if (is_array($links)) {
- $links = json_encode($links);
- }
- if (is_array($rulers)) {
- $rulers = json_encode($rulers);
- }
-
- $c1->links = $c->specialLinks = $links;
- $c1->rulers = $c->specialRulers = $rulers;
- $c1->update = $c->changedate = TIME;
- $c1->book_id = $book_id;
- $c->update('WHERE book_id=\'' . $this->con->escape($book_id) . '\'');
- try {
- $c1->insert();
- } catch (Exception $e) {
- try {
- $c1->update('WHERE book_id=\'' . $this->con->escape($book_id) . '\' AND `update`=' . TIME);
- } catch (Exception $e) {
-
- }
- }
+// $c1 = $this->con->openCursor('special_links_versions');
+// $c = $this->con->openCursor('books');
+//
+// if (is_string($links)) {
+// $links = json_encode(json_decode($links, false));
+// }
+// if (is_string($rulers)) {
+// $rulers = json_encode(json_decode($rulers, false));
+// }
+//
+//
+// $links = wsLinks::encryptLinks(json_decode($links));
+//
+//
+// if (is_array($links)) {
+// $links = json_encode($links);
+// }
+// if (is_array($rulers)) {
+// $rulers = json_encode($rulers);
+// }
+//
+// $c1->links = $c->specialLinks = $links;
+// $c1->rulers = $c->specialRulers = $rulers;
+// $c1->update = $c->changedate = TIME;
+// $c1->book_id = $book_id;
+// $c->update('WHERE book_id=\'' . $this->con->escape($book_id) . '\'');
+// try {
+// $c1->insert();
+// } catch (Exception $e) {
+// try {
+// $c1->update('WHERE book_id=\'' . $this->con->escape($book_id) . '\' AND `update`=' . TIME);
+// } catch (Exception $e) {
+//
+// }
+// }
}
public function setTheme($book_id, $theme)
public function setFluidbookLinksFromCSV($book_id)
{
+ // New way
+ wsLinks::addLinksFromPDF($book_id);
+
+ // Old way
$daoBook = new wsDAOBook($this->con);
$pages = $daoBook->getPagesOfBook($book_id);
public function restoreLinksVersion($book_id, $update, $user = 0)
{
+ $comments = 'Restore links from ' . date('Y-m-d H:i:s', $update);
+
+ // New way
+ wsLinks::getLinksAndRulersFromFile($book_id, $links, $rulers, $update);
+ wsLinks::saveLinksInFile($book_id, $user, $comments, $links, $rulers, [], []);
+
+ // OLD Way
wsLinks::getLinksAndRulers($book_id, $links, $rulers, $update);
- $this->setLinksAndRulers($book_id, json_encode($links), json_encode($rulers), 'Restore links from ' . date('Y-m-d H:i:s', $update), $user);
+ $this->setLinksAndRulers($book_id, json_encode($links), json_encode($rulers), $comments, $user);
$r = $this->con->select('SELECT * FROM special_links_versions WHERE `update`=' . $update . ' AND book_id=\'' . $this->con->escape($book_id) . '\'');
if ($r->count()) {
wsLinks::setDocumentLinks($document_id, json_encode($links), json_encode(array()), 0, 'Links imported from PDF', TIME);
+
return implode("\n", $log);
}
}
continue;
}
+
+ if (!isset($pages[$page])) {
+ continue;
+ }
+
$infos = $pages[$page];
$doc_id = $infos['document_id'];
$doc_page = $infos['document_page'];
return wsLinks::getLinksAndRulers($book_id, $links, $rulers, $time);
}
+ public function getLinksAndRulersFromFile($book_id, &$links, &$rulers, $time = 'latest')
+ {
+ return wsLinks::getLinksAndRulersFromFile($book_id, $links, $rulers, $time);
+ }
+
public function getLinksVersions($book_id)
{
$link['rot'] = 0;
}
$links[] = $link;
+ $i++;
}
}
if (isset($trulers[$infos['document_id']][$infos['document_page']])) {
}
}
}
+
}
$daoBook = new wsDAOBook($core->con);
$links = array_merge($links, $book->specialLinks);
}
+ public static function getLinksAndRulersFromFile($book_id, &$links, &$rulers, $time = 'latest')
+ {
+ if (null === $time) {
+ $time = 'latest';
+ }
+ $dir = self::getLinksDir($book_id);
+
+ $file = $dir . '/' . $time . '.links.gz';
+ if ($time === 'latest' && !file_exists($file)) {
+ $versions = wsLinks::getLinksVersions($book_id);
+ foreach ($versions as $version => $m) {
+ copy($dir . '/' . $version . '.links.gz', $dir . '/latest.links.gz');
+ copy($dir . '/' . $version . '.meta.gz', $dir . '/latest.meta.gz');
+ break;
+ }
+ }
+ if (!file_exists($file)) {
+ $links = [];
+ $rulers = [];
+ return;
+ }
+
+ $r = json_decode(gzdecode(file_get_contents($file)), true);
+ $links = $r['links'];
+ $rulers = $r['rulers'];
+ }
+
public static function getLinksFromExcel($xls, &$links, &$rulers)
{
$s = $xls->setActiveSheetIndexByName('Links');
$attrs = ['image_rollover'];
foreach ($attrs as $attr) {
+ if (!isset($link->$attr)) {
+ continue;
+ }
$link->$attr = trim($link->$attr);
if (strpos($link->$attr, '///') === 0 || $link->$attr == '') {
continue;
}
return $res;
}
+
+ public static function saveLinksInFile($book_id, $user_id, $comments, $links, $rulers = [], $specialLinks = [], $specialRulers = [])
+ {
+ $lr = wsLinks::mergeLinksAndRulers($links, $rulers, $specialLinks, $specialRulers);
+ $meta = ['links' => count($lr['links']), 'rulers' => count($lr['rulers']), 'comments' => $comments, 'user' => $user_id];
+ $base = self::getLinksDir($book_id) . '/' . TIME;
+ $latestLinks = self::getLinksDir($book_id) . '/latest.links.gz';
+ $latestMeta = self::getLinksDir($book_id) . '/latest.meta.gz';
+ file_put_contents($base . '.meta.gz', gzencode(json_encode($meta)));
+ file_put_contents($base . '.links.gz', gzencode(json_encode($lr)));
+ copy($base . '.links.gz', $latestLinks);
+ copy($base . '.meta.gz', $latestMeta);
+ }
+
+
+ public static function getLinksDir($book_id)
+ {
+ $dir = WS_BOOKS . '/links/' . $book_id;
+ if (!file_exists($dir)) {
+ mkdir($dir, 0777, true);
+ }
+ return $dir;
+ }
+
+ public static function getLinksVersions($book_id, $withLinks = false)
+ {
+ $dir = self::getLinksDir($book_id);
+ $dr = opendir($dir);
+ $updates = [];
+ while ($f = readdir($dr)) {
+ if ($f === '.' || $f === '..') {
+ continue;
+ }
+ $e = explode('.', $f, 2);
+ if ($e[1] !== 'meta.gz' || $e[0] === 'latest') {
+ continue;
+ }
+
+ $updates[$e[0]] = self::getMeta($book_id, $e[0]);
+ }
+ krsort($updates);
+
+ return $updates;
+ }
+
+ public static function getMeta($book_id, $update = 'latest')
+ {
+ return json_decode(gzdecode(file_get_contents(self::getLinksDir($book_id) . '/' . $update . '.meta.gz')), true);
+ }
+
+ public static function mergeLinksAndRulers($links, $rulers, $specialLinks, $specialRulers)
+ {
+ $finalLinks = [];
+ $l = array_merge(self::_getAsArray($links), self::_getAsArray($specialLinks));
+ foreach ($l as $k => $item) {
+ $item['id'] = $k + 1;
+ if (!isset($item['to'])) {
+ $item['to'] = '';
+ }
+ $finalLinks[] = $item;
+ }
+
+ return ['links' => self::encryptLinks($finalLinks), 'rulers' => array_merge(self::_getAsArray($rulers), self::_getAsArray($specialRulers))];
+ }
+
+ protected static function _getAsArray($v)
+ {
+ if (is_array($v)) {
+ return $v;
+ }
+ return json_decode($v, true);
+ }
+
+ public static function addLinksFromPDF($book_id)
+ {
+ global $core;
+
+ $daoBook = new wsDAOBook($core->con);
+ $pages = $daoBook->getPagesOfBook($book_id);
+
+ $booleans = array('video_loop', 'video_auto_start', 'video_controls', 'video_sound_on');
+
+ $links = [];
+
+ foreach ($pages as $page => $info) {
+ $links[$page] = [];
+
+ $csv = wsDocument::getDir($info['document_id']) . '/p' . $info['document_page'] . '.csv';
+ if (!file_exists($csv) && file_exists($csv . '.gz')) {
+ $csv = 'compress.zlib://' . $csv . '.gz';
+ } elseif (!file_exists($csv)) {
+ continue;
+ }
+
+ $newformat = (filemtime($csv) > 1363685416);
+
+ $fp = fopen($csv, 'rb');
+
+ while (true) {
+ $line = fgetcsv($fp, 512, ';', '"');
+ // End of file
+ if (!$line) {
+ break;
+ }
+ // Commentaire || ligne vide
+ if (substr($line[0], 0, 1) == '#' || is_null($line[0])) {
+ continue;
+ }
+ $link = array();
+ if ($newformat) {
+ $cols = array('page' => '', 'left' => '', 'top' => '', 'width' => '', 'height' => '', 'type' => '', 'to' => '', 'target' => '_blank', 'video_loop' => true, 'video_auto_start' => true, 'video_controls' => true, 'video_sound_on' => true, 'infobulle' => '', 'numerotation' => 'physical');
+ } else {
+ $cols = array('page' => '', 'type' => '', 'to' => '', 'left' => '', 'top' => '', 'width' => '', 'height' => '', 'target' => '_blank', 'video_loop' => true, 'video_auto_start' => true, 'video_controls' => true, 'video_sound_on' => true, 'infobulle' => '', 'numerotation' => 'physical');
+ }
+ $k = 0;
+ foreach ($cols as $col => $default) {
+ if (isset($line[$k])) {
+ if (in_array($k, $booleans)) {
+ $link[$col] = ($line[$k] == '1');
+ } else {
+ $link[$col] = utf8_encode($line[$k]);
+ }
+ } else {
+ $link[$col] = $default;
+ }
+ $k++;
+ }
+ $link['page'] = $page;
+ $links[$page][] = $link;
+ }
+
+ }
+
+ self::saveLinksInFile($book_id, $core->user->utilisateur_id, 'Links imported from PDF', $links, []);
+ }
}
\ No newline at end of file