From 52bc03f8a4f0a51c2068d2048e3c7f1a46057f6f Mon Sep 17 00:00:00 2001 From: "vincent@cubedesigners.com" Date: Wed, 11 May 2011 09:09:53 +0000 Subject: [PATCH] --- inc/commons/class.common.core.php | 175 +++++++++++++-------------- inc/ws/DAO/class.ws.dao.book.php | 10 ++ inc/ws/DAO/class.ws.dao.document.php | 136 ++++++++++----------- inc/ws/Metier/class.ws.book.php | 35 ++---- 4 files changed, 169 insertions(+), 187 deletions(-) diff --git a/inc/commons/class.common.core.php b/inc/commons/class.common.core.php index b655155c4..c0e927ffa 100644 --- a/inc/commons/class.common.core.php +++ b/inc/commons/class.common.core.php @@ -1,20 +1,22 @@ dbSync(); cubeLang::set(); try { $this->authentifie(); - } - catch(Exception $e) { + } catch (Exception $e) { + } if ($this->user) { @@ -61,8 +63,7 @@ class commonCore extends cubeCore { * * @return */ - protected function authentifie() - { + protected function authentifie() { // On regarde si user_email et user_password ont été postées // Si c'est le cas, on les copie dans la session $_SESSION['errorLogin'] = false; @@ -100,8 +101,7 @@ class commonCore extends cubeCore { * * @return */ - public function dbSync() - { + public function dbSync() { $cache = ROOT . '/cache/DB_SYNC'; $todo = ROOT . '/cache/DB_TODO'; if (!file_exists($cache)) { @@ -366,6 +366,8 @@ class commonCore extends cubeCore { $db->books->chapters('text', 0, false); $db->books->extras('text', 0, false); $db->books->traductions('text', 0, false); + $db->books->specialLinks('text', 0, false); + $db->books->specialRulers('text', 0, false); $db->books->date('integer', 0, false); $db->books->numerotation('text', 0, false); $db->books->changedate('integer', 0, false); @@ -433,8 +435,7 @@ class commonCore extends cubeCore { try { $dbi = new CubeDbStruct($this->con); $dbi->synchronize($db); - } - catch(Exception $e) { + } catch (Exception $e) { fb($e); return; } @@ -442,133 +443,129 @@ class commonCore extends cubeCore { $this->views->createView('equipiers', 'SELECT * FROM utilisateurs WHERE grade>=1'); $this->views->createView('gerants', 'SELECT * FROM utilisateurs WHERE grade=2'); $this->views->createView('impayes_entreprises', 'SELECT SUM(total_ht) AS impaye, u.entreprise AS entreprise ' - . 'FROM utilisateurs u LEFT JOIN projets p ON u.utilisateur_id=p.client LEFT JOIN factures f ON f.projet=p.projet_id ' - . 'WHERE f.status=1 GROUP BY u.entreprise'); + . 'FROM utilisateurs u LEFT JOIN projets p ON u.utilisateur_id=p.client LEFT JOIN factures f ON f.projet=p.projet_id ' + . 'WHERE f.status=1 GROUP BY u.entreprise'); $this->views->createView('entreprises_inter', 'SELECT e.*,' - . 'SUM(f.total_ht) AS ca ' - . 'FROM entreprises e LEFT JOIN utilisateurs u ON u.entreprise=e.entreprise_id AND grade=0 ' - . 'LEFT JOIN projets p ON p.client=u.utilisateur_id ' - . 'LEFT JOIN factures f ON f.projet=p.projet_id AND f.status IN(1,2) ' - . 'GROUP BY e.entreprise_id'); + . 'SUM(f.total_ht) AS ca ' + . 'FROM entreprises e LEFT JOIN utilisateurs u ON u.entreprise=e.entreprise_id AND grade=0 ' + . 'LEFT JOIN projets p ON p.client=u.utilisateur_id ' + . 'LEFT JOIN factures f ON f.projet=p.projet_id AND f.status IN(1,2) ' + . 'GROUP BY e.entreprise_id'); $this->views->createView('entreprises_vue', 'SELECT e.*,i.impaye AS impaye ' - . 'FROM entreprises_inter e LEFT JOIN impayes_entreprises i ON e.entreprise_id=i.entreprise'); + . 'FROM entreprises_inter e LEFT JOIN impayes_entreprises i ON e.entreprise_id=i.entreprise'); $this->views->createView('entreprises_ws', 'SELECT e.*, a.prenom AS administrateur, r.nom AS revendeur,a.utilisateur_id AS ws_super_admin ' - . 'FROM entreprises e ' - . 'LEFT JOIN ws_entreprises_tree ri ON ri.entreprise_id=e.entreprise_id ' - . 'LEFT JOIN utilisateurs ur ON e.ws_admin=ur.utilisateur_id ' - . 'LEFT JOIN entreprises r ON ur.entreprise=r.entreprise_id ' - . 'LEFT JOIN utilisateurs a ON ri.administrateur_id=a.utilisateur_id '); + . 'FROM entreprises e ' + . 'LEFT JOIN ws_entreprises_tree ri ON ri.entreprise_id=e.entreprise_id ' + . 'LEFT JOIN utilisateurs ur ON e.ws_admin=ur.utilisateur_id ' + . 'LEFT JOIN entreprises r ON ur.entreprise=r.entreprise_id ' + . 'LEFT JOIN utilisateurs a ON ri.administrateur_id=a.utilisateur_id '); $this->views->createView('clients_entreprise', 'SELECT u.*,e.nom AS rs, e.adresse_facturation AS adresse_facturation ' - . 'FROM entreprises e LEFT JOIN utilisateurs u ON u.entreprise=e.entreprise_id AND u.grade=0'); + . 'FROM entreprises e LEFT JOIN utilisateurs u ON u.entreprise=e.entreprise_id AND u.grade=0'); $this->views->createView('utilisateurs_entreprise', 'SELECT u.*,e.nom AS rs, e.adresse_facturation AS adresse_facturation, ' - . 'e.ws_grade, e.ws_admin, e.ws_signatures AS ws_signatures ' - . 'FROM entreprises e LEFT JOIN utilisateurs u ON u.entreprise=e.entreprise_id'); + . 'e.ws_grade, e.ws_admin, e.ws_signatures AS ws_signatures ' + . 'FROM entreprises e LEFT JOIN utilisateurs u ON u.entreprise=e.entreprise_id'); $this->views->createView('clients', 'SELECT u.*,e.nom AS rs, e.adresse_facturation AS adresse_facturation, i.impaye, ' - . 'SUM(f.total_ht) AS ca ' - . 'FROM entreprises e LEFT JOIN impayes_entreprises i ON e.entreprise_id=i.entreprise LEFT JOIN utilisateurs u ON u.entreprise=e.entreprise_id AND u.grade=0 LEFT JOIN projets p ON p.client=u.utilisateur_id LEFT JOIN factures f ON f.projet=p.projet_id AND f.status IN(1,2) ' - . 'GROUP BY u.utilisateur_id', 'TEMPTABLE'); + . 'SUM(f.total_ht) AS ca ' + . 'FROM entreprises e LEFT JOIN impayes_entreprises i ON e.entreprise_id=i.entreprise LEFT JOIN utilisateurs u ON u.entreprise=e.entreprise_id AND u.grade=0 LEFT JOIN projets p ON p.client=u.utilisateur_id LEFT JOIN factures f ON f.projet=p.projet_id AND f.status IN(1,2) ' + . 'GROUP BY u.utilisateur_id', 'TEMPTABLE'); $this->views->createView('taches_vue', 'SELECT taches.tache_id,taches.nom,taches.categorie,taches.type,taches.budget,taches.projet,taches.taux_journalier, ' - . '(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 ' - . 'FROM taches LEFT JOIN timereport ON taches.tache_id=timereport.tache_id ' - . 'GROUP BY taches.tache_id'); + . '(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 ' + . 'FROM taches LEFT JOIN timereport ON taches.tache_id=timereport.tache_id ' + . 'GROUP BY taches.tache_id'); $this->views->createView('taches_projet', 'SELECT projet, ' - . 'SUM(jours_prevus) AS jours_prevus,SUM(budget) AS budget,' - . 'SUM(jours_consommes) AS jours_consommes, (SUM(jours_consommes)/SUM(jours_prevus))*100 AS progression ' - . 'FROM taches_vue GROUP BY projet'); + . 'SUM(jours_prevus) AS jours_prevus,SUM(budget) AS budget,' + . 'SUM(jours_consommes) AS jours_consommes, (SUM(jours_consommes)/SUM(jours_prevus))*100 AS progression ' + . 'FROM taches_vue GROUP BY projet'); $this->views->createView('devis_vue', 'SELECT devis.devis_id,devis.nom,devis.lignes,devis.status,devis.total_ht,devis.date_creation,devis.email,clients.utilisateur_id AS client_id,clients.rs AS client,equipiers.prenom AS createur,equipiers.utilisateur_id AS createur_id,devis.adresse ' - . 'FROM devis,clients,equipiers ' - . 'WHERE devis.client=clients.utilisateur_id AND devis.createur=equipiers.utilisateur_id'); + . 'FROM devis,clients,equipiers ' + . 'WHERE devis.client=clients.utilisateur_id AND devis.createur=equipiers.utilisateur_id'); $this->views->createView('factures_payees', 'SELECT * FROM factures WHERE status=2'); $this->views->createView('factures_valides', 'SELECT * FROM factures WHERE status IN(1,2)'); $this->views->createView('projets_inter', 'SELECT projets.projet_id,projets.nom,projets.status,projets.date_debut,projets.date_fin,projets.date_creation,projets.deadline,projets.devis,' - . 'YEAR(FROM_UNIXTIME(projets.date_debut)) AS annee_debut,' - . 'IF(date_fin=0,YEAR(NOW()),YEAR(FROM_UNIXTIME(projets.date_fin))) AS annee_fin,' - . 'clients.rs AS client,equipiers.prenom AS chef,equipiers.utilisateur_id AS chef_id,clients.utilisateur_id AS client_id ' - . 'FROM projets JOIN clients_entreprise clients ON projets.client=clients.utilisateur_id ' - . 'JOIN equipiers ON projets.chef=equipiers.utilisateur_id'); + . 'YEAR(FROM_UNIXTIME(projets.date_debut)) AS annee_debut,' + . 'IF(date_fin=0,YEAR(NOW()),YEAR(FROM_UNIXTIME(projets.date_fin))) AS annee_fin,' + . 'clients.rs AS client,equipiers.prenom AS chef,equipiers.utilisateur_id AS chef_id,clients.utilisateur_id AS client_id ' + . 'FROM projets JOIN clients_entreprise clients ON projets.client=clients.utilisateur_id ' + . 'JOIN equipiers ON projets.chef=equipiers.utilisateur_id'); $this->views->createView('projets_facturation', 'SELECT projet,SUM(IF(status IN(1,2),total_ht,0)) AS montant_facture, SUM(IF(status=2,total_ht,0)) AS montant_paye FROM factures GROUP BY projet'); $this->views->createView('projets_vue', 'SELECT p.*,f.montant_facture,f.montant_paye, ' - . 't.jours_prevus,t.jours_consommes,t.progression,t.budget AS budget, ' - . 'IF(t.budget>0,f.montant_paye/t.budget,1) AS rapport_paiement, ' - . 'IF(t.budget>0,f.montant_facture/t.budget,1) AS rapport_facturation ' - . 'FROM projets_inter p ' - . 'LEFT JOIN projets_facturation f ON f.projet=p.projet_id ' - . 'LEFT JOIN taches_projet t ON p.projet_id=t.projet'); + . 't.jours_prevus,t.jours_consommes,t.progression,t.budget AS budget, ' + . 'IF(t.budget>0,f.montant_paye/t.budget,1) AS rapport_paiement, ' + . 'IF(t.budget>0,f.montant_facture/t.budget,1) AS rapport_facturation ' + . 'FROM projets_inter p ' + . 'LEFT JOIN projets_facturation f ON f.projet=p.projet_id ' + . 'LEFT JOIN taches_projet t ON p.projet_id=t.projet'); $this->views->createView('factures_vue', 'SELECT factures.facture_id,factures.nom,factures.lignes,factures.status,factures.total_ht,factures.date_creation,factures.texte_complementaire,factures.informations_paiement,factures.date_paiement,factures.adresse,factures.avoir,' - . 'projets.projet_id AS projet_id,projets.nom AS projet,clients.utilisateur_id AS client_id,clients.rs as client,equipiers.prenom AS createur,equipiers.utilisateur_id AS createur_id ' - . 'FROM factures,projets,equipiers,clients ' - . 'WHERE factures.projet=projets.projet_id AND clients.utilisateur_id=projets.client AND factures.createur=equipiers.utilisateur_id AND (factures.facture_id>=0 OR factures.status=1) '); + . 'projets.projet_id AS projet_id,projets.nom AS projet,clients.utilisateur_id AS client_id,clients.rs as client,equipiers.prenom AS createur,equipiers.utilisateur_id AS createur_id ' + . 'FROM factures,projets,equipiers,clients ' + . 'WHERE factures.projet=projets.projet_id AND clients.utilisateur_id=projets.client AND factures.createur=equipiers.utilisateur_id AND (factures.facture_id>=0 OR factures.status=1) '); $this->views->createView('projets_timereport', 'SELECT * FROM projets_vue WHERE status=0'); $this->views->createView('order_timereport', 'SELECT utilisateur_id,projet AS projet_id,MAX(date) AS derniere_activite FROM timereport,taches,projets WHERE taches.tache_id=timereport.tache_id AND taches.projet=projets.projet_id AND projets.status=0 GROUP BY utilisateur_id,taches.projet ORDER BY utilisateur_id ASC,MAX(date) DESC'); $this->views->createView('ca', 'SELECT SUM(total_ht) AS ca, YEAR(FROM_UNIXTIME(date_creation)) annee FROM factures WHERE status IN(1,2) GROUP BY annee'); $this->views->createView('ftpaccess', 'SELECT email AS userid,password AS passwd,utilisateur_id AS uid,' - . '\'1000\' AS gid,CONCAT(\'' . FTPROOT . '\',utilisateur_id) AS homedir, \'/bin/false\' AS shell ' - . 'FROM utilisateurs WHERE grade=0 ' - . 'UNION ' - . 'SELECT email AS userid,ws_password AS passwd,utilisateur_id AS uid,' - . '\'1000\' AS gid,CONCAT(\'' . FTPROOT . '\',utilisateur_id) AS homedir, \'/bin/false\' AS shell ' - . 'FROM utilisateurs WHERE grade=0 AND ws_password!=\'\''); + . '\'1000\' AS gid,CONCAT(\'' . FTPROOT . '\',utilisateur_id) AS homedir, \'/bin/false\' AS shell ' + . 'FROM utilisateurs WHERE grade=0 ' + . 'UNION ' + . 'SELECT email AS userid,ws_password AS passwd,utilisateur_id AS uid,' + . '\'1000\' AS gid,CONCAT(\'' . FTPROOT . '\',utilisateur_id) AS homedir, \'/bin/false\' AS shell ' + . 'FROM utilisateurs WHERE grade=0 AND ws_password!=\'\''); $this->views->createView('chiffres_categories', 'SELECT p.annee_fin AS annee, t.categorie, SUM(t.budget) AS ca ' - . 'FROM projets_vue p, taches_vue t ' - . 'WHERE t.projet=p.projet_id ' - . 'GROUP BY t.categorie,p.annee_fin'); + . 'FROM projets_vue p, taches_vue t ' + . 'WHERE t.projet=p.projet_id ' + . 'GROUP BY t.categorie,p.annee_fin'); $this->views->createView('temps_categories', 'SELECT p.annee_fin AS annee, t.categorie, SUM(t.jours_consommes) AS jours_consommes,SUM(t.jours_prevus) AS jours_prevus ' - . 'FROM projets_vue p, taches_vue t ' - . 'WHERE t.projet=p.projet_id ' - . 'GROUP BY t.categorie,p.annee_fin'); + . 'FROM projets_vue p, taches_vue t ' + . 'WHERE t.projet=p.projet_id ' + . 'GROUP BY t.categorie,p.annee_fin'); $this->views->createView('books_vue', 'SELECT b.*,b.proprietaire AS proprietaire_id,' - . 'CONCAT(c.rs,\' (\',c.prenom,\' \',c.nom,\')\') AS proprietaire_nom,' - . 'CONCAT(c.prenom,\' \',c.nom) AS proprietaire_utilisateur,c.ws_admin,' - . 'f.rs AS facturable, t.facturable_id AS facturable_id, ta.projet AS projet,' - . 'IF(c.ws_grade>=5,c.utilisateur_id,a.utilisateur_id) AS super_admin ' - . 'FROM books b ' - . 'LEFT JOIN utilisateurs_entreprise c ON b.proprietaire=c.utilisateur_id ' - . 'LEFT JOIN ws_users_tree t ON t.utilisateur_id=c.utilisateur_id ' - . 'LEFT JOIN utilisateurs a ON t.administrateur_id=a.utilisateur_id ' - . 'LEFT JOIN utilisateurs_entreprise f ON t.facturable_id=f.utilisateur_id ' - . 'LEFT JOIN taches ta ON ta.tache_id=b.tache' , - 'TEMPTABLE'); + . 'CONCAT(c.rs,\' (\',c.prenom,\' \',c.nom,\')\') AS proprietaire_nom,' + . 'CONCAT(c.prenom,\' \',c.nom) AS proprietaire_utilisateur,c.ws_admin,' + . 'f.rs AS facturable, t.facturable_id AS facturable_id, ta.projet AS projet,' + . 'IF(c.ws_grade>=5,c.utilisateur_id,a.utilisateur_id) AS super_admin ' + . 'FROM books b ' + . 'LEFT JOIN utilisateurs_entreprise c ON b.proprietaire=c.utilisateur_id ' + . 'LEFT JOIN ws_users_tree t ON t.utilisateur_id=c.utilisateur_id ' + . 'LEFT JOIN utilisateurs a ON t.administrateur_id=a.utilisateur_id ' + . 'LEFT JOIN utilisateurs_entreprise f ON t.facturable_id=f.utilisateur_id ' + . 'LEFT JOIN taches ta ON ta.tache_id=b.tache', 'TEMPTABLE'); $this->views->createView('themes_books_nb', 'SELECT theme,COUNT(*) AS nb FROM books GROUP BY theme'); $this->views->createView('themes_vue', 'SELECT t.*, b.nb as nbBooks, CONCAT(e.prenom,\' \',e.nom,\' (\',e.rs,\')\') AS proprietaire_nom ' - . 'FROM themes t ' - . 'LEFT JOIN themes_books_nb b ON t.theme_id=b.theme ' - . 'LEFT JOIN utilisateurs_entreprise e ON t.proprietaire=e.utilisateur_id'); + . 'FROM themes t ' + . 'LEFT JOIN themes_books_nb b ON t.theme_id=b.theme ' + . 'LEFT JOIN utilisateurs_entreprise e ON t.proprietaire=e.utilisateur_id'); $this->views->createView('demandes_vue', 'SELECT d.*, CONCAT(c.rs,\' (\',c.prenom,\' \',c.nom,\')\') AS utilisateur_nom, CONCAT(r.rs,\' (\',r.prenom,\' \',r.nom,\')\') AS revendeur_nom, c.entreprise AS entreprise, a.prenom AS administrateur_nom ' - . 'FROM demandes d ' - . 'LEFT JOIN utilisateurs_entreprise r ON d.revendeur=r.utilisateur_id ' - . 'LEFT JOIN utilisateurs_entreprise c ON d.utilisateur=c.utilisateur_id ' - . 'LEFT JOIN utilisateurs a ON d.administrateur=a.utilisateur_id'); + . 'FROM demandes d ' + . 'LEFT JOIN utilisateurs_entreprise r ON d.revendeur=r.utilisateur_id ' + . 'LEFT JOIN utilisateurs_entreprise c ON d.utilisateur=c.utilisateur_id ' + . 'LEFT JOIN utilisateurs a ON d.administrateur=a.utilisateur_id'); // cubeDb::mysqlConvert($this->con); touch($cache); } - public function sauvePreferencesUtilisateur() - { + public function sauvePreferencesUtilisateur() { $dao = new commonDAOUtilisateur($this->con); $dao->sauvePreferences($this->user); } - public function refreshWSUsersTree() - { + public function refreshWSUsersTree() { $t = new wsUsersTree($this->con); $t->refreshWSUsersTree(); } - public function loadExtranetClasses() - { + public function loadExtranetClasses() { global $__autoload; require_once(dirname(__FILE__) . '/../extranet/Metier/_common.php'); require_once(dirname(__FILE__) . '/../extranet/Controlleur/_common.php'); require_once(dirname(__FILE__) . '/../extranet/DAO/_common.php'); } - public function loadWSClasses() - { + public function loadWSClasses() { global $__autoload; require_once(dirname(__FILE__) . '/../ws/Metier/_common.php'); require_once(dirname(__FILE__) . '/../ws/Controlleur/_common.php'); require_once(dirname(__FILE__) . '/../ws/DAO/_common.php'); } + } ?> \ No newline at end of file diff --git a/inc/ws/DAO/class.ws.dao.book.php b/inc/ws/DAO/class.ws.dao.book.php index 051dfc85a..0900f80ae 100644 --- a/inc/ws/DAO/class.ws.dao.book.php +++ b/inc/ws/DAO/class.ws.dao.book.php @@ -25,6 +25,8 @@ class wsDAOBook extends commonDAO { $book->pages = array(); $book->chapters = $r->chapters; $book->traductions = $r->traductions; + $book->specialLinks = $r->specialLinks; + $book->specialRulers = $r->specialRulers; $book->parametres = $r->parametres; $book->extras = $r->extras; $book->numerotation = $r->numerotation; @@ -329,6 +331,14 @@ class wsDAOBook extends commonDAO { $c->update('WHERE book_id=\'' . $this->con->escape($book_id) . '\''); } + public function setSpecialLinksAndRulers($book_id, $links, $rulers) { + $c = $this->con->openCursor('books'); + $c->specialLinks = json_encode(json_decode($links, false)); + $c->specialRulers = json_encode(json_decode($rulers, false)); + $c->changedate = TIME; + $c->update('WHERE book_id=\'' . $this->con->escape($book_id) . '\''); + } + public function setTheme($book_id, $theme) { $c = $this->con->openCursor('books'); $c->theme = $theme; diff --git a/inc/ws/DAO/class.ws.dao.document.php b/inc/ws/DAO/class.ws.dao.document.php index 2eba9d29b..af39e9976 100644 --- a/inc/ws/DAO/class.ws.dao.document.php +++ b/inc/ws/DAO/class.ws.dao.document.php @@ -1,15 +1,16 @@ $k = $r->$k; } - foreach(self::$complex as $k) { + foreach (self::$complex as $k) { if ($r->$k != '') { $document->$k = unserialize($r->$k); } @@ -18,29 +19,26 @@ class wsDAODocument extends commonDAO { return $document; } - public function setFluidbookLinksFromCSV($book_id) - { + public function setFluidbookLinksFromCSV($book_id) { $daoBook = new wsDAOBook($this->con); $pages = $daoBook->getPagesOfBook($book_id); - foreach($pages as $page => $infos) { + foreach ($pages as $page => $infos) { $docs[] = $infos['document_id']; } $docs = array_unique($docs); - foreach($docs as $document_id) { + foreach ($docs as $document_id) { $this->putLinksFromCSV($document_id); } } - public function restoreLinksVersion($book_id, $update) - { + public function restoreLinksVersion($book_id, $update) { $sql = 'INSERT INTO document_links_versions SELECT document_id,links,rulers,' . TIME . ' FROM document_links_versions WHERE `update`=' . $update . ' AND document_id IN (SELECT document_id FROM book_pages WHERE book_id=' . $book_id . ')'; $this->con->execute($sql); } - public function putLinksFromCSV($document_id) - { + public function putLinksFromCSV($document_id) { $log = array('Copie des liens du PDF vers la base de données'); $document = $this->selectById($document_id); @@ -51,7 +49,7 @@ class wsDAODocument extends commonDAO { $c = $this->con->openCursor('document_links_versions'); $c->document_id = $document->document_id; - for($page = 1;$page <= $document->generalInfos['pages'];$page++) { + for ($page = 1; $page <= $document->generalInfos['pages']; $page++) { $links[$page] = array(); $csv = WS_DOCS . '/' . $document->document_id . '/p' . $page . '.csv'; @@ -78,7 +76,7 @@ class wsDAODocument extends commonDAO { $link = array(); $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) { + foreach ($cols as $col => $default) { if (isset($line[$k])) { if (in_array($k, $booleans)) { $link[$col] = ($line[$k] == '1'); @@ -104,8 +102,7 @@ class wsDAODocument extends commonDAO { return implode("\n", $log); } - public function setLinksAndRulers($book_id, $links, $rulers) - { + public function setLinksAndRulers($book_id, $links, $rulers) { $daoBook = new wsDAOBook($this->con); $pages = $daoBook->getPagesOfBook($book_id); @@ -114,13 +111,13 @@ class wsDAODocument extends commonDAO { $t = array(); - foreach($links as $link) { + foreach ($links as $link) { if (!isset($t[$link->page])) { $t[$link->page] = array('links' => array(), 'rulers' => array()); } $t[$link->page]['links'][] = $link; } - foreach($rulers as $ruler) { + foreach ($rulers as $ruler) { if (!isset($t[$ruler->page])) { $t[$ruler->page] = array('links' => array(), 'rulers' => array()); } @@ -130,7 +127,7 @@ class wsDAODocument extends commonDAO { $links = array(); $rulers = array(); - foreach($t as $page => $tt) { + foreach ($t as $page => $tt) { $infos = $pages[$page]; $doc_id = $infos['document_id']; $doc_page = $infos['document_page']; @@ -144,11 +141,11 @@ class wsDAODocument extends commonDAO { $rulers[$doc_id][$doc_page] = array(); } - foreach($tt['links'] as $link) { + foreach ($tt['links'] as $link) { $links[$doc_id][$doc_page][] = $link; } - foreach($tt['rulers'] as $ruler) { + foreach ($tt['rulers'] as $ruler) { $rulers[$doc_id][$doc_page][] = $ruler; } } @@ -156,7 +153,7 @@ class wsDAODocument extends commonDAO { $c = $this->con->openCursor('document_links_versions'); $c->update = TIME; - foreach($links as $document_id => $dummy) { + foreach ($links as $document_id => $dummy) { $c->document_id = $document_id; $c->links = json_encode($links[$document_id]); $c->rulers = json_encode($rulers[$document_id]); @@ -168,18 +165,16 @@ class wsDAODocument extends commonDAO { $c->update('WHERE book_id=\'' . $this->con->escape($book_id) . '\''); } - public function copyLinks($from, $to) - { + public function copyLinks($from, $to) { $sql = 'REPLACE INTO document_links_versions (`document_id`,`links`,`rulers`,`update`) ' - . 'SELECT \'' . $to . '\',`links`,`rulers`,`update` FROM document_links_versions WHERE document_id=\'' . $from . '\''; + . 'SELECT \'' . $to . '\',`links`,`rulers`,`update` FROM document_links_versions WHERE document_id=\'' . $from . '\''; fb($sql); $this->con->execute($sql); } - public function setLinksFromOldFluidbook($book_id) - { + public function setLinksFromOldFluidbook($book_id) { $daoBook = new wsDAOBook($this->con); $pages = $daoBook->getPagesOfBook($book_id); $book = $daoBook->selectById($book_id); @@ -190,15 +185,15 @@ class wsDAODocument extends commonDAO { $res = array(); $lpages = array(); - foreach($links as $l) { - if ((string)$l->page == '') { + foreach ($links as $l) { + if ((string) $l->page == '') { continue; } - $left = floatval((string)$l->startX); - $right = floatval((string)$l->endX); - $top = floatval((string)$l->startY); - $bottom = floatval((string)$l->endY); + $left = floatval((string) $l->startX); + $right = floatval((string) $l->endX); + $top = floatval((string) $l->startY); + $bottom = floatval((string) $l->endY); $lwidth = abs($right - $left); $lheight = abs($bottom - $top); @@ -207,7 +202,7 @@ class wsDAODocument extends commonDAO { $top = min($top, $bottom); $link = array(); - $link['page'] = (string)$l->page; + $link['page'] = (string) $l->page; $link['numerotation'] = false; $link['left'] = $left; $link['width'] = $lwidth; @@ -220,12 +215,12 @@ class wsDAODocument extends commonDAO { $link['height'] = $lheight; $link['infobulle'] = ''; $link['target'] = '_blank'; - $link['to'] = (string)$l->linkTo; - $link['type'] = intval((string)$l->linkType); - $link['video_loop'] = ((string)$l->loopFlag == '1'); + $link['to'] = (string) $l->linkTo; + $link['type'] = intval((string) $l->linkType); + $link['video_loop'] = ((string) $l->loopFlag == '1'); $link['video_auto_start'] = true; - $link['video_controls'] = ((string)$l->playerActive == '1'); - $link['video_sound_on'] = ((string)$l->soundOn == '1'); + $link['video_controls'] = ((string) $l->playerActive == '1'); + $link['video_sound_on'] = ((string) $l->soundOn == '1'); if ($link['type'] == '4' || $link['type'] == '6') { if (!stristr($link['to'], ':/')) { @@ -244,7 +239,7 @@ class wsDAODocument extends commonDAO { } $links = array(); - foreach($pages as $p => $infos) { + foreach ($pages as $p => $infos) { if (!isset($links[$infos['document_id']])) { $links[$infos['document_id']] = array(); } @@ -257,7 +252,7 @@ class wsDAODocument extends commonDAO { $c = $this->con->openCursor('document_links_versions'); $c->update = TIME; - foreach($links as $document_id => $l) { + foreach ($links as $document_id => $l) { $c->document_id = $infos['document_id']; $c->links = json_encode($l); @@ -270,12 +265,11 @@ class wsDAODocument extends commonDAO { $c->update('WHERE book_id=\'' . $this->con->escape($book_id) . '\''); } - public function getLinksAndRulers($book_id, &$links, &$rulers) - { + public function getLinksAndRulers($book_id, &$links, &$rulers) { $daoBook = new wsDAOBook($this->con); $pages = $daoBook->getPagesOfBook($book_id); - foreach($pages as $p => $infos) { + foreach ($pages as $p => $infos) { $documents[] = $infos['document_id']; } $documents = array_unique($documents); @@ -286,7 +280,7 @@ class wsDAODocument extends commonDAO { $links = array(); $rulers = array(); - foreach($documents as $d) { + foreach ($documents as $d) { $r = $this->con->select('SELECT * FROM document_links_versions WHERE document_id=' . $d . ' ORDER BY `update` DESC LIMIT 1'); if (mb_substr($r->links, 1, 1) == ':') { @@ -304,8 +298,8 @@ class wsDAODocument extends commonDAO { foreach ($pages as $p => $infos) { if (isset($tlinks[$infos['document_id']][$infos['document_page']])) { $l = $tlinks[$infos['document_id']][$infos['document_page']]; - foreach($l as $link) { - $link = (array)$link; + foreach ($l as $link) { + $link = (array) $link; $link['page'] = $p; $link['id'] = $i; $links[] = $link; @@ -313,16 +307,21 @@ class wsDAODocument extends commonDAO { } if (isset($trulers[$infos['document_id']][$infos['document_page']])) { $ru = $trulers[$infos['document_id']][$infos['document_page']]; - foreach($ru as $ruler) { + foreach ($ru as $ruler) { $ruler['page'] = $p; $rulers[] = $ruler; } } } + + $daoBook = new wsDAOBook($this->con); + $book = $daoBook->selectById($book_id); + + $rulers = array_merge($rulers, $book->specialRulers); + $links = array_merge($links, $book->specialLinks); } - public function getLinksVersions($book_id) - { + public function getLinksVersions($book_id) { $res = array(); $r = $this->con->select('SELECT * FROM document_links_versions WHERE document_id IN(SELECT document_id FROM book_pages WHERE book_id=\'' . $this->con->escape($book_id) . '\')'); while ($r->fetch()) { @@ -330,19 +329,18 @@ class wsDAODocument extends commonDAO { $res[$r->update] = array('links' => 0, 'rulers' => 0); } $ll = json_decode($r->links); - foreach($ll as $lll) { + foreach ($ll as $lll) { $res[$r->update]['links'] += count($lll); } $rr = json_decode($r->rulers); - foreach($rr as $rrr) { + foreach ($rr as $rrr) { $res[$r->update]['rulers'] += count($rrr); } } return $res; } - public function getNextId() - { + public function getNextId() { $r = $this->con->select('SELECT MAX(document_id) AS document_id FROM documents'); if ($r->document_id < 100000) { return 100000; @@ -350,26 +348,22 @@ class wsDAODocument extends commonDAO { return $r->document_id + 1; } - public function selectById($document_id) - { + public function selectById($document_id) { $r = $this->con->select('SELECT * FROM documents WHERE document_id=\'' . $this->con->escape($document_id) . '\''); return $this->singleton($r); } - public function selectByBookId($book_id) - { + public function selectByBookId($book_id) { $r = $this->con->select('SELECT * FROM documents WHERE document_id IN(SELECT document_id FROM book_pages WHERE book_id=\'' . $this->con->escape($book_id) . '\')'); return $this->factory($r); } - public function selectInList($documents_id) - { + public function selectInList($documents_id) { $r = $this->con->select('SELECT * FROM documents WHERE document_id IN(' . implode(',', $documents_id) . ')'); return $this->factory($r); } - public function cree() - { + public function cree() { $document = new wsDocument(); $document->document_id = 'new'; $document->file = ''; @@ -381,19 +375,18 @@ class wsDAODocument extends commonDAO { return $document; } - public function sauve($data) - { + public function sauve($data) { if (!isset($data['document_id'])) { $data['document_id'] = 'new'; } $c = $this->con->openCursor('documents'); - foreach(self::$normal as $k) { + foreach (self::$normal as $k) { if (isset($data[$k])) { $c->$k = $data[$k]; } } - foreach(self::$complex as $k) { + foreach (self::$complex as $k) { if (isset($data[$k])) { $c->$k = serialize($data[$k]); } @@ -414,24 +407,23 @@ class wsDAODocument extends commonDAO { return $doc; } - public function updateField($document_id, $fieldName, $value) - { + public function updateField($document_id, $fieldName, $value) { $c = $this->con->openCursor('documents'); $c->$fieldName = $value; $c->update('WHERE document_id=\'' . $this->con->escape($document_id) . '\''); } - public function updateFromObject($document) - { + public function updateFromObject($document) { $data = array(); - foreach(self::$normal as $k) { + foreach (self::$normal as $k) { $data[$k] = $document->$k; } - foreach(self::$complex as $k) { + foreach (self::$complex as $k) { $data[$k] = $document->$k; } return $this->sauve($data); } + } ?> \ No newline at end of file diff --git a/inc/ws/Metier/class.ws.book.php b/inc/ws/Metier/class.ws.book.php index 53427eca5..fbc30f627 100644 --- a/inc/ws/Metier/class.ws.book.php +++ b/inc/ws/Metier/class.ws.book.php @@ -1,51 +1,44 @@ $varname) || is_object($this->$varname)) { @@ -54,18 +47,7 @@ class wsBook extends cubeMetier { if ($this->$varname == '') { $this->$varname = array(); } else { - $this->$varname = json_decode($this->$varname, false); - } - return $this->$varname; - } - if ($varname == 'traductions') { - if (is_array($this->$varname) || is_object($this->$varname)) { - return $this->$varname; - } - if ($this->$varname == '') { - $this->$varname = array(); - } else { - $this->$varname = json_decode($this->$varname, true); + $this->$varname = json_decode($this->$varname,in_array($varname,$assoc)); } return $this->$varname; } @@ -86,6 +68,7 @@ class wsBook extends cubeMetier { return $this->$varname; } + } ?> \ No newline at end of file -- 2.39.5