exercise_admin.php 7.2 KB

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