gradebook_add_result.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Script
  5. * @package chamilo.gradebook
  6. */
  7. //$cidReset = true;
  8. $current_course_tool = TOOL_GRADEBOOK;
  9. api_protect_course_script(true);
  10. api_block_anonymous_users();
  11. GradebookUtils::block_students();
  12. $selectEval = isset($_GET['selecteval']) ? (int) $_GET['selecteval'] : 0;
  13. $resultadd = new Result();
  14. $resultadd->set_evaluation_id($selectEval);
  15. $evaluation = Evaluation :: load($selectEval);
  16. $category = !empty($_GET['selectcat']) ? $_GET['selectcat'] : "";
  17. $add_result_form = new EvalForm(
  18. EvalForm :: TYPE_RESULT_ADD,
  19. $evaluation[0],
  20. $resultadd,
  21. 'add_result_form',
  22. null,
  23. api_get_self() . '?selectcat=' . Security::remove_XSS($category) . '&selecteval=' . $selectEval.'&'.api_get_cidreq()
  24. );
  25. $table = $add_result_form->toHtml();
  26. if ($add_result_form->validate()) {
  27. $values = $add_result_form->exportValues();
  28. $nr_users = $values['nr_users'];
  29. if ($nr_users == '0') {
  30. header('Location: gradebook_view_result.php?addresultnostudents=&selecteval=' . $selectEval.'&'.api_get_cidreq());
  31. exit;
  32. }
  33. $scores = ($values['score']);
  34. foreach ($scores as $row) {
  35. $res = new Result();
  36. $res->set_evaluation_id($values['evaluation_id']);
  37. $res->set_user_id(key($scores));
  38. //if no scores are given, don't set the score
  39. if ((!empty ($row)) || ($row == '0')) $res->set_score($row);
  40. $res->add();
  41. next($scores);
  42. }
  43. header('Location: gradebook_view_result.php?addresult=&selecteval=' . $selectEval.'&'.api_get_cidreq());
  44. exit;
  45. }
  46. $interbreadcrumb[] = array(
  47. 'url' => Security::remove_XSS($_SESSION['gradebook_dest']),
  48. 'name' => get_lang('Gradebook')
  49. );
  50. Display :: display_header(get_lang('AddResult'));
  51. DisplayGradebook::display_header_result($evaluation[0], null, 0, 0);
  52. echo $table;
  53. Display :: display_footer();