gradebook_add_cat.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Script
  5. * @package chamilo.gradebook
  6. */
  7. require_once '../inc/global.inc.php';
  8. $_in_course = true;
  9. $course_code = api_get_course_id();
  10. if (empty($course_code )) {
  11. $_in_course = false;
  12. }
  13. api_block_anonymous_users();
  14. GradebookUtils::block_students();
  15. $edit_cat = isset($_REQUEST['editcat']) ? intval($_REQUEST['editcat']) : '';
  16. $get_select_cat = intval($_GET['selectcat']);
  17. $catadd = new Category();
  18. $my_user_id = api_get_user_id();
  19. $catadd->set_user_id($my_user_id);
  20. $catadd->set_parent_id($get_select_cat);
  21. $catcourse = Category :: load ($get_select_cat);
  22. if ($_in_course) {
  23. $catadd->set_course_code($course_code);
  24. } else {
  25. $catadd->set_course_code($catcourse[0]->get_course_code());
  26. }
  27. $catadd->set_course_code(api_get_course_id());
  28. $form = new CatForm(
  29. CatForm :: TYPE_ADD,
  30. $catadd,
  31. 'add_cat_form',
  32. null,
  33. api_get_self() . '?selectcat='.$get_select_cat.'&'.api_get_cidreq()
  34. );
  35. if ($form->validate()) {
  36. $values = $form->exportValues();
  37. $select_course=isset($values['select_course']) ? $values['select_course'] : array();
  38. $cat = new Category();
  39. if ($values['hid_parent_id'] == '0') {
  40. if ($select_course == 'COURSEINDEPENDENT') {
  41. $cat->set_name($values['name']);
  42. $cat->set_course_code(null);
  43. } else {
  44. $cat->set_course_code($select_course);
  45. $cat->set_name($values['name']);
  46. }
  47. } else {
  48. $cat->set_name($values['name']);
  49. $cat->set_course_code($values['course_code']);
  50. }
  51. $cat->set_session_id(api_get_session_id());
  52. //Always add the gradebook to the course
  53. $cat->set_course_code(api_get_course_id());
  54. if (isset($values['skills'])) {
  55. $cat->set_skills($values['skills']);
  56. }
  57. $cat->set_description($values['description']);
  58. $cat->set_user_id($values['hid_user_id']);
  59. $cat->set_parent_id($values['hid_parent_id']);
  60. $cat->set_weight($values['weight']);
  61. if (isset($values['generate_certificates'])) {
  62. $cat->setGenerateCertificates(true);
  63. } else {
  64. $cat->setGenerateCertificates(false);
  65. }
  66. if (isset($values['is_requirement'])) {
  67. $cat->setIsRequirement(true);
  68. } else {
  69. $cat->setIsRequirement(false);
  70. }
  71. if (empty ($values['visible'])) {
  72. $visible = 0;
  73. } else {
  74. $visible = 1;
  75. }
  76. $cat->set_visible($visible);
  77. $result = $cat->add();
  78. header('Location: '.Security::remove_XSS($_SESSION['gradebook_dest']).'?addcat=&selectcat=' . $cat->get_parent_id().'&'.api_get_cidreq());
  79. exit;
  80. }
  81. if (!$_in_course) {
  82. $interbreadcrumb[] = array (
  83. 'url' => Security::remove_XSS($_SESSION['gradebook_dest']).'?selectcat='.$get_select_cat.'&'.api_get_cidreq(),
  84. 'name' => get_lang('Gradebook')
  85. );
  86. }
  87. $interbreadcrumb[] = array('url' => 'index.php?'.api_get_cidreq(), 'name' => get_lang('ToolGradebook'));
  88. Display :: display_header(get_lang('NewCategory'));
  89. $display_form = true;
  90. if ($display_form) {
  91. $form->display();
  92. }
  93. Display :: display_footer();