gradebook_edit_cat.php 4.2 KB

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