-
Notifications
You must be signed in to change notification settings - Fork 0
/
form.php
318 lines (259 loc) · 11.4 KB
/
form.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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="viewport" content="width=device-width,initial scale=1">
<link rel="stylesheet" href="http://www.w3schools.com/lib/w3.css">
<title>Add Team</title>
<!-- Favicon -->
<link rel="shortcut icon" href="./img/svg/logo.svg" type="image/x-icon">
<!-- Custom styles -->
<link rel="stylesheet" href="./css/style.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css" integrity="sha512-9usAa10IRO0HhonpyAIVpjrylPvoDwiPUiKdWk5t3PyolY1cOd4DSE0Ga+ri4AuTroPR5aQvXU9xC6qOPnzFeg==" crossorigin="anonymous" referrerpolicy="no-referrer" />
<style type="text/css">
.swal2-container.swal2-center>.swal2-popup {
background:black;
}
</style>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css" integrity="sha512-9usAa10IRO0HhonpyAIVpjrylPvoDwiPUiKdWk5t3PyolY1cOd4DSE0Ga+ri4AuTroPR5aQvXU9xC6qOPnzFeg==" crossorigin="anonymous" referrerpolicy="no-referrer" />
<script>
/**
* sends a request to the specified url from a form. this will change the window location.
* @param {string} path the path to send the post request to
* @param {object} params the parameters to add to the url
* @param {string} [method=post] the method to use on the form
*/
var currentcolor = 'blue';
function post(path, params, method='post') {
// The rest of this code assumes you are not using a library.
// It can be made less verbose if you use one.
const form = document.createElement('form');
form.method = method;
form.action = path;
for (const key in params) {
if (params.hasOwnProperty(key)) {
const hiddenField = document.createElement('input');
hiddenField.type = 'hidden';
hiddenField.name = key;
hiddenField.value = params[key];
form.appendChild(hiddenField);
}
}
document.body.appendChild(form);
form.submit();
}
// Variables for referencing the canvas and 2dcanvas context
var canvas,ctx;
// Variables to keep track of the mouse position and left-button status
var mouseX,mouseY,mouseDown=0;
// Variables to keep track of the touch position
var touchX,touchY;
// Draws a dot at a specific position on the supplied canvas name
// Parameters are: A canvas context, the x position, the y position, the size of the dot
function drawDot(ctx,x,y,size) {
// Let's use black by setting RGB values to 0, and 255 alpha (completely opaque)
r=0; g=0; b=255; a=255;
// Select a fill style
if (currentcolor == 'red'){
ctx.fillStyle = "rgba("+255+","+0+","+0+","+(a/255)+")";
}else{
ctx.fillStyle = "rgba("+r+","+g+","+b+","+(a/255)+")";
}
// Draw a filled circle
ctx.beginPath();
ctx.arc(x, y, size, 0, Math.PI*2, true);
ctx.closePath();
ctx.fill();
}
// Clear the canvas context using the canvas width and height
function clearCanvas(canvas,ctx) {
ctx.clearRect(0, 0, canvas.width, canvas.height);
}
// Keep track of the mouse button being pressed and draw a dot at current location
function sketchpad_mouseDown() {
mouseDown=1;
drawDot(ctx,mouseX,mouseY,4);
}
// Keep track of the mouse button being released
function sketchpad_mouseUp() {
mouseDown=0;
}
// Keep track of the mouse position and draw a dot if mouse button is currently pressed
function sketchpad_mouseMove(e) {
// Update the mouse co-ordinates when moved
getMousePos(e);
// Draw a dot if the mouse button is currently being pressed
if (mouseDown==1) {
drawDot(ctx,mouseX,mouseY,4);
}
}
// Get the current mouse position relative to the top-left of the canvas
function getMousePos(e) {
if (!e)
var e = event;
if (e.offsetX) {
mouseX = e.offsetX;
mouseY = e.offsetY;
}
else if (e.layerX) {
mouseX = e.layerX;
mouseY = e.layerY;
}
}
// Draw something when a touch start is detected
function sketchpad_touchStart() {
// Update the touch co-ordinates
getTouchPos();
drawDot(ctx,touchX,touchY,4);
// Prevents an additional mousedown event being triggered
event.preventDefault();
}
// Draw something and prevent the default scrolling when touch movement is detected
function sketchpad_touchMove(e) {
// Update the touch co-ordinates
getTouchPos(e);
// During a touchmove event, unlike a mousemove event, we don't need to check if the touch is engaged, since there will always be contact with the screen by definition.
drawDot(ctx,touchX,touchY,4);
// Prevent a scrolling action as a result of this touchmove triggering.
event.preventDefault();
}
// Get the touch position relative to the top-left of the canvas
// When we get the raw values of pageX and pageY below, they take into account the scrolling on the page
// but not the position relative to our target div. We'll adjust them using "target.offsetLeft" and
// "target.offsetTop" to get the correct values in relation to the top left of the canvas.
function getTouchPos(e) {
if (!e)
var e = event;
if(e.touches) {
if (e.touches.length == 1) { // Only deal with one finger
var touch = e.touches[0]; // Get the information for finger #1
touchX=touch.pageX-touch.target.offsetLeft;
touchY=touch.pageY-touch.target.offsetTop;
}
}
}
// Set-up the canvas and add our event handlers after the page has loaded
function init() {
// Get the specific canvas element from the HTML document
canvas = document.getElementById('sketchpad');
// If the browser supports the canvas tag, get the 2d drawing context for this canvas
if (canvas.getContext)
ctx = canvas.getContext('2d');
// Check that we have a valid context to draw on/with before adding event handlers
if (ctx) {
// React to mouse events on the canvas, and mouseup on the entire document
canvas.addEventListener('mousedown', sketchpad_mouseDown, false);
canvas.addEventListener('mousemove', sketchpad_mouseMove, false);
window.addEventListener('mouseup', sketchpad_mouseUp, false);
// React to touch events on the canvas
canvas.addEventListener('touchstart', sketchpad_touchStart, false);
canvas.addEventListener('touchmove', sketchpad_touchMove, false);
}
}
function SetColor(color){
if (color == 'red'){
currentcolor = 'red';
}else{
currentcolor = 'blue';
}
}
</script>
</head>
<body onload="init()">
<style type="text/css">.swal2-title {
position: relative;
max-width: 100%;
margin: 0;
padding: 0.8em 1em 0;
color: white;
font-size: 1.875em;
font-weight: 600;
text-align: center;
text-transform: none;
word-wrap: break-word;
}
</style>
<div class="layer"></div>
<main style="width: fit-content;margin:auto;" class="page-center">
<article class="sign-up">
<form class="sign-up-form form" action="" id="scform" method="POST" style="margin-top: 3%;" class="col-sm-10 col-md-4 col-lg-2">
<input type="hidden" name="imagerawdata" id="imagerawdata" value="">
<input type="hidden" name="autototal" id="autototal" value="0">
<input type="hidden" name="teletotal" id="teletotal" value="0">
<input type="hidden" name="chargingstationstatus" id="chargingstationstatus" value="0">
<input type="hidden" name="notes" id="notes" value="">
<input type="hidden" name="teamid" id="teamid" value="">
<input type="hidden" name="matchid" id="matchid" value="">
<input type="hidden" name="penalties" id="penalties" value="">
<input type="hidden" name="hangarcheckbox" id="hangarcheckbox" value="0">
<input type="hidden" name="ballcheckbox" id="ballcheckbox" value="0">
<input type="hidden" name="defanscheckbox" id="defanscheckbox" value="0">
<div id="sketchpadapp">
<div class="leftside">
<input type="button" value="Clear" id="clearbutton" onclick="clearCanvas(canvas,ctx);">
<input onclick="save()" type="button" value="Kaydet" name="Save">
<input type="button" onclick="SetColor('red')" name="" value="Red">
<input type="button" onclick="SetColor('blue')" name="" value="Blue">
<div class="rightside">
<canvas id="sketchpad" height="426" width="604" style="background-image: url('field.png'); background-size: 604px 426px; margin-top: 20px; margin-bottom: 20px; border: 5px solid #eee;">
</canvas>
</div>
</div>
</div>
<input type="button" name="" value="Gönder" onclick="PostToMainPage()" class="form-btn primary-default-btn transparent-btn">
</form>
</article>
</main>
<!-- Chart library -->
<script src="./plugins/chart.min.js"></script>
<!-- Icons library -->
<script src="plugins/feather.min.js"></script>
<!-- Custom scripts -->
<script src="js/script.js"></script>
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>
<script type="text/javascript">
<?php
if($_POST){
echo 'document.getElementById("autototal").value = '. $_POST["autototal"].';
';
echo 'document.getElementById("teletotal").value = '. $_POST["teletotal"].';
';
echo 'document.getElementById("chargingstationstatus").value = '. $_POST["chargingstationstatus"].';
';
if($_POST["teamid"] == ""){
echo 'document.getElementById("teamid").value = 0;
';
}else{
echo 'document.getElementById("teamid").value = '.$_POST["teamid"].';
';
}
echo 'document.getElementById("notes").value = "'. $_POST["notes"].'";
';
echo 'document.getElementById("defanscheckbox").value = "'. $_POST["defanscheckbox"].'";
';
echo 'document.getElementById("ballcheckbox").value = "'. $_POST["ballcheckbox"].'";
';
echo 'document.getElementById("hangarcheckbox").value = "'. $_POST["hangarcheckbox"].'";
';
echo 'document.getElementById("matchid").value = "'.$_POST["matchid"].'";
';
echo 'document.getElementById("penalties").value = "'.$_POST["penalties"].'";
';
}
?>
function PostToMainPage(){
document.getElementById("sketchpad").style.border = "2px solid";
var dataURL = canvas.toDataURL();
console.log(dataURL);
document.getElementById("imagerawdata").value = dataURL;
document.getElementById("scform").action = "Rapor.php";
document.getElementById("scform").submit();
}
function save() {
PostToMainPage();
}
</script>
</body>
</html>