question_pool.php 30 KB

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