gradebook_edit_cat.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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']) ? (int) $_REQUEST['editcat'] : 0;
  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. $visible = 1;
  55. if (empty($values['visible'])) {
  56. $visible = 0;
  57. }
  58. $cat->set_visible($visible);
  59. if (isset($values['is_requirement'])) {
  60. $cat->setIsRequirement(true);
  61. } else {
  62. $cat->setIsRequirement(false);
  63. }
  64. $cat->save();
  65. header('Location: '.Category::getUrl().'editcat=&selectcat='.$cat->get_parent_id());
  66. exit;
  67. }
  68. $selectcat = isset($_GET['selectcat']) ? (int) $_GET['selectcat'] : 0;
  69. $action_details = '';
  70. $current_id = 0;
  71. if (isset($_GET['editcat'])) {
  72. $action_details = 'editcat';
  73. $current_id = (int) $_GET['editcat'];
  74. }
  75. $logInfo = [
  76. 'tool' => TOOL_GRADEBOOK,
  77. 'tool_id' => 0,
  78. 'tool_id_detail' => 0,
  79. 'action' => 'edit-cat',
  80. 'action_details' => $action_details,
  81. ];
  82. Event::registerLog($logInfo);
  83. $interbreadcrumb[] = [
  84. 'url' => Category::getUrl().'selectcat='.$selectcat,
  85. 'name' => get_lang('Gradebook'),
  86. ];
  87. $this_section = SECTION_COURSES;
  88. Display :: display_header(get_lang('EditCategory'));
  89. $form->display();
  90. Display :: display_footer();