/
tokens.php
3256 lines (2962 loc) · 162 KB
/
tokens.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
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?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$
*/
# TOKENS FILE
include_once("login_check.php");
if ($enableLdap)
{
require_once(dirname(__FILE__).'/../config-ldap.php');
}
if (!isset($surveyid)) {$surveyid=returnglobal('sid');}
if (!isset($order)) {$order=preg_replace('/[^_ a-z0-9-]/i', '', returnglobal('order'));}
if (!isset($limit)) {$limit=(int)returnglobal('limit');}
if ($limit==0) $limit=50;
if (!isset($start)) {$start=(int)returnglobal('start');}
if (!isset($searchstring)) {$searchstring=returnglobal('searchstring');}
if (!isset($tokenid)) {$tokenid=returnglobal('tid');}
if (!isset($tokenids)) {$tokenids=returnglobal('tids');}
if (!isset($gtokenid)) {$gtokenid=returnglobal('gtid');}
if (!isset($gtokenids)) {$gtokenids=returnglobal('gtids');}
if (!isset($starttokenid)) {$starttokenid=sanitize_int(returnglobal('last_tid'));}
if(isset($tokenids)) {
$tokenidsarray=explode("|", substr($tokenids, 1)); //Make the tokenids string into an array, and exclude the first character
unset($tokenids);
foreach($tokenidsarray as $tokenitem) {
if($tokenitem != "") $tokenids[]=sanitize_int($tokenitem);
}
}
include_once("login_check.php");
include_once("database.php");
$js_admin_includes[]='scripts/tokens.js';
$dateformatdetails=getDateFormatData($_SESSION['dateformat']);
$thissurvey=getSurveyInfo($surveyid);
if ($subaction == "import" || $subaction == "upload" ) // THis array only needs to be defined for these two functions
{
$js_admin_includes[]='scripts/tokens.js';
$encodingsarray = array("armscii8"=>$clang->gT("ARMSCII-8 Armenian")
,"ascii"=>$clang->gT("US ASCII")
,"auto"=>$clang->gT("Automatic")
,"big5"=>$clang->gT("Big5 Traditional Chinese")
,"binary"=>$clang->gT("Binary pseudo charset")
,"cp1250"=>$clang->gT("Windows Central European")
,"cp1251"=>$clang->gT("Windows Cyrillic")
,"cp1256"=>$clang->gT("Windows Arabic")
,"cp1257"=>$clang->gT("Windows Baltic")
,"cp850"=>$clang->gT("DOS West European")
,"cp852"=>$clang->gT("DOS Central European")
,"cp866"=>$clang->gT("DOS Russian")
,"cp932"=>$clang->gT("SJIS for Windows Japanese")
,"dec8"=>$clang->gT("DEC West European")
,"eucjpms"=>$clang->gT("UJIS for Windows Japanese")
,"euckr"=>$clang->gT("EUC-KR Korean")
,"gb2312"=>$clang->gT("GB2312 Simplified Chinese")
,"gbk"=>$clang->gT("GBK Simplified Chinese")
,"geostd8"=>$clang->gT("GEOSTD8 Georgian")
,"greek"=>$clang->gT("ISO 8859-7 Greek")
,"hebrew"=>$clang->gT("ISO 8859-8 Hebrew")
,"hp8"=>$clang->gT("HP West European")
,"keybcs2"=>$clang->gT("DOS Kamenicky Czech-Slovak")
,"koi8r"=>$clang->gT("KOI8-R Relcom Russian")
,"koi8u"=>$clang->gT("KOI8-U Ukrainian")
,"latin1"=>$clang->gT("cp1252 West European")
,"latin2"=>$clang->gT("ISO 8859-2 Central European")
,"latin5"=>$clang->gT("ISO 8859-9 Turkish")
,"latin7"=>$clang->gT("ISO 8859-13 Baltic")
,"macce"=>$clang->gT("Mac Central European")
,"macroman"=>$clang->gT("Mac West European")
,"sjis"=>$clang->gT("Shift-JIS Japanese")
,"swe7"=>$clang->gT("7bit Swedish")
,"tis620"=>$clang->gT("TIS620 Thai")
,"ucs2"=>$clang->gT("UCS-2 Unicode")
,"ujis"=>$clang->gT("EUC-JP Japanese")
,"utf8"=>$clang->gT("UTF-8 Unicode"));
if (isset($_POST['csvcharset']) && $_POST['csvcharset']) //sanitize charset - if encoding is not found sanitize to 'auto'
{
$uploadcharset=$_POST['csvcharset'];
if (!array_key_exists($uploadcharset,$encodingsarray)) {$uploadcharset='auto';}
$filterduplicatetoken=(isset($_POST['filterduplicatetoken']) && $_POST['filterduplicatetoken']=='on');
$filterblankemail=(isset($_POST['filterblankemail']) && $_POST['filterblankemail']=='on');
}
}
if ($subaction == "importldap" || $subaction == "uploadldap" )
{
$filterduplicatetoken=(isset($_POST['filterduplicatetoken']) && $_POST['filterduplicatetoken']=='on');
$filterblankemail=(isset($_POST['filterblankemail']) && $_POST['filterblankemail']=='on');
}
$tokenoutput = "";
if ($subaction == "export" && ( bHasSurveyPermission($surveyid, 'tokens', 'export')) )//EXPORT FEATURE SUBMITTED BY PIETERJAN HEYSE
{
header("Content-Disposition: attachment; filename=tokens_".$surveyid.".csv");
header("Content-type: text/comma-separated-values; charset=UTF-8");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Pragma: cache");
$bquery = "SELECT * FROM ".db_table_name("tokens_$surveyid").' where 1=1';
if (trim($_POST['filteremail'])!='')
{
if ($databasetype=='odbc_mssql' || $databasetype=='odbtp' || $databasetype=='mssql_n' || $connect->databaseType == 'mssqlnative')
{
$bquery .= ' and CAST(email as varchar) like '.db_quoteall('%'.$_POST['filteremail'].'%', true);
}
else
{
$bquery .= ' and email like '.db_quoteall('%'.$_POST['filteremail'].'%', true);
}
}
if ($_POST['tokenstatus']==1)
{
$bquery .= " and completed<>'N'";
}
if ($_POST['tokenstatus']==2)
{
$bquery .= " and completed='N'";
if ($thissurvey['anonymized']=='N')
{
$bquery .=" and token not in (select token from ".db_table_name("survey_$surveyid")." group by token)";
}
}
if ($_POST['tokenstatus']==3 && $thissurvey['anonymized']=='N')
{
$bquery .= " and completed='N' and token in (select token from ".db_table_name("survey_$surveyid")." group by token)";
}
if ($_POST['invitationstatus']==1)
{
$bquery .= " and sent<>'N'";
}
if ($_POST['invitationstatus']==2)
{
$bquery .= " and sent='N'";
}
if ($_POST['reminderstatus']==1)
{
$bquery .= " and remindersent<>'N'";
}
if ($_POST['reminderstatus']==2)
{
$bquery .= " and remindersent='N'";
}
if ($_POST['tokenlanguage']!='')
{
$bquery .= " and language=".db_quoteall($_POST['tokenlanguage']);
}
$bquery .= " ORDER BY tid";
$bresult = db_execute_assoc($bquery) or die ("$bquery<br />".htmlspecialchars($connect->ErrorMsg()));
$bfieldcount=$bresult->FieldCount();
// Export UTF8 WITH BOM
$tokenoutput = chr(hexdec('EF')).chr(hexdec('BB')).chr(hexdec('BF'));
$tokenoutput .= "tid,firstname,lastname,email,emailstatus,token,language,validfrom,validuntil,invited,reminded,remindercount,completed,usesleft";
$attrfieldnames = GetAttributeFieldnames($surveyid);
$attrfielddescr = GetTokenFieldsAndNames($surveyid, true);
foreach ($attrfieldnames as $attr_name)
{
$tokenoutput .=", $attr_name";
if (isset($attrfielddescr[$attr_name]))
$tokenoutput .=" <".str_replace(","," ",$attrfielddescr[$attr_name]).">";
}
$tokenoutput .="\n";
while ($brow = $bresult->FetchRow())
{
if (trim($brow['validfrom']!=''))
{
$datetimeobj = new Date_Time_Converter($brow['validfrom'] , "Y-m-d H:i:s");
$brow['validfrom']=$datetimeobj->convert('Y-m-d H:i');
}
if (trim($brow['validuntil']!=''))
{
$datetimeobj = new Date_Time_Converter($brow['validuntil'] , "Y-m-d H:i:s");
$brow['validuntil']=$datetimeobj->convert('Y-m-d H:i');
}
$tokenoutput .= '"'.trim($brow['tid']).'",';
$tokenoutput .= '"'.trim($brow['firstname']).'",';
$tokenoutput .= '"'.trim($brow['lastname']).'",';
$tokenoutput .= '"'.trim($brow['email']).'",';
$tokenoutput .= '"'.trim($brow['emailstatus']).'",';
$tokenoutput .= '"'.trim($brow['token']).'",';
$tokenoutput .= '"'.trim($brow['language']).'",';
$tokenoutput .= '"'.trim($brow['validfrom']).'",';
$tokenoutput .= '"'.trim($brow['validuntil']).'",';
$tokenoutput .= '"'.trim($brow['sent']).'",';
$tokenoutput .= '"'.trim($brow['remindersent']).'",';
$tokenoutput .= '"'.trim($brow['remindercount']).'",';
$tokenoutput .= '"'.trim($brow['completed']).'",';
$tokenoutput .= '"'.trim($brow['usesleft']).'",';
foreach ($attrfieldnames as $attr_name)
{
$tokenoutput .='"'.trim($brow[$attr_name]).'",';
}
$tokenoutput = substr($tokenoutput,0,-1); // remove last comma
$tokenoutput .= "\n";
}
echo $tokenoutput;
exit;
}
// Bouceprocessing
if($subaction=='bounceprocessing')
{
if ($thissurvey['bounceprocessing']!='N' && !($thissurvey['bounceprocessing']=='G' && getGlobalSetting('bounceaccounttype')=='off') && bHasSurveyPermission($surveyid, 'tokens','update'))
{
$bouncetotal=0;
$checktotal=0;
if($thissurvey['bounceprocessing']=='G')
{
$accounttype=getGlobalSetting('bounceaccounttype');
$hostname=getGlobalSetting('bounceaccounthost');
$username=getGlobalSetting('bounceaccountuser');
$pass=getGlobalSetting('bounceaccountpass');
$hostencryption=getGlobalSetting('bounceencryption');
}
else
{
$accounttype=$thissurvey['bounceaccounttype'];
$hostname=$thissurvey['bounceaccounthost'];
$username=$thissurvey['bounceaccountuser'];
$pass=$thissurvey['bounceaccountpass'];
$hostencryption=$thissurvey['bounceaccountencryption'];
}
@list($hostname,$port) = split(':', $hostname);
if(empty($port))
{
if($accounttype=="IMAP")
{
switch($hostencryption)
{
case "Off":
$hostname = $hostname.":143";
break;
case "SSL":
$hostname = $hostname.":993";
break;
case "TLS":
$hostname = $hostname.":993";
break;
}
}
else
{
switch($hostencryption)
{
case "Off":
$hostname = $hostname.":110";
break;
case "SSL":
$hostname = $hostname.":995";
break;
case "TLS":
$hostname = $hostname.":995";
break;
}
}
}
$flags="";
switch($accounttype)
{
case "IMAP":
$flags.="/imap";
break;
case "POP":
$flags.="/pop3";
break;
}
switch($hostencryption) // novalidate-cert to have personal CA , maybe option.
{
case "SSL":
$flags.="/ssl/novalidate-cert";
break;
case "TLS":
$flags.="/tls/novalidate-cert";
break;
}
if($mbox=imap_open('{'.$hostname.$flags.'}INBOX',$username,$pass))
{
imap_errors();
$count=imap_num_msg($mbox);
if($count>0)
{
$lasthinfo=imap_headerinfo($mbox,$count);
$datelcu = strtotime($lasthinfo->date);
$datelastbounce= $datelcu;
$lastbounce = $thissurvey['bouncetime'];
while($datelcu > $lastbounce)
{
$header = explode("\r\n",@imap_body($mbox,$count,FT_PEEK)); // Don't put read
foreach ($header as $item)
{
if (preg_match('/^X-surveyid/',$item))
{
$surveyidBounce=explode(": ",$item);
}
if (preg_match('/^X-tokenid/',$item))
{
$tokenBounce=explode(": ",$item);
if($surveyid == $surveyidBounce[1])
{
$bouncequery = "UPDATE ".db_table_name("tokens_$surveyid")." SET emailstatus='bounced' WHERE token='$tokenBounce[1]';";
$anish=$connect->Execute($bouncequery);
$readbounce=imap_body($mbox,$count); // Put read
if (isset($thissurvey['bounceremove']) && $thissurvey['bounceremove']) // TODO Y or just true, and a imap_delete
{
$deletebounce=imap_delete($mbox,$count); // Put delete
}
$bouncetotal++;
}
}
}
$count--;
$lasthinfo=@imap_headerinfo($mbox,$count);
$datelc=$lasthinfo->date;
$datelcu = strtotime($datelc);
$checktotal++;
}
if($bouncetotal>0)
{
echo sprintf($clang->gT("%s messages were scanned out of which %s were marked as bounce by the system."), $checktotal,$bouncetotal);
}
else
{
echo sprintf($clang->gT("%s messages were scanned, none were marked as bounce by the system."),$checktotal);
}
}
else
{
echo sprintf($clang->gT("Your inbox is empty."));
}
@imap_close($mbox);
$entertimestamp = "update ".db_table_name("surveys")." set bouncetime='$datelastbounce' where sid='$surveyid'";
$executetimestamp = $connect->Execute($entertimestamp);
}
else
{
echo $clang->gT("Please check your settings");
}
}
else
{
echo $clang->gT("We are sorry but you don't have permissions to do this.");
}
exit(0); // if bounceprocessing : javascript : no more todo
}
if ($subaction == "delete" && bHasSurveyPermission($surveyid, 'tokens','delete'))
{
$_SESSION['metaHeader']="<meta http-equiv=\"refresh\" content=\"1;URL={$scriptname}?action=tokens&subaction=browse&sid=".returnglobal('sid')."&start=$start&limit=$limit&order=$order\" />";
}
if ($subaction == "deletegroup" && bHasSurveyPermission($surveyid, 'tokens','delete'))
{
$_SESSION['metaHeader']="<meta http-equiv=\"refresh\" content=\"1;URL={$scriptname}?action=tokens&subaction=browsegroup&sid=".returnglobal('sid')."&start=$start&limit=$limit&order=$order\" />";
}
// MAKE SURE THAT THERE IS A SID
if (!isset($surveyid) || !$surveyid )
{
$tokenoutput .= "\t<div class='messagebox ui-corner-all'><div class='header ui-widget-header'>"
.$clang->gT("Token control")."</div>\n"
."\t<br /><div class='warningheader'>".$clang->gT("Error")."</div>"
."<br />".$clang->gT("You have not selected a survey")."<br /><br />"
."<input type='submit' value='"
.$clang->gT("Main admin screen")."' onclick=\"window.open('$scriptname', '_top')\" /><br />\n"
."</div>\n";
return;
}
// MAKE SURE THAT THE SURVEY EXISTS
$thissurvey=getSurveyInfo($surveyid);
if ($thissurvey===false)
{
$tokenoutput .= "\t<div class='messagebox ui-corner-all'>\n<div class='header ui-widget-header'>\n"
.$clang->gT("Token control")."</div>\n"
."\t<br /><div class='warningheader'>".$clang->gT("Error")."</div>"
."<br />".$clang->gT("The survey you selected does not exist")
."<br /><br />\n\t<input type='submit' value='"
.$clang->gT("Main admin screen")."' onclick=\"window.open('$scriptname', '_top')\" /><br />"
."</div>\n";
return;
}
else // A survey DOES exist
{
if($subaction != 'bounceprocessing')
{
$tokenoutput .= "\t<div class='menubar'>"
."<div class='menubar-title ui-widget-header'>"
."<strong>".$clang->gT("Token control")." </strong> ".htmlspecialchars($thissurvey['surveyls_title'])."</div>\n";
$surveyprivate = $thissurvey['anonymized'];
}
}
// CHECK TO SEE IF A TOKEN TABLE EXISTS FOR THIS SURVEY
$tokenexists=tableExists('tokens_'.$surveyid);
if (!$tokenexists) //If no tokens table exists
{
if (isset($_POST['createtable']) && $_POST['createtable']=="Y" && bHasSurveyPermission($surveyid, 'surveyactivation','update'))
{
$createtokentable=
"tid int I NOTNULL AUTO PRIMARY,\n "
. "firstname C(40),\n "
. "lastname C(40),\n ";
//MSSQL needs special treatment because of some strangeness in ADODB
if ($connect->databaseType == 'odbc_mssql' || $connect->databaseType == 'odbtp' || $connect->databaseType == 'mssql_n' || $connect->databaseType == 'mssqlnative')
{
$createtokentable.= "email C(320),\n "
."emailstatus C(300) DEFAULT 'OK',\n ";
}
else
{
$createtokentable.= "email X(320),\n "
."emailstatus X(300) DEFAULT 'OK',\n ";
}
$createtokentable.= "token C(36) ,\n "
. "language C(25) ,\n "
. "sent C(17) DEFAULT 'N',\n "
. "remindersent C(17) DEFAULT 'N',\n "
. "remindercount int I DEFAULT 0,\n "
. "completed C(17) DEFAULT 'N',\n "
. "usesleft I DEFAULT 1,\n"
. "validfrom T ,\n "
. "validuntil T ,\n "
. "mpid I ";
$tabname = "{$dbprefix}tokens_{$surveyid}"; # not using db_table_name as it quotes the table name (as does CreateTableSQL)
$taboptarray = array('mysql' => 'ENGINE='.$databasetabletype.' CHARACTER SET utf8 COLLATE utf8_unicode_ci',
'mysqli' => 'ENGINE='.$databasetabletype.' CHARACTER SET utf8 COLLATE utf8_unicode_ci');
$dict = NewDataDictionary($connect);
$sqlarray = $dict->CreateTableSQL($tabname, $createtokentable, $taboptarray);
$execresult=$dict->ExecuteSQLArray($sqlarray, false);
if ($execresult==0 || $execresult==1)
{
$tokenoutput .= "\t</div><div class='messagebox ui-corner-all'>\n"
."<font size='1'><strong><center>".$clang->gT("Token table could not be created.")."</center></strong></font>\n"
.$clang->gT("Error").": \n<font color='red'>" . $connect->ErrorMsg() . "</font>\n"
."<pre>".htmlspecialchars(implode(" ",$sqlarray))."</pre>\n"
."<br />"
."<input type='submit' value='"
.$clang->gT("Main admin screen")."' onclick=\"window.open('$scriptname?sid=$surveyid', '_top')\" />\n"
."</div>\n"
."</div>\n";
} else {
$createtokentableindex = $dict->CreateIndexSQL("{$tabname}_idx", $tabname, array('token'));
$dict->ExecuteSQLArray($createtokentableindex, false) or safe_die ("Failed to create token table index<br />$createtokentableindex<br /><br />".$connect->ErrorMsg());
if ($connect->databaseType == 'mysql' || $connect->databaseType == 'mysqli')
{
$query = 'CREATE INDEX idx_'.$tabname.'_efl ON '.$tabname.' ( email(120), firstname, lastname )';
$result=$connect->Execute($query) or safe_die("Failed Rename!<br />".$query."<br />".$connect->ErrorMsg());
}
$tokenoutput .= "\t</div><p>\n"
.$clang->gT("A token table has been created for this survey.")." (\"".$dbprefix."tokens_$surveyid\")<br /><br />\n"
."<input type='submit' value='"
.$clang->gT("Continue")."' onclick=\"window.open('$scriptname?action=tokens&sid=$surveyid', '_top')\" />\n";
}
return;
}
elseif (returnglobal('restoretable') == "Y" && returnglobal('oldtable') && bHasSurveyPermission($surveyid, 'surveyactivation','update'))
{
$query = db_rename_table(returnglobal('oldtable') , db_table_name_nq("tokens_$surveyid"));
$result=$connect->Execute($query) or safe_die("Failed Rename!<br />".$query."<br />".$connect->ErrorMsg());
$tokenoutput .= "\t</div><div class='messagebox ui-corner-all'>\n"
."<div class='header ui-widget-header'>".$clang->gT("Import old tokens")."</div>"
."<br />".$clang->gT("A token table has been created for this survey and the old tokens were imported.")." (\"".$dbprefix."tokens_$surveyid\")<br /><br />\n"
."<input type='submit' value='"
.$clang->gT("Continue")."' onclick=\"window.open('$scriptname?action=tokens&sid=$surveyid', '_top')\" />\n"
."</div>\n";
return;
}
else
{
$query=db_select_tables_like("{$dbprefix}old\_tokens\_".$surveyid."\_%");
$result=db_execute_num($query) or safe_die("Couldn't get old table list<br />".$query."<br />".$connect->ErrorMsg());
$tcount=$result->RecordCount();
if ($tcount > 0)
{
while($rows=$result->FetchRow())
{
$oldlist[]=$rows[0];
}
}
$tokenoutput .= "\t</div><div class='messagebox ui-corner-all'>\n"
."<div class='warningheader'>".$clang->gT("Warning")."</div>\n"
."<br /><strong>".$clang->gT("Tokens have not been initialised for this survey.")."</strong><br /><br />\n";
if (bHasSurveyPermission($surveyid, 'surveyactivation','update'))
{
$tokenoutput .= $clang->gT("If you initialise tokens for this survey then this survey will only be accessible to users who provide a token either manually or by URL.")
."<br /><br />\n";
$thissurvey=getSurveyInfo($surveyid);
if ($thissurvey['anonymized'] == 'Y')
{
$tokenoutput .= "".$clang->gT("Note: If you turn on the -Anonymized responses- option for this survey then LimeSurvey will mark your completed tokens only with a 'Y' instead of date/time to ensure the anonymity of your participants.")
."<br /><br />\n";
}
$tokenoutput .= $clang->gT("Do you want to create a token table for this survey?");
$tokenoutput .= "<br /><br />\n";
$tokenoutput .= "<input type='submit' value='"
.$clang->gT("Initialise tokens")."' onclick=\"".get2post("$scriptname?action=tokens&sid=$surveyid&createtable=Y")."\" />\n";
$tokenoutput .= "<input type='submit' value='"
.$clang->gT("No, thanks.")."' onclick=\"window.open('{$scriptname}?sid=$surveyid', '_top')\" /></div>\n";
}
else
{
$tokenoutput .= $clang->gT("You don't have the permission to activate tokens.");
$tokenoutput .= "<input type='submit' value='"
.$clang->gT("Back to main menu")."' onclick=\"window.open('{$scriptname}?sid=$surveyid', '_top')\" /></div>\n";
}
// Do not offer old postgres token tables for restore since these are having an issue with missing index
if ($tcount>0 && $databasetype!='postgres' && bHasSurveyPermission($surveyid, 'surveyactivation','update'))
{
$tokenoutput .= "<br /><div class='header ui-widget-header'>".$clang->gT("Restore options")."</div>\n"
."<div class='messagebox ui-corner-all'>\n"
."<form method='post' action='$scriptname?action=tokens'>\n"
.$clang->gT("The following old token tables could be restored:")."<br /><br />\n"
."<select size='4' name='oldtable' style='width:250px;'>\n";
foreach($oldlist as $ol)
{
$tokenoutput .= "<option>".$ol."</option>\n";
}
$tokenoutput .= "</select><br /><br />\n"
."<input type='submit' value='".$clang->gT("Restore")."' />\n"
."<input type='hidden' name='restoretable' value='Y' />\n"
."<input type='hidden' name='sid' value='$surveyid' />\n"
."</form></div>\n";
}
return;
}
}
#Lookup the names of the attributes
/*$query = "SELECT attribute1, attribute2 FROM ".db_table_name('surveys')." WHERE sid=$surveyid";
$result = db_execute_assoc($query) or safe_die("Couldn't execute query: <br />$query<br />".$connect->ErrorMsg());
$row = $result->FetchRow();
if ($row["attribute1"]) {$attr1_name = $row["attribute1"];} else {$attr1_name=$clang->gT("Attribute 1");}
if ($row["attribute2"]) {$attr2_name = $row["attribute2"];} else {$attr2_name=$clang->gT("Attribute 2");}*/
// IF WE MADE IT THIS FAR, THEN THERE IS A TOKENS TABLE, SO LETS DEVELOP THE MENU ITEMS
if($subaction != 'bounceprocessing')
{
$tokenoutput .= "\t<div class='menubar-main'>\n"
."<div class='menubar-left'>\n"
."<a href=\"#\" onclick=\"window.open('$scriptname?sid=$surveyid', '_top')\" "
."title='".$clang->gTview("Return to survey administration")."'>"
."<img name='HomeButton' src='$imageurl/home.png' alt='".$clang->gT("Return to survey administration")."' /></a>\n"
."<img src='$imageurl/blank.gif' alt='' width='11' />\n"
."<img src='$imageurl/seperator.gif' alt='' />\n"
."<a href=\"#\" onclick=\"window.open('$scriptname?action=tokens&sid=$surveyid', '_top')\" title='".$clang->gTview("Show token summary")."' >"
."<img name='SummaryButton' src='$imageurl/summary.png' alt='".$clang->gT("Show token summary")."' /></a>\n"
."<img src='$imageurl/seperator.gif' alt='' />\n"
."<a href=\"#\" onclick=\"window.open('$scriptname?action=tokens&sid=$surveyid&subaction=browse', '_top')\" "
."title='".$clang->gTview("Display tokens")."' >"
."<img name='ViewAllButton' src='$imageurl/document.png' alt='".$clang->gT("Display tokens")."' /></a>\n";
if (bHasSurveyPermission($surveyid, 'tokens','create'))
{
$tokenoutput .= "<a href=\"#\" onclick=\"window.open('$scriptname?action=tokens&sid=$surveyid&subaction=addnew', '_top')\""
."title='".$clang->gTview("Add new token entry")."' >"
."<img name='AddNewButton' src='$imageurl/add.png' title='' alt='".$clang->gT("Add new token entry")."' /></a>\n";
$tokenoutput .= "<a href=\"#\" onclick=\"window.open('$scriptname?action=tokens&sid=$surveyid&subaction=adddummys', '_top')\""
."title='".$clang->gTview("Add dummy tokens")."' >"
."<img name='AddNewDummyButton' src='$imageurl/create_dummy_token.png' title='' alt='".$clang->gT("Add dummy tokens")."' /></a>\n";
}
if (bHasSurveyPermission($surveyid, 'tokens','update'))
{
$tokenoutput .= "<img src='$imageurl/seperator.gif' alt='' />\n"
."<a href=\"#\" onclick=\"window.open('$scriptname?action=tokens&sid=$surveyid&subaction=managetokenattributes', '_top')\" "
."title='".$clang->gTview("Manage additional attribute fields")."'>"
."<img name='ManageAttributesButton' src='$imageurl/token_manage.png' title='' alt='".$clang->gT("Manage additional attribute fields")."' /></a>\n";
}
if (bHasSurveyPermission($surveyid, 'tokens','import'))
{
$tokenoutput .= "<img src='$imageurl/seperator.gif' alt='' />\n"
."<a href=\"#\" onclick=\"window.open('$scriptname?action=tokens&sid=$surveyid&subaction=import', '_top')\" "
."title='".$clang->gTview("Import tokens from CSV file")."'> "
."<img name='ImportButton' src='$imageurl/importcsv.png' title='' alt='".$clang->gT("Import tokens from CSV file")."' /></a>"
."<a href=\"#\" onclick=\"window.open('$scriptname?action=tokens&sid=$surveyid&subaction=importldap', '_top')\" "
."title='".$clang->gTview("Import tokens from LDAP query")."'> <img name='ImportLdapButton' src='$imageurl/importldap.png' alt='".$clang->gT("Import tokens from LDAP query")."' /></a>";
}
if (bHasSurveyPermission($surveyid, 'tokens','export'))
{
$tokenoutput .= "<a href=\"#\" onclick=\"window.open('$scriptname?action=tokens&sid=$surveyid&subaction=exportdialog', '_top')\" "
."title='".$clang->gTview("Export tokens to CSV file")."'>".
"<img name='ExportButton' src='$imageurl/exportcsv.png' alt='".$clang->gT("Export tokens to CSV file")."' /></a>\n";
}
if (bHasSurveyPermission($surveyid, 'tokens','update'))
{
$tokenoutput .= "<img src='$imageurl/seperator.gif' alt='' />\n"
."<a href='{$scriptname}?action=emailtemplates&sid={$surveyid}' title='".$clang->gTview("Edit email templates")."'>"
."<img name='EmailTemplatesButton' src='$imageurl/emailtemplates.png' alt='".$clang->gT("Edit email templates")."' /></a>\n"
."<a href=\"#\" onclick=\"window.open('$scriptname?action=tokens&sid=$surveyid&subaction=email', '_top')\" "
."title='".$clang->gTview("Send email invitation")."'>"
."<img name='InviteButton' src='$imageurl/invite.png' alt='".$clang->gT("Send email invitation")."' /></a>\n"
."<a href=\"#\" onclick=\"window.open('$scriptname?action=tokens&sid=$surveyid&subaction=remind', '_top')\" "
."title='".$clang->gTview("Send email reminder")."'>"
."<img name='RemindButton' src='$imageurl/remind.png' alt='".$clang->gT("Send email reminder")."' /></a>\n"
."<img src='$imageurl/seperator.gif' alt='' />\n"
."<a href=\"#\" onclick=\"".get2post("$scriptname?action=tokens&sid=$surveyid&subaction=tokenify")."\" "
." title='".$clang->gTview("Generate tokens")."'>"
."<img name='TokenifyButton' src='$imageurl/tokenify.png' alt='".$clang->gT("Generate tokens")."' /></a>\n"
."<img src='$imageurl/seperator.gif' alt='' />\n";
}
if (bHasSurveyPermission($surveyid, 'surveyactivation','update'))
{
$tokenoutput .="<a href=\"#\" onclick=\"".get2post("$scriptname?action=tokens&sid=$surveyid&subaction=kill")."\" "
."title='".$clang->gTview("Drop tokens table")."' >"
."<img name='DeleteTokensButton' src='$imageurl/delete.png' alt='".$clang->gT("Drop tokens table")."' /></a>\n"
."<img src='$imageurl/seperator.gif' alt='' />\n";
}
if (bHasSurveyPermission($surveyid, 'tokens','update'))
{
$tokenoutput .="<a href=\"#\" onclick=\"window.open('$scriptname?action=tokens&sid=$surveyid&subaction=bouncesettings', '_top')\" "
."title='".$clang->gTview("Bounce processing settings")."' >"
."<img name='BounceSettings' src='$imageurl/bounce_settings.png' alt='".$clang->gT("Bounce settings")."' /></a>\n";
}
$tokenoutput .="</div><div class='menubar-right'><a href=\"#\" onclick=\"showhelp('show')\" "
." title='".$clang->gTview("Show help")."'>"
."<img src='$imageurl/showhelp.png' align='right' alt='".$clang->gT("Show help")."' /></a>\n";
$tokenoutput .= "\t</div></div></div>\n";
}
// SEE HOW MANY RECORDS ARE IN THE TOKEN TABLE
$tksq = "SELECT count(tid) FROM ".db_table_name("tokens_$surveyid");
$tksr = db_execute_num($tksq);
$tkr = $tksr->FetchRow();
$tkcount = $tkr[0];
// GIVE SOME INFORMATION ABOUT THE TOKENS
if ($subaction=='')
{
$tokenoutput .= "\t<div class='header ui-widget-header'>".$clang->gT("Token summary")."</div>\n"
."<br /><table align='center' class='statisticssummary'>\n"
."\t<tr>\n"
."<th>\n"
.$clang->gT("Total records in this token table")."</th><td> $tkcount</td></tr><tr>\n";
$tksq = "SELECT count(*) FROM ".db_table_name("tokens_$surveyid")." WHERE token IS NULL OR token=''";
$tksr = db_execute_num($tksq);
while ($tkr = $tksr->FetchRow())
{$tokenoutput .= "<th>".$clang->gT("Total with no unique Token")."</th><td> $tkr[0] / $tkcount</td></tr><tr>\n";}
$tksq = "SELECT count(*) FROM ".db_table_name("tokens_$surveyid")." WHERE (sent!='N' and sent<>'')";
$tksr = db_execute_num($tksq);
while ($tkr = $tksr->FetchRow())
{$tokenoutput .= "<th>".$clang->gT("Total invitations sent")."</th><td> $tkr[0] / $tkcount</td></tr><tr>\n";}
$tksq = "SELECT count(*) FROM ".db_table_name("tokens_$surveyid")." WHERE emailstatus = 'optOut'";
$tksr = db_execute_num($tksq);
while ($tkr = $tksr->FetchRow())
{$tokenoutput .= "<th>".$clang->gT("Total opted out")."</th><td> $tkr[0] / $tkcount</td></tr><tr>\n";}
$tksq = "SELECT count(*) FROM ".db_table_name("tokens_$surveyid")." WHERE (completed!='N' and completed<>'')";
$tksr = db_execute_num($tksq) or safe_die ("Couldn't execute token selection query<br />$abquery<br />".$connect->ErrorMsg());
while ($tkr = $tksr->FetchRow())
{$tokenoutput .= "<th>".$clang->gT("Total surveys completed")."</th><td> $tkr[0] / $tkcount\n";}
$tokenoutput .= "</td>\n"
."\t</tr>\n"
."</table><br />\n";
}
#############################################################################################
// NOW FOR VARIOUS ACTIONS:
if(isset($surveyid) && getEmailFormat($surveyid) == 'html')
{
$ishtml=true;
}
else
{
$ishtml=false;
}
if ($subaction == "exportdialog" && bHasSurveyPermission($surveyid, 'tokens','export') )//EXPORT FEATURE SUBMITTED BY PIETERJAN HEYSE
{
$langquery = "SELECT language FROM ".db_table_name("tokens_$surveyid")." group by language";
$langresult = db_execute_assoc($langquery);
$tokenoutput .= "\t<div class='header ui-widget-header'>".$clang->gT("Token export options")."</div>\n";
$tokenoutput .= "<form id='exportdialog' name='exportdialog' action='$scriptname' method='post'>\n"
."<ul><li><label for='tokenstatus'>".$clang->gT('Token status:')."</label><select id='tokenstatus' name='tokenstatus' >"
."<option selected='selected' value='0'>".$clang->gT('All tokens')."</option>"
."<option value='1'>".$clang->gT('Completed')."</option>"
."<option value='2'>".$clang->gT('Not started')."</option>";
if ($thissurvey['anonymized']=='N')
{
$tokenoutput.="<option value='3'>".$clang->gT('Started but not yet completed')."</option>";
}
$tokenoutput.="</select></li>"
."<li><label for='invitationstatus'>".$clang->gT('Invitation status:')."</label><select id='invitationstatus' name='invitationstatus' >"
."<option selected='selected' value='0'>".$clang->gT('All')."</option>"
."<option value='1'>".$clang->gT('Invited')."</option>"
."<option value='2'>".$clang->gT('Not invited')."</option>";
$tokenoutput.="</select></li>"
."<li><label for='reminderstatus'>".$clang->gT('Reminder status:')."</label><select id='reminderstatus' name='reminderstatus' >"
."<option selected='selected' value='0'>".$clang->gT('All')."</option>"
."<option value='1'>".$clang->gT('Reminder(s) sent')."</option>"
."<option value='2'>".$clang->gT('No reminder(s) sent')."</option>";
$tokenoutput.="</select></li>"
."<li><label for='tokenlanguage' >".$clang->gT('Filter by language')."</label><select id='tokenlanguage' name='tokenlanguage' >"
."<option selected='selected' value=''>".$clang->gT('All')."</option>";
while ($lrow = $langresult->FetchRow())
{
$tokenoutput.="<option value='{$lrow['language']}'>".getLanguageNameFromCode($lrow['language'])."</option>";
}
$tokenoutput.="</select> </li>"
."<li><label for='filteremail' >".$clang->gT('Filter by email address')."</label><input type='text' id='filteremail' name='filteremail' /></li>"
."<li> </li>"
// ."<li><label for='tokendeleteexported' >".$clang->gT('Delete exported tokens')."</label><input type='checkbox' id='tokendeleteexported' name='tokendeleteexported' /> </li>"
."</ul>"
."<p><input type='submit' name='submit' value='".$clang->gT('Export tokens')."' />"
."<input type='hidden' name='action' id='action' value='tokens' />"
."<input type='hidden' name='sid' id='sid' value='$surveyid' />"
."<input type='hidden' name='subaction' id='subaction' value='export' />"
."</p></form>";
}
$tokenoutput .= "<script language='javascript' type='text/javascript'>"
."surveyid = '$surveyid'"
."</script>";
if($subaction=="surveysettingsave")
{
global $connect;
@$fieldvalue = array("bounceprocessing"=>$_POST['bounceprocessing'],
"bounce_email"=>$_POST['bounce_email'],
);
if(@$_POST['bounceprocessing']=='L')
{
$fieldvalue['bounceaccountencryption']=$_POST['bounceaccountencryption'];
$fieldvalue['bounceaccountuser']=$_POST['bounceaccountuser'];
$fieldvalue['bounceaccountpass']=$_POST['bounceaccountpass'];
$fieldvalue['bounceaccounttype']=$_POST['bounceaccounttype'];
$fieldvalue['bounceaccounthost']=$_POST['bounceaccounthost'];
}
$connect->AutoExecute("{$dbprefix}surveys", $fieldvalue, 2,"sid=$surveyid",get_magic_quotes_gpc());
$tokenoutput .= "<div class='header ui-widget-header'>".$clang->gT("Bounce settings")."</div>\n"
."<div class='messagebox ui-corner-all'>"
."\t<div class='successheader'>".$clang->gT("Bounce settings have been saved.")."</div>\n"
."</div>";
}
if ($subaction=='bouncesettings'){
$settings=getSurveyInfo($surveyid);
$tokenoutput .= "\t<div class='header ui-widget-header'>".$clang->gT("Bounce settings")."</div>\n";
$tokenoutput .= "<div id='bouncesettings'>\n"
."<form id='bouncesettings' name='bouncesettings' action='$scriptname?action=tokens&sid=$surveyid&subaction=surveysettingsave' method='post'>"
."\t\n<br><li><label for='bounce_email'>".$clang->gT('Survey bounce email:')."</label>\n"
."\t\t<input type='text' size='50' id='bounce_email' name='bounce_email' value=\"".$settings['bounce_email']."\" ></li>\n"
."\t<li><label for='bounceprocessing'>".$clang->gT("Bounce settings to be used")."</label>\n"
."\t\t<select id='bounceprocessing' name='bounceprocessing'>\n"
."\t\t\t<option value='N'";
if ($settings['bounceprocessing']=='N') {$tokenoutput .= " selected='selected'";}
$tokenoutput .= ">".$clang->gT("None")."</option>\n"
. "\t\t\t<option value='L'";
if ($settings['bounceprocessing']=='L') {$tokenoutput .= " selected='selected'";}
$tokenoutput .= ">".$clang->gT("Use settings below")."</option>\n"
. "\t\t\t<option value='G'";
if ($settings['bounceprocessing']=='G') {$tokenoutput .= " selected='selected'";}
$tokenoutput .= ">".$clang->gT("Use global settings")."</option>\n"
."\t\t</select></li>\n"
. "\t<li><label for='bounceaccounttype'>".$clang->gT("Server type:")."</label>\n"
. "\t\t<select id='bounceaccounttype' name='bounceaccounttype'>\n"
. "\t\t\t<option value='Off'";
if ($settings['bounceaccounttype']=='Off') {$tokenoutput .= " selected='selected'";}
$tokenoutput .= ">".$clang->gT("Off")."</option>\n"
. "\t\t\t<option value='IMAP'";
if ($settings['bounceaccounttype']=='IMAP') {$tokenoutput .= " selected='selected'";}
$tokenoutput .= ">".$clang->gT("IMAP")."</option>\n"
. "\t\t\t<option value='POP'";
if ($settings['bounceaccounttype']=='POP') {$tokenoutput .= " selected='selected'";}
$tokenoutput .= ">".$clang->gT("POP")."</option>\n"
."\t\t</select></li>\n"
. "\t<li><label for='bounceaccounthost'>".$clang->gT("Server name & port:")."</label>\n"
. "\t\t<input type='text' size='50' id='bounceaccounthost' name='bounceaccounthost' value=\"".$settings['bounceaccounthost']."\" />\n"."<font size='1'>".$clang->gT("Enter your hostname and port, e.g.: imap.gmail.com:995")."</font>\n"
. "\t<li><label for='bounceaccountuser'>".$clang->gT("User name:")."</label>\n"
. "\t\t<input type='text' size='50' id='bounceaccountuser' name='bounceaccountuser' value=\"".$settings['bounceaccountuser']."\" /></li>\n"
. "\t<li><label for='bounceaccountpass'>".$clang->gT("Password:")."</label>\n"
. "\t\t<input type='password' size='50' id='bounceaccountpass' name='bounceaccountpass' value=\"".$settings['bounceaccountpass']."\"/></li>\n";
$tokenoutput.= "\t<li><label for='bounceencryption'>".$clang->gT("Encryption type:")."</label>\n"
. "\t\t<select id='bounceaccountencryption' name='bounceaccountencryption'>\n"
. "\t\t\t<option value='Off'";
if ($settings['bounceaccountencryption']=='Off') {$tokenoutput .= " selected='selected'";}
$tokenoutput .= ">".$clang->gT("None")."</option>\n"
. "\t\t\t<option value='SSL'";
if ($settings['bounceaccountencryption']=='SSL') {$tokenoutput .= " selected='selected'";}
$tokenoutput .= ">".$clang->gT("SSL")."</option>\n"
. "\t\t\t<option value='TLS'";
if ($settings['bounceaccountencryption']=='TLS') {$tokenoutput .= " selected='selected'";}
$tokenoutput .= ">".$clang->gT("TLS")."</option>\n"
."\t\t</select></li>\n<br></div>"."</form>";
$tokenoutput .= "\t<p><input type='button' onclick='bouncesettings.submit()' class='standardbtn' value='".$clang->gT("Save settings")."' /><br /></p>\n";
}
if ($subaction == "deleteall" && bHasSurveyPermission($surveyid, 'tokens', 'delete')){
$query="DELETE FROM ".db_table_name("tokens_$surveyid");
$result=$connect->Execute($query) or safe_die ("Couldn't update sent field<br />$query<br />".$connect->ErrorMsg());
$tokenoutput .= "<div class='header ui-widget-header'>".$clang->gT("Delete all token entries")."</div>\n"
."<div class='messagebox ui-corner-all'><div class='successheader'>".$clang->gT("All token entries have been deleted.")."</div></div><br />\n";
$subaction="";
}
if ($subaction == "clearinvites" && bHasSurveyPermission($surveyid, 'tokens', 'update'))
{
$query="UPDATE ".db_table_name("tokens_$surveyid")." SET sent='N', remindersent='N', remindercount=0";
$result=$connect->Execute($query) or safe_die ("Couldn't update sent field<br />$query<br />".$connect->ErrorMsg());
$tokenoutput .= "<div class='header ui-widget-header'>".$clang->gT("Reset token invitation status")."</div>\n"
."<div class='messagebox ui-corner-all'><div class='successheader'>".$clang->gT("All token entries have been set to 'Not invited'.")."</div></div><br />\n";
$subaction="";
}
if ($subaction == "cleartokens" && bHasSurveyPermission($surveyid, 'tokens', 'update'))
{
$query="UPDATE ".db_table_name("tokens_$surveyid")." SET token=''";
$result=$connect->Execute($query) or safe_die("Couldn't reset the tokens field<br />$query<br />".$connect->ErrorMsg());
$tokenoutput .= "<div class='header ui-widget-header'>".$clang->gT("Remove unique token numbers")."</div>\n"
."<div class='messagebox ui-corner-all'><div class='successheader'>".$clang->gT("All unique token numbers have been removed.")."</div></div><br />\n";
$subaction="";
}
if (!$subaction && (bHasSurveyPermission($surveyid, 'tokens', 'update') || bHasSurveyPermission($surveyid, 'tokens', 'delete')))
{
$tokenoutput .= "\t<div class='header ui-widget-header'>".$clang->gT("Token database administration options")."</div>\n"
."<div style='width:30%; margin:0 auto;'>";
if (bHasSurveyPermission($surveyid, 'tokens', 'update'))
{
$tokenoutput .="<ul><li><a href='#' onclick=\"if( confirm('"
.$clang->gT("Are you really sure you want to reset all invitation records to NO?","js")."')) {".get2post("$scriptname?action=tokens&sid=$surveyid&subaction=clearinvites")."}\">".$clang->gT("Set all entries to 'No invitation sent'.")."</a></li>\n"
."<li><a href='#' onclick=\"if ( confirm('"
.$clang->gT("Are you sure you want to delete all unique token strings?","js")."')) {".get2post("$scriptname?action=tokens&sid=$surveyid&subaction=cleartokens")."}\">".$clang->gT("Delete all unique token strings")."</a></li>\n";
}
if (bHasSurveyPermission($surveyid, 'tokens', 'delete'))
{
$tokenoutput .="<li><a href='#' onclick=\" if (confirm('"
.$clang->gT("Are you really sure you want to delete ALL token entries?","js")."')) {".get2post("$scriptname?action=tokens&sid=$surveyid&subaction=deleteall")."}\">".$clang->gT("Delete all token entries")."</a></li>\n";
}
$tokenoutput .= "</ul></div>\n";
}
if ($subaction == "browse" || $subaction == "search")
{
if (!isset($limit)) {$limit = 100;}
if (!isset($start)) {$start = 0;}
if ($limit > $tkcount) {$limit=$tkcount;}
$next=$start+$limit;
$last=$start-$limit;
$end=$tkcount-$limit;
if ($end < 0) {$end=0;}
if ($last <0) {$last=0;}
if ($next >= $tkcount) {$next=$tkcount-$limit;}
if ($end < 0) {$end=0;}
$baselanguage = GetBaseLanguageFromSurveyID($surveyid);
//ALLOW SELECTION OF NUMBER OF RECORDS SHOWN
if($subaction != 'bounceprocessing')
{
$tokenoutput .="\t<div class='menubar'><div class='menubar-title ui-widget-header'><span style='font-weight:bold;'>"
.$clang->gT("Data view control")."</span></div>\n"
."<div class='menubar-main'>\n";
$tokenoutput .="<div class='menubar-left'>\n";
if (bHasSurveyPermission($surveyid,'tokens','update'))
{
if($thissurvey['bounceprocessing']=='N')
{
$tokenoutput .="<img src='$imageurl/bounce_disabled.png' alt='".$clang->gT("You have selected not to use any bounce settings")."' align='left' />\n";
}
else
{
$tokenoutput .="<img src='$imageurl/bounce.png' id='bounceprocessing' alt='".$clang->gT("Bounce processing")."' align='left' />\n";
}
$tokenoutput .= "<img src='$imageurl/seperator.gif' alt='' border='0' hspace='0' align='left' />\n";
}
$tokenoutput .= "<a href='$scriptname?action=tokens&subaction=browse&sid=$surveyid&start=0&limit=$limit&order=$order&searchstring=".urlencode($searchstring)."'"
." title='".$clang->gTview("Show start...")."'>"
."<img name='DBeginButton' align='left' src='$imageurl/databegin.png' alt='".$clang->gT("Show start...")."' /></a>\n"
."<a href='$scriptname?action=toknens&subaction=browse&sid=$surveyid&start=$last&limit=$limit&order=$order&searchstring=".urlencode($searchstring)."'" .
" title='".$clang->gTview("Show previous...")."'>"
."<img name='DBackButton' align='left' src='$imageurl/databack.png' alt='".$clang->gT("Show previous...")."' /></a>\n"
."<img src='$imageurl/blank.gif' alt='' width='13' height='20' border='0' hspace='0' align='left' />\n"
."<a href='$scriptname?action=tokens&subaction=browse&sid=$surveyid&start=$next&limit=$limit&order=$order&searchstring=".urlencode($searchstring)."'" .
"title='".$clang->gTview("Show next...")."'>" .
"<img name='DForwardButton' align='left' src='$imageurl/dataforward.png' alt='".$clang->gT("Show next...")."' /></a>\n"
."<a href='$scriptname?action=tokens&subaction=browse&sid=$surveyid&start=$end&limit=$limit&order=$order&searchstring=".urlencode($searchstring)."'" .
"title='".$clang->gTview("Show last...")."'>".
"<img name='DEndButton' align='left' src='$imageurl/dataend.png' alt='".$clang->gT("Show last...")."' /></a>\n"
."<img src='$imageurl/seperator.gif' alt='' border='0' hspace='0' align='left' />\n";
}
$tokenoutput .="\t<form id='tokensearch' method='post' action='$scriptname?action=tokens'>\n"
."<input type='text' name='searchstring' value='".htmlspecialchars($searchstring,ENT_QUOTES,'utf-8')."' />\n"
."<input type='submit' value='".$clang->gT("Search")."' />\n"
."\t<input type='hidden' name='order' value='$order' />\n"
."\t<input type='hidden' name='subaction' value='search' />\n"
."\t<input type='hidden' name='sid' value='$surveyid' />\n"
."\t</form>\n"
."<form id='tokenrange' action='{$scriptname}'>\n"
."<img src='$imageurl/seperator.gif' alt='' border='0' />\n"
."<font size='1' face='verdana'>"
." <label for='limit'>".$clang->gT("Records displayed:")."</label> <input type='text' size='4' value='$limit' id='limit' name='limit' />"
." <label for='start'>".$clang->gT("Starting from:")."</label> <input type='text' size='4' value='$start' id='start' name='start' />"
." <input type='submit' value='".$clang->gT("Show")."' />\n"
."</font>\n"
."<input type='hidden' name='sid' value='$surveyid' />\n"
."<input type='hidden' name='action' value='tokens' />\n"
."<input type='hidden' name='subaction' value='browse' />\n"
."<input type='hidden' name='order' value='$order' />\n"
."<input type='hidden' name='searchstring' value='".htmlspecialchars($searchstring,ENT_QUOTES,'utf-8')."' />\n"
."</form>\n";
$bquery = "SELECT * FROM ".db_table_name("tokens_$surveyid");
if ($searchstring)
{
$sSearch=db_quote($searchstring);
$bquery .= " WHERE firstname LIKE '%{$sSearch}%' "
. "OR lastname LIKE '%{$sSearch}%' "
. "OR email LIKE '%{$sSearch}%' "
. "OR emailstatus LIKE '%{$sSearch}%' "
. "OR token LIKE '%{$sSearch}%'";
}
if (!isset($order) || !$order) {$bquery .= " ORDER BY tid";}
else {$bquery .= " ORDER BY $order"; }
$bresult = db_select_limit_assoc($bquery, $limit, $start) or safe_die ($clang->gT("Error").": $bquery<br />".$connect->ErrorMsg());
$bgc="";
$tokenoutput .= "</div></div></div>\n";
$tokenoutput .= "<table class='browsetokens' id='browsetokens' cellpadding='1' cellspacing='1'>\n";
//COLUMN HEADINGS
$tokenoutput .= "\t<tr>\n"
."<th><input type='checkbox' id='tokencheckboxtoggle' /></th>\n" //Checkbox
."<th align='left' >"
."<a href='$scriptname?action=tokens&sid=$surveyid&subaction=browse&order=tid&start=$start&limit=$limit&searchstring=".urlencode($searchstring)."'>"
."<img src='$imageurl/downarrow.png' title='"
.$clang->gT("Sort by: ")