From 0bf1d3771a6e3d699c2675795cab2f4f4fe19cf2 Mon Sep 17 00:00:00 2001 From: "vincent@cubedesigners.com" Date: Wed, 19 Jan 2011 16:26:54 +0000 Subject: [PATCH] --- importWs.php | 1 + inc/commons/class.common.core.php | 1 + inc/ws/Controlleur/class.ws.droits.php | 2 +- inc/ws/Controlleur/class.ws.flash.php | 1 + inc/ws/Controlleur/class.ws.url.php | 68 +++++++++++++++++++++----- inc/ws/DAO/class.ws.dao.book.php | 17 ++++--- inc/ws/DAO/class.ws.dao.document.php | 2 +- inc/ws/Metier/class.ws.document.php | 15 +++++- 8 files changed, 87 insertions(+), 20 deletions(-) diff --git a/importWs.php b/importWs.php index 470965ba7..67a30662f 100644 --- a/importWs.php +++ b/importWs.php @@ -324,6 +324,7 @@ try { $c->pages = $r->pages; $c->trim = $r->trim; $c->date = $r->date; + $c->version=1; $c->insert(); // TODO Copie des fichiers $docs[$r->did] = true; diff --git a/inc/commons/class.common.core.php b/inc/commons/class.common.core.php index 87655d801..43a8f6774 100644 --- a/inc/commons/class.common.core.php +++ b/inc/commons/class.common.core.php @@ -322,6 +322,7 @@ class commonCore extends cubeCore { $db->documents->conversionInfos('text', 0, false); $db->documents->numberSections('text', 0, false); $db->documents->localHash('varchar', 64, false); + $db->documents->version('integer', 0, false, '1'); // Clés $db->documents->primary('pk_documents', 'document_id'); $db->documents->index('index_documents_file', 'BTREE', 'file'); diff --git a/inc/ws/Controlleur/class.ws.droits.php b/inc/ws/Controlleur/class.ws.droits.php index b3743c7d2..062bc36de 100644 --- a/inc/ws/Controlleur/class.ws.droits.php +++ b/inc/ws/Controlleur/class.ws.droits.php @@ -54,7 +54,7 @@ class wsDroits { protected static function gradeIn($list, $error = false) { global $core; - if (!in_array($core->user->grade, $list)) { + if (!in_array($core->user->ws_grade, $list)) { if ($error) { commonDroits::error(); } diff --git a/inc/ws/Controlleur/class.ws.flash.php b/inc/ws/Controlleur/class.ws.flash.php index 342f462b9..59c29fe38 100644 --- a/inc/ws/Controlleur/class.ws.flash.php +++ b/inc/ws/Controlleur/class.ws.flash.php @@ -51,6 +51,7 @@ class wsFlash extends cubeFlashGateway { $data = array(); $data['proprietaire'] = $core->user->utilisateur_id; $data['pages'] = 0; + $data['version'] = 2; $data['file'] = cubeFiles::tidyName($infos['name']); $li = new wsDocumentLocalInfos($this); $li->fileName = $this->args['fileName']; diff --git a/inc/ws/Controlleur/class.ws.url.php b/inc/ws/Controlleur/class.ws.url.php index 6645a7be7..e48adb7c2 100644 --- a/inc/ws/Controlleur/class.ws.url.php +++ b/inc/ws/Controlleur/class.ws.url.php @@ -8,11 +8,14 @@ class wsUrl { $shortcuts = array(); if (wsDroits::creation()) { + fb('creation'); $shortcuts[] = '' . $core->typo->Ajouter(__('Créer une nouvelle publication')) . ''; } $filtres = array(); - $filtres[] = new commonFiltre(__('Status'), 'status_book', $settings['filtres']); + if (wsDroits::revendeur(false)) { + $filtres[] = new commonFiltre(__('Status'), 'status_book', $settings['filtres']); + } $filtres[] = new commonFiltre(__('Année'), 'annee_book', $settings['filtres']); $res = commonPage::barre($filtres , 'filtreBooks', 'books', $shortcuts); $res .= commonPage::tMain(null, true); @@ -208,13 +211,15 @@ class wsUrl { public static function editor($args) { - wsDroits::creation(true); + commonDroits::min(1); global $core; $args = cubePage::getArgs($args); $book_id = $args[0]; + self::checkDocumentVersionOfBook($book_id); + if ($book_id == 'new') { $dao = new wsDAOBook($core->con); $book = $dao->creeEmpty($core->user->utilisateur_id, $core->user->lang); @@ -235,6 +240,14 @@ html{height:100%}' . "\n"; echo $res; } + public static function editComposition($args) + { + $fv = array(session_name() => session_id(), + 'book_id' => $args[0]); + $res = cubeMedia::flash2(WEBROOT . '/swf/composer.swf?junk=' . TIME, '100%', '100%', $fv, 'composerSwf', 'swfPanel', 10, '#d2d3c7', '', 'false', 'noscale', 'normal', array(), false, true, true); + return $res; + } + public static function stats($args) { $bid = (isset($args[1]))?$args[1]:null; @@ -266,6 +279,9 @@ html{height:100%}' . "\n"; $dao = new wsDAOBook($core->con); $book_id = $e[0]; + + self::checkDocumentVersionOfBook($book_id); + $book = $dao->selectById($book_id); if ($book->hash != $e[1]) { commonDroits::error(); @@ -325,15 +341,6 @@ html{height:100%}' . "\n"; wsStats::exportXLS($bid); } - public static function editComposition($args) - { - wsDroits::creation(true); - $fv = array(session_name() => session_id(), - 'book_id' => $args[0]); - $res = cubeMedia::flash2(WEBROOT . '/swf/composer.swf?junk=' . TIME, '100%', '100%', $fv, 'composerSwf', 'swfPanel', 10, '#d2d3c7', '', 'false', 'noscale', 'normal', array(), false, true, true); - return $res; - } - public static function chooseExistingBook() { wsDroits::creation(true); @@ -364,6 +371,7 @@ html{height:100%}' . "\n"; if (!isset($args[1])) { $args[1] = 2964; } + self::checkDocumentVersionOfBook($args[1]); // cubePHP::neverStop(); $dao = new wsDAOBook($core->con); header('Content-type: text/plain'); @@ -372,6 +380,44 @@ html{height:100%}' . "\n"; exit; } + protected static function checkDocumentVersionOfBook($book_id) + { + global $core; + cubePHP::neverStop(); + $dao = new wsDAOBook($core->con); + $pages = $dao->getPagesOfBook($book_id); + $toUpdate = array(); + foreach($pages as $p => $infos) { + if ($infos['version'] < 2) { + $toUpdate[] = $infos['document_id']; + } + } + + $toUpdate = array_unique($toUpdate); + foreach($toUpdate as $document_id) { + fb('updateDocument', $document_id); + self::updateDocument($document_id); + } + } + + protected static function updateDocument($document_id) + { + global $core; + + $dao = new wsDAODocument($core->con); + $doc = $dao->selectById($document_id); + + $doc->copyOriginalFromOlderVersion(); + $doc->globalOperations(); + + for($i = 1;$i <= $doc->generalInfos['pages'];$i++) { + $doc->processOnePage($i); + } + + $doc->version = 2; + $dao->updateFromObject($doc); + } + public static function getParamsHelp() { commonDroits::min(5); diff --git a/inc/ws/DAO/class.ws.dao.book.php b/inc/ws/DAO/class.ws.dao.book.php index db543f498..0c62103fb 100644 --- a/inc/ws/DAO/class.ws.dao.book.php +++ b/inc/ws/DAO/class.ws.dao.book.php @@ -165,7 +165,7 @@ class wsDAOBook extends commonDAO { public function getPagesOfBook($book_id) { $pages = array(); - $r = $this->con->select('SELECT b.*,d.numberSections AS num,d.conversionInfos AS conversion,d.pages AS doc_pages FROM book_pages b LEFT JOIN documents d ON d.document_id=b.document_id WHERE b.book_id=\'' . $this->con->escape($book_id) . '\' ORDER BY book_page'); + $r = $this->con->select('SELECT b.*,d.numberSections AS num,d.conversionInfos AS conversion,d.pages AS doc_pages,d.version AS version FROM book_pages b LEFT JOIN documents d ON d.document_id=b.document_id WHERE b.book_id=\'' . $this->con->escape($book_id) . '\' ORDER BY book_page'); while ($r->fetch()) { $n = explode(',', $r->num); if ($r->conversion != '') { @@ -179,12 +179,17 @@ class wsDAOBook extends commonDAO { } $pages[$r->book_page] = array('document_id' => $r->document_id, 'document_page' => $r->document_page, + 'version' => $r->version, 'defaultNum' => $num, - 'nb_pages' => $r->doc_pages, - 'resolution' => $c->resolution, - 'quality' => $c->quality, - 'method' => $c->method, - 'objects' => $c->objects); + 'nb_pages' => $r->doc_pages + ); + + $qp = array('resolution', 'method', 'quality', 'objects'); + foreach($qp as $p) { + if (isset($c) && isset($c->$p)) { + $pages[$r->book_page][$p] = $c->$p; + } + } } return $pages; } diff --git a/inc/ws/DAO/class.ws.dao.document.php b/inc/ws/DAO/class.ws.dao.document.php index 8d405e6ab..e6aafe095 100644 --- a/inc/ws/DAO/class.ws.dao.document.php +++ b/inc/ws/DAO/class.ws.dao.document.php @@ -1,6 +1,6 @@ uncropped = $this->out . 'uncrop.pdf'; $this->common_log_pointer = fopen($this->log . '/commons.log', 'a'); $this->pages_log_pointers = array(); + + if(is_null($this->conversionInfos)){ + $this->conversionInfos=new wsDocumentConversionInfos(); + } } - public function copyOriginal($tmp_file) + public function copyOriginalFromUpload($tmp_file) { move_uploaded_file($tmp_file, $this->in); $this->uncropDocument(); } + public function copyOriginalFromOlderVersion() + { + if (!file_exists($this->in)) { + copy('http://ws.fluidbook.com/docs/' . $this->document_id . '/original.pdf', $this->in); + } + $this->uncropDocument(); + } + public function getInfos($in = null, $force = false) { if (is_null($in)) { -- 2.39.5