-
Notifications
You must be signed in to change notification settings - Fork 3
/
wordalign_output.php
711 lines (621 loc) · 25.5 KB
/
wordalign_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
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
<link href="css/mtequal.css" rel="styleSheet" type="text/css">
<link href="css/wordaligner.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");
#activate the Javascript functions
if (!isset($userid)) {
$userid = $mysession['userid'];
}
if (!isset($taskid)) {
$taskid = $mysession["taskid"];
}
if (isset($monitoring) && $monitoring == 1) {
$sentidx=-1;
} else {
$monitoring=0;
if (!isset($sentidx)) {
$sentidx=-1;
}
}
?>
</head>
<div id="errortypes" onclick="this.style.visibility='hidden';" style="font-size: 10px"></div>
<?php
$prevAndnextIDs = getPrevNext($taskid, $id);
if ($sentidx != -1) {
$sentidx = $prevAndnextIDs[2];
}
print "<div class=donebottom>";
$prevpage = "wordaligner.php?id=".$prevAndnextIDs[0]."&taskid=$taskid&sentidx=".($sentidx-1);
$nextpage = "wordaligner.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 ($taskid > 0 && isset($id) && isset($userid)) {
$hash_target = getSystemSentences($id,$taskid);
$i = 1;
$checked = 0;
print "<div style='width: 100%; position: relative; height: 100%; margin-top:0px; margin-left: -28px; padding-right: 47px; margin-bottom: auto; overflow-y: auto;'>";
if (count($hash_target) > 0) {
$sentence_hash = getSentence($id,$taskid);
while (list ($sentence_id, $sentence_item) = each($hash_target)) {
$errors = getErrors($id, $sentence_id, $userid);
print "<table cellpadding=0 cellspacing=2 border=0> <td valign=top>";
print "<div class='cell'>";
//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);
//ripristino eventuali errori nei caratteri 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</b>: </div>$sent</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 class=cell>
<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></table>";
//end cell (output+comment)
//print "###### $id, $sentence_id, $userid";
$hash_eval = getErrors($id, $sentence_id, $userid);
//start matrix
echo "<script type=\"text/Javascript\">\nvar sourceString=\"". preg_replace('/\"/',""", join(" ",getTokens($sentence_hash["source"][0], trim($sentence_hash["source"][1]), $sentence_hash["source"][2]))) ."\";\n".
"var targetString=\"".preg_replace('/\"/',""", join(" ",getTokens($sentence_item[0], trim($sentence_item[1]), $sentence_item[2])))."\";\n";
if (isset($hash_eval[0])) {
echo "var initialPossAlignments=\"".$hash_eval[0][0]."\";\n";
} else {
echo "var initialPossAlignments=\"\";\n";
}
if (isset($hash_eval[1])) {
echo "var initialSureAlignments=\"".$hash_eval[1][0]."\";\n";
} else {
echo "var initialSureAlignments=\"\";\n";
}
//echo "var initialSureAlignments=\"1-6 2-0\";\n";
//echo "var initialPossAlignments=\"0-6\";\n";
?>
var disagreed_alignments_type1="";
var disagreed_alignments_type2="";
var disagreed_alignments_type3="";
// the URL directory where rotated word images are stored
//var imageDirectory = "http://ironman.jhu.edu/wordImageServer/";
var imageDirectory = "./img/";
// specify whether the languages should be written right-to-left
var sourceIsRTL = false;
var targetIsRTL = false;
// indicates whether to switch the view from the source being
// along top (default) or the target on top (transposed).
// The results still keep the same source / target names.
var viewTransposed = false;
// read in the values for this sentence pair
// ${source} and ${target} should contain whitespace delimited words
//var sourceString = "${source}";
//var targetString = "${target}";
//var initialSureAlignments = "${sureAlignments}";
// sure alignments should have the format "0-0 0-1 1-2" where the first number
// in each pair is the index of the source word, and the second it the target
//var initialPossAlignments = "${possAlignments}";
// indicates which rows and columns are highlighted
var initialSourceHighlights = "${sourceHighlights}";
var initialTargetHighlights = "${targetHighlights}";
var initialDisagreedAlignmentsType1 = "";
var initialDisagreedAlignmentsType2 = "";
var initialDisagreedAlignmentsType3 = "";
var sourceIsRTL = false;
var targetIsRTL = true;
if(viewTransposed) {
var tmp = sourceString;
sourceString = targetString;
targetString = tmp;
tmp = initialSourceHighlights;
initialSourceHighlights = initialTargetHighlights;
initialTargetHighlights = tmp;
tmp = sourceIsRTL;
sourceIsRTL = targetIsRTL;
targetIsRTL = tmp;
initialSureAlignments = transposeAlignments(initialSureAlignments);
initialPossAlignments = transposeAlignments(initialPossAlignments);
initialDisagreedAlignmentsType1 = transposeAlignments(disagreed_alignments_type1);
initialDisagreedAlignmentsType2 = transposeAlignments(disagreed_alignments_type2);
initialDisagreedAlignmentsType3 = transposeAlignments(disagreed_alignments_type3);
}
// split the source and target sentences into words
var whitespacePattern = /\s/;
var sourceWords = sourceString.split(whitespacePattern);
var targetWords = targetString.split(whitespacePattern);
var width = sourceWords.length;
var height = targetWords.length;
// initialize the sureGrid and the probGrid
var sureGrid = initalizeBooleanGrid(width, height, initialSureAlignments);
var probGrid = initalizeBooleanGrid(width, height, initialPossAlignments);
var disagreed_alignments_type1Grid = initalizeBooleanGrid(width, height, initialDisagreedAlignmentsType1);
var disagreed_alignments_type2Grid = initalizeBooleanGrid(width, height, initialDisagreedAlignmentsType2);
var disagreed_alignments_type3Grid = initalizeBooleanGrid(width, height, initialDisagreedAlignmentsType3);
// initialize the highlighted rows and columns
var sourceHighlights = initalizeBooleanArray(width, initialSourceHighlights);
var targetHighlights = initalizeBooleanArray(height, initialTargetHighlights);
if(sourceIsRTL) {
writeHtmlAlignmentTableRTL(sourceWords, targetWords, sureGrid, probGrid, sourceHighlights, targetHighlights, imageDirectory);
} else {
writeHtmlAlignmentTable(sourceWords, targetWords, sureGrid, probGrid, disagreed_alignments_type1Grid, disagreed_alignments_type2Grid, disagreed_alignments_type3Grid, sourceHighlights, targetHighlights, imageDirectory);
}
// log the time...
date = new Date();
timeAtStart = date.getTime();
timeOfLastModification = date.getTime();
activeTime = 0;
// Transposes the string form of the alignment. Changes each x-y into y-x
function transposeAlignments(alignmentString) {
var transposedAlignmentsString = "";
var whitespacePattern = /\s/;
var dash = '-';
var points = alignmentString.split(whitespacePattern);
for(i = 0; i < points.length; i++) {
if(points[i].indexOf(dash) > 0) {
var point = points[i].split(dash);
var x = point[0];
var y = point[1];
var transposedAlignmentsString = transposedAlignmentsString + y + "-" + x + " ";
}
}
transposedAlignmentsString.replace(/\s$/, '');
return transposedAlignmentsString;
}
// Returns an initialized boolean grid. Sets the points to true
// that are included in the alignmentString as "x-y".
function initalizeBooleanGrid(width, height, alignmentString) {
var grid = new Array(width);
for (i = 0; i < grid.length; i++) {
grid[i] = new Array(height);
for(j = 0; j < height; j++) {
grid[i][j] = false;
}
}
// Set the points in alignmentString to true
var whitespacePattern = /\s/;
var dash = '-';
var points = alignmentString.split(whitespacePattern);
var errmsg = "";
for(i = 0; i < points.length; i++) {
if(points[i].indexOf(dash) > 0) {
var point = points[i].split(dash);
var x = point[0]-1;
var y = point[1]-1;
if (typeof(grid[x]) == 'undefined' || typeof(grid[x][y]) == 'undefined') {
errmsg += " "+x+"-"+y;
} else {
grid[x][y] = true;
}
}
}
if (errmsg != "") {
alert("WARNING! These offsets" + errmsg +" are out of the matrix");
}
return grid;
}
// Returns an initialized boolean array
function initalizeBooleanArray(length, indexOfTruesString) {
// pad the indexOfTruesString with spaces
indexOfTruesString = " " + indexOfTruesString + " ";
var array = new Array(length);
for (i = 0; i < array.length; i++) {
array[i] = false;
}
// set the points in alignmentString to true
var whitespacePattern = /\s/;
var indicies = indexOfTruesString.split(whitespacePattern);
for(i = 0; i < indicies.length; i++) {
var index = indicies[i];
array[index] = true;
}
return array;
}
// This method outputs the HTML table with clickable grid squares
// that are indexed into the sure and prob alignment boolean grids.
// There is an alternate version for source languages that should be
// displayed right-to-left.
function writeHtmlAlignmentTable(sourceWords, targetWords, sureGrid, probGrid, disagreed_alignments_type1Grid,
disagreed_alignments_type2Grid, disagreed_alignments_type3Grid, highlightedSourceWords, highlightedTargetWords, imageDirectory) {
var smallerFont = false;
var size = 20;
var fontSize = 0;
if(sourceWords.length > 20 || targetWords.length > 20) {
size = 15;
smallerFont = true;
fontSize = -1;
}
document.write('<table style="margin-left: 35px">\n');
// print the source words as a table header
document.write('<tr>\n');
// write the source words
document.write('\t<td></td>\n');
for(i = 0; i < sourceWords.length; i++) {
var word = sourceWords[i];
document.write('\t<td valign="bottom" bgcolor=#ADE9E6 onmouseover="this.style.cursor=\'crosshair\'" onClick="javascript:clickColumn(<?php echo $sentence_id; ?>,' + i + ')">');
//document.write('<div class=verticaltext >' + word + '</div>');
document.write('<div class=verticaltext>' + word + '</div>');
//document.write('<img src = "' + getImagePath(word, imageDirectory) + '" width="' + size + '" alt="' + word + '"' + ' title="' + word + '" border="0">');
document.write('</td>\n');
}
document.write('\t<td></td>\n');
document.write('</tr>\n');
for(row = 0; row < targetWords.length; row++) {
// print the target word
document.write('<tr heigth=\"'+size+'px\">\n');
var targetWord = targetWords[row];
if(!targetIsRTL) {
document.write('<td>');
} else {
document.write('<td align=left bgcolor=#E6E6FA onmouseover="this.style.cursor=\'crosshair\'" onClick="javascript:clickRow(<?php echo $sentence_id; ?>,' + row + ')">');
}
if(smallerFont) {
document.write('<font size=' + fontSize + '>');
}
document.write(targetWord);
if(smallerFont) document.write('</font>');
document.write('</td>\n\t');
// print this row
for(column = 0; column < sourceWords.length; column++) {
if (disagreed_alignments_type1Grid[column][row]) {
document.write('<td width="' + size +'" class="blue" id="<?php echo $sentence_id; ?>.' + column + '.' + row + '"');
} else if (disagreed_alignments_type2Grid[column][row]) {
document.write('<td width="' + size +'" class="yellow" id="<?php echo $sentence_id; ?>.' + column + '.' + row + '"');
} else if (disagreed_alignments_type3Grid[column][row]) {
document.write('<td width="' + size +'" class="red" id="<?php echo $sentence_id; ?>.' + column + '.' + row + '"');
} else if(sureGrid[column][row]) {
document.write('<td width="' + size +'" class="black" id="<?php echo $sentence_id; ?>.' + column + '.' + row + '"');
} else if(probGrid[column][row]) {
document.write('<td width="' + size +'" class="gray" id="<?php echo $sentence_id; ?>.' + column + '.' + row + '"');
} else {
if(highlightedSourceWords[column] || highlightedTargetWords[row]) {
document.write('<td width="' + size +'" class="highlight" id="<?php echo $sentence_id; ?>.' + column + '.' + row + '"');
} else {
document.write('<td width="' + size +'" class="white" id="<?php echo $sentence_id; ?>.' + column + '.' + row + '"');
}
}
document.write(" onmouseover=\"this.style.cursor='pointer'\" onClick=\"javascript:clickButton('<?php echo $id; ?>','<?php echo $sentence_id; ?>','<?php echo $userid; ?>','" + column + "','" + row + "')\">");
document.write('<img src= "'+ imageDirectory + 'clearpixel.gif" border="0" ');
document.write('title="' + targetWords[row] + ', ' + sourceWords[column]+ ' ['+row+','+column+']" ');
document.write('title="' + targetWords[row] + ', ' + sourceWords[column]+ '" ');
document.write('width="' + size + '" height="' + size + '">');
document.write('</td>\n');
}
// print the target word again
if(!targetIsRTL) {
document.write('<td>');
} else {
document.write('<td align=left bgcolor=#E6E6FA onmouseover="this.style.cursor=\'crosshair\'" onclick="javascript:clickRow(<?php echo $sentence_id; ?>,' + row + ')">');
}
if(smallerFont) document.write('<font size=' + fontSize + '>');
document.write(targetWord);
if(smallerFont) document.write('</font>');
document.write('</td>\n\t');
document.write('</tr>');
document.write('\n');
}
// write the source words again
document.write('\t<td></td>\n');
for(i = 0; i < sourceWords.length; i++) {
var word = sourceWords[i];
document.write('\t<td valign=bottom bgcolor=#ADE9E6 onmouseover="this.style.cursor=\'crosshair\'" onclick="javascript:clickColumn(<?php echo $sentence_id; ?>,' + i + ')">');
document.write('<div style="margin-top: '+(word.length/2*13)+ 'px;"><div class=verticaltext-rtl>' + word + '</div></div>');
//document.write('<div class=verticaltext-rtl>' + word + '</div>');
//document.write('<img src = "' + getImagePath(word, imageDirectory) + '" width="' + size + '" alt="' + word + '"' + ' title="' + word + '" border="0">');
document.write('</td>\n');
}
document.write('\t<td></td>\n');
document.write('</tr>\n');
document.write('</table>\n');
// document.write('<p> PIPPO: ' + sureGrid[4][1] + sureGrid[1][4] + ' </p>');
}
// An alternate version of writeHtmlAlignmentTable which displays the
// source language in a right to left (RTL) fashion.
function writeHtmlAlignmentTableRTL(sourceWords, targetWords, sureGrid, probGrid,
highlightedSourceWords, highlightedTargetWords, imageDirectory) {
var smallerFont = false;
var size = 15;
var fontSize = 0;
if(sourceWords.length > 20 || targetWords.length > 20) {
size = 11;
smallerFont = true;
fontSize = -1;
}
document.write('<table>\n');
// print the source words as a table header
document.write('<tr>\n');
// write the source words
document.write('\t<td></td>\n');
for(i = sourceWords.length-1; i >= 0; i--) {
var word = sourceWords[i];
document.write('\t<td valign="bottom">');
document.write('<a href="javascript:clickColumn(<?php echo $sentence_id; ?>,' + i + ')">');
document.write('<div class=verticaltext ><div style="width: ' + fontSize + 'px">' + word + '</div></div>');
//document.write('<img src = "' + getImagePath(word, imageDirectory) + '" width="' + size + '" alt="' + word + '"' + ' title="' + word + '" border="0">');
document.write('</a>');
document.write('</td>\n');
}
document.write('\t<td></td>\n');
document.write('</tr>\n');
for(row = 0; row < targetWords.length; row++) {
// print the target word
document.write('<tr>\n');
var targetWord = targetWords[row];
document.write('<td>');
if(smallerFont) {
document.write('<font size=' + fontSize + '>');
}
document.write('<span class="blacklink"><a href="javascript:clickRow(<?php echo $sentence_id; ?>,' + row + ')">');
document.write(targetWord);
document.write('<a href="javascript:clickRow(<?php echo $sentence_id; ?>,' + row + ')"></span>');
if(smallerFont) document.write('</font>');
document.write('</td>\n\t');
// print this row
for(column = sourceWords.length-1; column >= 0; column--) {
if(sureGrid[column][row]) {
document.write('<td class="black" id="<?php echo $sentence_id; ?>.' + column + '.' + row + '">');
} else if(probGrid[column][row]) {
document.write('<td class="gray" id="<?php echo $sentence_id; ?>.' + column + '.' + row + '">');
} else {
if(highlightedSourceWords[column] || highlightedTargetWords[row]) {
document.write('<td class="highlight" id="<?php echo $sentence_id; ?>.' + column + '.' + row + '">');
} else {
document.write('<td class="white" id="<?php echo $sentence_id; ?>.' + column + '.' + row + '">');
}
}
document.write("<a href=\"javascript:clickButton('<?php echo $id; ?>','<?php echo $sentence_id; ?>','<?php echo $userid; ?>','" + column + "','" + row + "')\">");
document.write('<img src= "'+ imageDirectory + 'clearpixel.gif" border="0" ');
document.write('title="' + targetWords[row] + ', ' + sourceWords[column]+ '" ');
document.write('width="' + size + '" height="' + size + '"></a>');
document.write('</td>\n');
}
// print the target word again
document.write('<td>');
if(smallerFont) document.write('<font size=' + fontSize + '>');
document.write('<span class="blacklink"><a href="javascript:clickRow(<?php echo $sentence_id; ?>,' + row + ')">');
document.write(targetWord);
document.write('<a href="javascript:clickRow(<?php echo $sentence_id; ?>,' + row + ')"></span>');
if(smallerFont) document.write('</font>');
document.write('</td>\n\t');
document.write('</tr>');
document.write('\n');
}
// write the source words again
document.write('\t<td></td>\n');
for(i = sourceWords.length-1; i >= 0; i--) {
var word = sourceWords[i];
document.write('\t<td valign="top">');
document.write('<a href="javascript:clickColumn(<?php echo $sentence_id; ?>,' + i + ')">');
document.write('<div class=verticaltext-rtl>' + word + '</div>');
//document.write('<img src = "' + getImagePath(word, imageDirectory) + '" width="' + size + '" alt="' + word + '"' + ' title="' + word + '" border="0">');
document.write('</a>');
document.write('</td>\n');
}
document.write('\t<td></td>\n');
document.write('</tr>\n');
document.write('</table>\n');
}
function clickButton(id, sentid, userid, x, y) {
button = document.getElementById(sentid+"."+x+"."+y);
if (button != null) {
activateDone("<?php echo $monitoring;?>");
if (button.className == "white" || button.className == "highlight") {
button.className = "gray";
//alert(id+","+ sentid+","+ userid+","+x+","+y + " :: " +getCheckedButton(sentid,"gray"));
saveAlignment(id, sentid, userid, 0, getCheckedButton(sentid,"gray"));
} else if (button.className == "gray") {
button.className = "black";
saveAlignment(id, sentid, userid, 0, getCheckedButton(sentid,"gray"));
saveAlignment(id, sentid, userid, 1, getCheckedButton(sentid,"black"));
} else {
button.className = "white";
saveAlignment(id, sentid, userid, 1, getCheckedButton(sentid,"black"));
}
}
//alert("SURE: "+getCheckedButton(sentid,"black")+"\nPOSS: " +getCheckedButton(sentid,"gray"));
}
function clickRow(sentid, y) {
for(var x = 0; x < width; x++) {
var button = document.getElementById(sentid+"."+x+"."+y);
if (button.className == "white") {
button.className = "highlight";
} else if (button.className == "highlight") {
button.className = "white";
}
}
}
function clickColumn(sentid, x) {
for(var y = 0; y < height; y++) {
var button = document.getElementById(sentid+"."+x+"."+y);
if (button.className == "white") {
button.className = "highlight";
} else if (button.className == "highlight") {
button.className = "white";
}
}
}
function getCheckedButton (id, color) {
var ranges="";
for (var x=0; x >= 0; x++) {
var y=0;
el = document.getElementById(id+"."+x+"."+y);
if (el == null) {
break;
}
while (true) {
if (el.className == color) {
ranges += (x+1)+"-"+(y+1)+" ";
}
y++;
el = document.getElementById(id+"."+x+"."+y);
if (el == null) {
break;
}
}
}
return ranges.replace(/\s+$/g, "");
}
function saveAlignment (id, sentid, userid, checkid, alignids) {
$.ajax({
url: 'update.php',
type: 'GET',
data: {id: id, targetid: sentid, userid: userid, check: checkid, alignids: alignids},
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!");
}
},
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);
}
});
}
function boolGridToString(grid) {
var gridString = "";
for(i = 0; i < grid.length; i++) {
row = grid[i];
for(j = 0; j < row.length; j++) {
if(grid[i][j]) {
gridString += i + "-" + j + " ";
}
}
}
// remove the training space
gridString = gridString.substring(0, gridString.length-1);
if(viewTransposed) {
//gridString = transposeAlignments(gridString);
}
return gridString;
}
// Converts an array of highlights into a string
function highlightsToString(array) {
var arrayString = "";
for(i = 0; i < array.length; i++) {
if(array[i]) {
arrayString += i + " ";
}
}
// remove the training space
arrayString = arrayString.substring(0, arrayString.length-1);
return arrayString;
}
function goto (url) {
var button = document.getElementById("updatebutton");
if (button == null || button.disabled == true) {
window.location = url;
} else {
if (confirm("You have unsaved changes, are you sure that you want to cancel? All of your changes will be lost.")) {
window.location = url;
}
}
}
</script>
<?php
//end matrix
print "<div style='display: inline-block; border-top: dashed #666 1px; width: 100%'> </div>";
$i++;
}
#print "</div>";
#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>";
}
}
?>
<script>
$(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');
}
}
});
});
});
</script>