question_pool.php 30 KB

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