-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathindex.php
More file actions
241 lines (217 loc) · 8.4 KB
/
Copy pathindex.php
File metadata and controls
241 lines (217 loc) · 8.4 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
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
<?php
/*
* The MIT License (MIT)
*
* Copyright (c) 2014 Internet-Based User Experience Lab, HCDE, University at Washington
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
require __DIR__.'/vendor/autoload.php';
require __DIR__.'/src/Models/Study.php';
require __DIR__.'/src/Controllers/StudiesGet.php';
require __DIR__.'/src/Models/Session.php';
require __DIR__.'/src/Controllers/SessionsGet.php';
/*
* Within WebLabUX, every user-facing page (for the researcher) is rendered using Twig templates.
* The UI loop for researcher-facing WebLabUX is contained within this index.php file, and specific
* are selected.
*/
/* create a Symfony Request, used only to help make each URL render a different Twig template */
/* See more at API reference documentation: http://api.symfony.com/2.4/index.html */
use Symfony\Component\HttpFoundation\Request;
$request = Request::createFromGlobals();
$uri = $request->getPathInfo();
/*
* If we decide to define a restful style set of UI<->controller mappings, we would want
* to come up with the routing convensions (rails convension is now the most common), and
* explode the $uri to grab the the verbs and nouns within the path. This would require
* fleshing out the routing branch-case statement or writing controller functions...
*
* $uriarray = explode('/', $uri);
* $uripath = "/" . $uriarray[1];
* ...etc for getting the rest of the pieces of the request within the path...
*/
/* bootstrap Twig templating system */
$loader = new Twig_Loader_Filesystem(__DIR__.'/templates');
$twig = new Twig_Environment($loader, array(
'cache' => false, // !! for development only
'debug' => true, // !! for development only
'strict_variables' => true
));
$twig->addExtension(new Twig_Extension_Debug());
/*
* THIS FAST AND DIRTY DEBUG SWITCH EXISTS ONLY UNTIL WE HAVE AUTHENTICATION FOR USER LOGIN.
* HARD CODE THIS SWITCH APPROPRIATELY FOR YOUR NEEDS. ALTERNATIVELY, EXTEND OR REPLACE AS YOU
* WISH TO SERVE YOUR TEAM'S NEEDED WHILE DEVELOPING.
*
* THIS WILL NEED TO BE RIPPED OUT AND REPLACED WITH WHATEVER MECHANISM WE ARE USING FOR AUTH...
*/
//$loggedin = true;
$loggedin = false;
if(isset($_COOKIE['weblabuxToken'])) {
$loggedin = true;
}
/*
* MAIN UI BRANCH & SWITCH
*/
if ($loggedin) { // Render dynamic pages for research who is logged into WebLabUX
// Pass any necessary data to the template -OR- have the switch's case
// statement call a function that acts as a controller for the page.
switch ($uri) {
case '/':
case '/allstudies':
echo $twig->render('dynamicpages/allstudies.twig', array(
'pageData' => array(
'title' => 'WebLabUX - All Studies',
),
'studies' => studiesGetAll(),
'sessions' => sessionsGetAll(),
));
break;
case '/general':
echo $twig->render('dynamicpages/general.twig', array(
'pageData' => array(
'title' => 'WebLabUX - General Study',
'submit_text' => 'Continue',
),
));
break;
case '/general':
echo $twig->render('dynamicpages/general.twig', array(
'pageData' => array(
'title' => 'WebLabUX - General Study',
'submit_text' => 'Continue',
),
));
break;
case '/scheduling':
echo $twig->render('dynamicpages/scheduling.twig', array(
'pageData' => array(
'title' => 'WebLabUX - Scheduling',
'submit_text' => 'Continue',
),
));
break;
case '/createstudy':
echo $twig->render('dynamicpages/newstudy.twig', array(
'pageData' => array(
'title' => 'WebLabUX - Create Study',
'submit_text' => 'Continue',
),
));
break;
case '/protocol':
echo $twig->render('dynamicpages/protocol.twig', array(
'pageData' => array(
'title' => 'WebLabUX - Create Study',
'submit_text' => 'Continue',
),
));
break;
case '/variables':
echo $twig->render('dynamicpages/variables.twig', array(
'pageData' => array(
'title' => 'WebLabUX - Create Study',
'submit_text' => 'Continue',
),
));
break;
case '/createstudy-session':
echo $twig->render('dynamicpages/session.twig', array(
'pageData' => array(
'title' => 'WebLabUX - Create Study',
'submit_text' => 'Submit',
),
));
break;
case '/tutorial':
echo $twig->render('dynamicpages/tutorial.twig', array(
'pageData' => array(
'title' => 'WebLabUX Tutorial',
'submit_text' => 'Submit',
),
));
break;
// Bad dynamic page URI - or unimplimented feature!
// This is fast placeholder -- this really needs to be made far more robust!
default:
echo $twig->render('dynamicpages/notfound.twig', array(
'pageData' => array(
'title' => 'Feature not yet implemented: ' . $uri,
),
));
}
}
else { // Render static pages for someone who is not logged into WebLabUX
// Right now the code is only passing a title to the template but
// other variables could be constructed and passed in.
switch ($uri) {
case '/':
echo $twig->render('staticpages/homepage.twig', array(
'pageData' => array(
'title' => 'WebLabUX',
),
));
break;
case '/about':
echo $twig->render('staticpages/about.twig', array(
'pageData' => array(
'title' => 'About WebLabUX',
),
));
break;
case '/howitworks':
echo $twig->render('staticpages/howitworks.twig', array(
'pageData' => array(
'title' => 'How WebLabUX Works',
),
));
break;
case '/tutorials':
echo $twig->render('staticpages/tutorials.twig', array(
'pageData' => array(
'title' => 'WebLabUX Tutorial',
),
));
break;
case '/error':
echo $twig->render('staticpages/error.twig', array(
'pageData' => array(
'title' => 'WebLabUX',
),
));
break;
case '/loginerror':
echo $twig->render('staticpages/loginerror.twig', array(
'pageData' => array(
'title' => 'WebLabUX',
),
));
break;
// Bad static page URI - treat this as if a 404
// This is fast placeholder -- this really needs to be made far more robust!
default:
echo $twig->render('staticpages/notfound.twig', array(
'pageData' => array(
'title' => 'Page not found = ' . $uri,
),
));
}
}
?>