-
Notifications
You must be signed in to change notification settings - Fork 0
/
save.php
75 lines (54 loc) · 1.88 KB
/
save.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
<?php require_once 'php/db.php' ?>
<?php
if (!isset($_POST['location'])) {
echo '{"error": "Unknown save location. Please try again."}';
die();
}
if (!isset($_POST['u']) || !isset($_POST['id'])) {
echo '{ "error": "Invalid user information. Please try again." }';
die();
}
if (!isset($_POST['shared']) || !$_POST['shared']) {
$now = gmdate("Y-m-d H:i:s");
$status = ($_POST['location'] == 'db') ? 'remote' : 'local';
$evaluation = '';
$db = new SMART_DB();
if (!$db->connect()) {
echo '{ "error": "Save functionality is currently unavailable. Please try again." }';
die();
}
if (!$db->prepare("UPDATE evaluations SET modified = ?, status = ?, evaluation = ? WHERE username = ? AND id = ?")) {
echo '{ "error": "Failed to save evaluation. Please try again." }';
die();
}
if ($_POST['location'] == 'db') {
if (!isset($_POST['evaluation'])) {
echo '{ "error": "Invalid evaluation. Please try again." }';
die();
}
$evaluation = $_POST['evaluation'];
}
if (!$db->bind_param("ssssi", array($now, $status, $evaluation, $_POST['u'], $_POST['id']))) {
echo '{ "error": "An error occurred while preparing to save evaluation. Please try again." }';
die();
}
if (!$db->execute()) {
echo '{ "error": "An error occurred saving the evaluation. Please try again." }';
die();
}
$db->close();
}
if ($_POST['location'] == 'db') {
echo '{ "status": "Evaluation successfully saved." }';
}
else {
$title = $_POST['t'] ? $_POST['t'] : 'ace-smart-evaluation';
$dateTime = new DateTime();
$title .= '-' . $dateTime->format('Ymd') . '.json';
header('Content-Disposition: attachment; filename="' . $title . '"');
header('Content-Type: application/json');
# header('Content-Length: ' . strlen($_POST['evaluation']));
header('Connection: close');
echo $_POST['evaluation'];
}
?>