-
Notifications
You must be signed in to change notification settings - Fork 1
/
project.php
executable file
·317 lines (276 loc) · 13.8 KB
/
project.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
<?php
require_once $_SERVER['DOCUMENT_ROOT'] . '/include/main_func.php';
require_once DOC_ROOT . '/include/classes/Parsedown.php';
/****************************************************
* Get Project Info
***************************************************/
if (count($_GET) > 0) {
$keys = array_keys($_GET);
$projectname = $keys[0];
$projexcl = array();
if ($_SESSION['age'] > 0) {
$projexcl[] = '(lower_age <= ' . ($_SESSION['age']) . ' OR lower_age IS NULL)';
$projexcl[] = '(upper_age >= ' . ($_SESSION['age']) . ' OR upper_age IS NULL)';
} else {
// only show items with no age limits for people without an age
$projexcl[] = '(lower_age IS NULL AND upper_age IS NULL)';
}
if ($_SESSION['sex'] == 'male') {
$projexcl[] = '(sex!="female")';
} else if ($_SESSION['sex'] == 'female') {
$projexcl[] = '(sex!="male")';
}
$projexcl = implode(' AND ', $projexcl);
if (in_array($_SESSION['status'], $RES_STATUS)) {
# res users can see all studies, no demog restrictions
$myproject = new myQuery('SELECT * FROM project WHERE url="' . $projectname . '"');
} else if ($_SESSION['status'] == 'test') {
# test users can see non-archive studies, with demog restrictions
$myproject = new myQuery('SELECT * FROM project WHERE status!="archive" AND url="' . $projectname . '" AND ' . $projexcl);
} else if (in_array($_SESSION['status'], array('guest', 'registered'))) {
# guest and registered users can see active studies, with demog restrictions
$myproject = new myQuery('SELECT * FROM project WHERE status="active" AND url="' . $projectname . '" AND ' . $projexcl);
} else if (array_key_exists('test', $_GET)) {
# non-logged in test can see non-archive studies, no demog restrictions yet
$myproject = new myQuery('SELECT * FROM project WHERE status!="archive" AND url="' . $projectname . '"');
} else {
# non-logged in non-test can see active studies, no demog restrictions yet
$myproject = new myQuery('SELECT * FROM project WHERE status="active" AND url="' . $projectname . '"');
}
// check if a project was returned or exit
if ($myproject->get_num_rows() == 0) {
$title = loc('Project not found');
$page = new page($title);
$page->set_menu(true);
$page->displayHead();
$page->displayBody();
$proj = new myQuery('SELECT status FROM project WHERE url="' . $projectname . '"');
if ($proj->get_num_rows() == 0) {
echo '<p>' . loc('Sorry, this project does not exist.'). '</p>';
} else if (in_array($proj->get_one(), array('test', 'archive')) ) {
echo '<p>' . loc('Sorry, this project is not active.'). '</p>';
} else {
echo '<p>' . loc('Sorry, this project is not available. It may have gender or age restrictions.'). '</p>';
}
echo '<p>' . loc('Double-check the link and contact the researcher if this seems to be an error.'). '</p>';
$page->displayFooter();
exit;
}
// project found, check for showable items
$_SESSION['project'] = $projectname;
$project = $myproject->get_one_array();
// set new session if project has changed
if ($_SESSION['project_id'] != $project['id']) { unset($_SESSION['session_id']); }
$_SESSION['project_id'] = $project['id'];
/*
$exclusions = array();
if ($_SESSION['age'] > 0) {
$exclusions['exp'][] = '(exp.lower_age <= ' . ($_SESSION['age']) . ' OR exp.lower_age IS NULL)';
$exclusions['quest'][] = '(quest.lower_age <= ' . ($_SESSION['age']) . ' OR quest.lower_age IS NULL)';
$exclusions['sets'][] = '(sets.lower_age <= ' . ($_SESSION['age']) . ' OR sets.lower_age IS NULL)';
$exclusions['exp'][] = '(exp.upper_age >= ' . ($_SESSION['age']) . ' OR exp.upper_age IS NULL)';
$exclusions['quest'][] = '(quest.upper_age >= ' . ($_SESSION['age']) . ' OR quest.upper_age IS NULL)';
$exclusions['sets'][] = '(sets.upper_age >= ' . ($_SESSION['age']) . ' OR sets.upper_age IS NULL)';
} else {
// only show items with no age limits for people without an age
$exclusions['exp'][] = 'exp.lower_age IS NULL AND exp.upper_age IS NULL';
$exclusions['quest'][] = 'quest.lower_age IS NULL AND quest.upper_age IS NULL';
$exclusions['sets'][] = 'sets.lower_age IS NULL AND sets.upper_age IS NULL';
}
if ($_SESSION['sex'] == 'male') {
$exclusions['exp'][] = '(exp.sex!="female")';
$exclusions['quest'][] = '(quest.sex!="female")';
$exclusions['sets'][] = '(sets.sex!="female")';
} else if ($_SESSION['sex'] == 'female') {
$exclusions['exp'][] = '(exp.sex!="male")';
$exclusions['quest'][] = '(quest.sex!="male")';
$exclusions['sets'][] = '(sets.sex!="male")';
}
$myitems = new myQuery('SELECT item_type, item_id, icon,
IF(item_type="exp", exp.name,
IF(item_type="quest", quest.name,
IF(item_type="set", sets.name, "Mystery Item"))) as name,
IF(item_type="exp", exp.status,
IF(item_type="quest", quest.status,
IF(item_type="set", sets.status, NULL))) as the_status,
IF(item_type="exp", exp.lower_age,
IF(item_type="quest", quest.lower_age,
IF(item_type="set", sets.lower_age, NULL))) as the_lower_age,
IF(item_type="exp", exp.upper_age,
IF(item_type="quest", quest.upper_age,
IF(item_type="set", sets.upper_age, NULL))) as the_upper_age
FROM project_items as p
LEFT JOIN exp ON (exp.id=item_id) AND item_type="exp" AND ' . implode(' AND ', $exclusions['exp']) . '
LEFT JOIN quest ON (quest.id=item_id) AND item_type="quest" AND ' . implode(' AND ', $exclusions['quest']) . '
LEFT JOIN sets ON (sets.id=item_id) AND item_type="set" AND ' . implode(' AND ', $exclusions['sets']) . '
WHERE p.project_id=' . $project['id'] . '
ORDER BY item_n');
*/
$myitems = new myQuery(
'SELECT item_type, item_id, icon,
IF(item_type="exp", exp.name,
IF(item_type="quest", quest.name,
IF(item_type="set", sets.name, "Mystery Item"))) as name,
IF(item_type="exp", exp.status,
IF(item_type="quest", quest.status,
IF(item_type="set", sets.status, NULL))) as the_status,
IF(item_type="exp", exp.sex,
IF(item_type="quest", quest.sex,
IF(item_type="set", sets.sex, NULL))) as the_sex,
IF(item_type="exp", exp.lower_age,
IF(item_type="quest", quest.lower_age,
IF(item_type="set", sets.lower_age, NULL))) as the_lower_age,
IF(item_type="exp", exp.upper_age,
IF(item_type="quest", quest.upper_age,
IF(item_type="set", sets.upper_age, NULL))) as the_upper_age
FROM project_items as p
LEFT JOIN exp ON (exp.id=item_id) AND item_type="exp"
LEFT JOIN quest ON (quest.id=item_id) AND item_type="quest"
LEFT JOIN sets ON (sets.id=item_id) AND item_type="set"
WHERE p.project_id=' . $project['id'] . '
ORDER BY item_n');
/*
echo $myitems->get_query();
*/
$items = $myitems->get_assoc();
} else {
# no project in GET
header('Location: /');
exit;
}
/****************************************************/
/* !Display Page */
/***************************************************/
$title = loc($project['name']);
$buttonwidth = count($items) * 11;
$styles = array(
'#fb-login' => 'display: none;',
'#logresguest' => 'max-width: 22em; margin: 1em auto;',
'#logres' => 'max-width: 22em; margin: 1em auto;',
'#guest' => 'max-width: 11em; margin: 1em auto;',
'.bigbuttons li a.registerbutton' => 'background-image: url(/images/linearicons/pencil?c=FFF);',
'.bigbuttons li a.loginbutton' => 'background-image: url(/images/linearicons/lock?c=FFF);',
'.bigbuttons li a.autobutton' => 'background-image: url(/images/linearicons/0676-ghost-hipster?c=FFF);',
'.bigbuttons li a.testbutton' => 'background-image: url(/images/linearicons/rocket.php?c=FFFFFF);',
'#itembuttons' => "margin: 1em auto; max-width: {$buttonwidth}em;"
);
$page = new page($title);
$page->set_menu(false);
$page->displayHead($styles);
$page->displayBody();
// warn if not eligible for any parts of the study
if (isset($_SESSION['status']) && in_array($_SESSION['status'], $ALL_STATUS)) {
$visitems = false;
foreach ($items as $i) { $visitems = $visitems || !empty($i['the_status']); }
if (!$visitems) {
echo "<h3 class='error'>You are not eligible for any items in this study.<br>
They might be restricted by age or gender.</h3>";
}
}
$Parsedown = new Parsedown();
echo $Parsedown->text($project['intro']);
if (array_key_exists("test", $_GET) && $_SESSION['status'] != 'test') {
# logs out a user and logs them in as test
?>
<script>
testLogin('<?= $projectname ?>');
</script>
<?php
} else if (!empty($_SESSION['status'])) {
$class = in_array($_SESSION['status'], $RES_STATUS) ? 'resuser' : '';
if ($_SESSION['status'] == 'test') { $class = ' testuser'; }
// participant is logged in
echo '<ul class="bigbuttons '.$class.'" id="itembuttons">';
$url = array(
'exp' => '/exp',
'quest' => '/quest',
'set' => '/include/scripts/set'
);
foreach ($items as $i) {
$hide = 'hide';
if ($i['the_status'] == 'active') { $hide = ''; }
if ($_SESSION['status'] == 'test' && $i['the_status'] == 'test') { $hide = ''; }
$age_sex = '';
if ($i['the_sex'] == 'male' && $_SESSION['sex'] == 'female') { $age_sex = 'restricted'; }
if ($i['the_sex'] == 'female' && $_SESSION['sex'] == 'male') { $age_sex = 'restricted'; }
if ($i['the_lower_age'] > 0 && $_SESSION['age'] < $i['the_lower_age']) { $age_sex = 'restricted'; }
if ($i['the_upper_age'] > 0 && $_SESSION['age'] > $i['the_upper_age']) { $age_sex = 'restricted'; }
printf('<li id="%s_%s" class="%s %s %s"><a class="%s" href="%s?id=%s" style="%s">%s</a></li>' . ENDLINE,
$i['item_type'],
$i['item_id'],
$i['the_status'],
$age_sex,
$hide,
$i['item_type'],
$url[$i['item_type']],
$i['item_id'],
(!empty($i['icon'])) ? "background-image: url({$i['icon']}?c=FFF)" : "",
ifEmpty($i['name'], $i['item_type'] . "_" . $i['item_id'] . "<span class='corner'>hidden</span>")
);
}
echo '</ul>';
if (!in_array($_SESSION['status'], array('guest', 'registered'))) {
echo "<h3>Your responses will not count towards research as a test user or researcher</h3>\n";
echo "<h4><ul>\n";
echo " <li>White borders indicate active sections</li>\n";
echo " <li>Yellow borders indicate test sections</li>\n";
if (in_array($_SESSION['status'], $RES_STATUS)) {
echo " <li>Blue borders indicate archived sections</li>\n";
echo " <li>Purple backgrounds indicate age- or gender-restricted sections.</li>\n";
}
echo "</ul></h4>\n";
}
// start project session id if not started
if (empty($_SESSION['session_id'])) {
$q = new myQuery();
$q->prepare("INSERT INTO session (project_id, user_id, dt) VALUES (?, ?, NOW())",
array('ii', $_SESSION['project_id'], $_SESSION['user_id']));
$_SESSION['session_id'] = $q->get_insert_id();
}
// insert credit id
if (array_key_exists('credit', $_GET)) {
$_SESSION['credit'] = $_GET['credit'];
$q = new myQuery();
$q->prepare("INSERT IGNORE INTO credit (credit, project_id) VALUES (?, ?)",
array('si', $_GET['credit'], $_SESSION['project_id']));
}
} else if (array_key_exists("auto", $_GET)) {
?>
<script>
guestLogin('<?= $projectname ?>');
</script>
<?php
} else if (array_key_exists("autond", $_GET)) {
?>
<script>
guestLoginNodemog('<?= $projectname ?>');
</script>
<?php
} else if (array_key_exists("guest", $_GET)) {
// participant should be auto-logged in
?>
<ul class="bigbuttons" id="guest">
<li><a class="autobutton" href="javascript: guestLogin('<?= $projectname ?>');">Login as a Guest</a></li>
</ul>
<?php
} else if (array_key_exists("all", $_GET)) {
?>
<ul class="bigbuttons" id="logresguest">
<li><a class="loginbutton" href="javascript: modalLogin('<?= $projectname ?>');">Login</a></li>
<li><a class="registerbutton" href="/consent">Register</a></li>
<li><a class="autobutton" href="javascript: guestLogin('<?= $projectname ?>');">Login as a Guest</a></li>
<li><a class="testbutton" href="javascript: testLogin('<?= $projectname ?>');">Test</a></li>
</ul>
<?php
} else {
// participant is not logged in yet
?>
<p>Please login or register if you do not yet have an account.</p>
<ul class="bigbuttons" id="logres">
<li><a class="loginbutton" href="javascript: modalLogin('<?= $projectname ?>');">Login</a></li>
<li><a class="registerbutton" href="/consent">Register</a></li>
</ul>
<?php
}
$page->displayFooter();
?>