header('Location: https://toolbox.fluidbook.com/quiz/');
}
- /**
- * @param $tmp_name
- * @param $name
- * @return false|string
- * @throws Exception
- */
- protected static function _updateOneQuiz($tmp_name, $name)
- {
- $tidySettings = ['input-xml' => 1, 'indent' => 1, 'wrap' => 0];
-
- $template = ROOT . '/quiz/template.zip';
- $temp = ROOT . '/quiz/quiz-' . md5(random_int(0, 10000000)) . '.zip';
- copy($template, $temp);
-
- $assets = ['assets/logo.png', 'assets/banner.jpg'];
-
- $uploaded = new ZipArchive();
- $uploaded->open($tmp_name);
-
- $template = new ZipArchive();
- $template->open($temp);
-
- $data = simplexml_load_string($uploaded->getFromName('data.xml'), "SimpleXMLElement", LIBXML_NOERROR | LIBXML_ERR_NONE);
- $quizTitle = (string)$data->xpath('/quiz/title')[0];
-
- // Replace assets
- foreach ($assets as $asset) {
- $template->addFromString($asset, $uploaded->getFromName($asset));
- }
- // *** Replace XML ***
- // First, merge both xml
- $oMX = new MergeXML();
- $oMX->AddSource($template->getFromName('data.xml'));
- $oMX->AddSource($uploaded->getFromName('data.xml'));
- $template->deleteName('data.xml');
- // Save data.xml in dest zip
- $template->addFromString('data.xml', tidy_repair_string($oMX->Get(1), $tidySettings));
- // *** IMS Manifest ***
- $imsmanifest = file_get_contents(ROOT . '/quiz/imsmanifest.xml');
- $imsmanifest = str_replace('$title', $quizTitle, tidy_repair_string($imsmanifest, $tidySettings));
- $template->addFromString('imsmanifest.xml', $imsmanifest);
- // *** Save zip ***
- $template->close();
-
- $res = file_get_contents($temp);
- unlink($temp);
- return $res;
- }
-
- /**
- * @throws Exception
- */
- public static function updateQuiz()
- {
- $multiple = count($_FILES['file']['name']) > 1;
- if ($multiple) {
- $fname = 'updated.zip';
- $zip = new ZipArchive();
- $zipName = ROOT . '/quiz/quiz-' . md5(random_int(0, 10000000)) . '.zip';
- $zip->open($zipName, ZipArchive::CREATE);
- } else {
- $fname = $_FILES['file']['name'][0];
- }
-
- foreach ($_FILES['file']['name'] as $i => $name) {
- $tmp_name = $_FILES['file']['tmp_name'][$i];
- $res = self::_updateOneQuiz($tmp_name, $name);
- if ($multiple) {
- $zip->addFromString($name, $res);
- }
- }
-
- header('Content-Type: application/zip');
- header('Content-Disposition: attachment; filename=' . $fname);
- ob_end_clean();
-
- if ($multiple) {
- $zip->close();
- echo file_get_contents($zipName);
- unlink($zipName);
- } else {
- echo $res;
- }
- exit;
- }
public static function formVerificationCode($args)
{
$this->config->manifest = $this->writeManifest();
}
- $this->writeGPUDatabase();
-
if ($this->config->form == 'bulle') {
$this->addJsLib('bulle', 'js/libs/fluidbook/forms/fluidbook.form.bulle.js');
} else if ($this->config->form == 'bourbon') {
}
}
- public function writeGPUDatabase()
- {
- global $core;
- $r = $core->con->select('SELECT gpu,rgpu,score FROM gpu');
- $gpu = [];
- while ($r->fetch()) {
- $gpu[$r->gpu] = $r->score;
- $gpu[$r->rgpu] = $r->score;
- }
- $this->config->gupsc = $gpu;
- $this->config->gupse = wsServices::gpuSeparators();
- }
-
public function log($step)
{
$currenttime = microtime(true);