-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
403 lines (383 loc) · 14.1 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
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
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
<html>
<head>
<meta name="viewport" content="width=300, initial-scale=1">
<style>
#canvas {
border: 1px solid gray;
}
body, html {
height: 100%;
display: grid;
}
.wrap {
/* center align */
text-align: center;
margin: auto;
/* Prevent nearby text being highlighted when accidentally dragging mouse outside confines of the canvas */
-webkit-touch-callout: none;
-webkit-user-select: none;
-khtml-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}
.left {
font-size: 120px;
line-height: 120px;
}
.left, .right {
margin: 10px;
}
.right button {
margin-top: 5px;
}
.divTable{
display: table;
width: 100%;
}
.divTableRow {
display: table-row;
}
.divTableHeading {
background-color: #EEE;
display: table-header-group;
}
.divTableCell, .divTableHead {
border: 1px dashed #999999;
display: table-cell;
padding: 3px 10px;
vertical-align: middle;
}
.divTableCell:first-child {
border-right-style: none;
}
.divTableHeading {
background-color: #EEE;
display: table-header-group;
font-weight: bold;
}
.divTableFoot {
background-color: #EEE;
display: table-footer-group;
font-weight: bold;
}
.divTableBody {
display: table-row-group;
}
.nextbutton .divTableCell {
text-align: right;
border: none;
padding-left: 0px;
padding-right: 0;
padding-top: 10px;
}
</style>
<script
src="https://code.jquery.com/jquery-3.3.1.min.js"
integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8="
crossorigin="anonymous"></script>
</head>
<body>
<?php
$tamil_html_unicodes = array("அ",
"ஆ",
"இ",
"ஈ",
"உ",
"ஊ",
"எ",
"ஏ",
"ஐ",
"ஒ",
"ஓ",
"ஃ",
"க",
"ங",
"ச",
"ஞ",
"ட",
"ண",
"த",
"ந",
"ப",
"ம",
"ய",
"ர",
"ல",
"வ",
"ழ",
"ள",
"ற",
"ன",
"ஸ",
"ஷ",
"ஜ",
"ஹ",
"க்ஷ",
"கி",
"ஙி",
"சி",
"ஞி",
"டி",
"ணி",
"தி",
"நி",
"பி",
"மி",
"யி",
"ரி",
"லி",
"வி",
"ழி",
"ளி",
"றி",
"னி",
"ஸி",
"ஷி",
"ஜி",
"ஹி",
"க்ஷி",
"கீ",
"ஙீ",
"சீ",
"ஞீ",
"டீ",
"ணீ",
"தீ",
"நீ",
"பீ",
"மீ",
"யீ",
"ரீ",
"லீ",
"வீ",
"ழீ",
"ளீ",
"றீ",
"னீ",
"ஸீ",
"ஷீ",
"ஜீ",
"ஹீ",
"க்ஷீ",
"கு",
"ஙு",
"சு",
"ஞு",
"டு",
"ணு",
"து",
"நு",
"பு",
"மு",
"யு",
"ரு",
"லு",
"வு",
"ழு",
"ளு",
"று",
"னு",
"கூ",
"ஙூ",
"சூ",
"ஞூ",
"டூ",
"ணூ",
"தூ",
"நூ",
"பூ",
"மூ",
"யூ",
"ரூ",
"லூ",
"வூ",
"ழூ",
"ளூ",
"றூ",
"னூ",
"ா",
"ெ",
"ே",
"ை",
"ஸ்ரீ",
"ஸு",
"ஷு",
"ஜு",
"ஹு",
"க்ஷு",
"ஸூ",
"ஷூ",
"ஜூ",
"ஹூ",
"க்ஷூ",
"க்",
"ங்",
"ச்",
"ஞ்",
"ட்",
"ண்",
"த்",
"ந்",
"ப்",
"ம்",
"ய்",
"ர்",
"ல்",
"வ்",
"ழ்",
"ள்",
"ற்",
"ன்",
"ஸ்",
"ஷ்",
"ஜ்",
"ஹ்",
"க்ஷ்",
"ஔ");
$total = sizeof($tamil_html_unicodes);
$id = 1;
if(is_numeric(@$_GET["id"]))
$id = $_GET["id"];
if( !((1 < $id) && ($id <= $total)) )
$id = 1;
?>
<div class="wrap">
<div class="divTable">
<div class="divTableBody">
<div class="divTableRow">
<div class="divTableCell"><div class="left"><?= $tamil_html_unicodes[$id-1] ?></div></div>
<div class="divTableCell"><div class="right" id="canvasDiv"><br/><button onclick="clearCanvas()">Clear</button></div></div>
</div>
<div class="divTableRow nextbutton">
<div class="divTableCell"><button onclick="previous()" style="float: left;">Previous</button> <?=$id."/".$total?></div>
<div class="divTableCell"><button onclick="next()">next</button></div>
</div>
</div>
</div>
</div>
<script type="text/javascript">
/* Canvas paint code start */
var canvasDiv = document.getElementById('canvasDiv');
var canvasWidth = 100;
var canvasHeight = 100;
canvas = document.createElement('canvas');
canvas.setAttribute('width', canvasWidth);
canvas.setAttribute('height', canvasHeight);
canvas.setAttribute('id', 'canvas');
canvasDiv.prepend(canvas);
if(typeof G_vmlCanvasManager != 'undefined') {
canvas = G_vmlCanvasManager.initElement(canvas);
}
context = canvas.getContext("2d");
// Simple canvas drawing
$('#canvas').mousedown(function(e) {
var mouseX = e.pageX - this.offsetLeft;
var mouseY = e.pageY - this.offsetTop;
paint = true;
addClick(e.pageX - this.offsetLeft, e.pageY - this.offsetTop);
redraw();
});
$('#canvas').mousemove(function(e) {
if(paint){
addClick(e.pageX - this.offsetLeft, e.pageY - this.offsetTop, true);
redraw();
}
});
$('#canvas').mouseup(function(e) {
paint = false;
});
$('#canvas').mouseleave(function(e) {
paint = false;
});
var clickX = new Array();
var clickY = new Array();
var clickDrag = new Array();
var paint;
var hasPainted = false;
function addClick(x, y, dragging) {
clickX.push(x);
clickY.push(y);
clickDrag.push(dragging);
}
function redraw() {
context.clearRect(0, 0, context.canvas.width, context.canvas.height); // Clears the canvas
hasPainted = true;
context.strokeStyle = "#000";
context.lineJoin = "round";
context.lineWidth = 2;
for(var i=0; i < clickX.length; i++) {
context.beginPath();
if(clickDrag[i] && i){
context.moveTo(clickX[i-1], clickY[i-1]);
}else{
context.moveTo(clickX[i]-1, clickY[i]);
}
context.lineTo(clickX[i], clickY[i]);
context.closePath();
context.stroke();
}
}
// Clear the canvas context using the canvas width and height
function clearCanvas() {
hasPainted = false;
clickX = new Array();
clickY = new Array();
clickDrag = new Array();
context.clearRect(0, 0, canvas.width, canvas.height);
}
// Add touch event listeners to canvas element
canvas.addEventListener("touchstart", function(e)
{
// Mouse down location
var mouseX = (e.changedTouches ? e.changedTouches[0].pageX : e.pageX) - this.offsetLeft,
mouseY = (e.changedTouches ? e.changedTouches[0].pageY : e.pageY) - this.offsetTop;
paint = true;
addClick(mouseX, mouseY, false);
redraw();
}, false);
canvas.addEventListener("touchmove", function(e){
var mouseX = (e.changedTouches ? e.changedTouches[0].pageX : e.pageX) - this.offsetLeft,
mouseY = (e.changedTouches ? e.changedTouches[0].pageY : e.pageY) - this.offsetTop;
if(paint){
addClick(mouseX, mouseY, true);
redraw();
}
e.preventDefault()
}, false);
canvas.addEventListener("touchend", function(e){
paint = false;
redraw();
}, false);
canvas.addEventListener("touchcancel", function(e){
paint = false;
}, false);
/* Canvas paint code end */
// Save the picture
function next() {
if(hasPainted) {
var photo = canvas.toDataURL('image/png');
$.ajax({
method: 'POST',
url: 'save.php',
data: {
photo: photo,
id: <?= $id ?>
},
statusCode: {
200: function() {
window.location.href = "<?=$_SERVER["PHP_SELF"]."?id=".($id == $total? 1:($id+1))?>";
}
}
});
}
else {
window.location.href = "<?=$_SERVER["PHP_SELF"]."?id=".($id == $total? 1:($id+1))?>";
}
}
function previous() {
window.location.href = "<?=$_SERVER["PHP_SELF"]."?id=".($id == 1? $total:($id-1))?>";
}
</script>
</body>
</html>