gradebook_add_eval.php 4.0 KB

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