/
translate_functions.php
857 lines (797 loc) · 41.9 KB
/
translate_functions.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
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
<?php
/*
* LimeSurvey
* Copyright (C) 2007 The LimeSurvey Project Team / Carsten Schmitz
* All rights reserved.
* License: GNU/GPL License v2 or later, see LICENSE.php
* LimeSurvey is free software. This version may have been modified pursuant
* to the GNU General Public License, and as distributed it includes or
* is derivative of works licensed under the GNU General Public License or
* other free or open source software licenses.
* See COPYRIGHT.php for copyright notices and details.
*
* $Id: translate_functions.php 9586 2010-12-06 03:08:07Z c_schmitz $
*
*/
/**
* menuItem() creates a menu item with text and image in the admin screen menus
* @param string $menuText
* @global string $clang, $imageurl
* @return string
*/
function menuItem($menuText, $jsMenuText, $menuImageText, $menuImageFile, $scriptname)
{
global $clang, $imageurl;
$menu = ""
."<a href=\"#\" onclick=\"window.open('".$scriptname."', '_top')\""
."title='".$menuText."'>"
."<img name='".$menuImageText."' src='$imageurl/".$menuImageFile."' alt='"
.$jsMenuText."' /></a>\n"
."<img src='$imageurl/blank.gif' alt='' width='11' />\n";
return $menu;
}
/**
* menuSeparator() creates a separator bar in the admin screen menus
* @global string $imageurl
* @return string
*/
function menuSeparator()
{
global $imageurl;
return ("<img src='$imageurl/seperator.gif' alt='' />\n");
}
/**
* showTranslateAdminmenu() creates the main menu options for the survey translation page
* @param string $surveyid The survey ID
* @param string $survey_title
* @param string $tolang
* @param string $activated
* @param string $scriptname
* @global string $imageurl, $clang, $publicurl
* @return string
*/
function showTranslateAdminmenu($surveyid, $survey_title, $tolang, $scriptname)
{
global $imageurl, $clang, $publicurl;
$baselang = GetBaseLanguageFromSurveyID($surveyid);
$supportedLanguages = getLanguageData(false);
$langs = GetAdditionalLanguagesFromSurveyID($surveyid);
$adminmenu = ""
."<div class='menubar'>\n"
."<div class='menubar-title ui-widget-header'>\n"
."<strong>".$clang->gT("Translate survey").": $survey_title</strong>\n"
."</div>\n" // class menubar-title
."<div class='menubar-main'>\n";
$adminmenu .= ""
."<div class='menubar-left'>\n";
// Return to survey administration button
$adminmenu .= menuItem($clang->gT("Return to survey administration"),
$clang->gTview("Return to survey administration"),
"Administration", "home.png", "$scriptname?sid=$surveyid");
// Separator
$adminmenu .= menuSeparator();
// Test / execute survey button
if ($tolang != "")
{
$sumquery1 = "SELECT * FROM ".db_table_name('surveys')." inner join ".db_table_name('surveys_languagesettings')." on (surveyls_survey_id=sid and surveyls_language=language) WHERE sid=$surveyid"; //Getting data for this survey
$sumresult1 = db_select_limit_assoc($sumquery1, 1) ; //Checked
$surveyinfo = $sumresult1->FetchRow();
$surveyinfo = array_map('FlattenText', $surveyinfo);
$activated = $surveyinfo['active'];
if ($activated == "N")
{
$menutext=$clang->gT("Test This Survey");
$menutext2=$clang->gTview("Test This Survey");
} else
{
$menutext=$clang->gT("Execute This Survey");
$menutext2=$clang->gTview("Execute This Survey");
}
if (count(GetAdditionalLanguagesFromSurveyID($surveyid)) == 0)
{
$adminmenu .= menuItem($menutext, $menutext2, "do.png", "$publicurl/index.php?sid=$surveyid&newtest=Y&lang=$baselang");
}
else
{
$icontext = $clang->gT($menutext);
$icontext2 = $clang->gT($menutext);
$adminmenu .= "<a href='#' id='dosurvey' class='dosurvey'"
. "title=\"".$icontext2."\" accesskey='d'>"
. "<img src='$imageurl/do.png' alt='$icontext' />"
. "</a>\n";
$tmp_survlangs = GetAdditionalLanguagesFromSurveyID($surveyid);
$tmp_survlangs[] = $baselang;
rsort($tmp_survlangs);
// Test Survey Language Selection Popup
$adminmenu .="<div class=\"langpopup\" id=\"dosurveylangpopup\">"
.$clang->gT("Please select a language:")."<ul>";
foreach ($tmp_survlangs as $tmp_lang)
{
$adminmenu .= "<li><a accesskey='d' onclick=\"$('.dosurvey').qtip('hide');"
."\" target='_blank' href='{$publicurl}/index.php?sid=$surveyid&"
."newtest=Y&lang={$tmp_lang}'>".getLanguageNameFromCode($tmp_lang,false)."</a></li>";
}
$adminmenu .= "</ul></div>";
}
}
// End of survey-bar-left
$adminmenu .= "</div>";
// Survey language list
$selected = "";
if (!isset($tolang))
{
$selected = " selected='selected' ";
}
$adminmenu .= ""
."<div class='menubar-right'>\n"
."<span class=\"boxcaption\">".$clang->gT("Translate to").":</span>"
."<select onchange=\"window.open(this.options[this.selectedIndex].value,'_top')\">\n";
if (count(GetAdditionalLanguagesFromSurveyID($surveyid)) > 1)
{
$adminmenu .= "<option {$selected} value='$scriptname?action=translate&sid={$surveyid}'>".$clang->gT("Please choose...")."</option>\n";
}
foreach($langs as $lang)
{
$selected="";
if ($tolang==$lang)
{
$selected = " selected='selected' ";
}
$tolangtext = $supportedLanguages[$lang]['description'];
$adminmenu .= "<option {$selected} value='$scriptname?action=translate&sid={$surveyid}&tolang={$lang}'> " . $tolangtext ." </option>\n";
}
$adminmenu .= ""
."</select>\n"
."</div>\n"; // End of menubar-right
$adminmenu .= ""
."</div>\n";
$adminmenu .= ""
."</div>\n";
return($adminmenu);
}
/**
* setupTranslateFields() creates a customised array with database query
* information for use by survey translation
* @global $dbprefix, $clang;
* @param string $surveyid Survey id
* @param string $type Type of database field that is being translated, e.g. title, question, etc.
* @param string $baselang The source translation language code, e.g. "En"
* @param string $tolang The target translation language code, e.g. "De"
* @param string $new The new value of the translated string
* @param string $id1 An index variable used in the database select and update query
* @param string $id2 An index variable used in the database select and update query
* @return array
*/
function setupTranslateFields($surveyid, $type, $tolang, $baselang, $id1="", $id2="", $new="")
{
global $dbprefix, $clang;
switch ( $type )
{
case 'title':
$amTypeOptions = array(
"querybase" => "SELECT * "
."FROM ".db_table_name('surveys_languagesettings')
." WHERE surveyls_survey_id=".db_quoteall($surveyid,true)
." AND surveyls_language=".db_quoteall($baselang,true),
"queryto" => "SELECT * "
." FROM ".db_table_name('surveys_languagesettings')
." WHERE surveyls_survey_id=".db_quoteall($surveyid,true)
." AND surveyls_language=".db_quoteall($tolang,true),
"queryupdate" => "UPDATE ".db_table_name('surveys_languagesettings')
." SET surveyls_title = ".db_quoteall($new,true)
." WHERE surveyls_survey_id=".db_quoteall($surveyid,true)
." AND surveyls_language=".db_quoteall($tolang,true),
"id1" => "",
"id2" => "",
"gid" => FALSE,
"qid" => FALSE,
"dbColumn" => 'surveyls_title',
"description" => $clang->gT("Survey title and description"),
"HTMLeditorType" => "title", // This value is passed to HTML editor and determines LimeReplacementFields
"HTMLeditorDisplay" => "Inline", // Allowed values: Inline, Popup or None
"associated" => "description"
);
break;
case 'description':
$amTypeOptions = array(
"querybase" => "SELECT * "
." FROM ".db_table_name('surveys_languagesettings')
." WHERE surveyls_survey_id=".db_quoteall($surveyid,true)
." AND surveyls_language='{$baselang}' ",
"queryto" => "SELECT * "
." FROM ".db_table_name('surveys_languagesettings')
." WHERE surveyls_survey_id=".db_quoteall($surveyid,true)
." AND surveyls_language='{$tolang}' ",
"queryupdate" => "UPDATE ".db_table_name('surveys_languagesettings')
." SET surveyls_description = ".db_quoteall($new,true)
." WHERE surveyls_survey_id=".db_quoteall($surveyid,true)
." AND surveyls_language='{$tolang}'",
"id1" => "",
"id2" => "",
"gid" => FALSE,
"qid" => FALSE,
"dbColumn" => 'surveyls_description',
"description" => $clang->gT("Description:"),
"HTMLeditorType" => "description", // This value is passed to HTML editor and determines LimeReplacementFields
"HTMLeditorDisplay" => "Inline", // Allowed values: Inline, Popup or None
"associated" => ""
);
break;
case 'welcome':
$amTypeOptions = array(
"querybase" => "SELECT * "
." FROM ".db_table_name('surveys_languagesettings')
." WHERE surveyls_survey_id=".db_quoteall($surveyid,true)
." AND surveyls_language='{$baselang}' ",
"queryto" => "SELECT * "
." FROM ".db_table_name('surveys_languagesettings')
." WHERE surveyls_survey_id=".db_quoteall($surveyid,true)
." AND surveyls_language='{$tolang}' ",
"queryupdate" => "UPDATE ".db_table_name('surveys_languagesettings')
." SET surveyls_welcometext = ".db_quoteall($new,true)
." WHERE surveyls_survey_id=".db_quoteall($surveyid,true)
." AND surveyls_language='{$tolang}'",
"id1" => "",
"id2" => "",
"gid" => FALSE,
"qid" => FALSE,
"dbColumn" => 'surveyls_welcometext',
"description" => $clang->gT("Welcome and end text"),
"HTMLeditorType" => "welcome", // This value is passed to HTML editor and determines LimeReplacementFields
"HTMLeditorDisplay" => "Inline", // Allowed values: Inline, Popup or None
"associated" => "end"
);
break;
case 'end':
$amTypeOptions = array(
"querybase" => "SELECT * "
." FROM ".db_table_name('surveys_languagesettings')
." WHERE surveyls_survey_id=".db_quoteall($surveyid,true)
." AND surveyls_language='{$baselang}' ",
"queryto" => "SELECT * "
." FROM ".db_table_name('surveys_languagesettings')
." WHERE surveyls_survey_id=".db_quoteall($surveyid,true)
." AND surveyls_language='{$tolang}' ",
"queryupdate" => "UPDATE ".db_table_name('surveys_languagesettings')
." SET surveyls_endtext = ".db_quoteall($new,true)
." WHERE surveyls_survey_id=".db_quoteall($surveyid,true)
." AND surveyls_language='{$tolang}'",
"id1" => "",
"id2" => "",
"gid" => FALSE,
"qid" => FALSE,
"dbColumn" => 'surveyls_endtext',
"description" => $clang->gT("End message:"),
"HTMLeditorType" => "end", // This value is passed to HTML editor and determines LimeReplacementFields
"HTMLeditorDisplay" => "Inline", // Allowed values: Inline, Popup or None
"associated" => ""
);
break;
case 'group':
$amTypeOptions = array(
"querybase" => "SELECT * "
." FROM ".db_table_name('groups')
." WHERE sid=".db_quoteall($surveyid,true)
." AND language='{$baselang}' "
." ORDER BY group_order ",
"queryto" => "SELECT * "
." FROM ".db_table_name('groups')
." WHERE sid=".db_quoteall($surveyid,true)
." AND language=".db_quoteall($tolang,true)
." ORDER BY group_order ",
"queryupdate" => "UPDATE ".db_table_name('groups')
." SET group_name = ".db_quoteall($new,true)
." WHERE gid = '{$id1}' "
." AND sid=".db_quoteall($surveyid,true)
." AND language='{$tolang}'",
"id1" => "gid",
"id2" => "",
"gid" => TRUE,
"qid" => FALSE,
"dbColumn" => "group_name",
"description" => $clang->gT("Question groups"),
"HTMLeditorType" => "group", // This value is passed to HTML editor and determines LimeReplacementFields
"HTMLeditorDisplay" => "Popup", // Allowed values: Inline, Popup or None
"associated" => "group_desc"
);
break;
case 'group_desc':
$amTypeOptions = array(
"querybase" => "SELECT * "
." FROM ".db_table_name('groups')
." WHERE sid=".db_quoteall($surveyid,true)
." AND language='{$baselang}' "
." ORDER BY group_order ",
"queryto" => "SELECT *"
." FROM ".db_table_name('groups')
." WHERE sid=".db_quoteall($surveyid,true)
." AND language=".db_quoteall($tolang,true)
." ORDER BY group_order ",
"queryupdate" => "UPDATE ".db_table_name('groups')
." SET description = ".db_quoteall($new,true)
." WHERE gid = '{$id1}' "
." AND sid=".db_quoteall($surveyid,true)." "
." AND language='{$tolang}'",
"id1" => "gid",
"id2" => "",
"gid" => TRUE,
"qid" => FALSE,
"dbColumn" => "description",
"description" => $clang->gT("Group description"),
"HTMLeditorType" => "group_desc", // This value is passed to HTML editor and determines LimeReplacementFields
"HTMLeditorDisplay" => "Popup", // Allowed values: Inline, Popup or None
"associated" => ""
);
break;
case 'question':
$amTypeOptions = array(
"querybase" => "SELECT q.qid as questionid, q.title, q.question, q.qid, q.gid "
." FROM ".db_table_name('questions')." q "
." JOIN ".db_table_name('groups')." g ON g.gid=q.gid "
." WHERE q.sid=".db_quoteall($surveyid,true)
." AND q.language='{$baselang}' "
." AND g.language='{$baselang}' "
." AND parent_qid=0 "
." ORDER BY group_order,question_order, scale_id ",
"queryto" => "SELECT q.qid as questionid, q.title, q.question, q.qid, q.gid "
." FROM ".db_table_name('questions')." q "
." JOIN ".db_table_name('groups')." g ON g.gid=q.gid "
." WHERE q.sid=".db_quoteall($surveyid,true)
." AND q.language='{$tolang}' "
." AND g.language='{$tolang}' "
." AND parent_qid=0 "
." ORDER BY group_order,question_order, scale_id ",
"queryupdate" => "UPDATE ".db_table_name('questions')
." SET question = ".db_quoteall($new,true)
." WHERE qid = '{$id1}' "
." AND sid=".db_quoteall($surveyid,true)
." AND parent_qid=0 "
." AND language='{$tolang}'",
"dbColumn" => 'question',
"id1" => 'qid',
"id2" => "",
"gid" => TRUE,
"qid" => TRUE,
"description" => $clang->gT("Questions"),
"HTMLeditorType" => "question", // This value is passed to HTML editor and determines LimeReplacementFields
"HTMLeditorDisplay" => "Popup", // Allowed values: Inline, Popup or ""
"associated" => "question_help"
);
break;
case 'question_help':
$amTypeOptions = array(
"querybase" => "SELECT q.qid as questionid, q.help, q.qid, q.title "
." FROM ".db_table_name('questions')." q "
." JOIN ".db_table_name('groups')." g ON g.gid=q.gid "
." WHERE g.sid=".db_quoteall($surveyid,true)
." AND q.language='{$baselang}' "
." AND g.language='{$baselang}' "
." AND parent_qid=0 "
." ORDER BY group_order,question_order ",
"queryto" => "SELECT q.qid as questionid, q.help, q.qid, q.title "
." FROM ".db_table_name('questions')." q "
." JOIN ".db_table_name('groups')." g ON g.gid=q.gid "
." WHERE g.sid=".db_quoteall($surveyid,true)
." AND q.language='{$tolang}' "
." AND g.language='{$tolang}' "
." AND parent_qid=0 "
." ORDER BY g.group_order,q.question_order ",
"queryupdate" => "UPDATE ".db_table_name('questions')
." SET help = ".db_quoteall($new,true)
." WHERE qid = '{$id1}' "
." AND sid=".db_quoteall($surveyid,true)
." AND parent_qid=0 "
." AND language='{$tolang}'",
"dbColumn" => 'help',
"id1" => 'qid',
"id2" => "",
"gid" => TRUE,
"qid" => TRUE,
"description" => "",
"HTMLeditorType" => "question_help", // This value is passed to HTML editor and determines LimeReplacementFields
"HTMLeditorDisplay" => "Popup", // Allowed values: Inline, Popup or ""
"associated" => ""
);
break;
case 'subquestion':
$amTypeOptions = array(
"querybase" => "SELECT q.qid as questionid, q.title, sq.qid, sq.question, sq.gid "
." FROM ".db_table_name('questions')." sq "
." JOIN ".db_table_name('questions')." q ON sq.parent_qid=q.qid "
." JOIN ".db_table_name('groups')." g ON g.gid=q.gid "
." WHERE sq.sid=".db_quoteall($surveyid,true)
." AND sq.language='{$baselang}' AND q.language='{$baselang}' AND g.language='{$baselang}' AND sq.parent_qid>0 "
." ORDER BY g.group_order, q.question_order, q.scale_id, sq.question_order, sq.scale_id ",
"queryto" => "SELECT sq.question "
." FROM ".db_table_name('questions')." sq "
." JOIN ".db_table_name('questions')." q ON sq.parent_qid=q.qid "
." JOIN ".db_table_name('groups')." g ON g.gid=q.gid "
." WHERE sq.sid=".db_quoteall($surveyid,true)
." AND sq.language=".db_quoteall($tolang,true)." AND q.language=".db_quoteall($tolang,true)." AND g.language=".db_quoteall($tolang,true)." AND sq.parent_qid>0 "
." ORDER BY g.group_order, q.question_order, q.scale_id, sq.question_order, sq.scale_id ",
"queryupdate" => "UPDATE ".db_table_name('questions')
." SET question = ".db_quoteall($new,true)
." WHERE qid = '{$id1}' "
." AND sid=".db_quoteall($surveyid,true)
." AND language='{$tolang}'",
"dbColumn" => 'question',
"id1" => 'qid',
"id2" => "",
"gid" => TRUE,
"qid" => TRUE,
"description" => $clang->gT("Subquestions"),
"HTMLeditorType" => "question", // This value is passed to HTML editor and determines LimeReplacementFields
"HTMLeditorDisplay" => "Popup", // Allowed values: Inline, Popup or None
"associated" => ""
);
break;
case 'answer':
$amTypeOptions = array(
"querybase" => "SELECT q.qid as questionid, a.code, a.answer, q.qid, q.title "
." FROM ".db_table_name('answers')." a "
." JOIN ".db_table_name('questions')." q ON a.qid=q.qid "
." JOIN ".db_table_name('groups')." g ON g.gid=q.gid "
." WHERE q.sid ='{$surveyid}' "
." AND q.qid = q.qid "
." AND a.language = '{$baselang}'"
." AND q.language = '{$baselang}'"
." AND g.language = '{$baselang}'"
." ORDER BY g.group_order, q.question_order, a.sortorder, a.scale_id",
"queryto" => "SELECT a.code, a.answer, q.qid, q.title "
." FROM ".db_table_name('answers')." a "
." JOIN ".db_table_name('questions')." q ON a.qid=q.qid "
." JOIN ".db_table_name('groups')." g ON g.gid=q.gid "
." WHERE q.sid ='{$surveyid}' "
." AND q.qid = q.qid "
." AND a.language = ".db_quoteall($tolang,true)
." AND q.language = ".db_quoteall($tolang,true)
." AND g.language = ".db_quoteall($tolang,true)
." ORDER BY g.group_order, q.question_order, a.sortorder, a.scale_id",
"queryupdate" => "UPDATE ".db_table_name('answers')
." SET answer = ".db_quoteall($new,true)
." WHERE qid = '{$id1}' "
." AND code='{$id2}' "
." AND language='{$tolang}'",
"dbColumn" => 'answer',
"id1" => 'qid',
"id2" => 'code',
"gid" => FALSE,
"qid" => TRUE,
"description" => $clang->gT("Answer options"),
"HTMLeditorType" => "subquestion", // This value is passed to HTML editor and determines LimeReplacementFields
"HTMLeditorDisplay" => "Popup", // Allowed values: Inline, Popup or None
"associated" => ""
);
break;
case 'emailinvite':
$amTypeOptions = array(
"querybase" => "SELECT * FROM ".db_table_name("surveys_languagesettings")
." WHERE surveyls_survey_id=$surveyid and surveyls_language='$baselang'" ,
"queryto" => "SELECT * FROM ".db_table_name("surveys_languagesettings")
." WHERE surveyls_survey_id=$surveyid and surveyls_language='$tolang'" ,
"queryupdate" => "UPDATE ".db_table_name("surveys_languagesettings")
."SET surveyls_email_invite_subj = ".db_quoteall($new,true)
." WHERE surveyls_survey_id=$surveyid "
." AND surveyls_language='$tolang'",
"dbColumn" => 'surveyls_email_invite_subj',
"id1" => '',
"id2" => '',
"gid" => FALSE,
"qid" => FALSE,
"description" => $clang->gT("Invitation email"),
"HTMLeditorType" => "email", // This value is passed to HTML editor and determines LimeReplacementFields
"HTMLeditorDisplay" => "", // Allowed values: Inline, Popup or ""
"associated" => "emailinvitebody"
);
break;
case 'emailinvitebody':
$amTypeOptions = array(
"querybase" => "SELECT * FROM ".db_table_name("surveys_languagesettings")
." WHERE surveyls_survey_id=$surveyid and surveyls_language='$baselang'" ,
"queryto" => "SELECT * FROM ".db_table_name("surveys_languagesettings")
." WHERE surveyls_survey_id=$surveyid and surveyls_language='$tolang'" ,
"queryupdate" => "UPDATE ".db_table_name("surveys_languagesettings")
." SET surveyls_email_invite = ".db_quoteall($new,true)
." WHERE surveyls_survey_id=$surveyid "
." AND surveyls_language='$tolang'",
"dbColumn" => 'surveyls_email_invite',
"id1" => '',
"id2" => '',
"gid" => FALSE,
"qid" => FALSE,
"description" => "",
"HTMLeditorType" => "email", // This value is passed to HTML editor and determines LimeReplacementFields
"HTMLeditorDisplay" => "", // Allowed values: Inline, Popup or ""
"associated" => ""
);
break;
case 'emailreminder':
$amTypeOptions = array(
"querybase" => "SELECT * FROM ".db_table_name("surveys_languagesettings")
." WHERE surveyls_survey_id=$surveyid and surveyls_language='$baselang'" ,
"queryto" => "SELECT * FROM ".db_table_name("surveys_languagesettings")
." WHERE surveyls_survey_id=$surveyid and surveyls_language='$tolang'" ,
"queryupdate" => "UPDATE ".db_table_name("surveys_languagesettings")
." SET surveyls_email_remind_subj = ".db_quoteall($new,true)
." WHERE surveyls_survey_id=$surveyid "
." AND surveyls_language='$tolang'",
"dbColumn" => 'surveyls_email_remind_subj',
"id1" => '',
"id2" => '',
"gid" => FALSE,
"qid" => FALSE,
"description" => $clang->gT("Reminder email"),
"HTMLeditorType" => "email", // This value is passed to HTML editor and determines LimeReplacementFields
"HTMLeditorDisplay" => "", // Allowed values: Inline, Popup or ""
"associated" => "emailreminderbody"
);
break;
case 'emailreminderbody':
$amTypeOptions = array(
"querybase" => "SELECT * FROM ".db_table_name("surveys_languagesettings")
." WHERE surveyls_survey_id=$surveyid and surveyls_language='$baselang'" ,
"queryto" => "SELECT * FROM ".db_table_name("surveys_languagesettings")
." WHERE surveyls_survey_id=$surveyid and surveyls_language='$tolang'" ,
"queryupdate" => "UPDATE ".db_table_name("surveys_languagesettings")
." SET surveyls_email_remind = ".db_quoteall($new,true)
." WHERE surveyls_survey_id=$surveyid "
."AND surveyls_language='$tolang'",
"dbColumn" => 'surveyls_email_remind',
"id1" => '',
"id2" => '',
"gid" => FALSE,
"qid" => FALSE,
"description" => "",
"HTMLeditorType" => "email", // This value is passed to HTML editor and determines LimeReplacementFields
"HTMLeditorDisplay" => "", // Allowed values: Inline, Popup or ""
"associated" => ""
);
break;
case 'emailconfirmation':
$amTypeOptions = array(
"querybase" => "SELECT * FROM ".db_table_name("surveys_languagesettings")
." WHERE surveyls_survey_id=$surveyid and surveyls_language='$baselang'" ,
"queryto" => "SELECT * FROM ".db_table_name("surveys_languagesettings")
." WHERE surveyls_survey_id=$surveyid and surveyls_language='$tolang'" ,
"queryupdate" => "UPDATE ".db_table_name("surveys_languagesettings")
." SET surveyls_email_confirm_subj = ".db_quoteall($new,true)
." WHERE surveyls_survey_id=$surveyid "
." AND surveyls_language='$tolang'",
"dbColumn" => 'surveyls_email_confirm_subj',
"id1" => '',
"id2" => '',
"gid" => FALSE,
"qid" => FALSE,
"description" => $clang->gT("Confirmation email"),
"HTMLeditorType" => "email", // This value is passed to HTML editor and determines LimeReplacementFields
"HTMLeditorDisplay" => "", // Allowed values: Inline, Popup or ""
"associated" => "emailconfirmationbody"
);
break;
case 'emailconfirmationbody':
$amTypeOptions = array(
"querybase" => "SELECT * FROM ".db_table_name("surveys_languagesettings")
." WHERE surveyls_survey_id=$surveyid and surveyls_language='$baselang'" ,
"queryto" => "SELECT * FROM ".db_table_name("surveys_languagesettings")
." WHERE surveyls_survey_id=$surveyid and surveyls_language='$tolang'" ,
"queryupdate" => "UPDATE ".db_table_name("surveys_languagesettings")
."SET surveyls_email_confirm = ".db_quoteall($new,true)
." WHERE surveyls_survey_id=$surveyid "
." AND surveyls_language='$tolang'",
"dbColumn" => 'surveyls_email_confirm',
"id1" => '',
"id2" => '',
"gid" => FALSE,
"qid" => FALSE,
"description" => "",
"HTMLeditorType" => "email", // This value is passed to HTML editor and determines LimeReplacementFields
"HTMLeditorDisplay" => "", // Allowed values: Inline, Popup or ""
"associated" => ""
);
break;
case 'emailregistration':
$amTypeOptions = array(
"querybase" => "SELECT * FROM ".db_table_name("surveys_languagesettings")
." WHERE surveyls_survey_id=$surveyid and surveyls_language='$baselang'" ,
"queryto" => "SELECT * FROM ".db_table_name("surveys_languagesettings")
." WHERE surveyls_survey_id=$surveyid and surveyls_language='$tolang'" ,
"queryupdate" => "UPDATE ".db_table_name("surveys_languagesettings")
."SET surveyls_email_register_subj = ".db_quoteall($new,true)
." WHERE surveyls_survey_id=$surveyid "
." AND surveyls_language='$tolang'",
"dbColumn" => 'surveyls_email_register_subj',
"id1" => '',
"id2" => '',
"gid" => FALSE,
"qid" => FALSE,
"description" => $clang->gT("Registration email"),
"HTMLeditorType" => "email", // This value is passed to HTML editor and determines LimeReplacementFields
"HTMLeditorDisplay" => "", // Allowed values: Inline, Popup or ""
"associated" => "emailregistrationbody"
);
break;
case 'emailregistrationbody':
$amTypeOptions = array(
"querybase" => "SELECT * FROM ".db_table_name("surveys_languagesettings")
." WHERE surveyls_survey_id=$surveyid and surveyls_language='$baselang'" ,
"queryto" => "SELECT * FROM ".db_table_name("surveys_languagesettings")
." WHERE surveyls_survey_id=$surveyid and surveyls_language='$tolang'" ,
"queryupdate" => "UPDATE ".db_table_name("surveys_languagesettings")
."SET surveyls_email_register = ".db_quoteall($new,true)
." WHERE surveyls_survey_id=$surveyid "
."AND surveyls_language='$tolang'",
"dbColumn" => 'surveyls_email_register',
"id1" => '',
"id2" => '',
"gid" => FALSE,
"qid" => FALSE,
"description" => "",
"HTMLeditorType" => "email", // This value is passed to HTML editor and determines LimeReplacementFields
"HTMLeditorDisplay" => "", // Allowed values: Inline, Popup or ""
"associated" => ""
);
break;
case 'email_confirm':
$amTypeOptions = array(
"querybase" => "SELECT * FROM ".db_table_name("surveys_languagesettings")
." WHERE surveyls_survey_id=$surveyid and surveyls_language='$baselang'" ,
"queryto" => "SELECT * FROM ".db_table_name("surveys_languagesettings")
." WHERE surveyls_survey_id=$surveyid and surveyls_language='$tolang'" ,
"queryupdate" => "UPDATE ".db_table_name("surveys_languagesettings")
." SET surveyls_email_confirm_subj = ".db_quoteall($new,true)
." WHERE surveyls_survey_id=$surveyid "
." AND surveyls_language='$tolang'",
"dbColumn" => 'surveyls_email_confirm_subj',
"id1" => '',
"id2" => '',
"gid" => FALSE,
"qid" => FALSE,
"description" => $clang->gT("Confirmation email"),
"HTMLeditorType" => "email", // This value is passed to HTML editor and determines LimeReplacementFields
"HTMLeditorDisplay" => "", // Allowed values: Inline, Popup or ""
"associated" => "email_confirmbody"
);
break;
case 'email_confirmbody':
$amTypeOptions = array(
"querybase" => "SELECT * FROM ".db_table_name("surveys_languagesettings")
." WHERE surveyls_survey_id=$surveyid and surveyls_language='$baselang'" ,
"queryto" => "SELECT * FROM ".db_table_name("surveys_languagesettings")
." WHERE surveyls_survey_id=$surveyid and surveyls_language='$tolang'" ,
"queryupdate" => "UPDATE ".db_table_name("surveys_languagesettings")
." SET surveyls_email_confirm = ".db_quoteall($new,true)
." WHERE surveyls_survey_id=$surveyid "
." AND surveyls_language='$tolang'",
"dbColumn" => 'surveyls_email_confirm',
"id1" => '',
"id2" => '',
"gid" => FALSE,
"qid" => FALSE,
"description" => "",
"HTMLeditorType" => "email", // This value is passed to HTML editor and determines LimeReplacementFields
"HTMLeditorDisplay" => "", // Allowed values: Inline, Popup or ""
"associated" => ""
);
break;
}
return($amTypeOptions);
}
/**
* displayTranslateFieldsHeader() Formats and displays header of translation fields table
* @param string $baselangdesc The source translation language, e.g. "English"
* @param string $tolangdesc The target translation language, e.g. "German"
* @param string $type The target translation language, e.g. "German"
* @return string $translateoutput
*/
function displayTranslateFieldsHeader($baselangdesc, $tolangdesc, $type)
{
global $clang;
$translateoutput = '<table class="translate">';
if ($type=='question' || $type=='subquestion' || $type=='question_help' || $type=='answer')
{
$translateoutput.='<colgroup valign="top" width="8%" />';
}
$translateoutput.='<colgroup valign="top" width="37%" />'
. '<colgroup valign="top" width="55%" />'
. "<tr>\n";
if ($type=='question' || $type=='subquestion' || $type=='question_help' || $type=='answer')
{
$translateoutput.="<th>{$clang->gT('Question code / ID')}</th>\n";
}
$translateoutput.="<th>{$baselangdesc}</th>\n"
. "<th>{$tolangdesc}</th>\n"
. "</tr>\n";
return($translateoutput);
}
/**
* displayTranslateFieldsFooter() Formats and displays footer of translation fields table
* @return string $translateoutput
*/
function displayTranslateFieldsFooter()
{
$translateoutput = ""
. "</table>\n";
return($translateoutput);
}
/**
* displayTranslateFields() Formats and displays translation fields (base language as well as to language)
* @global $dbprefix, $clang;
* @param string $surveyid Survey id
* @param string $gid Group id
* @param string $qid Question id
* @param string $type Type of database field that is being translated, e.g. title, question, etc.
* @param array $amTypeOptions Array containing options associated with each $type
* @param string $baselangdesc The source translation language, e.g. "English"
* @param string $tolangdesc The target translation language, e.g. "German"
* @param string $textfrom The text to be translated in source language
* @param string $textto The text to be translated in target language
* @param integer $i Counter
* @param string $rowfrom Contains current row of database query
* @param boolean $evenRow True for even rows, false for odd rows
* @return string $translateoutput
*/
function displayTranslateFields($surveyid, $gid, $qid, $type, $amTypeOptions,
$baselangdesc, $tolangdesc, $textfrom, $textto, $i, $rowfrom, $evenRow)
{
$translateoutput = "";
if ($evenRow)
{
$translateoutput .= "<tr class=\"odd\">";
}
else
{
$translateoutput .= "<tr class=\"even\">";
}
$value1 = "";
if ($amTypeOptions["id1"] != "") $value1 = $rowfrom[$amTypeOptions["id1"]];
$value2 = "";
if ($amTypeOptions["id2"] != "") $value2 = $rowfrom[$amTypeOptions["id2"]];
// Display text in original language
// Display text in foreign language. Save a copy in type_oldvalue_i to identify changes before db update
if ($type=='question' || $type=='subquestion' || $type=='question_help' || $type=='answer')
{
$translateoutput .= ""
. "<td>".htmlspecialchars($rowfrom['title'])." ({$rowfrom['questionid']})</td>\n";
}
$translateoutput .= "<td class='_from_' id='${type}_from_${i}'>$textfrom</td>\n"
. "<td>\n";
$translateoutput .= "<input type='hidden' name='{$type}_id1_{$i}' value='{$value1}' />\n";
$translateoutput .= "<input type='hidden' name='{$type}_id2_{$i}' value='{$value2}' />\n";
$nrows = max(calc_nrows($textfrom), calc_nrows($textto));
$translateoutput .= "<input type='hidden' "
."name='".$type."_oldvalue_".$i."' "
."value='".htmlspecialchars($textto, ENT_QUOTES)."' />\n";
$translateoutput .= "<textarea cols='75' rows='".($nrows)."' "
." name='{$type}_newvalue_{$i}' >".htmlspecialchars($textto)."</textarea>\n";
if ($amTypeOptions["HTMLeditorDisplay"]=="Inline")
{
$translateoutput .= ""
.getEditor("edit".$type , $type."_newvalue_".$i, htmlspecialchars($textto), $surveyid, $gid, $qid, "translate".$amTypeOptions["HTMLeditorType"]);
}
if ($amTypeOptions["HTMLeditorDisplay"]=="Popup")
{
$translateoutput .= ""
.getPopupEditor("edit".$type , $type."_newvalue_".$i, urlencode($amTypeOptions['description']), $surveyid, $gid, $qid, "translate".$amTypeOptions["HTMLeditorType"]);
}
$translateoutput .= "\n</td>\n"
. "</tr>\n";
return($translateoutput);
}
/**
* calc_nrows($subject) calculates the vertical size of textbox for survey translation.
* The function adds the number of line breaks <br /> to the number of times a string wrap occurs.
* @param string $subject The text string that is being translated
* @return integer
*/
function calc_nrows( $subject )
{
// Determines the size of the text box
// A proxy for box sixe is string length divided by 80
$pattern = "(<br..?>)";
//$pattern = "/\n/";
$pattern = '[(<br..?>)|(/\n/)]';
$nrows_newline = preg_match_all($pattern, $subject, $matches);
$nrows_char = ceil(strlen((string)$subject)/80);
return $nrows_newline + $nrows_char;
}
?>