question_pool.php 30 KB

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