exercise_admin.php 12 KB

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