question_pool.php 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Question Pool
  5. * This script allows administrators to manage questions and add them into their exercises.
  6. * One question can be in several exercises
  7. * @package chamilo.exercise
  8. * @author Olivier Brouckaert
  9. * @author Julio Montoya adding support to query all questions from all session, courses, exercises
  10. * @author Modify by hubert borderiou 2011-10-21 Question's category
  11. */
  12. /**
  13. * Code
  14. */
  15. // name of the language file that needs to be included
  16. $language_file = 'exercice';
  17. require_once 'exercise.class.php';
  18. require_once 'question.class.php';
  19. require_once 'answer.class.php';
  20. require_once '../inc/global.inc.php';
  21. require_once 'exercise.lib.php';
  22. $this_section = SECTION_COURSES;
  23. $is_allowedToEdit=api_is_allowed_to_edit(null,true);
  24. if (empty($delete)) {
  25. $delete = intval($_GET['delete']);
  26. }
  27. if ( empty ( $recup ) ) {
  28. $recup = intval($_GET['recup']);
  29. }
  30. if ( empty ( $fromExercise ) ) {
  31. $fromExercise = intval($_REQUEST['fromExercise']);
  32. }
  33. if(isset($_GET['exerciseId'])){
  34. $exerciseId = intval($_GET['exerciseId']);
  35. }
  36. if (isset($_GET['courseCategoryId'])) {
  37. $courseCategoryId = intval($_GET['courseCategoryId']);
  38. }
  39. $exerciseLevel = -1;
  40. if(isset($_REQUEST['exerciseLevel'])){
  41. $exerciseLevel = intval($_REQUEST['exerciseLevel']);
  42. }
  43. if(isset($_GET['answerType'])){
  44. $answerType = intval($_REQUEST['answerType']);
  45. }
  46. $page = 0;
  47. if(!empty($_GET['page'])){
  48. $page = intval($_GET['page']);
  49. }
  50. $copy_question = 0;
  51. if(!empty($_GET['copy_question'])){
  52. $copy_question = intval($_GET['copy_question']);
  53. }
  54. $session_id = intval($_GET['session_id']);
  55. $selected_course = intval($_GET['selected_course']);
  56. $course_id_changed = intval($_GET['course_id_changed']); // save the id of the previous course selected by user to reset menu if we detect that user change course hub 13-10-2011
  57. $exercice_id_changed = intval($_GET['exercice_id_changed']); // save the id of the previous exercice selected by user to reset menu if we detect that user change course hub 13-10-2011
  58. // by default when we go to the page for the first time, we select the current course
  59. if (!isset($_GET['selected_course']) && !isset($_GET['exerciseId'])) {
  60. $selected_course = api_get_course_int_id();
  61. }
  62. // document path
  63. $documentPath = api_get_path(SYS_COURSE_PATH).$_course['path'].'/document';
  64. // picture path
  65. $picturePath = $documentPath.'/images';
  66. if(!($objExcercise instanceOf Exercise) && !empty($fromExercise)) {
  67. $objExercise = new Exercise();
  68. $objExercise->read($fromExercise);
  69. }
  70. $nameTools = get_lang('QuestionPool');
  71. $interbreadcrumb[] = array("url" => "exercice.php","name" => get_lang('Exercices'));
  72. $interbreadcrumb[] = array("url" => "admin.php?exerciseId=".$objExercise->id, "name" => $objExercise->name);
  73. $displayMessage = ""; // messag to be displayed if actions succesfull
  74. if ($is_allowedToEdit) {
  75. //Duplicating a Question
  76. if (!isset($_POST['recup']) && $copy_question != 0 && isset($fromExercise)) {
  77. $origin_course_id = intval($_GET['course_id']);
  78. $origin_course_info = api_get_course_info_by_id($origin_course_id);
  79. $current_course = api_get_course_info();
  80. $old_question_id = $copy_question;
  81. //Reading the source question
  82. $old_question_obj = Question::read($old_question_id, $origin_course_id);
  83. if ($old_question_obj) {
  84. $old_question_obj->updateTitle($old_question_obj->selectTitle().' - '.get_lang('Copy'));
  85. //Duplicating the source question, in the current course
  86. $new_id = $old_question_obj->duplicate($current_course);
  87. //Reading new question
  88. $new_question_obj = Question::read($new_id);
  89. $new_question_obj->addToList($fromExercise);
  90. //Reading Answers obj of the current course
  91. $new_answer_obj = new Answer($old_question_id, $origin_course_id);
  92. $new_answer_obj->read();
  93. //Duplicating the Answers in the current course
  94. $new_answer_obj->duplicate($new_id, $current_course);
  95. // destruction of the Question object
  96. unset($new_question_obj);
  97. unset($old_question_obj);
  98. if (!$objExcercise instanceOf Exercise) {
  99. $objExercise = new Exercise();
  100. $objExercise->read($fromExercise);
  101. }
  102. api_session_register('objExercise');
  103. }
  104. $displayMessage = get_lang('ItemAdded');
  105. // header("Location: admin.php?".api_get_cidreq()."&exerciseId=$fromExercise");
  106. // exit();
  107. }
  108. // deletes a question from the database and all exercises
  109. if ($delete) {
  110. // construction of the Question object
  111. // if the question exists
  112. if($objQuestionTmp = Question::read($delete)) {
  113. // deletes the question from all exercises
  114. $objQuestionTmp->delete();
  115. }
  116. // destruction of the Question object
  117. unset($objQuestionTmp);
  118. } elseif($recup && $fromExercise) {
  119. // gets an existing question and copies it into a new exercise
  120. $objQuestionTmp = Question :: read($recup);
  121. // if the question exists
  122. if($objQuestionTmp = Question :: read($recup)) {
  123. // adds the exercise ID represented by $fromExercise into the list of exercises for the current question
  124. $objQuestionTmp->addToList($fromExercise);
  125. }
  126. // destruction of the Question object
  127. unset($objQuestionTmp);
  128. if (!$objExcercise instanceOf Exercise) {
  129. $objExercise = new Exercise();
  130. $objExercise->read($fromExercise);
  131. }
  132. // adds the question ID represented by $recup into the list of questions for the current exercise
  133. $objExercise->addToList($recup);
  134. api_session_register('objExercise');
  135. // header("Location: admin.php?".api_get_cidreq()."&exerciseId=$fromExercise");
  136. // exit();
  137. }
  138. else if( isset($_POST['recup']) && is_array($_POST['recup']) && $fromExercise) {
  139. $list_recup = $_POST['recup'];
  140. foreach ($list_recup as $course_id => $question_data) {
  141. $origin_course_id = intval($course_id);
  142. $origin_course_info = api_get_course_info_by_id($origin_course_id);
  143. $current_course = api_get_course_info();
  144. foreach ($question_data as $old_question_id) {
  145. /*
  146. $recup = intval($recup);
  147. // if the question exists
  148. if($objQuestionTmp = Question :: read($recup)) {
  149. // adds the exercise ID represented by $fromExercise into the list of exercises for the current question
  150. $objQuestionTmp->addToList($fromExercise);
  151. }
  152. // destruction of the Question object
  153. unset($objQuestionTmp);
  154. if(!$objExcercise instanceOf Exercise) {
  155. $objExercise = new Exercise();
  156. $objExercise->read($fromExercise);
  157. }
  158. // adds the question ID represented by $recup into the list of questions for the current exercise
  159. $objExercise->addToList($recup);
  160. */
  161. //Reading the source question
  162. $old_question_obj = Question::read($old_question_id, $origin_course_id);
  163. if ($old_question_obj) {
  164. $old_question_obj->updateTitle($old_question_obj->selectTitle().' - '.get_lang('Copy'));
  165. //Duplicating the source question, in the current course
  166. $new_id = $old_question_obj->duplicate($current_course);
  167. //Reading new question
  168. $new_question_obj = Question::read($new_id);
  169. $new_question_obj->addToList($fromExercise);
  170. //Reading Answers obj of the current course
  171. $new_answer_obj = new Answer($old_question_id, $origin_course_id);
  172. $new_answer_obj->read();
  173. //Duplicating the Answers in the current course
  174. $new_answer_obj->duplicate($new_id, $current_course);
  175. // destruction of the Question object
  176. unset($new_question_obj);
  177. unset($old_question_obj);
  178. if (!$objExcercise instanceOf Exercise) {
  179. $objExercise = new Exercise();
  180. $objExercise->read($fromExercise);
  181. }
  182. }
  183. }
  184. }
  185. api_session_register('objExercise');
  186. // header("Location: admin.php?".api_get_cidreq()."&exerciseId=$fromExercise");
  187. // exit();
  188. }
  189. }
  190. if (isset($_SESSION['gradebook'])){
  191. $gradebook= $_SESSION['gradebook'];
  192. }
  193. if (!empty($gradebook) && $gradebook=='view') {
  194. $interbreadcrumb[]= array ('url' => '../gradebook/'.Security::remove_XSS($_SESSION['gradebook_dest']),'name' => get_lang('ToolGradebook'));
  195. }
  196. // if admin of course
  197. if (!$is_allowedToEdit) {
  198. api_not_allowed(true);
  199. }
  200. $confirmYourChoice = addslashes(api_htmlentities(get_lang('ConfirmYourChoice'),ENT_QUOTES,$charset));
  201. $htmlHeadXtra[] = "
  202. <script type='text/javascript'>
  203. function submit_form(obj) {
  204. document.question_pool.submit();
  205. }
  206. function mark_course_id_changed() {
  207. $('#course_id_changed').val('1');
  208. }
  209. function mark_exercice_id_changed() {
  210. $('#exercice_id_changed').val('1');
  211. }
  212. function confirm_your_choice() {
  213. return confirm('$confirmYourChoice');
  214. }
  215. </script>
  216. ";
  217. Display::display_header($nameTools,'Exercise');
  218. // Menu
  219. echo '<div class="actions">';
  220. if (isset($type)) {
  221. $url = api_get_self().'?type=1';
  222. } else {
  223. $url = api_get_self();
  224. }
  225. if (isset($fromExercise) && $fromExercise > 0) {
  226. echo '<a href="admin.php?'.api_get_cidreq().'&exerciseId='.$fromExercise.'">'.Display::return_icon('back.png', get_lang('GoBackToQuestionList'),'',ICON_SIZE_MEDIUM).'</a>';
  227. $titleAdd = get_lang('AddQuestionToTest');
  228. }
  229. else {
  230. echo '<a href="exercice.php?'.api_get_cidReq().'">'.Display::return_icon('back.png', get_lang('BackToExercisesList'),'',ICON_SIZE_MEDIUM).'</a>';
  231. echo "<a href='admin.php?exerciseId=0'>".Display::return_icon('add_question.gif', get_lang('NewQu'), '', 32)."</a>";
  232. $titleAdd = get_lang('ManageAllQuestions');
  233. }
  234. echo '</div>';
  235. if ($displayMessage != "") {
  236. Display::display_confirmation_message($displayMessage);
  237. $displayMessage = "";
  238. }
  239. //Title
  240. echo '<h2>'.$nameTools.' - '.$titleAdd.'</h2>';
  241. //Form
  242. echo '<form name="question_pool" method="GET" action="'.$url.'">';
  243. if (isset($type)) {
  244. echo '<input type="hidden" name="type" value="1">';
  245. }
  246. echo '<input type="hidden" name="fromExercise" value="'.$fromExercise.'">';
  247. // Session list, if sessions are used.
  248. $session_list = SessionManager::get_sessions_by_coach(api_get_user_id());
  249. $tabAttrParam = array('class'=>'chzn-select', 'onchange'=>'submit_form(this)'); // when sessions are used
  250. $labelFormRow = get_lang('Session');
  251. if (api_get_setting('use_session_mode') == 'false') {
  252. $tabAttrParam = array('style'=>'visibility:hidden', 'onchange'=>'submit_form(this)');
  253. $labelFormRow = "";
  254. }
  255. $session_select_list = array();
  256. foreach($session_list as $item) {
  257. $session_select_list[$item['id']] = $item['name'];
  258. }
  259. $select_session_html = Display::select('session_id', $session_select_list, $session_id, $tabAttrParam);
  260. echo Display::form_row($labelFormRow, $select_session_html); // hub 13-10-2011
  261. // Course list, get course list of session, or for course where user is admin
  262. if (!empty($session_id) && $session_id != '-1') {
  263. $course_list = SessionManager::get_course_list_by_session_id($session_id);
  264. } else {
  265. $course_list = CourseManager::get_course_list_of_user_as_course_admin(api_get_user_id());
  266. }
  267. $course_select_list = array();
  268. foreach ($course_list as $item) {
  269. $course_select_list[$item['id']] = "";
  270. if ($item['id'] == api_get_course_int_id()) {
  271. $course_select_list[$item['id']] = ">&nbsp;&nbsp;&nbsp;&nbsp;";
  272. }
  273. $course_select_list[$item['id']] .= $item['title'];
  274. }
  275. $select_course_html = Display::select('selected_course', $course_select_list, $selected_course, array('class'=>'chzn-select','onchange'=>'mark_course_id_changed(); submit_form(this);'));
  276. echo Display::form_row(get_lang('Course'), $select_course_html);
  277. if (empty($selected_course) || $selected_course == '-1') {
  278. $course_info = api_get_course_info();
  279. reset_menu_exo_lvl_type(); // no course selected, reset menu test / difficult� / type de reponse // hub 13-10-2011
  280. }
  281. else {
  282. $course_info = CourseManager::get_course_information_by_id($selected_course);
  283. }
  284. // If course has changed, reset the menu default
  285. if ($course_id_changed) {
  286. reset_menu_exo_lvl_type();
  287. }
  288. $course_id = $course_info['real_id'];
  289. //Redefining table calls
  290. $TBL_EXERCICE_QUESTION = Database::get_course_table(TABLE_QUIZ_TEST_QUESTION);
  291. $TBL_EXERCICES = Database::get_course_table(TABLE_QUIZ_TEST);
  292. $TBL_QUESTIONS = Database::get_course_table(TABLE_QUIZ_QUESTION);
  293. $TBL_REPONSES = Database::get_course_table(TABLE_QUIZ_ANSWER);
  294. $TBL_CATEGORY = Database::get_course_table(TABLE_QUIZ_QUESTION_CATEGORY); // hub 13-10-2011
  295. $TBL_COURSE_REL_CATEGORY = Database::get_course_table(TABLE_QUIZ_QUESTION_REL_CATEGORY); // hub 13-10-2011
  296. // Get course categories for the selected course
  297. // get category list for the course $selected_course
  298. $tabCatList = Testcategory::getCategoriesIdAndName($selected_course);
  299. $selectCourseCateogry = Display::select('courseCategoryId', $tabCatList, $courseCategoryId, array('class'=>'chzn-select','onchange'=>'submit_form(this);'), false);
  300. echo Display::form_row(get_lang("QuestionCategory"), $selectCourseCateogry);
  301. // Get exercice list for this course
  302. $exercise_list = get_all_exercises_for_course_id($course_info, $session_id, $selected_course);
  303. //Exercise List
  304. $my_exercise_list = array();
  305. $my_exercise_list['0'] = get_lang('AllExercises');
  306. $my_exercise_list['-1'] = get_lang('OrphanQuestions');
  307. if (is_array($exercise_list)) {
  308. foreach($exercise_list as $row) {
  309. $my_exercise_list[$row['id']] = "";
  310. if ($row['id'] == $fromExercise && $selected_course == api_get_course_int_id()) {
  311. $my_exercise_list[$row['id']] = ">&nbsp;&nbsp;&nbsp;&nbsp;"; // hub 13-10-2011
  312. }
  313. $my_exercise_list[$row['id']] .= $row['title'];
  314. }
  315. }
  316. if ($exercice_id_changed == 1) {
  317. reset_menu_lvl_type();
  318. }
  319. $select_exercise_html = Display::select('exerciseId', $my_exercise_list, $exerciseId, array('class'=>'chzn-select','onchange'=>'mark_exercice_id_changed(); submit_form(this);'), false);
  320. echo Display::form_row(get_lang('Exercise'), $select_exercise_html);
  321. // Difficulty list (only from 0 to 5)
  322. $select_difficulty_html = Display::select('exerciseLevel', array(-1 => get_lang('All'), 0=>0, 1=>1, 2=>2, 3=>3, 4=>4, 5=>5), $exerciseLevel, array('class'=>'chzn-select', 'onchange'=>'submit_form(this);'), false);
  323. echo Display::form_row(get_lang('Difficulty'), $select_difficulty_html);
  324. // Answer type
  325. $question_list = Question::get_question_type_list();
  326. $new_question_list = array();
  327. $new_question_list['-1'] = get_lang('All');
  328. $objExercise = new Exercise();
  329. $objExercise->read($fromExercise);
  330. foreach ($question_list as $key=>$item) {
  331. if ($objExercise->feedbacktype == EXERCISE_FEEDBACK_TYPE_DIRECT) {
  332. if (!in_array($key, array(HOT_SPOT_DELINEATION, UNIQUE_ANSWER))) {
  333. continue;
  334. }
  335. $new_question_list[$key] = get_lang($item[1]);
  336. } else {
  337. if ($key == HOT_SPOT_DELINEATION) {
  338. continue;
  339. }
  340. $new_question_list[$key] = get_lang($item[1]);
  341. }
  342. }
  343. //Answer type list
  344. $select_answer_html = Display::select('answerType', $new_question_list, $answerType, array('class'=>'chzn-select','onchange'=>'submit_form(this);'), false);
  345. echo Display::form_row(get_lang('AnswerType'), $select_answer_html);
  346. $button = '<button class="save" type="submit" name="name" value="'.get_lang('Filter').'">'.get_lang('Filter').'</button>';
  347. echo Display::form_row('', $button);
  348. echo "<input type='hidden' id='course_id_changed' name='course_id_changed' value='0' />";
  349. echo "<input type='hidden' id='exercice_id_changed' name='exercice_id_changed' value='0' />";
  350. ?>
  351. </form>
  352. <div class="clear"></div>
  353. <form method="post" action="<?php echo $url.'?'.api_get_cidreq().'&fromExercise='.$fromExercise; ?>" >
  354. <?php
  355. echo '<input type="hidden" name="course_id" value="'.$selected_course.'">';
  356. // if we have selected an exercise in the list-box 'Filter'
  357. if ($exerciseId > 0) {
  358. $where = '';
  359. $from = '';
  360. if (isset($courseCategoryId) && $courseCategoryId > 0) {
  361. $from = ", $TBL_COURSE_REL_CATEGORY crc ";
  362. $where .= " AND crc.c_id=$selected_course AND crc.question_id=qu.id AND crc.category_id=$courseCategoryId";
  363. }
  364. if (isset($exerciseLevel) && $exerciseLevel != -1) {
  365. $where .= ' AND level='.$exerciseLevel;
  366. }
  367. if (isset($answerType) && $answerType > 0) {
  368. $where .= ' AND type='.$answerType;
  369. }
  370. $sql = "SELECT DISTINCT
  371. id,question,
  372. type,
  373. level
  374. FROM
  375. $TBL_EXERCICE_QUESTION qt,
  376. $TBL_QUESTIONS qu
  377. $from
  378. WHERE
  379. qt.question_id=qu.id
  380. AND qt.exercice_id=$exerciseId
  381. AND qt.c_id=$selected_course
  382. AND qu.c_id=$selected_course
  383. $where
  384. ORDER BY
  385. question_order";
  386. $result=Database::query($sql);
  387. while($row = Database::fetch_array($result, 'ASSOC')) {
  388. $main_question_list[] = $row;
  389. }
  390. } elseif ($exerciseId == -1) {
  391. //
  392. // if we have selected the option 'Orphan questions' in the list-box 'Filter'
  393. //
  394. $level_where = '';
  395. $from = '';
  396. if (isset($courseCategoryId) && $courseCategoryId > 0) {
  397. $from = ", $TBL_COURSE_REL_CATEGORY crc ";
  398. $level_where .= " AND crc.c_id=$selected_course AND crc.question_id=qu.id AND crc.category_id=$courseCategoryId";
  399. }
  400. if (isset($exerciseLevel) && $exerciseLevel!= -1 ) {
  401. $level_where = ' AND level='.$exerciseLevel;
  402. }
  403. $answer_where = '';
  404. if (isset($answerType) && $answerType >0 -1 ) {
  405. $answer_where = ' AND type='.$answerType;
  406. }
  407. $sql = "SELECT DISTINCT * FROM $TBL_QUESTIONS qu $from WHERE qu.c_id=$selected_course AND qu.id NOT IN (SELECT question_id FROM $TBL_EXERCICE_QUESTION WHERE c_id=$selected_course ) $level_where $answer_where";
  408. $result = Database::query($sql);
  409. while($row = Database::fetch_array($result, 'ASSOC')) {
  410. $main_question_list[] = $row;
  411. }
  412. }
  413. else {
  414. //
  415. // All tests for selected course
  416. //
  417. // if we have not selected any option in the list-box 'Filter'
  418. $filter = '';
  419. $from = '';
  420. if (isset($courseCategoryId) && $courseCategoryId > 0) {
  421. $from = ", $TBL_COURSE_REL_CATEGORY crc ";
  422. $filter .= " AND crc.c_id=$selected_course AND crc.question_id=qu.id AND crc.category_id=$courseCategoryId";
  423. }
  424. if (isset($exerciseLevel) && $exerciseLevel != -1) {
  425. $filter .= ' AND level='.$exerciseLevel.' ';
  426. }
  427. if (isset($answerType) && $answerType > 0) {
  428. $filter .= ' AND qu.type='.$answerType.' ';
  429. }
  430. // // why these lines ?
  431. // if ($objExercise->feedbacktype != EXERCISE_FEEDBACK_TYPE_DIRECT) {
  432. // $filter .= ' AND qu.type <> '.HOT_SPOT_DELINEATION.' ';
  433. // }
  434. // // fwhy
  435. //
  436. // if in session
  437. //
  438. if (!empty($session_id) && $session_id != '-1') {
  439. $main_question_list = array();
  440. if (!empty($course_list))
  441. foreach ($course_list as $course_item) {
  442. if (!empty($selected_course) && $selected_course != '-1') {
  443. if ($selected_course != $course_item['id']) {
  444. continue;
  445. }
  446. }
  447. $exercise_list = get_all_exercises($course_item, $session_id);
  448. if (!empty($exercise_list)) {
  449. foreach ($exercise_list as $exercise) {
  450. $my_exercise = new Exercise($course_item['id']);
  451. $my_exercise->read($exercise['id']);
  452. if (!empty($my_exercise)) {
  453. if (!empty($my_exercise->questionList)) {
  454. foreach ($my_exercise->questionList as $question_id) {
  455. $question_obj = Question::read($question_id, $course_item['id']);
  456. if ($exerciseLevel != '-1')
  457. if ($exerciseLevel != $question_obj->level) {
  458. continue;
  459. }
  460. if ($answerType > 0)
  461. if ($answerType != $question_obj->type) {
  462. continue;
  463. }
  464. if ($courseCategoryId > 0 && Testcategory::getCategoryForQuestion($question_obj->id, $selected_course)) {
  465. continue;
  466. }
  467. if ($objExercise->feedbacktype != EXERCISE_FEEDBACK_TYPE_DIRECT) {
  468. if ($question_obj->type == HOT_SPOT_DELINEATION) {
  469. continue;
  470. }
  471. }
  472. $question_row = array( 'id' => $question_obj->id,
  473. 'question' => $question_obj->question,
  474. 'type' => $question_obj->type,
  475. 'level' => $question_obj->level,
  476. 'exercise_id' => $exercise['id'],
  477. 'course_id' => $course_item['id'],
  478. );
  479. $main_question_list[] = $question_row;
  480. }
  481. }
  482. }
  483. }
  484. }
  485. }
  486. }
  487. else {
  488. //
  489. // All tests for the course selected, not in session
  490. //
  491. $sql = "SELECT DISTINCT qu.id, question, qu.type, level, q.session_id FROM $TBL_QUESTIONS as qu, $TBL_EXERCICE_QUESTION as qt, $TBL_EXERCICES as q $from WHERE qu.c_id=$selected_course AND qt.c_id=$selected_course AND q.c_id=$selected_course AND qu.id = qt.question_id AND q.id = qt.exercice_id $filter ORDER BY session_id ASC";
  492. $result = Database::query($sql);
  493. while($row = Database::fetch_array($result, 'ASSOC')) {
  494. $main_question_list[] = $row;
  495. }
  496. }
  497. // forces the value to 0
  498. $exerciseId=0;
  499. }
  500. $nbrQuestions = count($main_question_list);
  501. // build the line of the array to display questions
  502. // Actions are different if you launch the question_pool page
  503. // They are different too if you have displayed questions from your course
  504. // Or from another course you are the admin(or session admin)
  505. // from a test or not
  506. /*
  507. +--------------------------------------------+--------------------------------------------+
  508. | NOT IN A TEST | IN A TEST |
  509. +----------------------+---------------------+---------------------+----------------------+
  510. |IN THE COURSE (*) "x | NOT IN THE COURSE o | IN THE COURSE + | NOT IN THE COURSE o |
  511. +----------------------+---------------------+---------------------+----------------------+
  512. |Edit the question | Do nothing | Add question to test|Clone question in test|
  513. |Delete the question | | | |
  514. |(true delete) | | | |
  515. +----------------------+---------------------+---------------------+----------------------+
  516. (*) this is the only way to delete or modify orphan questions
  517. */
  518. //
  519. if ($fromExercise <= 0) { // NOT IN A TEST - IN THE COURSE
  520. if ($selected_course == api_get_course_int_id()) {
  521. $actionLabel = get_lang('Modify');
  522. $actionIcon1 = "edit";
  523. $actionIcon2 = "delete";
  524. $questionTagA = 1; // we are in the course, question title can be a link to the question edit page
  525. }
  526. else { // NOT IN A TEST - NOT IN THE COURSE
  527. $actionLabel = get_lang('langReuse');
  528. $actionIcon1 = get_lang('MustBeInATest');
  529. $actionIcon2 = "";
  530. $questionTagA = 0; // we are not in this course, to messy if we link to the question in another course
  531. }
  532. }
  533. else { // IN A TEST - IN THE COURSE
  534. if ($selected_course == api_get_course_int_id()) {
  535. $actionLabel = get_lang('langReuse');
  536. $actionIcon1 = "add";
  537. $actionIcon2 = "";
  538. $questionTagA = 1;
  539. }
  540. else { // IN A TEST - NOT IN THE COURSE
  541. $actionLabel = get_lang('langReuse');
  542. $actionIcon1 = "clone";
  543. $actionIcon2 = "";
  544. $questionTagA = 0;
  545. }
  546. }
  547. //
  548. // display table
  549. //
  550. $header = array();
  551. $header[] = array(get_lang('QuestionUpperCaseFirstLetter'), false, array("style"=>"text-align:center"), '');
  552. $header[] = array(get_lang('Type'), false, array("style"=>"text-align:center"), array("style"=>"text-align:center"), '');
  553. $header[] = array(get_lang('QuestionCategory'), false, array("style"=>"text-align:center"), array("style"=>"text-align:center"), '');
  554. $header[] = array(get_lang('Difficulty'), false, array("style"=>"text-align:center"), array("style"=>"text-align:center"), '');
  555. $header[] = array($actionLabel, false, array("style"=>"text-align:center"), array("style"=>"text-align:center"), '');
  556. $data = array();
  557. foreach ($main_question_list as $tabQuestion) {
  558. $row = array();
  559. //This function checks if the question can be read
  560. $question_type = get_question_type_for_question($selected_course, $tabQuestion['id']);
  561. if (empty($question_type)) {
  562. continue;
  563. }
  564. $row[] = get_a_tag_for_question($questionTagA, $fromExercise, $tabQuestion['id'], $tabQuestion['type'], $tabQuestion['question']);
  565. $row[] = $question_type;
  566. $row[] = get_question_categorie_for_question($selected_course, $tabQuestion['id']);
  567. $row[] = $tabQuestion['level'];
  568. $row[] = get_action_icon_for_question($actionIcon1, $fromExercise, $tabQuestion['id'], $tabQuestion['type'],
  569. $tabQuestion['question'], $selected_course, $courseCategoryId, $exerciseLevel,
  570. $answerType, $session_id, $exerciseId).
  571. "&nbsp;".
  572. get_action_icon_for_question($actionIcon2, $fromExercise, $tabQuestion['id'], $tabQuestion['type'],
  573. $tabQuestion['question'], $selected_course, $courseCategoryId, $exerciseLevel, $answerType,
  574. $session_id, $exerciseId);
  575. $data[] = $row;
  576. }
  577. Display :: display_sortable_table($header, $data, '', array('per_page_default'=>999,'per_page'=>999,'page_nr'=>1));
  578. if (!$nbrQuestions) {
  579. echo get_lang('NoQuestion');
  580. }
  581. // The (+) system as now make this button useless
  582. // Hubert Borderiou 27-10-2011
  583. //if (api_get_session_id() == 0){
  584. // echo '<div style="width:100%; border-top:1px dotted #4171B5;"><button class="save" type="submit">'.get_lang('Reuse').'</button></div></form>';
  585. //}
  586. Display::display_footer();
  587. // Some functions here, just for question_pool to ease the code
  588. /*
  589. Put the menu entry for level and type to default "Choice"
  590. It is usefull if you change the exercice, you need to reset the other menus
  591. hubert.borderiou 13-10-2011
  592. */
  593. function reset_menu_lvl_type() {
  594. global $exerciseLevel, $answerType;
  595. $answerType = -1;
  596. $exerciseLevel = -1;
  597. }
  598. /*
  599. Put the menu entry for exercice and level and type to default "Choice"
  600. It is usefull if you change the course, you need to reset the other menus
  601. hubert.borderiou 13-10-2011
  602. */
  603. function reset_menu_exo_lvl_type() {
  604. global $exerciseId, $courseCategoryId;
  605. reset_menu_lvl_type();
  606. $exerciseId = 0;
  607. $courseCategoryId = 0;
  608. }
  609. //
  610. // return the <a> link to admin question, if needed
  611. // hubert.borderiou 13-10-2011
  612. function get_a_tag_for_question($in_addA, $in_fromex, $in_questionid, $in_questiontype, $in_questionname) {
  613. $res = $in_questionname;
  614. if ($in_addA) {
  615. $res = "<a href='admin.php?".api_get_cidreq()."&editQuestion=$in_questionid&type=$in_questiontype&fromExercise=$in_fromex'>".$res."</a>";
  616. }
  617. return $res;
  618. }
  619. /*
  620. $row[] = get_action_icon_for_question(
  621. $actionIcon1, --
  622. $fromExercise, --
  623. $tabQuestion['id'], --
  624. $tabQuestion['type'],
  625. $tabQuestion['question'],
  626. $selected_course,
  627. $courseCategoryId,
  628. $exerciseLevel,
  629. $answerType,
  630. $session_id,
  631. $exerciseId).
  632. "&nbsp;".
  633. get_action_icon_for_question($actionIcon2, $fromExercise, $tabQuestion['id'], $tabQuestion['type'],
  634. $tabQuestion['question'], $selected_course, $courseCategoryId, $exerciseLevel, $answerType,
  635. $session_id, $exerciseId);
  636. */
  637. //
  638. // return the <a> html code for delete, add, clone, edit a question
  639. // hubert.borderiou 13-10-2011
  640. // in_action = the code of the action triggered by the button
  641. // from_exercice = the id of the current exercice from which we click on question pool
  642. // in_questionid = the id of the current question
  643. // in_questiontype = the code of the type of the current question
  644. // in_questionname = the name of the question
  645. // in_selected_course = the if of the course chosen in the FILTERING MENU
  646. // in_courseCategoryId = the id of the category chosen in the FILTERING MENU
  647. // in_exerciseLevel = the level of the exercice chosen in the FILTERING MENU
  648. // in_answerType = the code of the type of the question chosen in the FILTERING MENU
  649. // in_session_id = the id of the session_id chosen in the FILTERING MENU
  650. // in_exercice_id = the id of the exercice chosen in the FILTERING MENU
  651. function get_action_icon_for_question($in_action, $from_exercice, $in_questionid, $in_questiontype, $in_questionname,
  652. $in_selected_course, $in_courseCategoryId, $in_exerciseLevel, $in_answerType, $in_session_id, $in_exercice_id
  653. ) {
  654. $res = "";
  655. $getParams = "&selected_course=$in_selected_course&courseCategoryId=$in_courseCategoryId&exerciseId=$in_exercice_id&exerciseLevel=$in_exerciseLevel&answerType=$in_answerType&session_id=$in_session_id";
  656. switch ($in_action) {
  657. case "delete" :
  658. $res = "<a href='".api_get_self()."?".api_get_cidreq()."&delete=$in_questionid$getParams' onclick='return confirm_your_choice()'>";
  659. $res .= Display::return_icon("delete.gif", get_lang('Delete'));
  660. $res .= "</a>";
  661. break;
  662. case "edit" :
  663. $res = get_a_tag_for_question(1, $from_exercice, $in_questionid, $in_questiontype, Display::return_icon("edit.gif", get_lang('Modify')));
  664. break;
  665. case "add":
  666. // add if question is not already in test
  667. $myObjEx = new Exercise();
  668. $myObjEx->read($from_exercice);
  669. if (!$myObjEx->isInList($in_questionid)) {
  670. $res = "<a href='".api_get_self()."?".api_get_cidreq()."&recup=$in_questionid&fromExercise=$from_exercice$getParams'>";
  671. $res .= Display::return_icon("view_more_stats.gif", get_lang('InsertALinkToThisQuestionInTheExercise'));
  672. $res .= "</a>";
  673. }
  674. else {
  675. $res = "-";
  676. }
  677. unset($myObjEx);
  678. break;
  679. case "clone":
  680. $res = "<a href='".api_get_self()."?".api_get_cidreq()."&amp;copy_question=$in_questionid&course_id=$in_selected_course&fromExercise=$from_exercice$getParams'>";
  681. $res .= Display::return_icon('cd.gif', get_lang('ReUseACopyInCurrentTest'));
  682. $res .= "</a>";
  683. break;
  684. default :
  685. $res = $in_action;
  686. break;
  687. }
  688. return $res;
  689. }
  690. // return the icon for the question type
  691. // hubert.borderiou 13-10-2011
  692. function get_question_type_for_question($in_selectedcourse, $in_questionid) {
  693. $myObjQuestion = Question::read($in_questionid, $in_selectedcourse);
  694. $questionType = null;
  695. if (!empty($myObjQuestion)) {
  696. list($typeImg, $typeExpl) = $myObjQuestion->get_type_icon_html();
  697. $questionType = Display::tag('div', Display::return_icon($typeImg, $typeExpl, array(), 32), array());
  698. unset($myObjQuestion);
  699. }
  700. return $questionType;
  701. }
  702. // return the name of the category for the question in a course
  703. // hubert.borderiou 13-10-2011
  704. function get_question_categorie_for_question($in_courseid, $in_questionid) {
  705. $cat = Testcategory::getCategoryNameForQuestion($in_questionid, $in_courseid);
  706. return $cat;
  707. }