exercise_admin.php 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  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. // name of the language file that needs to be included
  11. use \ChamiloSession as Session;
  12. require_once '../inc/global.inc.php';
  13. $this_section = SECTION_COURSES;
  14. if (!api_is_allowed_to_edit(null,true)) {
  15. api_not_allowed(true);
  16. }
  17. $htmlHeadXtra[] = '<script>
  18. function activate_start_date() {
  19. if(document.getElementById(\'start_date_div\').style.display == \'none\') {
  20. document.getElementById(\'start_date_div\').style.display = \'block\';
  21. } else {
  22. document.getElementById(\'start_date_div\').style.display = \'none\';
  23. }
  24. }
  25. function activate_end_date() {
  26. if(document.getElementById(\'end_date_div\').style.display == \'none\') {
  27. document.getElementById(\'end_date_div\').style.display = \'block\';
  28. } else {
  29. document.getElementById(\'end_date_div\').style.display = \'none\';
  30. }
  31. }
  32. function feedbackselection() {
  33. var index = document.exercise_admin.exerciseFeedbackType.selectedIndex;
  34. if (index == \'1\') {
  35. document.exercise_admin.exerciseType[1].checked=true;
  36. document.exercise_admin.exerciseType[0].disabled=true;
  37. } else {
  38. document.exercise_admin.exerciseType[0].disabled=false;
  39. }
  40. }
  41. function option_time_expired() {
  42. if(document.getElementById(\'timercontrol\').style.display == \'none\')
  43. {
  44. document.getElementById(\'timercontrol\').style.display = \'block\';
  45. } else {
  46. document.getElementById(\'timercontrol\').style.display = \'none\';
  47. }
  48. }
  49. function check_per_page_one() {
  50. document.getElementById(\'exerciseType_0\').checked=true;
  51. }
  52. function check_per_page_all() {
  53. if (document.getElementById(\'exerciseType_1\') && document.getElementById(\'exerciseType_1\').checked) {
  54. document.getElementById(\'exerciseType_0\').checked = true;
  55. }
  56. }
  57. function check_feedback() {
  58. if (document.getElementById(\'result_disabled_1\').checked == true) {
  59. document.getElementById(\'result_disabled_0\').checked = true;
  60. }
  61. }
  62. function check_direct_feedback() {
  63. document.getElementById(\'option_page_one\').checked = true;
  64. document.getElementById(\'result_disabled_0\').checked = true;
  65. }
  66. function check_results_disabled() {
  67. document.getElementById(\'exerciseType_2\').checked = true;
  68. }
  69. </script>';
  70. // to correct #4029 Random and number of attempt menu empty added window.onload=advanced_parameters;
  71. $htmlHeadXtra[] = '<script>
  72. function setFocus(){
  73. $("#exercise_title").focus();
  74. }
  75. $(document).ready(function () {
  76. setFocus();
  77. });
  78. </script>';
  79. $objExercise = new Exercise();
  80. $course_id = api_get_course_int_id();
  81. //INIT FORM
  82. if (isset($_GET['exerciseId'])) {
  83. $form = new FormValidator('exercise_admin', 'post', api_get_self().'?'.api_get_cidreq().'&exerciseId='.intval($_GET['exerciseId']));
  84. $objExercise->read($_GET['exerciseId']);
  85. $form->addElement('hidden','edit','true');
  86. } else {
  87. $form = new FormValidator('exercise_admin','post',api_get_self().'?'.api_get_cidreq());
  88. $form->addElement('hidden','edit','false');
  89. }
  90. $objExercise->createForm($form);
  91. // VALIDATE FORM
  92. if ($form->validate()) {
  93. $objExercise->processCreation($form);
  94. if ($form->getSubmitValue('edit') == 'true') {
  95. Display::addFlash(Display::return_message(get_lang('ExerciseEdited')));
  96. } else {
  97. Display::addFlash(Display::return_message(get_lang('ExerciseAdded')));
  98. }
  99. $exercise_id = $objExercise->id;
  100. Session::erase('objExercise');
  101. header('Location:admin.php?&exerciseId='.$exercise_id.'&'.api_get_cidreq());
  102. exit;
  103. } else {
  104. // DISPLAY FORM
  105. if (isset($_SESSION['gradebook'])) {
  106. $gradebook = $_SESSION['gradebook'];
  107. }
  108. if (!empty($gradebook) && $gradebook=='view') {
  109. $interbreadcrumb[]= array ('url' => '../gradebook/'.$_SESSION['gradebook_dest'],'name' => get_lang('ToolGradebook'));
  110. }
  111. $nameTools = get_lang('ExerciseManagement');
  112. $interbreadcrumb[] = array("url"=>'exercise.php', 'name'=> get_lang('Exercises'));
  113. $interbreadcrumb[] = array("url"=>"admin.php?exerciseId=".$objExercise->id, "name" => $objExercise->name);
  114. Display::display_header($nameTools, get_lang('Exercise'));
  115. echo '<div class="actions">';
  116. if ($objExercise->id != 0) {
  117. echo '<a href="admin.php?'.api_get_cidReq().'&exerciseId='.$objExercise->id.'">' .
  118. Display :: return_icon('back.png', get_lang('GoBackToQuestionList'), '', ICON_SIZE_MEDIUM).'</a>';
  119. } else {
  120. if (!empty($_GET['lp_id']) || !empty($_POST['lp_id'])){
  121. if (!empty($_POST['lp_id'])){
  122. $lp_id = intval($_POST['lp_id']);//TODO:this remains to be implemented after press the first post
  123. } else {
  124. $lp_id = intval($_GET['lp_id']);
  125. }
  126. 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>";
  127. } else {
  128. echo '<a href="exercise.php">' .
  129. Display :: return_icon('back.png', get_lang('BackToExercisesList'),'',ICON_SIZE_MEDIUM).
  130. '</a>';
  131. }
  132. }
  133. echo '</div>';
  134. if ($objExercise->feedback_type==1)
  135. Display::display_normal_message(get_lang('DirectFeedbackCantModifyTypeQuestion'));
  136. if (api_get_setting('search_enabled')=='true' && !extension_loaded('xapian')) {
  137. Display::display_error_message(get_lang('SearchXapianModuleNotInstalled'));
  138. }
  139. // to hide the exercise description
  140. echo '<style> .media { display:none;}</style>';
  141. $form->display();
  142. }
  143. Display::display_footer();