exercise_admin.php 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. use ChamiloSession as Session;
  4. /**
  5. * Exercise administration
  6. * This script allows to manage an exercise. It is included from
  7. * the script admin.php
  8. * @package chamilo.exercise
  9. * @author Olivier Brouckaert, Julio Montoya
  10. */
  11. require_once __DIR__.'/../inc/global.inc.php';
  12. $this_section = SECTION_COURSES;
  13. if (!api_is_allowed_to_edit(null, true)) {
  14. api_not_allowed(true);
  15. }
  16. $htmlHeadXtra[] = '<script>
  17. function activate_start_date() {
  18. if(document.getElementById(\'start_date_div\').style.display == \'none\') {
  19. document.getElementById(\'start_date_div\').style.display = \'block\';
  20. } else {
  21. document.getElementById(\'start_date_div\').style.display = \'none\';
  22. }
  23. }
  24. function activate_end_date() {
  25. if(document.getElementById(\'end_date_div\').style.display == \'none\') {
  26. document.getElementById(\'end_date_div\').style.display = \'block\';
  27. } else {
  28. document.getElementById(\'end_date_div\').style.display = \'none\';
  29. }
  30. }
  31. function feedbackselection() {
  32. var index = document.exercise_admin.exerciseFeedbackType.selectedIndex;
  33. if (index == \'1\') {
  34. document.exercise_admin.exerciseType[1].checked=true;
  35. document.exercise_admin.exerciseType[0].disabled=true;
  36. } else {
  37. document.exercise_admin.exerciseType[0].disabled=false;
  38. }
  39. }
  40. function option_time_expired() {
  41. if(document.getElementById(\'timercontrol\').style.display == \'none\')
  42. {
  43. document.getElementById(\'timercontrol\').style.display = \'block\';
  44. } else {
  45. document.getElementById(\'timercontrol\').style.display = \'none\';
  46. }
  47. }
  48. function check_per_page_one() {
  49. document.getElementById(\'exerciseType_0\').checked=true;
  50. }
  51. function check_per_page_all() {
  52. if (document.getElementById(\'exerciseType_1\') && document.getElementById(\'exerciseType_1\').checked) {
  53. document.getElementById(\'exerciseType_0\').checked = true;
  54. }
  55. }
  56. function check_feedback() {
  57. if (document.getElementById(\'result_disabled_1\').checked == true) {
  58. document.getElementById(\'result_disabled_0\').checked = true;
  59. }
  60. }
  61. function check_direct_feedback() {
  62. document.getElementById(\'option_page_one\').checked = true;
  63. document.getElementById(\'result_disabled_0\').checked = true;
  64. }
  65. function check_results_disabled() {
  66. document.getElementById(\'exerciseType_2\').checked = true;
  67. }
  68. function disabledHideRandom() {
  69. $("#hidden_random option:eq(0)").prop("selected", true);
  70. $("#hidden_random").hide();
  71. }
  72. function checkQuestionSelection() {
  73. var selection = $("#questionSelection option:selected").val();
  74. switch (selection) {
  75. case "'.EX_Q_SELECTION_ORDERED.'":
  76. disabledHideRandom();
  77. $("#hidden_matrix").hide();
  78. break;
  79. case "'.EX_Q_SELECTION_RANDOM.'":
  80. $("#hidden_random").show();
  81. $("#hidden_matrix").hide();
  82. break;
  83. case "'.EX_Q_SELECTION_CATEGORIES_ORDERED_QUESTIONS_ORDERED.'":
  84. disabledHideRandom();
  85. $("#hidden_matrix").show();
  86. break;
  87. case "per_categories":
  88. $("#questionSelection option:eq('.EX_Q_SELECTION_CATEGORIES_ORDERED_QUESTIONS_ORDERED.')").prop("selected", true);
  89. disabledHideRandom();
  90. $("#hidden_matrix").show();
  91. break;
  92. default:
  93. disabledHideRandom();
  94. $("#hidden_matrix").show();
  95. break;
  96. }
  97. }
  98. </script>';
  99. // to correct #4029 Random and number of attempt menu empty added window.onload=advanced_parameters;
  100. $htmlHeadXtra[] = '<script>
  101. function setFocus(){
  102. $("#exercise_title").focus();
  103. }
  104. $(document).ready(function () {
  105. setFocus();
  106. });
  107. </script>';
  108. $objExercise = new Exercise();
  109. $course_id = api_get_course_int_id();
  110. //INIT FORM
  111. if (isset($_GET['exerciseId'])) {
  112. $form = new FormValidator(
  113. 'exercise_admin',
  114. 'post',
  115. api_get_self().'?'.api_get_cidreq().'&exerciseId='.intval($_GET['exerciseId'])
  116. );
  117. $objExercise->read($_GET['exerciseId']);
  118. $form->addElement('hidden', 'edit', 'true');
  119. } else {
  120. $form = new FormValidator(
  121. 'exercise_admin',
  122. 'post',
  123. api_get_self().'?'.api_get_cidreq()
  124. );
  125. $form->addElement('hidden', 'edit', 'false');
  126. }
  127. $objExercise->createForm($form);
  128. // VALIDATE FORM
  129. if ($form->validate()) {
  130. $objExercise->processCreation($form);
  131. if ($form->getSubmitValue('edit') == 'true') {
  132. Display::addFlash(
  133. Display::return_message(get_lang('ExerciseEdited'), 'success')
  134. );
  135. } else {
  136. Display::addFlash(
  137. Display::return_message(get_lang('ExerciseAdded'), 'success')
  138. );
  139. }
  140. $exercise_id = $objExercise->id;
  141. Session::erase('objExercise');
  142. header('Location:admin.php?exerciseId='.$exercise_id.'&'.api_get_cidreq());
  143. exit;
  144. } else {
  145. // DISPLAY FORM
  146. if (isset($_SESSION['gradebook'])) {
  147. $gradebook = $_SESSION['gradebook'];
  148. }
  149. if (!empty($gradebook) && $gradebook == 'view') {
  150. $interbreadcrumb[] = array(
  151. 'url' => '../gradebook/'.$_SESSION['gradebook_dest'],
  152. 'name' => get_lang('ToolGradebook')
  153. );
  154. }
  155. $nameTools = get_lang('ExerciseManagement');
  156. $interbreadcrumb[] = array(
  157. "url" => 'exercise.php?'.api_get_cidreq(),
  158. 'name' => get_lang('Exercises'),
  159. );
  160. $interbreadcrumb[] = array(
  161. "url" => 'admin.php?exerciseId='.$objExercise->id.'&'.api_get_cidreq(),
  162. "name" => $objExercise->selectTitle(true),
  163. );
  164. Display::display_header($nameTools, get_lang('Exercise'));
  165. echo '<div class="actions">';
  166. if ($objExercise->id != 0) {
  167. echo '<a href="admin.php?'.api_get_cidreq().'&exerciseId='.$objExercise->id.'">'.
  168. Display::return_icon('back.png', get_lang('GoBackToQuestionList'), '', ICON_SIZE_MEDIUM).'</a>';
  169. } else {
  170. if (!empty($_GET['lp_id']) || !empty($_POST['lp_id'])) {
  171. if (!empty($_POST['lp_id'])) {
  172. $lp_id = intval($_POST['lp_id']);
  173. //TODO:this remains to be implemented after press the first post
  174. } else {
  175. $lp_id = intval($_GET['lp_id']);
  176. }
  177. echo "<a href=\"../lp/lp_controller.php?".api_get_cidreq()."&gradebook=&action=add_item&type=step&lp_id=".$lp_id."#resource_tab-2\">".Display::return_icon('back.png', get_lang("BackTo").' '.get_lang("LearningPaths"), '', ICON_SIZE_MEDIUM)."</a>";
  178. } else {
  179. echo '<a href="exercise.php?'.api_get_cidreq().'">'.
  180. Display::return_icon('back.png', get_lang('BackToExercisesList'), '', ICON_SIZE_MEDIUM).
  181. '</a>';
  182. }
  183. }
  184. echo '</div>';
  185. if ($objExercise->feedback_type == 1) {
  186. echo Display::return_message(get_lang('DirectFeedbackCantModifyTypeQuestion'));
  187. }
  188. if (api_get_setting('search_enabled') == 'true' &&
  189. !extension_loaded('xapian')
  190. ) {
  191. echo Display::return_message(get_lang('SearchXapianModuleNotInstalled'), 'error');
  192. }
  193. // to hide the exercise description
  194. echo '<style> .media { display:none;}</style>';
  195. $form->display();
  196. }
  197. Display::display_footer();