gradebook_add_cat.php 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Script
  5. * @package chamilo.gradebook
  6. */
  7. require_once '../inc/global.inc.php';
  8. $_in_course = true;
  9. $course_code = api_get_course_id();
  10. if (empty($course_code )) {
  11. $_in_course = false;
  12. }
  13. api_block_anonymous_users();
  14. GradebookUtils::block_students();
  15. $edit_cat = isset($_REQUEST['editcat']) ? intval($_REQUEST['editcat']) : '';
  16. $htmlHeadXtra[] = '<script>
  17. $(document).ready(function () {
  18. $("#skills").fcbkcomplete({
  19. json_url: "'.api_get_path(WEB_AJAX_PATH).'skill.ajax.php?a=find_skills",
  20. cache: false,
  21. filter_case: false,
  22. filter_hide: true,
  23. complete_text:"'.get_lang('StartToType').'",
  24. firstselected: true,
  25. //onremove: "testme",
  26. onselect:"check_skills",
  27. filter_selected: true,
  28. newel: true
  29. });
  30. $(".closebutton").click(function() {
  31. var skill_id = ($(this).attr("id")).split("_")[1];
  32. if (skill_id) {
  33. $.ajax({
  34. url: "'.api_get_path(WEB_AJAX_PATH).'skill.ajax.php?a=remove_skill",
  35. data: "gradebook_id=' . $edit_cat . '&skill_id="+skill_id,
  36. success: function(return_value) {
  37. if (return_value == 1 ) {
  38. $("#skill_"+skill_id).remove();
  39. }
  40. }
  41. });
  42. }
  43. });
  44. });
  45. function check_skills() {
  46. // selecting only selected users
  47. $("#skills option:selected").each(function() {
  48. var skill_id = $(this).val();
  49. if (skill_id != "" ) {
  50. $.ajax({
  51. url: "'.api_get_path(WEB_AJAX_PATH).'skill.ajax.php?a=skill_exists",
  52. data: "skill_id="+skill_id,
  53. success: function(return_value) {
  54. if (return_value == 0 ) {
  55. alert("'.get_lang('SkillDoesNotExist').'");
  56. //Deleting select option tag
  57. $("#skills option[value="+skill_id+"]").remove();
  58. //Deleting holder
  59. $(".holder li").each(function () {
  60. if ($(this).attr("rel") == skill_id) {
  61. $(this).remove();
  62. }
  63. });
  64. }
  65. }
  66. });
  67. }
  68. });
  69. }
  70. </script>';
  71. $get_select_cat = intval($_GET['selectcat']);
  72. $catadd = new Category();
  73. $my_user_id = api_get_user_id();
  74. $catadd->set_user_id($my_user_id);
  75. $catadd->set_parent_id($get_select_cat);
  76. $catcourse = Category :: load ($get_select_cat);
  77. if ($_in_course) {
  78. $catadd->set_course_code($course_code);
  79. } else {
  80. $catadd->set_course_code($catcourse[0]->get_course_code());
  81. }
  82. $catadd->set_course_code(api_get_course_id());
  83. $form = new CatForm(
  84. CatForm :: TYPE_ADD,
  85. $catadd,
  86. 'add_cat_form',
  87. null,
  88. api_get_self() . '?selectcat='.$get_select_cat.'&'.api_get_cidreq()
  89. );
  90. if ($form->validate()) {
  91. $values = $form->exportValues();
  92. $select_course=isset($values['select_course']) ? $values['select_course'] : array();
  93. $cat = new Category();
  94. if ($values['hid_parent_id'] == '0') {
  95. if ($select_course == 'COURSEINDEPENDENT') {
  96. $cat->set_name($values['name']);
  97. $cat->set_course_code(null);
  98. } else {
  99. $cat->set_course_code($select_course);
  100. $cat->set_name($values['name']);
  101. }
  102. } else {
  103. $cat->set_name($values['name']);
  104. $cat->set_course_code($values['course_code']);
  105. }
  106. $cat->set_session_id(api_get_session_id());
  107. //Always add the gradebook to the course
  108. $cat->set_course_code(api_get_course_id());
  109. if (isset($values['skills'])) {
  110. $cat->set_skills($values['skills']);
  111. }
  112. $cat->set_description($values['description']);
  113. $cat->set_user_id($values['hid_user_id']);
  114. $cat->set_parent_id($values['hid_parent_id']);
  115. $cat->set_weight($values['weight']);
  116. if (isset($values['generate_certificates'])) {
  117. $cat->setGenerateCertificates(true);
  118. } else {
  119. $cat->setGenerateCertificates(false);
  120. }
  121. if (isset($values['is_requirement'])) {
  122. $cat->setIsRequirement(true);
  123. } else {
  124. $cat->setIsRequirement(false);
  125. }
  126. if (empty ($values['visible'])) {
  127. $visible = 0;
  128. } else {
  129. $visible = 1;
  130. }
  131. $cat->set_visible($visible);
  132. $result = $cat->add();
  133. header('Location: '.Security::remove_XSS($_SESSION['gradebook_dest']).'?addcat=&selectcat=' . $cat->get_parent_id().'&'.api_get_cidreq());
  134. exit;
  135. }
  136. if (!$_in_course) {
  137. $interbreadcrumb[] = array (
  138. 'url' => Security::remove_XSS($_SESSION['gradebook_dest']).'?selectcat='.$get_select_cat.'&'.api_get_cidreq(),
  139. 'name' => get_lang('Gradebook')
  140. );
  141. }
  142. $interbreadcrumb[]= array( 'url' =>'index.php','name' => get_lang('ToolGradebook'));
  143. Display :: display_header(get_lang('NewCategory'));
  144. $display_form = true;
  145. /*if (!empty($grading_contents)) {
  146. $count_items = count($grading_contents['items']);
  147. $cats = Category :: load(null, null, $course_code, null, null, $session_id, false); //already init
  148. $cats_count = count($cats) - 1 ;
  149. if ($cats_count >= $count_items) {
  150. Display::display_warning_message(get_lang('CheckYourGradingModelValues'));
  151. $display_form = false;
  152. }
  153. }*/
  154. if ($display_form) {
  155. $form->display();
  156. }
  157. Display :: display_footer();