gradebook_edit_cat.php 2.4 KB

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