admin.php 15 KB

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