exercise_admin.php 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Exercise administration
  5. * This script allows to manage an exercise. It is included from
  6. * the script admin.php
  7. * @package chamilo.exercise
  8. * @author Olivier Brouckaert, Julio Montoya
  9. */
  10. use \ChamiloSession as Session;
  11. require_once '../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(Display::return_message(get_lang('ExerciseEdited')));
  133. } else {
  134. Display::addFlash(Display::return_message(get_lang('ExerciseAdded')));
  135. }
  136. $exercise_id = $objExercise->id;
  137. Session::erase('objExercise');
  138. header('Location:admin.php?exerciseId='.$exercise_id.'&'.api_get_cidreq());
  139. exit;
  140. } else {
  141. // DISPLAY FORM
  142. if (isset($_SESSION['gradebook'])) {
  143. $gradebook = $_SESSION['gradebook'];
  144. }
  145. if (!empty($gradebook) && $gradebook=='view') {
  146. $interbreadcrumb[]= array (
  147. 'url' => '../gradebook/'.$_SESSION['gradebook_dest'],
  148. 'name' => get_lang('ToolGradebook')
  149. );
  150. }
  151. $nameTools = get_lang('ExerciseManagement');
  152. $interbreadcrumb[] = array(
  153. "url" => 'exercise.php?'.api_get_cidreq(),
  154. 'name' => get_lang('Exercises'),
  155. );
  156. $interbreadcrumb[] = array(
  157. "url" => 'admin.php?exerciseId='.$objExercise->id.'&'.api_get_cidreq(),
  158. "name" => $objExercise->name,
  159. );
  160. Display::display_header($nameTools, get_lang('Exercise'));
  161. echo '<div class="actions">';
  162. if ($objExercise->id != 0) {
  163. echo '<a href="admin.php?'.api_get_cidreq().'&exerciseId='.$objExercise->id.'">' .
  164. Display :: return_icon('back.png', get_lang('GoBackToQuestionList'), '', ICON_SIZE_MEDIUM).'</a>';
  165. } else {
  166. if (!empty($_GET['lp_id']) || !empty($_POST['lp_id'])){
  167. if (!empty($_POST['lp_id'])){
  168. $lp_id = intval($_POST['lp_id']);
  169. //TODO:this remains to be implemented after press the first post
  170. } else {
  171. $lp_id = intval($_GET['lp_id']);
  172. }
  173. echo "<a href=\"../newscorm/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>";
  174. } else {
  175. echo '<a href="exercise.php?'.api_get_cidreq().'">' .
  176. Display :: return_icon('back.png', get_lang('BackToExercisesList'), '', ICON_SIZE_MEDIUM).
  177. '</a>';
  178. }
  179. }
  180. echo '</div>';
  181. if ($objExercise->feedback_type == 1)
  182. Display::display_normal_message(
  183. get_lang('DirectFeedbackCantModifyTypeQuestion')
  184. );
  185. if (api_get_setting('search_enabled')=='true' && !extension_loaded('xapian')) {
  186. Display::display_error_message(get_lang('SearchXapianModuleNotInstalled'));
  187. }
  188. // to hide the exercise description
  189. echo '<style> .media { display:none;}</style>';
  190. $form->display();
  191. }
  192. Display::display_footer();