Source for file admin.php
Documentation is available at admin.php
DOKEOS - elearning and course management software
For a full list of contributors, see documentation/credits.html
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
See "documentation/licence.html" more details.
Rue des Palais 44 Paleizenstraat
B-1030 Brussels - Belgium
* Exercise administration
* This script allows to manage (create, modify) an exercise and its questions
* Following scripts are includes for a best code understanding :
* - exercise.class.php : for the creation of an Exercise object
* - question.class.php : for the creation of a Question object
* - answer.class.php : for the creation of an Answer object
* - exercise.lib.php : functions used in the exercise tool
* - exercise_admin.inc.php : management of the exercise
* - question_admin.inc.php : management of a question (statement & answers)
* - statement_admin.inc.php : management of a statement
* - answer_admin.inc.php : management of answers
* - question_list_admin.inc.php : management of the question list
* Main variables used in this script :
* - $is_allowedToEdit : set to 1 if the user is allowed to manage the exercise
* - $objExercise : exercise object
* - $objQuestion : question object
* - $objAnswer : answer object
* - $aType : array with answer types
* - $exerciseId : the exercise ID
* - $picturePath : the path of question pictures
* - $newQuestion : ask to create a new question
* - $modifyQuestion : ID of the question to modify
* - $editQuestion : ID of the question to edit
* - $submitQuestion : ask to save question modifications
* - $cancelQuestion : ask to cancel question modifications
* - $deleteQuestion : ID of the question to delete
* - $moveUp : ID of the question to move up
* - $moveDown : ID of the question to move down
* - $modifyExercise : ID of the exercise to modify
* - $submitExercise : ask to save exercise modifications
* - $cancelExercise : ask to cancel exercise modifications
* - $modifyAnswers : ID of the question which we want to modify answers for
* - $cancelAnswers : ask to cancel answer modifications
* - $buttonBack : ask to go back to the previous page in answers of type "Fill in blanks"
* @package dokeos.exercise
* @author Olivier Brouckaert
* @version $Id: admin.php 15333 2008-05-20 17:07:26Z elixir_inter $
include('exercise.class.php');
include('question.class.php');
include('answer.class.php');
// name of the language file that needs to be included
$language_file= 'exercice';
include("../inc/global.inc.php");
include('exercise.lib.php');
// allows script inclusions
include_once(api_get_path(LIBRARY_PATH). 'fileUpload.lib.php');
include_once(api_get_path(LIBRARY_PATH). 'document.lib.php');
/****************************/
/* stripslashes POST data */
/****************************/
if($_SERVER['REQUEST_METHOD'] == 'POST')
foreach($_POST as $key=> $val)
foreach($val as $key2=> $val2)
$GLOBALS[$key]= $_POST[$key];
if ( empty ( $exerciseId ) )
if ( empty ( $newQuestion ) )
$newQuestion = $_GET['newQuestion'];
if ( empty ( $modifyAnswers ) )
$modifyAnswers = $_GET['modifyAnswers'];
if ( empty ( $editQuestion ) )
$editQuestion = $_GET['editQuestion'];
if ( empty ( $modifyQuestion ) )
$modifyQuestion = $_GET['modifyQuestion'];
if ( empty ( $deleteQuestion ) )
$deleteQuestion = $_GET['deleteQuestion'];
if ( empty ( $questionId ) )
$questionId = $_SESSION['questionId'];
if ( empty ( $modifyExercise ) )
$modifyExercise = $_GET['modifyExercise'];
$objExercise = $_SESSION['objExercise'];
$objQuestion = $_SESSION['objQuestion'];
$objAnswer = $_SESSION['objAnswer'];
$picturePath= $documentPath. '/images';
$audioPath= $documentPath. '/audio';
// the 5 types of answers
// tables used in the exercise tool
if($_GET['action'] == 'exportqti2' && !empty($_GET['questionId']))
require_once('export/qti2/qti2_export.php');
$qid = (int) $_GET['questionId'];
require_once(api_get_path(LIBRARY_PATH). 'pclzip/pclzip.lib.php');
$temp_zip_dir = $garbage_path. "/". $temp_dir_short;
$temp_zip_file = $temp_zip_dir. "/". md5(time()). ".zip";
$temp_xml_file = $temp_zip_dir. "/qti2export_". $qid. '.xml';
$zip_folder= new PclZip($temp_zip_file);
$name = 'qti2_export_'. $qid. '.zip';
//DocumentManager::string_send_for_download($export,true,'qti2export_q'.$_GET['questionId'].'.xml');
exit(); //otherwise following clicks may become buggy
// intializes the Exercise object
// construction of the Exercise object
// creation of a new exercise if wrong or not specified exercise ID
$objExercise->read($exerciseId);
// saves the object into the session
// doesn't select the exercise ID if we come from the question pool
// gets the right exercise ID, and if 0 creates a new exercise
if(!$exerciseId= $objExercise->selectId())
$nbrQuestions= $objExercise->selectNbrQuestions();
// intializes the Question object
if($editQuestion || $newQuestion || $modifyQuestion || $modifyAnswers)
if($editQuestion || $newQuestion)
// saves the object into the session
// checks if the object exists
$questionId= $objQuestion->selectId();
// if cancelling an exercise
// goes back to the exercise list
header('Location: exercice.php');
// if cancelling question creation/modification
// if we are creating a new question from the question pool
if(!$exerciseId && !$questionId)
// goes back to the question pool
header('Location: question_pool.php');
// goes back to the question viewing
$editQuestion= $modifyQuestion;
unset ($newQuestion,$modifyQuestion);
// if cancelling answer creation/modification
// goes back to the question viewing
$editQuestion= $modifyAnswers;
// modifies the query string that is used in the link of tool name
if($editQuestion || $modifyQuestion || $newQuestion || $modifyAnswers)
$nameTools= get_lang('QuestionManagement');
$nameTools= get_lang('ExerciseManagement');
$interbreadcrumb[]= array("url" => "exercice.php","name" => get_lang('Exercices'));
$interbreadcrumb[]= array("url" => "admin.php?exerciseId=". $objExercise->id,"name" => $objExercise->exercise);
// shows a link to go back to the question pool
if(!$exerciseId && $nameTools != get_lang('ExerciseManagement'))
$interbreadcrumb[]= array("url" => "question_pool.php?fromExercise=$fromExercise","name" => get_lang('QuestionPool'));
// if the question is duplicated, disable the link of tool name
if($modifyIn == 'thisExercise')
$modifyIn= 'allExercises';
$htmlHeadXtra[] = "<script type=\"text/javascript\" src=\"../plugin/hotspot/JavaScriptFlashGateway.js\"></script>
<script src=\"../plugin/hotspot/hotspot.js\" type=\"text/javascript\"></script>
<script language=\"JavaScript\" type=\"text/javascript\">
// -----------------------------------------------------------------------------
// Major version of Flash required
var requiredMajorVersion = 7;
// Minor version of Flash required
var requiredMinorVersion = 0;
// Minor version of Flash required
var requiredRevision = 0;
// the version of javascript supported
// -----------------------------------------------------------------------------
<script language=\"VBScript\" type=\"text/vbscript\">
<!-- // Visual basic helper required to detect Flash Player ActiveX control version information
set swControl = CreateObject(\"ShockwaveFlash.ShockwaveFlash.\" + CStr(i))
if (IsObject(swControl)) then
swVersion = swControl.GetVariable(\"\$version\")
<script language=\"JavaScript1.1\" type=\"text/javascript\">
<!-- // Detect Client Browser type
var isIE = (navigator.appVersion.indexOf(\"MSIE\") != -1) ? true : false;
var isWin = (navigator.appVersion.toLowerCase().indexOf(\"win\") != -1) ? true : false;
var isOpera = (navigator.userAgent.indexOf(\"Opera\") != -1) ? true : false;
// JavaScript helper required to detect Flash Player PlugIn version information
// NS/Opera version >= 3 check for Flash plugin in plugin array
if (navigator.plugins != null && navigator.plugins.length > 0) {
if (navigator.plugins[\"Shockwave Flash 2.0\"] || navigator.plugins[\"Shockwave Flash\"]) {
var swVer2 = navigator.plugins[\"Shockwave Flash 2.0\"] ? \" 2.0\" : \"\";
var flashDescription = navigator.plugins[\"Shockwave Flash\" + swVer2].description;
descArray = flashDescription.split(\" \");
tempArrayMajor = descArray[2].split(\".\");
versionMajor = tempArrayMajor[0];
versionMinor = tempArrayMajor[1];
if ( descArray[3] != \"\" ) {
tempArrayMinor = descArray[3].split(\"r\");
tempArrayMinor = descArray[4].split(\"r\");
versionRevision = tempArrayMinor[1] > 0 ? tempArrayMinor[1] : 0;
flashVer = versionMajor + \".\" + versionMinor + \".\" + versionRevision;
// MSN/WebTV 2.6 supports Flash 4
else if (navigator.userAgent.toLowerCase().indexOf(\"webtv/2.6\") != -1) flashVer = 4;
// WebTV 2.5 supports Flash 3
else if (navigator.userAgent.toLowerCase().indexOf(\"webtv/2.5\") != -1) flashVer = 3;
// older WebTV supports Flash 2
else if (navigator.userAgent.toLowerCase().indexOf(\"webtv\") != -1) flashVer = 2;
// Can't detect in all other cases
// When called with reqMajorVer, reqMinorVer, reqRevision returns true if that version or greater is available
function DetectFlashVer(reqMajorVer, reqMinorVer, reqRevision)
reqVer = parseFloat(reqMajorVer + \".\" + reqRevision);
// loop backwards through the versions until we find the newest version
if (isIE && isWin && !isOpera) {
versionStr = VBGetSwfVer(i);
versionStr = JSGetSwfVer(i);
} else if (versionStr != 0) {
if(isIE && isWin && !isOpera) {
tempArray = versionStr.split(\" \");
tempString = tempArray[1];
versionArray = tempString .split(\",\");
versionArray = versionStr.split(\".\");
versionMajor = versionArray[0];
versionMinor = versionArray[1];
versionRevision = versionArray[2];
versionString = versionMajor + \".\" + versionRevision; // 7.0r24 == 7.24
versionNum = parseFloat(versionString);
// is the major.revision >= requested major.revision AND the minor version >= requested minor
if ( (versionMajor > reqMajorVer) && (versionNum >= reqVer) ) {
return ((versionNum >= reqVer && versionMinor >= reqMinorVer) ? true : false );
if(isset ($_GET['message']))
if (in_array($_GET['message'], array('ExerciseStored')))
$description = $objExercise->selectDescription();
echo '<h3 style="display:inline">'. $objExercise->selectTitle(). '</h3> --> <a href="exercice_submit.php?'. api_get_cidreq(). '&exerciseId='. $objExercise->id. '">'. get_lang('Preview'). '</a>';
echo '<div id="description_box">'. stripslashes($description). '</div>';
if($newQuestion || $editQuestion)
$type = $_REQUEST['answerType'];
?><input type="hidden" name="Type" value=" <?php echo $type; ?>" />
include('question_admin.inc.php');
if(isset ($_GET['hotspotadmin']))
include('hotspot_admin.inc.php');
if(!$newQuestion && !$modifyQuestion && !$editQuestion && !isset ($_GET['hotspotadmin']))
// question list management
include('question_list_admin.inc.php');
|