commit f37d001ad97a737f1204d82579317407b5712994
parent 2e0bcbe34cdf3b83b9784d0e48989bfe0f74d127
Author: John Kubach <johnkubach@gmail.com>
Date: Wed, 19 Dec 2018 17:48:29 -0500
check if survey has expired
an expired survey may still be taken, but no furthur results will be saved.
Diffstat:
2 files changed, 26 insertions(+), 9 deletions(-)
diff --git a/website/res/submit-survey.php b/website/res/submit-survey.php
@@ -20,9 +20,11 @@ if (isset($_POST['answers'])) {
for($counter = 0; $counter < sizeof($answers); $counter++) {
$questionNum = $counter+1;
$q = $answers[$counter];
- $sql = "INSERT INTO answer_numeric (user_id, survey_id, question_number, answer)
- VALUES ('$user', '$survey_id', $counter + 1, $q);";
- mysqli_query($connect, $sql) or die(mysqli_error($connect));
+ if ($_SESSION['expired'] != 1) {
+ $sql = "INSERT INTO answer_numeric (user_id, survey_id, question_number, answer)
+ VALUES ('$user', '$survey_id', $counter + 1, $q);";
+ mysqli_query($connect, $sql) or die(mysqli_error($connect));
+ }
$getsql = "SELECT question_content from question where survey_id=$survey_id and question_number=$counter+1;";
$result = mysqli_query($connect, $getsql);
@@ -44,9 +46,11 @@ if (isset($_POST['answers'])) {
$type = 49;
$questionNum = $counter+1;
$q = $answers[$counter];
- $sql = "INSERT INTO answer_bool (user_id, survey_id, question_number, answer)
- VALUES ('$user', '$survey_id', $counter + 1, '$q');";
- mysqli_query($connect, $sql) or die(mysqli_error($connect));
+ if ($_SESSION['expired'] != 1) {
+ $sql = "INSERT INTO answer_bool (user_id, survey_id, question_number, answer)
+ VALUES ('$user', '$survey_id', $counter + 1, '$q');";
+ mysqli_query($connect, $sql) or die(mysqli_error($connect));
+ }
$getsql = "SELECT question_content from question where survey_id=$survey_id and question_number=$counter+1;";
$result = mysqli_query($connect, $getsql);
@@ -69,9 +73,11 @@ if (isset($_POST['answers'])) {
{
$questionNum = $counter+1;
$q = $answers[$counter];
- $sql = "INSERT INTO answer_text (user_id, survey_id, question_number, answer)
- VALUES ('$user', '$survey_id', $counter + 1, $q);";
- mysqli_query($connect, $sql) or die(mysqli_error($connect));
+ if ($_SESSION['expired'] != 1) {
+ $sql = "INSERT INTO answer_text (user_id, survey_id, question_number, answer)
+ VALUES ('$user', '$survey_id', $counter + 1, $q);";
+ mysqli_query($connect, $sql) or die(mysqli_error($connect));
+ }
$getsql = "SELECT question_content from question where survey_id=$survey_id and question_number=$counter+1;";
$result = mysqli_query($connect, $getsql);
@@ -79,6 +85,7 @@ if (isset($_POST['answers'])) {
echo "For Question #", $counter+1, ": ", $question['question_content'], ", you answered: ", $answers[$counter], "<br>";
}
+ unset($_SESSION['expired']);
echo "<a href='../index.php'> Home </a>";
exit();
diff --git a/website/takesurvey.php b/website/takesurvey.php
@@ -51,7 +51,9 @@ if (empty($code)) {
$title = $row['title'];
$number_questions = $row['number_questions'];
$type = ord($row['type']);
+ $expire_date = $row['expiration_date'];
$one_shot = ord($row['one_shot']);
+
if ($one_shot == 49) {
if ($type == 48) {
@@ -69,6 +71,14 @@ if (empty($code)) {
}
}
+ if ($expire_date < date("Y-m-d")) {
+ $_SESSION['expired'] = 1;
+ echo "<h3> NOTICE: This survey is expired. Your answers will not be counted. </h3>";
+ } else {
+ $_SESSION['expired'] = 0;
+ }
+
+
echo "<form method = 'POST' action = 'res/submit-survey.php'>";
echo "<h1> $title </h1> <br>";