admin.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492
  1. <?php // $Id: admin.php 9665 2006-10-24 10:43:48Z elixir_inter $
  2. /*
  3. ==============================================================================
  4. Dokeos - elearning and course management software
  5. Copyright (c) 2004 Dokeos S.A.
  6. Copyright (c) 2003 Ghent University (UGent)
  7. Copyright (c) 2001 Universite catholique de Louvain (UCL)
  8. Copyright (c) Olivier Brouckaert
  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: Dokeos, 181 rue Royale, B-1000 Brussels, Belgium, info@dokeos.com
  17. ==============================================================================
  18. */
  19. /**
  20. * EXERCISE ADMINISTRATION
  21. * This script allows to manage (create, modify) an exercise and its questions
  22. *
  23. * Following scripts are includes for a best code understanding :
  24. *
  25. * - exercise.class.php : for the creation of an Exercise object
  26. * - question.class.php : for the creation of a Question object
  27. * - answer.class.php : for the creation of an Answer object
  28. *
  29. * - exercise.lib.php : functions used in the exercise tool
  30. *
  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. *
  41. * - $objExercise : exercise object
  42. * - $objQuestion : question object
  43. * - $objAnswer : answer object
  44. *
  45. * - $aType : array with answer types
  46. * - $exerciseId : the exercise ID
  47. * - $picturePath : the path of question pictures
  48. *
  49. * - $newQuestion : ask to create a new question
  50. * - $modifyQuestion : ID of the question to modify
  51. * - $editQuestion : ID of the question to edit
  52. * - $submitQuestion : ask to save question modifications
  53. * - $cancelQuestion : ask to cancel question modifications
  54. * - $deleteQuestion : ID of the question to delete
  55. * - $moveUp : ID of the question to move up
  56. * - $moveDown : ID of the question to move down
  57. * - $modifyExercise : ID of the exercise to modify
  58. * - $submitExercise : ask to save exercise modifications
  59. * - $cancelExercise : ask to cancel exercise modifications
  60. * - $modifyAnswers : ID of the question which we want to modify answers for
  61. * - $cancelAnswers : ask to cancel answer modifications
  62. * - $buttonBack : ask to go back to the previous page in answers of type "Fill in blanks"
  63. *
  64. * @author Olivier Brouckaert
  65. * @package dokeos.exercise
  66. */
  67. include('exercise.class.php');
  68. include('question.class.php');
  69. include('answer.class.php');
  70. $langFile='exercice';
  71. include("../inc/global.inc.php");
  72. include('exercise.lib.php');
  73. $this_section=SECTION_COURSES;
  74. include_once(api_get_path(LIBRARY_PATH).'fileUpload.lib.php');
  75. include_once(api_get_path(LIBRARY_PATH).'document.lib.php');
  76. /****************************/
  77. /* stripslashes POST data */
  78. /****************************/
  79. if($_SERVER['REQUEST_METHOD'] == 'POST')
  80. {
  81. foreach($_POST as $key=>$val)
  82. {
  83. if(is_string($val))
  84. {
  85. $_POST[$key]=stripslashes($val);
  86. }
  87. elseif(is_array($val))
  88. {
  89. foreach($val as $key2=>$val2)
  90. {
  91. $_POST[$key][$key2]=stripslashes($val2);
  92. }
  93. }
  94. $GLOBALS[$key]=$_POST[$key];
  95. }
  96. }
  97. // get vars from GET
  98. if ( empty ( $exerciseId ) ) {
  99. $exerciseId = mysql_real_escape_string($_GET['exerciseId']);
  100. }
  101. if ( empty ( $newQuestion ) ) {
  102. $newQuestion = $_GET['newQuestion'];
  103. }
  104. if ( empty ( $modifyAnswers ) ) {
  105. $modifyAnswers = $_GET['modifyAnswers'];
  106. }
  107. if ( empty ( $editQuestion ) ) {
  108. $editQuestion = $_GET['editQuestion'];
  109. }
  110. if ( empty ( $modifyQuestion ) ) {
  111. $modifyQuestion = $_GET['modifyQuestion'];
  112. }
  113. if ( empty ( $deleteQuestion ) ) {
  114. $deleteQuestion = $_GET['deleteQuestion'];
  115. }
  116. if ( empty ( $questionId ) ) {
  117. $questionId = $_SESSION['questionId'];
  118. }
  119. if ( empty ( $modifyExercise ) ) {
  120. $modifyExercise = $_GET['modifyExercise'];
  121. }
  122. // get from session
  123. $objExercise = $_SESSION['objExercise'];
  124. $objQuestion = $_SESSION['objQuestion'];
  125. $objAnswer = $_SESSION['objAnswer'];
  126. // answer types
  127. define(UNIQUE_ANSWER, 1);
  128. define(MULTIPLE_ANSWER, 2);
  129. define(FILL_IN_BLANKS, 3);
  130. define(MATCHING, 4);
  131. define(FREE_ANSWER, 5);
  132. define(HOT_SPOT, 6);
  133. define(HOT_SPOT_ORDER, 7);
  134. // allows script inclusions
  135. define(ALLOWED_TO_INCLUDE,1);
  136. $is_allowedToEdit=$is_courseAdmin;
  137. // document path
  138. $documentPath=api_get_path(SYS_COURSE_PATH).$_course['path'].'/document';
  139. // picture path
  140. $picturePath=$documentPath.'/images';
  141. // audio path
  142. $audioPath=$documentPath.'/audio';
  143. // the 5 types of answers
  144. $aType=array(get_lang('langUniqueSelect'),get_lang('langMultipleSelect'),get_lang('langFillBlanks'),get_lang('langMatching'),get_lang('freeAnswer'));
  145. // tables used in the exercise tool
  146. $TBL_EXERCICE_QUESTION = $_course['dbNameGlu'].'quiz_rel_question';
  147. $TBL_EXERCICES = $_course['dbNameGlu'].'quiz';
  148. $TBL_QUESTIONS = $_course['dbNameGlu'].'quiz_question';
  149. $TBL_REPONSES = $_course['dbNameGlu'].'quiz_answer';
  150. $TBL_DOCUMENT = $_course['dbNameGlu']."document";
  151. if(!$is_allowedToEdit)
  152. {
  153. api_not_allowed();
  154. }
  155. // intializes the Exercise object
  156. if(!is_object($objExercise))
  157. {
  158. // construction of the Exercise object
  159. $objExercise=new Exercise();
  160. // creation of a new exercise if wrong or not specified exercise ID
  161. if($exerciseId)
  162. {
  163. $objExercise->read($exerciseId);
  164. }
  165. // saves the object into the session
  166. api_session_register('objExercise');
  167. }
  168. // doesn't select the exercise ID if we come from the question pool
  169. if(!$fromExercise)
  170. {
  171. // gets the right exercise ID, and if 0 creates a new exercise
  172. if(!$exerciseId=$objExercise->selectId())
  173. {
  174. $modifyExercise='yes';
  175. }
  176. }
  177. $nbrQuestions=$objExercise->selectNbrQuestions();
  178. // intializes the Question object
  179. if($editQuestion || $newQuestion || $modifyQuestion || $modifyAnswers)
  180. {
  181. if($editQuestion || $newQuestion)
  182. {
  183. // construction of the Question object
  184. $objQuestion=new Question();
  185. // saves the object into the session
  186. api_session_register('objQuestion');
  187. // reads question data
  188. if($editQuestion)
  189. {
  190. // question not found
  191. if(!$objQuestion->read($editQuestion))
  192. {
  193. die(get_lang('QuestionNotFound'));
  194. }
  195. }
  196. }
  197. // checks if the object exists
  198. if(is_object($objQuestion))
  199. {
  200. // gets the question ID
  201. $questionId=$objQuestion->selectId();
  202. }
  203. // question not found
  204. else
  205. {
  206. die(get_lang('QuestionNotFound'));
  207. }
  208. }
  209. // if cancelling an exercise
  210. if($cancelExercise)
  211. {
  212. // existing exercise
  213. if($exerciseId)
  214. {
  215. unset($modifyExercise);
  216. }
  217. // new exercise
  218. else
  219. {
  220. // goes back to the exercise list
  221. header('Location: exercice.php');
  222. exit();
  223. }
  224. }
  225. // if cancelling question creation/modification
  226. if($cancelQuestion)
  227. {
  228. // if we are creating a new question from the question pool
  229. if(!$exerciseId && !$questionId)
  230. {
  231. // goes back to the question pool
  232. header('Location: question_pool.php');
  233. exit();
  234. }
  235. else
  236. {
  237. // goes back to the question viewing
  238. $editQuestion=$modifyQuestion;
  239. unset($newQuestion,$modifyQuestion);
  240. }
  241. }
  242. // if cancelling answer creation/modification
  243. if($cancelAnswers)
  244. {
  245. // goes back to the question viewing
  246. $editQuestion=$modifyAnswers;
  247. unset($modifyAnswers);
  248. }
  249. // modifies the query string that is used in the link of tool name
  250. if($editQuestion || $modifyQuestion || $newQuestion || $modifyAnswers)
  251. {
  252. $nameTools=get_lang('QuestionManagement');
  253. }
  254. else
  255. {
  256. $nameTools=get_lang('ExerciseManagement');
  257. }
  258. $interbreadcrump[]=array("url" => "exercice.php","name" => get_lang('Exercices'));
  259. // shows a link to go back to the question pool
  260. if(!$exerciseId && $nameTools != get_lang('ExerciseManagement'))
  261. {
  262. $interbreadcrump[]=array("url" => "question_pool.php?fromExercise=$fromExercise","name" => get_lang('QuestionPool'));
  263. }
  264. // if the question is duplicated, disable the link of tool name
  265. if($modifyIn == 'thisExercise')
  266. {
  267. if($buttonBack)
  268. {
  269. $modifyIn='allExercises';
  270. }
  271. else
  272. {
  273. $noPHP_SELF=true;
  274. }
  275. }
  276. $htmlHeadXtra[] = "<script type=\"text/javascript\" src=\"../plugin/hotspot/JavaScriptFlashGateway.js\"></script>
  277. <script src=\"../plugin/hotspot/hotspot.js\" type=\"text/javascript\"></script>
  278. <script language=\"JavaScript\" type=\"text/javascript\">
  279. <!--
  280. // -----------------------------------------------------------------------------
  281. // Globals
  282. // Major version of Flash required
  283. var requiredMajorVersion = 7;
  284. // Minor version of Flash required
  285. var requiredMinorVersion = 0;
  286. // Minor version of Flash required
  287. var requiredRevision = 0;
  288. // the version of javascript supported
  289. var jsVersion = 1.0;
  290. // -----------------------------------------------------------------------------
  291. // -->
  292. </script>
  293. <script language=\"VBScript\" type=\"text/vbscript\">
  294. <!-- // Visual basic helper required to detect Flash Player ActiveX control version information
  295. Function VBGetSwfVer(i)
  296. on error resume next
  297. Dim swControl, swVersion
  298. swVersion = 0
  299. set swControl = CreateObject(\"ShockwaveFlash.ShockwaveFlash.\" + CStr(i))
  300. if (IsObject(swControl)) then
  301. swVersion = swControl.GetVariable(\"\$version\")
  302. end if
  303. VBGetSwfVer = swVersion
  304. End Function
  305. // -->
  306. </script>
  307. <script language=\"JavaScript1.1\" type=\"text/javascript\">
  308. <!-- // Detect Client Browser type
  309. var isIE = (navigator.appVersion.indexOf(\"MSIE\") != -1) ? true : false;
  310. var isWin = (navigator.appVersion.toLowerCase().indexOf(\"win\") != -1) ? true : false;
  311. var isOpera = (navigator.userAgent.indexOf(\"Opera\") != -1) ? true : false;
  312. jsVersion = 1.1;
  313. // JavaScript helper required to detect Flash Player PlugIn version information
  314. function JSGetSwfVer(i){
  315. // NS/Opera version >= 3 check for Flash plugin in plugin array
  316. if (navigator.plugins != null && navigator.plugins.length > 0) {
  317. if (navigator.plugins[\"Shockwave Flash 2.0\"] || navigator.plugins[\"Shockwave Flash\"]) {
  318. var swVer2 = navigator.plugins[\"Shockwave Flash 2.0\"] ? \" 2.0\" : \"\";
  319. var flashDescription = navigator.plugins[\"Shockwave Flash\" + swVer2].description;
  320. descArray = flashDescription.split(\" \");
  321. tempArrayMajor = descArray[2].split(\".\");
  322. versionMajor = tempArrayMajor[0];
  323. versionMinor = tempArrayMajor[1];
  324. if ( descArray[3] != \"\" ) {
  325. tempArrayMinor = descArray[3].split(\"r\");
  326. } else {
  327. tempArrayMinor = descArray[4].split(\"r\");
  328. }
  329. versionRevision = tempArrayMinor[1] > 0 ? tempArrayMinor[1] : 0;
  330. flashVer = versionMajor + \".\" + versionMinor + \".\" + versionRevision;
  331. } else {
  332. flashVer = -1;
  333. }
  334. }
  335. // MSN/WebTV 2.6 supports Flash 4
  336. else if (navigator.userAgent.toLowerCase().indexOf(\"webtv/2.6\") != -1) flashVer = 4;
  337. // WebTV 2.5 supports Flash 3
  338. else if (navigator.userAgent.toLowerCase().indexOf(\"webtv/2.5\") != -1) flashVer = 3;
  339. // older WebTV supports Flash 2
  340. else if (navigator.userAgent.toLowerCase().indexOf(\"webtv\") != -1) flashVer = 2;
  341. // Can't detect in all other cases
  342. else {
  343. flashVer = -1;
  344. }
  345. return flashVer;
  346. }
  347. // When called with reqMajorVer, reqMinorVer, reqRevision returns true if that version or greater is available
  348. function DetectFlashVer(reqMajorVer, reqMinorVer, reqRevision)
  349. {
  350. reqVer = parseFloat(reqMajorVer + \".\" + reqRevision);
  351. // loop backwards through the versions until we find the newest version
  352. for (i=25;i>0;i--) {
  353. if (isIE && isWin && !isOpera) {
  354. versionStr = VBGetSwfVer(i);
  355. } else {
  356. versionStr = JSGetSwfVer(i);
  357. }
  358. if (versionStr == -1 ) {
  359. return false;
  360. } else if (versionStr != 0) {
  361. if(isIE && isWin && !isOpera) {
  362. tempArray = versionStr.split(\" \");
  363. tempString = tempArray[1];
  364. versionArray = tempString .split(\",\");
  365. } else {
  366. versionArray = versionStr.split(\".\");
  367. }
  368. versionMajor = versionArray[0];
  369. versionMinor = versionArray[1];
  370. versionRevision = versionArray[2];
  371. versionString = versionMajor + \".\" + versionRevision; // 7.0r24 == 7.24
  372. versionNum = parseFloat(versionString);
  373. // is the major.revision >= requested major.revision AND the minor version >= requested minor
  374. if ( (versionMajor > reqMajorVer) && (versionNum >= reqVer) ) {
  375. return true;
  376. } else {
  377. return ((versionNum >= reqVer && versionMinor >= reqMinorVer) ? true : false );
  378. }
  379. }
  380. }
  381. }
  382. // -->
  383. </script>";
  384. Display::display_header($nameTools,"Exercise");
  385. ?>
  386. <h4>
  387. <?php echo $nameTools; ?>
  388. </h4>
  389. <?php
  390. if($newQuestion || $modifyQuestion)
  391. {
  392. // statement management
  393. $type = $_REQUEST['answerType'];
  394. ?><input type="hidden" name="Type" value=" <?= $type; ?>" />
  395. <?php
  396. include("statement_admin.inc.php");
  397. }
  398. /*if($modifyAnswers && !$_REQUEST['setWeighting'])
  399. { // this might be loaded after statement_admin (second step of answers writing)
  400. // and $modifyAnswers is then set within statement_admin.inc.php
  401. // answer management
  402. include('answer_admin.inc.php');
  403. }
  404. */
  405. if($modifyAnswers)
  406. { // this might be loaded after statement_admin (second step of answers writing)
  407. // and $modifyAnswers is then set within statement_admin.inc.php
  408. // answer management
  409. include('answer_admin.inc.php');
  410. }
  411. if($editQuestion || $usedInSeveralExercises)
  412. {
  413. // question management
  414. include('question_admin.inc.php');
  415. }
  416. if(!$newQuestion && !$modifyQuestion && !$editQuestion && !$modifyAnswers)
  417. {
  418. // exercise management
  419. include('exercise_admin.inc.php');
  420. if(!$modifyExercise)
  421. {
  422. // question list management
  423. include('question_list_admin.inc.php');
  424. }
  425. }
  426. api_session_register('objExercise');
  427. api_session_register('objQuestion');
  428. api_session_register('objAnswer');
  429. Display::display_footer();
  430. ?>