forked from rbwatson/wlux_test_server
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstudy_data.php
More file actions
executable file
·64 lines (60 loc) · 2.31 KB
/
Copy pathstudy_data.php
File metadata and controls
executable file
·64 lines (60 loc) · 2.31 KB
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
<?php
include 'config_files.php';
// set the returnURL dynamically depending on whether we're on the
// development or produciton environment.
// NOTE: this assumes that the site and server directories are in the root
// of the site only when developing on localhost
$LOCAL = is_dir("../wlux_test_site");
$serverRoot = "http://staff.washington.edu/rbwatson/";
if ($LOCAL) {
$serverRoot = "/server/";
}
$returnURL = $serverRoot."end.php";
$taskBarCSS = $serverRoot."wluxTaskBar.css";
$data = array();
$condition = "";
$cssURL = "";
$session = $_GET["wlux_session"];
// get the data from the file. Eventually we need to query a database and
// ensure the session is a valid, open session
$file = fopen($sessionDataFile,"r");
while(! feof($file)) {
$line = fgets($file);
$line = explode(' ', $line);
if ($line[0] == $session) {
$condition = $line[1];
$cssURL = trim($line[2]);
}
}
fclose($file);
if ($condition != "" && $cssURL != "") {
$data = array("conditionId" => $condition,
"cssURL" => $cssURL,
"taskBarCSS" => $taskBarCSS,
"buttonText" => "End study",
"returnURL" => $returnURL,
// taskHTML will override taskText if both are sent
// but one or the other must be present
"taskText" => "Task: Learn to play hearts and spades to become a card shark.",
"taskHTML" => "<p class='wlux_taskbar_text'><strong>Task 1:</strong> This is some <i>formatted</i> text</p>",
"tabShowText" => "Show",
"tabHideText" => "Hide",
);
} else {
// this will trigger the jquery ajax call's error handling callback
header("HTTP/1.1 404 Not Found");
}
$jsonpTag = $_GET["callback"]; // set by jquery ajax call when using jsonp data type
if (!empty($jsonpTag)) {
header('content-type: application/json');
echo $jsonpTag . '(' . json_encode($data) . ')';
} else {
// this line only works on PHP > 5.4.0, which not everyone seems to have.
// http_response_code(500);
// this works on PHP > 4.3 (or so)
if (!headers_sent()) {
header('X-PHP-Response-Code: 500', true, 500);
}
// else too late to send a header with an error code
}
?>