-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.php
58 lines (51 loc) · 1.52 KB
/
index.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
<?php
require "vendor/autoload.php";
require "functions.php";
$app = new \Slim\Slim();
$app->get('/results/form/:form/:questions(/)', function ($form, $questions) {
$questionsArrs = processReqString($questions);
if(questionIdsExist($questionsArrs, $form)) {
if(hasArray($questionsArrs)) {
$resultsArr = array();
foreach($questionsArrs as $qArr) {
if(is_array($qArr)) {
//Related questions query
$sql = buildRelatedSqlQuery($qArr, $form);
$resultArr = getRelatedJsonArray($sql);
}
else {
//Single question query
$sql = buldSqlQuery(array ($qArr), $form);
$resultArr = getJsonArray($sql);
}
$resultsArr["answers"][] = $resultArr["answers"];
}
$json = json_encode($resultsArr);
echo $json;
}
else {
$sql = buldSqlQuery($questionsArrs, $form);
$resultArr = getJsonArray($sql);
$resultsArr["answers"][] = $resultArr["answers"];
$json = json_encode($resultsArr);
echo $json;
}
}
else echo "ERROR: Wrong FormID or QuestionID";
});
$app->get('/results/form/:form/:questions/graphs(/)', function ($form, $questions) {
$url = 'html/graphs.html';
$html = ' <!doctype html>
<html><head>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script type="text/javascript">
var form = "' . $form . '";
var questions = "' . $questions . '";
</script>
';
$html .= file_get_contents($url);
echo $html;
});
$app->run();
?>