-
Notifications
You must be signed in to change notification settings - Fork 3
/
admin_task.php
429 lines (386 loc) · 16.1 KB
/
admin_task.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
<!--
MT-EQuAl: a Toolkit for Human Assessment of Machine Translation Output
Copyright 2014, Christian Girardi (cgirardi@fbk.eu)
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<head>
<script type="text/javascript" src="js/jscolor/jscolor.js"></script>
<meta charset="utf-8">
<!-- markItUp! skin -->
<link rel="stylesheet" type="text/css" href="js/markitup/skins/markitup/style.css">
<!-- markItUp! toolbar skin -->
<link rel="stylesheet" type="text/css" href="js/markitup/sets/default/style.css">
<!-- markItUp! -->
<script type="text/javascript" src="js/markitup/jquery.markitup.js"></script>
<!-- markItUp! toolbar settings -->
<script type="text/javascript" src="js/markitup/sets/default/set.js"></script>
<style>
li.row {
padding-top: 1px;
border-bottom: 1px solid #fff;
}
li.row:hover {
padding-top: 1px;
border-bottom: 1px solid #090;
background:#BAE3E0;
}
li.selected {
background:#E0A4AA;
padding-right:4px;
border-bottom: 1px solid #5c0120;
font-size:14px;
color: #600;
}
</style>
<SCRIPT language="javascript">
var DEFAULT_ERRORS_RANGES="[{\"val\": \"0\",\"label\": \"No errors\",\"color\": \"C8E8B8\"},{\"val\": \"1\",\"label\": \"Too many errors\",\"color\": \"F0D3A8\"}]";
var DEFAULT_WORDALIGN_RANGES="[{\"val\": \"0\",\"label\": \"Possible alignment\",\"color\": \"BABABA\"},{\"val\": \"1\",\"label\": \"Sure alignment\",\"color\": \"000000\"}]";
var DEFAULT_DOCANN_RANGES="[{\"val\": \"0\",\"label\": \"No annotation\",\"color\": \"C8E8B8\"},{\"val\": \"1\",\"label\": \"Too many annotations\",\"color\": \"F0D3A8\"}]";
var DEFAULT_RANGES="[{\"val\": \"\",\"label\": \"\",\"color\": \"FFFFFF\"}]";
function addRange(taskid, type) {
jsonRanges = getRanges(false);
$.ajax({
url: 'ranges.php',
type: 'GET',
data: {taskid: taskid, type: type, ranges: jsonRanges, action: "add"},
async: false,
cache:false,
crossDomain: true,
success: function(response) {
$("#divranges").html(response);
},
error: function(response, xhr,err ) {
alert("Error!");
}
});
}
function getRanges(checkOnly) {
var jsonRanges="";
var table = document.getElementById("rangesTable");
if (table != null) {
var rowCount = table.rows.length;
if (rowCount>0) {
var colCount = table.rows[0].cells.length;
// var arrayVal = new Array(rowCount);
for(var x=1; x<rowCount; x++) {
var item="";
for(var y=0; y<colCount; y++) {
var val=table.rows[x].cells[y].childNodes[0].value;
if (typeof val == 'undefined') {
val = "";
}
val = val.trim();
if (y==0) {
item += '{"val": "'+val+'",';
} else if (y==1) {
item += '"label": "'+val+'",';
} else if (y==2) {
if (val=="") {
val="444444";
}
item += '"color": "'+val+'"}';
}
}
if (item != "") {
if (jsonRanges != "")
jsonRanges += ",";
jsonRanges += item;
}
}
}
}
//alert(jsonRanges);
return "["+jsonRanges+"]";
}
function deleteRow(tableID,item) {
try {
var table = document.getElementById(tableID);
var rowCount = table.rows.length;
if(rowCount <= 2) {
alert("Cannot delete all values.");
return;
}
for(var i=0; i<rowCount; i++) {
if (i==item) {
table.deleteRow(i);
break;
}
}
} catch(e) {
alert(e);
}
}
function showRanges(taskid, type, jsonRanges) {
if (jsonRanges == null) {
jsonRanges = getRanges(false);
//alert(jsonRanges);
}
$.ajax({
url: 'ranges.php',
type: 'GET',
data: {taskid: taskid, type: type, ranges: jsonRanges},
async: false,
cache:false,
crossDomain: true,
success: function(response) {
$("#divranges").html(response);
},
error: function(response, xhr,err ) {
alert("Error!");
}
});
}
function defaultRanges(type) {
if (type == "") {
var selectel = document.getElementById("type");
var type = selectel.options[selectel.options.selectedIndex].value;
}
if (type == "") {
alert("WARNING! Choose the type of the task to set a default values.");
return;
} else {
jsonRanges = getRanges(true);
if (jsonRanges != "[]" && jsonRanges != DEFAULT_RANGES &&
jsonRanges != DEFAULT_ERRORS_RANGES && jsonRanges != DEFAULT_WORDALIGN_RANGES && jsonRanges != DEFAULT_DOCANN_RANGES) {
if (!confirm("Do you want to discard your customization and use the default one?")) {
return;
}
}
var ranges ="";
if (type == "quality") {
ranges = "[{\"val\": \"1\",\"label\": \"1\",\"color\": \"FFFF99\"},{\"val\": \"2\",\"label\": \"2\",\"color\": \"D9FF99\"},{\"val\": \"3\",\"label\": \"3\",\"color\": \"B2FF99\"},{\"val\": \"4\",\"label\": \"4\",\"color\": \"8CFF99\"},{\"val\": \"5\",\"label\": \"5\",\"color\": \"66FF99\"}]";
} else if (type == "errors") {
ranges = "[{\"val\": \"0\",\"label\": \"No errors\",\"color\": \"C8E8B8\"},{\"val\": \"1\",\"label\": \"Too many errors\",\"color\": \"F0D3A8\"},{\"val\": \"2\",\"label\": \"Reordering errors\",\"color\": \"69B4FF\"},{\"val\": \"3\",\"label\": \"Wrong lexical choice\",\"color\": \"B296FF\"},{\"val\": \"4\",\"label\": \"Missing word(s)\",\"color\": \"E9FF24\"},{\"val\": \"5\",\"label\": \"Superfluous word(s)\",\"color\": \"91F0FF\"},{\"val\": \"6\",\"label\": \"Morphology errors\",\"color\": \"FF9EFF\"},{\"val\": \"7\",\"label\": \"Casing and punctuation errors\",\"color\": \"A6445B\"}]";
} else if (type == "wordaligner") {
ranges = "[{\"val\": \"0\",\"label\": \"Possible alignment\",\"color\": \"BABABA\"},{\"val\": \"1\",\"label\": \"Sure alignment\",\"color\": \"000000\"}]";
}
if (ranges != "") {
showRanges(-1, type, ranges);
}
}
}
function setMandatoryRanges(selectel) {
var type = selectel.options[selectel.options.selectedIndex].value;
if (type == "errors") {
showRanges(-1, type, DEFAULT_ERRORS_RANGES);
} else if (type == "wordaligner") {
showRanges(-1, type, DEFAULT_WORDALIGN_RANGES);
} else if (type == "docann") {
showRanges(-1, type, DEFAULT_DOCANN_RANGES);
} else {
showRanges(-1, type, "");
addRange(-1,'');
}
}
function send(form) {
jsonRanges = getRanges(false);
form.ranges.value = jsonRanges;
form.update.value = "yes";
form.submit();
}
// And you can add/remove markItUp! whenever you want
// $(textarea).markItUpRemove();
function markup() {
if ($("#markItUp.markItUpEditor").length === 1) {
$("#markItUp").markItUp('remove');
$("#markupbutton").html("enable HTML editor");
} else {
$('#markItUp').markItUp(mySettings);
$("#markupbutton").html("disable HTML editor");
}
return false;
};
</SCRIPT>
</head>
<div style='margin: 10px; vertical-align: top; top: 0px; display: inline-block'>
<div style='float: left; vertical-align: top; top: 0px; display: inline-block; padding-right: 0px; margin: 0px'>
<?php
/*if (isset($_POST['txt'])) {
$txtbox = $_POST['txt'];
$color = $_POST['color'];
foreach($txtbox as $a => $b) {
if (isset($txtbox[$a]) && isset($color[$a])) {
echo "$txtbox[$a] - $color[$a] <br />";
}
}
}*/
$sentypes = getSentenceType();
if ($mysession["status"] == "root" || $mysession["status"] == "admin" || $mysession["status"] == "advisor") {
$tasks = getTasks($mysession["userid"]);
$sentlabel="Create";
$cancelbutton="<input type=button onclick=\"javascript:window.open('admin.php?section=task','_self');\" value='Cancel'> ";
$visibility_tform="visible";
$taskinfo = array("name" => "",
"type" => "",
"descr" => "",
"randout" => "N",
"instructions" => "",
"ranges" => "[]",
"owner" => $mysession['userid']);
if (isset($ranges) && $ranges != "[]") {
$taskinfo["ranges"] = $ranges;
}
if (isset($id) && ($id<0 || isset($tasks{$id}))) {
$query = "";
if (isset($action) && $action="remove") {
if (removeTask($id) == 1) {
$id=-1;
print "<script>alert('The task information and all annotations refering to it have been removed.'); \nwindow.open(\"admin.php?section=task\", \"_self\");</script>";
##print "<button id='newtask' style='position: absolute;' onclick=\"showForm(this);\">Create a new task</button>";
##$visibility_tform="hidden";
} else {
print "<script>alertify.alert('ERROR! The task hasn't been removed correctly.'); </script>";
}
} else {
if ($id == -1 || (isset($update) && $update=="yes")) {
while (list ($key,$val) = each($taskinfo)) {
if (isset($$key)) {
if ($key == "randout" && $$key == "on") {
$$key = "Y";
}
$taskinfo[$key] = $$key;
}
$query .= ",$key=\"".addslashes($taskinfo[$key])."\"";
}
#print "Q: " .$query ."<br>";
} else {
$taskinfo = getTaskInfo($id);
$sentlabel = "Update";
$cancelbutton = "<input type=button onclick=\"javascript:window.open('admin.php?section=task','_self');\" value='Cancel'> ";
}
if ($id == -1) {
if ($taskinfo["name"] != "" && $taskinfo["type"] != "") {
$res = safe_query("INSERT INTO task (name,owner) VALUES ('_NEW_','".$mysession['userid']."');");
if ($res == 1) {
$id = mysql_insert_id();
}
} else {
if ($taskinfo["type"] == "") {
print "<br><font color=red>WARNING!</font> The type is mandatory.<br>";
} else if ($taskinfo["name"] == "") {
print "<br><font color=red>WARNING!</font> The name is mandatory.<br>";
}
$cancelbutton = "<input type=button onclick=\"javascript:window.open('admin.php?section=task','_self');\" value='Cancel'> ";
}
}
if (!empty($query) && $id != -1) {
$query = "UPDATE task SET ".substr($query, 1). " WHERE id=$id";
if (safe_query($query) != 1) {
print "<script>alertify.alert('ERROR! This user has not been saved correctly.');</script>";
} else {
print "<script>window.open(\"admin.php?section=task\", \"_self\");</script>";
}
#print "QUERY: $query<br>";
$sentlabel = "Update";
$cancelbutton = "<input type=button onclick=\"javascript:window.open('admin.php?section=task','_self');\" value='Cancel'> ";
}
}
} else {
$id = -1;
print "<button id='newtask' style='position: absolute; margin-left: 0px; float: left;' onclick=\"showForm(this);\">Create a new task</button>";
$visibility_tform="hidden";
}
if (!isset($id) || $id<0 || !isset($tasks{$id})) {
$id = -1;
}
?>
<span class='spinner'><img width=25 src='img/spinner.gif' valign=bottom></span>
</div>
<div style="white-space: nowrap; float: left; padding-left: 2px; display: inline; position: relative; top: 20px">
<?php
reset($tasks);
$ttype = "";
while (list ($tid,$tarr) = each($tasks)) {
if ($tarr[1] != $ttype) {
$ttype = $tarr[1];
print "<br><b>".$taskTypes[$ttype] ." tasks</b><hr>";
}
if (isset($id) && $id == $tid) {
print "<div style='position: absolute; padding-bottom: 2px; left:0px; background: #5c0120'> </div><li type=square class=selected>";
} else {
print "<li type=square class=row>";
}
print "<a href=\"javascript:delTask($tid);\"><img border=0 width=12 src='img/remove.png'></a> <a href='admin.php?section=task&id=$tid'>".$tarr[0]."</a> <font color=#444 title='this task has $tarr[2] annotations'>[".$tarr[2]."]</font></li>";
}
}
?>
<br><br>
</div>
<form id="tform" style='margin-right: -2px; border: 2px solid #5c0120; float:left; visibility: <?php echo $visibility_tform; ?>' name="tform" heigth=80 action="admin.php?section=task" method="post" enctype="multipart/form-data">
<input type=hidden name="id" value="<?php echo $id; ?>">
<input type=hidden name="ranges" id="ranges" value="">
<input type=hidden name="update" value="">
<table border=0 cellspacing=0 cellpadding=4>
<tr><th bgcolor=#ddd align=right>Task type: </th><td>
<?php
if ($id < 0) {
print "<select id=\"type\" name=\"type\" onchange=\"setMandatoryRanges(this)\"><option value=''> -- SELECT --\n";
while (list ($stype, $ltype) = each($taskTypes)) {
print "<option value='$stype'";
if ($stype == $taskinfo['type']) {
print " selected";
}
print ">".$ltype."\n";
}
} else {
print "<input type=hidden name=\"type\" value=\"".$taskinfo['type']."\">" .$taskTypes[$taskinfo['type']];
}
?>
</select></td></tr>
<tr><th bgcolor=#ddd align=right>
Task name:</th><td><input TYPE=text name="name" value="<?php echo $taskinfo['name']; ?>"> <font size=-1 color=gray>(es. TEST_Errors_EN-AR-ZH)</font> </td></tr>
<tr><th bgcolor=#ddd align=right valign=top>Short description:</th><td> <textarea rows="3" cols="50" NAME="descr" ><?php echo stripslashes($taskinfo['descr']); ?></textarea></td></tr>
<tr><th bgcolor=#ddd align=right valign=top>Instructions:</th><td>
<button onclick="return markup();" id=markupbutton>enable HTML editor</button><br>
<textarea id="markItUp" rows="7" cols="50" NAME="instructions"><?php echo stripslashes($taskinfo['instructions']); ?></textarea>
</td></tr>
<tr><th bgcolor=#ddd align=left colspan=2>Show systems output randomly: <input type="checkbox" name=randout
<?php
if ($taskinfo['randout'] == "Y") {
print " checked";
}
?>
></th></tr>
<tr><th bgcolor=#ddd align=left>Task customization<a href="#"><img src="img/question.png" width=18 onclick="alertify.alert('<table><td align=left><b>Quality</b>: You can choose the number of points in the rating scale. The `Label` of each point must be a number (typically from 0 or 1 to n), and correspond to the number that appears in the rating scale in the annotation interface. You can also choose the color displayed for each point in the scale.<hr><b>Error</b>: You can choose the number and type of errors you want to annotate. The `Label` of each error type appears in the error menu in the annotation interface. You can also choose a color for each error: the word(s) annotated with errors are displayed underlined with the color associated to the error.<hr><b>Word Alignment</b>: You can choose how many types of alignment you want to annotate and assign a color to each alignment type. In the annotation interface, at each click in the matrix cell the color of each given alignment type is displayed following the order set for the task.</td></table>'); return false;"></a>:</th>
<td>
<?php
$alreadyUsedValues = getUsedValues($id);
if (count($alreadyUsedValues) == 0 && $taskinfo['type'] != "docann") {
?>
<INPUT type="button" value="Use default setting" onclick="defaultRanges('<?php echo $taskinfo['type']; ?>')" /><a href="#"><img src="img/question.png" width=18 onclick="alertify.alert('<table><td align=left><b>Quality</b>: The default setting for the quality rating task is a 5-point rating scale\n<hr><b>Error</b>: The default error typology includes 6 classes: reordering errors, wrong lexical choices, missing word(s), superfluous word(s), morphology errors, casing and punctuation errors.\n<hr><b>Alignment</b>: The default setting for the word alignment task allows to annotate 2 alignment types, distinguishing between `possible` and `sure` alignments.</td></table>'); return false;"></a>
<?php
}
?>
</td></tr>
<tr><td colspan=2>
<div id="divranges"></div>
</td></tr>
<tr><td align=right colspan=2 align=center><div style="height: 100%; display: inline; top: 0px"><?php echo $cancelbutton; ?>
<!-- <input type="submit" name=update value="<?php echo $sentlabel; ?>"> -->
<button onclick="send(document.tform)"><?php echo $sentlabel; ?></button></div></td></tr>
</table>
</form>
</div>
<?php
#show the task ranges
if (isset($taskinfo["ranges"]) && $taskinfo["ranges"] != "[]" && $taskinfo["ranges"] != "") {
print "<script>showRanges($id,\"".$taskinfo["type"]."\",\"".$taskinfo["ranges"]."\");</script>";
} else {
print "<script>addRange($id,'');</script>";
}
?>
<script>
$('.spinner').hide();
var button = document.getElementById('newtask');
if (button != null) {
button.disabled = false;
}
</script>