admin.php 14 KB

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