gradebook_add_eval.php 3.9 KB

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