gradebook_add_eval.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Script
  5. * @package chamilo.gradebook
  6. */
  7. require_once __DIR__.'/../inc/global.inc.php';
  8. $current_course_tool = TOOL_GRADEBOOK;
  9. api_protect_course_script(true);
  10. api_block_anonymous_users();
  11. GradebookUtils::block_students();
  12. $select_cat = isset($_GET['selectcat']) ? (int) $_GET['selectcat'] : 0;
  13. $is_allowedToEdit = $is_courseAdmin;
  14. $evaladd = new Evaluation();
  15. $evaladd->set_user_id($_user['user_id']);
  16. if (!empty($select_cat)) {
  17. $evaladd->set_category_id($_GET['selectcat']);
  18. $cat = Category :: load($_GET['selectcat']);
  19. $evaladd->set_course_code($cat[0]->get_course_code());
  20. } else {
  21. $evaladd->set_category_id(0);
  22. }
  23. $form = new EvalForm(
  24. EvalForm :: TYPE_ADD,
  25. $evaladd,
  26. null,
  27. 'add_eval_form',
  28. null,
  29. api_get_self().'?selectcat='.$select_cat.'&'.api_get_cidreq()
  30. );
  31. if ($form->validate()) {
  32. $values = $form->exportValues();
  33. $eval = new Evaluation();
  34. $eval->set_name($values['name']);
  35. $eval->set_description($values['description']);
  36. $eval->set_user_id($values['hid_user_id']);
  37. if (!empty($values['hid_course_code'])) {
  38. $eval->set_course_code($values['hid_course_code']);
  39. }
  40. //Always add the gradebook to the course
  41. $eval->set_course_code(api_get_course_id());
  42. $eval->set_category_id($values['hid_category_id']);
  43. $parent_cat = Category :: load($values['hid_category_id']);
  44. $global_weight = $cat[0]->get_weight();
  45. //$values['weight'] = $values['weight_mask']/$global_weight*$parent_cat[0]->get_weight();
  46. $values['weight'] = $values['weight_mask'];
  47. $eval->set_weight($values['weight']);
  48. $eval->set_max($values['max']);
  49. if (empty($values['visible'])) {
  50. $visible = 0;
  51. } else {
  52. $visible = 1;
  53. }
  54. $eval->set_visible($visible);
  55. $eval->add();
  56. if ($eval->get_course_code() == null) {
  57. if ($values['adduser'] == 1) {
  58. //Disabling code when course code is null see issue #2705
  59. //header('Location: gradebook_add_user.php?selecteval=' . $eval->get_id());
  60. exit;
  61. } else {
  62. header('Location: '.Security::remove_XSS($_SESSION['gradebook_dest']).'?selectcat='.$eval->get_category_id().'&'.api_get_cidreq());
  63. exit;
  64. }
  65. } else {
  66. $val_addresult = isset($values['addresult']) ? $values['addresult'] : null;
  67. if ($val_addresult == 1) {
  68. header('Location: gradebook_add_result.php?selecteval='.$eval->get_id().'&'.api_get_cidreq());
  69. exit;
  70. } else {
  71. header('Location: '.Security::remove_XSS($_SESSION['gradebook_dest']).'?selectcat='.$eval->get_category_id().'&'.api_get_cidreq());
  72. exit;
  73. }
  74. }
  75. }
  76. $interbreadcrumb[] = array(
  77. 'url' => Security::remove_XSS($_SESSION['gradebook_dest']).'?selectcat='.$select_cat.'&'.api_get_cidreq(),
  78. 'name' => get_lang('Gradebook'))
  79. ;
  80. $this_section = SECTION_COURSES;
  81. $htmlHeadXtra[] = '<script type="text/javascript">
  82. $(document).ready( function() {
  83. $("#hid_category_id").change(function() {
  84. $("#hid_category_id option:selected").each(function () {
  85. var cat_id = $(this).val();
  86. $.ajax({
  87. url: "' . api_get_path(WEB_AJAX_PATH).'gradebook.ajax.php?a=get_gradebook_weight",
  88. data: "cat_id="+cat_id,
  89. success: function(return_value) {
  90. if (return_value != 0 ) {
  91. $("#max_weight").html(return_value);
  92. }
  93. }
  94. });
  95. });
  96. });
  97. });
  98. </script>';
  99. if ($evaladd->get_course_code() == null) {
  100. Display::addFlash(Display::return_message(get_lang('CourseIndependentEvaluation'), 'normal', false));
  101. }
  102. Display::display_header(get_lang('NewEvaluation'));
  103. $form->display();
  104. Display :: display_footer();