gradebook_add_eval.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Script
  5. * @package chamilo.gradebook
  6. */
  7. /**
  8. * Init
  9. */
  10. $language_file = 'gradebook';
  11. require_once '../inc/global.inc.php';
  12. require_once 'lib/be.inc.php';
  13. require_once 'lib/gradebook_functions.inc.php';
  14. require_once 'lib/fe/evalform.class.php';
  15. $current_course_tool = TOOL_GRADEBOOK;
  16. api_protect_course_script();
  17. api_block_anonymous_users();
  18. block_students();
  19. $select_cat=isset($_GET['selectcat']) ? Security::remove_XSS($_GET['selectcat']) : '';
  20. $is_allowedToEdit = api_is_course_admin();
  21. $evaladd = new Evaluation();
  22. $evaladd->set_user_id($_user['user_id']);
  23. if (isset ($_GET['selectcat']) && (!empty ($_GET['selectcat']))) {
  24. $evaladd->set_category_id($_GET['selectcat']);
  25. $cat = Category :: load($_GET['selectcat']);
  26. $evaladd->set_course_code($cat[0]->get_course_code());
  27. } else {
  28. $evaladd->set_category_id(0);
  29. }
  30. $form = new EvalForm(EvalForm :: TYPE_ADD, $evaladd, null, 'add_eval_form',null, api_get_self() . '?selectcat=' .$select_cat);
  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());
  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());
  69. exit;
  70. } else {
  71. header('Location: '.Security::remove_XSS($_SESSION['gradebook_dest']).'?selectcat=' . $eval->get_category_id());
  72. exit;
  73. }
  74. }
  75. }
  76. $interbreadcrumb[] = array (
  77. 'url' => Security::remove_XSS($_SESSION['gradebook_dest']).'?selectcat='.$select_cat,
  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. Display :: display_header(get_lang('NewEvaluation'));
  100. if ($evaladd->get_course_code() == null) {
  101. Display :: display_normal_message(get_lang('CourseIndependentEvaluation'),false);
  102. }
  103. $form->display();
  104. Display :: display_footer();