]> _ Git - cubeextranet.git/commitdiff
(no commit message)
authorvincent@cubedesigners.com <vincent@cubedesigners.com@f5622870-0f3c-0410-866d-9cb505b7a8ef>
Wed, 25 May 2011 13:07:01 +0000 (13:07 +0000)
committervincent@cubedesigners.com <vincent@cubedesigners.com@f5622870-0f3c-0410-866d-9cb505b7a8ef>
Wed, 25 May 2011 13:07:01 +0000 (13:07 +0000)
inc/commons/class.common.core.php
inc/ws/Controlleur/class.ws.ajax.php
inc/ws/Controlleur/class.ws.flash.php
inc/ws/Controlleur/class.ws.url.php
inc/ws/DAO/class.ws.dao.document.php

index c0e927ffa422e12dfb8ad529ea9766f5ec53b888..02a7caf5bc2ff36c751f8e3d9409212a350d7741 100644 (file)
@@ -347,6 +347,8 @@ class commonCore extends cubeCore {
                $db->document_links_versions->document_id('integer', 0, false);\r
                $db->document_links_versions->links('text', 0, false);\r
                $db->document_links_versions->rulers('text', 0, false);\r
+               $db->document_links_versions->comments('varchar', 32, false);\r
+               $db->document_links_versions->user('integer', 0, false);\r
                $db->document_links_versions->update('integer', 0, false);\r
                // .\r
                $db->document_links_versions->primary('pk_document_links_version', 'document_id', 'update');\r
index c4bae8d1f8b0f745188f6b42211101191adbd75c..133f72d178dfd0a79d5a094b31c8fdb23c97b213 100644 (file)
@@ -684,7 +684,7 @@ class wsAjax extends cubeAjax {
                $date = $args[2];\r
 \r
                $dao = new wsDAODocument($core->con);\r
-               $dao->restoreLinksVersion($book_id, $date);\r
+               $dao->restoreLinksVersion($book_id, $date,$core->user->utilisateur_id);\r
        }\r
 }\r
 \r
index 665a2399e533b9209d0a0767382839842f352065..f1ba7167047314de59cbf1593161ab7932f656ec 100644 (file)
@@ -453,8 +453,11 @@ class wsFlash extends cubeFlashGateway {
 \r
        public function saveLinks() {\r
                global $core;\r
+               \r
+               $comments=isset($this->args['comments'])?$this->args['comments']:'Saved from editor';\r
+               \r
                $dao = new wsDAODocument($core->con);\r
-               $dao->setLinksAndRulers($this->args['book_id'], $this->args['links'], $this->args['rulers']);\r
+               $dao->setLinksAndRulers($this->args['book_id'], $this->args['links'], $this->args['rulers'],$comments,$core->user->utilisateur_id);\r
 \r
                $daoBook = new wsDAOBook($core->con);\r
                $daoBook->setSpecialLinksAndRulers($this->args['book_id'], $this->args['specialLinks'], $this->args['specialRulers']);\r
index df7bb0f80a9bdd15812717524d49dc7e3c2455d7..23300e0591db8f7251c3d42442481528b8dee510 100644 (file)
@@ -342,11 +342,20 @@ html{height:100%}' . "\n";
                $res .= '</head>';\r
                $res .= '<body onload="this.focus();">';\r
                $res .= '<div id="restoreLinks">';\r
+               $res.='<div class="center" style="padding:15px;">';\r
+               $res.='<form action="' . SITE_PATH . 'importLinksAsExcel/' . $book_id . '" method="post" enctype="multipart/form-data" class="notajax">';\r
+               $res.=__("Importer des liens à partir d'un fichier Excel") . ' : <input type="file" name="file" accept="*.xlsx" />';\r
+               $res.='<input type="submit" value="' . __('Importer') . '" />';\r
+               $res.='</form>';\r
+               $res.='</div>';\r
                $res .= '<table class="liste" style="width:100%;min-width:0;">';\r
                $res .= '<tr>';\r
                $res .= '<th>' . __('Date') . '</th>';\r
-               $res .= '<th class="center">' . __('Nombre de liens') . '</th>';\r
-               $res .= '<th class="center">' . __('Nombre de règles') . '</th>';\r
+               $res .= '<th class="center">' . __('Liens') . '</th>';\r
+               $res .= '<th class="center">' . __('Règles') . '</th>';\r
+               $res.='<th class="center">' . __('Utilisateur') . '</th>';\r
+               $res.='<th class="center">' . __('Informations') . '</th>';\r
+               $res .= '<th class="min"></th>';\r
                $res .= '<th class="min"></th>';\r
                $res .= '</tr>';\r
                $i = 0;\r
@@ -356,7 +365,10 @@ html{height:100%}' . "\n";
                        $res .= '<td>' . date('Y-m-d H:i:s', $time) . '</td>';\r
                        $res .= '<td class="center">' . $infos['links'] . '</td>';\r
                        $res .= '<td class="center">' . $infos['rulers'] . '</td>';\r
+                       $res.='<td class="center">'.$infos['user'].'</td>';\r
+                       $res.='<td class="center">'.$infos['comments'].'</td>';\r
                        $res .= '<td><a href="#" rel="' . $book_id . '/' . $time . '" class="restoreLink">' . __('Restaurer') . '</a></td>';\r
+                       $res .= '<td><a href="' . SITE_PATH . 'exportLinksAsExcel/' . $book_id . '/' . $time . '">' . str_replace(' ', '&nbsp;', __('Export Excel')) . '</a></td>';\r
                        $res .= '</tr>';\r
                        $i++;\r
                }\r
@@ -369,6 +381,175 @@ html{height:100%}' . "\n";
                echo $res;\r
        }\r
 \r
+       public static function exportLinksAsExcel($args) {\r
+               global $core;\r
+\r
+               $book_id = $args[1];\r
+               $time = $args[2];\r
+\r
+               $daoBook = new wsDAOBook($core->con);\r
+               $pages = $daoBook->getPagesOfBook($book_id);\r
+\r
+               $dao = new wsDAODocument($core->con);\r
+               $dao->getLinksAndRulers($book_id, $links, $rulers, $time);\r
+\r
+               $cols = array('document_id' => __('Document'), 'document_page' => __('Page du document'),\r
+                       'page' => __('Page de la publication'), 'left' => __('x'), 'top' => __('y'), 'width' => __('Largeur'), 'height' => __('Hauteur'),\r
+                       'type' => __('Type'), 'to' => __('Destination'), 'target' => __('Cible'),\r
+                       'infobulle' => __('Infobulle'), 'numerotation' => __('Numérotation'),\r
+                       'display_area' => __('Activer la surbrillance'),\r
+                       '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'),\r
+                       'inline' => __('Vidéo : afficher dans la page'), 'video_width' => __('Vidéo : Largeur du popup'), 'video_height' => __('Vidéo : Hauteur du popup'),\r
+                       'interactive' => __('Interactivité'), 'video_service' => __('Webvideo : service')\r
+               );\r
+\r
+               $xls = new PHPExcel();\r
+               $s = $xls->setActiveSheetIndex(0);\r
+               $s->setTitle('Links');\r
+\r
+\r
+\r
+               // Labels\r
+               $i = 0;\r
+               foreach ($cols as $id => $label) {\r
+                       $s->setCellValueByColumnAndRow($i, 1, $id);\r
+                       $s->getColumnDimensionByColumn($i)->setAutoSize(true);\r
+                       $s->getStyleByColumnAndRow($i, 1)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);\r
+                       $i++;\r
+               }\r
+               // Links\r
+               $j = 2;\r
+               foreach ($links as $l) {\r
+                       $i = 0;\r
+                       foreach ($cols as $id => $label) {\r
+                               if ($id == 'document_id' || $id == 'document_page') {\r
+                                       $infos = $pages[$l['page']];\r
+                                       $value = $infos[$id];\r
+                               } else {\r
+                                       if (is_bool($l[$id])) {\r
+                                               $l[$id] = $l[$id] ? 1 : 0;\r
+                                       }\r
+                                       if ($id == 'numerotation') {\r
+                                               if ($l[$id] == 'false') {\r
+                                                       $l[$id] = 'physical';\r
+                                               }\r
+                                       }\r
+                                       $value = $l[$id];\r
+                               }\r
+                               $s->setCellValueByColumnAndRow($i, $j, $value);\r
+                               $s->getStyleByColumnAndRow($i, $j)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_LEFT);\r
+                               $i++;\r
+                       }\r
+                       $j++;\r
+               }\r
+               // Rulers\r
+               $s = $xls->createSheet();\r
+               $s->setTitle('Rulers');\r
+\r
+               $rcols = array('document_id', 'document_page', 'page', 'type', 'pos');\r
+               $i = 0;\r
+               // Labels\r
+               foreach ($rcols as $id) {\r
+                       $s->setCellValueByColumnAndRow($i, 1, $id);\r
+                       $s->getColumnDimensionByColumn($i)->setAutoSize(true);\r
+                       $s->getStyleByColumnAndRow($i, 1)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);\r
+                       $i++;\r
+               }\r
+\r
+               // Contents\r
+               $j = 2;\r
+               foreach ($rulers as $r) {\r
+                       $i = 0;\r
+                       foreach ($rcols as $id) {\r
+                               if ($id == 'document_id' || $id == 'document_page') {\r
+                                       $infos = $pages[$r['page']];\r
+                                       $value = $infos[$id];\r
+                               } else {\r
+                                       $value = $r[$id];\r
+                               }\r
+                               $s->setCellValueByColumnAndRow($i, $j, $value);\r
+                               $s->getStyleByColumnAndRow($i, $j)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_LEFT);\r
+                               $i++;\r
+                       }\r
+                       $j++;\r
+               }\r
+\r
+               $xls->setActiveSheetIndex(0);\r
+\r
+               ob_end_clean();\r
+               files::registerMimeTypes(array('xlsx' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'));\r
+               cubeHTTP::forceDownload('links_' . $book_id . '_' . $time . '.xlsx', false);\r
+\r
+               $writer = new PHPExcel_Writer_Excel2007($xls);\r
+               $writer->save('php://output');\r
+\r
+               exit;\r
+       }\r
+\r
+       public static function importLinksAsExcel($args) {\r
+               global $core;\r
+               $book_id = $args[1];\r
+\r
+               $xls = new PHPExcel();\r
+               $reader = new PHPExcel_Reader_Excel2007();\r
+               $xls = $reader->load($_FILES['file']['tmp_name']);\r
+\r
+               $s = $xls->setActiveSheetIndexByName('Links');\r
+               $i = 0;\r
+               $links = array();\r
+               foreach ($s->getRowIterator() as $row) {\r
+                       $cellIterator = $row->getCellIterator();\r
+                       $cellIterator->setIterateOnlyExistingCells(false);\r
+                       if ($i == 0) {\r
+                               $cols = array();\r
+                               foreach ($cellIterator as $cell) {\r
+                                       $cols[] = $cell->getValue();\r
+                               }\r
+                       } else {\r
+                               $link = array();\r
+                               $j = 0;\r
+                               foreach ($cellIterator as $cell) {\r
+                                       $link[$cols[$j]] = $cell->getValue();\r
+                                       $j++;\r
+                               }\r
+                               $links[] = $link;\r
+                       }\r
+\r
+                       $i++;\r
+               }\r
+\r
+               $i = 0;\r
+               $rulers = array();\r
+               $s = $xls->setActiveSheetIndexByName('Rulers');\r
+               foreach ($s->getRowIterator() as $row) {\r
+                       $cellIterator = $row->getCellIterator();\r
+                       $cellIterator->setIterateOnlyExistingCells(false);\r
+                       if ($i == 0) {\r
+                               $cols = array();\r
+                               foreach ($cellIterator as $cell) {\r
+                                       $cols[] = $cell->getValue();\r
+                               }\r
+                       } else {\r
+                               $link = array();\r
+                               $j = 0;\r
+                               foreach ($cellIterator as $cell) {\r
+                                       $ruler[$cols[$j]] = $cell->getValue();\r
+                                       $j++;\r
+                               }\r
+\r
+                               $rulers[] = $ruler;\r
+                       }\r
+                       $i++;\r
+               }\r
+\r
+\r
+\r
+               $dao = new wsDAODocument($core->con);\r
+               $dao->setLinksAndRulers($book_id, json_encode($links), json_encode($rulers), 'Import from excel',$core->user->utilisateur_id);\r
+\r
+               http::redirect(SITE_PATH . 'restoreLinks/' . $book_id);\r
+       }\r
+\r
        public static function editComposition($args) {\r
                $fv = array(session_name() => session_id(),\r
                        'book_id' => $args[0]);\r
@@ -434,7 +615,7 @@ html{height:100%}' . "\n";
                        $e[2] = TIME;\r
                        //http::redirect(SITE_PATH . 'viewer/' . implode('_', $e) . '/' . $wmode);\r
                        $url = SITE_PATH . 'viewer/' . implode('_', $e) . '/' . $wmode . '/';\r
-                       $url = rtrim($url, '/').'/';\r
+                       $url = rtrim($url, '/') . '/';\r
                        ob_end_clean();\r
                        echo '<script type="text/javascript">window.location=\'' . $url . '\'+window.location.hash;</script>';\r
                        exit;\r
index 73059882b297a145564a7df83774599787ad2cbd..defabeb16935a61547e6e2a56fdd11174bf9bc36 100644 (file)
@@ -33,8 +33,8 @@ class wsDAODocument extends commonDAO {
                }\r
        }\r
 \r
-       public function restoreLinksVersion($book_id, $update) {\r
-               $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 . ')';\r
+       public function restoreLinksVersion($book_id, $update, $user=0) {\r
+               $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 . ')';\r
                $this->con->execute($sql);\r
        }\r
 \r
@@ -102,7 +102,7 @@ class wsDAODocument extends commonDAO {
                return implode("\n", $log);\r
        }\r
 \r
-       public function setLinksAndRulers($book_id, $links, $rulers) {\r
+       public function setLinksAndRulers($book_id, $links, $rulers, $comments='', $user=0) {\r
                $daoBook = new wsDAOBook($this->con);\r
                $pages = $daoBook->getPagesOfBook($book_id);\r
 \r
@@ -157,6 +157,8 @@ class wsDAODocument extends commonDAO {
                        $c->document_id = $document_id;\r
                        $c->links = json_encode($links[$document_id]);\r
                        $c->rulers = json_encode($rulers[$document_id]);\r
+                       $c->comments = $comments;\r
+                       $c->user = $user;\r
                        $c->insert();\r
                }\r
 \r
@@ -177,7 +179,7 @@ class wsDAODocument extends commonDAO {
                $pages = $daoBook->getPagesOfBook($book_id);\r
                $book = $daoBook->selectById($book_id);\r
                $width = $book->parametres->width;\r
-               \r
+\r
                $xml = simplexml_load_file('http://ws.fluidbook.com/books/' . $book_id . '/data/links.xml');\r
                $links = $xml->xpath('//oneLink');\r
 \r
@@ -251,7 +253,7 @@ class wsDAODocument extends commonDAO {
 \r
                $c = $this->con->openCursor('document_links_versions');\r
                $c->update = TIME;\r
-               \r
+\r
                krsort($links);\r
 \r
                foreach ($links as $document_id => $l) {\r
@@ -266,7 +268,14 @@ class wsDAODocument extends commonDAO {
                $c->update('WHERE book_id=\'' . $this->con->escape($book_id) . '\'');\r
        }\r
 \r
-       public function getLinksAndRulers($book_id, &$links, &$rulers) {\r
+       public function getLinksAndRulers($book_id, &$links, &$rulers, $time=null) {\r
+\r
+               if (is_null($time)) {\r
+                       $timeQuery = 'ORDER BY `update` DESC LIMIT 1';\r
+               } else {\r
+                       $timeQuery = 'AND `update`=' . $time;\r
+               }\r
+\r
                $daoBook = new wsDAOBook($this->con);\r
                $pages = $daoBook->getPagesOfBook($book_id);\r
 \r
@@ -282,7 +291,7 @@ class wsDAODocument extends commonDAO {
                $rulers = array();\r
 \r
                foreach ($documents as $d) {\r
-                       $r = $this->con->select('SELECT * FROM document_links_versions WHERE document_id=' . $d . ' ORDER BY `update` DESC LIMIT 1');\r
+                       $r = $this->con->select('SELECT * FROM document_links_versions WHERE document_id=' . $d . ' ' . $timeQuery);\r
 \r
                        if (mb_substr($r->links, 1, 1) == ':') {\r
                                $ll = unserialize($r->links);\r
@@ -324,7 +333,7 @@ class wsDAODocument extends commonDAO {
 \r
        public function getLinksVersions($book_id) {\r
                $res = array();\r
-               $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) . '\')');\r
+               $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
                while ($r->fetch()) {\r
                        if (!isset($res[$r->update])) {\r
                                $res[$r->update] = array('links' => 0, 'rulers' => 0);\r
@@ -337,6 +346,13 @@ class wsDAODocument extends commonDAO {
                        foreach ($rr as $rrr) {\r
                                $res[$r->update]['rulers'] += count($rrr);\r
                        }\r
+                       $res[$r->update]['comments'] = $r->comments;\r
+                       if ($r->user > 0) {\r
+                               $user = $r->prenom . ' ' . $r->nom;\r
+                       } else {\r
+                               $user = '';\r
+                       }\r
+                       $res[$r->update]['user'] = $user;\r
                }\r
                return $res;\r
        }\r