gradebook_add_eval.php 3.7 KB

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