exercise_admin.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301
  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. /**
  11. * Code
  12. */
  13. use \ChamiloSession as Session;
  14. require_once 'exercise.class.php';
  15. require_once 'question.class.php';
  16. require_once 'answer.class.php';
  17. ////require_once '../inc/global.inc.php';
  18. $this_section = SECTION_COURSES;
  19. if (!api_is_allowed_to_edit(null,true)) {
  20. api_not_allowed(true);
  21. }
  22. $url = api_get_path(WEB_AJAX_PATH).'exercise.ajax.php?1=1';
  23. $htmlHeadXtra[] = '<script>
  24. function check() {
  25. $("#category_id option:selected").each(function() {
  26. var id = $(this).val();
  27. var name = $(this).text();
  28. if (id != "" ) {
  29. $.ajax({
  30. async: false,
  31. url: "'.$url.'&a=exercise_category_exists",
  32. data: "id="+id,
  33. success: function(return_value) {
  34. if (return_value == 0 ) {
  35. alert("'.get_lang('CategoryDoesNotExists').'");
  36. // Deleting select option tag
  37. $("#category_id").find("option").remove();
  38. $(".holder li").each(function () {
  39. if ($(this).attr("rel") == id) {
  40. $(this).remove();
  41. }
  42. });
  43. } else {
  44. option_text = $("#category_id").find("option").text();
  45. $("#category_inputs").append( option_text + "<input type=text>");
  46. }
  47. },
  48. });
  49. }
  50. });
  51. }
  52. $(function() {
  53. $("#category_id").fcbkcomplete({
  54. json_url: "'.$url.'&a=search_category",
  55. maxitems: 20,
  56. addontab: false,
  57. input_min_size: 1,
  58. cache: false,
  59. complete_text: "'.get_lang('StartToType').'",
  60. firstselected: false,
  61. onselect: check,
  62. // oncreate: add_item,
  63. filter_selected: true,
  64. newel: true
  65. });
  66. $("input[name=\'model_type\']").each(function(index, value) {
  67. $(this).click(function() {
  68. var value = $(this).attr("value");
  69. // Committee‎
  70. if (value == 2) {
  71. $("#score_type").show();
  72. } else {
  73. $("#score_type").hide();
  74. }
  75. });
  76. });
  77. });
  78. function FCKeditor_OnComplete( editorInstance ) {
  79. if (document.getElementById ( \'HiddenFCK\' + editorInstance.Name )) {
  80. HideFCKEditorByInstanceName (editorInstance.Name);
  81. }
  82. }
  83. function HideFCKEditorByInstanceName ( editorInstanceName ) {
  84. if (document.getElementById ( \'HiddenFCK\' + editorInstanceName ).className == "HideFCKEditor" ) {
  85. document.getElementById ( \'HiddenFCK\' + editorInstanceName ).className = "media";
  86. }
  87. }
  88. function show_media() {
  89. var my_display = document.getElementById(\'HiddenFCKexerciseDescription\').style.display;
  90. if(my_display== \'none\' || my_display == \'\') {
  91. document.getElementById(\'HiddenFCKexerciseDescription\').style.display = \'block\';
  92. document.getElementById(\'media_icon\').innerHTML=\' '.Display::return_icon('media-question.png').' '.addslashes(get_lang('ExerciseDescription')).'\';
  93. } else {
  94. document.getElementById(\'HiddenFCKexerciseDescription\').style.display = \'none\';
  95. document.getElementById(\'media_icon\').innerHTML=\' '.Display::return_icon('media-question.png').' '.addslashes(get_lang('ExerciseDescription')).'\';
  96. }
  97. }
  98. function activate_start_date() {
  99. if(document.getElementById(\'start_date_div\').style.display == \'none\') {
  100. document.getElementById(\'start_date_div\').style.display = \'block\';
  101. } else {
  102. document.getElementById(\'start_date_div\').style.display = \'none\';
  103. }
  104. }
  105. function activate_end_date() {
  106. if(document.getElementById(\'end_date_div\').style.display == \'none\') {
  107. document.getElementById(\'end_date_div\').style.display = \'block\';
  108. } else {
  109. document.getElementById(\'end_date_div\').style.display = \'none\';
  110. }
  111. }
  112. function feedbackselection() {
  113. var index = document.exercise_admin.exerciseFeedbackType.selectedIndex;
  114. if (index == \'1\') {
  115. document.exercise_admin.exerciseType[1].checked=true;
  116. document.exercise_admin.exerciseType[0].disabled=true;
  117. } else {
  118. document.exercise_admin.exerciseType[0].disabled=false;
  119. }
  120. }
  121. function option_time_expired() {
  122. if(document.getElementById(\'timercontrol\').style.display == \'none\')
  123. {
  124. document.getElementById(\'timercontrol\').style.display = \'block\';
  125. } else {
  126. document.getElementById(\'timercontrol\').style.display = \'none\';
  127. }
  128. }
  129. function check_per_page_one() {
  130. /*if (document.getElementById(\'divtimecontrol\').style.display==\'none\') {
  131. document.getElementById(\'divtimecontrol\').style.display=\'block\';
  132. document.getElementById(\'divtimecontrol\').display=block;
  133. document.getElementById(\'timecontrol\').display=none;
  134. }*/
  135. document.getElementById(\'exerciseType_0\').checked=true;
  136. }
  137. function check_per_page_all() {
  138. /*if (document.getElementById(\'divtimecontrol\').style.display==\'block\') {
  139. document.getElementById(\'divtimecontrol\').style.display=\'none\';
  140. document.getElementById(\'enabletimercontroltotalminutes\').value=\'\';
  141. }*/
  142. if (document.getElementById(\'exerciseType_1\') && document.getElementById(\'exerciseType_1\').checked) {
  143. document.getElementById(\'exerciseType_0\').checked = true;
  144. }
  145. }
  146. function check_feedback() {
  147. document.getElementById(\'result_disabled_0\').checked = true;
  148. }
  149. function check_direct_feedback() {
  150. document.getElementById(\'option_page_one\').checked = true;
  151. document.getElementById(\'result_disabled_0\').checked = true;
  152. }
  153. function check_results_disabled() {
  154. document.getElementById(\'exerciseType_2\').checked = true;
  155. }
  156. function disabledHideRandom() {
  157. $("#hidden_random option:eq(0)").prop("selected", true);
  158. $("#hidden_random").hide();
  159. }
  160. function checkQuestionSelection() {
  161. var selection = $("#questionSelection option:selected").val()
  162. switch (selection) {
  163. case "'.EX_Q_SELECTION_ORDERED.'":
  164. disabledHideRandom();
  165. $("#hidden_matrix").hide();
  166. break;
  167. case "'.EX_Q_SELECTION_RANDOM.'":
  168. $("#hidden_random").show();
  169. $("#hidden_matrix").hide();
  170. break;
  171. case "'.EX_Q_SELECTION_CATEGORIES_ORDERED_QUESTIONS_ORDERED.'":
  172. disabledHideRandom();
  173. $("#hidden_matrix").show();
  174. break;
  175. case "per_categories":
  176. $("#questionSelection option:eq('.EX_Q_SELECTION_CATEGORIES_ORDERED_QUESTIONS_ORDERED.')").prop("selected", true);
  177. disabledHideRandom();
  178. $("#hidden_matrix").show();
  179. break;
  180. default:
  181. disabledHideRandom();
  182. $("#hidden_matrix").show();
  183. break;
  184. }
  185. }
  186. </script>';
  187. // to correct #4029 Random and number of attempt menu empty added window.onload=advanced_parameters;
  188. $htmlHeadXtra[] = '<script>
  189. function setFocus(){
  190. $("#exercise_title").focus();
  191. }
  192. $(document).ready(function () {
  193. setFocus();
  194. });
  195. </script>';
  196. // INIT EXERCISE
  197. $objExercise = new Exercise();
  198. $objExercise->setCategoriesGrouping(false);
  199. $course_id = api_get_course_int_id();
  200. //INIT FORM
  201. if (isset($_GET['exerciseId'])) {
  202. $form = new FormValidator('exercise_admin', 'post', api_get_self().'?'.api_get_cidreq().'&exerciseId='.intval($_GET['exerciseId']));
  203. $objExercise->read($_GET['exerciseId']);
  204. $form->addElement('hidden','edit','true');
  205. } else {
  206. $form = new FormValidator('exercise_admin','post',api_get_self().'?'.api_get_cidreq());
  207. $form->addElement('hidden','edit','false');
  208. }
  209. $objExercise->createForm($form);
  210. // VALIDATE FORM
  211. if ($form->validate()) {
  212. $objExercise->processCreation($form);
  213. if ($form->getSubmitValue('edit') == 'true') {
  214. $message = 'ExerciseEdited';
  215. } else {
  216. $message = 'ExerciseAdded';
  217. }
  218. $exercise_id = $objExercise->id;
  219. Session::erase('objExercise');
  220. header('Location:admin.php?message='.$message.'&exerciseId='.$exercise_id.'&'.api_get_cidreq());
  221. exit;
  222. } else {
  223. // DISPLAY FORM
  224. if (isset($_SESSION['gradebook'])) {
  225. $gradebook= $_SESSION['gradebook'];
  226. }
  227. if (!empty($gradebook) && $gradebook=='view') {
  228. $interbreadcrumb[]= array ('url' => '../gradebook/'.$_SESSION['gradebook_dest'],'name' => get_lang('ToolGradebook'));
  229. }
  230. $nameTools = get_lang('ExerciseManagement');
  231. $interbreadcrumb[] = array("url"=>'exercice.php', 'name'=> get_lang('Exercices'));
  232. $interbreadcrumb[] = array("url"=>"admin.php?exerciseId=".$objExercise->id, "name" => $objExercise->name);
  233. Display::display_header($nameTools,get_lang('Exercise'));
  234. echo '<div class="actions">';
  235. if ($objExercise->id != 0) {
  236. echo '<a href="admin.php?'.api_get_cidReq().'&exerciseId='.$objExercise->id.'">' . Display :: return_icon('back.png', get_lang('GoBackToQuestionList'),'',ICON_SIZE_MEDIUM).'</a>';
  237. } else {
  238. if (!empty($_GET['lp_id']) || !empty($_POST['lp_id'])){
  239. if (!empty($_POST['lp_id'])){
  240. $lp_id = Security::remove_XSS($_POST['lp_id']);//TODO:this remains to be implemented after press the first post
  241. } else {
  242. $lp_id = Security::remove_XSS($_GET['lp_id']);
  243. }
  244. 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>";
  245. } else {
  246. echo '<a href="exercice.php">' . Display :: return_icon('back.png', get_lang('BackToExercisesList'),'',ICON_SIZE_MEDIUM).'</a>';
  247. }
  248. }
  249. echo '</div>';
  250. if ($objExercise->feedback_type == 1) {
  251. Display::display_normal_message(get_lang('DirectFeedbackCantModifyTypeQuestion'));
  252. }
  253. if (api_get_setting('search_enabled')=='true' && !extension_loaded('xapian')) {
  254. Display::display_error_message(get_lang('SearchXapianModuleNotInstalled'));
  255. }
  256. if ($objExercise->id != 0 && $objExercise->edit_exercise_in_lp == false) {
  257. $form->freeze();
  258. }
  259. $form->display();
  260. }
  261. Display::display_footer();