PageRenderTime 50ms CodeModel.GetById 28ms RepoModel.GetById 1ms app.codeStats 0ms

/save_answ.php

https://bitbucket.org/swallow13/online_exam_system
PHP | 88 lines | 77 code | 7 blank | 4 comment | 9 complexity | 92464cb929dd74b079be7fc9ee426490 MD5 | raw file
  1. <?php
  2. /**
  3. * @Alex Ai swallow13@163.com
  4. * @copyright 2009
  5. */
  6. session_start();
  7. if ((!isset($_SESSION['pid'])) or (!isset($_SESSION['stamp']))) {
  8. header("location:index.php");
  9. exit;
  10. }
  11. require_once("include/config.php");
  12. $client_ip = $_SERVER['REMOTE_ADDR'];
  13. $time = $_SERVER['REQUEST_TIME'];
  14. $client_port = $_SERVER['REMOTE_PORT'];
  15. $keyword = md5($time.$client_ip.$client_port);
  16. $_SESSION['keyword'] = $keyword;
  17. $v1 = $_SESSION['pid'];$v2 = $_SESSION['uid'];$v3 = $_SESSION['stamp'];
  18. mysql_query("INSERT INTO `gb_answer_papers` (`paper_id`,`stu_id`,`keyword`,`time`) VALUES ('$v1','$v2','$keyword','$v3');");
  19. $answ_id = mysql_insert_id();
  20. $_SESSION['answ_id'] = $answ_id;
  21. $tmp_score_1 = 0;$tmp_score_2 = 0;
  22. for ($i = 1;$i <= $_POST['count_items'];++$i) {
  23. $s1 = "T".$i;
  24. $s1 = $_POST["$s1"];
  25. $decision[] = $s1;
  26. $s2 = "ID".$i;
  27. $s2 = $_POST["$s2"];
  28. switch ($s1) {
  29. case 1:
  30. $s3 = "Q".$i;
  31. $s3 = $_POST["$s3"];
  32. mysql_query("INSERT INTO `gb_obj_answ` (`id`,`item_id`,`answ`) VALUES ('$answ_id','$s2','$s3');");
  33. $std_answ = mysql_result(mysql_query("SELECT `std_answ` FROM `gb_item_std_answ` WHERE `item_id` = '$s2';"),0);
  34. $cost = mysql_result(mysql_query("SELECT `item_score` FROM `gb_items_warehouse` WHERE `item_id` = '$s2';"),0);
  35. if ($s3 == $std_answ) {
  36. $tmp_score_1 = $tmp_score_1 + $cost;
  37. }
  38. break;
  39. case 2:
  40. $s3 = "Q".$i;
  41. $s3 = $_POST["$s3"];
  42. $str = "";
  43. foreach ($s3 as $each) {
  44. $str .= $each;
  45. }
  46. mysql_query("INSERT INTO `gb_obj_answ` (`id`,`item_id`,`answ`) VALUES ('$answ_id','$s2','$str');");
  47. $std_answ = mysql_result(mysql_query("SELECT `std_answ` FROM `gb_item_std_answ` WHERE `item_id` = '$s2';"),0);
  48. $cost = mysql_result(mysql_query("SELECT `item_score` FROM `gb_items_warehouse` WHERE `item_id` = '$s2';"),0);
  49. if ($str == $std_answ) {
  50. $tmp_score_2 = $tmp_score_2 + $cost;
  51. }
  52. $str = "";
  53. break;
  54. case 3:
  55. $s3 = "Q".$i;
  56. $s3 = $_POST["$s3"];
  57. foreach ($s3 as $each) {
  58. mysql_query("INSERT INTO `gb_sub_answ` (`id`,`item_id`,`answ`) VALUES ('$answ_id','$s2','$each');");
  59. }
  60. break;
  61. case 4:
  62. $s3 = "Q".$i;
  63. $s3 = $_POST["$s3"];
  64. mysql_query("INSERT INTO `gb_sub_answ` (`id`,`item_id`,`answ`) VALUES ('$answ_id','$s2','$s3');");
  65. break;
  66. }
  67. }
  68. $tmp_total = $tmp_score_1 + $tmp_score_2;
  69. mysql_query("INSERT INTO `gb_answ_score` (`id`,`score1`,`score2`,`total`) VALUES ('$answ_id','$tmp_score_1','$tmp_score_2','$tmp_total');");
  70. $decision = array_unique($decision);
  71. foreach ($decision as $tmp) {
  72. $he = $he + $tmp;
  73. }
  74. if (intval($he) <= 3) {
  75. mysql_query("UPDATE `gb_answer_papers` SET `status` = '1' WHERE `id` = '$answ_id';");
  76. header("location:final.php");
  77. } else {
  78. header("location:waiting.php");
  79. }
  80. echo "It is unavilible..";
  81. ?>