gradebook_edit_cat.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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. api_block_anonymous_users();
  9. GradebookUtils::block_students();
  10. $edit_cat = isset($_REQUEST['editcat']) ? intval($_REQUEST['editcat']) : '';
  11. $htmlHeadXtra[] = '<script>
  12. $(document).ready(function() {
  13. $("#skills").fcbkcomplete({
  14. json_url: "'.api_get_path(WEB_AJAX_PATH).'skill.ajax.php?a=find_skills",
  15. cache: false,
  16. filter_case: false,
  17. filter_hide: true,
  18. complete_text:"'.get_lang('StartToType').'",
  19. firstselected: true,
  20. //onremove: "testme",
  21. onselect:"check_skills",
  22. filter_selected: true,
  23. newel: true
  24. });
  25. $(".closebutton").click(function() {
  26. var skill_id = ($(this).attr("id")).split("_")[1];
  27. if (skill_id) {
  28. $.ajax({
  29. url: "'.api_get_path(WEB_AJAX_PATH).'skill.ajax.php?a=remove_skill",
  30. data: "gradebook_id='.$edit_cat.'&skill_id="+skill_id,
  31. success: function(return_value) {
  32. if (return_value == 1 ) {
  33. $("#skill_"+skill_id).remove();
  34. }
  35. }
  36. });
  37. }
  38. });
  39. });
  40. function check_skills() {
  41. //selecting only selected users
  42. $("#skills option:selected").each(function() {
  43. var skill_id = $(this).val();
  44. if (skill_id != "" ) {
  45. $.ajax({
  46. url: "'.api_get_path(WEB_AJAX_PATH).'skill.ajax.php?a=skill_exists",
  47. data: "skill_id="+skill_id,
  48. success: function(return_value) {
  49. if (return_value == 0 ) {
  50. alert("'.get_lang('SkillDoesNotExist').'");
  51. //Deleting select option tag
  52. $("#skills option[value="+skill_id+"]").remove();
  53. //Deleting holder
  54. $(".holder li").each(function () {
  55. if ($(this).attr("rel") == skill_id) {
  56. $(this).remove();
  57. }
  58. });
  59. }
  60. }
  61. });
  62. }
  63. });
  64. }
  65. </script>';
  66. $catedit = Category::load($edit_cat);
  67. $form = new CatForm(
  68. CatForm::TYPE_EDIT,
  69. $catedit[0],
  70. 'edit_cat_form',
  71. 'post',
  72. api_get_self().'?'.api_get_cidreq().'&editcat='.$edit_cat
  73. );
  74. if ($form->validate()) {
  75. $values = $form->getSubmitValues();
  76. $cat = new Category();
  77. if (!empty($values['hid_id'])) {
  78. $cat = $cat->load($values['hid_id']);
  79. if (isset($cat[0])) {
  80. $cat = $cat[0];
  81. }
  82. }
  83. $cat->set_id($values['hid_id']);
  84. $cat->set_name($values['name']);
  85. if (empty ($values['course_code'])) {
  86. $cat->set_course_code(null);
  87. } else {
  88. $cat->set_course_code($values['course_code']);
  89. }
  90. if (isset($values['grade_model_id'])) {
  91. $cat->set_grade_model_id($values['grade_model_id']);
  92. }
  93. $cat->set_description($values['description']);
  94. if (isset($values['skills'])) {
  95. $cat->set_skills($values['skills']);
  96. }
  97. $cat->set_user_id($values['hid_user_id']);
  98. $cat->set_parent_id($values['hid_parent_id']);
  99. $cat->set_weight($values['weight']);
  100. if (isset($values['generate_certificates'])) {
  101. $cat->setGenerateCertificates($values['generate_certificates']);
  102. }
  103. if ($values['hid_parent_id'] == 0 ) {
  104. $cat->set_certificate_min_score($values['certif_min_score']);
  105. } else {
  106. $cat->setGenerateCertificates(false);
  107. }
  108. if (empty ($values['visible'])) {
  109. $visible = 0;
  110. } else {
  111. $visible = 1;
  112. }
  113. $cat->set_visible($visible);
  114. if (isset($values['is_requirement'])) {
  115. $cat->setIsRequirement(true);
  116. } else {
  117. $cat->setIsRequirement(false);
  118. }
  119. $cat->save();
  120. header('Location: '.Security::remove_XSS($_SESSION['gradebook_dest']).'?editcat=&selectcat=' . $cat->get_parent_id().'&'.api_get_cidreq());
  121. exit;
  122. }
  123. $selectcat = isset($_GET['selectcat']) ? Security::remove_XSS($_GET['selectcat']) : '';
  124. $interbreadcrumb[] = array(
  125. 'url' => Security::remove_XSS($_SESSION['gradebook_dest']) . '?selectcat=' . $selectcat . '&' . api_get_cidreq(),
  126. 'name' => get_lang('Gradebook')
  127. );
  128. $this_section = SECTION_COURSES;
  129. Display :: display_header(get_lang('EditCategory'));
  130. $form->display();
  131. Display :: display_footer();