]> _ Git - cubeextranet.git/commitdiff
wip #4211 @0.5
authorvincent@cubedesigners.com <vincent@cubedesigners.com@f5622870-0f3c-0410-866d-9cb505b7a8ef>
Mon, 7 Mar 2022 18:11:33 +0000 (18:11 +0000)
committervincent@cubedesigners.com <vincent@cubedesigners.com@f5622870-0f3c-0410-866d-9cb505b7a8ef>
Mon, 7 Mar 2022 18:11:33 +0000 (18:11 +0000)
inc/ws/DAO/_common.php
inc/ws/DAO/class.ws.dao.book.php
inc/ws/DAO/class.ws.dao.book3.php [new file with mode: 0644]
inc/ws/Metier/class.ws.parametres.php

index 80302254aca9a45dbdbf1c5db00509752d1376e8..4d189820e345e8c9c92e4cc6eeeb3f87d303d121 100644 (file)
@@ -1,5 +1,6 @@
 <?php\r
 $__autoload['wsDAOBook'] = dirname(__FILE__) . '/class.ws.dao.book.php';\r
+$__autoload['wsDAOBook3'] = dirname(__FILE__) . '/class.ws.dao.book3.php';\r
 $__autoload['wsDAODocument'] = dirname(__FILE__) . '/class.ws.dao.document.php';\r
 $__autoload['wsDAOTheme'] = dirname(__FILE__) . '/class.ws.dao.theme.php';\r
 $__autoload['wsDAOIcone'] = dirname(__FILE__) . '/class.ws.dao.icone.php';\r
index 3488e6ad6f969d09c91e675bddd258da14177bda..fff2d5991531be077df5c07ff6285a482a0b695a 100644 (file)
@@ -16,49 +16,98 @@ class wsDAOBook extends commonDAO
      * @param mixed $r
      * @return
      */
+
+    protected static function _toTimestamp($date)
+    {
+        return strtotime($date);
+    }
+
     protected function singleton($r)
     {
-        $book = new wsBook();
-        $book->book_id = $r->book_id;
-        $book->cid = $r->cid;
-        $book->nom = $r->nom;
-        $book->lang = $r->lang;
-        $book->theme = $r->theme;
-        $book->proprietaire = $r->proprietaire_nom;
-        $book->proprietaire_id = $r->proprietaire_id;
-        $book->proprietaire_utilisateur = $r->proprietaire_utilisateur;
-        $book->hash = $r->hash;
-        $book->compteur_visites = $r->compteur_visites;
-        $book->status = $r->status;
-        $book->date_status = $r->date_status;
-        $book->date = $r->date;
-        $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;
-        $book->changedate = $r->changedate;
-        $book->compiledate = $r->compiledate;
-        $book->compile1date = $r->compile1date;
-        $book->compilehtml5date = $r->compilehtml5date;
-        $book->facturable = $r->facturable;
-        $book->facturable_id = $r->facturable_id;
-        $book->tache = $r->tache;
-        if (isset($r->projet)) {
-            $book->projet = $r->projet;
-        }
-        $book->version = $r->version;
-        $book->composition_update = $r->composition_update;
-        $book->dir_references = $r->dir_references;
-        $book->dir_hosting = $r->dir_hosting;
-        $book->dir_macbook_phonegap_ios = $r->dir_macbook_phonegap_ios;
-        $book->dir_phonegap_android = $r->dir_phonegap_android;
-        $book->dir_external = $r->dir_external;
-        $book->demo_counter = $r->demo_counter;
-        $book->exportdatas = $r->exportdatas;
+        if (isset($r->id)) {
+            $book = new wsBook();
+            $book->book_id = $r->id;
+            $book->cid = $r->cid;
+            $book->nom = $r->name;
+            $book->lang = $r->locale;
+            $book->theme = $r->theme;
+            $book->proprietaire = $r->proprietaire_nom;
+            $book->proprietaire_id = $r->owner;
+            $book->proprietaire_utilisateur = $r->proprietaire_utilisateur;
+            $book->hash = $r->hash;
+            $book->compteur_visites = $r->visits_counter;
+            $book->status = $r->status;
+            $book->date_status = self::_toTimestamp($r->status_date);
+            $book->date = self::_toTimestamp($r->created_at);
+            $book->pages = array();
+            $book->chapters = $r->chapters;
+            $book->traductions = $r->translations;
+//            $book->specialLinks = $r->specialLinks;
+//            $book->specialRulers = $r->specialRulers;
+            $book->parametres = new wsBookParametres($this);
+            $book->parametres->importFromJson($r->settings);
+            //$book->extras = $r->extras;
+            $book->numerotation = $r->page_numbers;
+            $book->changedate = self::_toTimestamp($r->updated_at);
+            $book->compilehtml5date = $book->compile1date = $book->compiledate = self::_toTimestamp($r->compilation_date);
+            $book->facturable = $r->facturable;
+            $book->facturable_id = $r->facturable_id;
+            $book->tache = $r->extranet_task;
+            if (isset($r->projet)) {
+                $book->projet = $r->projet;
+            }
+            $book->version = 2;
+            $book->composition_update = self::_toTimestamp($r->composition_updated_at);
+            $book->dir_references = $r->install_references_settings;
+            $book->dir_hosting = $r->install_hosting_settings;
+//            $book->dir_macbook_phonegap_ios = $r->dir_macbook_phonegap_ios;
+//            $book->dir_phonegap_android = $r->dir_phonegap_android;
+            $book->dir_external = $r->install_ftp_settings;
+//            $book->demo_counter = $r->demo_counter;
+//            $book->exportdatas = $r->exportdatas;
+        } else {
+            $book = new wsBook();
+            $book->book_id = $r->book_id;
+            $book->cid = $r->cid;
+            $book->nom = $r->nom;
+            $book->lang = $r->lang;
+            $book->theme = $r->theme;
+            $book->proprietaire = $r->proprietaire_nom;
+            $book->proprietaire_id = $r->proprietaire_id;
+            $book->proprietaire_utilisateur = $r->proprietaire_utilisateur;
+            $book->hash = $r->hash;
+            $book->compteur_visites = $r->compteur_visites;
+            $book->status = $r->status;
+            $book->date_status = $r->date_status;
+            $book->date = $r->date;
+            $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;
+            $book->changedate = $r->changedate;
+            $book->compiledate = $r->compiledate;
+            $book->compile1date = $r->compile1date;
+            $book->compilehtml5date = $r->compilehtml5date;
+            $book->facturable = $r->facturable;
+            $book->facturable_id = $r->facturable_id;
+            $book->tache = $r->tache;
+            if (isset($r->projet)) {
+                $book->projet = $r->projet;
+            }
+            $book->version = $r->version;
+            $book->composition_update = $r->composition_update;
+            $book->dir_references = $r->dir_references;
+            $book->dir_hosting = $r->dir_hosting;
+            $book->dir_macbook_phonegap_ios = $r->dir_macbook_phonegap_ios;
+            $book->dir_phonegap_android = $r->dir_phonegap_android;
+            $book->dir_external = $r->dir_external;
+            $book->demo_counter = $r->demo_counter;
+            $book->exportdatas = $r->exportdatas;
+        }
 
         return $book;
     }
@@ -183,20 +232,6 @@ class wsDAOBook extends commonDAO
         return $this->singleton($r);
     }
 
-    public function selectLuceneToDo()
-    {
-        $sql = 'SELECT * FROM books_vue WHERE lucene_time<composition_update AND version=2 ORDER BY book_id ASC LIMIT 1';
-        $r = $this->con->select($sql);
-        return $this->factory($r);
-    }
-
-    public function selectLuceneTimeNotSet()
-    {
-        $sql = 'SELECT * FROM books_vue WHERE lucene_time=0 AND version=2';
-        $r = $this->con->select($sql);
-        return $this->factory($r);
-    }
-
     /**
      * wsDAOBook::sauve()
      *
@@ -618,41 +653,7 @@ class wsDAOBook extends commonDAO
 
     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) {
-//
-//            }
-//        }
+
     }
 
     public function setTheme($book_id, $theme)
@@ -674,33 +675,6 @@ class wsDAOBook extends commonDAO
         return $this->selectById($book_id);
     }
 
-    public function setChaptersFromOldFluidbook($book_id)
-    {
-        $book = $this->selectById($book_id);
-        $n = explode(',', $book->numerotation);
-
-        $xml = simplexml_load_file('https://ws.fluidbook.com/books/' . $book_id . '/data/links.xml');
-        $res = array();
-        $chapters = $xml->xpath('//chapters');
-        foreach ($chapters as $ch) {
-            $c = array();
-            $c['label'] = (string)$ch->txt;
-
-            $p = intval((string)$ch->page);
-            if ($p <= 0) {
-                continue;
-            }
-            $c['page'] = $n[$p];
-            $c['level'] = intval((string)$ch->level);
-            $res[] = $c;
-        }
-
-        $c = $this->con->openCursor('books');
-        $c->chapters = json_encode($res);
-        $c->changedate = TIME;
-        $c->update('WHERE book_id=\'' . $this->con->escape($book_id) . '\'');
-    }
-
     public function saveCompositionVersion($book_id, $time = null)
     {
         $time = is_null($time) ? TIME : $time;
@@ -835,17 +809,11 @@ class wsDAOBook extends commonDAO
     public function touchCompile($book_id, $version = 'all')
     {
         $c = $this->con->openCursor('books');
-        if ($version == '2') {
-            $c->compiledate = TIME;
-        } elseif ($version == '1') {
-            $c->compile1date = TIME;
-        } elseif ($version == 'html5') {
-            $c->compilehtml5date = TIME;
-        } else {
-            $c->compiledate = TIME;
-            $c->compile1date = TIME;
-            $c->compilehtml5date = TIME;
-        }
+
+        $c->compiledate = TIME;
+        $c->compile1date = TIME;
+        $c->compilehtml5date = TIME;
+
         $c->update('WHERE book_id=\'' . $this->con->escape($book_id) . '\'');
     }
 
@@ -1173,10 +1141,7 @@ class wsDAOBook extends commonDAO
         }
     }
 
-    public function getNumerotationFromDocs($book_id)
-    {
-        $pages = $this->getPagesOfBook($book_id);
-    }
+
 
     public function compileTemp($book_id, $version, $dir)
     {
diff --git a/inc/ws/DAO/class.ws.dao.book3.php b/inc/ws/DAO/class.ws.dao.book3.php
new file mode 100644 (file)
index 0000000..549f5f2
--- /dev/null
@@ -0,0 +1,742 @@
+<?php
+
+class wsDAOBook3 extends wsDAOBook
+{
+
+    public static $pagesOfBookCache = array();
+
+    /** @var wsHTML5Compiler */
+    public static $lastHTML5Compiler = null;
+
+    protected $_compileLock = null;
+
+    /**
+     * wsDAOBook::singleton()
+     *
+     * @param mixed $r
+     * @return
+     */
+
+    protected static function _toTimestamp($date)
+    {
+        return strtotime($date);
+    }
+
+    protected function singleton($r)
+    {
+
+        $book = new wsBook();
+        $book->book_id = $r->id;
+        $book->cid = $r->cid;
+        $book->nom = $r->name;
+        $book->lang = $r->locale;
+        $book->theme = $r->theme;
+        $book->proprietaire = $r->proprietaire_nom;
+        $book->proprietaire_id = $r->owner;
+        $book->proprietaire_utilisateur = $r->proprietaire_utilisateur;
+        $book->hash = $r->hash;
+        $book->demo_counter = $book->compteur_visites = $r->visits_counter;
+        $book->status = $r->status;
+        $book->date_status = self::_toTimestamp($r->status_date);
+        $book->date = self::_toTimestamp($r->created_at);
+        $book->pages = array();
+        $book->chapters = $r->chapters;
+        $book->traductions = $r->translations;
+//            $book->specialLinks = $r->specialLinks;
+//            $book->specialRulers = $r->specialRulers;
+        $book->parametres = new wsBookParametres($this);
+        $book->parametres->importFromJson($r->settings);
+        //$book->extras = $r->extras;
+        $book->numerotation = $r->page_numbers;
+        $book->changedate = self::_toTimestamp($r->updated_at);
+        $book->compilehtml5date = $book->compile1date = $book->compiledate = self::_toTimestamp($r->compilation_date);
+        if (isset($r->facturable)) {
+            $book->facturable = $r->facturable;
+        }
+        if (isset($r->facturable_id)) {
+            $book->facturable_id = $r->facturable_id;
+        }
+        $book->tache = $r->extranet_task;
+        if (isset($r->projet)) {
+            $book->projet = $r->projet;
+        }
+        $book->version = 2;
+        $book->composition_update = self::_toTimestamp($r->composition_updated_at);
+        $book->dir_references = $r->install_references_settings;
+        $book->dir_hosting = $r->install_hosting_settings;
+//            $book->dir_macbook_phonegap_ios = $r->dir_macbook_phonegap_ios;
+//            $book->dir_phonegap_android = $r->dir_phonegap_android;
+        $book->dir_external = $r->install_ftp_settings;
+//            $book->demo_counter = $r->demo_counter;
+//            $book->exportdatas = $r->exportdatas;
+
+        return $book;
+    }
+
+    protected function cree($r)
+    {
+        $book = new wsBook();
+        $book->book_id = 'new';
+        $book->nom = '';
+        $book->cid = null;
+        $book->lang = 'fr';
+        $book->theme = 1;
+        $book->proprietaire = '';
+        $book->proprietaire_id = 0;
+        $book->hash = '';
+        $book->compteur_visites = 20;
+        $book->status = 0;
+        $book->date_status = TIME;
+        $book->date = TIME;
+        $book->composition_update = TIME;
+        $book->chapters = json_encode(array());
+        $book->parametres = new wsBookParametres();
+        $book->tache = 0;
+        $book->pages = array();
+        $book->version = 2;
+        return $book;
+    }
+
+    protected function getNextId()
+    {
+        $r = $this->con->select('SELECT MAX(book_id) AS book_id FROM books');
+        if ($r->book_id < 10000) {
+            return 10000;
+        }
+        return $r->book_id + 1;
+    }
+
+    public function saveExportDatas($book_id, $datas)
+    {
+        $c = $this->con->openCursor('books');
+        $c->exportdatas = json_encode($datas);
+        $c->update('WHERE book_id=\'' . $this->con->escape($book_id) . '\'');
+    }
+
+    public function addDemoCount($book_id)
+    {
+
+        $r = $this->con->select('SELECT demo_counter,nom FROM books WHERE book_id=\'' . $book_id . '\'');
+        $m = 20;
+        if ($r->demo_counter > 0 && $r->demo_counter % $m == 0) {
+            $mail = new cubeMail();
+            $mail->charset = 'UTF-8';
+            $mail->from = 'contact@fluidbook.com';
+            $mail->to = 'tech@fluidbook.com';
+            $mail->subject = '[Fluidbook Workshop] Fluidbook consulté via l\'url publique';
+            $mail->body = 'Le fluidbook suivant a été consulté ' . $m . ' fois (et ' . $r->demo_counter . ' au total) via l\'url publique : ' . "\r\n" .
+                'Fluidbook # ' . $book_id . ' - ' . $r->nom;
+            $mail->send();
+        }
+
+        $this->con->select('UPDATE books SET demo_counter=demo_counter+1 WHERE book_id=\'' . $book_id . '\'');
+    }
+
+    public function selectByIds($book_ids = array(), $simple = false)
+    {
+        if ($simple) {
+            $table = 'books';
+        } else {
+            $table = 'books_vue';
+        }
+
+        $ids = array();
+        foreach ($book_ids as $bid) {
+            fb($bid);
+            if (intval($bid) > 0) {
+                $ids[] = $bid;
+            }
+        }
+
+        $sql = 'SELECT * FROM ' . $table . ' WHERE book_id IN (' . implode(',', $ids) . ')';
+        $books = $this->factory($this->con->select($sql));
+        $res = array();
+        foreach ($books as $book) {
+            $res[$book->book_id] = $book;
+        }
+        return $res;
+    }
+
+    public function selectAll()
+    {
+        $table = 'books_vue';
+        $sql = 'SELECT * FROM ' . $table;
+        $r = $this->con->select($sql);
+        return $this->factory($r);
+    }
+
+    public function selectById($book_id = null, $simple = false)
+    {
+        if (is_null($book_id)) {
+            return $this->cree();
+        }
+        if ($simple) {
+            $table = 'books';
+        } else {
+            $table = 'books_vue';
+        }
+        $sql = 'SELECT * FROM ' . $table . ' WHERE book_id=\'' . $this->con->escape($book_id) . '\' LIMIT 1';
+        $r = $this->con->select($sql);
+        return $this->singleton($r);
+    }
+
+    public function selectByCid($cid = null, $simple = false)
+    {
+        if ($simple) {
+            $table = 'books';
+        } else {
+            $table = 'books_vue';
+        }
+
+        $sql = 'SELECT * FROM ' . $table . ' WHERE cid LIKE BINARY \'' . $this->con->escape($cid) . '\' LIMIT 1';
+        $r = $this->con->select($sql);
+        return $this->singleton($r);
+    }
+
+
+    /**
+     * wsDAOBook::sauve()
+     *
+     * @param mixed $createur
+     * @param mixed $data
+     * @return
+     */
+    public function sauve($createur, $data)
+    {
+        $c = $this->con->openCursor('books');
+        if (isset($data['nom'])) {
+            $c->nom = $data['nom'];
+        }
+        if (isset($data['lang'])) {
+            $c->lang = $data['lang'];
+        }
+        if (isset($data['theme'])) {
+            $c->theme = $data['theme'];
+        }
+        if (isset($data['proprietaire'])) {
+            $c->proprietaire = $data['proprietaire'];
+        }
+
+        if ($data['book_id'] == 'new' || $data['book_id'] == '') {
+            $c->date = TIME;
+            $c->hash = md5(rand(0, 123456789365469));
+            $c->compteur_visites = 20;
+            $c->parametres = serialize(new wsParametres());
+            $c->changedate = TIME;
+            $book_id = $c->book_id = $this->getNextId();
+
+            $c->insert();
+        } else {
+            $c->changedate = TIME;
+            $book_id = $data['book_id'];
+            $c->update('WHERE book_id=\'' . $this->con->escape($data['book_id']) . '\'');
+        }
+
+        if (isset(self::$pagesOfBookCache[$book_id])) {
+            unset(self::$pagesOfBookCache[$book_id]);
+        }
+
+        return $this->selectById($book_id);
+    }
+
+    public function duplicate($book_id, $createur, $nom = null, $pages = false, $complete = false)
+    {
+        $r = $this->con->select('SELECT * FROM books_vue WHERE book_id=\'' . $this->con->escape($book_id) . '\'');
+
+        $old_id = $book_id;
+
+
+        $parametres = unserialize($r->parametres);
+        $parametres->setParent($this);
+        if (null === $nom) {
+            $nom = $parametres->title;
+        }
+        $parametres->title = $nom;
+
+        if (!$complete) {
+            $parametres->pdfReplace = '';
+        }
+
+        $c = $this->con->openCursor('books');
+        $c->proprietaire = $createur;
+        $c->date = TIME;
+        $c->hash = md5(rand(0, 1234567893));
+        $c->cid = $this->generateCID();
+        $c->compteur_visites = 20;
+        $c->status = -1;
+        $c->date_status = TIME;
+        $c->lang = $r->lang;
+        $c->parametres = serialize($parametres);
+        $c->nom = $nom;
+        $c->theme = $r->theme;
+        $c->changedate = TIME;
+        $c->compiledate = 0;
+        $c->version = 2;
+        $c->traductions = $r->traductions;
+        $c->specialLinks = $r->specialLinks;
+        $c->specialRulers = $r->specialRulers;
+        $c->composition_update = TIME;
+        $book_id = $c->book_id = $this->getNextId();
+        if ($pages) {
+            $c->numerotation = $r->numerotation;
+            $c->chapters = $r->chapters;
+            $this->con->execute('INSERT INTO book_pages SELECT ' . $book_id . ' AS book_id,book_page,document_id,document_page FROM book_pages WHERE book_id=' . $old_id);
+        }
+        if ($complete) {
+            $c->numerotation = $r->numerotation;
+            $c->chapters = $r->chapters;
+        }
+        $c->insert();
+
+        $this->saveCompositionVersion($book_id);
+
+        return $this->selectById($book_id);
+    }
+
+    public function creeEmpty($createur, $lang, $nom)
+    {
+        $c = $this->con->openCursor('books');
+
+        $parametres = new wsBookParametres($this);
+        $parametres->title = $nom;
+
+        $c->proprietaire = $createur;
+        $c->cid = $this->generateCID();
+        $c->nom = $nom;
+        $c->date = TIME;
+        $c->hash = md5(rand(0, 1234567893));
+        $c->compteur_visites = 20;
+        $c->status = -1;
+        $c->date_status = TIME;
+        $c->parametres = serialize($parametres);
+
+        $c->theme = 1;
+        $c->lang = $lang;
+        $c->changedate = TIME;
+        $c->compiledate = 0;
+        $c->version = 2;
+        $c->composition_update = TIME;
+        $book_id = $c->book_id = $this->getNextId();
+        $c->insert();
+        return $this->selectById($book_id);
+    }
+
+    public function supprime($book_id)
+    {
+        $this->con->execute('DELETE FROM book_pages_versions WHERE book_id=\'' . $this->con->escape($book_id) . '\'');
+        $this->con->execute('DELETE FROM book_pages WHERE book_id=\'' . $this->con->escape($book_id) . '\'');
+        return $this->con->execute('DELETE FROM books WHERE book_id=\'' . $this->con->escape($book_id) . '\'');
+    }
+
+    public function count($limitedToUserRights = false)
+    {
+        $filters = $this->makeWhereFromFiltres();
+        if ($filters == '1=1') {
+            $table = 'books';
+        } else {
+            $table = 'books_vue';
+        }
+
+        $where = '(' . $filters . ')';
+        $where .= $this->limitToUserRights($limitedToUserRights);
+        $r = $this->con->select('SELECT COUNT(*) AS nb FROM ' . $table . ' WHERE ' . $where);
+        return $r->nb;
+    }
+
+
+    public function insertDocument($book_id, $after_page, $document_id)
+    {
+        // Obtiens le book
+        $book = $this->selectById($book_id);
+        $num = explode(',', $book->numerotation);
+        // Obtiens le nombre de pages
+        $r = $this->con->select('SELECT pages,numberSections FROM documents WHERE document_id=\'' . $this->con->escape($document_id) . '\'');
+        // Décale les pages vers le bas
+        if ($after_page > 0) {
+            $this->decalePages($book_id, $after_page, $r->pages);
+        }
+        // Insère les pages
+        $c = $this->con->openCursor('book_pages');
+        $c->book_id = $book_id;
+        $c->document_id = $document_id;
+        for ($i = 1; $i <= $r->pages; $i++) {
+            $c->document_page = $i;
+            $c->book_page = $after_page + $i;
+            $c->insert();
+        }
+        // Mets à jour la liste des numéros des pages
+        $before = array_slice($num, 0, $after_page);
+        $after = array_slice($num, $after_page, count($num) - $after_page);
+
+        $newnum = $r->numberSections;
+        if (trim($newnum, ',') == '') {
+            // If no number detected, we create a numeric list from 1
+            $between = range(1, $r->pages);
+        } else {
+            // Else, we use numbers detected at conversion
+            $between = explode(',', $r->numberSections);
+        }
+        $num = array_merge($before, $between, $after);
+        // Mets à jour la numerotation de la publication
+        $c = $this->con->openCursor('books');
+        $c->numerotation = implode(',', $num);
+        $c->composition_update = TIME;
+        $c->update('WHERE book_id=\'' . $this->con->escape($book_id) . '\'');
+
+        $this->saveCompositionVersion($book_id);
+    }
+
+
+    public function getListe($orderby = null, $sens = null, $limit = null, $limitedToUserRights = false)
+    {
+        if (!is_null($this->q)) {
+            $where = '(';
+            if ($this->search_id) {
+                $where .= ' book_id=\'' . $this->con->escape($this->q) . '\' OR ';
+            }
+
+            if (!cubeMath::is_int($this->q)) {
+                $where .= 'nom LIKE \'%' . $this->con->escape($this->q) . '%\'';
+                $daoClient = new commonDAOClient($this->con);
+                $where .= ' OR proprietaire_id IN(' . $daoClient->querySearchByName($this->q) . ') OR ';
+            }
+            $limit = null;
+            $where .= '1=2)';
+        } else {
+            $where = '(' . $this->makeWhereFromFiltres() . ')';
+        }
+        $where .= $this->limitToUserRights($limitedToUserRights);
+
+        $orderby = is_null($orderby) ? 'book_id' : $orderby;
+        $sens = is_null($sens) ? 'DESC' : $sens;
+        $limit = is_null($limit) ? '' : $this->con->limit($limit);
+
+        $sql = 'SELECT * FROM books_vue WHERE ' . $where . ' ORDER BY ' . $orderby . ' ' . $sens . ' ' . $limit;
+        $r = $this->con->select($sql);
+        return $this->factory($r);
+    }
+
+    protected function limitToUserRights($utilisateur)
+    {
+        if ($utilisateur) {
+            if (wsDroits::admin()) {
+                return '';
+            }
+            return ' AND proprietaire IN (' . $utilisateur->ws_rights . ')';
+        }
+        return '';
+    }
+
+    protected function makeWhereFromFiltres()
+    {
+        if (!is_null($this->filtres)) {
+            $w = array('1=1');
+            if (commonFiltre::test('admin_book', $this->filtres)) {
+                $w[] = 'super_admin IN (' . implode(',', array_keys($this->filtres['admin_book'])) . ')';
+            }
+            if (commonFiltre::test('status_book', $this->filtres)) {
+                $w[] = 'status IN(' . implode(',', array_keys($this->filtres['status_book'])) . ')';
+            }
+            if (commonFiltre::test('revendeur_book', $this->filtres)) {
+                $v = array_keys($this->filtres['revendeur_book']);
+                $values = array();
+                foreach ($v as $r) {
+                    $values[] = $this->con->escape($r);
+                }
+
+
+                $w[] = 'facturable IN(\'' . implode('\',\'', $values) . '\')';
+            }
+            return implode(' AND ', $w);
+        } else {
+            return '1=1';
+        }
+    }
+
+    public function setChapters($book_id, $json)
+    {
+        $chapters = json_decode($json, true);
+        $res = array();
+
+        foreach ($chapters as $c) {
+            $c['label'] = trim($c['label']);
+            $n = (string)$c['page'];
+            $c['label'] = trim(preg_replace('|\s+' . $n . '$|iu', '', $c['label']));
+            $res[] = $c;
+        }
+
+        $json_chapters = json_encode($res);
+
+        $c = $this->con->openCursor('books');
+        $c->chapters = $json_chapters;
+        $c->changedate = TIME;
+        $c->update('WHERE book_id=\'' . $this->con->escape($book_id) . '\'');
+
+        if ($json_chapters && $json_chapters != '[]') {
+            if (count($res) == 1) {
+                if ($res[0]['label'] == '' && $res[0]['page'] == '') {
+                    return;
+                }
+            }
+            $c = $this->con->openCursor('books_chapters_versions');
+            $c->book_id = $book_id;
+            $c->chapters = $json_chapters;
+            $c->time = TIME;
+            $c->insert();
+        }
+    }
+
+    public function setTheme($book_id, $theme)
+    {
+        $c = $this->con->openCursor('books');
+        $c->theme = $theme;
+        $c->changedate = TIME;
+        $c->update('WHERE book_id=\'' . $this->con->escape($book_id) . '\'');
+    }
+
+    public function setStatus($book_id, $status)
+    {
+        $c = $this->con->openCursor('books');
+        if ($status < 2) {
+            $c->tache = 0;
+        }
+        $c->status = $status;
+        $c->update('WHERE book_id=\'' . $this->con->escape($book_id) . '\'');
+        return $this->selectById($book_id);
+    }
+
+    public function setLang($book_id, $base, $traductions)
+    {
+        // Cleanup user translations
+        $traductions = json_decode($traductions, true);
+        foreach ($traductions as $k => $v) {
+            $traductions[$k] = $v;
+        }
+
+        $daoLang = new wsDAOLang($this->con);
+        $lang = $daoLang->selectById($base);
+        // Cleanup base translations
+        $baseTraductions = $lang->traductions;
+        foreach ($baseTraductions as $k => $v) {
+            $baseTraductions[$k] = $v;
+        }
+        // Then compare them. If there is no differences, we don't save translations in the book
+        if ($traductions == $baseTraductions) {
+            $t = '';
+        } else {
+            $t = json_encode($traductions);
+        }
+
+        $c = $this->con->openCursor('books');
+        $c->lang = $base;
+        $c->traductions = $t;
+        $c->changedate = TIME;
+        $c->update('WHERE book_id=\'' . $this->con->escape($book_id) . '\'');
+    }
+
+    public function setSettings($book_id, $settings)
+    {
+        $book = $this->selectById($book_id);
+        $parametres = $book->parametres;
+        $new = $settings;
+        $root = ['lang', 'proprietaire_id', 'status'];
+        $rootSettings = [];
+        foreach ($new as $k => $v) {
+            if ($k == '_empty_') {
+                continue;
+            }
+            if (in_array($k, $root)) {
+                $rootSettings[$k] = $v;
+            } else {
+                try {
+                    $parametres->$k = $v;
+                } catch (Exception $e) {
+
+                }
+            }
+        }
+
+
+        $ip = array();
+        if (isset($parametres->stats_exclude_ip) && trim($parametres->stats_exclude_ip) != '') {
+            $list = $parametres->stats_exclude_ip;
+            $list = str_replace("\r", "\n", $list);
+            $e = explode("\n", $list);
+            foreach ($e as $i) {
+                $i = trim($i);
+                if ($i == '') {
+                    continue;
+                }
+                $long = ip2long($i);
+                if ($long !== false) {
+                    $ip[] = $long;
+                }
+            }
+        }
+
+        $file = '/home/stats/www/exclude/' . $book_id;
+
+        if (count($ip)) {
+            file_put_contents($file, implode(',', $ip));
+            chmod($file, 0777);
+            chown($file, 'stats');
+        } else if (file_exists($file)) {
+            unlink($file);
+        }
+
+        $c = $this->con->openCursor('books');
+        $c->nom = $parametres->title;
+        $c->parametres = serialize($parametres);
+        $c->changedate = TIME;
+        foreach ($rootSettings as $k => $v) {
+            $c->$k = $v;
+        }
+        $c->update('WHERE book_id=\'' . $this->con->escape($book_id) . '\'');
+    }
+
+    public function setProprietaire($book_id, $proprietaire_id)
+    {
+        $c = $this->con->openCursor('books');
+        $c->proprietaire = $proprietaire_id;
+        $c->update('WHERE book_id=\'' . $this->con->escape($book_id) . '\'');
+    }
+
+    public function setTache($book_id, $tache)
+    {
+        $c = $this->con->openCursor('books');
+        $c->tache = $tache;
+        $c->status = 2;
+        $c->update('WHERE book_id=\'' . $this->con->escape($book_id) . '\'');
+    }
+
+    public function setVersion($book_id, $version)
+    {
+        $c = $this->con->openCursor('books');
+        $c->version = $version;
+        $c->update('WHERE book_id=\'' . $this->con->escape($book_id) . '\'');
+    }
+
+    public function touch($book_id)
+    {
+        $c = $this->con->openCursor('books');
+        $c->changedate = TIME;
+        $c->update('WHERE book_id=\'' . $this->con->escape($book_id) . '\'');
+    }
+
+    public function touchCompile($book_id, $version = 'all')
+    {
+        $c = $this->con->openCursor('books');
+        if ($version == '2') {
+            $c->compiledate = TIME;
+        } elseif ($version == '1') {
+            $c->compile1date = TIME;
+        } elseif ($version == 'html5') {
+            $c->compilehtml5date = TIME;
+        } else {
+            $c->compiledate = TIME;
+            $c->compile1date = TIME;
+            $c->compilehtml5date = TIME;
+        }
+        $c->update('WHERE book_id=\'' . $this->con->escape($book_id) . '\'');
+    }
+
+    /**
+     * @param $book wsBook
+     * @param $version
+     * @return bool
+     */
+    public function isUpToDate($book, $version)
+    {
+        $version = (string)$version;
+        if ($version == '2') {
+            if (!file_exists(WS_BOOKS . '/final/' . $book->book_id)) {
+                return false;
+            }
+            if ($book->compiledate < $book->changedate) {
+                return false;
+            }
+        } else if ($version == '1') {
+            // V1
+            if (!file_exists(WS_BOOKS . '/finalv1/' . $book->book_id . '/index.swf')) {
+                return false;
+            }
+            if ($book->compile1date < $book->changedate) {
+                return false;
+            }
+        } else if ($version == 'html5') {
+            return false;
+            // HTML5
+            $checks = array($book->changedate, cubeFiles::filemtimeRecursive($book->getAssetDir()), cubeFiles::filemtimeRecursive(WS_COMPILE_ASSETS . '/_html5'), cubeFiles::filemtimeRecursive(ROOT . '/inc/ws/Util/html5'));
+            foreach ($checks as $check) {
+                if ($check > $book->compilehtml5date) {
+                    return false;
+                }
+            }
+        }
+        return true;
+    }
+
+    public function setComposition($book_id, $pages, $setNumerotation = true)
+    {
+        $numerotation = array();
+        $nb_pages = 0;
+        foreach ($pages as $p) {
+            if ($setNumerotation) {
+                $numerotation[] = $p->virtual;
+            }
+            $nb_pages++;
+        }
+
+        $book = $this->selectById($book_id);
+        $parametres = $book->parametres;
+        $parametres->pages = $nb_pages;
+
+        $c = $this->con->openCursor('books');
+        $c->parametres = serialize($parametres);
+        if ($setNumerotation) {
+            $c->numerotation = implode(',', $numerotation);
+        }
+        $c->changedate = TIME;
+
+        // Check if composition need to be updated
+        $r = $this->con->select('SELECT * FROM book_pages WHERE book_id=\'' . $this->con->escape($book_id) . '\'');
+        $tab = array();
+        $now = array();
+        $ref = array();
+        while ($r->fetch()) {
+            $ref[$r->book_page] = array((int)$r->document_id, (int)$r->document_page);
+        }
+        $i = 1;
+        foreach ($pages as $p) {
+            $now[$i] = array((int)$p->document_id, (int)$p->document_page);
+            $i++;
+        }
+        if ($now != $ref) {
+            $this->con->execute('DELETE FROM book_pages WHERE book_id=\'' . $this->con->escape($book_id) . '\'');
+
+            $c1 = $this->con->openCursor('book_pages');
+            $c1->book_id = $book_id;
+            $i = 1;
+            foreach ($pages as $p) {
+                $c1->document_id = $p->document_id;
+                $c1->document_page = $p->document_page;
+                $c1->book_page = $i;
+                $c1->insert();
+                $i++;
+            }
+            $c->composition_update = TIME;
+            $this->saveCompositionVersion($book_id);
+        }
+
+        $c->update('WHERE book_id=\'' . $this->con->escape($book_id) . '\'');
+    }
+
+    public function setInstallDir($book_id, $dir, $server)
+    {
+        $col = 'dir_' . $server;
+
+        $c = $this->con->openCursor('books');
+        $c->$col = $dir;
+        $c->update('WHERE book_id=\'' . $this->con->escape($book_id) . '\'');
+    }
+}
index d08d99fff690ccf8ceb635dde494b52162bf972f..570cd862855edc1976b510c74d12d3e43342ee27 100644 (file)
@@ -352,8 +352,8 @@ class wsParametres extends cubeMetier implements Iterator
         }\r
         $res = "    ";\r
         $res .= '$this->addField(\'' . addcslashes($attributes['name'], "'") . '\', ' . $attributes['type'] . '::class';\r
-        if(isset($attributes['label']) && $attributes['label']){\r
-            $res.=', ' . $attributes['label'];\r
+        if (isset($attributes['label']) && $attributes['label']) {\r
+            $res .= ', ' . $attributes['label'];\r
         }\r
         unset($attributes['name']);\r
         unset($attributes['type']);\r
@@ -423,6 +423,8 @@ class wsParametres extends cubeMetier implements Iterator
             $attrs['accept'] = explode(';', $f['fileFilter']->extensions);\r
         }\r
 \r
+        $attrs['fake'] = true;\r
+        $attrs['store_in'] = 'settings';\r
         $attrs['translatable'] = false;\r
 \r
         return $this->generateV3Field($attrs, $tab);\r