gradebook_add_cat.php 5.3 KB

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