From 7e58265cf16a2fbcba406bfa57e83574b7126cf8 Mon Sep 17 00:00:00 2001 From: "vincent@cubedesigners.com" Date: Thu, 9 Jan 2014 13:08:39 +0000 Subject: [PATCH] --- inc/ws/Controlleur/class.ws.maintenance.php | 1668 ++++++++++--------- 1 file changed, 849 insertions(+), 819 deletions(-) diff --git a/inc/ws/Controlleur/class.ws.maintenance.php b/inc/ws/Controlleur/class.ws.maintenance.php index b3e1e3702..bbcac4f28 100644 --- a/inc/ws/Controlleur/class.ws.maintenance.php +++ b/inc/ws/Controlleur/class.ws.maintenance.php @@ -1,820 +1,850 @@ -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 setCID() { - global $core; - $dao = new wsDAOBook($core->con); - - $r = $core->con->select('SELECT book_id FROM books WHERE cid=\'\''); - $c = $core->con->openCursor('books'); - while ($r->fetch()) { - $c->cid = $dao->generateCID(); - $c->update('WHERE book_id=\'' . $core->con->escape($r->book_id) . '\''); - } - } - - public static function compactLinks() { - global $core; - $r = $core->con->select('SELECT * FROM `document_links_versions` GROUP BY document_id,links,rulers'); - $keep = array(); - while ($r->fetch()) { - if (!isset($keep[$r->document_id])) { - $keep[$r->document_id] = array(); - } - $keep[$r->document_id][] = $r->update; - } - - foreach ($keep as $document_id => $dates) { - $core->con->execute('DELETE FROM document_links_versions WHERE document_id=' . $document_id . ' AND `update` NOT IN(' . implode(',', $dates) . ')'); - } - } - - public static function checkSerializeLinks() { - global $core; - $r = $core->con->select('SELECT * FROM document_links_versions'); - while ($r->fetch()) { - if (substr($r->links, 1, 1) == ':') { - $links = unserialize($r->links); - $rulers = unserialize($r->rulers); - $c = $core->con->openCursor('document_links_versions'); - $c->rulers = json_encode($rulers); - $c->links = json_encode($links); - $c->update('WHERE document_id=' . $r->document_id . ' AND `update`=' . $r->update); - } - } - } - - public static function moveLinksToVersionDB() { - global $core; - $r = $core->con->select('SELECT * FROM document_links'); - $d = array(); - while ($r->fetch()) { - if (!isset($d[$r->document_id])) { - $d[$r->document_id] = array(); - } - if (!isset($d[$r->document_id][$r->update])) { - $d[$r->document_id][$r->update] = array(); - } - if (!isset($d[$r->document_id][$r->update][$r->document_page])) { - $d[$r->document_id][$r->update]['links'][$r->document_page] = json_decode($r->links); - $d[$r->document_id][$r->update]['rulers'][$r->document_page] = json_encode($r->rulers); - } - } - - $c = $core->con->openCursor('document_links_versions'); - foreach ($d as $document_id => $updates) { - $c->document_id = $document_id; - foreach ($updates as $date => $dummy) { - $c->update = $date; - $c->links = json_encode($d[$document_id][$date]['links']); - $c->rulers = json_encode($d[$document_id][$date]['rulers']); - try { - $c->insert(); - } catch (Exception $e) { - // fb($e); - } - } - } - } - - public static function importFromOldWS($args) { - global $core; - // Import des fluidbooks - // Donc le dernier importé est le max dont le numéro est inférieur à 10000 - $r = $core->con->select('SELECT MAX(book_id) AS book_id FROM books WHERE book_id<10000'); - $lastImported = $r->book_id; - // On recherche maintenant les fluidbook dans la vieille base - $r = $core->con->select('SELECT bid FROM ws.book WHERE bid>' . $lastImported); - $oldBooks = array(); - while ($r->fetch()) { - $oldBooks[] = $r->bid; - } - - if (count($oldBooks)) { - self::importLangs($oldBooks); - self::importThemes($oldBooks); - self::importDocs($oldBooks); - self::importBooks($oldBooks); - } - $core->refreshWSUsersTree(); - } - - public static function importLangs($oldBooks) { - global $core, $allTrads, $trads; - // On regarde d'abord les langues que nous avons déjà - $r = $core->con->select('SELECT lang_id FROM langues'); - $already = array(); - while ($r->fetch()) { - $already[] = $r->lang_id; - } - - $toImport = array(); - $r = $core->con->select('SELECT DISTINCT lang FROM ws.book WHERE bid ' . self::_sqlIn($oldBooks)); - while ($r->fetch()) { - $idl = self::_getLangCode($r->lang); - if (in_array($idl, $already)) { - continue; - } - if (strlen($idl) > 2) { - continue; - } - $toImport[] = $r->lang; - } - - $allTrads = array(); - $trad = array(); - $r = $core->con->select('SELECT * FROM ws.lang_trad,ws.lang_ord WHERE lang_trad.idlt=lang_ord.idlt AND idl ' . self::_sqlIn($toImport) . ' '); - while ($r->fetch()) { - $idl = self::_getLangCode($r->idl); - if (!isset($trad[$idl])) { - $trad[$idl] = array(); - } - $trad[$idl][$r->ord] = $r->text; - } - - foreach ($trad as $idl => $t) { - $traductions = wsLang::getTraductionWithId($trad[$idl]); - $allTrads[$idl] = $traductions; - } - - if (!count($toImport)) { - return; - } - - foreach ($toImport as $idl) { - $idl = self::_getLangCode($idl); - - $c = $core->con->openCursor('langues'); - $c->lang_id = $idl; - $c->charset = 'Latin1'; - $c->font = 'Fluidbook.otf'; - $c->traductions = json_encode($allTrads[$idl]); - $c->insert(); - } - } - - public static function importThemes($oldBooks) { - global $core, $signatures; - - $r = $core->con->select('SELECT tid,sigid FROM ws.theme'); - while ($r->fetch()) { - $signatures[$r->tid] = $r->sigid; - } - - $r = $core->con->select('SELECT MAX(theme_id) AS theme_id FROM themes WHERE theme_id<1000'); - $lastImported = $r->theme_id; - // Import des thèmes - $r = $core->con->select('SELECT * FROM ws.theme WHERE tid IN (SELECT tid FROM ws.book WHERE bid ' . self::_sqlIn($oldBooks) . ') AND tid>' . $lastImported); - $theme = new wsTheme(); - while ($r->fetch()) { - $tid = $r->tid; - - $c = $core->con->openCursor('themes'); - $c->theme_id = $r->tid; - $c->proprietaire = self::_getWsUser($r->proprietaire); - $c->date = $r->date; - $c->nom = $r->titre; - - $parametres = new wsThemeParametres($theme); - $parametres->fromRecord($r); - self::_oldIconesToColor($r->iid, $parametres); - $c->parametres = serialize($parametres); - $c->insert(); - - $dest = WS_THEMES . '/' . $tid . '/'; - if (!file_exists($dest)) { - mkdir($dest, 0777, true); - } - - `/bin/cp -r /home/ws/www/themes/$tid/* $dest`; - } - } - - public static function importDocs($oldBooks) { - global $core; - // On cherche maintenant à savoir si l'on doit importer de nouveaux documents associés - $oldDocuments = array(); - $r = $core->con->select('SELECT DISTINCT did FROM ws.book_pages WHERE bid ' . self::_sqlIn($oldBooks) . ''); - while ($r->fetch()) { - $oldDocuments[] = $r->did; - } - - if (!count($oldDocuments)) { - return; - } - - $r = $core->con->select('SELECT * FROM ws.document WHERE did ' . self::_sqlIn($oldDocuments) . ' ORDER BY did'); - while ($r->fetch()) { - $c = $core->con->openCursor('documents'); - $c->document_id = $r->did; - $c->pages = $r->pages; - $c->version = 1; - try { - $c->insert(); - } catch (Exception $e) { - fb($e); - } - } - } - - public static function copyLinks($args) { - list($from, $to) = $args; - global $core; - - $dao = new wsDAODocument($core->con); - - $dao->getLinksAndRulers($from, $fromlinks, $fromrulers); - $dao->getLinksAndRulers($to, $tolinks, $torulers); - - $tolinks = array_merge($tolinks, $fromlinks); - $torulers = array_merge($torulers, $fromrulers); - - $dao->setLinksAndRulers($to, $tolinks, $torulers, 'Copy links from #' . $from . ' to #' . $to, $core->user->utilisateur_id); - } - - public static function importBooks($oldBooks) { - global $core, $allTrads, $signatures; - // Importe les fluidbooks - $r = $core->con->select('SELECT * FROM ws.book WHERE bid ' . self::_sqlIn($oldBooks) . ' ORDER BY bid'); - if (!$r->count()) { - return; - } - // . - while ($r->fetch()) { - $c = $core->con->openCursor('books'); - $c->book_id = $r->bid; - $c->nom = $r->titre; - $c->lang = substr(self::_getLangCode($r->lang), 0, 2); - $c->theme = $r->tid; - if (strlen($r->lang) > 2) { - $c->traductions = json_encode($allTrads[self::_getLangCode($r->lang)]); - } else { - $c->traductions = ''; - } - $c->proprietaire = self::_getWsUser($r->uid); - $c->status = $r->status; - $c->date_status = $r->date_status; - $c->hash = $r->code; - $c->compteur_visites = 20; - $c->date = $r->date; - $c->syncv1 = 1; - $c->version = 1; - $parametres = new wsBookParametres(new stdClass()); - $parametres->fromRecord($r); - - $xml = @simplexml_load_string('' . $r->extras . ''); - if ($xml !== false) { - $parametres->fromXML($xml); - } else { - - } - - $n = array(); - // Pages sans numéro - $offset = $r->first_page_nr - 1; - for ($i = 0; $i < $offset; $i++) { - $n[] = ''; - } - // Pages avec numero - for ($j = 1; $j + $offset <= $r->pages; $j++) { - $n[] = $j; - } - $c->numerotation = implode(',', $n); - - $parametres->signature = $signatures[$r->tid]; - $parametres->title = $r->titre; - $parametres->visualisationMode = '2'; - $c->parametres = serialize($parametres); - $c->version = 1; - $c->insert(); - } - // 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) { - global $oldIconesColors; - if (!isset($oldIconesColors)) { - $oldIconesColors = array(); - $fp = fopen(dirname(__FILE__) . '/../../../icones.csv', 'rb'); - $i = 1; - while ($line = fgetcsv($fp, 1000, ';', '"')) { - $oldIconesColors[$i] = array('color' => trim($line[0]), 'iid' => trim($line[1])); - $i++; - } - } - $line = $oldIconesColors[$iid]; - if ($line['iid'] != '') { - $parametres->iconSet = $line['iid']; - $parametres->iconsHMargin = $line['iid'] == 1 ? 20 : 0; - $parametres->menuHeight = 39; - $parametres->colorizeIcons = false; - $parametres->couleurI = 'ffffff'; - } else { - $parametres->iconSet = 1; - $parametres->colorizeIcons = 1; - $parametres->iconsHMargin = 20; - $parametres->menuHeight = 39; - $parametres->couleurI = $line['color']; - } - } - - protected static function _getWsUser($oldid) { - global $ws2ext; - if (!isset($ws2ext)) { - self::_getAllUsers(); - } - if (!isset($ws2ext[$oldid])) { - self::_importOldUser($oldid); - } - if (!isset($ws2ext[$oldid])) { - $ws2ext[$oldid] = 1; - } - return $ws2ext[$oldid]; - } - - protected static function _getAllUsers() { - global $core, $entreprises, $entreprise_id, $utilisateurs_entreprises, $utilisateur_id, $ws2ext, $grades, $utilisateurs; - $grades = array(0 => 1, 0.4 => 1, '0.4' => 1, 0.5 => 1, '0.5' => 1, 1 => 1, 2 => 2, 3 => 3, 4 => 5); - // Contrôle des entreprises déjà dans la base extranet - $entreprises = array(); - $entreprise_id = 0; - $r = $core->con->select('SELECT entreprise_id,nom FROM entreprises'); - while ($r->fetch()) { - $nom = mb_strtolower(trim($r->nom)); - $nom = cubeText::str2URL($nom); - $entreprises[$nom] = $r->entreprise_id; - $entreprise_id = max($entreprise_id, $r->entreprise_id); - } - - $utilisateurs_entreprises = array(); - $r = $core->con->select('SELECT entreprise,utilisateur_id FROM utilisateurs'); - while ($r->fetch()) { - $utilisateurs_entreprises[$r->utilisateur_id] = $r->entreprise; - } - - $entreprise_id++; - // Obtient les emails des utilisateurs - $utilisateur_id = 0; - $utilisateurs = array(); - $r = $core->con->select('SELECT utilisateur_id,email FROM utilisateurs'); - while ($r->fetch()) { - $utilisateur_id = max($r->utilisateur_id, $utilisateur_id); - $utilisateurs[trim(mb_strtolower($r->email))] = $r->utilisateur_id; - } - $utilisateur_id++; - - $ws2ext = array(); - $r = $core->con->select('SELECT ws_id,utilisateur_id,entreprise FROM utilisateurs WHERE ws_id IS NOT NULL'); - while ($r->fetch()) { - $ws2ext[$r->ws_id] = $r->utilisateur_id; - } - } - - protected static function _importOldUser($oldid) { - global $core, $entreprises, $entreprise_id, $utilisateurs_entreprises, $utilisateur_id, $ws2ext, $grades, $utilisateurs; - // Get user from old - $r = $core->con->select('SELECT * FROM ws.user WHERE uid=\'' . $core->con->escape($oldid) . '\''); - if ($r->extranet != 0) { - $ws2ext[$r->uid] = $r->extranet; - return; - } - // On s'occupe de l'entreprise - $email = trim(mb_strtolower($r->email)); - - $rs = trim($r->rs); - if ($rs == '') { - $rs = trim($r->prenom . ' ' . $r->nom); - } - $nom = mb_strtolower($rs); - - $nom = cubeText::str2URL($nom); - - if (isset($utilisateurs[$email])) { - $newid = $utilisateurs[$email]; - $e = $utilisateurs_entreprises[$newid]; - $update = true; - } elseif (isset($entreprises[$nom])) { - $e = $entreprises[$nom]; - $update = true; - } else { - $c = $core->con->openCursor('entreprises'); - $c->entreprise_id = $entreprise_id; - $c->nom = $rs; - $c->adresse = $r->adresse; - $c->code_postal = $r->code_postal; - $c->ville = $r->ville; - $c->pays = $r->pays; - $c->date_creation = $r->date; - $c->ws_grade = $grades[$r->grade]; - $c->ws_admin = self::_getWsUser($r->admin); - $c->insert(); - $e = $entreprises[$nom] = $entreprise_id; - $entreprise_id++; - $update = false; - } - - if ($update) { - $c = $core->con->openCursor('entreprises'); - $c->ws_grade = $grades[$r->grade]; - $c->ws_admin = self::_getWsUser($r->admin); - $c->update('WHERE entreprise_id=\'' . $e . '\''); - } - // Puis de l'utilisateur - if (isset($utilisateurs[$email])) { - $c = $core->con->openCursor('utilisateurs'); - $c->ws_password = $r->password; - $c->ws_id = $r->uid; - $c->update('WHERE utilisateur_id=\'' . $utilisateurs[$email] . '\''); - $ws2ext[$r->uid] = $utilisateurs[$email]; - $utilisateurs_entreprises[$utilisateurs[$email]] = $e; - } else { - $c = $core->con->openCursor('utilisateurs'); - $c->utilisateur_id = $utilisateur_id; - $c->entreprise = $e; - $c->nom = $r->nom; - $c->prenom = $r->prenom; - $c->email = $r->email; - $c->password = $r->password; - $c->adresse = $r->adresse; - $c->code_postal = $r->code_postal; - $c->ville = $r->ville; - $c->pays = $r->pays; - $c->lang = $r->lang; - $c->telephone = $r->telephone; - $c->date_creation = $r->date; - $c->notes = 'Inséré à l\'import vers le nouveau Fluidbook Workshop'; - $c->ws_password = $r->password; - $c->ws_id = $r->uid; - $c->insert(); - $ws2ext[$r->uid] = $utilisateur_id; - $utilisateurs_entreprises[$utilisateur_id] = $e; - $utilisateur_id++; - } - } - - protected static function _sqlIn($tab) { - return ' IN(\'' . implode('\',\'', $tab) . '\') '; - } - - protected static function _getLangCode($lang) { - $lang = strtolower($lang); - if ($lang == 'cz') { - $lang = 'cs'; - } - return $lang; - } - - public static function dumpDatabase() { - cubeDb::mysqlDump(DB_HOST, DB_NAME, DB_USER, DB_PASSWORD, ROOT . '/backups/dump-' . date('Y-m-d-H-i-s') . '.sql', true, 8); - } - - public static function cleanPackages() { - $limit = TIME - (4 * 3600); // 4 heures avant maintenant* - // - $dirs = array(ROOT . '/cache/download', - WS_FILES . '/packager/download/', - WS_FILES . '/packager/', - '/home/ws/www/download'); - // Clean downloads - - foreach ($dirs as $dir) { - if (!file_exists($dir)) { - continue; - } - $dr = opendir($dir); - while ($file = readdir($dr)) { - if ($file == '.' || $file == '..') { - continue; - } - $f = $dir . $file; - if (!is_dir($f)) { - continue; - } - if (filemtime($f) > $limit) { - continue; - } - `rm -rf $f`; - } - - if (!file_exists($dir)) { - mkdir($dir, 0777, true); - } - } - } - - public static function cleanConversionSessions() { - $limit = TIME - (4 * 3600); // 4 heures avant maintenant* - - $dir = ROOT . '/cache/conversionSessions/'; - $dr = opendir($dir); - while ($file = readdir($dr)) { - if ($file == '.' || $file == '..') { - continue; - } - $f = $dir . $file; - if (filemtime($f) > $limit) { - continue; - } - unlink($f); - } - } - - public static function cleanUnusedDocs() { - global $core; - cubePHP::neverStop(); - $r = $core->con->select('SELECT document_id FROM documents WHERE document_id NOT IN (SELECT document_id FROM book_pages)'); - while ($r->fetch()) { - if (file_exists(WS_DOCS . '/' . $r->document_id)) { - $rm = new cubeCommandLine('rm'); - $rm->setPath(CONVERTER_PATH); - $rm->setArg('r'); - $rm->setArg('f'); - $rm->setArg(null, WS_DOCS . '/' . $r->document_id . '/'); - $rm->execute(); - echo $rm->commande . "
"; - } - } - } - - public static function moveFluidbookDatas() { - $dir = WS_BOOKS . '/final/'; - $dr = opendir($dir); - while ($d = readdir($dr)) { - if ($d == '.' || $d == '..' || !is_dir($dir . $d)) { - continue; - } - rename($dir . $d . '/FluidbookDatas.swf', $dir . $d . '/data/fd.swf'); - rename($dir . $d . '/FluidbookDatasLight.swf', $dir . $d . '/data/fdl.swf'); - } - } - - public static function mergeEntreprise($args) { - global $core; - - $from = $args[0]; - $to = $args[1]; - - $c = $core->con->openCursor('utilisateurs'); - $c->entreprise = $to; - $c->update('WHERE entreprise=' . $from); - - $core->con->execute('DELETE FROM entreprises WHERE entreprise_id=' . $from); - - $core->refreshWSUsersTree(); - } - - public static function updateLuceneTime() { - global $core; - $dao = new wsDAOBook($core->con); - $books = $dao->selectLuceneTimeNotSet(); - foreach ($books as $book) { - $index = WS_BOOKS . '/search/' . $book->book_id; - if (!file_exists($index)) { - fb($book->book_id, 'Skip'); - continue; - } - - $mtime = 0; - $dr = opendir($index); - while ($file = readdir($dr)) { - if ($file == '.' || $file == '..') { - continue; - } - $mtime = max($mtime, filemtime($index . '/' . $file)); - } - - $c = $core->con->openCursor('books'); - $c->lucene_time = $mtime; - $c->update('WHERE book_id=' . $book->book_id); - - fb($book->book_id, 'Update : ' . $mtime); - } - } - - public static function makeLuceneIndexes() { - global $core; - - cubePHP::neverStop(); - - $dao = new wsDAOBook($core->con); - $books = $dao->selectLuceneToDo(); - foreach ($books as $book) { - $pages = $dao->getPagesOfBook($book->book_id); - $dao->indexPDF($book, $pages); - } - } - - public static function restoreComposition($args) { - global $core; - $book_id = $args[0]; - - $r = $core->con->select('SELECT * FROM book_pages_versions WHERE book_id=\'' . $core->con->escape($book_id) . '\' AND composition!=\'a:0:{}\' ORDER BY `update` DESC LIMIT 1'); - if (!$r->count()) { - return; - } - - $comp = unserialize($r->composition); - $core->con->execute('DELETE FROM book_pages WHERE book_id=\'' . $core->con->escape($book_id) . '\''); - - $c = $core->con->openCursor('book_pages'); - $c->book_id = $book_id; - foreach ($comp as $book_page => $infos) { - $c->book_page = $book_page; - $c->document_id = $infos['document_id']; - $c->document_page = $infos['document_page']; - $c->insert(); - } - } - - public static function getV1Translations() { - wsLang::getV1Translations(); - } - - public static function appendDocument($args) { - global $core; - $book_id = $args[0]; - $document_id = $args[1]; - $dao = new wsDAOBook($core->con); - $dao->appendDocument($book_id, $document_id); - } - - public static function reprocessVideos($args) { - global $core; - - $book_id = $args[0]; - - $dir = WS_BOOKS . '/working/' . $book_id; - - $dao = new wsDAODocument($core->con); - $dao->getLinksAndRulers($book_id, $links, $rulers); - - foreach ($links as $link) { - if ($link['type'] != 4) { - continue; - } - - $file = $dir . '/' . $link['to']; - if (!file_exists($file)) { - continue; - } - - wsTools::encodeWebVideos($file, null, true, true); - } - } - - public static function syncLDAP() { - global $core; - cubePHP::neverStop(); - - $res = '
';
-
-		$ds = ldap_connect('localhost', 10389);
-		ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3);
-		ldap_bind($ds, 'uid=admin,ou=system', '*arica*6');
-
-		$r = $core->con->select('SELECT * FROM utilisateurs_entreprise ORDER BY utilisateur_id');
-		while ($r->fetch()) {
-			if (is_null($r->utilisateur_id)) {
-				continue;
-			}
-			$entree = array();
-			$entree['objectClass'][] = 'top';
-			$entree['objectClass'][] = 'person';
-			$entree['objectClass'][] = 'organizationalPerson';
-			$entree['objectClass'][] = 'extensibleObject';
-			$entree['cn'] = trim($r->prenom . ' ' . $r->nom . ' - ' . $r->rs . ' (' . $r->utilisateur_id . ')', ' -');
-			$entree['sn'] = $r->nom == '' ? $entree['cn'] : $r->nom;
-			$entree['mail'] = $r->email;
-			$entree['uid'] = 'extranet_' . $r->utilisateur_id;
-			$entree['OrganizationalUnitName'] = $r->rs;
-			if ($r->telephone && $r->telephone != '+33') {
-				$entree['telephoneNumber'][] = $r->telephone;
-			}
-			if ($r->mobile && $r->mobile != '+33') {
-				$entree['telephoneNumber'][] = $r->mobile;
-			}
-			if ($r->fax && $r->fax != '+33') {
-				$entree['telexNumber'] = $r->fax;
-			}
-			$dn = 'uid=' . $entree['uid'] . ',o=cubedesigners';
-			if (!ldap_add($ds, $dn, $entree)) {
-				$e = ldap_error($ds);
-				if ($e == 'Already exists') {
-					ldap_modify($ds, $dn, $entree);
-				} else {
-					fb($entree, $e);
-				}
-			}
-		}
-		$res = 'test';
-		$res.='
'; - - ldap_close($ds); - return $res; - } - - public static function updateHTML5Sources($args = array(), $externals = true) { - $svn = new cubeCommandLine('updatewshtml5prod'); - $svn->setPath(CONVERTER_PATH); - $svn->execute(); - } - - public static function cleanDownload($args) { - $root = ROOT . '/cache/download/'; - cubeFiles::scanRecursiveDir($root, $files); - $limit = TIME - 14400; - foreach ($files as $f) { - if (filemtime($f) < $limit) { - unlink($f); - } - } - $files = cubeFiles::scandir($root, true); - foreach ($files as $f) { - if (cubeFiles::isEmpty($f)) { - @rmdir($f); - } - } - } - - public static function deleteOldFilesFromFTP($args) { - global $core; - cubePHP::neverStop(); - - $dao = new commonDAOFichier($core->con); - $dao->deleteOldFiles(); - - cubeFiles::deleteFilesOlderThan('/home/ws/ftp', 60, array('*.ipa', '*.apk')); - cubeFiles::deleteFilesOlderThan('/home/ws/www/getpdf', 60); - } - - public static function reencodeVideos($args) { - - cubePHP::neverStop(); - - $book_id = $args[0]; - $dir = WS_BOOKS . '/working/' . $book_id; - - wsLinks::getLinksAndRulers($book_id, $links, $rulers); - - foreach ($links as $link) { - if ($link['type'] != 4) { - continue; - } - - $file = $dir . '/' . $link['to']; - if (!file_exists($file)) { - continue; - } - - wsTools::encodeWebVideos($file, null, false, true); - } - } - - public static function correctAutoBookmarkLinks($args) { - global $core; - $book_id = $args[0]; - wsLinks::getLinksAndRulers($book_id, $links, $rulers); - - - $newlinks = array(); - foreach ($links as $link) { - $link['left']-=1; - $link['top']+=1; - $link['width']+=5; - $link['height']+=3; - $newlinks[] = $link; - } - - $dao = new wsDAODocument($core->con); - $dao->setLinksAndRulers($book_id, json_encode($newlinks), json_encode($rulers), 'Autobookmark links correction', $core->user->utilisateur_id); - } - -} - +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 setCID() { + global $core; + $dao = new wsDAOBook($core->con); + + $r = $core->con->select('SELECT book_id FROM books WHERE cid=\'\''); + $c = $core->con->openCursor('books'); + while ($r->fetch()) { + $c->cid = $dao->generateCID(); + $c->update('WHERE book_id=\'' . $core->con->escape($r->book_id) . '\''); + } + } + + public static function compactLinks() { + global $core; + $r = $core->con->select('SELECT * FROM `document_links_versions` GROUP BY document_id,links,rulers'); + $keep = array(); + while ($r->fetch()) { + if (!isset($keep[$r->document_id])) { + $keep[$r->document_id] = array(); + } + $keep[$r->document_id][] = $r->update; + } + + foreach ($keep as $document_id => $dates) { + $core->con->execute('DELETE FROM document_links_versions WHERE document_id=' . $document_id . ' AND `update` NOT IN(' . implode(',', $dates) . ')'); + } + } + + public static function checkSerializeLinks() { + global $core; + $r = $core->con->select('SELECT * FROM document_links_versions'); + while ($r->fetch()) { + if (substr($r->links, 1, 1) == ':') { + $links = unserialize($r->links); + $rulers = unserialize($r->rulers); + $c = $core->con->openCursor('document_links_versions'); + $c->rulers = json_encode($rulers); + $c->links = json_encode($links); + $c->update('WHERE document_id=' . $r->document_id . ' AND `update`=' . $r->update); + } + } + } + + public static function moveLinksToVersionDB() { + global $core; + $r = $core->con->select('SELECT * FROM document_links'); + $d = array(); + while ($r->fetch()) { + if (!isset($d[$r->document_id])) { + $d[$r->document_id] = array(); + } + if (!isset($d[$r->document_id][$r->update])) { + $d[$r->document_id][$r->update] = array(); + } + if (!isset($d[$r->document_id][$r->update][$r->document_page])) { + $d[$r->document_id][$r->update]['links'][$r->document_page] = json_decode($r->links); + $d[$r->document_id][$r->update]['rulers'][$r->document_page] = json_encode($r->rulers); + } + } + + $c = $core->con->openCursor('document_links_versions'); + foreach ($d as $document_id => $updates) { + $c->document_id = $document_id; + foreach ($updates as $date => $dummy) { + $c->update = $date; + $c->links = json_encode($d[$document_id][$date]['links']); + $c->rulers = json_encode($d[$document_id][$date]['rulers']); + try { + $c->insert(); + } catch (Exception $e) { + // fb($e); + } + } + } + } + + public static function importFromOldWS($args) { + global $core; + // Import des fluidbooks + // Donc le dernier importé est le max dont le numéro est inférieur à 10000 + $r = $core->con->select('SELECT MAX(book_id) AS book_id FROM books WHERE book_id<10000'); + $lastImported = $r->book_id; + // On recherche maintenant les fluidbook dans la vieille base + $r = $core->con->select('SELECT bid FROM ws.book WHERE bid>' . $lastImported); + $oldBooks = array(); + while ($r->fetch()) { + $oldBooks[] = $r->bid; + } + + if (count($oldBooks)) { + self::importLangs($oldBooks); + self::importThemes($oldBooks); + self::importDocs($oldBooks); + self::importBooks($oldBooks); + } + $core->refreshWSUsersTree(); + } + + public static function importLangs($oldBooks) { + global $core, $allTrads, $trads; + // On regarde d'abord les langues que nous avons déjà + $r = $core->con->select('SELECT lang_id FROM langues'); + $already = array(); + while ($r->fetch()) { + $already[] = $r->lang_id; + } + + $toImport = array(); + $r = $core->con->select('SELECT DISTINCT lang FROM ws.book WHERE bid ' . self::_sqlIn($oldBooks)); + while ($r->fetch()) { + $idl = self::_getLangCode($r->lang); + if (in_array($idl, $already)) { + continue; + } + if (strlen($idl) > 2) { + continue; + } + $toImport[] = $r->lang; + } + + $allTrads = array(); + $trad = array(); + $r = $core->con->select('SELECT * FROM ws.lang_trad,ws.lang_ord WHERE lang_trad.idlt=lang_ord.idlt AND idl ' . self::_sqlIn($toImport) . ' '); + while ($r->fetch()) { + $idl = self::_getLangCode($r->idl); + if (!isset($trad[$idl])) { + $trad[$idl] = array(); + } + $trad[$idl][$r->ord] = $r->text; + } + + foreach ($trad as $idl => $t) { + $traductions = wsLang::getTraductionWithId($trad[$idl]); + $allTrads[$idl] = $traductions; + } + + if (!count($toImport)) { + return; + } + + foreach ($toImport as $idl) { + $idl = self::_getLangCode($idl); + + $c = $core->con->openCursor('langues'); + $c->lang_id = $idl; + $c->charset = 'Latin1'; + $c->font = 'Fluidbook.otf'; + $c->traductions = json_encode($allTrads[$idl]); + $c->insert(); + } + } + + public static function importThemes($oldBooks) { + global $core, $signatures; + + $r = $core->con->select('SELECT tid,sigid FROM ws.theme'); + while ($r->fetch()) { + $signatures[$r->tid] = $r->sigid; + } + + $r = $core->con->select('SELECT MAX(theme_id) AS theme_id FROM themes WHERE theme_id<1000'); + $lastImported = $r->theme_id; + // Import des thèmes + $r = $core->con->select('SELECT * FROM ws.theme WHERE tid IN (SELECT tid FROM ws.book WHERE bid ' . self::_sqlIn($oldBooks) . ') AND tid>' . $lastImported); + $theme = new wsTheme(); + while ($r->fetch()) { + $tid = $r->tid; + + $c = $core->con->openCursor('themes'); + $c->theme_id = $r->tid; + $c->proprietaire = self::_getWsUser($r->proprietaire); + $c->date = $r->date; + $c->nom = $r->titre; + + $parametres = new wsThemeParametres($theme); + $parametres->fromRecord($r); + self::_oldIconesToColor($r->iid, $parametres); + $c->parametres = serialize($parametres); + $c->insert(); + + $dest = WS_THEMES . '/' . $tid . '/'; + if (!file_exists($dest)) { + mkdir($dest, 0777, true); + } + + `/bin/cp -r /home/ws/www/themes/$tid/* $dest`; + } + } + + public static function importDocs($oldBooks) { + global $core; + // On cherche maintenant à savoir si l'on doit importer de nouveaux documents associés + $oldDocuments = array(); + $r = $core->con->select('SELECT DISTINCT did FROM ws.book_pages WHERE bid ' . self::_sqlIn($oldBooks) . ''); + while ($r->fetch()) { + $oldDocuments[] = $r->did; + } + + if (!count($oldDocuments)) { + return; + } + + $r = $core->con->select('SELECT * FROM ws.document WHERE did ' . self::_sqlIn($oldDocuments) . ' ORDER BY did'); + while ($r->fetch()) { + $c = $core->con->openCursor('documents'); + $c->document_id = $r->did; + $c->pages = $r->pages; + $c->version = 1; + try { + $c->insert(); + } catch (Exception $e) { + fb($e); + } + } + } + + public static function copyLinks($args) { + list($from, $to) = $args; + global $core; + + $dao = new wsDAODocument($core->con); + + $dao->getLinksAndRulers($from, $fromlinks, $fromrulers); + $dao->getLinksAndRulers($to, $tolinks, $torulers); + + $tolinks = array_merge($tolinks, $fromlinks); + $torulers = array_merge($torulers, $fromrulers); + + $dao->setLinksAndRulers($to, $tolinks, $torulers, 'Copy links from #' . $from . ' to #' . $to, $core->user->utilisateur_id); + } + + public static function importBooks($oldBooks) { + global $core, $allTrads, $signatures; + // Importe les fluidbooks + $r = $core->con->select('SELECT * FROM ws.book WHERE bid ' . self::_sqlIn($oldBooks) . ' ORDER BY bid'); + if (!$r->count()) { + return; + } + // . + while ($r->fetch()) { + $c = $core->con->openCursor('books'); + $c->book_id = $r->bid; + $c->nom = $r->titre; + $c->lang = substr(self::_getLangCode($r->lang), 0, 2); + $c->theme = $r->tid; + if (strlen($r->lang) > 2) { + $c->traductions = json_encode($allTrads[self::_getLangCode($r->lang)]); + } else { + $c->traductions = ''; + } + $c->proprietaire = self::_getWsUser($r->uid); + $c->status = $r->status; + $c->date_status = $r->date_status; + $c->hash = $r->code; + $c->compteur_visites = 20; + $c->date = $r->date; + $c->syncv1 = 1; + $c->version = 1; + $parametres = new wsBookParametres(new stdClass()); + $parametres->fromRecord($r); + + $xml = @simplexml_load_string('' . $r->extras . ''); + if ($xml !== false) { + $parametres->fromXML($xml); + } else { + + } + + $n = array(); + // Pages sans numéro + $offset = $r->first_page_nr - 1; + for ($i = 0; $i < $offset; $i++) { + $n[] = ''; + } + // Pages avec numero + for ($j = 1; $j + $offset <= $r->pages; $j++) { + $n[] = $j; + } + $c->numerotation = implode(',', $n); + + $parametres->signature = $signatures[$r->tid]; + $parametres->title = $r->titre; + $parametres->visualisationMode = '2'; + $c->parametres = serialize($parametres); + $c->version = 1; + $c->insert(); + } + // 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) { + global $oldIconesColors; + if (!isset($oldIconesColors)) { + $oldIconesColors = array(); + $fp = fopen(dirname(__FILE__) . '/../../../icones.csv', 'rb'); + $i = 1; + while ($line = fgetcsv($fp, 1000, ';', '"')) { + $oldIconesColors[$i] = array('color' => trim($line[0]), 'iid' => trim($line[1])); + $i++; + } + } + $line = $oldIconesColors[$iid]; + if ($line['iid'] != '') { + $parametres->iconSet = $line['iid']; + $parametres->iconsHMargin = $line['iid'] == 1 ? 20 : 0; + $parametres->menuHeight = 39; + $parametres->colorizeIcons = false; + $parametres->couleurI = 'ffffff'; + } else { + $parametres->iconSet = 1; + $parametres->colorizeIcons = 1; + $parametres->iconsHMargin = 20; + $parametres->menuHeight = 39; + $parametres->couleurI = $line['color']; + } + } + + protected static function _getWsUser($oldid) { + global $ws2ext; + if (!isset($ws2ext)) { + self::_getAllUsers(); + } + if (!isset($ws2ext[$oldid])) { + self::_importOldUser($oldid); + } + if (!isset($ws2ext[$oldid])) { + $ws2ext[$oldid] = 1; + } + return $ws2ext[$oldid]; + } + + protected static function _getAllUsers() { + global $core, $entreprises, $entreprise_id, $utilisateurs_entreprises, $utilisateur_id, $ws2ext, $grades, $utilisateurs; + $grades = array(0 => 1, 0.4 => 1, '0.4' => 1, 0.5 => 1, '0.5' => 1, 1 => 1, 2 => 2, 3 => 3, 4 => 5); + // Contrôle des entreprises déjà dans la base extranet + $entreprises = array(); + $entreprise_id = 0; + $r = $core->con->select('SELECT entreprise_id,nom FROM entreprises'); + while ($r->fetch()) { + $nom = mb_strtolower(trim($r->nom)); + $nom = cubeText::str2URL($nom); + $entreprises[$nom] = $r->entreprise_id; + $entreprise_id = max($entreprise_id, $r->entreprise_id); + } + + $utilisateurs_entreprises = array(); + $r = $core->con->select('SELECT entreprise,utilisateur_id FROM utilisateurs'); + while ($r->fetch()) { + $utilisateurs_entreprises[$r->utilisateur_id] = $r->entreprise; + } + + $entreprise_id++; + // Obtient les emails des utilisateurs + $utilisateur_id = 0; + $utilisateurs = array(); + $r = $core->con->select('SELECT utilisateur_id,email FROM utilisateurs'); + while ($r->fetch()) { + $utilisateur_id = max($r->utilisateur_id, $utilisateur_id); + $utilisateurs[trim(mb_strtolower($r->email))] = $r->utilisateur_id; + } + $utilisateur_id++; + + $ws2ext = array(); + $r = $core->con->select('SELECT ws_id,utilisateur_id,entreprise FROM utilisateurs WHERE ws_id IS NOT NULL'); + while ($r->fetch()) { + $ws2ext[$r->ws_id] = $r->utilisateur_id; + } + } + + protected static function _importOldUser($oldid) { + global $core, $entreprises, $entreprise_id, $utilisateurs_entreprises, $utilisateur_id, $ws2ext, $grades, $utilisateurs; + // Get user from old + $r = $core->con->select('SELECT * FROM ws.user WHERE uid=\'' . $core->con->escape($oldid) . '\''); + if ($r->extranet != 0) { + $ws2ext[$r->uid] = $r->extranet; + return; + } + // On s'occupe de l'entreprise + $email = trim(mb_strtolower($r->email)); + + $rs = trim($r->rs); + if ($rs == '') { + $rs = trim($r->prenom . ' ' . $r->nom); + } + $nom = mb_strtolower($rs); + + $nom = cubeText::str2URL($nom); + + if (isset($utilisateurs[$email])) { + $newid = $utilisateurs[$email]; + $e = $utilisateurs_entreprises[$newid]; + $update = true; + } elseif (isset($entreprises[$nom])) { + $e = $entreprises[$nom]; + $update = true; + } else { + $c = $core->con->openCursor('entreprises'); + $c->entreprise_id = $entreprise_id; + $c->nom = $rs; + $c->adresse = $r->adresse; + $c->code_postal = $r->code_postal; + $c->ville = $r->ville; + $c->pays = $r->pays; + $c->date_creation = $r->date; + $c->ws_grade = $grades[$r->grade]; + $c->ws_admin = self::_getWsUser($r->admin); + $c->insert(); + $e = $entreprises[$nom] = $entreprise_id; + $entreprise_id++; + $update = false; + } + + if ($update) { + $c = $core->con->openCursor('entreprises'); + $c->ws_grade = $grades[$r->grade]; + $c->ws_admin = self::_getWsUser($r->admin); + $c->update('WHERE entreprise_id=\'' . $e . '\''); + } + // Puis de l'utilisateur + if (isset($utilisateurs[$email])) { + $c = $core->con->openCursor('utilisateurs'); + $c->ws_password = $r->password; + $c->ws_id = $r->uid; + $c->update('WHERE utilisateur_id=\'' . $utilisateurs[$email] . '\''); + $ws2ext[$r->uid] = $utilisateurs[$email]; + $utilisateurs_entreprises[$utilisateurs[$email]] = $e; + } else { + $c = $core->con->openCursor('utilisateurs'); + $c->utilisateur_id = $utilisateur_id; + $c->entreprise = $e; + $c->nom = $r->nom; + $c->prenom = $r->prenom; + $c->email = $r->email; + $c->password = $r->password; + $c->adresse = $r->adresse; + $c->code_postal = $r->code_postal; + $c->ville = $r->ville; + $c->pays = $r->pays; + $c->lang = $r->lang; + $c->telephone = $r->telephone; + $c->date_creation = $r->date; + $c->notes = 'Inséré à l\'import vers le nouveau Fluidbook Workshop'; + $c->ws_password = $r->password; + $c->ws_id = $r->uid; + $c->insert(); + $ws2ext[$r->uid] = $utilisateur_id; + $utilisateurs_entreprises[$utilisateur_id] = $e; + $utilisateur_id++; + } + } + + protected static function _sqlIn($tab) { + return ' IN(\'' . implode('\',\'', $tab) . '\') '; + } + + protected static function _getLangCode($lang) { + $lang = strtolower($lang); + if ($lang == 'cz') { + $lang = 'cs'; + } + return $lang; + } + + public static function dumpDatabase() { + cubeDb::mysqlDump(DB_HOST, DB_NAME, DB_USER, DB_PASSWORD, ROOT . '/backups/dump-' . date('Y-m-d-H-i-s') . '.sql', true, 8); + } + + public static function cleanPackages() { + $limit = TIME - (4 * 3600); // 4 heures avant maintenant* + // + $dirs = array(ROOT . '/cache/download', + WS_FILES . '/packager/download/', + WS_FILES . '/packager/', + '/home/ws/www/download'); + // Clean downloads + + foreach ($dirs as $dir) { + if (!file_exists($dir)) { + continue; + } + $dr = opendir($dir); + while ($file = readdir($dr)) { + if ($file == '.' || $file == '..') { + continue; + } + $f = $dir . $file; + if (!is_dir($f)) { + continue; + } + if (filemtime($f) > $limit) { + continue; + } + `rm -rf $f`; + } + + if (!file_exists($dir)) { + mkdir($dir, 0777, true); + } + } + } + + public static function cleanConversionSessions() { + $limit = TIME - (4 * 3600); // 4 heures avant maintenant* + + $dir = ROOT . '/cache/conversionSessions/'; + $dr = opendir($dir); + while ($file = readdir($dr)) { + if ($file == '.' || $file == '..') { + continue; + } + $f = $dir . $file; + if (filemtime($f) > $limit) { + continue; + } + unlink($f); + } + } + + public static function cleanUnusedDocs() { + global $core; + cubePHP::neverStop(); + $r = $core->con->select('SELECT document_id FROM documents WHERE document_id NOT IN (SELECT document_id FROM book_pages)'); + while ($r->fetch()) { + if (file_exists(WS_DOCS . '/' . $r->document_id)) { + $rm = new cubeCommandLine('rm'); + $rm->setPath(CONVERTER_PATH); + $rm->setArg('r'); + $rm->setArg('f'); + $rm->setArg(null, WS_DOCS . '/' . $r->document_id . '/'); + $rm->execute(); + echo $rm->commande . "
"; + } + } + } + + public static function moveFluidbookDatas() { + $dir = WS_BOOKS . '/final/'; + $dr = opendir($dir); + while ($d = readdir($dr)) { + if ($d == '.' || $d == '..' || !is_dir($dir . $d)) { + continue; + } + rename($dir . $d . '/FluidbookDatas.swf', $dir . $d . '/data/fd.swf'); + rename($dir . $d . '/FluidbookDatasLight.swf', $dir . $d . '/data/fdl.swf'); + } + } + + public static function mergeEntreprise($args) { + global $core; + + $from = $args[0]; + $to = $args[1]; + + $c = $core->con->openCursor('utilisateurs'); + $c->entreprise = $to; + $c->update('WHERE entreprise=' . $from); + + $core->con->execute('DELETE FROM entreprises WHERE entreprise_id=' . $from); + + $core->refreshWSUsersTree(); + } + + public static function updateLuceneTime() { + global $core; + $dao = new wsDAOBook($core->con); + $books = $dao->selectLuceneTimeNotSet(); + foreach ($books as $book) { + $index = WS_BOOKS . '/search/' . $book->book_id; + if (!file_exists($index)) { + fb($book->book_id, 'Skip'); + continue; + } + + $mtime = 0; + $dr = opendir($index); + while ($file = readdir($dr)) { + if ($file == '.' || $file == '..') { + continue; + } + $mtime = max($mtime, filemtime($index . '/' . $file)); + } + + $c = $core->con->openCursor('books'); + $c->lucene_time = $mtime; + $c->update('WHERE book_id=' . $book->book_id); + + fb($book->book_id, 'Update : ' . $mtime); + } + } + + public static function makeLuceneIndexes() { + global $core; + + cubePHP::neverStop(); + + $dao = new wsDAOBook($core->con); + $books = $dao->selectLuceneToDo(); + foreach ($books as $book) { + $pages = $dao->getPagesOfBook($book->book_id); + $dao->indexPDF($book, $pages); + } + } + + public static function restoreComposition($args) { + global $core; + $book_id = $args[0]; + + $r = $core->con->select('SELECT * FROM book_pages_versions WHERE book_id=\'' . $core->con->escape($book_id) . '\' AND composition!=\'a:0:{}\' ORDER BY `update` DESC LIMIT 1'); + if (!$r->count()) { + return; + } + + $comp = unserialize($r->composition); + $core->con->execute('DELETE FROM book_pages WHERE book_id=\'' . $core->con->escape($book_id) . '\''); + + $c = $core->con->openCursor('book_pages'); + $c->book_id = $book_id; + foreach ($comp as $book_page => $infos) { + $c->book_page = $book_page; + $c->document_id = $infos['document_id']; + $c->document_page = $infos['document_page']; + $c->insert(); + } + } + + public static function getV1Translations() { + wsLang::getV1Translations(); + } + + public static function appendDocument($args) { + global $core; + $book_id = $args[0]; + $document_id = $args[1]; + $dao = new wsDAOBook($core->con); + $dao->appendDocument($book_id, $document_id); + } + + public static function reprocessVideos($args) { + global $core; + + $book_id = $args[0]; + + $dir = WS_BOOKS . '/working/' . $book_id; + + $dao = new wsDAODocument($core->con); + $dao->getLinksAndRulers($book_id, $links, $rulers); + + foreach ($links as $link) { + if ($link['type'] != 4) { + continue; + } + + $file = $dir . '/' . $link['to']; + if (!file_exists($file)) { + continue; + } + + wsTools::encodeWebVideos($file, null, true, true); + } + } + + public static function syncLDAP() { + global $core; + cubePHP::neverStop(); + + $res = '
';
+
+		$ds = ldap_connect('localhost', 10389);
+		ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3);
+		ldap_bind($ds, 'uid=admin,ou=system', '*arica*6');
+
+		$r = $core->con->select('SELECT * FROM utilisateurs_entreprise ORDER BY utilisateur_id');
+		while ($r->fetch()) {
+			if (is_null($r->utilisateur_id)) {
+				continue;
+			}
+			$entree = array();
+			$entree['objectClass'][] = 'top';
+			$entree['objectClass'][] = 'person';
+			$entree['objectClass'][] = 'organizationalPerson';
+			$entree['objectClass'][] = 'extensibleObject';
+			$entree['cn'] = trim($r->prenom . ' ' . $r->nom . ' - ' . $r->rs . ' (' . $r->utilisateur_id . ')', ' -');
+			$entree['sn'] = $r->nom == '' ? $entree['cn'] : $r->nom;
+			$entree['mail'] = $r->email;
+			$entree['uid'] = 'extranet_' . $r->utilisateur_id;
+			$entree['OrganizationalUnitName'] = $r->rs;
+			if ($r->telephone && $r->telephone != '+33') {
+				$entree['telephoneNumber'][] = $r->telephone;
+			}
+			if ($r->mobile && $r->mobile != '+33') {
+				$entree['telephoneNumber'][] = $r->mobile;
+			}
+			if ($r->fax && $r->fax != '+33') {
+				$entree['telexNumber'] = $r->fax;
+			}
+			$dn = 'uid=' . $entree['uid'] . ',o=cubedesigners';
+			if (!ldap_add($ds, $dn, $entree)) {
+				$e = ldap_error($ds);
+				if ($e == 'Already exists') {
+					ldap_modify($ds, $dn, $entree);
+				} else {
+					fb($entree, $e);
+				}
+			}
+		}
+		$res = 'test';
+		$res.='
'; + + ldap_close($ds); + return $res; + } + + public static function updateHTML5Sources($args = array(), $externals = true) { + $svn = new cubeCommandLine('updatewshtml5prod'); + $svn->setPath(CONVERTER_PATH); + $svn->execute(); + } + + public static function cleanDownload($args) { + $root = ROOT . '/cache/download/'; + cubeFiles::scanRecursiveDir($root, $files); + $limit = TIME - 14400; + foreach ($files as $f) { + if (filemtime($f) < $limit) { + unlink($f); + } + } + $files = cubeFiles::scandir($root, true); + foreach ($files as $f) { + if (cubeFiles::isEmpty($f)) { + @rmdir($f); + } + } + } + + public static function deleteOldFilesFromFTP($args) { + global $core; + cubePHP::neverStop(); + + $dao = new commonDAOFichier($core->con); + $dao->deleteOldFiles(); + + cubeFiles::deleteFilesOlderThan('/home/ws/ftp', 60, array('*.ipa', '*.apk')); + cubeFiles::deleteFilesOlderThan('/home/ws/www/getpdf', 60); + } + + public static function reencodeVideos($args) { + + cubePHP::neverStop(); + + $book_id = $args[0]; + $dir = WS_BOOKS . '/working/' . $book_id; + + wsLinks::getLinksAndRulers($book_id, $links, $rulers); + + foreach ($links as $link) { + if ($link['type'] != 4) { + continue; + } + + $file = $dir . '/' . $link['to']; + if (!file_exists($file)) { + continue; + } + + wsTools::encodeWebVideos($file, null, false, true); + } + } + + public static function correctAutoBookmarkLinks($args) { + global $core; + $book_id = $args[0]; + wsLinks::getLinksAndRulers($book_id, $links, $rulers); + + + $newlinks = array(); + foreach ($links as $link) { + $link['left']-=1; + $link['top']+=1; + $link['width']+=5; + $link['height']+=3; + $newlinks[] = $link; + } + + $dao = new wsDAODocument($core->con); + $dao->setLinksAndRulers($book_id, json_encode($newlinks), json_encode($rulers), 'Autobookmark links correction', $core->user->utilisateur_id); + } + + public static function offsetLinksPos($args) { + global $core; + $book_id = $args[0]; + $direction = $args[1]; + $value = intval($args[2]); + wsLinks::getLinksAndRulers($book_id, $links, $rulers); + + if ($direction == 'y') { + $k = 'top'; + } elseif ($direction == 'x') { + $k = 'left'; + } else { + return; + } + + if (!$value) { + return; + } + + + $newlinks = array(); + foreach ($links as $link) { + $link[$k]+=$value; + $newlinks[] = $link; + } + + $dao = new wsDAODocument($core->con); + $dao->setLinksAndRulers($book_id, json_encode($newlinks), json_encode($rulers), 'Offset links positions (' . $direction . ' :: ' . $value . ')', $core->user->utilisateur_id); + } + +} + ?> \ No newline at end of file -- 2.39.5