-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpost_SHORT_quiz.php
66 lines (55 loc) · 2.25 KB
/
post_SHORT_quiz.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<?php
//'session_check.php' checks if the session is active and if not
// redirects to the splash page
include("session_check.php");
?>
<!-- SESSION: ABOVE MUST BE PLACED AT VERY BEGINNING OF FILE BEFORE ANYTHING GET'S OUTPUTTED TO BROWSER -->
<?php
//user gets a soc score out of $numQuestions * 100 (can get total of 100 per question)
//and fisc score out of $numQuestions * 100
//We will store a number out of 100 - where we know that >50 is conservative and <50 is liberal
$numQuestions = 5; //must have equal nums fisc/soc questions
$econScore = 0;
$socScore = 0;
$quizIsComplete = True;
for ($i=1; $i<=$numQuestions; $i++)
{
$econVal = $_POST["econ".(string)$i.""];
$socVal = $_POST["soc".(string)$i.""];
if ($econVal == '') {
echo "You have not completed fiscal question #".((string)$i)."<br/>"; // This will only show up in the post_quiz.php page which is loaded briefly before redirecting to profile.php?quiz_results page. To see this, comment out the window.location code at the bottom.
$quizIsComplete = False;
}
if ($socVal == '') {
echo "You have not completed social question #".((string)$i)."<br/>"; // This will only show up in the post_quiz.php page which is loaded briefly before redirecting to profile.php?quiz_results page. To see this, comment out the window.location code at the bottom.
$quizIsComplete = False;
}
$econScore += (int)$econVal;
$socScore += (int)$socVal;
}
$normalizedSocScore = ($socScore/($numQuestions*100))*100;
$normalizedEconScore = ($econScore/($numQuestions*100))*100;
//now put the score into the db. and redirect to profile page
include("config.php");
$query = sprintf("UPDATE balance_users SET fiscal_scale=%d, social_scale=%d WHERE id=%d",
mysql_real_escape_string($normalizedEconScore),
mysql_real_escape_string($normalizedSocScore),
mysql_real_escape_string($_SESSION['user_id'])
);
// Actually update db now
$result = mysql_query($query);
?>
<script type="text/javascript">
//SET quiz confirm MESSAGE HERE
<?php if ($quizIsComplete) { ?>
window.location = "./profile.php?post_quiz";
<?php } else { ?>
window.location = "./quiz.php?unfinished_quiz"
<?php }
?>
</script>
<!DOCTYPE html>
<html>
<body>
</body>
</html>