/
tokens.php
1756 lines (1599 loc) · 83.2 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 #
#############################################################
# > Author: Jason Cleeland #
# > E-mail: jason@cleeland.org #
# > Mail: Box 99, Trades Hall, 54 Victoria St, #
# > CARLTON SOUTH 3053, AUSTRALIA #
# > Date: 20 February 2003 #
# #
# This set of scripts allows you to develop, publish and #
# perform data-entry on surveys. #
#############################################################
# #
# Copyright (C) 2003 Jason Cleeland #
# #
# This program is free software; you can redistribute #
# it and/or modify it under the terms of the GNU General #
# Public License Version 2 as published by the Free #
# Software Foundation. #
# #
# #
# This program is distributed in the hope that it will be #
# useful, but WITHOUT ANY WARRANTY; without even the #
# implied warranty of MERCHANTABILITY or FITNESS FOR A #
# PARTICULAR PURPOSE. See the GNU General Public License #
# for more details. #
# #
# You should have received a copy of the GNU General #
# Public License along with this program; if not, write to #
# the Free Software Foundation, Inc., 59 Temple Place - #
# Suite 330, Boston, MA 02111-1307, USA. #
#############################################################
*/
# TOKENS FILE
if (!isset($dbprefix) || isset($_REQUEST['dbprefix'])) {die("Cannot run this script directly");}
if ($enableLdap)
{
require_once(dirname(__FILE__).'/../config-ldap.php');
}
//if (!isset($action)) {$action=returnglobal('action');}
//if (!isset($subaction)) {$subaction=returnglobal('subaction');}
if (!isset($surveyid)) {$surveyid=returnglobal('sid');}
if (!isset($order)) {$order=returnglobal('order');}
if (!isset($limit)) {$limit=returnglobal('limit');}
if (!isset($start)) {$start=returnglobal('start');}
if (!isset($searchstring)) {$searchstring=returnglobal('searchstring');}
include_once("login_check.php");
include_once("database.php");
$tokenoutput='';
$sumquery5 = "SELECT b.* FROM {$dbprefix}surveys AS a INNER JOIN {$dbprefix}surveys_rights AS b ON a.sid = b.sid WHERE a.sid=$surveyid AND b.uid = ".$_SESSION['loginID']; //Getting rights for this survey and user
$sumresult5 = db_execute_assoc($sumquery5);
$sumrows5 = $sumresult5->FetchRow();
if ($subaction == "export" && $sumrows5['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");
$bquery = "SELECT * FROM ".db_table_name("tokens_$surveyid");
$bquery .= " ORDER BY tid";
$bresult = db_execute_assoc($bquery) or die ("$bquery<br />".htmlspecialchars($connect->ErrorMsg()));
$bfieldcount=$bresult->FieldCount();
$tokenoutput .= "firstname, lastname, email, token, language code, attribute1, attribute2, tid\n";
while ($brow = $bresult->FetchRow())
{
$tokenoutput .= '"'.trim($brow['firstname'])."\",";
$tokenoutput .= '"'.trim($brow['lastname'])."\",";
$tokenoutput .= '"'.trim($brow['email'])."\",";
$tokenoutput .= '"'.trim($brow['token'])."\",";
$tokenoutput .= '"'.trim($brow['language'])."\"";
if($bfieldcount > 8)
{
$tokenoutput .= ",";
$tokenoutput .= '"'.trim($brow['attribute_1'])."\",";
$tokenoutput .= '"'.trim($brow['attribute_2'])."\",";
$tokenoutput .= '"'.trim($brow['tid'])."\"";
}
$tokenoutput .= "\n";
}
echo $tokenoutput;
exit;
}
if ($subaction == "delete" && ($sumrows5['edit_survey_property'] || $sumrows5['activate_survey']))
{
$_SESSION['metaHeader']="<meta http-equiv=\"refresh\" content=\"1;URL={$scriptname}?action=tokens&subaction=browse&sid={$_GET['sid']}&start=$start&limit=$limit&order=$order\" />";
}
//Show Help
$tokenoutput .= "<script type='text/javascript'>\n"
."<!--\n"
."\tfunction showhelp(action)\n"
."\t\t{\n"
."\t\tvar name='help';\n"
."\t\tif (action == \"hide\")\n"
."\t\t\t{\n"
."\t\t\tdocument.getElementById(name).style.display='none';\n"
."\t\t\t}\n"
."\t\telse if (action == \"show\")\n"
."\t\t\t{\n"
."\t\t\tdocument.getElementById(name).style.display='';\n"
."\t\t\t}\n"
."\t\t}\n"
."-->\n"
."</script>\n";
$tokenoutput .= "<table width='100%' border='0' cellpadding='0' cellspacing='0'>\n"
."\t<tr>\n"
."\t\t<td valign='top' align='center' bgcolor='#BBBBBB'>\n"
."\t\t<table><tr><td></td></tr></table>\n";
$tokenoutput .= "<table class='menubar' cellpadding='1' cellspacing='0'>\n";
// MAKE SURE THAT THERE IS A SID
if (!isset($surveyid) || !$surveyid)
{
$tokenoutput .= "\t<tr><td colspan='2' height='4'><font size='1'><strong>"
.$clang->gT("Token Control").":</strong></font></td></tr>\n"
."\t<tr><td align='center'><br /><font color='red'><strong>"
.$clang->gT("Error")."</strong></font><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 /><br /></td></tr>\n"
."</table>\n"
."</body>\n</html>";
return;
}
// MAKE SURE THAT THE SURVEY EXISTS
$chquery = "SELECT * FROM ".db_table_name('surveys')." as a inner join ".db_table_name('surveys_languagesettings')." as b on (b.surveyls_survey_id=a.sid and b.surveyls_language=a.language) WHERE a.sid=$surveyid";
$chresult=db_execute_assoc($chquery);
$chcount=$chresult->RecordCount();
if (!$chcount)
{
$tokenoutput .= "\t<tr><td colspan='2' height='4'><font size='1'><strong>"
.$clang->gT("Token Control").":</strong></font></td></tr>\n"
."\t<tr><td align='center'><br /><font color='red'><strong>"
.$clang->gT("Error")."</strong></font><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 /><br /></td></tr>\n"
."</table>\n"
."</body>\n</html>";
return;
}
// A survey DOES exist
while ($chrow = $chresult->FetchRow())
{
$tokenoutput .= "\t<tr><td colspan='2' height='4'><font size='1'><strong>"
.$clang->gT("Token Control").":</strong> "
."<font>{$chrow['surveyls_title']}</font></font></td></tr>\n";
$surveyprivate = $chrow['private'];
}
// CHECK TO SEE IF A TOKEN TABLE EXISTS FOR THIS SURVEY
$tkquery = "SELECT * FROM ".db_table_name("tokens_$surveyid");
if (!$tkresult = $connect->Execute($tkquery)) //If the query fails, assume no tokens table exists
{
if (isset($_GET['createtable']) && $_GET['createtable']=="Y" && ($sumrows5['edit_survey_property'] || $sumrows5['activate_survey']))
{
$createtokentable=
"tid int I NOTNULL AUTO PRIMARY,\n "
. "firstname C(40) ,\n "
. "lastname C(40) ,\n "
. "email C(100) ,\n "
. "token C(10) ,\n "
. "language C(25) ,\n "
. "sent C(17) DEFAULT 'N',\n "
. "completed C(15) DEFAULT 'N',\n "
. "attribute_1 C(100) ,\n"
. "attribute_2 C(100) ,\n"
. "mpid I ";
$tabname = "{$dbprefix}tokens_{$surveyid}"; # not using db_table_name as it quotes the table name (as does CreateTableSQL)
$taboptarray = array('mysql' => 'TYPE='.$databasetabletype);
$dict = NewDataDictionary($connect);
$sqlarray = $dict->CreateTableSQL($tabname, $createtokentable, $taboptarray);
$execresult=$dict->ExecuteSQLArray($sqlarray, false);
if ($execresult==0 || $execresult==1)
{
$tokenoutput .= "\t<tr>\n"
."\t\t<td align='center'>\n"
. "<br />\n<table width='350' align='center' class='menubar' cellpadding='1' cellspacing='0'>\n" .
"<tr><td height='4'><font size='1'><strong><center>".$clang->gT("Token table could not be created.")."</center></strong></font></td></tr>\n" .
"<tr><td>\n" .
$clang->gT("Error").": \n<font color='red'>" . $connect->ErrorMsg() . "</font>\n" .
"<pre>".implode(" ",$sqlarray)."</pre>\n" .
"</td></tr></table>"
."\t\t\t<input type='submit' value='"
.$clang->gT("Main Admin Screen")."' onclick=\"window.open('$scriptname?sid=$surveyid', '_top')\" />\n"
."\t\t</td>\n"
."\t</tr>\n"
."</table>\n"
."<table><tr><td></td></tr></table>\n"
."</td></tr></table>\n";
} else {
$createtokentableindex = $dict->CreateIndexSQL("{$tabname}_idx", $tabname, array('token'));
$dict->ExecuteSQLArray($createtokentableindex, false) or die ("Failed to create token table index<br />$createtokentableindex<br /><br />".htmlspecialchars($connect->ErrorMsg()));
$tokenoutput .= "\t<tr>\n"
."\t\t<td align='center'>\n"
."\t\t\t<br /><br />\n"
."\t\t\t".$clang->gT("A token table has been created for this survey.")." (\"tokens_$surveyid\")<br /><br />\n"
."\t\t\t<input type='submit' value='"
.$clang->gT("Continue")."' onclick=\"window.open('$scriptname?action=tokens&sid=$surveyid', '_top')\" />\n"
."\t\t</td>\n"
."\t</tr>\n"
."</table>\n"
."<table><tr><td></td></tr></table>\n"
."</td></tr></table>\n";
}
return;
}
elseif (returnglobal('restoretable') == "Y" && returnglobal('oldtable') && ($sumrows5['edit_survey_property'] || $sumrows5['activate_survey']))
{
$query = db_rename_table(db_quote_id(returnglobal('oldtable')) , db_table_name("tokens_$surveyid"));
$result=$connect->Execute($query) or die("Failed Rename!<br />".$query."<br />".htmlspecialchars($connect->ErrorMsg()));
$tokenoutput .= "\t<tr>\n"
."\t\t<td align='center'>\n"
."\t\t\t<br /><br />\n"
."\t\t\t".$clang->gT("A token table has been created for this survey.")." (\"tokens_$surveyid\")<br /><br />\n"
."\t\t\t<input type='submit' value='"
.$clang->gT("Continue")."' onclick=\"window.open('$scriptname?action=tokens&sid=$surveyid', '_top')\" />\n"
."\t\t</td>\n"
."\t</tr>\n"
."</table>\n"
."<table><tr><td></td></tr></table>\n"
."</td></tr></table>\n";
return;
}
else
{
$query=db_select_tables_like("{$dbprefix}old_tokens_".$surveyid."_%");
$result=db_execute_num($query) or die("Couldn't get old table list<br />".$query."<br />".htmlspecialchars($connect->ErrorMsg()));
$tcount=$result->RecordCount();
if ($tcount > 0)
{
while($rows=$result->FetchRow())
{
$oldlist[]=$rows[0];
}
}
$tokenoutput .= "\t<tr>\n"
."\t\t<td align='center'>\n"
."\t\t\t<br /><font color='red'><strong>".$clang->gT("Warning")."</strong></font><br />\n"
."\t\t\t<strong>".$clang->gT("Tokens have not been initialised for this survey.")."</strong><br /><br />\n";
if ($sumrows5['edit_survey_property'] || $sumrows5['activate_survey'])
{
$tokenoutput .= "\t\t\t".$clang->gT("If you initialise tokens for this survey, the survey will only be accessible to users who have been assigned a token.")
."\t\t\t<br /><br />\n";
$thissurvey=getSurveyInfo($surveyid);
if ($thissurvey['private'] == 'Y' && $thissurvey['datestamp'] =='Y')
{
$tokenoutput .= "\t\t\t".$clang->gT("If you set a survey to anonymous, answers to timestamped and create a tokens table, LimeSurvey will mark your completed tokens only with a 'Y' instead of date/time to ensure the anonymity of your participants.")
."\t\t\t<br /><br />\n";
}
$tokenoutput .= "\t\t\t".$clang->gT("Do you want to create a tokens table for this survey?");
$tokenoutput .= "<br /><br />\n";
$tokenoutput .= "\t\t\t<input type='submit' value='"
.$clang->gT("Initialise Tokens")."' onclick=\"window.open('$scriptname?action=tokens&sid=$surveyid&createtable=Y', '_top')\" /><br />\n";
}
$tokenoutput .= "\t\t\t<input type='submit' value='"
.$clang->gT("Main Admin Screen")."' onclick=\"window.open('$homeurl/admin.php?sid=$surveyid', '_top')\" /><br /><br />\n";
if ($tcount>0 && ($sumrows5['edit_survey_property'] || $sumrows5['activate_survey']))
{
$tokenoutput .= "<table width='350' border='0' align='center' style='border: 1px solid #555555' cellpadding='1' cellspacing='0'><tr>\n"
."<td class='settingcaption'><font>".$clang->gT("Restore Options").":\n"
."</font></td></tr>\n"
."<tr>\n"
."<td class='evenrow' align='center'><form method='post' >\n"
.$clang->gT("The following old token tables could be restored:")."<br />\n"
."<select size='4' name='oldtable'>\n";
foreach($oldlist as $ol)
{
$tokenoutput .= "<option>".$ol."</option>\n";
}
$tokenoutput .= "</select><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></td>\n"
."</tr></table>\n";
}
$tokenoutput .= "\t\t</td>\n"
."\t</tr>\n"
."</table>\n"
."<table><tr><td></td></tr></table>\n"
."</td></tr></table>\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 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
$tokenoutput .= "\t<tr>\n"
."\t\t<td>\n"
."\t\t\t<a href=\"#\" onclick=\"showhelp('show')\" onmouseout=\"hideTooltip()\""
."onmouseover=\"showTooltip(event,'".$clang->gT("Show Help", "js")."');return false\">" .
"<img src='$imagefiles/showhelp.png' title='' align='right' alt='' /></a>\n"
."\t\t\t<a href=\"#\" onclick=\"window.open('$scriptname?sid=$surveyid', '_top')\" onmouseout=\"hideTooltip()\""
."onmouseover=\"showTooltip(event,'".$clang->gT("Return to Survey Administration", "js")."');return false\">" .
"<img name='HomeButton' src='$imagefiles/home.png' align='left' alt='' /></a>\n"
."\t\t\t<img src='$imagefiles/blank.gif' alt='' width='11' border='0' hspace='0' align='left' />\n"
."\t\t\t<img src='$imagefiles/seperator.gif' alt='' border='0' hspace='0' align='left' />\n"
."\t\t\t<a href=\"#\" onclick=\"window.open('$scriptname?action=tokens&sid=$surveyid', '_top')\" onmouseout=\"hideTooltip()\" onmouseover=\"showTooltip(event,'".$clang->gT("Show summary information", "js")."');return false\" >" .
"<img name='SummaryButton' src='$imagefiles/summary.png' title='' align='left' alt='' /></a>\n"
."\t\t\t<a href=\"#\" onclick=\"window.open('$scriptname?action=tokens&sid=$surveyid&subaction=browse', '_top')\" onmouseout=\"hideTooltip()\""
."onmouseover=\"showTooltip(event,'".$clang->gT("Display Tokens", "js")."');return false\">" .
"<img name='ViewAllButton' src='$imagefiles/document.png' title='' align='left' alt='' /></a>\n"
."\t\t\t<img src='$imagefiles/blank.gif' alt='' width='20' border='0' hspace='0' align='left' />\n"
."\t\t\t<img src='$imagefiles/seperator.gif' alt='' border='0' hspace='0' align='left' />\n";
if ($sumrows5['edit_survey_property'] || $sumrows5['activate_survey'])
{
$tokenoutput .= "\t\t\t<a href=\"#\" onclick=\"window.open('$scriptname?action=tokens&sid=$surveyid&subaction=addnew', '_top')\" onmouseout=\"hideTooltip()\"" .
"onmouseover=\"showTooltip(event,'".$clang->gT("Add new token entry", "js")."');return false\">" .
"<img name='AddNewButton' src='$imagefiles/add.png' title='' align='left' alt='' /></a>\n"
."\t\t\t<a href=\"#\" onclick=\"window.open('$scriptname?action=tokens&sid=$surveyid&subaction=import', '_top')\" onmouseout=\"hideTooltip()\" ".
"onmouseover=\"showTooltip(event,'".$clang->gT("Import Tokens from CSV File", "js")."');return false\"> <img name='ImportButton' src='$imagefiles/importcsv.png' title='' align='left' alt='' /></a>"
."\t\t\t<a href=\"#\" onclick=\"window.open('$scriptname?action=tokens&sid=$surveyid&subaction=importldap', '_top')\" onmouseout=\"hideTooltip()\" ".
"onmouseover=\"showTooltip(event,'".$clang->gT("Import Tokens from LDAP Query", "js")."');return false\"> <img name='ImportLdapButton' src='$imagefiles/importldap.png' title='' alt='' align='left' /></a>";
}
if ($sumrows5['export'])
{
$tokenoutput .= "\t\t\t<a href=\"#\" onclick=\"window.open('$scriptname?action=tokens&sid=$surveyid&subaction=export', '_top')\" onmouseout=\"hideTooltip()\"" .
"onmouseover=\"showTooltip(event,'".$clang->gT("Export Tokens to CSV file", "js")."');return false\">".
"<img name='ExportButton' src='$imagefiles/exportcsv.png' align='left' alt='' /></a>\n";
}
if ($sumrows5['edit_survey_property'] || $sumrows5['activate_survey'])
{
$tokenoutput .= "\t\t\t<img src='$imagefiles/seperator.gif' alt='' border='0' hspace='0' align='left' />\n"
."\t\t\t<a href=\"#\" onclick=\"window.open('$scriptname?action=tokens&sid=$surveyid&subaction=email', '_top')\" onmouseout=\"hideTooltip()\" onmouseover=\"showTooltip(event,'".$clang->gT("Send email invitation", "js")."');return false\">" .
"<img name='InviteButton' src='$imagefiles/invite.png' title='' align='left' alt='' /></a>\n"
."\t\t\t<a href=\"#\" onclick=\"window.open('$scriptname?action=tokens&sid=$surveyid&subaction=remind', '_top')\" onmouseout=\"hideTooltip()\" onmouseover=\"showTooltip(event,'".$clang->gT("Send email reminder", "js")."');return false\">" .
"<img name='RemindButton' src='$imagefiles/remind.png' title='' align='left' alt='' /></a>\n"
."\t\t\t<img src='$imagefiles/seperator.gif' border='0' hspace='0' align='left' alt='' />\n"
."\t\t\t<a href=\"#\" onclick=\"window.open('$scriptname?action=tokens&sid=$surveyid&subaction=tokenify', '_top')\" onmouseout=\"hideTooltip()\" onmouseover=\"showTooltip(event,'".$clang->gT("Generate Tokens", "js")."');return false\">" .
"<img name='TokenifyButton' src='$imagefiles/tokenify.png' title='' align='left' alt='' /></a>\n"
."\t\t\t<img src='$imagefiles/seperator.gif' border='0' hspace='0' align='left' alt='' />\n"
."\t\t\t<a href=\"#\" onclick=\"window.open('$scriptname?action=tokens&sid=$surveyid&subaction=kill', '_top')\" onmouseout=\"hideTooltip()\" onmouseover=\"showTooltip(event,'".$clang->gT("Drop tokens table", "js")."');return false\">" .
"<img name='DeleteTokensButton' src='$imagefiles/delete.png' title='' align='left' alt='' /></a>\n"
."\t\t</td>\n";
}
$tokenoutput .= "\t</tr>\n";
// SEE HOW MANY RECORDS ARE IN THE TOKEN TABLE
$tkcount = $tkresult->RecordCount();
// GIVE SOME INFORMATION ABOUT THE TOKENS
$tokenoutput .= "\t<tr>\n"
."\t\t<td align='center'>\n"
."\t\t<br />\n"
."\t\t\t<table align='center' bgcolor='#DDDDDD' cellpadding='2' style='border: 1px solid #555555'>\n"
."\t\t\t\t<tr>\n"
."\t\t\t\t\t<td align='center'>\n"
."\t\t\t\t\t<strong>".$clang->gT("Total Records in this Token Table").": $tkcount</strong><br />\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 .= "\t\t\t\t\t\t".$clang->gT("Total With No Unique Token").": $tkr[0] / $tkcount<br />\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 .= "\t\t\t\t\t\t".$clang->gT("Total Invitations Sent").": $tkr[0] / $tkcount<br />\n";}
$tksq = "SELECT count(*) FROM ".db_table_name("tokens_$surveyid")." WHERE (completed!='N' and completed<>'')";
$tksr = db_execute_num($tksq) or die ("Couldn't execute token selection query<br />$abquery<br />".$connect->ErrorMsg());
while ($tkr = $tksr->FetchRow())
{$tokenoutput .= "\t\t\t\t\t\t".$clang->gT("Total Surveys Completed").": $tkr[0] / $tkcount\n";}
$tokenoutput .= "\t\t\t\t\t</td>\n"
."\t\t\t\t</tr>\n"
."\t\t\t</table>\n"
."\t\t\t<br />\n"
."\t\t</td>\n"
."\t</tr>\n"
."</table>\n"
."<table ><tr><td></td></tr></table>\n";
$tokenoutput .= "<table width='99%' class='menubar' cellpadding='1' cellspacing='0'>\n";
#############################################################################################
// NOW FOR VARIOUS ACTIONS:
if ($subaction == "deleteall" && ($sumrows5['edit_survey_property'] || $sumrows5['activate_survey']))
{
$query="DELETE FROM ".db_table_name("tokens_$surveyid");
$result=$connect->Execute($query) or die ("Couldn't update sent field<br />$query<br />".htmlspecialchars($connect->ErrorMsg()));
$tokenoutput .= "<tr><td bgcolor='silver' align='center'><strong><font color='green'>".$clang->gT("All token entries have been deleted.")."</font></strong></td></tr>\n";
$subaction="";
}
if ($subaction == "clearinvites" && ($sumrows5['edit_survey_property'] || $sumrows5['activate_survey']))
{
$query="UPDATE ".db_table_name("tokens_$surveyid")." SET sent='N'";
$result=$connect->Execute($query) or die ("Couldn't update sent field<br />$query<br />".htmlspecialchars($connect->ErrorMsg()));
$tokenoutput .= "<tr><td bgcolor='silver' align='center'><strong><font color='green'>".$clang->gT("All invite entries have been set to 'Not Invited'.")."</font></strong></td></tr>\n";
$subaction="";
}
if ($subaction == "cleartokens" && ($sumrows5['edit_survey_property'] || $sumrows5['activate_survey']))
{
$query="UPDATE ".db_table_name("tokens_$surveyid")." SET token=''";
$result=$connect->Execute($query) or die("Couldn't reset the tokens field<br />$query<br />".htmlspecialchars($connect->ErrorMsg()));
$tokenoutput .= "<tr><td align='center' bgcolor='silver'><strong><font color='green'>".$clang->gT("All unique token numbers have been removed.")."</font></strong></td></tr>\n";
$subaction="";
}
if ($subaction == "updatedb" && $surveyid && ($sumrows5['edit_survey_property'] || $sumrows5['activate_survey']))
{
$query = "ALTER TABLE `tokens_$surveyid`\n"
. "ADD `attribute_1` varchar(100) NULL,\n"
. "ADD `attribute_2` varchar(100) NULL,\n"
. "ADD `mpid` int NULL";
if ($result = $connect->Execute($query))
{
$tokenoutput .= "<tr><td align='center'>".$clang->gT("Success")."</td></tr>\n";
$subaction="";
}
else
{
$tokenoutput .= "<tr><td align='center'>".$clang->gT("Error")."</td></tr>\n";
$subaction="";
}
}
if (!$subaction && ($sumrows5['edit_survey_property'] || $sumrows5['activate_survey']))
{
$tokenoutput .= "\t<tr><td colspan='2' height='4'><font size='1'><strong>"
.$clang->gT("Token Database Administration Options").":</strong></font></td></tr>\n"
."\t<tr>\n"
."\t\t<td align='center'>\n"
."\t\t\t<table align='center'><tr><td>\n"
."\t\t\t<br />\n"
."\t\t\t<ul><li><a href='$scriptname?action=tokens&sid=$surveyid&subaction=clearinvites' onclick='return confirm(\""
.$clang->gT("Are you really sure you want to reset all invitation records to NO?")."\")'>".$clang->gT("Set all entries to 'No invitation sent'.")."</a></li>\n"
."\t\t\t<li><a href='$scriptname?action=tokens&sid=$surveyid&subaction=cleartokens' onclick='return confirm(\""
.$clang->gT("Are you sure you want to delete all unique token numbers?")."\")'>".$clang->gT("Delete all unique token numbers")."</a></li>\n"
."\t\t\t<li><a href='$scriptname?action=tokens&sid=$surveyid&subaction=deleteall' onclick='return confirm(\""
.$clang->gT("Are you really sure you want to delete ALL token entries?")."\")'>".$clang->gT("Delete all token entries")."</a></li>\n";
$bquery = "SELECT * FROM ".db_table_name("tokens_$surveyid");
$bresult = db_select_limit_assoc($bquery, 1) or die($clang->gT("Error")." counting fields<br />".htmlspecialchars($connect->ErrorMsg()));
$bfieldcount=$bresult->FieldCount();
if ($bfieldcount==7)
{
$tokenoutput .= "\t\t\t<li><a href='$scriptname?action=tokens&sid=$surveyid&subaction=updatedb'>".$clang->gT("Update tokens table with new fields")."</a></li>\n";
}
$tokenoutput .= "\t\t\t<li><a href='$scriptname?action=tokens&sid=$surveyid&subaction=kill'>".$clang->gT("Drop tokens table")."</a></li></ul>\n"
."\t\t\t</td></tr></table>\n"
."\t\t</td>\n"
."\t</tr>\n"
."</table>\n";
}
if ($subaction == "browse" || $subaction == "search")
{
if (!isset($limit)) {$limit = 50;}
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;}
//ALLOW SELECTION OF NUMBER OF RECORDS SHOWN
$tokenoutput .= "\t<tr><td colspan='3' height='4'><font><strong>"
.$clang->gT("Data View Control").":</strong></font></td></tr>\n"
."\t<tr bgcolor='#999999'><td width='230' align='left' valign='middle'>\n"
."\t\t\t<img src='$imagefiles/blank.gif' alt='' width='31' height='20' border='0' hspace='0' align='left' />\n"
."\t\t\t<img src='$imagefiles/seperator.gif' alt='' border='0' hspace='0' align='left' />\n"
."\t\t\t<a href='$scriptname?action=tokens&subaction=browse&sid=$surveyid&start=0&limit=$limit&order=$order&searchstring=$searchstring'" .
"onmouseout=\"hideTooltip()\" onmouseover=\"showTooltip(event,'".$clang->gT("Show start..", "js")."');return false\">".
"<img name='DBeginButton' align='left' src='$imagefiles/databegin.png' title='' /></a>\n"
."\t\t\t<a href='$scriptname?action=tokens&subaction=browse&sid=$surveyid&start=$last&limit=$limit&order=$order&searchstring=$searchstring'" .
"onmouseout=\"hideTooltip()\" onmouseover=\"showTooltip(event,'".$clang->gT("Show previous...", "js")."');return false\">" .
"<img name='DBackButton' align='left' src='$imagefiles/databack.png' title='' /></a>\n"
."\t\t\t<img src='$imagefiles/blank.gif' alt='' width='13' height='20' border='0' hspace='0' align='left' />\n"
."\t\t\t<a href='$scriptname?action=tokens&subaction=browse&sid=$surveyid&start=$next&limit=$limit&order=$order&searchstring=$searchstring'" .
"onmouseout=\"hideTooltip()\" onmouseover=\"showTooltip(event,'".$clang->gT("Show next...", "js")."');return false\">" .
"<img name='DForwardButton' align='left' src='$imagefiles/dataforward.png' title='' /></a>\n"
."\t\t\t<a href='$scriptname?action=tokens&subaction=browse&sid=$surveyid&start=$end&limit=$limit&order=$order&searchstring=$searchstring'" .
" onmouseout=\"hideTooltip()\" onmouseover=\"showTooltip(event,'".$clang->gT("Show last...", "js")."');return false\">".
"<img name='DEndButton' align='left' src='$imagefiles/dataend.png' title='' /></a>\n"
."\t\t\t<img src='$imagefiles/seperator.gif' alt='' border='0' hspace='0' align='left' />\n"
."\t\t\t\n</td><td align='left'>"
."\t\t\t\t<form method='post' action='$scriptname?action=tokens'>\n"
."\t\t\t\t\t<input type='text' name='searchstring' value='$searchstring' />\n"
."\t\t\t\t\t<input type='submit' value='".$clang->gT("Search")."' />\n"
."\t\t\t\t<input type='hidden' name='order' value='$order' />\n"
."\t\t\t\t<input type='hidden' name='subaction' value='search' />\n"
."\t\t\t\t<input type='hidden' name='sid' value='$surveyid' />\n"
."\t\t\t\t</form>\n"
."\t\t</td>\n"
."\t\t<td align='right'><form action='$homeurl/admin.php'>\n"
."\t\t<font size='1' face='verdana'>"
." ".$clang->gT("Records Displayed:")."<input type='text' size='4' value='$limit' name='limit' />"
." ".$clang->gT("Starting From:")."<input type='text' size='4' value='$start' name='start' />"
." <input type='submit' value='".$clang->gT("Show")."' />\n"
."\t\t</font>\n"
."\t\t<input type='hidden' name='sid' value='$surveyid' />\n"
."\t\t<input type='hidden' name='action' value='tokens' />\n"
."\t\t<input type='hidden' name='subaction' value='browse' />\n"
."\t\t<input type='hidden' name='order' value='$order' />\n"
."\t\t<input type='hidden' name='searchstring' value='$searchstring' />\n"
."\t\t</form></td>\n"
."\t</tr>\n";
$bquery = "SELECT * FROM ".db_table_name("tokens_$surveyid");
$bresult = db_select_limit_assoc($bquery, 1) or die($clang->gT("Error")." counting fields<br />".htmlspecialchars($connect->ErrorMsg()));
$bfieldcount=$bresult->FieldCount()-1;
$bquery = "SELECT * FROM ".db_table_name("tokens_$surveyid");
if ($searchstring)
{
$bquery .= " WHERE firstname LIKE '%$searchstring%' "
. "OR lastname LIKE '%$searchstring%' "
. "OR email LIKE '%$searchstring%' "
. "OR token LIKE '%$searchstring%'";
if ($bfieldcount == 9)
{
$bquery .= " OR attribute_1 like '%$searchstring%' "
. "OR attribute_2 like '%$searchstring%'";
}
}
if (!isset($order) || !$order) {$bquery .= " ORDER BY tid";}
else {$bquery .= " ORDER BY $order"; }
//die($bquery.":::".$start.":::".$limit);
$bresult = db_select_limit_assoc($bquery, $limit, $start) or die ($clang->gT("Error").": $bquery<br />".htmlspecialchars($connect->ErrorMsg()));
$bgc="";
$tokenoutput .= "<tr><td colspan='3'>\n"
."<table width='100%' cellpadding='1' cellspacing='1' cellspacing='1' cellpadding='1' border='0' style='border: 1px solid rgb(85, 85, 85);'>\n";
//COLUMN HEADINGS
$tokenoutput .= "\t<tr>\n"
."\t\t<th align='left' valign='top' class='settingcaption'>"
."<a href='$scriptname?action=tokens&sid=$surveyid&subaction=browse&order=tid&start=$start&limit=$limit&searchstring=$searchstring'>"
."<img src='$imagefiles/downarrow.png' alt='' title='"
.$clang->gT("Sort by: ")."ID' border='0' align='left' hspace='0' /></a>"."ID</th>\n"
."\t\t<th align='left' valign='top' class='settingcaption'>"
."<a href='$scriptname?action=tokens&sid=$surveyid&subaction=browse&order=firstname&start=$start&limit=$limit&searchstring=$searchstring'>"
."<img src='$imagefiles/downarrow.png' alt='' title='"
.$clang->gT("Sort by: ").$clang->gT("First Name")."' border='0' align='left' /></a>".$clang->gT("First Name")."</th>\n"
."\t\t<th align='left' valign='top' class='settingcaption'>"
."<a href='$scriptname?action=tokens&sid=$surveyid&subaction=browse&order=lastname&start=$start&limit=$limit&searchstring=$searchstring'>"
."<img src='$imagefiles/downarrow.png' alt='' title='"
.$clang->gT("Sort by: ").$clang->gT("Last Name")."' border='0' align='left' /></a>".$clang->gT("Last Name")."</th>\n"
."\t\t<th align='left' valign='top' class='settingcaption'>"
."<a href='$scriptname?action=tokens&sid=$surveyid&subaction=browse&order=email&start=$start&limit=$limit&searchstring=$searchstring'>"
."<img src='$imagefiles/downarrow.png' alt='' title='"
.$clang->gT("Sort by: ").$clang->gT("Email")."' border='0' align='left' /></a>".$clang->gT("Email")."</th>\n"
."\t\t<th align='left' valign='top' class='settingcaption'>"
."<a href='$scriptname?action=tokens&sid=$surveyid&subaction=browse&order=token&start=$start&limit=$limit&searchstring=$searchstring'>"
."<img src='$imagefiles/downarrow.png' alt='' title='"
.$clang->gT("Sort by: ").$clang->gT("Token")."' border='0' align='left' /></a>".$clang->gT("Token")."</th>\n"
."\t\t<th align='left' valign='top' class='settingcaption'>"
."<a href='$scriptname?action=tokens&sid=$surveyid&subaction=browse&order=language&start=$start&limit=$limit&searchstring=$searchstring'>"
."<img src='$imagefiles/downarrow.png' alt='' title='"
.$clang->gT("Sort by: ").$clang->gT("Language")."' border='0' align='left' /></a>".$clang->gT("Language")."</th>\n"
."\t\t<th align='left' valign='top' class='settingcaption'>"
."<a href='$scriptname?action=tokens&sid=$surveyid&subaction=browse&order=sent%20desc&start=$start&limit=$limit&searchstring=$searchstring'>"
."<img src='$imagefiles/downarrow.png' alt='' title='"
.$clang->gT("Sort by: ").$clang->gT("Invite sent?")."' border='0' align='left' /></a>".$clang->gT("Invite sent?")."</th>\n"
."\t\t<th align='left' valign='top' class='settingcaption'>"
."<a href='$scriptname?action=tokens&sid=$surveyid&subaction=browse&order=completed%20desc&start=$start&limit=$limit&searchstring=$searchstring'>"
."<img src='$imagefiles/downarrow.png' alt='' title='"
.$clang->gT("Sort by: ").$clang->gT("Completed?")."' border='0' align='left' /></a>".$clang->gT("Completed?")."</th>\n";
if ($bfieldcount == 10)
{
$tokenoutput .= "\t\t<th align='left' valign='top' class='settingcaption'>"
."<a href='$scriptname?action=tokens&sid=$surveyid&subaction=browse&order=attribute_1&start=$start&limit=$limit&searchstring=$searchstring'>"
."<img src='$imagefiles/downarrow.png' alt='' title='"
.$clang->gT("Sort by: ").$clang->gT("Attribute 1")."' border='0' align='left' /></a>".$attr1_name."</th>\n"
."\t\t<th align='left' valign='top' class='settingcaption'>"
."<a href='$scriptname?action=tokens&sid=$surveyid&subaction=browse&order=attribute_2&start=$start&limit=$limit&searchstring=$searchstring'>"
."<img src='$imagefiles/downarrow.png' alt='' title='"
.$clang->gT("Sort by: ").$clang->gT("Attribute 2")."' border='0' align='left' /></a>".$attr2_name."</th>\n";
//."\t\t<th align='left' valign='top'>"
//."<a href='$scriptname?action=tokens&sid=$surveyid&subaction=browse&order=mpid&start=$start&limit=$limit&searchstring=$searchstring'>"
//."<img src='$imagefiles/downarrow.png' alt='"
//.$clang->gT("Sort by: ").$clang->gT("MPID")."' border='0' align='left'></a>".$clang->gT("MPID")."</th>\n";
}
$tokenoutput .= "\t\t<th align='left' valign='top' colspan='4' class='settingcaption'>".$clang->gT("Actions")."</th>\n"
."\t</tr>\n";
while ($brow = $bresult->FetchRow())
{
$brow['token'] = trim($brow['token']);
if ($bgc == "evenrow") {$bgc = "oddrow";} else {$bgc = "evenrow";}
$tokenoutput .= "\t<tr class='$bgc'>\n";
foreach ($brow as $a=>$b)
{
$tokenoutput .= "\t\t<td class='$bgc'>$brow[$a]</td>\n";
}
if ($sumrows5['edit_survey_property'] || $sumrows5['activate_survey'])
{
$tokenoutput .= "\t\t<td align='left'>\n"
."\t\t\t<input style='height: 16; width: 16px; font-size: 8; font-family: verdana' type='submit' value='E' title='"
.$clang->gT("Edit Token Entry")."' onclick=\"window.open('$scriptname?action=tokens&sid=$surveyid&subaction=edit&tid=".$brow['tid']."', '_top')\" />"
."<input style='height: 16; width: 16px; font-size: 8; font-family: verdana' type='submit' value='D' title='"
.$clang->gT("Delete Token Entry")."' onclick=\"window.open('$scriptname?action=tokens&sid=$surveyid&subaction=delete&tid=".$brow['tid']."&limit=$limit&start=$start&order=$order', '_top')\" />";
if (($brow['completed'] == "N" || $brow['completed'] == "") &&$brow['token']) {$tokenoutput .= "<input style='height: 16; width: 16px; font-size: 8; font-family: verdana' type='submit' value='S' title='".$clang->gT("Do Survey")."' onclick=\"window.open('$publicurl/index.php?sid=$surveyid&lang=".$brow['language']."&token=".trim($brow['token'])."', '_blank')\" />\n";}
$tokenoutput .= "\n\t\t</td>\n";
}
if ($brow['completed'] != "N" && $brow['completed']!="" && $surveyprivate == "N")
{
// Get response Id
$query="SELECT id FROM ".db_table_name("survey_$surveyid")." WHERE token='".$brow['token']."'";
$result=db_execute_num($query) or die ("<br />Could not find token!<br />\n" . htmlspecialchars($connect->ErrorMsg()));
list($id) = $result->FetchRow();
// UPDATE button to the tokens display in the MPID Actions column
if ($id)
{
$tokenoutput .= "\t\t<form action='$homeurl/$scriptname?action=browse' method='post' target='_blank'>\n"
."\t\t<td align='center' valign='top'>\n"
."\t\t\t<input style='height: 16; width: 16px; font-size: 8; font-family: verdana' type='submit' value='V' title='"
.$clang->gT("View Response")."' />\n"
."\t\t</td>\n"
."\t\t<input type='hidden' name='sid' value='$surveyid' />\n"
."\t\t<input type='hidden' value='id' name='subaction' />\n"
."\t\t<input type='hidden' value='$id' name='id' />\n"
."\t\t</form>\n";
$tokenoutput .= "\t\t<form action='$homeurl/$scriptname?action=dataentry&subaction=edit' method='post' target='_blank'>\n";
$tokenoutput .= "\t\t<form action='$homeurl/$scriptname?action=dataentry' method='post' target='_blank'>\n"
."\t\t<td align='center' valign='top'>\n"
."\t\t\t<input style='height: 16; width: 16px; font-size: 8; font-family: verdana' type='submit' value='U' title='"
.$clang->gT("Update Response")."' />\n"
."\t\t</td>\n"
."\t\t<input type='hidden' name='sid' value='$surveyid' />\n"
// ."\t\t<input type='hidden' $subaction value='edit' />\n"
."\t\t<input type='hidden' name='surveytable' value='survey_$surveyid' />\n"
."\t\t<input type='hidden' name='id' value='$id' />\n"
."\t\t</form>\n";
}
}
elseif ($brow['completed'] == "N" && $brow['token'] && $brow['sent'] == "N")
{
$tokenoutput .= "\t\t<td align='center' valign='middle'>\n"
."\t\t\t<input style='height: 16; width: 16px; font-size: 8; font-family: verdana' type='submit' value='I' title='"
.$clang->gT("Send invitation email to this entry")."' onclick=\"window.open('{$_SERVER['PHP_SELF']}?action=tokens&sid=$surveyid&subaction=email&tid=".$brow['tid']."', '_top')\" />"
."\t\t</td>\n";
}
elseif ($brow['completed'] == "N" && $brow['token'] && $brow['sent'] != "N")
{
$tokenoutput .= "\t\t<td align='center' valign='middle'>\n"
."\t\t\t<input style='height: 16; width: 16px; font-size: 8; font-family: verdana' type='submit' value='R' title='"
.$clang->gT("Send reminder email to this entry")."' onclick=\"window.open('{$_SERVER['PHP_SELF']}?sid=$surveyid&action=tokens&subaction=remind&tid=".$brow['tid']."', '_top')\" />"
."\t\t</td>\n";
}
else
{
$tokenoutput .= "\t\t<td>\n"
."\t\t</td>\n";
}
$tokenoutput .= "\t</tr>\n";
}
$tokenoutput .= "</table>\n"
."</td></tr></table>\n";
}
if ($subaction == "kill" && ($sumrows5['edit_survey_property'] || $sumrows5['activate_survey']))
{
$date = date('YmdHis');
$tokenoutput .= "\t<tr><td colspan='2' height='4' align='center'>"
."<strong>".$clang->gT("Delete Tokens Table").":</strong>"
."</td></tr>\n"
."\t<tr><td colspan='2' align='center'>\n"
."<br />\n";
// ToDo: Just delete it if there is no token in the table
if (!isset($_GET['ok']) || !$_GET['ok'])
{
$tokenoutput .= "<font color='red'><strong>".$clang->gT("Warning")."</strong></font><br />\n"
.$clang->gT("If you delete this table tokens will no longer be required to access this survey.")."<br />".$clang->gT("A backup of this table will be made if you proceed. Your system administrator will be able to access this table.")."<br />\n"
."( \"old_tokens_{$_GET['sid']}_$date\" )<br /><br />\n"
."<input type='submit' value='"
.$clang->gT("Delete Tokens")."' onclick=\"window.open('$scriptname?action=tokens&sid=$surveyid&subaction=kill&ok=surething', '_top')\" /><br />\n"
."<input type='submit' value='"
.$clang->gT("Cancel")."' onclick=\"window.open('$scriptname?action=tokens&sid=$surveyid', '_top')\" />\n";
}
elseif (isset($_GET['ok']) && $_GET['ok'] == "surething")
{
$oldtable = "tokens_$surveyid";
$newtable = "old_tokens_{$surveyid}_$date";
$deactivatequery = db_rename_table( db_table_name($oldtable), db_table_name($newtable));
$deactivateresult = $connect->Execute($deactivatequery) or die ("Couldn't deactivate because:<br />\n".htmlspecialchars($connect->ErrorMsg())." - Query: $deactivatequery <br /><br />\n<a href='$scriptname?sid=$surveyid'>Admin</a>\n");
$tokenoutput .= "<span style='display: block; text-align: center; width: 70%'>\n"
.$clang->gT("The tokens table has now been removed and tokens are no longer required to access this survey.")."<br /> ".$clang->gT("A backup of this table has been made and can be accessed by your system administrator.")."<br />\n"
."(\"{$dbprefix}old_tokens_{$_GET['sid']}_$date\")"."<br /><br />\n"
."<input type='submit' value='"
.$clang->gT("Main Admin Screen")."' onclick=\"window.open('$scriptname?sid={$_GET['sid']}', '_top')\" />\n"
."</span>\n";
}
$tokenoutput .= "</font></td></tr></table>\n"
."<table><tr><td></td></tr></table>\n";
}
if ($subaction == "email" && ($sumrows5['edit_survey_property'] || $sumrows5['activate_survey']))
{
$tokenoutput .= "\t<tr>\n\t\t<td colspan='2' height='4'>"
."<strong>"
.$clang->gT("Email Invitation").":</strong></td>\n\t</tr>\n"
."\t<tr>\n\t\t<td colspan='2' align='center'>\n";
if (!isset($_POST['ok']) || !$_POST['ok'])
{
$tokenoutput .= "<form method='post' action='$scriptname?action=tokens&sid=$surveyid'>";
$surveylangs = GetAdditionalLanguagesFromSurveyID($surveyid);
$baselang = GetBaseLanguageFromSurveyID($surveyid);
array_unshift($surveylangs,$baselang);
$tokenoutput .= "<div class='tab-pane' id='tab-pane-1'>";
foreach ($surveylangs as $language)
{
//GET SURVEY DETAILS
$thissurvey=getSurveyInfo($surveyid,$language);
if (!$thissurvey['email_invite']) {$thissurvey['email_invite']=str_replace("\n", "\r\n", $clang->gT("Dear {FIRSTNAME},\n\nYou have been invited to participate in a survey.\n\nThe survey is titled:\n\"{SURVEYNAME}\"\n\n\"{SURVEYDESCRIPTION}\"\n\nTo participate, please click on the link below.\n\nSincerely,\n\n{ADMINNAME} ({ADMINEMAIL})\n\n----------------------------------------------\nClick here to do the survey:\n{SURVEYURL}"));}
$fieldsarray["{ADMINNAME}"]= $thissurvey['adminname'];
$fieldsarray["{ADMINEMAIL}"]=$thissurvey['adminemail'];
$fieldsarray["{SURVEYNAME}"]=$thissurvey['name'];
$fieldsarray["{SURVEYDESCRIPTION}"]=$thissurvey['description'];
$subject=Replacefields($thissurvey['email_invite_subj'], $fieldsarray);
$textarea=Replacefields($thissurvey['email_invite'], $fieldsarray);
$subject=html_escape($subject);
$textarea=html_escape($textarea);
$tokenoutput .= '<div class="tab-page"> <h2 class="tab">'.getLanguageNameFromCode($language,false);
if ($language==$baselang)
{
$tokenoutput .= "(".$clang->gT("Base Language").")";
}
$tokenoutput .= "</h2><table class='table2columns'>\n"
."\n";
$tokenoutput .= "\t<tr>\n"
."\t\t<td align='right'><strong>".$clang->gT("From").":</strong></font></td>\n"
."\t\t<td><input type='text' size='50' name='from_$language' value=\"{$thissurvey['adminname']} <{$thissurvey['adminemail']}>\" /></td>\n"
."\t</tr>\n"
."\t<tr>\n"
."\t\t<td align='right'><strong>".$clang->gT("Subject").":</strong></font></td>\n"
."\t\t<td><input type='text' size='83' name='subject_$language' value=\"$subject\" /></td>\n"
."\t</tr>\n"
."\t<tr>\n"
."\t\t<td align='right' valign='top'><strong>".$clang->gT("Message").":</strong></font></td>\n"
."\t\t<td>\n"
."\t\t\t<textarea name='message_$language' rows='20' cols='80'>\n"
.$textarea
."\t\t\t</textarea>\n"
."\t\t</td>\n"
."\t</tr></table></div>\n";
}
$tokenoutput .= "</div><table class='table2columns'>";
if (isset($_GET['tid']) && $_GET['tid'])
{
$tokenoutput .= "<tr><td colspan='2'>"
.$clang->gT("to TokenID No")." {$_GET['tid']}"
."</td></tr>";
}
$tokenoutput .="\t<tr><td> </td><td align='left'><input type='submit' value='"
.$clang->gT("Send Invitations")."'>\n"
."\t<input type='hidden' name='ok' value='absolutely' />\n"
."\t<input type='hidden' name='sid' value='{$_GET['sid']}' />\n"
."\t<input type='hidden' name='subaction' value='email' /></td></tr>\n";
if (isset($_GET['tid']) && $_GET['tid']) {$tokenoutput .= "\t<input type='hidden' name='tid' value='{$_GET['tid']}' />";}
$tokenoutput .= "\n"
."</table></form>\n";
}
else
{
$tokenoutput .= $clang->gT("Sending Invitations");
if (isset($_POST['tid']) && $_POST['tid']) {$tokenoutput .= " (".$clang->gT("Sending to TID No:")." {$_POST['tid']})";}
$tokenoutput .= "<br />\n";
$ctquery = "SELECT * FROM ".db_table_name("tokens_{$_POST['sid']}")." WHERE ((completed ='N') or (completed='')) AND ((sent ='N') or (sent='')) AND token !='' AND email != ''";
if (isset($_POST['tid']) && $_POST['tid']) {$ctquery .= " and tid='{$_POST['tid']}'";}
$tokenoutput .= "<!-- ctquery: $ctquery -->\n";
$ctresult = $connect->Execute($ctquery) or die("Database error!<br />\n" . htmlspecialchars($connect->ErrorMsg()));
$ctcount = $ctresult->RecordCount();
$ctfieldcount = $ctresult->FieldCount();
$emquery = "SELECT firstname, lastname, email, token, tid, language";
if ($ctfieldcount > 7) {$emquery .= ", attribute_1, attribute_2";}
$emquery .= " FROM ".db_table_name("tokens_{$_POST['sid']}")." WHERE ((completed ='N') or (completed='')) AND ((sent ='N') or (sent='')) AND token !='' AND email != ''";
if (isset($_POST['tid']) && $_POST['tid']) {$emquery .= " and tid='{$_POST['tid']}'";}
$emquery .= " LIMIT $maxemails";
$tokenoutput .= "\n\n<!-- emquery: $emquery -->\n\n";
$emresult = db_execute_assoc($emquery) or die ("Couldn't do query.<br />\n$emquery<br />\n".htmlspecialchars($connect->ErrorMsg()));
$emcount = $emresult->RecordCount();
$tokenoutput .= "<table width='500px' align='center' bgcolor='#EEEEEE'>\n"
."\t<tr>\n"
."\t\t<td><font size='1'>\n";
$surveylangs = GetAdditionalLanguagesFromSurveyID($surveyid);
$baselanguage = GetBaseLanguageFromSurveyID($surveyid);
array_unshift($surveylangs,$baselanguage);
foreach ($surveylangs as $language)
{
$_POST['message_'.$language]=auto_unescape($_POST['message_'.$language]);
$_POST['subject_'.$language]=auto_unescape($_POST['subject_'.$language]);
}
if ($emcount > 0)
{
while ($emrow = $emresult->FetchRow())
{
unset($fieldsarray);
$to = $emrow['email'];
$fieldsarray["{EMAIL}"]=$emrow['email'];
$fieldsarray["{FIRSTNAME}"]=$emrow['firstname'];
$fieldsarray["{LASTNAME}"]=$emrow['lastname'];
$fieldsarray["{TOKEN}"]=$emrow['token'];
$fieldsarray["{LANGUAGE}"]=$emrow['language'];
$fieldsarray["{ATTRIBUTE_1}"]=$emrow['attribute_1'];
$fieldsarray["{ATTRIBUTE_2}"]=$emrow['attribute_2'];
$emrow['language']=trim($emrow['language']);
if ($emrow['language']=='') {$emrow['language']=$baselanguage;} //if language is not give use default
$found = array_search($emrow['language'], $surveylangs);
if ($found==false) {$emrow['language']=$baselanguage;}
$from = $_POST['from_'.$emrow['language']];
$fieldsarray["{SURVEYURL}"]="$publicurl/index.php?sid=$surveyid&token={$emrow['token']}&lang=".trim($emrow['language']);
$modsubject=Replacefields($_POST['subject_'.$emrow['language']], $fieldsarray);
$modmessage=Replacefields($_POST['message_'.$emrow['language']], $fieldsarray);
if (MailTextMessage($modmessage, $modsubject, $to , $from, $sitename))
{
// Put date into sent
$today = date("Y-m-d H:i");
$udequery = "UPDATE ".db_table_name("tokens_{$_POST['sid']}")."\n"
."SET sent='$today' WHERE tid={$emrow['tid']}";
//
$uderesult = $connect->Execute($udequery) or die ("Could not update tokens<br />$udequery<br />".htmlspecialchars($connect->ErrorMsg()));
$tokenoutput .= "[".$clang->gT("Invitation sent to:")."{$emrow['firstname']} {$emrow['lastname']} ($to)]<br />\n";
}
else
{
$tokenoutput .= ReplaceFields($clang->gT("Mail to {FIRSTNAME} {LASTNAME} ({EMAIL}) Failed"), $fieldsarray);
$tokenoutput .= "<br /><pre>$modsubject<br />$modmessage</pre>";
}
}
if ($ctcount > $emcount)
{
$lefttosend = $ctcount-$maxemails;
$tokenoutput .= "\t\t</td>\n"
."\t</tr>\n"
."\t<tr>\n"
."\t\t<td align='center'><strong>".$clang->gT("Warning")."</strong><br />\n"
."\t\t\t<form method='post'>\n"
.$clang->gT("There are more emails pending than can be sent in one batch. Continue sending emails by clicking below.")."<br /><br />\n";
$tokenoutput .= str_replace("{EMAILCOUNT}", "$lefttosend", $clang->gT("There are {EMAILCOUNT} emails still to be sent."));
$tokenoutput .= "<br /><br />\n";
$tokenoutput .= "\t\t\t<input type='submit' value='".$clang->gT("Continue")."' />\n"
."\t\t\t<input type='hidden' name='ok' value=\"absolutely\" />\n"
."\t\t\t<input type='hidden' name='subaction' value=\"email\" />\n"
."\t\t\t<input type='hidden' name='action' value=\"tokens\" />\n"
."\t\t\t<input type='hidden' name='sid' value=\"{$_POST['sid']}\" />\n";
foreach ($surveylangs as $language)
{
$message = html_escape($_POST['message_'.$language]);
$subject = html_escape($_POST['subject_'.$language]);
$tokenoutput .="\t\t\t<input type='hidden' name='from_$language' value=\"".$_POST['from_'.$language]."\" />\n"
."\t\t\t<input type='hidden' name='subject_$language' value=\"".$_POST['subject_'.$language]."\" />\n"
."\t\t\t<input type='hidden' name='message_$language' value=\"$message\" />\n";
}
$tokenoutput .="\t\t\t</form>\n";
}
}
else
{
$tokenoutput .= "<center><strong>".$clang->gT("Warning")."</strong><br />\n".$clang->gT("There were no eligible emails to send. This will be because none satisfied the criteria of - having an email address, not having been sent an invitation already, having already completed the survey and having a token.")."</center>\n";
}
$tokenoutput .= "\t\t</td>\n";
}
$tokenoutput .= "</td></tr></table>\n";
}
if ($subaction == "remind" && ($sumrows5['edit_survey_property'] || $sumrows5['activate_survey']))
{
$tokenoutput .= "\t<tr><td colspan='2' height='4'><strong>"
.$clang->gT("Email Reminder").":</strong></td></tr>\n"
."\t<tr><td colspan='2' align='center'>\n";
if (!isset($_POST['ok']) || !$_POST['ok'])
{
//GET SURVEY DETAILS
$tokenoutput .= "<form method='post' action='$scriptname?action=tokens'>";
$surveylangs = GetAdditionalLanguagesFromSurveyID($surveyid);
$baselang = GetBaseLanguageFromSurveyID($surveyid);
array_unshift($surveylangs,$baselang);
$tokenoutput .= "<div class='tab-pane' id='tab-pane-1'>";
foreach ($surveylangs as $language)
{
//GET SURVEY DETAILS
$thissurvey=getSurveyInfo($surveyid,$language);
if (!$thissurvey['email_remind']) {$thissurvey['email_remind']=str_replace("\n", "\r\n", $clang->gT("Dear {FIRSTNAME},\n\nRecently we invited you to participate in a survey.\n\nWe note that you have not yet completed the survey, and wish to remind you that the survey is still available should you wish to take part.\n\nThe survey is titled:\n\"{SURVEYNAME}\"\n\n\"{SURVEYDESCRIPTION}\"\n\nTo participate, please click on the link below.\n\nSincerely,\n\n{ADMINNAME} ({ADMINEMAIL})\n\n----------------------------------------------\nClick here to do the survey:\n{SURVEYURL}"));}
$tokenoutput .= '<div class="tab-page"> <h2 class="tab">'.getLanguageNameFromCode($language,false);
if ($language==$baselang)
{
$tokenoutput .= "(".$clang->gT("Base Language").")";
}
$tokenoutput .= "</h2><table class='table2columns' >\n"
."\n"
."\t<tr>\n"
."\t\t<td align='right' width='150'><strong>".$clang->gT("From").":</strong></td>\n"
."\t\t<td><input type='text' size='50' name='from_$language' value=\"{$thissurvey['adminname']} <{$thissurvey['adminemail']}>\" /></td>\n"
."\t</tr>\n"
."\t<tr>\n"
."\t\t<td align='right' width='150'><strong>".$clang->gT("Subject").":</strong></td>\n";
$subject=str_replace("{SURVEYNAME}", $thissurvey['name'], $thissurvey['email_remind_subj']);
$tokenoutput .= "\t\t<td><input type='text' size='83' name='subject_$language' value='".html_escape($subject)."' /></td>\n"
."\t</tr>\n";
$tokenoutput .= "\t<tr>\n"
."\t\t<td align='right' width='150' valign='top'><strong>"
.$clang->gT("Message").":</strong></td>\n"
."\t\t<td>\n"
."\t\t\t<textarea name='message_$language' rows='20' cols='80' >\n";
$textarea = $thissurvey['email_remind'];
$textarea = str_replace("{ADMINNAME}", $thissurvey['adminname'], $textarea);
$textarea = str_replace("{ADMINEMAIL}", $thissurvey['adminemail'], $textarea);
$textarea = str_replace("{SURVEYNAME}", $thissurvey['name'], $textarea);
$textarea = str_replace("{SURVEYDESCRIPTION}", $thissurvey['description'], $textarea);
$tokenoutput .= $textarea;
$tokenoutput .= "\t\t\t</textarea>\n"
."\t\t</td>\n"
."\t</tr>\n"
."</table></div>";
}
$tokenoutput .= "</div><table class='table2columns'>\n";
if (!isset($_GET['tid']) || !$_GET['tid'])
{
$tokenoutput .= "\t<tr>\n"
."\t\t<td align='right' width='150' valign='top'><strong>"
.$clang->gT("Start at Token ID No:")."</strong></td>\n"
."\t\t<td><input type='text' size='5' name='last_tid' /></td>\n"
."\t</tr>\n";
}
else
{
$tokenoutput .= "\t<tr>\n"
."\t\t<td align='right' width='150' valign='top'><strong>"
.$clang->gT("Sending to TID No:")."</strong></font></td>\n"
."\t\t<td>{$_GET['tid']}</font></td>\n"