forked from jwnisbet/melodiesforus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
looper.php
67 lines (53 loc) · 1.72 KB
/
looper.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
67
<?php
session_start();
// Continues running the experiment until the user has finished the group
include('config.php');
include('functions.php');
// Get session
$sid = intval($_COOKIE['sid']);
$db = db_connect();
$group = get_from_session($sid, 'group_num');
$transaction = get_from_session($sid, 'transaction');
$treatment = get_from_session($sid, 'treatment_id');
$action = $_GET['sendEmail']; // based on user choice in purchase.php
$mediaId = $_GET['mediaId'];
if($action == 'true') {
// email needs to be sent
// adds media id to array
if (isset($_SESSION['mediaId'])) {
$_SESSION['mediaId'][] = $mediaId;
} else {
$_SESSION['mediaId'] = array($mediaId);
}
$action = 1;
}
else {
$action = 0;
}
// Insert results into database
$q = "INSERT INTO treatment_selections(sid, treatment_id, action)
VALUES($sid, $treatment, $action)";
runQuery($db, $q, false);
/*
If $action is true, then media id should be added to an array
that contains all media to be sent at final transaction
*/
if($transaction == 12) {
// Redirect to end survey, we're at the end
header('Location: endSurvey.php?sendEmail=' . $_GET['sendEmail'] . '&post_email=' . $_GET['post_email']);
die;
}
else {
// increments transaction
$newSeq = $transaction+1;
// Get the ID of the next item in the sequence (transaction)
// $q = "SELECT id FROM treatment WHERE sequence = $newSeq AND group_num = $group LIMIT 1";
// $result = runQuery($db, $q, true);
// $newTreatment = $result[0]['id'];
// updates transaction num for session
edit_session(array('transaction' => $newSeq), true, 'override');
// Redirect back to shopping
header('Location: shopping.php?success&transaction='.$newSeq);
die;
}
?>