-
Notifications
You must be signed in to change notification settings - Fork 0
/
evaluationInfo.php
109 lines (97 loc) · 3.02 KB
/
evaluationInfo.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
<?php
$type = $_GET["type"];
$date = $_GET["date"];
$filename = $_GET["filename"];
$fn_arr = explode("_", $filename);
// $date = $fn_arr[0];
$evaluator_id = $fn_arr[0];
$group_id = $fn_arr[1];
if ($type == "student") {
$student_id = $fn_arr[2];
}
// var_dump($date, $evaluator_id, $formid);
// $datenum = strtotime($date);
// print($datenum);
$template_file = "json/templates.json";
if (file_exists($template_file)) {
$json_template = file_get_contents($template_file);
$decoded_template = json_decode($json_template, true);
// var_dump($template);
} else {
echo "Template file doesn't exist";
exit;
}
if ($type == "student") { /* Student Evaluation */
$form_url = "studentResponses/$filename.json";
$template = $decoded_template["Student Evaluation"];
} else { /* Group Evaluation */
$form_url = "groupResponses/$filename.json";
$template = $decoded_template["Group Evaluation"];
}
if (!isset($_POST["data"])) { /* GET request */
// if ($type == "student") {
// $fn_pattern = "studentResponses/*_$evaluator_id\_$formid.json";
// } else {
// $fn_pattern = "groupResponses/*_$evaluator_id\_$formid.json";
// }
// // compare datetime of all existing form responses, return most recent response
// $matched_files = glob($fn_pattern);
// if (sizeof($matched_files) == 0) {
// print_r(json_encode($template));
// } else {
// rsort($matched_files); // most recent response should now be in index 0
// $data = file_get_contents($matched_files[0]);
// $decoded_data = json_decode($data, true);
// if ($type == "student") {
// $form_data = $decoded_data["Student Evaluation"];
// } else {
// $form_data = $decoded_data["Group Evaluation"];
// }
// print(json_encode($form_data));
// }
if (file_exists($form_url)) {
$data = file_get_contents($form_url);
$decoded_data = json_decode($data, true);
if ($type == "student") {
$form_data = $decoded_data["Student Evaluation"];
} else {
$form_data = $decoded_data["Group Evaluation"];
}
print_r(json_encode($form_data));
} else {
print_r(json_encode($template));
}
} else { /* POST request */
$data = $_POST["data"];
$form_details = $data["Details"];
$form_data = $data["Response Data"];
// var_dump($data, $form_details, $form_data);
foreach ($form_data as $key => $value) {
$template[$key]["Value"] = $value;
}
// print_r(json_encode($template));
if ($type == "student") {
$data = array(
"Details" => array(
"Date" => $date,
"Evaluated By" => $evaluator_id,
"Student Name" => str_replace('_', ' ', $form_details["Student Name"]),
"Student NetID" => $student_id,
"Group" => $group_id
),
"Student Evaluation" => $template
);
} else {
$data = array(
"Details" => array(
"Date" => $date,
"Evaluated By" => $evaluator_id,
"Group" => $group_id
),
"Group Evaluation" => $template
);
}
print_r(json_encode($data));
file_put_contents($form_url, json_encode($data));
}
?>