exercise_admin.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305
  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. $language_file = 'exercice';
  12. require_once 'exercise.class.php';
  13. require_once 'question.class.php';
  14. require_once 'answer.class.php';
  15. require_once '../inc/global.inc.php';
  16. require_once 'exercise.lib.php';
  17. $this_section = SECTION_COURSES;
  18. if (!api_is_allowed_to_edit(null,true)) {
  19. api_not_allowed(true);
  20. }
  21. $htmlHeadXtra[] = '<script src="'.api_get_path(WEB_LIBRARY_PATH).'javascript/tag/jquery.fcbkcomplete.js" type="text/javascript" language="javascript"></script>';
  22. $htmlHeadXtra[] = '<link href="'.api_get_path(WEB_LIBRARY_PATH).'javascript/tag/style.css" rel="stylesheet" type="text/css" />';
  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 advanced_parameters() {
  79. if(document.getElementById(\'options\').style.display == \'none\') {
  80. document.getElementById(\'options\').style.display = \'block\';
  81. document.getElementById(\'img_plus_and_minus\').innerHTML=\' <img style="vertical-align:middle;" src="../img/div_hide.gif" alt="" /> '.addslashes(api_htmlentities(get_lang('AdvancedParameters'))).'\';
  82. } else {
  83. document.getElementById(\'options\').style.display = \'none\';
  84. document.getElementById(\'img_plus_and_minus\').innerHTML=\' <img style="vertical-align:middle;" src="../img/div_show.gif" alt="" /> '.addslashes(api_htmlentities(get_lang('AdvancedParameters'))).'\';
  85. }
  86. }
  87. function FCKeditor_OnComplete( editorInstance ) {
  88. if (document.getElementById ( \'HiddenFCK\' + editorInstance.Name )) {
  89. HideFCKEditorByInstanceName (editorInstance.Name);
  90. }
  91. }
  92. function HideFCKEditorByInstanceName ( editorInstanceName ) {
  93. if (document.getElementById ( \'HiddenFCK\' + editorInstanceName ).className == "HideFCKEditor" ) {
  94. document.getElementById ( \'HiddenFCK\' + editorInstanceName ).className = "media";
  95. }
  96. }
  97. function show_media() {
  98. var my_display = document.getElementById(\'HiddenFCKexerciseDescription\').style.display;
  99. if(my_display== \'none\' || my_display == \'\') {
  100. document.getElementById(\'HiddenFCKexerciseDescription\').style.display = \'block\';
  101. document.getElementById(\'media_icon\').innerHTML=\' <img src="../img/looknfeelna.png" alt="" /> '.addslashes(api_htmlentities(get_lang('ExerciseDescription'))).'\';
  102. } else {
  103. document.getElementById(\'HiddenFCKexerciseDescription\').style.display = \'none\';
  104. document.getElementById(\'media_icon\').innerHTML=\' <img src="../img/looknfeel.png" alt="" /> '.addslashes(api_htmlentities(get_lang('ExerciseDescription'))).'\';
  105. }
  106. }
  107. function activate_start_date() {
  108. if(document.getElementById(\'start_date_div\').style.display == \'none\') {
  109. document.getElementById(\'start_date_div\').style.display = \'block\';
  110. } else {
  111. document.getElementById(\'start_date_div\').style.display = \'none\';
  112. }
  113. }
  114. function activate_end_date() {
  115. if(document.getElementById(\'end_date_div\').style.display == \'none\') {
  116. document.getElementById(\'end_date_div\').style.display = \'block\';
  117. } else {
  118. document.getElementById(\'end_date_div\').style.display = \'none\';
  119. }
  120. }
  121. function feedbackselection() {
  122. var index = document.exercise_admin.exerciseFeedbackType.selectedIndex;
  123. if (index == \'1\') {
  124. document.exercise_admin.exerciseType[1].checked=true;
  125. document.exercise_admin.exerciseType[0].disabled=true;
  126. } else {
  127. document.exercise_admin.exerciseType[0].disabled=false;
  128. }
  129. }
  130. function option_time_expired() {
  131. if(document.getElementById(\'timercontrol\').style.display == \'none\')
  132. {
  133. document.getElementById(\'timercontrol\').style.display = \'block\';
  134. } else {
  135. document.getElementById(\'timercontrol\').style.display = \'none\';
  136. }
  137. }
  138. function check_per_page_one() {
  139. document.getElementById(\'exerciseType_0\').checked=true;
  140. }
  141. function check_per_page_all() {
  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. if (document.getElementById(\'result_disabled_1\').checked == true) {
  148. document.getElementById(\'result_disabled_0\').checked = true;
  149. }
  150. }
  151. function check_direct_feedback() {
  152. document.getElementById(\'option_page_one\').checked = true;
  153. document.getElementById(\'result_disabled_0\').checked = true;
  154. }
  155. function check_results_disabled() {
  156. document.getElementById(\'exerciseType_2\').checked = true;
  157. }
  158. function disabledHideRandom() {
  159. $("#hidden_random option:eq(0)").prop("selected", true);
  160. $("#hidden_random").hide();
  161. }
  162. function checkQuestionSelection() {
  163. var selection = $("#questionSelection option:selected").val()
  164. switch (selection) {
  165. case "\'.EX_Q_SELECTION_ORDERED.\'":
  166. disabledHideRandom();
  167. $("#hidden_matrix").hide();
  168. break;
  169. case "\'.EX_Q_SELECTION_RANDOM.\'":
  170. $("#hidden_random").show();
  171. $("#hidden_matrix").hide();
  172. break;
  173. case "\'.EX_Q_SELECTION_CATEGORIES_ORDERED_QUESTIONS_ORDERED.\'":
  174. disabledHideRandom();
  175. $("#hidden_matrix").show();
  176. break;
  177. case "per_categories":
  178. $("#questionSelection option:eq(\'.EX_Q_SELECTION_CATEGORIES_ORDERED_QUESTIONS_ORDERED.\')").prop("selected", true);
  179. disabledHideRandom();
  180. $("#hidden_matrix").show();
  181. break;
  182. default:
  183. disabledHideRandom();
  184. $("#hidden_matrix").show();
  185. break;
  186. }
  187. }
  188. </script>';
  189. // to correct #4029 Random and number of attempt menu empty added window.onload=advanced_parameters;
  190. $htmlHeadXtra[] = '<script>
  191. function setFocus(){
  192. $("#exercise_title").focus();
  193. }
  194. $(document).ready(function () {
  195. setFocus();
  196. });
  197. window.onload=advanced_parameters;
  198. </script>';
  199. // INIT EXERCISE
  200. $objExercise = new Exercise();
  201. $objExercise->setCategoriesGrouping(false);
  202. $course_id = api_get_course_int_id();
  203. //INIT FORM
  204. if (isset($_GET['exerciseId'])) {
  205. $form = new FormValidator('exercise_admin', 'post', api_get_self().'?'.api_get_cidreq().'&exerciseId='.intval($_GET['exerciseId']));
  206. $objExercise->read($_GET['exerciseId']);
  207. $form->addElement('hidden','edit','true');
  208. } else {
  209. $form = new FormValidator('exercise_admin','post',api_get_self().'?'.api_get_cidreq());
  210. $form->addElement('hidden','edit','false');
  211. }
  212. $objExercise->createForm($form);
  213. // VALIDATE FORM
  214. if ($form->validate()) {
  215. $objExercise->processCreation($form);
  216. if ($form->getSubmitValue('edit') == 'true') {
  217. $message = 'ExerciseEdited';
  218. } else {
  219. $message = 'ExerciseAdded';
  220. }
  221. $exercise_id = $objExercise->id;
  222. Session::erase('objExercise');
  223. header('Location:admin.php?message='.$message.'&exerciseId='.$exercise_id.'&'.api_get_cidreq());
  224. exit;
  225. } else {
  226. // DISPLAY FORM
  227. if (isset($_SESSION['gradebook'])) {
  228. $gradebook= $_SESSION['gradebook'];
  229. }
  230. if (!empty($gradebook) && $gradebook=='view') {
  231. $interbreadcrumb[]= array ('url' => '../gradebook/'.$_SESSION['gradebook_dest'],'name' => get_lang('ToolGradebook'));
  232. }
  233. $nameTools = get_lang('ExerciseManagement');
  234. $interbreadcrumb[] = array("url"=>'exercice.php', 'name'=> get_lang('Exercices'));
  235. $interbreadcrumb[] = array("url"=>"admin.php?exerciseId=".$objExercise->id, "name" => $objExercise->name);
  236. Display::display_header($nameTools,get_lang('Exercise'));
  237. echo '<div class="actions">';
  238. if ($objExercise->id != 0) {
  239. echo '<a href="admin.php?'.api_get_cidReq().'&exerciseId='.$objExercise->id.'">' . Display :: return_icon('back.png', get_lang('GoBackToQuestionList'),'',ICON_SIZE_MEDIUM).'</a>';
  240. } else {
  241. if (!empty($_GET['lp_id']) || !empty($_POST['lp_id'])){
  242. if (!empty($_POST['lp_id'])){
  243. $lp_id = Security::remove_XSS($_POST['lp_id']);//TODO:this remains to be implemented after press the first post
  244. } else {
  245. $lp_id = Security::remove_XSS($_GET['lp_id']);
  246. }
  247. 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>";
  248. } else {
  249. echo '<a href="exercice.php">' . Display :: return_icon('back.png', get_lang('BackToExercisesList'),'',ICON_SIZE_MEDIUM).'</a>';
  250. }
  251. }
  252. echo '</div>';
  253. if ($objExercise->feedback_type==1)
  254. Display::display_normal_message(get_lang('DirectFeedbackCantModifyTypeQuestion'));
  255. if (api_get_setting('search_enabled')=='true' && !extension_loaded('xapian')) {
  256. Display::display_error_message(get_lang('SearchXapianModuleNotInstalled'));
  257. }
  258. // to hide the exercise description
  259. echo '<style> .media { display:none;}</style>';
  260. $form->display();
  261. }
  262. Display::display_footer();