gradebook_add_cat.php 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  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 type="text/javascript">
  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. $models = api_get_settings_options('grading_model');
  92. $course_grading_model_id = api_get_course_setting('course_grading_model');
  93. $grading_model = '';
  94. if (!empty($course_grading_model_id)) {
  95. foreach($models as $option) {
  96. if (intval($option['id']) == $course_grading_model_id) {
  97. $grading_model = $option['value'];
  98. }
  99. }
  100. }
  101. $grading_contents = api_grading_model_functions($grading_model, 'to_array');
  102. $form = new CatForm(CatForm :: TYPE_ADD, $catadd, 'add_cat_form', null, api_get_self() . '?selectcat='.$get_select_cat);
  103. if ($form->validate()) {
  104. $values = $form->exportValues();
  105. $select_course=isset($values['select_course']) ? $values['select_course'] : array();
  106. $cat = new Category();
  107. if ($values['hid_parent_id'] == '0') {
  108. if ($select_course == 'COURSEINDEPENDENT') {
  109. $cat->set_name($values['name']);
  110. $cat->set_course_code(null);
  111. } else {
  112. $cat->set_course_code($select_course);
  113. $cat->set_name($values['name']);
  114. }
  115. } else {
  116. $cat->set_name($values['name']);
  117. $cat->set_course_code($values['course_code']);//?
  118. }
  119. //Always add the gradebook to the course
  120. $cat->set_course_code(api_get_course_id());
  121. $cat->set_skills($values['skills']);
  122. $cat->set_description($values['description']);
  123. $cat->set_user_id($values['hid_user_id']);
  124. $cat->set_parent_id($values['hid_parent_id']);
  125. $cat->set_weight($values['weight']);
  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());
  134. exit;
  135. }
  136. if ( !$_in_course ) {
  137. $interbreadcrumb[] = array ('url' => Security::remove_XSS($_SESSION['gradebook_dest']).'?selectcat='.$get_select_cat,'name' => get_lang('Gradebook'));
  138. }
  139. $interbreadcrumb[]= array ( 'url' =>'index.php','name' => get_lang('ToolGradebook'));
  140. Display :: display_header(get_lang('NewCategory'));
  141. $display_form = true;
  142. if (!empty($grading_contents)) {
  143. $count_items = count($grading_contents['items']);
  144. $cats = Category :: load(null, null, $course_code, null, null, $session_id, false); //already init
  145. $cats_count = count($cats) - 1 ;
  146. if ($cats_count >= $count_items) {
  147. Display::display_warning_message(get_lang('CheckYourGradingModelValues'));
  148. $display_form = false;
  149. }
  150. }
  151. if ($display_form)
  152. $form->display();
  153. Display :: display_footer();