gradebook_add_cat.php 4.8 KB

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