gradebook_add_result.php 2.2 KB

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