dokeos-exercise
[ class tree: dokeos-exercise ] [ index: dokeos-exercise ] [ all elements ]

Source for file admin.php

Documentation is available at admin.php

  1. <?php
  2. /*
  3.     DOKEOS - elearning and course management software
  4.  
  5.     For a full list of contributors, see documentation/credits.html
  6.  
  7.     This program is free software; you can redistribute it and/or
  8.     modify it under the terms of the GNU General Public License
  9.     as published by the Free Software Foundation; either version 2
  10.     of the License, or (at your option) any later version.
  11.     See "documentation/licence.html" more details.
  12.  
  13.     Contact:
  14.         Dokeos
  15.         Rue des Palais 44 Paleizenstraat
  16.         B-1030 Brussels - Belgium
  17.         Tel. +32 (2) 211 34 56
  18. */
  19.  
  20.  
  21. /**
  22. *    Exercise administration
  23. *     This script allows to manage (create, modify) an exercise and its questions
  24. *
  25. *     Following scripts are includes for a best code understanding :
  26. *
  27. *     - exercise.class.php : for the creation of an Exercise object
  28. *     - question.class.php : for the creation of a Question object
  29. *     - answer.class.php : for the creation of an Answer object
  30. *     - exercise.lib.php : functions used in the exercise tool
  31. *     - exercise_admin.inc.php : management of the exercise
  32. *     - question_admin.inc.php : management of a question (statement & answers)
  33. *     - statement_admin.inc.php : management of a statement
  34. *     - answer_admin.inc.php : management of answers
  35. *     - question_list_admin.inc.php : management of the question list
  36. *
  37. *     Main variables used in this script :
  38. *
  39. *     - $is_allowedToEdit : set to 1 if the user is allowed to manage the exercise
  40. *     - $objExercise : exercise object
  41. *     - $objQuestion : question object
  42. *     - $objAnswer : answer object
  43. *     - $aType : array with answer types
  44. *     - $exerciseId : the exercise ID
  45. *     - $picturePath : the path of question pictures
  46. *     - $newQuestion : ask to create a new question
  47. *     - $modifyQuestion : ID of the question to modify
  48. *     - $editQuestion : ID of the question to edit
  49. *     - $submitQuestion : ask to save question modifications
  50. *     - $cancelQuestion : ask to cancel question modifications
  51. *     - $deleteQuestion : ID of the question to delete
  52. *     - $moveUp : ID of the question to move up
  53. *     - $moveDown : ID of the question to move down
  54. *     - $modifyExercise : ID of the exercise to modify
  55. *     - $submitExercise : ask to save exercise modifications
  56. *     - $cancelExercise : ask to cancel exercise modifications
  57. *     - $modifyAnswers : ID of the question which we want to modify answers for
  58. *     - $cancelAnswers : ask to cancel answer modifications
  59. *     - $buttonBack : ask to go back to the previous page in answers of type "Fill in blanks"
  60. *
  61. *    @package dokeos.exercise
  62. *     @author Olivier Brouckaert
  63. *     @version $Id: admin.php 15333 2008-05-20 17:07:26Z elixir_inter $
  64. */
  65.  
  66.  
  67. include('exercise.class.php');
  68. include('question.class.php');
  69. include('answer.class.php');
  70.  
  71.  
  72. // name of the language file that needs to be included
  73. $language_file='exercice';
  74.  
  75. include("../inc/global.inc.php");
  76. include('exercise.lib.php');
  77. $this_section=SECTION_COURSES;
  78.  
  79. $is_allowedToEdit=api_is_allowed_to_edit();
  80.  
  81. if(!$is_allowedToEdit)
  82. {
  83.     api_not_allowed(true);
  84. }
  85.  
  86. // allows script inclusions
  87. define(ALLOWED_TO_INCLUDE,1);
  88.  
  89. include_once(api_get_path(LIBRARY_PATH).'fileUpload.lib.php');
  90. include_once(api_get_path(LIBRARY_PATH).'document.lib.php');
  91. /****************************/
  92. /*  stripslashes POST data  */
  93. /****************************/
  94.  
  95. if($_SERVER['REQUEST_METHOD'== 'POST')
  96. {
  97.     foreach($_POST as $key=>$val)
  98.     {
  99.         if(is_string($val))
  100.         {
  101.             $_POST[$key]=stripslashes($val);
  102.         }
  103.         elseif(is_array($val))
  104.         {
  105.             foreach($val as $key2=>$val2)
  106.             {
  107.                 $_POST[$key][$key2]=stripslashes($val2);
  108.             }
  109.         }
  110.  
  111.         $GLOBALS[$key]=$_POST[$key];
  112.     }
  113. }
  114.  
  115. // get vars from GET
  116. if empty $exerciseId ) )
  117. {
  118.     $exerciseId mysql_real_escape_string($_GET['exerciseId']);
  119. }
  120. if empty $newQuestion ) )
  121. {
  122.     $newQuestion $_GET['newQuestion'];
  123. }
  124. if empty $modifyAnswers ) )
  125. {
  126.     $modifyAnswers $_GET['modifyAnswers'];
  127. }
  128. if empty $editQuestion ) )
  129. {
  130.     $editQuestion $_GET['editQuestion'];
  131. }
  132. if empty $modifyQuestion ) )
  133. {
  134.     $modifyQuestion $_GET['modifyQuestion'];
  135. }
  136. if empty $deleteQuestion ) )
  137. {
  138.     $deleteQuestion $_GET['deleteQuestion'];
  139. }
  140. if empty $questionId ) )
  141. {
  142.     $questionId $_SESSION['questionId'];
  143. }
  144. if empty $modifyExercise ) )
  145. {
  146.     $modifyExercise $_GET['modifyExercise'];
  147. }
  148.  
  149. // get from session
  150. $objExercise $_SESSION['objExercise'];
  151. $objQuestion $_SESSION['objQuestion'];
  152. $objAnswer   $_SESSION['objAnswer'];
  153.  
  154. // document path
  155. $documentPath=api_get_path(SYS_COURSE_PATH).$_course['path'].'/document';
  156.  
  157. // picture path
  158. $picturePath=$documentPath.'/images';
  159.  
  160. // audio path
  161. $audioPath=$documentPath.'/audio';
  162.  
  163. // the 5 types of answers
  164. $aType=array(get_lang('UniqueSelect'),get_lang('MultipleSelect'),get_lang('FillBlanks'),get_lang('Matching'),get_lang('freeAnswer'));
  165.  
  166. // tables used in the exercise tool
  167. $TBL_EXERCICE_QUESTION Database::get_course_table(TABLE_QUIZ_TEST_QUESTION);
  168. $TBL_EXERCICES         Database::get_course_table(TABLE_QUIZ_TEST);
  169. $TBL_QUESTIONS         Database::get_course_table(TABLE_QUIZ_QUESTION);
  170. $TBL_REPONSES          Database::get_course_table(TABLE_QUIZ_ANSWER);
  171. $TBL_DOCUMENT          Database::get_course_table(TABLE_DOCUMENT);
  172.  
  173. if($_GET['action'== 'exportqti2' && !empty($_GET['questionId']))
  174. {
  175.     require_once('export/qti2/qti2_export.php');
  176.     $export export_question((int)$_GET['questionId'],true);
  177.     $qid = (int)$_GET['questionId'];
  178.     require_once(api_get_path(LIBRARY_PATH).'pclzip/pclzip.lib.php');
  179.     $garbage_path api_get_path(GARBAGE_PATH);
  180.     $temp_dir_short uniqid();
  181.     $temp_zip_dir $garbage_path."/".$temp_dir_short;
  182.     if(!is_dir($temp_zip_dir)) mkdir($temp_zip_dir);
  183.     $temp_zip_file $temp_zip_dir."/".md5(time()).".zip";
  184.     $temp_xml_file $temp_zip_dir."/qti2export_".$qid.'.xml';
  185.     file_put_contents($temp_xml_file,$export);
  186.     $zip_folder=new PclZip($temp_zip_file);    
  187.     $zip_folder->add($temp_zip_dirPCLZIP_OPT_REMOVE_PATH$temp_zip_dir);
  188.     $name 'qti2_export_'.$qid.'.zip';
  189.  
  190.     DocumentManager::file_send_for_download($temp_zip_file,true,$name);
  191.     unlink($temp_zip_file);
  192.     unlink($temp_xml_file);
  193.     rmdir($temp_zip_dir);
  194.     //DocumentManager::string_send_for_download($export,true,'qti2export_q'.$_GET['questionId'].'.xml');
  195.     exit()//otherwise following clicks may become buggy
  196. }
  197.  
  198. // intializes the Exercise object
  199. if(!is_object($objExercise))
  200. {
  201.     // construction of the Exercise object
  202.     $objExercise=new Exercise();
  203.  
  204.     // creation of a new exercise if wrong or not specified exercise ID
  205.     if($exerciseId)
  206.     {
  207.         $objExercise->read($exerciseId);
  208.     }
  209.  
  210.     // saves the object into the session
  211.     api_session_register('objExercise');
  212. }
  213.  
  214. // doesn't select the exercise ID if we come from the question pool
  215. if(!$fromExercise)
  216. {
  217.  
  218.     // gets the right exercise ID, and if 0 creates a new exercise
  219.     if(!$exerciseId=$objExercise->selectId())
  220.     {
  221.         $modifyExercise='yes';
  222.     }
  223. }
  224.  
  225. $nbrQuestions=$objExercise->selectNbrQuestions();
  226.  
  227. // intializes the Question object
  228. if($editQuestion || $newQuestion || $modifyQuestion || $modifyAnswers)
  229. {
  230.     if($editQuestion || $newQuestion)
  231.     {
  232.  
  233.         // reads question data
  234.         if($editQuestion)
  235.         {
  236.             // question not found
  237.             if(!$objQuestion Question::read($editQuestion))
  238.             {
  239.                 die(get_lang('QuestionNotFound'));
  240.             }
  241.             // saves the object into the session
  242.             api_session_register('objQuestion');
  243.         }
  244.     }
  245.  
  246.     // checks if the object exists
  247.     if(is_object($objQuestion))
  248.     {
  249.         // gets the question ID
  250.         $questionId=$objQuestion->selectId();
  251.     }
  252. }
  253.  
  254. // if cancelling an exercise
  255. if($cancelExercise)
  256. {
  257.     // existing exercise
  258.     if($exerciseId)
  259.     {
  260.         unset($modifyExercise);
  261.     }
  262.     // new exercise
  263.     else
  264.     {
  265.         // goes back to the exercise list
  266.         header('Location: exercice.php');
  267.         exit();
  268.     }
  269. }
  270.  
  271. // if cancelling question creation/modification
  272. if($cancelQuestion)
  273. {
  274.     // if we are creating a new question from the question pool
  275.     if(!$exerciseId && !$questionId)
  276.     {
  277.         // goes back to the question pool
  278.         header('Location: question_pool.php');
  279.         exit();
  280.     }
  281.     else
  282.     {
  283.         // goes back to the question viewing
  284.         $editQuestion=$modifyQuestion;
  285.  
  286.         unset($newQuestion,$modifyQuestion);
  287.     }
  288. }
  289.  
  290. // if cancelling answer creation/modification
  291. if($cancelAnswers)
  292. {
  293.     // goes back to the question viewing
  294.     $editQuestion=$modifyAnswers;
  295.  
  296.     unset($modifyAnswers);
  297. }
  298.  
  299. // modifies the query string that is used in the link of tool name
  300. if($editQuestion || $modifyQuestion || $newQuestion || $modifyAnswers)
  301. {
  302.     $nameTools=get_lang('QuestionManagement');
  303. }
  304. else
  305. {
  306.     $nameTools=get_lang('ExerciseManagement');
  307. }
  308.  
  309. $interbreadcrumb[]=array("url" => "exercice.php","name" => get_lang('Exercices'));
  310. $interbreadcrumb[]=array("url" => "admin.php?exerciseId=".$objExercise->id,"name" => $objExercise->exercise);
  311.  
  312. // shows a link to go back to the question pool
  313. if(!$exerciseId && $nameTools != get_lang('ExerciseManagement'))
  314. {
  315.     $interbreadcrumb[]=array("url" => "question_pool.php?fromExercise=$fromExercise","name" => get_lang('QuestionPool'));
  316. }
  317.  
  318. // if the question is duplicated, disable the link of tool name
  319. if($modifyIn == 'thisExercise')
  320. {
  321.     if($buttonBack)
  322.     {
  323.         $modifyIn='allExercises';
  324.     }
  325.     else
  326.     {
  327.         $noPHP_SELF=true;
  328.     }
  329. }
  330.  
  331. $htmlHeadXtra["<script type=\"text/javascript\" src=\"../plugin/hotspot/JavaScriptFlashGateway.js\"></script>
  332. <script src=\"../plugin/hotspot/hotspot.js\" type=\"text/javascript\"></script>
  333. <script language=\"JavaScript\" type=\"text/javascript\">
  334. <!--
  335. // -----------------------------------------------------------------------------
  336. // Globals
  337. // Major version of Flash required
  338. var requiredMajorVersion = 7;
  339. // Minor version of Flash required
  340. var requiredMinorVersion = 0;
  341. // Minor version of Flash required
  342. var requiredRevision = 0;
  343. // the version of javascript supported
  344. var jsVersion = 1.0;
  345. // -----------------------------------------------------------------------------
  346. // -->
  347. </script>
  348. <script language=\"VBScript\" type=\"text/vbscript\">
  349. <!-- // Visual basic helper required to detect Flash Player ActiveX control version information
  350. Function VBGetSwfVer(i)
  351.   on error resume next
  352.   Dim swControl, swVersion
  353.   swVersion = 0
  354.  
  355.   set swControl = CreateObject(\"ShockwaveFlash.ShockwaveFlash.\" + CStr(i))
  356.   if (IsObject(swControl)) then
  357.     swVersion = swControl.GetVariable(\"\$version\")
  358.   end if
  359.   VBGetSwfVer = swVersion
  360. End Function
  361. // -->
  362. </script>
  363.  
  364. <script language=\"JavaScript1.1\" type=\"text/javascript\">
  365. <!-- // Detect Client Browser type
  366. var isIE  = (navigator.appVersion.indexOf(\"MSIE\") != -1) ? true : false;
  367. var isWin = (navigator.appVersion.toLowerCase().indexOf(\"win\") != -1) ? true : false;
  368. var isOpera = (navigator.userAgent.indexOf(\"Opera\") != -1) ? true : false;
  369. jsVersion = 1.1;
  370. // JavaScript helper required to detect Flash Player PlugIn version information
  371. function JSGetSwfVer(i){
  372.     // NS/Opera version >= 3 check for Flash plugin in plugin array
  373.     if (navigator.plugins != null && navigator.plugins.length > 0) {
  374.         if (navigator.plugins[\"Shockwave Flash 2.0\"] || navigator.plugins[\"Shockwave Flash\"]) {
  375.             var swVer2 = navigator.plugins[\"Shockwave Flash 2.0\"] ? \" 2.0\" : \"\";
  376.               var flashDescription = navigator.plugins[\"Shockwave Flash\" + swVer2].description;
  377.             descArray = flashDescription.split(\" \");
  378.             tempArrayMajor = descArray[2].split(\".\");
  379.             versionMajor = tempArrayMajor[0];
  380.             versionMinor = tempArrayMajor[1];
  381.             if ( descArray[3] != \"\" ) {
  382.                 tempArrayMinor = descArray[3].split(\"r\");
  383.             } else {
  384.                 tempArrayMinor = descArray[4].split(\"r\");
  385.             }
  386.               versionRevision = tempArrayMinor[1] > 0 ? tempArrayMinor[1] : 0;
  387.             flashVer = versionMajor + \".\" + versionMinor + \".\" + versionRevision;
  388.           } else {
  389.             flashVer = -1;
  390.         }
  391.     }
  392.     // MSN/WebTV 2.6 supports Flash 4
  393.     else if (navigator.userAgent.toLowerCase().indexOf(\"webtv/2.6\") != -1) flashVer = 4;
  394.     // WebTV 2.5 supports Flash 3
  395.     else if (navigator.userAgent.toLowerCase().indexOf(\"webtv/2.5\") != -1) flashVer = 3;
  396.     // older WebTV supports Flash 2
  397.     else if (navigator.userAgent.toLowerCase().indexOf(\"webtv\") != -1) flashVer = 2;
  398.     // Can't detect in all other cases
  399.     else {
  400.  
  401.         flashVer = -1;
  402.     }
  403.     return flashVer;
  404. }
  405. // When called with reqMajorVer, reqMinorVer, reqRevision returns true if that version or greater is available
  406. function DetectFlashVer(reqMajorVer, reqMinorVer, reqRevision)
  407. {
  408.      reqVer = parseFloat(reqMajorVer + \".\" + reqRevision);
  409.        // loop backwards through the versions until we find the newest version
  410.     for (i=25;i>0;i--) {
  411.         if (isIE && isWin && !isOpera) {
  412.             versionStr = VBGetSwfVer(i);
  413.         } else {
  414.             versionStr = JSGetSwfVer(i);
  415.         }
  416.         if (versionStr == -1 ) {
  417.             return false;
  418.         } else if (versionStr != 0) {
  419.             if(isIE && isWin && !isOpera) {
  420.                 tempArray         = versionStr.split(\" \");
  421.                 tempString        = tempArray[1];
  422.                 versionArray      = tempString .split(\",\");
  423.             } else {
  424.                 versionArray      = versionStr.split(\".\");
  425.             }
  426.             versionMajor      = versionArray[0];
  427.             versionMinor      = versionArray[1];
  428.             versionRevision   = versionArray[2];
  429.  
  430.             versionString     = versionMajor + \".\" + versionRevision;   // 7.0r24 == 7.24
  431.             versionNum        = parseFloat(versionString);
  432.             // is the major.revision >= requested major.revision AND the minor version >= requested minor
  433.             if ( (versionMajor > reqMajorVer) && (versionNum >= reqVer) ) {
  434.                 return true;
  435.             } else {
  436.                 return ((versionNum >= reqVer && versionMinor >= reqMinorVer) ? true : false );
  437.             }
  438.         }
  439.     }
  440. }
  441. // -->
  442. </script>";
  443. Display::display_header($nameTools,"Exercise");
  444.  
  445. if(isset($_GET['message']))
  446. {
  447.     if (in_array($_GET['message']array('ExerciseStored')))
  448.     {
  449.         Display::display_confirmation_message(get_lang($_GET['message']));
  450.     }
  451. }
  452.  
  453. $description $objExercise->selectDescription();
  454. echo '<h3 style="display:inline">'.$objExercise->selectTitle().'</h3>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;--> <a href="exercice_submit.php?'.api_get_cidreq().'&exerciseId='.$objExercise->id.'">'.get_lang('Preview').'</a>';
  455. if(!empty($description))
  456. {
  457.     echo '<div id="description_box">'.stripslashes($description).'</div>';
  458. }
  459. echo '<br /><br />';
  460.  
  461. if($newQuestion || $editQuestion)
  462. {
  463.     // statement management
  464.     $type $_REQUEST['answerType'];
  465.     ?><input type="hidden" name="Type" value="<?php echo $type?>" />
  466.     <?php
  467.     include('question_admin.inc.php');
  468. }
  469. if(isset($_GET['hotspotadmin']))
  470. {
  471.     include('hotspot_admin.inc.php');
  472. }
  473. if(!$newQuestion && !$modifyQuestion && !$editQuestion && !isset($_GET['hotspotadmin']))
  474. {
  475.     // question list management
  476.     include('question_list_admin.inc.php');
  477.  
  478. }
  479.  
  480.  
  481. api_session_register('objExercise');
  482. api_session_register('objQuestion');
  483. api_session_register('objAnswer');
  484.  
  485. ?>

Documentation generated on Thu, 12 Jun 2008 12:54:39 -0500 by phpDocumentor 1.4.1