gradebook_add_result.php 1.9 KB

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