/
admin_core.js
708 lines (615 loc) · 20.5 KB
/
admin_core.js
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
//$Id: admin_core.js 10154 2011-05-31 11:45:24Z c_schmitz $
$(document).ready(function(){
if(typeof(userdateformat) !== 'undefined')
{
$(".popupdate").each(function(i,e) {
format=$('#dateformat'+e.name).val();
if(!format) format = userdateformat;
$(e).datepicker({ dateFormat: format,
showOn: 'button',
changeYear: true,
changeMonth: true,
duration: 'fast'
}, $.datepicker.regional[userlanguage]);
});
$(".popupdatetime").datepicker({ dateFormat: userdateformat+' 00:00',
showOn: 'button',
changeYear: true,
changeMonth: true,
duration: 'fast'
}, $.datepicker.regional[userlanguage]);
}
$('button,input[type=submit],input[type=button],input[type=reset]').addClass("limebutton ui-state-default ui-corner-all");
$('button,input[type=submit],input[type=button],input[type=reset]').hover(
function(){
$(this).addClass("ui-state-hover");
},
function(){
$(this).removeClass("ui-state-hover");
}
)
// Loads the tooltips for the toolbars except the surveybar
$('img[alt],input[src]').not('.surveybar img').each(function() {
if($(this).attr('alt') != '')
{
$(this).qtip({
style: {name: 'light',
tip:true,
border: {
width: 1,
radius: 5
}
},
position: {adjust: {
screen: true, scroll:true},
corner: {
target: 'bottomRight'}
},
show: {effect: {length:50}},
hide: {when: 'mouseout'}
});
}
});
$(".progressbar").each(function(){
var pValue = parseInt($(this).attr('name'));
$(this).progressbar({
value: pValue
});
if (pValue > 85){
$("div",$(this)).css({ 'background': 'Red' });
}
$("div",this).html(pValue + "%");
});
$('label[title]').each(function() {
if($(this).attr('title') != '')
{
$(this).qtip({
style: {name: 'cream',
tip:true,
color:'#1D2D45',
border: {
width: 1,
radius: 5,
color: '#EADF95'}
},
position: {adjust: {
screen: true, scroll:true},
corner: {
target: 'bottomRight'}
},
show: {effect: {length:50}}
});
}
});
$('.dosurvey').qtip({
content:{
text:$('#dosurveylangpopup')
},
style: {name: 'cream',
tip:true,
color:'#1D2D45',
border: {
width: 1,
radius: 5,
color: '#EADF95'}
},
position: {adjust: {
screen: true, scroll:true},
corner: {
target: 'bottomMiddle',
tooltip: 'topMiddle'}
},
show: {effect: {length:50},
when: {
event:'click'
}},
hide: {fixed:true,
when: {
event:'unfocus'
}}
});
$('#previewquestion').qtip({
content:{
text:$('#previewquestionpopup')
},
style: {name: 'cream',
tip:true,
color:'#111111',
border: {
width: 1,
radius: 5,
color: '#EADF95'}
},
position: {adjust: {
screen: true, scroll:true},
corner: {
target: 'bottomMiddle',
tooltip: 'topMiddle'}
},
show: {effect: {length:50},
when: {
event:'click'
}},
hide: {fixed:true,
when: {
event:'unfocus'
}}
});
$('.tipme').each(function() {
if($(this).attr('alt') != '')
{
$(this).qtip({
style: {name: 'cream',
tip:true,
color:'#111111',
border: {
width: 1,
radius: 5,
color: '#EADF95'}
},
position: {adjust: {
screen: true, scroll:true},
corner: {
target: 'topRight',
tooltip: 'bottomLeft'
}
},
show: {effect: {length:100}}
});
}
});
if ($('#showadvancedattributes').length>0) updatequestionattributes();
$('#showadvancedattributes').click(function(){
$('#showadvancedattributes').hide();
$('#hideadvancedattributes').show();
$('#advancedquestionsettingswrapper').animate({
"height": "toggle", "opacity": "toggle"
});
})
$('#hideadvancedattributes').click(function(){
$('#showadvancedattributes').show();
$('#hideadvancedattributes').hide();
$('#advancedquestionsettingswrapper').animate({
"height": "toggle", "opacity": "toggle"
});
})
$('#question_type').change(updatequestionattributes);
$('#MinimizeGroupWindow').click(function(){
$('#groupdetails').hide();
});
$('#MaximizeGroupWindow').click(function(){
$('#groupdetails').show();
});
$('#tabs').tabs();
$("#flashmessage").notify().notify('create','themeroller',{},{custom:true,
speed: 500,
expires: 5000
});
if ($("#question_type").not('.none').length > 0 && $("#question_type").attr('type')!='hidden'){
$("#question_type").msDropDown({onInit:qTypeDropdownInit});
$("#question_type").change(function(event){
var selected_value = qDescToCode[''+$("#question_type_child .selected").text()];
OtherSelection(selected_value);
});
}
$("#question_type.none").change(function(event){
var selected_value = $("#question_type").val();
OtherSelection(selected_value);
});
});
function qTypeDropdownInit()
{
$("#question_type_child a").each(function(index,element){
$(element).qtip({
style: {
margin: 15,
width: 450,
height: 'auto',
border: {
width: 4,
radius: 2
}
},
content: getToolTip($(element).text()),
position: {
corner:{
target: 'leftMiddle',
tooltip:'rightMiddle'
},
adjust:{
screen: true
}
},
show: 'mouseover'
//hide: 'mouseout'
});
});
}
var aToolTipData = {
};
var qDescToCode;
var qCodeToInfo;
function getToolTip(type){
var code = qDescToCode[''+type];
var multiple = 0;
if (code=='S') multiple = 2;
if (code == ":") code = "COLON";
else if(code == "|") code = "PIPE";
else if(code == "*") code = "EQUATION";
if (multiple > 0){
returnval = '';
for(i=1;i<=multiple;i++){
returnval = returnval + "<img src='" + imgurl + "/screenshots/"+code+i+".png' /><br /><br />";
}
return returnval;
}
return "<img src='" + imgurl + "/screenshots/"+code+".png' />";
}
//We have form validation and other stuff..
function updatequestionattributes()
{
$('.loader').show();
$('#advancedquestionsettings').html('');
var selected_value = qDescToCode[''+$("#question_type_child .selected").text()];
if (selected_value==undefined) selected_value = $("#question_type").val();
$('#advancedquestionsettings').load(attr_url,{qid:$('#qid').val(),
question_type:selected_value,
sid:$('#sid').val()
}, function(){
// Loads the tooltips for the toolbars
// Loads the tooltips for the toolbars
$('.loader').hide();
$('label[title]').qtip({
style: {name: 'cream',
tip: true,
color:'#111111',
border: {
width: 1,
radius: 5,
color: '#EADF95'}
},
position: {adjust: {
screen: true, scroll:true},
corner: {
target: 'bottomRight'}
},
show: {effect: {length:50}}
});}
);
}
function validatefilename (form, strmessage )
{
if (form.the_file.value == "") {
alert( strmessage );
form.the_file.focus();
return false ;
}
return true ;
}
// If the length of the element's string is 0 then display helper message
function isEmpty(elem, helperMsg)
{
if($.trim(elem.value).length == 0){
alert(helperMsg);
elem.focus(); // set the focus to this input
return false;
}
return true;
}
function arrHasDupes( A ) { // finds any duplicate array elements using the fewest possible comparison
var i, j, n;
n=A.length;
// to ensure the fewest possible comparisons
for (i=0; i<n; i++) { // outer loop uses each item i at 0 through n
for (j=i+1; j<n; j++) { // inner loop only compares items j at i+1 to n
if (A[i]==A[j]) return true;
}}
return false;
}
// (c) 2006 Simon Wunderlin, License: GPL, hacks want to be free ;)
// This fix forces Firefox to fire the onchange event if someone changes select box with cursor keys
function ev_gecko_select_keyup_ev(Ev) {
// prevent tab, alt, ctrl keys from fireing the event
if (Ev.keyCode && (Ev.keyCode == 1 || Ev.keyCode == 9 ||
Ev.keyCode == 16 || Ev.altKey || Ev.ctrlKey))
return true;
Ev.target.onchange();
return true;
}
function init_gecko_select_hack() {
var selects = document.getElementsByTagName("SELECT");
for(i=0; i<selects.length; i++)
selects.item(i).addEventListener("keyup", ev_gecko_select_keyup_ev, false);
return true;
}
function getkey(e)
{
if (window.event) return window.event.keyCode;
else
if (e) return e.which;
else return null;
}
function goodchars(e, goods)
{
var key, keychar;
key = getkey(e);
if (key == null) return true;
// get character
keychar = String.fromCharCode(key);
keychar = keychar.toLowerCase();
goods = goods.toLowerCase();
// check goodkeys
if (goods.indexOf(keychar) != -1)
return true;
// control keys
if ( key==null || key==0 || key==8 || key==9 || key==27 )
return true;
// else return false
return false;
}
function trim(stringToTrim) {
return stringToTrim.replace(/^\s+|\s+$/g,"");
}
function DoAdd()
{
if (document.getElementById("available_languages").selectedIndex>-1)
{
var strText = document.getElementById("available_languages").options[document.getElementById("available_languages").selectedIndex].text;
var strId = document.getElementById("available_languages").options[document.getElementById("available_languages").selectedIndex].value;
AddItem(document.getElementById("additional_languages"), strText, strId);
RemoveItem(document.getElementById("available_languages"), document.getElementById("available_languages").selectedIndex);
sortSelect(document.getElementById("additional_languages"));
UpdateLanguageIDs();
}
}
function DoRemove(minItems,strmsg)
{
var strText = document.getElementById("additional_languages").options[document.getElementById("additional_languages").selectedIndex].text;
var strId = document.getElementById("additional_languages").options[document.getElementById("additional_languages").selectedIndex].value;
if (document.getElementById("additional_languages").options.length>minItems)
{
AddItem(document.getElementById("available_languages"), strText, strId);
RemoveItem(document.getElementById("additional_languages"), document.getElementById("additional_languages").selectedIndex);
sortSelect(document.getElementById("available_languages"));
UpdateLanguageIDs();
}
else
if (strmsg!=''){alert(strmsg);}
}
function AddItem(objListBox, strText, strId)
{
var newOpt;
newOpt = document.createElement("OPTION");
newOpt = new Option(strText,strId);
newOpt.id = strId;
objListBox.options[objListBox.length]=newOpt;
}
function RemoveItem(objListBox, strId)
{
if (strId > -1)
objListBox.options[strId]=null;
}
function GetItemIndex(objListBox, strId)
{
for (var i = 0; i < objListBox.children.length; i++)
{
var strCurrentValueId = objListBox.children[i].id;
if (strId == strCurrentValueId)
{
return i;
}
}
return -1;
}
function UpdateLanguageIDs(mylangs,confirmtxt)
{
document.getElementById("languageids").value = '';
var lbBox = document.getElementById("additional_languages");
for (var i = 0; i < lbBox.options.length; i++)
{
document.getElementById("languageids").value = document.getElementById("languageids").value + lbBox.options[i].value+ ' ';
}
if (mylangs)
{
if (checklangs(mylangs))
{
return true;
} else
{
return confirm(confirmtxt);
}
}
}
function compareText (option1, option2) {
return option1.text < option2.text ? -1 :
option1.text > option2.text ? 1 : 0;
}
function compareValue (option1, option2) {
return option1.value < option2.value ? -1 :
option1.value > option2.value ? 1 : 0;
}
function compareTextAsFloat (option1, option2) {
var value1 = parseFloat(option1.text);
var value2 = parseFloat(option2.text);
return value1 < value2 ? -1 :
value1 > value2 ? 1 : 0;
}
function compareValueAsFloat (option1, option2) {
var value1 = parseFloat(option1.value);
var value2 = parseFloat(option2.value);
return value1 < value2 ? -1 :
value1 > value2 ? 1 : 0;
}
function sortSelect (select, compareFunction) {
if (!compareFunction)
compareFunction = compareText;
var options = new Array (select.options.length);
for (var i = 0; i < options.length; i++)
options[i] =
new Option (
select.options[i].text,
select.options[i].value,
select.options[i].defaultSelected,
select.options[i].selected
);
options.sort(compareFunction);
select.options.length = 0;
for (var i = 0; i < options.length; i++)
select.options[i] = options[i];
}
function checklangs(mylangs)
{
selObject=document.getElementById("additional_languages");
var found;
for (x = 0; x < mylangs.length; x++)
{
found = 0;
for (i=0;i<selObject.options.length;i++)
{
if(selObject.options[i].value == mylangs[x])
{
found = 1;
break;
}
}
if (found == 0) {return false;}
}
return true;
}
function isset( variable )
{
return( typeof( variable ) != 'undefined' );
}
String.prototype.splitCSV = function(sep) {
for (var foo = this.split(sep = sep || ","), x = foo.length - 1, tl; x >= 0; x--) {
if (foo[x].replace(/"\s+$/, '"').charAt(foo[x].length - 1) == '"') {
if ((tl = foo[x].replace(/^\s+"/, '"')).length > 1 && tl.charAt(0) == '"') {
foo[x] = foo[x].replace(/^\s*"|"\s*$/g, '').replace(/""/g, '"');
} else if (x) {
foo.splice(x - 1, 2, [foo[x - 1], foo[x]].join(sep));
} else foo = foo.shift().split(sep).concat(foo);
} else foo[x].replace(/""/g, '"');
}return foo;
};
// This is a helper function to extract the question ID from a DOM ID element
function removechars(strtoconvert){
return strtoconvert.replace(/[-a-zA-Z_]/g,"");
}
function htmlspecialchars (string, quote_style, charset, double_encode) {
// Convert special characters to HTML entities
//
// version: 1109.2015
// discuss at: http://phpjs.org/functions/htmlspecialchars // + original by: Mirek Slugen
// + improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
// + bugfixed by: Nathan
// + bugfixed by: Arno
// + revised by: Kevin van Zonneveld (http://kevin.vanzonneveld.net) // + bugfixed by: Brett Zamir (http://brett-zamir.me)
// + input by: Ratheous
// + input by: Mailfaker (http://www.weedem.fr/)
// + reimplemented by: Brett Zamir (http://brett-zamir.me)
// + input by: felix // + bugfixed by: Brett Zamir (http://brett-zamir.me)
// % note 1: charset argument not supported
// * example 1: htmlspecialchars("<a href='test'>Test</a>", 'ENT_QUOTES');
// * returns 1: '<a href='test'>Test</a>'
// * example 2: htmlspecialchars("ab\"c'd", ['ENT_NOQUOTES', 'ENT_QUOTES']); // * returns 2: 'ab"c'd'
// * example 3: htmlspecialchars("my "&entity;" is still here", null, null, false);
// * returns 3: 'my "&entity;" is still here'
var optTemp = 0,
i = 0, noquotes = false;
if (typeof quote_style === 'undefined' || quote_style === null) {
quote_style = 2;
}
string = string.toString(); if (double_encode !== false) { // Put this first to avoid double-encoding
string = string.replace(/&/g, '&');
}
string = string.replace(/</g, '<').replace(/>/g, '>');
var OPTS = {
'ENT_NOQUOTES': 0,
'ENT_HTML_QUOTE_SINGLE': 1,
'ENT_HTML_QUOTE_DOUBLE': 2,
'ENT_COMPAT': 2, 'ENT_QUOTES': 3,
'ENT_IGNORE': 4
};
if (quote_style === 0) {
noquotes = true; }
if (typeof quote_style !== 'number') { // Allow for a single string or an array of string flags
quote_style = [].concat(quote_style);
for (i = 0; i < quote_style.length; i++) {
// Resolve string input to bitwise e.g. 'ENT_IGNORE' becomes 4
if (OPTS[quote_style[i]] === 0) {
noquotes = true;
}
else if (OPTS[quote_style[i]]) {
optTemp = optTemp | OPTS[quote_style[i]]; }
}
quote_style = optTemp;
}
if (quote_style & OPTS.ENT_HTML_QUOTE_SINGLE) { string = string.replace(/'/g, ''');
}
if (!noquotes) {
string = string.replace(/"/g, '"');
}
return string;
}
function saveaslabelset()
{
var lang = langs.split(";");
dataToSend = {};
dataToSend['langs'] = lang;
dataToSend['codelist'] = [];
$(".answertable:first tbody tr").each(function(i,e){
code = $(".code",e).attr('id');
code = code.split("_");
code = code[1];
dataToSend['codelist'].push(code);
var assessment_val = '0';
if ($("#assessment_"+code+"_0").length != 0 ){
assessment_val = $("#assessment_"+code+"_0").val();
}
dataToSend[code] = {
code: $("#code_"+code+"_0").val(),
assessmentvalue: assessment_val
};
$(lang).each(function(index,element){
dataToSend[code]['text_'+element] = $("#answer_"+element+"_"+code+"_0").val();
});
});
var label_name = prompt("Enter new label name", "");
var data = {
action: 'ajaxmodlabelsetanswers',
lid:'1',
dataToSend:js2php(dataToSend),
ajax:'1',
label_name:label_name,
languageids: dataToSend['langs'].join(" "),
checksessionbypost: $("[name=checksessionbypost]").val()
}
$.ajax({
type: 'POST',
url: 'admin.php',
data: data,
success: function(){
alert("Label successfully created");
}
});
}
function js2php(object){
var json = "{";
for (property in object){
var value = object[property];
if (typeof(value)=="string"){
json += '"'+property+'":"'+value.replace(/[\\"']/g, '\\$&')+'",'
}
else{
if (!value[0]){
json += '"'+property + '":'+js2php(value)+',';
}
else{
json += '"' + property + '":[';
for (prop in value) json += '"'+value[prop]+'",';
json = json.substr(0,json.length-1)+"],";
}
}
}
return json.substr(0,json.length-1)+ "}";
}