gradebook_add_cat.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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. $_in_course = true;
  10. $course_code = api_get_course_id();
  11. if (empty($course_code)) {
  12. $_in_course = false;
  13. }
  14. api_block_anonymous_users();
  15. GradebookUtils::block_students();
  16. $edit_cat = isset($_REQUEST['editcat']) ? intval($_REQUEST['editcat']) : '';
  17. $get_select_cat = intval($_GET['selectcat']);
  18. $catadd = new Category();
  19. $my_user_id = api_get_user_id();
  20. $catadd->set_user_id($my_user_id);
  21. $catadd->set_parent_id($get_select_cat);
  22. $catcourse = Category :: load($get_select_cat);
  23. if ($_in_course) {
  24. $catadd->set_course_code($course_code);
  25. } else {
  26. $catadd->set_course_code($catcourse[0]->get_course_code());
  27. }
  28. $catadd->set_course_code(api_get_course_id());
  29. $form = new CatForm(
  30. CatForm::TYPE_ADD,
  31. $catadd,
  32. 'add_cat_form',
  33. null,
  34. api_get_self().'?selectcat='.$get_select_cat.'&'.api_get_cidreq()
  35. );
  36. if ($form->validate()) {
  37. $values = $form->exportValues();
  38. $select_course = isset($values['select_course']) ? $values['select_course'] : [];
  39. $cat = new Category();
  40. if ($values['hid_parent_id'] == '0') {
  41. if ($select_course == 'COURSEINDEPENDENT') {
  42. $cat->set_name($values['name']);
  43. $cat->set_course_code(null);
  44. } else {
  45. $cat->set_course_code($select_course);
  46. $cat->set_name($values['name']);
  47. }
  48. } else {
  49. $cat->set_name($values['name']);
  50. $cat->set_course_code($values['course_code']);
  51. }
  52. $cat->set_session_id(api_get_session_id());
  53. // Always add the gradebook to the course
  54. $cat->set_course_code(api_get_course_id());
  55. if (isset($values['skills'])) {
  56. $cat->set_skills($values['skills']);
  57. }
  58. $cat->set_description($values['description']);
  59. $cat->set_user_id($values['hid_user_id']);
  60. $cat->set_parent_id($values['hid_parent_id']);
  61. $cat->set_weight($values['weight']);
  62. if (isset($values['generate_certificates'])) {
  63. $cat->setGenerateCertificates(true);
  64. } else {
  65. $cat->setGenerateCertificates(false);
  66. }
  67. if (isset($values['is_requirement'])) {
  68. $cat->setIsRequirement(true);
  69. } else {
  70. $cat->setIsRequirement(false);
  71. }
  72. if (empty($values['visible'])) {
  73. $visible = 0;
  74. } else {
  75. $visible = 1;
  76. }
  77. $cat->set_visible($visible);
  78. $result = $cat->add();
  79. $logInfo = [
  80. 'tool' => TOOL_GRADEBOOK,
  81. 'tool_id' => 0,
  82. 'tool_id_detail' => 0,
  83. 'action' => 'new-cat',
  84. 'action_details' => 'parent_id='.$cat->get_parent_id(),
  85. ];
  86. Event::registerLog($logInfo);
  87. header('Location: '.Category::getUrl().'addcat=&selectcat='.$cat->get_parent_id());
  88. exit;
  89. }
  90. $logInfo = [
  91. 'tool' => TOOL_GRADEBOOK,
  92. 'tool_id' => 0,
  93. 'tool_id_detail' => 0,
  94. 'action' => 'add-cat',
  95. 'action_details' => Category::getUrl().'selectcat='.$get_select_cat,
  96. ];
  97. Event::registerLog($logInfo);
  98. if (!$_in_course) {
  99. $interbreadcrumb[] = [
  100. 'url' => Category::getUrl().'selectcat='.$get_select_cat,
  101. 'name' => get_lang('Assessments'),
  102. ];
  103. }
  104. $interbreadcrumb[] = ['url' => 'index.php?'.api_get_cidreq(), 'name' => get_lang('ToolAssessments')];
  105. Display :: display_header(get_lang('New category'));
  106. $display_form = true;
  107. if ($display_form) {
  108. $form->display();
  109. }
  110. Display :: display_footer();