-
Notifications
You must be signed in to change notification settings - Fork 33
/
draw.php
executable file
·83 lines (72 loc) · 1.97 KB
/
draw.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
<?php
require_once 'global.php';
require_once 'validate.php';
$x = intval($_REQUEST['x']);
$y = intval($_REQUEST['y']);
if ($_REQUEST['submit']) {
$data = $_POST['data'];
# Validate data
list($data, $success) = validateData($x, $y, $data);
# list($data, $success) = array($data, 1);
if (!$success) {
print "<script>$data</script>";
return;
}
# Save to file.
$key = "$x,$y";
$filename = "tmp/" . $key . '-' . rand()%100;
file_put_contents($filename, json_encode($data));
# Send to firestore.
$result = trim(shell_exec("python save.py '$x' '$y' '$filename' 2>&1"));
if ($result != 1) {
die("Error saving. $result<HR>");
}
print "<script>window.location = 'index.php';</script>";
return;
}
print <<<EOF
<!doctype html>
<html>
<style>
body {
margin: 30px;
font-family: Arial, Helvetica, sans-serif;
background-color: #f0f0f0;
}
#mycanvas {
margin-top: 8px;
border: 1px #000 solid;
background-color: #fff;
}
</style>
<body>
<script>
let DIMENSION = $DIMENSION;
</script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<link rel="stylesheet" href="pickr/dist/themes/classic.min.css" />
<!-- 'classic' theme -->
<script src="pickr/dist/pickr.min.js"></script>
<script src="draw.js?version=$VERSION"></script>
<body>
<input onclick="window.location='index.php'" value="Back" type=button>
<BR>
<BR>
<table>
<tr>
<Td>
<div id=picker></div>
</td>
<td>
<input type=button value="Choose Color" onclick="PICKR.show()" />
</td>
</tr>
</table>
<div>
<canvas id=mycanvas width=500 height=500></canvas>
</div>
<input id=saveButton type=submit value=Save onclick="save($x, $y)">
<div id=spinner></div>
</body>
</html>
EOF;