gradebook_add_cat.php 3.0 KB

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