-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy patherrors_output.php
547 lines (492 loc) · 16.9 KB
/
errors_output.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
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
<html>
<head>
<link href="css/mtequal.css" rel="styleSheet" type="text/css">
<script type="text/javascript" src="js/jquery-1.9.1.min.js"></script>
<script type="text/javascript" src="js/mtequal.js"></script>
<?php
header("Content-type: text/html; charset=utf-8");
include("config.php");
include("functions.php");
if (!isset($userid)) {
$userid = $mysession['userid'];
}
if (!isset($taskid)) {
$taskid = $mysession["taskid"];
}
if (isset($monitoring) && $monitoring == 1) {
$sentidx=-1;
} else {
$monitoring=0;
}
?>
<script type="text/javascript">
/* Default value of choice */
var selectionFrom = 0;
var selectionTo = 1;
function getColor (idx) {
return "#ccc";
}
function goto(el,interval) {
var leftEl = document.getElementById("LeftPane");
var tokenEl = document.getElementById(el+"."+interval);
if (leftEl != null && tokenEl != null) {
if (tokenEl.offsetTop > 100) {
leftEl.scrollTop = tokenEl.offsetTop-100;
} else {
leftEl.scrollTop = 0;
}
}
}
function showRange(el,sentid,range) {
el.style.borderBottom = "solid #000 2px";
el.style.cursor = "nw-resize";
var ids = range.split(" ");
for (var i in ids) {
var el = document.getElementById(sentid+"."+ids[i]);
if (el != null) {
if (el.style.backgroundColor == COLOR) {
el.style.borderTop = "2px solid "+COLOR;
}
el.style.backgroundColor = "#bbb";
}
}
}
function hideRange(el,sentid,range) {
el.style.borderBottom = "none";
el.style.cursor = "default";
var ids = range.split(" ");
for (var i in ids) {
var el = document.getElementById(sentid+"."+ids[i]);
if (el != null) {
if (el.style.borderTop == "2px solid "+COLOR) {
el.style.backgroundColor = COLOR;
el.style.borderTop = "none";
} else {
el.style.backgroundColor = WHITE;
}
}
}
}
function removeAnnotation(id,targetid,ranges,errid) {
//alert(id+","+ranges);
if (confirm("Do you really want to cancel this annotation?")) {
$.ajax({
url: 'update.php',
type: 'GET',
data: "id="+id+"&targetid="+targetid+"&taskid=<?php echo $taskid;?>&userid=<?php echo $userid;?>&check="+errid+"&action=remove&tokenids="+ranges,
async: false,
cache:false,
crossDomain: true,
success: function(response) {
$("#output"+targetid).html(response);
$.ajax({
url: 'errors_type.php',
type: 'GET',
data: "id=<?php echo $id;?>&targetid="+targetid+"&userid=<?php echo $userid;?>",
async: false,
cache:false,
crossDomain: true,
success: function(response) {
$("#errors"+targetid).html(response);
}
});
},
error: function(response, xhr,err ) {
//alert(err+"\nreadyState: "+xhr.readyState+"\nstatus: "+xhr.status+"\nresponseText: "+xhr.responseText);
switch(xhr.status) {
case 200:
alert("Sorry! Data has not been saved!");
}
}
});
//window.open("errors_output.php?id="+id+"&sentidx=<?php echo $sentidx; ?>","_self");
}
}
$(document).ready(function() {
try {
$(document).bind("contextmenu", function(e) {
e.preventDefault();
/*if (OUTPUTID != null && isSelected(OUTPUTID) == 1) {
$("#errortypes").css({ top: (e.pageY-2) + "px", left: (e.pageX-20) + "px" }).show(100);
} else {
$("#noselection").css({top: (e.pageY-2) + "px", left: (e.pageX-20) + "px" }).show(100);
var el = document.getElementById("noselection");
el.style.visibility = "visible";
}*/
});
$(document).mouseup(function(e) {
var container = $("#errortypes");
if (container.has(e.target).length == 0) {
container.hide();
//container.show();
//hideErrorMenu();
//alert(container.has(e.target).length);
}
//showErrorMenu();
});
} catch (err) {
alert(err);
}
});
</script>
</head>
<body>
<div id="errortypes" onclick="this.style.visibility='hidden';" style="font-size: 10px">
<table width=200 border=0 cellspacing=0 cellpadding=2 style='background-color: #ddd; color: #000; font-size: 16px; box-shadow: 3px 3px 3px #888; '>
<?php
$ranges = $mysession["taskranges"];
while (list ($val,$attrs) = each($ranges)) {
if ($val > 1) {
print "<tr><td onclick=\"javascript:saveAnnotationRanges($val);\" onmouseover=\"this.className='yellow'\" onmouseout=\"this.className='whitebg'\">".$attrs[0]."</td></tr>";
}
}
?>
</table>
</div>
<!--
<div id="noselection" onclick="this.style.visibility='hidden';" style="position: fixed; visibility: hidden; box-shadow: 2px 2px 2px #888; font-size: 14px; padding-left: 20px; width: 140px; border: 1px solid #000; background: lightyellow">
<img src='img/bullet_error.png'> No selection!
</div>
-->
<?php
$prevAndnextIDs = getPrevNext($taskid, $id);
if ($sentidx != -1) {
$sentidx = $prevAndnextIDs[2];
}
print "<div class=donebottom>";
$prevpage = "errors.php?id=".$prevAndnextIDs[0]."&taskid=$taskid&sentidx=".($sentidx-1);
$nextpage = "errors.php?id=".$prevAndnextIDs[1]."&taskid=$taskid&sentidx=".($sentidx+1);
print "<button id=prev name=prev onclick=\"javascript:next('$prevpage');\"> « prev </button> ";
print "<button style='width: 170' id=done name=done onclick=\"javascript:doneAndIndex('$id','$userid',this);\" disabled></button> ";
print "<button id=next name=next onclick=\"javascript:next('$nextpage');\"> next » </button>";
print "</div>";
if (empty($mysession["status"])) {
print "<script>window.open('index.php','_self');</script>";
}
if (!isset($errorid)) {
$errorid = "";
}
if ($taskid > 0 && isset($id) && isset($userid)) {
$hash_target = getSystemSentences($id,$taskid);
$i = 0;
$checked = 0;
print "<div style='width: 100%; position: relative; height: 100%; margin-top:0px; margin-left: -28px; padding-right: 46px; margin-bottom: auto; overflow-y: auto;'>";
if (count($hash_target) > 0) {
while (list ($sentence_id, $sentence_item) = each($hash_target)) {
$errors = getErrors($id,$sentence_id,$userid);
if (count($errors) > 0) {
$checked++;
}
print "<table cellpadding=0 cellspacing=2 border=0> <td valign=top>";
print "<div>";
//print "<div style='display: table-cell; float: left; width: 666px'>";
//Add output row
$sent = showSentence ($sentence_item[0], $sentence_item[1], "output", $sentence_item[2], $sentence_id, $errors, $ranges);
//ripristino eventuali errori nei carattri con lastring vuota se non sono stati fatte delle anotazioni
#if(count($errors) == 0) {
# $sent = preg_replace("/<img src='img\/check_error.png' width=16>/","",$sent);
#}
print "<div class=row><div class=label>OUTPUT <b>".($i+1)."</b>: </div><div class=cell id='output".$sentence_id."'>$sent</div></div>";
//end output row
//Add comment row
print "<div class=row><div class=cell>";
$comment = getComment($sentence_id,$userid);
if ($monitoring==0) {
?>
<!-- comment -->
<a href='#comm<?php echo $sentence_id; ?>' class='nav-toggle'><img src='img/addcomment.png' style='vertical-align: top; float: right;' width=80></a> </div>
<div id="comm<?php echo $sentence_id; ?>" style="display:none; font-size: 12px;">
<textarea id=comm<?php echo $sentence_id; ?>_text rows=2 cols=75 style='background: lightyellow'><?php echo $comment; ?></textarea>
</div>
<div style="display: inline-block; top: 10px;" id=comm<?php echo $sentence_id; ?>_label><?php echo $comment; ?></div>
<?php
} else {
if ($comment !="") {
print "<small><i>Comment:</i></small> </div>$comment<div class=cell>";
}
}
?>
<!-- fine comment -->
<?php
print "</div>";
//end comment row
print "</div>";
//end cell (output+comment)
//start error cell
print "<td valign=top>";
print "<div class='cell right' id='errors".$sentence_id."'>";
reset($ranges);
$checkid = 0;
while (list ($val,$attrs) = each($ranges)) {
if ($val <= 1) {
if (count($errors) == 0 || isset($errors[0]) || isset($errors[1])) {
$color="#".$attrs[1];
$bordercolor="4px solid ".$color;
if (isset($errors[$val])) {
$bordercolor="4px solid red";
}
if ($val == 0) {
print "<table cellspacing=4>";
}
print "<td style='padding: 1px; background: $color; border: $bordercolor; box-shadow: 2px 2px 2px #888; font-size:13px' id='check.$i.$checkid' align=center onmouseover='fadeIn(this);' onmouseout='fadeOut(this,\"".$attrs[1]."\");' onClick=\"check('$id','$sentence_id',$userid,$val,$checkid,".count($ranges).",$i,".count($hash_target).");\" nowrap>".$attrs[0] ."</td></tr>";
if ($val == 1) {
print "</table>";
}
}
$checkid++;
}
}
while (list ($errID, $errARRAY) = each($errors)) {
if ($errID > 1) {
$tokenids = explode(",",$errARRAY[0]);
$texts = explode("__BR__",$errARRAY[1]);
$annotations = "";
for($r=0; $r<count($tokenids); $r++) {
$delicon = "";
if (count($ranges) > 1) {
if ($monitoring==0) {
$delicon = "<a href=\"javascript:removeAnnotation($id,$sentence_id,'".$tokenids[$r]."',$errID);\"><img src='img/delete.png' width=12></a>";
}
}
$annotations .= "- $delicon<div style='display: inline; font-size:17px' onmouseover=\"javascript:showRange(this,$sentence_id,'".$tokenids[$r]."');\" onmouseout=\"javascript:hideRange(this,$sentence_id,'".$tokenids[$r]."');\"> ";
if (trim($texts[$r]) == "") {
$annotations .= "<small>_SPACE_</small>";
} else {
$annotations .= $texts[$r];
}
$annotations .="</div><br>";
}
print "<div style='background: #".$ranges[$errID][1]."; white-space: nowrap;'> ";
if ($monitoring==0) {
print "<button id=reset.$i.$errID onclick=\"javascript:reset('$id','$sentence_id',$taskid,$userid,$errID,".count($ranges).",$sentidx,".count($hash_target).");\">reset</button>";
}
print " <i><small><b>".$ranges[$errID][0].":</b></small></i></div>$annotations";
}
}
print "</div></td>";
//end error cell
print "</table><div style='display: inline-block; border-top: dashed #666 1px; width: 100%'> </div>";
$i++;
}
#print count($hash_target) ."!= $checked || ".isDone($id,$userid);
if (isDone($id,$userid) > 0) {
print "<script>alreadyDone();</script>";
} else {
if ($checked != count($hash_target)) {
print "<script>notDoneYet();</script>";
} else {
print "<script>activateDone(".$monitoring.");</script>";
}
}
} else {
print "<h3><font color=red>No output found!</font></h3>";
}
}
?>
<div class=log id=log></div>
<script type="text/javascript" src="js/errors.js"></script>
<script type="text/javascript" charset="utf-8">
var ERRORID="<?php echo $errorid; ?>";
var ERRORCOLOR = "red";
var OUTPUTID = null;
function saveAnnotationRanges(errid) {
ERRORID = errid;
var elid = 1;
var ranges = "";
var entities = "";
var prevcolor = null;
while(true) {
//alert(OUTPUTID+" "+elid);
el = document.getElementById(OUTPUTID+"."+elid);
//alert(ERRORID+" "+OUTPUTID+"."+elid + " " + el.style.backgroundColor);
if (el == null) {
break;
} else {
if (el.style.backgroundColor != WHITE) {
if (prevcolor == null || prevcolor != el.style.backgroundColor) {
//alert(el.id + " ## " +prevcolor + " ---- backgroundColor:" +el.style.backgroundColor);
//ranges += "("+getType(prevcolor)+"),";
ranges += ","+elid;
//entities += " ("+getType(prevcolor)+")__BR__";
entities += "__BR__";
} else {
ranges += " "+elid;
entities += " ";
}
entities += encodeURIComponent(el.innerHTML).replace(/%3Cnobr.*$/gi,"")
}
prevcolor = el.style.backgroundColor;
}
//check spaces
el = document.getElementById(OUTPUTID+"."+elid+"-"+(elid+ 1));
if (el != null) {
if (el.style.backgroundColor != WHITE) {
if (prevcolor== null || prevcolor != el.style.backgroundColor) {
//ranges += "("+getType(prevcolor)+"),";
ranges += ","+elid+"-"+(elid+ 1);
//entities += " ("+getType(prevcolor)+")__BR__";
entities += "__BR___SPACE_";
} else {
ranges += " "+elid+"-"+(elid+ 1);
entities += " ";
}
}
prevcolor = el.style.backgroundColor;
}
elid++;
}
//alert("ID: <?php echo $id;?>, OUTPUTID: "+OUTPUTID+", ERRORID: "+ERRORID+", RANGES: "+ranges);
ranges = ranges.replace(/^,\s*/,"");
entities = entities.replace(/^__BR__\s*/, "").replace(/ /gi," ");
//if (send) { // && trim(ranges) != "") {
$.ajax({
url: 'update.php',
type: 'GET',
data: "id=<?php echo $id;?>&targetid="+OUTPUTID+"&userid=<?php echo $userid;?>&check="+ERRORID+"&tokenids="+ranges+"&taskid=<?php echo $taskid;?>&words="+entities,
async: false,
cache:false,
crossDomain: true,
success: function(response) {
if (response == "error") {
//$("#log").html("");
alert("Warning! A problem occurred during saving the data. Try again later!");
} else {
//update list of annotated tokens
$("#output"+OUTPUTID).html(response);
$.ajax({
url: 'errors_type.php',
type: 'GET',
data: "id=<?php echo $id;?>&targetid="+OUTPUTID+"&userid=<?php echo $userid;?>",
async: false,
cache:false,
crossDomain: true,
success: function(response) {
$("#errors"+OUTPUTID).html(response);
}
});
//window.open("errors_output.php?id=<?php echo $id;?>&sentidx=<?php echo $sentidx; ?>","_self");
}
},
error: function(response, xhr,err ) {
//alert(err+"\nreadyState: "+xhr.readyState+"\nstatus: "+xhr.status+"\nresponseText: "+xhr.responseText);
//alert(ERRORID);
switch(xhr.status) {
case 200:
$("#log").html('<font color=gray>Data saved!</font>');
break;
case 404:
$("#log").html('<font color=red>Could not contact server.</font>');
break;
case 500:
$("#log").html('<font color=red>A server-side error has occurred.</font>');
break;
}
setTimeout(function(){$("#log").html('')}, 3000);
}
});
ERRORID = "";
}
function getType (color) {
if (color == ERRORCOLOR) {
return ERRORID;
}
return color;
}
function setColor(selectel, index, id) {
var color = selectel.value;
if (selectel.id == "corefcolor" || selectel == "corefcolor") {
ERRORID = id;
COLOR = ERRORCOLOR;
color = COLOR;
//$("#color").prop("selectedIndex",0);
} else {
//ERRORID = selectel.options[selectel.options.selectedIndex].text;
//ERRORID = ERRORID.substr(0,3).toUpperCase();
ERROR = null;
COLOR = color;
//$("#corefcolor").prop("selectedIndex",0);
}
}
$(document).ready(function() {
$('.nav-toggle').click(function() {
//get collapse content selector
var collapse_content_selector = $(this).attr('href');
//make the collapse content to be shown or hide
var toggle_switch = $(this);
$(collapse_content_selector).toggle(function(){
if ($(this).css('display')=='none'){
//change the button label to be 'Show'
if (this.id.indexOf("comm") == 0) {
toggle_switch.html("<img src='img/addcomment.png' style='vertical-align: top; float: right;' width=80>");
el = document.getElementById(this.id+"_text");
if (el != null) {
save_comment(this.id,<?php echo $userid ?>,el.value);
$("#"+this.id+"_label").html(el.value);
elComment = document.getElementById(this.id+"_label");
elComment.style.visibility = "visible";
//activateDone();
} else {
alert("Error while saving the comment! Please contact the administrator. (code: 1001)");
}
} else {
toggle_switch.html('read more');
}
}else{
//change the button label to be 'Hide'
if (this.id.indexOf("comm") == 0) {
$("#"+this.id+"_text").focus();
elabel = this.id.replace(/_label/,"");
elComment = document.getElementById(elabel+"_label");
//alert(el.id);
if (elComment != null) {
elComment.style.visibility = "hidden";
}
toggle_switch.html("<img src='img/savecomment.png' style='vertical-align: top; float: right;' width=40>");
} else {
toggle_switch.html('close');
}
}
});
});
});
/*(function($){
var methods = {
disable: function() {
return $(this)
.attr('unselectable', 'on')
.attr('disabled','disabled')
.css({
'-user-select': 'none',
'-webkit-user-select': 'none',
'-khtml-user-select': 'none',
'-moz-user-select': 'none',
'-o-user-select': 'none'
})
.each(function() {
this.onselectstart = function() { return false; };
});
}
};
$.fn.textSelect = function( method ) {
// Method calling logic
if ( methods[method] ) {
return methods[ method ].apply( this, Array.prototype.slice.call( arguments, 1 ));
} else {
$.error( 'Method ' + method + ' does not exist on jQuery.textSelect' );
}
}
})(jQuery);
$('.unselect').textSelect('disable');
*/
//if IE4+
//document.onselectstart=new Function ("return false")
//if NS6
//if (window.sidebar){
//document.onmousedown=disableselect
//document.onclick=reEnable
//}
</script>
<br></br>
</div>
</body>
</html>