From: vincent@cubedesigners.com Date: Thu, 11 Aug 2011 11:58:46 +0000 (+0000) Subject: (no commit message) X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=9e2879addc66182e22af957e9103da163ef17c8f;p=cubeextranet.git --- diff --git a/inc/commons/class.common.core.php b/inc/commons/class.common.core.php index 1c31d034c..34b180072 100644 --- a/inc/commons/class.common.core.php +++ b/inc/commons/class.common.core.php @@ -347,7 +347,7 @@ class commonCore extends cubeCore { $db->document_links_versions->document_id('integer', 0, false); $db->document_links_versions->links('text', 0, false); $db->document_links_versions->rulers('text', 0, false); - $db->document_links_versions->comments('varchar', 32, false); + $db->document_links_versions->comments('varchar', 64, false); $db->document_links_versions->user('integer', 0, false); $db->document_links_versions->update('integer', 0, false); // . @@ -447,7 +447,6 @@ class commonCore extends cubeCore { $dbi = new CubeDbStruct($this->con); $dbi->synchronize($db); } catch (Exception $e) { - fb($e); return; } diff --git a/inc/ws/Controlleur/class.ws.ajax.php b/inc/ws/Controlleur/class.ws.ajax.php index 8cb1cc22c..a38791439 100644 --- a/inc/ws/Controlleur/class.ws.ajax.php +++ b/inc/ws/Controlleur/class.ws.ajax.php @@ -636,20 +636,21 @@ class wsAjax extends cubeAjax { global $core; $book_id = $args[1]; - $date = $args[2]; + $time = $args[2]; $dao = new wsDAODocument($core->con); - $dao->restoreLinksVersion($book_id, $date, $core->user->utilisateur_id); - } + $dao->getLinksAndRulers($book_id, $links, $rulers, $time); + $xls = $dao->getLinksAsExcel($links, $rulers); + + self::getLinksFromExcel($xls, $links, $rulers); - public static function importLinksAsExcel($args) { - global $core; - $book_id = $args[1]; - $xls = new PHPExcel(); - $reader = new PHPExcel_Reader_Excel2007(); - $xls = $reader->load($_FILES['file']['tmp_name']); + $dao = new wsDAODocument($core->con); + $dao->setLinksAndRulers($book_id, json_encode($links), json_encode($rulers), 'Restore links from ' . date('Y-m-d H:i:s', $time), $core->user->utilisateur_id); + } + + private static function getLinksFromExcel($xls, &$links, &$rulers) { $s = $xls->setActiveSheetIndexByName('Links'); $i = 0; $links = array(); @@ -697,8 +698,17 @@ class wsAjax extends cubeAjax { } $i++; } + } + public static function importLinksAsExcel($args) { + global $core; + $book_id = $args[1]; + + $xls = new PHPExcel(); + $reader = new PHPExcel_Reader_Excel2007(); + $xls = $reader->load($_FILES['file']['tmp_name']); + self::getLinksFromExcel($xls, $links, $rulers); $dao = new wsDAODocument($core->con); $dao->setLinksAndRulers($book_id, json_encode($links), json_encode($rulers), 'Import from excel', $core->user->utilisateur_id); diff --git a/inc/ws/Controlleur/class.ws.maintenance.php b/inc/ws/Controlleur/class.ws.maintenance.php index fb8cfcab4..9b5e57e9a 100644 --- a/inc/ws/Controlleur/class.ws.maintenance.php +++ b/inc/ws/Controlleur/class.ws.maintenance.php @@ -11,6 +11,16 @@ class wsMaintenance { } } + public static function initCompositionVersions($args) { + global $core; + $dao = new wsDAOBook($core->con); + + $r = $core->con->select('SELECT * FROM books ORDER by book_id'); + while ($r->fetch()) { + $dao->saveCompositionVersion($r->book_id,$r->composition_update); + } + } + public static function resetLinks($args) { global $core; $book_id = $args[0]; @@ -284,6 +294,11 @@ class wsMaintenance { } // Import des pages $core->con->execute('INSERT INTO book_pages (book_id,book_page,document_id,document_page) SELECT bid,bpid,did,dpid FROM ws.book_pages WHERE bid ' . self::_sqlIn($oldBooks)); + + $dao = new wsDAOBook($core->con); + foreach ($oldBooks as $book_id) { + $dao->saveCompositionVersion($book_id); + } } protected static function _oldIconesToColor($iid, &$parametres) { diff --git a/inc/ws/Controlleur/class.ws.url.php b/inc/ws/Controlleur/class.ws.url.php index 9885c6557..10770f84e 100644 --- a/inc/ws/Controlleur/class.ws.url.php +++ b/inc/ws/Controlleur/class.ws.url.php @@ -4,9 +4,9 @@ class wsUrl { public static function publications($args) { global $core; - - if(isset($args[1])){ - $_SESSION['q']=$args[1]; + + if (isset($args[1])) { + $_SESSION['q'] = $args[1]; } $settings = $core->user->getSettings('books'); @@ -502,100 +502,9 @@ html{height:100%}' . "\n"; $book_id = $args[1]; $time = $args[2]; - $daoBook = new wsDAOBook($core->con); - $pages = $daoBook->getPagesOfBook($book_id); - $dao = new wsDAODocument($core->con); $dao->getLinksAndRulers($book_id, $links, $rulers, $time); - - $cols = array('document_id' => __('Document'), 'document_page' => __('Page du document'), - 'page' => __('Page de la publication'), 'left' => __('x'), 'top' => __('y'), 'width' => __('Largeur'), 'height' => __('Hauteur'), - 'type' => __('Type'), 'to' => __('Destination'), 'target' => __('Cible'), - 'infobulle' => __('Infobulle'), 'numerotation' => __('Numérotation'), - 'display_area' => __('Activer la surbrillance'), - 'video_loop' => __('Video : boucle'), 'video_auto_start' => __('Video : démarrage automatique'), 'video_controls' => __('Vidéo : afficher les contrôles'), 'video_sound_on' => __('Vidéo : activer le son'), - 'inline' => __('Vidéo : afficher dans la page'), 'video_width' => __('Vidéo : Largeur du popup'), 'video_height' => __('Vidéo : Hauteur du popup'), - 'interactive' => __('Interactivité'), 'video_service' => __('Webvideo : service'), - 'display_area' => __('Afficher le lien au rollover') - ); - - $xls = new PHPExcel(); - $s = $xls->setActiveSheetIndex(0); - $s->setTitle('Links'); - - - - // Labels - $i = 0; - foreach ($cols as $id => $label) { - $s->setCellValueByColumnAndRow($i, 1, $id); - $s->getColumnDimensionByColumn($i)->setAutoSize(true); - $s->getStyleByColumnAndRow($i, 1)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER); - $i++; - } - // Links - $j = 2; - foreach ($links as $l) { - $i = 0; - foreach ($cols as $id => $label) { - if ($id == 'document_id' || $id == 'document_page') { - $infos = $pages[$l['page']]; - $value = $infos[$id]; - } else { - if (is_bool($l[$id])) { - $l[$id] = $l[$id] ? 1 : 0; - } - if ($id == 'numerotation') { - if ($l[$id] == 'false') { - $l[$id] = 'physical'; - } - } else if ($id == 'display_area') { - if ($l[$id] == '') { - $l[$id] = '1'; - } - } - $value = $l[$id]; - } - - $s->setCellValueByColumnAndRow($i, $j, $value); - $s->getStyleByColumnAndRow($i, $j)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_LEFT); - $i++; - } - $j++; - } - // Rulers - $s = $xls->createSheet(); - $s->setTitle('Rulers'); - - $rcols = array('document_id', 'document_page', 'page', 'type', 'pos'); - $i = 0; - // Labels - foreach ($rcols as $id) { - $s->setCellValueByColumnAndRow($i, 1, $id); - $s->getColumnDimensionByColumn($i)->setAutoSize(true); - $s->getStyleByColumnAndRow($i, 1)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER); - $i++; - } - - // Contents - $j = 2; - foreach ($rulers as $r) { - $i = 0; - foreach ($rcols as $id) { - if ($id == 'document_id' || $id == 'document_page') { - $infos = $pages[$r['page']]; - $value = $infos[$id]; - } else { - $value = $r[$id]; - } - $s->setCellValueByColumnAndRow($i, $j, $value); - $s->getStyleByColumnAndRow($i, $j)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_LEFT); - $i++; - } - $j++; - } - - $xls->setActiveSheetIndex(0); + $xls = $dao->getLinksAsExcel($links, $rulers); ob_end_clean(); files::registerMimeTypes(array('xlsx' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet')); diff --git a/inc/ws/DAO/class.ws.dao.book.php b/inc/ws/DAO/class.ws.dao.book.php index fe93ec2d6..b23d97023 100644 --- a/inc/ws/DAO/class.ws.dao.book.php +++ b/inc/ws/DAO/class.ws.dao.book.php @@ -205,9 +205,35 @@ class wsDAOBook extends commonDAO { return $r->nb; } + public function getPagesOfBookAt($book_id, $time) { + $r = $this->con->select('SELECT * FROM book_pages_versions WHERE book_id=\'' . $this->con->escape($book_id) . '\' ORDER BY `update`'); + if (!$r->count()) { + return $this->getPagesOfBook($book_id); + } + if ($r->count() == 1) { + $pages = unserialize($r->composition); + if (!count($pages)) { + return $this->getPagesOfBook($book_id); + } + return $pages; + } + $pages = null; + while ($r->fetch()) { + if ($r->update > $time) { + if (is_null($pages)) { + return $this->getPagesOfBook($book_id); + } + return unserialize($pages); + } + $pages = $r->composition; + } + return unserialize($pages); + } + 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,d.version AS version FROM book_pages b JOIN documents d ON d.document_id=b.document_id WHERE b.book_id=\'' . $this->con->escape($book_id) . '\' ORDER BY book_page'); + $update = $r->composition_update; while ($r->fetch()) { $n = explode(',', $r->num); if ($r->conversion != '') { @@ -415,11 +441,14 @@ class wsDAOBook extends commonDAO { $c->update('WHERE book_id=\'' . $this->con->escape($book_id) . '\''); } - public function saveCompositionVersion($book_id) { + public function saveCompositionVersion($book_id, $time=null) { + + $time = is_null($time) ? TIME : $time; + $pages = $this->getPagesOfBook($book_id); $c = $this->con->openCursor('book_pages_versions'); - $c->update = TIME; + $c->update = $time; $c->book_id = $book_id; $c->composition = serialize($pages); $c->insert(); diff --git a/inc/ws/DAO/class.ws.dao.document.php b/inc/ws/DAO/class.ws.dao.document.php index f2884d9b6..1399ca7ba 100644 --- a/inc/ws/DAO/class.ws.dao.document.php +++ b/inc/ws/DAO/class.ws.dao.document.php @@ -34,7 +34,16 @@ class wsDAODocument extends commonDAO { } public function restoreLinksVersion($book_id, $update, $user=0) { - $sql = 'INSERT INTO document_links_versions (document_id,links,rulers,`update`,comments,user) SELECT document_id,links,rulers,' . TIME . ',\'Links from a previous version\',' . $user . ' FROM document_links_versions WHERE `update`=' . $update . ' AND document_id IN (SELECT document_id FROM book_pages WHERE book_id=' . $book_id . ')'; + + $daoBook = new wsDAOBook($this->con); + $pages = $daoBook->getPagesOfBookAt($book_id, $update); + + $docs = array(); + foreach ($pages as $infos) { + $docs[] = $infos['document_id']; + } + + $sql = 'INSERT INTO document_links_versions (document_id,links,rulers,`update`,comments,user) SELECT document_id,links,rulers,' . TIME . ',\'Links from a previous version\',' . $user . ' FROM document_links_versions WHERE `update`=' . $update . ' AND document_id IN (' . implode(',', $docs) . ')'; $this->con->execute($sql); } @@ -61,7 +70,7 @@ class wsDAODocument extends commonDAO { $log[] = 'Links file of page ' . $page . ' found'; - + $fp = fopen($csv, 'rb'); while (true) { @@ -279,7 +288,7 @@ class wsDAODocument extends commonDAO { } $daoBook = new wsDAOBook($this->con); - $pages = $daoBook->getPagesOfBook($book_id); + $pages = $daoBook->getPagesOfBookAt($book_id,$time); foreach ($pages as $p => $infos) { $documents[] = $infos['document_id']; @@ -334,8 +343,18 @@ class wsDAODocument extends commonDAO { } public function getLinksVersions($book_id) { + // Get composition versions + $r = $this->con->select('SELECT * FROM book_pages_versions WHERE book_id=\'' . $this->con->escape($book_id) . '\''); + $docs = array(); + while ($r->fetch()) { + $c = unserialize($r->composition); + foreach ($c as $infos) { + $docs[] = $infos['document_id']; + } + } + $res = array(); - $r = $this->con->select('SELECT l.*,u.prenom,u.nom FROM document_links_versions l LEFT JOIN utilisateurs u ON l.user=u.utilisateur_id WHERE document_id IN(SELECT document_id FROM book_pages WHERE book_id=\'' . $this->con->escape($book_id) . '\')'); + $r = $this->con->select('SELECT l.*,u.prenom,u.nom FROM document_links_versions l LEFT JOIN utilisateurs u ON l.user=u.utilisateur_id WHERE document_id IN(' . implode(',', $docs) . ')'); while ($r->fetch()) { if (!isset($res[$r->update])) { $res[$r->update] = array('links' => 0, 'rulers' => 0); @@ -443,6 +462,96 @@ class wsDAODocument extends commonDAO { return $this->sauve($data); } + public function getLinksAsExcel($links, $rulers) { + $cols = array('document_id' => __('Document'), 'document_page' => __('Page du document'), + 'page' => __('Page de la publication'), 'left' => __('x'), 'top' => __('y'), 'width' => __('Largeur'), 'height' => __('Hauteur'), + 'type' => __('Type'), 'to' => __('Destination'), 'target' => __('Cible'), + 'infobulle' => __('Infobulle'), 'numerotation' => __('Numérotation'), + 'display_area' => __('Activer la surbrillance'), + 'video_loop' => __('Video : boucle'), 'video_auto_start' => __('Video : démarrage automatique'), 'video_controls' => __('Vidéo : afficher les contrôles'), 'video_sound_on' => __('Vidéo : activer le son'), + 'inline' => __('Vidéo : afficher dans la page'), 'video_width' => __('Vidéo : Largeur du popup'), 'video_height' => __('Vidéo : Hauteur du popup'), + 'interactive' => __('Interactivité'), 'video_service' => __('Webvideo : service'), + 'display_area' => __('Afficher le lien au rollover') + ); + + $xls = new PHPExcel(); + $s = $xls->setActiveSheetIndex(0); + $s->setTitle('Links'); + + // Labels + $i = 0; + foreach ($cols as $id => $label) { + $s->setCellValueByColumnAndRow($i, 1, $id); + $s->getColumnDimensionByColumn($i)->setAutoSize(true); + $s->getStyleByColumnAndRow($i, 1)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER); + $i++; + } + // Links + $j = 2; + foreach ($links as $l) { + $i = 0; + foreach ($cols as $id => $label) { + if ($id == 'document_id' || $id == 'document_page') { + $infos = $pages[$l['page']]; + $value = $infos[$id]; + } else { + if (is_bool($l[$id])) { + $l[$id] = $l[$id] ? 1 : 0; + } + if ($id == 'numerotation') { + if ($l[$id] == 'false') { + $l[$id] = 'physical'; + } + } else if ($id == 'display_area') { + if ($l[$id] == '') { + $l[$id] = '1'; + } + } + $value = $l[$id]; + } + + $s->setCellValueByColumnAndRow($i, $j, $value); + $s->getStyleByColumnAndRow($i, $j)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_LEFT); + $i++; + } + $j++; + } + // Rulers + $s = $xls->createSheet(); + $s->setTitle('Rulers'); + + $rcols = array('document_id', 'document_page', 'page', 'type', 'pos'); + $i = 0; + // Labels + foreach ($rcols as $id) { + $s->setCellValueByColumnAndRow($i, 1, $id); + $s->getColumnDimensionByColumn($i)->setAutoSize(true); + $s->getStyleByColumnAndRow($i, 1)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER); + $i++; + } + + // Contents + $j = 2; + foreach ($rulers as $r) { + $i = 0; + foreach ($rcols as $id) { + if ($id == 'document_id' || $id == 'document_page') { + $infos = $pages[$r['page']]; + $value = $infos[$id]; + } else { + $value = $r[$id]; + } + $s->setCellValueByColumnAndRow($i, $j, $value); + $s->getStyleByColumnAndRow($i, $j)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_LEFT); + $i++; + } + $j++; + } + + $xls->setActiveSheetIndex(0); + return $xls; + } + } ?> \ No newline at end of file