$displaySettings = true; } else { // sql error in save() ? $cmd = 'rqEdit'; } } else { if (claro_failure::get_last_failure() == 'exercise_no_title') { $dialogBox->error(get_lang('Field \'%name\' is required', array('%name' => get_lang('Title')))); } elseif (claro_failure::get_last_failure() == 'exercise_incorrect_dates') { $dialogBox->error(get_lang('Start date must be before end date ...')); } $cmd = 'rqEdit'; } } if ($cmd == 'rqEdit') { $form['title'] = $exercise->getTitle(); $form['description'] = $exercise->getDescription(); $form['displayType'] = $exercise->getDisplayType(); $form['randomize'] = (bool) $exercise->getShuffle() > 0; $form['questionDrawn'] = $exercise->getShuffle(); $form['useSameShuffle'] = (bool) $exercise->getUseSameShuffle(); $form['showAnswers'] = $exercise->getShowAnswers(); $form['startDate'] = $exercise->getStartDate(); // unix if (is_null($exercise->getEndDate())) { $form['useEndDate'] = false; $form['endDate'] = 0; } else { $form['useEndDate'] = true; $form['endDate'] = $exercise->getEndDate(); }
/** * Create files (quiz) needed in the export of this module * * @copyright (c) 2001-2011, Universite catholique de Louvain (UCL) * @param int $quizId id of the Quiz * @param object $item item of the path * @param string $destDir path when the files need to be copied * @param int $deepness deepness of the destinationd directory * @return boolean */ public function prepareFiles($quizId, &$item, $destDir, $deepness) { $completionThresold = $item->getCompletionThreshold(); if (empty($completionThresold)) { $completionThresold = 50; } $quizId = (int) $quizId; $quiz = new Exercise(); if (!$quiz->load($quizId)) { $this->error[] = get_lang('Unable to load the exercise'); return false; } $deep = ''; if ($deepness) { for ($i = $deepness; $i > 0; $i--) { $deep .= ' ../'; } } // Generate standard page header $pageHeader = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html> <head> <title>' . $quiz->getTitle() . '</title> <meta http-equiv="expires" content="Tue, 05 DEC 2000 07:00:00 GMT"> <meta http-equiv="Pragma" content="no-cache"> <meta http-equiv="Content-Type" content="text/HTML; charset=' . get_locale('charset') . '" /> <link rel="stylesheet" type="text/css" href="' . $deep . get_conf('claro_stylesheet') . '/main.css" media="screen, projection, tv" /> <script language="javascript" type="text/javascript" src="' . $deep . 'js/jquery.js"></script> <script language="javascript" type="text/javascript" src="' . $deep . 'js/claroline.js"></script> <script language="javascript" type="text/javascript" src="' . $deep . 'js/claroline.ui.js"></script> <script language="javascript" type="text/javascript" src="' . $deep . 'js/APIWrapper.js"></script> <script language="javascript" type="text/javascript" src="' . $deep . 'js/connector13.js"></script> <script language="javascript" type="text/javascript" src="' . $deep . 'js/scores.js"></script> </head> ' . "\n"; $pageBody = '<body onload="loadPage()"> <div id="claroBody"><form id="quiz"> <table width="100%" border="0" cellpadding="1" cellspacing="0" class="claroTable">' . "\n"; // Get the question list $questionList = $quiz->getQuestionList(); $questionCount = count($questionList); // Keep track of raw scores (ponderation) for each question $questionPonderationList = array(); // Keep track of correct texts for fill-in type questions // TODO La variable $fillAnswerList n'apparaît qu'une fois $fillAnswerList = array(); // Display each question $questionCount = 0; foreach ($questionList as $question) { // Update question number $questionCount++; // read the question, abort on error $scormQuestion = new ScormQuestion(); if (!$scormQuestion->load($question['id'])) { $this->error[] = get_lang('Unable to load exercise\'s question'); return false; } $questionPonderationList[] = $scormQuestion->getGrade(); $pageBody .= '<thead>' . "\n" . '<tr>' . "\n" . '<th>' . get_lang('Question') . ' ' . $questionCount . '</th>' . "\n" . '</tr>' . "\n" . '</thead>' . "\n"; $pageBody .= '<tr>' . "\n" . '<td>' . "\n" . $scormQuestion->export() . "\n" . '</td>' . "\n" . '</tr>' . "\n"; } $pageEnd = ' <tr> <td align="center"><br /><input type="button" value="' . get_lang('Ok') . '" onclick="calcScore()" /></td> </tr> </table> </form> </div></body></html>' . "\n"; /* Generate the javascript that'll calculate the score * We have the following variables to help us : * $idCounter : number of elements to check. their id are "scorm_XY" * $raw_to_pass : score (on 100) needed to pass the quiz * $fillAnswerList : a list of arrays (text, score) indexed on <input>'s names * */ $pageHeader .= ' <script type="text/javascript" language="javascript"> var raw_to_pass = '******'; var weighting = ' . array_sum($questionPonderationList) . '; var rawScore; var scoreCommited = false; var showScore = true; var fillAnswerList = new Array();' . "\n"; // This is the actual code present in every exported exercise. // use claro_html_entity_decode in output to prevent double encoding errors with some languages... $pageHeader .= ' function calcScore() { if( !scoreCommited ) { rawScore = CalculateRawScore(document, ' . getIdCounter() . ', fillAnswerList); var score = Math.max(Math.round(rawScore * 100 / weighting), 0); var oldScore = doLMSGetValue("cmi.score.raw"); doLMSSetValue("cmi.score.max", weighting); doLMSSetValue("cmi.score.min", 0); computeTime(); if (score > oldScore) // Update only if score is better than the previous time. { doLMSSetValue("cmi.raw", rawScore); } var oldStatus = doLMSGetValue( "cmi.completion_status" ) if (score >= raw_to_pass) { doLMSSetValue("cmi.completion_status", "completed"); } else if (oldStatus != "completed" ) // If passed once, never mark it as failed. { doLMSSetValue("cmi.completion_status", "failed"); } doLMSCommit(); doLMSFinish(); scoreCommited = true; if(showScore) alert(\'' . clean_str_for_javascript(claro_html_entity_decode(get_lang('Score'))) . ' :\\n\' + rawScore + \'/\' + weighting ); } } </script> '; // Construct the HTML file and save it. $filename = "quiz_" . $quizId . ".html"; $pageContent = $pageHeader . $pageBody . $pageEnd; if (!($f = fopen($destDir . '/' . $filename, 'w'))) { $this->error = get_lang('Unable to create file : ') . $filename; return false; } fwrite($f, $pageContent); fclose($f); return true; }
/** * Exports an exercise as a SCO. * This method is intended to be called from the prepare method. * *@note There's a lot of nearly cut-and-paste from exercise.lib.php here * because of some little differences... * Perhaps something that could be refactorised ? * * @see prepare * @param $quizId The quiz * @param $raw_to_pass The needed score to attain * @return False on error, True if everything went well. * @author Amand Tihon <*****@*****.**> */ public function prepareQuiz($quizId, $raw_to_pass = 50) { global $claro_stylesheet; // those two variables are needed by display_attached_file() global $attachedFilePathWeb; global $attachedFilePathSys; $attachedFilePathWeb = 'Exercises'; $attachedFilePathSys = $this->destDir . '/Exercises'; // read the exercise $quiz = new Exercise(); if (!$quiz->load($quizId)) { $this->error[] = get_lang('Unable to load the exercise'); return false; } // Generate standard page header $pageHeader = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <title>' . $quiz->getTitle() . '</title> <meta http-equiv="expires" content="Tue, 05 DEC 2000 07:00:00 GMT"> <meta http-equiv="Pragma" content="no-cache"> <meta http-equiv="Content-Type" content="text/HTML; charset=' . get_locale('charset') . '" /> <link rel="stylesheet" type="text/css" href="' . get_conf('claro_stylesheet') . '/main.css" media="screen, projection, tv" /> <script language="javascript" type="text/javascript" src="jquery.js"></script> <script language="javascript" type="text/javascript" src="claroline.js"></script> <script language="javascript" type="text/javascript" src="claroline.ui.js"></script> <script language="javascript" type="text/javascript" src="APIWrapper.js"></script> <script language="javascript" type="text/javascript" src="scores.js"></script> ' . "\n"; $pageBody = '<body onload="loadPage()"> <div id="claroBody"><form id="quiz"> <table width="100%" border="0" cellpadding="1" cellspacing="0" class="claroTable">' . "\n"; // Get the question list $questionList = $quiz->getQuestionList(); $questionCount = count($questionList); // Keep track of raw scores (ponderation) for each question $questionPonderationList = array(); // Keep track of correct texts for fill-in type questions // TODO La variable $fillAnswerList n'appara�t qu'une fois $fillAnswerList = array(); // Display each question $questionCount = 0; foreach ($questionList as $question) { // Update question number $questionCount++; // read the question, abort on error $scormQuestion = new ScormQuestion(); if (!$scormQuestion->load($question['id'])) { $this->error[] = get_lang('Unable to load exercise\'s question'); return false; } $questionPonderationList[] = $scormQuestion->getGrade(); $pageBody .= '<tr class="headerX">' . "\n" . '<th>' . get_lang('Question') . ' ' . $questionCount . '</th>' . "\n" . '</tr>' . "\n"; $pageBody .= '<tr>' . "\n" . '<td>' . "\n" . $scormQuestion->export() . "\n" . '</td>' . "\n" . '</tr>' . "\n"; /* if( !empty($scormQuestion->getAttachment()) ) { // copy the attached file if ( !claro_copy_file($this->srcDirExercise . '/' . $attachedFile, $this->destDir . '/Exercises') ) { $this->error[] = get_lang('Unable to copy file : %filename', array ( '%filename' => $attachedFile )); return false; } // Ok, if it was an mp3, we need to copy the flash mp3-player too. $extension=substr(strrchr($attachedFile, '.'), 1); if ( $extension == 'mp3') $this->mp3Found = true; $pageBody .= '<tr><td colspan="2">' . display_attached_file($attachedFile) . '</td></tr>' . "\n"; } */ /* * Display the possible answers */ // End of the question } // foreach($questionList as $questionId) // No more questions, add the button. $pageEnd = ' <tr> <td align="center"><br /><input type="button" value="' . get_lang('Ok') . '" onclick="calcScore()" /></td> </tr> </table> </form> </div></body></html>' . "\n"; /* Generate the javascript that'll calculate the score * We have the following variables to help us : * $idCounter : number of elements to check. their id are "scorm_XY" * $raw_to_pass : score (on 100) needed to pass the quiz * $fillAnswerList : a list of arrays (text, score) indexed on <input>'s names * */ $pageHeader .= ' <script type="text/javascript" language="javascript"> var raw_to_pass = '******'; var weighting = ' . array_sum($questionPonderationList) . '; var rawScore; var scoreCommited = false; var showScore = true; var fillAnswerList = new Array();' . "\n"; // This is the actual code present in every exported exercise. // use claro_html_entity_decode in output to prevent double encoding errors with some languages... $pageHeader .= ' function calcScore() { if( !scoreCommited ) { rawScore = CalculateRawScore(document, ' . getIdCounter() . ', fillAnswerList); var score = Math.max(Math.round(rawScore * 100 / weighting), 0); var oldScore = doLMSGetValue("cmi.core.score.raw"); doLMSSetValue("cmi.core.score.max", weighting); doLMSSetValue("cmi.core.score.min", 0); computeTime(); if (score > oldScore) // Update only if score is better than the previous time. { doLMSSetValue("cmi.core.score.raw", rawScore); } var mode = doLMSGetValue( "cmi.core.lesson_mode" ); if ( mode != "review" && mode != "browse" ) { var oldStatus = doLMSGetValue( "cmi.core.lesson_status" ) if (score >= raw_to_pass) { doLMSSetValue("cmi.core.lesson_status", "passed"); } else if (oldStatus != "passed" ) // If passed once, never mark it as failed. { doLMSSetValue("cmi.core.lesson_status", "failed"); } } doLMSCommit(); doLMSFinish(); scoreCommited = true; if(showScore) alert(\'' . clean_str_for_javascript(claro_html_entity_decode(get_lang('Score'))) . ' :\\n\' + rawScore + \'/\' + weighting ); } } </script> '; // Construct the HTML file and save it. $filename = "quiz_" . $quizId . ".html"; $pageContent = $pageHeader . $pageBody . $pageEnd; if (!($f = fopen($this->destDir . '/' . $filename, 'w'))) { $this->error[] = get_lang('Unable to create file : ') . $filename; return false; } fwrite($f, $pageContent); fclose($f); // Went well. return True; }
/* * Output */ if (is_null($quId)) { $nameTools = get_lang('New question'); ClaroBreadCrumbs::getInstance()->setCurrent($nameTools, Url::Contextualize('./edit_question.php?exId=' . $exId . '&cmd=rqEdit')); } elseif ($cmd == 'rqEdit') { $nameTools = get_lang('Edit question'); ClaroBreadCrumbs::getInstance()->prepend(get_lang('Question'), Url::Contextualize('./edit_question.php?exId=' . $exId . '&quId=' . $quId)); ClaroBreadCrumbs::getInstance()->setCurrent($nameTools, Url::Contextualize('./edit_question.php?exId=' . $exId . '&quId=' . $quId . '&cmd=rqEdit')); } else { $nameTools = get_lang('Question'); ClaroBreadCrumbs::getInstance()->setCurrent($nameTools, Url::Contextualize('./edit_question.php?exId=' . $exId . '&quId=' . $quId)); } if (!is_null($exId)) { ClaroBreadCrumbs::getInstance()->prepend($exercise->getTitle(), Url::Contextualize('./edit_exercise.php?exId=' . $exId)); //ClaroBreadCrumbs::getInstance()->prepend( get_lang('Exercise'), './edit_exercise.php?exId='.$exId ); } else { ClaroBreadCrumbs::getInstance()->prepend(get_lang('Question pool'), Url::Contextualize('./question_pool.php')); } ClaroBreadCrumbs::getInstance()->prepend(get_lang('Exercises'), Url::Contextualize(get_module_url('CLQWZ') . '/exercise.php')); // Command list $cmdList = array(); $cmdList[] = array('img' => 'edit', 'name' => get_lang('Edit question'), 'url' => claro_htmlspecialchars(Url::Contextualize('./edit_question.php?exId=' . $exId . '&cmd=rqEdit&quId=' . $quId))); $cmdList[] = array('img' => 'edit', 'name' => get_lang('Edit answers'), 'url' => claro_htmlspecialchars(Url::Contextualize('./edit_answers.php?exId=' . $exId . '&cmd=rqEdit&quId=' . $quId))); $cmdList[] = array('img' => 'default_new', 'name' => get_lang('New question'), 'url' => claro_htmlspecialchars(Url::Contextualize('./edit_question.php?exId=' . $exId . '&cmd=rqEdit'))); $out = ''; $out .= claro_html_tool_title($nameTools, null, $cmdList); // dialog box if required $out .= $dialogBox->render(); $localizedQuestionType = get_localized_question_type();
$exoExport = new ExoExportByQuestion($exId); $csv = $exoExport->buildCsv(); $csvFileName = 'exercise_' . $exId . '_results_by_question'; break; } if (isset($csv)) { header("Content-type: application/csv"); header('Content-Disposition: attachment; filename="' . $csvFileName . '.csv"'); echo $csv; exit; } } $out = ''; // display title $titleTab['mainTitle'] = $nameTools; $titleTab['subTitle'] = $exercise->getTitle(); $out .= claro_html_tool_title($titleTab); if (get_conf('is_trackingEnabled')) { // get global infos about scores in the exercise $sql = "SELECT MIN(TEX.`result`) AS `minimum`,\n MAX(TEX.`result`) AS `maximum`,\n AVG(TEX.`result`) AS `average`,\n MAX(TEX.`weighting`) AS `weighting` ,\n COUNT(DISTINCT TEX.`user_id`) AS `users`,\n COUNT(TEX.`user_id`) AS `tusers`,\n AVG(`TEX`.`time`) AS `avgTime`\n FROM `" . $tbl_qwz_tracking . "` AS TEX\n WHERE TEX.`exo_id` = " . (int) $exercise->getId() . "\n AND TEX.`user_id` IS NOT NULL"; $exo_scores_details = claro_sql_query_get_single_row($sql); if (!isset($exo_scores_details['minimum'])) { $exo_scores_details['minimum'] = 0; $exo_scores_details['maximum'] = 0; $exo_scores_details['average'] = 0; } else { // round average number for a better display $exo_scores_details['average'] = round($exo_scores_details['average'] * 100) / 100; } if (isset($exo_score_details['weighting']) || $exo_scores_details['weighting'] != '') { $displayedWeighting = '/' . $exo_scores_details['weighting'];
$questionList[$_id]['answerList'][$i] = $questionObj->answer->answerDecode($questionObj->answer->addslashesEncodedBrackets($answer)); } $questionList[$_id]['answerType'] = $questionObj->answer->type; break; case 'MATCHING': $questionList[$_id]['leftList'] = $questionObj->answer->leftList; $questionList[$_id]['rightList'] = $questionObj->answer->rightList; break; } $questionList[$_id]['type'] = $questionObj->getType(); } } require_once get_path('incRepositorySys') . '/lib/thirdparty/tcpdf/tcpdf.php'; // create new PDF document $pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false); $pdf->SetTitle(claro_utf8_encode($exercise->getTitle())); $pdf->SetSubject(claro_utf8_encode($exercise->getTitle())); //set margins $pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT); $pdf->SetHeaderMargin(PDF_MARGIN_HEADER); $pdf->SetFooterMargin(PDF_MARGIN_FOOTER); //set auto page breaks $pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM); //set image scale factor $pdf->setImageScale(PDF_IMAGE_SCALE_RATIO); $pdf->setPrintHeader(false); // add a page $pdf->AddPage(); $htmlcontent = '<div style="font-size: xx-large; font-weight: bold;">' . claro_htmlspecialchars($exercise->getTitle()) . '<div>' . "\n"; $pdf->writeHTML(claro_utf8_encode($htmlcontent, get_conf('charset')), true, 0, true, 0); //change Img URL