From: vincent@cubedesigners.com Date: Tue, 25 Jun 2013 16:29:27 +0000 (+0000) Subject: (no commit message) X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=64fe0c9fcd86e6a55d837e800173112201924277;p=cubeextranet.git --- diff --git a/inc/commons/class.common.core.php b/inc/commons/class.common.core.php index 61489320f..d77339811 100644 --- a/inc/commons/class.common.core.php +++ b/inc/commons/class.common.core.php @@ -354,6 +354,15 @@ class commonCore extends cubeCore { // . $db->document_links_versions->primary('pk_document_links_version', 'document_id', 'update'); $db->document_links_versions->index('idx_document_links_version_update', 'BTREE', 'update'); + + $db->special_links_versions->book_id('integer', 0, false); + $db->special_links_versions->links('text', 0, false); + $db->special_links_versions->rulers('text', 0, false); + $db->special_links_versions->update('integer', 0, false); + + $db->special_links_versions->primary('pk_special_links_versionsn', 'book_id', 'update'); + $db->special_links_versions->index('idx_special_links_versions_update', 'BTREE', 'update'); + // Table Books $db->books->book_id('integer', 0, false); $db->books->cid('varchar', 8, false); diff --git a/inc/ws/Controlleur/class.ws.ajax.php b/inc/ws/Controlleur/class.ws.ajax.php index f8b19ef68..e45e840b9 100644 --- a/inc/ws/Controlleur/class.ws.ajax.php +++ b/inc/ws/Controlleur/class.ws.ajax.php @@ -798,67 +798,13 @@ class wsAjax extends cubeAjax { $dao->getLinksAndRulers($book_id, $links, $rulers, $time); $xls = $dao->getLinksAsExcel($links, $rulers); - self::getLinksFromExcel($xls, $nlinks, $nrulers); + wsLinks::getLinksFromExcel($xls, $nlinks, $nrulers); $dao = new wsDAODocument($core->con); $dao->setLinksAndRulers($book_id, json_encode($nlinks), json_encode($nrulers), 'Restore links from ' . date('Y-m-d H:i:s', $time), $core->user->utilisateur_id); } - public static function getLinksFromExcel($xls, &$links, &$rulers) { - $s = $xls->setActiveSheetIndexByName('Links'); - $i = 0; - $links = array(); - foreach ($s->getRowIterator() as $row) { - $cellIterator = $row->getCellIterator(); - $cellIterator->setIterateOnlyExistingCells(false); - if ($i == 0) { - $cols = array(); - foreach ($cellIterator as $cell) { - $cols[] = $cell->getValue(); - } - } else { - $link = array(); - $j = 0; - foreach ($cellIterator as $cell) { - $link[$cols[$j]] = $cell->getValue(); - $j++; - } - if ($link['display_area'] == '') { - $link['display_area'] = '1'; - } - if (trim($link['infobulle']) == '') { - $link['infobulle'] = ''; - } - $links[] = $link; - } - - $i++; - } - $i = 0; - $rulers = array(); - $s = $xls->setActiveSheetIndexByName('Rulers'); - foreach ($s->getRowIterator() as $row) { - $cellIterator = $row->getCellIterator(); - $cellIterator->setIterateOnlyExistingCells(false); - if ($i == 0) { - $cols = array(); - foreach ($cellIterator as $cell) { - $cols[] = $cell->getValue(); - } - } else { - $link = array(); - $j = 0; - foreach ($cellIterator as $cell) { - $ruler[$cols[$j]] = $cell->getValue(); - $j++; - } - - $rulers[] = $ruler; - } - $i++; - } - } public static function importLinksAsExcel($args) { global $core; @@ -868,7 +814,7 @@ class wsAjax extends cubeAjax { $reader = new PHPExcel_Reader_Excel2007(); $xls = $reader->load($_FILES['file']['tmp_name']); - self::getLinksFromExcel($xls, $links, $rulers); + wsLinks::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.services.php b/inc/ws/Controlleur/class.ws.services.php index d91e7757d..4547dfed5 100644 --- a/inc/ws/Controlleur/class.ws.services.php +++ b/inc/ws/Controlleur/class.ws.services.php @@ -360,7 +360,6 @@ class wsServices extends cubeFlashGateway { - diff --git a/inc/ws/DAO/class.ws.dao.book.php b/inc/ws/DAO/class.ws.dao.book.php index b18a74af7..b1c86855c 100644 --- a/inc/ws/DAO/class.ws.dao.book.php +++ b/inc/ws/DAO/class.ws.dao.book.php @@ -186,7 +186,7 @@ class wsDAOBook extends commonDAO { if ($data['book_id'] == 'new' || $data['book_id'] == '') { $c->date = TIME; - $c->hash = md5(rand(0, 1234567893)); + $c->hash = md5(rand(0, 123456789365469)); $c->compteur_visites = 20; $c->parametres = serialize(new wsParametres()); $c->changedate = TIME; @@ -511,11 +511,35 @@ class wsDAOBook extends commonDAO { } public function setSpecialLinksAndRulers($book_id, $links, $rulers) { + $c1 = $this->con->openCursor('special_links_versions'); $c = $this->con->openCursor('books'); - $c->specialLinks = json_encode(json_decode($links, false)); - $c->specialRulers = json_encode(json_decode($rulers, false)); - $c->changedate = TIME; + + if (is_string($links)) { + $links = json_encode(json_decode($links, false)); + } + if (is_string($rulers)) { + $rulers = json_encode(json_decode($rulers, false)); + } + + 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) { + $c1->update('WHERE book_id=\'' . $this->con->escape($book_id) . '\' AND `update`=' . TIME); + } } public function setTheme($book_id, $theme) { @@ -631,7 +655,7 @@ class wsDAOBook extends commonDAO { } $file = '/home/stats/www/exclude/' . $book_id; - + if (count($ip)) { file_put_contents($file, implode(',', $ip)); chmod($file, 0777); @@ -1323,7 +1347,7 @@ class wsDAOBook extends commonDAO { $flex->addFont(FONT_PATH . '/vagrounded/VAGRoundedStd-Light.otf', 'GeneralFont', $lang->charset); $flex->addFont(FONT_PATH . '/FluidbookCredits.ttf', 'CreditsFont', 'ASCII'); $flexLight->addFont(FONT_PATH . '/vagrounded/VAGRoundedStd-Bold.otf', 'LoaderFont', 'Numerals'); - }else if($theme->parametres->fontKit=='gill'){ + } else if ($theme->parametres->fontKit == 'gill') { $flex->addFont(FONT_PATH . '/gill/gill.ttf', 'BoldFont', $lang->charset); $flex->addFont(FONT_PATH . '/gill/gill.ttf', 'GeneralFont', $lang->charset); $flex->addFont(FONT_PATH . '/FluidbookCredits.ttf', 'CreditsFont', 'ASCII'); diff --git a/inc/ws/DAO/class.ws.dao.document.php b/inc/ws/DAO/class.ws.dao.document.php index 1de7b546c..9119db448 100644 --- a/inc/ws/DAO/class.ws.dao.document.php +++ b/inc/ws/DAO/class.ws.dao.document.php @@ -48,6 +48,14 @@ class wsDAODocument extends commonDAO { while ($r->fetch()) { wsLinks::setDocumentLinks($r->document_id, $r->links, $r->rulers, $user, 'Links restored from ' . date('Y-m-d H:i:s', $update) . ' version', TIME); } + + $r = $this->con->select('SELECT * FROM special_links_versions WHERE `update`=' . $update . ' AND book_id=\'' . $this->con->escape($book_id) . '\''); + if ($r->count()) { + $c = $this->con->openCursor('books'); + $c->specialLinks = $r->links; + $c->specialRulers = $r->rulers; + $c->update('WHERE book_id=\'' . $this->con->escape($book_id) . '\''); + } } public function putLinksFromCSV($document_id) { @@ -158,8 +166,17 @@ class wsDAODocument extends commonDAO { } } + $specialLinks = array(); + $specialRulers = array(); + foreach ($t as $page => $tt) { if (!is_int($page)) { + if (isset($tt['links'])) { + $specialLinks = array_merge($specialLinks, $tt['links']); + } + if (isset($tt['rulers'])) { + $specialRulers = array_merge($specialRulers, $tt['rulers']); + } continue; } $infos = $pages[$page]; @@ -187,6 +204,8 @@ class wsDAODocument extends commonDAO { foreach ($links as $document_id => $dummy) { wsLinks::setDocumentLinks($document_id, json_encode($links[$document_id]), json_encode($rulers[$document_id]), $user, $comments, TIME); } + + $daoBook->setSpecialLinksAndRulers($book_id, $specialLinks, $specialRulers); $c = $this->con->openCursor('books'); $c->changedate = TIME; @@ -294,6 +313,15 @@ class wsDAODocument extends commonDAO { } public function getLinksVersions($book_id) { + $r = $this->con->select('SELECT * FROM special_links_versions WHERE book_id=\'' . $this->con->escape($book_id) . '\''); + $specials = array(); + while ($r->fetch()) { + $ll = json_decode($r->links); + $lr = json_decode($r->rulers); + $specials[$r->update] = array('links' => count($ll), 'rulers' => count($lr)); + } + + // Get composition versions $r = $this->con->select('SELECT * FROM book_pages_versions WHERE book_id=\'' . $this->con->escape($book_id) . '\''); $docs = array(); @@ -308,8 +336,14 @@ class wsDAODocument extends commonDAO { $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); + if (isset($specials[$r->update])) { + $res[$r->update] = $specials[$r->update]; + } else { + $res[$r->update] = array('links' => 0, 'rulers' => 0); + } } + + $ll = json_decode($r->links); foreach ($ll as $lll) { $res[$r->update]['links'] += count($lll); diff --git a/inc/ws/Util/class.ws.links.php b/inc/ws/Util/class.ws.links.php index fa82a2710..10da61d61 100644 --- a/inc/ws/Util/class.ws.links.php +++ b/inc/ws/Util/class.ws.links.php @@ -128,7 +128,7 @@ class wsLinks { $c->user = $user; $c->update = $time; $c->insert(); - + $core->con->execute('DELETE FROM document_links WHERE document_id=' . $document_id); $c1->insert(); } @@ -226,6 +226,62 @@ class wsLinks { $links = array_merge($links, $book->specialLinks); } + public static function getLinksFromExcel($xls, &$links, &$rulers) { + $s = $xls->setActiveSheetIndexByName('Links'); + $i = 0; + $links = array(); + foreach ($s->getRowIterator() as $row) { + $cellIterator = $row->getCellIterator(); + $cellIterator->setIterateOnlyExistingCells(false); + if ($i == 0) { + $cols = array(); + foreach ($cellIterator as $cell) { + $cols[] = $cell->getValue(); + } + } else { + $link = array(); + $j = 0; + foreach ($cellIterator as $cell) { + $link[$cols[$j]] = $cell->getValue(); + $j++; + } + if ($link['display_area'] == '') { + $link['display_area'] = '1'; + } + if (trim($link['infobulle']) == '') { + $link['infobulle'] = ''; + } + $links[] = $link; + } + + $i++; + } + + $i = 0; + $rulers = array(); + $s = $xls->setActiveSheetIndexByName('Rulers'); + foreach ($s->getRowIterator() as $row) { + $cellIterator = $row->getCellIterator(); + $cellIterator->setIterateOnlyExistingCells(false); + if ($i == 0) { + $cols = array(); + foreach ($cellIterator as $cell) { + $cols[] = $cell->getValue(); + } + } else { + $link = array(); + $j = 0; + foreach ($cellIterator as $cell) { + $ruler[$cols[$j]] = $cell->getValue(); + $j++; + } + + $rulers[] = $ruler; + } + $i++; + } + } + } ?> diff --git a/js/ws.js b/js/ws.js index c2237326c..2d16d9439 100644 --- a/js/ws.js +++ b/js/ws.js @@ -124,10 +124,6 @@ function load_ws() { return false; }); - - - - $(".restoreLink").click(restoreLink); $(".hide_new_value").change(function() {