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