From 3abfa12ec9b44c7d585e1c646fbd4ad3019c4183 Mon Sep 17 00:00:00 2001 From: "vincent@cubedesigners.com" Date: Wed, 19 Aug 2020 14:46:14 +0000 Subject: [PATCH] wip #3839 @2 --- inc/ws/Controlleur/class.ws.droits.php | 18 +++++++- inc/ws/Controlleur/class.ws.maintenance.php | 22 ++++++++++ inc/ws/Util/class.ws.util.php | 28 +++++++++++++ .../html5/master/class.ws.html5.compiler.php | 41 +++++++++++++++---- 4 files changed, 100 insertions(+), 9 deletions(-) diff --git a/inc/ws/Controlleur/class.ws.droits.php b/inc/ws/Controlleur/class.ws.droits.php index 9046e615e..c83a5d711 100644 --- a/inc/ws/Controlleur/class.ws.droits.php +++ b/inc/ws/Controlleur/class.ws.droits.php @@ -128,6 +128,20 @@ class wsDroits } -} + public static function hasRightsOnBook($book_id) + { + global $core; + if (self::admin()) { + return true; + } + $daoBook = new wsDAOBook($core->con); + $books = $daoBook->getListe(null, null, null, true); + foreach ($books as $book) { + if ($book->book_id == $book_id) { + return true; + } + } + return false; + } -?> \ No newline at end of file +} \ No newline at end of file diff --git a/inc/ws/Controlleur/class.ws.maintenance.php b/inc/ws/Controlleur/class.ws.maintenance.php index 3d08d071e..085946919 100644 --- a/inc/ws/Controlleur/class.ws.maintenance.php +++ b/inc/ws/Controlleur/class.ws.maintenance.php @@ -1294,6 +1294,28 @@ class wsMaintenance } $daoBook->setComposition($book_id, $pages, false); } + + public static function downloadWorkingFiles($args) + { + global $core; + + $book_id = $args[0]; + + if (!wsDroits::hasRightsOnBook($book_id)) { + echo ':('; + return; + } + + $tmp = CubeIT_Files::tempnam() . ".zip"; + CubeIT_Util_Zip::archive(WS_BOOKS . '/working/' . $book_id, $tmp); + header('Content-Type: application/zip'); + header('Content-Disposition: attachment; filename="working_' . $book_id . '.zip"'); + header('Content-Length: ' . filesize($tmp)); + ob_end_clean(); + readfile($tmp); + unlink($tmp); + exit; + } } diff --git a/inc/ws/Util/class.ws.util.php b/inc/ws/Util/class.ws.util.php index c0d8b5b37..fcdd9c040 100644 --- a/inc/ws/Util/class.ws.util.php +++ b/inc/ws/Util/class.ws.util.php @@ -75,6 +75,34 @@ class wsUtil return $res; } + public static function excelToArrayKeyVars($excelFile) + { + $worksheets = self::excelToArray($excelFile); + $res = []; + foreach ($worksheets as $worksheet) { + + foreach ($worksheet as $i => $line) { + if ($i === 0) { + $vars = []; + foreach ($line as $j => $varname) { + if ($j === 0) { + continue; + } + $vars[$j] = $varname; + } + } else { + $r = []; + foreach ($vars as $j => $varname) { + $r[$varname] = trim($line[$j]); + } + $res[trim($line[0])] = $r; + } + } + break; + } + return $res; + } + public static function excelToArrayKeyValMulti($excelFile) { $worksheets = self::excelToArray($excelFile); diff --git a/inc/ws/Util/html5/master/class.ws.html5.compiler.php b/inc/ws/Util/html5/master/class.ws.html5.compiler.php index 82a2bdb58..27b33e375 100644 --- a/inc/ws/Util/html5/master/class.ws.html5.compiler.php +++ b/inc/ws/Util/html5/master/class.ws.html5.compiler.php @@ -624,9 +624,29 @@ class wsHTML5Compiler if (!$this->book->parametres->tagcommander_prod) { $id .= '/uat'; } - $this->book->parametres->googleAnalyticsCustom .= ''; + + $default = ['page_name' => '', 'page_cat1_name' => '', 'page_cat2_name' => '', 'page_cat3_name' => '']; + $this->config->tagcommander_default_vars = array_merge($default, $this->parseVariables($this->book->parametres->tagcommander_default_vars)); + $this->config->tagcommander_default_vars['env_work'] = $this->book->parametres->tagcommander_prod ? 'prod' : 'pre-prod'; + + $this->book->parametres->googleAnalyticsCustom .= ''; $this->book->parametres->statsCustom .= ''; $this->book->parametres->statsCustom .= ''; + + + if ($this->book->parametres->tagcommander_plan) { + $plan = wsUtil::excelToArrayKeyVars($this->wdir . '/' . $this->book->parametres->tagcommander_plan); + $fixedplan = []; + foreach ($plan as $k => $v) { + $e = explode('#', $k); + if (count($e) === 2) { + $k = $e[1]; + } + + $fixedplan[trim($k, '#/')] = $v; + } + $this->config->tagcommander_plan = $fixedplan; + } } } @@ -1140,20 +1160,27 @@ class wsHTML5Compiler } $this->vdir->file_put_contents('imsmanifest.xml', $manifest); + + $this->config->scorm_variables = $this->book->parametres->scorm_variables = $this->parseVariables($this->book->parametres->scorm_variables); + if ($this->book->parametres->scorm_quizdata) { + $this->config->scorm_quizdata = wsUtil::excelToArray($this->wdir . '/' . $this->book->parametres->scorm_quizdata); + } + } + + protected function parseVariables($f) + { $variables = []; - $e = CubeIT_Text::explodeNewLines($this->book->parametres->scorm_variables); + $f = str_replace("\r", "\n", $f); + $e = CubeIT_Text::explodeNewLines($f); foreach ($e as $item) { $item = trim($item); if ($item == '') { continue; } $f = explode('=', $item, 2); - $variables[$f[0]] = $f[1]; - } - $this->config->scorm_variables = $this->book->parametres->scorm_variables = $variables; - if ($this->book->parametres->scorm_quizdata) { - $this->config->scorm_quizdata = wsUtil::excelToArray($this->wdir . '/' . $this->book->parametres->scorm_quizdata); + $variables[trim($f[0])] = trim($f[1]); } + return $variables; } protected function writePrint() -- 2.39.5