-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.php
executable file
·156 lines (141 loc) · 4.5 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
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
<?
require_once 'slcapiwrapper.php';
$api = new slcAPIWrapper();
$apiCalls = array('student', 'students', 'sections', 'attendances', 'courses', 'reportCards', 'teacher', 'parents', 'studentAssessments');
function json_format($json) {
$tab = " ";
$new_json = "";
$indent_level = 0;
$in_string = false;
$json_obj = json_decode($json);
if ($json_obj === false)
return false;
$json = json_encode($json_obj);
$len = strlen($json);
for ($c = 0; $c < $len; $c++) {
$char = $json[$c];
if ($char == '\\' && $c + 1 < $len && $json[$c + 1] != '\\')
$char = '';
switch ($char) {
case '{':
case '[':
if (!$in_string) {
$new_json .= $char . "\n" . str_repeat($tab, $indent_level + 1);
$indent_level++;
}
else {
$new_json .= $char;
}
break;
case '}':
case ']':
if (!$in_string) {
$indent_level--;
$new_json .= "\n" . str_repeat($tab, $indent_level) . $char;
}
else {
$new_json .= $char;
}
break;
case ',':
if (!$in_string) {
$new_json .= ",\n" . str_repeat($tab, $indent_level);
}
else {
$new_json .= $char;
}
break;
case ':':
if (!$in_string) {
$new_json .= ": ";
}
else {
$new_json .= $char;
}
break;
case '"':
if ($c > 0 && $json[$c - 1] != '\\') {
$in_string = !$in_string;
}
default:
$new_json .= $char;
break;
}
}
return $new_json;
}
?>
<html>
<head>
<script src="codemirror/lib/codemirror.js"></script>
<link rel="stylesheet" href="codemirror/lib/codemirror.css">
<script src="codemirror/mode/javascript/javascript.js"></script>
<style type="text/css">
.CodeMirror-scroll { height: 600px; }
.CodeMirror {border-top: 1px solid black; border-bottom: 1px solid black;}
</style>
</head>
<body style='font-family: verdana, serif;'>
<div style='padding: 1%; width: 60%; margin: 0; border: 2px solid #999;'>
<div style='text-align: center; font-size: 1.1em; font-weight: bold'>SLC API Test Page</div>
<form action='' method='post' style='width: 200px; margin: 0 auto;'>
<select name='apiCall'>
<option value=''>Select API Call...</option>
<? foreach ($apiCalls as $call) {
?><option <? if (isset($_POST['apiCall']) && $call == $_POST['apiCall']) { ?>selected='selected'<? } ?> value='<?= $call ?>'>
<?= $call ?>
</option> <? }
$uuid = $_POST['uuid'];
?>
</select>
<span style="font-size:75%">UUID:</span> <input type="text" size="60" name="uuid" value="<?= $uuid ?>" />
<br /><br />
<button style='width: 100px;' type='submit'>Make API Call</button>
</form>
</div>
<? if (isset($_POST['apiCall']) && $_POST['apiCall']) { ?>
<div>
<h3>API Response:</h3>
<textarea id="codeEditor" rows="80" cols="120" wrap="off" style="height:500px; border: solid black" >
<?
switch ($_POST['apiCall']) {
case 'student':
$result = $api->getStudent($uuid);
break;
case 'students':
$result = $api->getAllStudents();
break;
case 'sections':
$result = $api->getAllSections();
break;
case 'attendances':
$result = $api->getAttendances($uuid);
break;
case 'courses':
$result = $api->getAllCourses();
break;
case 'reportCards':
$result = $api->getAllReportCards();
break;
case 'teacher':
$result = $api->getTeacher($uuid);
break;
case 'parents':
$result = $api->getParents();
break;
case 'studentAssessments':
$result = $api->getAllStudentAssessments();
break;
}
echo json_format(json_encode($result));
?></textarea></div><?
;
}
?>
<script>
var editor = CodeMirror.fromTextArea(document.getElementById("codeEditor"), {
lineNumbers: true
});
</script>
</body>
</html>