gradebook_edit_cat.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * @package chamilo.gradebook
  5. */
  6. require_once __DIR__.'/../inc/global.inc.php';
  7. api_block_anonymous_users();
  8. GradebookUtils::block_students();
  9. $edit_cat = isset($_REQUEST['editcat']) ? (int) $_REQUEST['editcat'] : 0;
  10. $catedit = Category::load($edit_cat);
  11. $form = new CatForm(
  12. CatForm::TYPE_EDIT,
  13. $catedit[0],
  14. 'edit_cat_form',
  15. 'post',
  16. api_get_self().'?'.api_get_cidreq().'&editcat='.$edit_cat
  17. );
  18. if ($form->validate()) {
  19. $values = $form->getSubmitValues();
  20. $cat = new Category();
  21. if (!empty($values['hid_id'])) {
  22. $cat = $cat->load($values['hid_id']);
  23. if (isset($cat[0])) {
  24. $cat = $cat[0];
  25. }
  26. }
  27. $cat->set_id($values['hid_id']);
  28. $cat->set_name($values['name']);
  29. if (empty($values['course_code'])) {
  30. $cat->set_course_code(null);
  31. } else {
  32. $cat->set_course_code($values['course_code']);
  33. }
  34. if (isset($values['grade_model_id'])) {
  35. $cat->set_grade_model_id($values['grade_model_id']);
  36. }
  37. $cat->set_description($values['description']);
  38. if (isset($values['skills'])) {
  39. $cat->set_skills($values['skills']);
  40. }
  41. $cat->set_user_id($values['hid_user_id']);
  42. $cat->set_parent_id($values['hid_parent_id']);
  43. $cat->set_weight($values['weight']);
  44. if (isset($values['generate_certificates'])) {
  45. $cat->setGenerateCertificates($values['generate_certificates']);
  46. } else {
  47. $cat->setGenerateCertificates(false);
  48. }
  49. if ($values['hid_parent_id'] == 0) {
  50. $cat->set_certificate_min_score($values['certif_min_score']);
  51. }
  52. $visible = 1;
  53. if (empty($values['visible'])) {
  54. $visible = 0;
  55. }
  56. $cat->set_visible($visible);
  57. if (isset($values['is_requirement'])) {
  58. $cat->setIsRequirement(true);
  59. } else {
  60. $cat->setIsRequirement(false);
  61. }
  62. $cat->save();
  63. header('Location: '.Category::getUrl().'editcat=&selectcat='.$cat->get_parent_id());
  64. exit;
  65. }
  66. $selectcat = isset($_GET['selectcat']) ? (int) $_GET['selectcat'] : 0;
  67. $action_details = '';
  68. $current_id = 0;
  69. if (isset($_GET['editcat'])) {
  70. $action_details = 'editcat';
  71. $current_id = (int) $_GET['editcat'];
  72. }
  73. $logInfo = [
  74. 'tool' => TOOL_GRADEBOOK,
  75. 'tool_id' => 0,
  76. 'tool_id_detail' => 0,
  77. 'action' => 'edit-cat',
  78. 'action_details' => $action_details,
  79. ];
  80. Event::registerLog($logInfo);
  81. $interbreadcrumb[] = [
  82. 'url' => Category::getUrl().'selectcat='.$selectcat,
  83. 'name' => get_lang('Gradebook'),
  84. ];
  85. $this_section = SECTION_COURSES;
  86. Display::display_header(get_lang('EditCategory'));
  87. $form->display();
  88. Display::display_footer();