gradebook_edit_cat.php 2.7 KB

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