/
tokens.php
671 lines (627 loc) · 29.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
<?php
/*
#############################################################
# >>> PHP Surveyor #
#############################################################
# > 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 as published by the Free Software #
# Foundation; either version 2 of the License, or (at your #
# option) any later version. #
# #
# 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
include("config.php");
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
// always modified
header("Cache-Control: no-store, no-cache, must-revalidate"); // HTTP/1.1
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache"); // HTTP/1.0
echo $htmlheader;
echo "<table width='100%'>\n";
echo "\t<tr><td bgcolor='#BBBBBB' colspan='2' align='center'>$setfont<b>Token Control</b></td></tr>\n";
// MAKE SURE THAT THERE IS A SID
if (!$_GET['sid'] && !$_POST['sid'])
{
echo "\t<tr><td colspan='2' align='center'>$setfont<br /><br />Sorry, you have not chosen a survey_id!</td></tr>\n";
echo "</table>\n";
exit;
}
else
{
$sid=$_GET['sid'];
if (!$sid) {$sid=$_POST['sid'];}
}
// MAKE SURE THAT THE SURVEY EXISTS
$chquery = "SELECT * FROM surveys WHERE sid=$sid";
if (!$chresult=mysql_query($chquery))
{
echo "\t<tr><td colspan='2' align='center'>$setfont<br /><br />Sorry, this survey does not exist</td></tR>\n";
echo "</table>\n";
exit;
}
while ($chrow=mysql_fetch_row($chresult))
{
echo "\t<tr><td colspan='2' align='center'>$setfont<b>Survey $sid - $chrow[1]</td></tr>\n";
}
// CHECK TO SEE IF A TOKEN TABLE EXISTS FOR THIS SURVEY
$tkquery="SELECT * FROM tokens_$sid";
if (!$tkresult=mysql_query($tkquery))
{
if (!$createtable)
{
echo "\t<tr>\n";
echo "\t\t<td colspan='2' align='center'>\n";
echo "\t\t\t$setfont<br /><br />\n";
echo "\t\t\tNo token system has been created for this survey. Do you want to create one now?<br /><br />\n";
echo "\t\t\t<input type='submit' $btstyle value='Create Token Table' onClick=\"window.open('tokens.php?sid=$sid&createtable=Y', '_top')\"><br />\n";
echo "\t\t\t<input type='submit' $btstyle value='Return to Admin' onClick=\"window.open('admin.php?sid=$sid', '_top')\">\n";
echo "\t\t</td>\n";
echo "\t</tr>\n";
echo "</table>\n";
exit;
}
else
{
$createtokentable="CREATE TABLE tokens_$sid (\n tid int NOT NULL auto_increment,\n firstname varchar(40) NULL, lastname varchar(40) NULL,\n email varchar(100) NULL, token varchar(10) NULL,\n sent varchar(1) NULL DEFAULT 'N', completed varchar(1) NULL DEFAULT 'N', PRIMARY KEY (tid)\n) TYPE=MyISAM;";
$ctresult=mysql_query($createtokentable) or die ("Completely mucked up<br />$createtokentable<br /><br />".mysql_error());
echo "\t<tr>\n";
echo "\t\t<td colspan='2' align='center'>\n";
echo "\t\t\t$setfont<br /><br />\n";
echo "\t\t\tA token table has been created for this survey, called \"tokens_$sid\"<br /><br />\n";
echo "\t\t\t<input type='submit' $btstyle value='Continue' onClick=\"window.open('tokens.php?sid=$sid', '_top')\">\n";
echo "\t\t</td>\n";
echo "\t</tr>\n";
echo "</table>\n";
exit;
}
}
// IF WE MADE IT THIS FAR, THEN THERE IS A TOKENS TABLE, SO LETS DEVELOP THE MENU ITEMS
$tokenmenu = "\t<tr>\n";
$tokenmenu .= "\t\t<td bgcolor='#EEEEEE' colspan='2' align='center' ";
$tokenmenu .= "style='border-top-style: solid; border-top-width: 1; border-top-color:#BBBBBB; border-left-color:#BBBBBB; border-left-width:1; border-left-style:solid; border-right-style: solid; border-right-width:1; border-right-color:#BBBBBB'>\n";
$tokenmenu .= "\t\t\t<font size='2'>[<a href='admin.php?sid=$sid'>admin</a>] \n";
$tokenmenu .= "\t\t\t[<a href='tokens.php?sid=$sid'>summary</a>] \n";
$tokenmenu .= "\t\t\t[<a href='tokens.php?sid=$sid&action=browse'>browse</a>] \n";
$tokenmenu .= "\t\t\t[<a href='tokens.php?sid=$sid&action=add'>add</a>] \n";
$tokenmenu .= "\t\t\t[<a href='tokens.php?sid=$sid&action=import'>import</a>] \n";
$tokenmenu .= "\t\t\t[<a href='tokens.php?sid=$sid&action=email'>invite</a>] \n";
$tokenmenu .= "\t\t\t[<a href='tokens.php?sid=$sid&action=remind'>remind</a>] \n";
$tokenmenu .= "\t\t\t[<a href='tokens.php?sid=$sid&action=tokenify'>tokenify</a>] \n";
$tokenmenu .= "\t\t\t[<a href='tokens.php?sid=$sid&action=kill'>drop tokens</a>] \n";
$tokenmenu .= "\t\t</td>\n";
$tokenmenu .= "\t</tr>\n";
// SEE HOW MANY RECORDS ARE IN THE TOKEN TABLE
$tkcount=mysql_num_rows($tkresult);
echo "$tokenmenu";
echo "\t<tr><td colspan='2' align='center'>There are $tkcount records in your token table for this survey.</td></tr>\n";
// GIVE SOME INFORMATION ABOUT THE TOKENS
echo "\t<tr>\n";
echo "\t\t<td colspan='2' align='center'>\n";
echo "\t\t\t<table width='400' align='center' bgcoloR='#DDDDDD'>\n";
echo "\t\t\t\t<tr>\n";
echo "\t\t\t\t\t<td align='center'>\n";
$tksq="SELECT count(*) FROM tokens_$sid WHERE sent='Y'";
$tksr=mysql_query($tksq);
while ($tkr=mysql_fetch_row($tksr))
{echo "\t\t\t\t\t\t$setfont$tkr[0] of $tkcount have been sent an invitation to participate<br />\n";}
$tksq="SELECT count(*) FROM tokens_$sid WHERE completed='Y'";
$tksr=mysql_query($tksq);
while ($tkr=mysql_fetch_row($tksr))
{echo "\t\t\t\t\t\t$setfont$tkr[0] of $tkcount entries have completed the survey<br />\n";}
$tksq="SELECT count(*) FROM tokens_$sid WHERE token IS NULL OR token=''";
$tksr=mysql_query($tksq);
while ($tkr=mysql_fetch_row($tksr))
{echo "\t\t\t\t\t\t$setfont$tkr[0] of $tkcount have not had a token generated\n";}
echo "\t\t\t\t\t</td>\n";
echo "\t\t\t\t</tr>\n";
echo "\t\t\t</table>\n";
if ($action == "browse")
{
echo "<br>\n<table width='600' cellpadding='1' cellspacing='1' align='center' bgcolor='#CCCCCC'>\n";
//COLUMN HEADINGS
echo "\t<tr>\n";
echo "\t\t<td><a href='tokens.php?sid=$sid&action=browse&order=tid'><img src='DownArrow.gif' border='0' align='left'></a>$setfont<b>ID</b></td>\n";
echo "\t\t<td><a href='tokens.php?sid=$sid&action=browse&order=firstname'><img src='DownArrow.gif' border='0' align='left'></a>$setfont<b>First</b></td>\n";
echo "\t\t<td><a href='tokens.php?sid=$sid&action=browse&order=lastname'><img src='DownArrow.gif' border='0' align='left'></a>$setfont<b>Last</b></td>\n";
echo "\t\t<td><a href='tokens.php?sid=$sid&action=browse&order=email'><img src='DownArrow.gif' border='0' align='left'></a>$setfont<b>Email</b></td>\n";
echo "\t\t<td><a href='tokens.php?sid=$sid&action=browse&order=token'><img src='DownArrow.gif' border='0' align='left'></a>$setfont<b>Token</b></td>\n";
echo "\t\t<td><a href='tokens.php?sid=$sid&action=browse&order=sent%20desc'><img src='DownArrow.gif' border='0' align='left'></a>$setfont<b>Invite?</b></td>\n";
echo "\t\t<td><a href='tokens.php?sid=$sid&action=browse&order=completed%20desc'><img src='DownArrow.gif' border='0' align='left'></a>$setfont<b>Complete?</b></td>\n";
echo "\t\t<td>$setfont<b>Action</b></td>\n";
echo "\t</tr>\n";
$bquery="SELECT * FROM tokens_$sid";
if (!$order) {$bquery .= " ORDER BY tid";}
else {$bquery .= " ORDER BY $order";}
$bresult=mysql_query($bquery);
while ($brow=mysql_fetch_row($bresult))
{
if ($bgc=="#EEEEEE") {$bgc="#DDDDDD";} else {$bgc="#EEEEEE";}
echo "\t<tr bgcolor='$bgc'>\n";
for ($i=0; $i<=6; $i++)
{
echo "\t\t<td>$setfont$brow[$i]</td>\n";
}
echo "\t\t<td align='center'>\n";
echo "\t\t\t<input style='height: 16; width: 16px; font-size: 8; font-face: verdana' type='submit' value='E' title='Edit' onClick=\"window.open('$PHP_SELF?sid=$sid&action=edit&tid=$brow[0]', '_top')\">\n";
echo "\t\t\t<input style='height: 16; width: 16px; font-size: 8; font-face: verdana' type='submit' value='D' title='Delete' onClick=\"window.open('$PHP_SELF?sid=$sid&action=delete&tid=$brow[0]', '_top')\">\n";
echo "\t\t</td>\n";
echo "\t</tr>\n";
}
echo "</table>\n";
}
if ($action == "kill")
{
$date = date(Ymd);
echo "<CENTER>$setfont<B>Drop/Delete Tokens</B><BR>\n";
if (!$ok)
{
echo "<TABLE WIDTH='80%' ALIGN='CENTER' BGCOLOR='#DDDDDD'>\n";
echo " <TR><TD ALIGN='CENTER'>";
echo "Deleting this tokens table will mean that tokens are no longer<BR>";
echo "required for public access to this survey. It will also delete<BR>";
echo "all the existing tokens in this survey. A backup of this table<BR>";
echo "will be made, and called \"old_tokens_$sid\". This can be<BR>";
echo "recovered by a systems administrator.<BR><BR>";
echo "<INPUT TYPE='SUBMIT' $btstyle VALUE='Delete Tokens' onClick=\"window.open('tokens.php?sid=$sid&action=kill&ok=surething', '_top')\"><BR>\n";
echo "<INPUT TYPE='SUBMIT' $btstyle VALUE='Cancel' onClick=\"window.open('tokens.php?sid=$sid', '_top')\">";
echo " </TD></TR></TABLE>\n";
}
elseif ($ok == "surething")
{
$oldtable="tokens_{$sid}";
$newtable="old_tokens_{$sid}_{$date}";
$deactivatequery = "RENAME TABLE $oldtable TO $newtable";
$deactivateresult = mysql_query($deactivatequery) or die ("Couldn't deactivate because:<BR>".mysql_error()."<BR><BR><a href='$scriptname?sid=$sid'>Admin</a>");
echo "<TABLE WIDTH='80%' ALIGN='CENTER' BGCOLOR='#DDDDDD'>\n";
echo " <TR><TD ALIGN='CENTER'>";
echo "The tokens table has now been removed and tokens are no longer<BR>";
echo "required for public access to this survey. A backup of this table<BR>";
echo "has been made, and is called \"old_tokens_$sid_$date\". This can be<BR>";
echo "recovered by a systems administrator.<BR><BR>";
echo "<INPUT TYPE='SUBMIT' $btstyle VALUE='Finished' onClick=\"window.open('tokens.php?sid=$sid', '_top')\">";
echo " </TD></TR></TABLE>\n";
}
}
if ($_GET['action'] == "email" || $_POST['action'] == "email")
{
echo "<CENTER>$setfont<B>Email Invitation</B><BR>\n";
if (!$_POST['ok'])
{
//GET SURVEY DETAILS
$esquery="SELECT * FROM surveys WHERE sid=$sid";
$esresult=mysql_query($esquery);
while ($esrow=mysql_fetch_row($esresult))
{
$surveyname=$esrow[1];
$surveydescription=$esrow[2];
$surveyadmin=$esrow[3];
$surveyadminemail=$esrow[7];
}
echo "<TABLE WIDTH='80%' ALIGN='CENTER' BGCOLOR='#DDDDDD'>\n";
echo "<FORM METHOD='POST'>\n";
//echo "<FORM>\n";
echo " <TR><TD COLSPAN='2' BGCOLOR='BLACK' ALIGN='CENTER'>$setfont<FONT COLOR='WHITE'><B>Send Invitation</TD></TR>\n";
echo " <TR>\n";
echo " <TD ALIGN='RIGHT'>$setfont<B>From:</TD>\n";
echo " <TD><INPUT TYPE='TEXT' $slstyle SIZE='50' NAME='from' VALUE='$surveyadminemail'></TD></TR>\n";
echo " <TR>\n <TD ALIGN='RIGHT'>$setfont<B>Subject:</TD>\n";
echo " <TD><INPUT TYPE='TEXT' $slstyle SIZE='50' NAME='subject' VALUE='Invitation to participate in $surveyname survey'></TD></TR>\n";
echo " <TR>\n <TD ALIGN='RIGHT' VALIGN='TOP'>$setfont<B>Message:</TD>\n";
echo " <TD>$setfont<B>The following will be added to the top of your message:</B>";
echo "<TABLE WIDTH='500' BGCOLOR='#EEEEEE' BORDER='1' CELLPADDING='0' CELLSPACING='0'><TR><TD>";
echo "$setfont Dear [FIRSTNAME],";
echo "</TD></TR></TABLE>\n";
echo "<B>You can make changes to this part of the message:</B><BR>";
echo "<TEXTAREA NAME='message' ROWS='6' COLS='60'>";
echo "You have been invited to participate in the following survey.\n\n";
echo "** Survey Name **\n$surveyname\n\n";
echo "** Survey Description **\n$surveydescription\n\n";
echo "To participate, please click on the link below.";
echo "\n\nSincerely,\n\n$surveyadmin ($surveyadminemail)";
echo "</TEXTAREA></TD></TR>\n";
echo " <TR>\n <TD></TD>";
echo " <TD>$setfont<B>The following will be added to the end of your email message:</B><BR>";
echo "<TABLE WIDTH='500' BGCOLOR='#EEEEEE' BORDER='1' CELLPADDING='0' CELLSPACING='0'><TR><TD>";
echo "$setfont---------------------------------<BR> Click Here to do Survey:<BR>$publicurl/index.php?sid=$sid&token=[TOKENVALUE]<BR>";
echo "</TD></TR></TABLE>\n</TD></TR>\n";
echo " <TR>";
echo " <TD COLSPAN='2' ALIGN='CENTER'><INPUT TYPE='SUBMIT' $btstyle VALUE='Send Invitations'></TD></TR>\n";
echo "<INPUT TYPE='HIDDEN' NAME='ok' VALUE='absolutely'>\n";
echo "<INPUT TYPE='HIDDEN' NAME='sid' VALUE='{$_GET['sid']}'>\n";
echo "<INPUT TYPE='HIDDEN' NAME='action' VALUE='email'\n";
echo "</FORM></TABLE>\n";
}
else
{
echo "Sending email!";
$ctquery="SELECT firstname FROM tokens_{$_POST['sid']} WHERE completed !='Y' AND sent !='Y' AND token !=''";
$ctresult=mysql_query($ctquery);
$ctcount=mysql_num_rows($ctresult);
$emquery="SELECT firstname, lastname, email, token, tid FROM tokens_{$_POST['sid']} WHERE completed != 'Y' AND sent != 'Y' AND token !='' LIMIT $maxemails";
$emresult=mysql_query($emquery) or die ("Couldn't do query.<BR>$emquery<BR>".mysql_error());
$emcount=mysql_num_rows($emresult);
$headers = "From: {$_POST['from']}\r\n";
$headers .= "X-Mailer: $sitename Email Inviter";
$message = strip_tags($_POST['message']);
$message = str_replace(""", '"', $message);
if (get_magic_quotes_gpc() != "0")
{$message = stripcslashes($message);}
echo "<TABLE WIDTH='500' ALIGN='CENTER' BGCOLOR='#EEEEEE'><TR><TD><FONT SIZE='1'>\n";
if ($emcount > 0)
{
while ($emrow=mysql_fetch_array($emresult))
{
$to=$emrow['email'];
//echo "To: $to ($emrow[0] $emrow[1])<BR>";
//$from=$surveyadminemail;
//echo "From: $from<BR>";
//echo "Subject: $subject<BR>";
$sendmessage = "Dear {$emrow['firstname']},\n\n".$message;
$sendmessage .= "\n\n-------------------------------------------\n\n";
$sendmessage .= "Click here to do this survey:\n\n";
$sendmessage .= "$publicurl/index.php?sid=$sid&token={$emrow['token']}\n\n";
//echo "Message:". str_replace("\n", "<BR>", $sendmessage) . "<P>";
mail($to, $_POST['subject'], $sendmessage, $headers);
$udequery = "UPDATE tokens_{$_POST['sid']} SET sent='Y' WHERE tid={$emrow['tid']}";
$uderesult=mysql_query($udequery) or die ("Couldn't update tokens<BR>$udequery<BR>".mysql_error());
echo "[Invite Sent to {$emrow['firstname']} {$emrow['lastname']}] ";
}
if ($ctcount > $emcount)
{
$lefttosend=$ctcount-$maxemails;
echo "</TD></TR><TR><FORM METHOD='POST'><TD ALIGN='CENTER'>$setfont<B>Warning:</B><BR>";
echo "The number of emails to send ($ctcount) is greater than the maximum number";
echo " of emails that can be sent in one lot ($maxemails). There are still $lefttosend";
echo " emails to go. You can continue sending the next $maxemails by clicking on the";
echo " button below.<BR>";
$message = str_replace('"', """, $message);
echo "<INPUT TYPE='SUBMIT' VALUE=\"Send More\"></TD>\n";
echo "<INPUT TYPE='HIDDEN' NAME='ok' VALUE=\"absolutely\">\n";
echo "<INPUT TYPE='HIDDEN' NAME='action' VALUE=\"email\">\n";
echo "<INPUT TYPE='HIDDEN' NAME='sid' VALUE=\"{$_POST['sid']}\">\n";
echo "<INPUT TYPE='HIDDEN' NAME='from' VALUE=\"{$_POST['from']}\">\n";
echo "<INPUT TYPE='HIDDEN' NAME='subject' VALUE=\"{$_POST['subject']}\">\n";
echo "<INPUT TYPE='HIDDEN' NAME='message' VALUE=\"$message\">\n";
echo "</FORM>\n";
}
}
else
{
echo "<CENTER><B>WARNING:</B><BR>There were no token recipients who have not already had";
echo " an invitation sent out, or who have not responded!<BR><BR>";
echo "No invitations have been sent out!";
}
echo "</TD></TR></TABLE>\n";
}
}
if ($_GET['action'] == "remind" || $_POST['action'] == "remind")
{
echo "<center>$setfont<b>Email Reminder</b><br />\n";
if (!$_POST['ok'])
{
//GET SURVEY DETAILS
$esquery="SELECT * FROM surveys WHERE sid=$sid";
$esresult=mysql_query($esquery);
while ($esrow=mysql_fetch_row($esresult))
{
$surveyname=$esrow[1];
$surveydescription=$esrow[2];
$surveyadmin=$esrow[3];
$surveyadminemail=$esrow[7];
}
echo "<table width='80%' align='center' bgcolor='#DDDDDD'>\n";
echo "\t<form method='post' action='tokens.php'>\n";
echo "\t<tr><td colspan='2' bgcolor='black' align='center'>\n";
echo "\t\t$setfont<font color='white'><b>Send Reminder\n";
echo "\t</td></tr>\n";
echo "\t<tr><td align='right'>\n";
echo "\t\t$setfont<b>From:</td>\n";
echo "\t\t<td><input type='text' $slstyle size='50' name='from' value='$surveyadminemail'>\n";
echo "\t</td></tr>\n";
echo "\t<tr><td align='right'>\n\t\t$setfont<b>Subject:\n\t</td>\n\t<td>\n";
echo "\t\t<input type='text' $slstyle size='50' name='subject' value='Reminder to participate in $surveyname'>\n";
echo "\t</td></tr>\n";
echo "\t<tr><td align='right' valign='top'>\n\t\t$setfont<b>Start at ID:\n\t</td>\n";
echo "\t\t<td><input type='text' $slstyle size='5' name='last_tid'>\n";
echo "\t</td></tr>\n";
echo "\t<tr><td align='right' valign='top'>\n\t\t$setfont<b>Message:\n\t</td>\n";
echo "\t<td>\n\t\t$setfont<b>The following will be added to the top of your message:</b>\n";
echo "\t\t\t<table width='500' bgcolor='#EEEEEE' border='1' cellpadding='0' cellspacing='0'>\n\t\t\t\t<tr><td>\n";
echo "\t\t\t\t\t$setfont Dear [FIRSTNAME],\n";
echo "\t\t\t\t</td></tr>\n\t\t\t</table>\n";
echo "\t\t\t<b>You can make changes to this part of the message:</b><br />\n";
echo "\t\t\t<textarea name='message' rows='6' cols='60'>";
echo "Recently we invited you to participate in a survey.\n\n";
echo "We note that you have not yet completed the survey, and wish to remind you ";
echo "that the survey is still available should you wish to take part.\n\n";
echo "** Survey Name **\n$surveyname\n\n";
echo "** Survey Description **\n";
echo strip_tags($surveydescription)."\n\n";
echo "To participate, please click on the link below.";
echo "\n\nSincerely,\n\n$surveyadmin ($surveyadminemail)";
echo "</textarea>\n\t\t</td></tr>\n";
echo "\t\t<tr>\n\t\t<td></td>";
echo "\t\t<td>$setfont<b>The following will be added to the end of your email message:</b><br />\n";
echo "\t\t\t<table width='500' bgcolor='#EEEEEE' border='1' cellpadding='0' cellspacing='0'>\n";
echo "\t\t\t\t<tr><td>";
echo "$setfont---------------------------------<br /> Click Here to do Survey:<br />$publicurl/index.php?sid=$sid&token=[TOKENVALUE]<br />\n";
echo "\t\t\t\t</td></tr>\n\t\t\t</table>\n\t\t</td></tr>\n";
echo "\t\t<tr><td colspan='2' align='center'>\n";
echo "\t\t\t<input type='submit' $btstyle value='Send Reminder'>\n\t\t</td></tr>\n";
echo "\t\t<input type='hidden' name='ok' value='absolutely'>\n";
echo "\t\t<input type='hidden' name='sid' value='{$_GET['sid']}'>\n";
echo "\t\t<input type='hidden' name='action' value='remind'>\n";
echo "\t</form>\n</table>\n";
}
else
{
echo "Sending reminder email! (Starting after {$_POST['last_tid']})";
$ctquery="SELECT firstname FROM tokens_{$_POST['sid']} WHERE completed !='Y' AND sent='Y' AND token !=''";
if ($_POST['last_tid']) {$ctquery .= " AND tid > '{$_POST['last_tid']}'";}
$ctresult=mysql_query($ctquery);
$ctcount=mysql_num_rows($ctresult);
$emquery="SELECT firstname, lastname, email, token, tid FROM tokens_{$_POST['sid']} WHERE completed != 'Y' AND sent = 'Y' AND token !=''";
if ($_POST['last_tid']) {$emquery .= " AND tid > '{$_POST['last_tid']}'";}
$emquery .= " ORDER BY tid LIMIT $maxemails";
$emresult=mysql_query($emquery) or die ("Couldn't do query.<BR>$emquery<BR>".mysql_error());
$emcount=mysql_num_rows($emresult);
$headers = "From: {$_POST['from']}\r\n";
$headers .= "X-Mailer: $sitename Email Reminder";
echo "<table width='500' align='CENTER' bgcolor='#EEEEEE'><tr><td><font size='1'>\n";
$message = strip_tags($_POST['message']);
$message = str_replace(""", '"', $message);
if (get_magic_quotes_gpc() != "0")
{$message = stripcslashes($message);}
if ($emcount > 0)
{
while ($emrow=mysql_fetch_array($emresult))
{
$to=$emrow['email'];
$sendmessage = "Dear {$emrow['firstname']},\n\n";
$sendmessage .= $message;
$sendmessage .= "\n\n-------------------------------------------\n\n";
$sendmessage .= "Click here to do this survey:\n\n";
$sendmessage .= "$publicurl/index.php?sid={$_POST['sid']}&token={$emrow['token']}\n\n";
mail($to, $_POST['subject'], $sendmessage, $headers);
echo "[Reminder Sent to {$emrow['firstname']} {$emrow['lastname']}]({$emrow['tid']}) ";
$lasttid=$emrow['tid'];
}
if ($ctcount > $emcount)
{
$lefttosend=$ctcount-$maxemails;
echo "</td></tr><tr><form method='post' action='tokens.php'><td align='center'>$setfont<b>Warning:</b><br>";
echo "The number of emails to send ($ctcount) is greater than the maximum number";
echo " of emails that can be sent in one lot ($maxemails). There are still $lefttosend";
echo " emails to go. You can continue sending the next $maxemails by clicking on the";
echo " button below.<br />";
echo "<input type='submit' value='Send More'></TD>\n";
echo "<input type='hidden' name='ok' value=\"absolutely\">\n";
echo "<input type='hidden' name='action' value=\"remind\">\n";
echo "<input type='hidden' name='sid' value=\"{$_POST['sid']}\">\n";
echo "<input type='hidden' name='from' value=\"{$_POST['from']}\">\n";
echo "<input type='hidden' name='subject' value=\"{$_POST['subject']}\">\n";
$message = str_replace('"', """, $message);
echo "<input type='hidden' name='message' value=\"$message}\">\n";
echo "<input type='hidden' name='last_tid' value=\"$lasttid\">\n";
echo "</form>\n";
}
}
else
{
echo "<center><b>WARNING:</b><br />There were no token recipients who have not yet responded.";
echo "<br><br>";
echo "No invitations have been sent out!";
}
echo "</td></tr></table>\n";
}
}
if ($action == "tokenify")
{
echo "<CENTER>$setfont<B>Tokens</B><BR>\n";
if (!$ok)
{
echo "<CENTER><BR>$setfont Clicking OK will generate tokens for all<BR>those in this token list that have not<BR>been issued one. Is this OK?";
echo "<BR><INPUT TYPE='SUBMIT' $btstyle VALUE='Yes' onClick=\"window.open('tokens.php?sid=$sid&action=tokenify&ok=Y', '_top')\">";
echo "<BR><INPUT TYPE='SUBMIT' $btstyle VALUE='No' onClick=\"window.open('tokens.php?sid=$sid', '_top')\">";
}
else
{
$tkquery="SELECT * FROM tokens_$sid WHERE token IS NULL OR token=''";
$tkresult=mysql_query($tkquery) or die ("Mucked up!<BR>$tkquery<BR>".mysql_error());
while ($tkrow=mysql_fetch_row($tkresult))
{
$insert="NO";
while ($insert!="OK")
{
$newtoken=sprintf("%010s", rand(1,10000000000));
$ntquery="SELECT * FROM tokens_$sid WHERE token='$newtoken'";
$ntresult=mysql_query($ntquery);
if (!mysql_num_rows($ntresult)) {$insert="OK";}
}
$itquery="UPDATE tokens_$sid SET token='$newtoken' WHERE tid=$tkrow[0]";
$itresult=mysql_query($itquery);
$newtokencount++;
}
echo "<BR><BR><B>$newtokencount tokens have been generated";
}
}
if ($action == "delete")
{
$dlquery="DELETE FROM tokens_$sid WHERE tid=$tid";
$dlresult=mysql_query($dlquery) or die ("Couldn't delete record $tid<BR>".mysql_error());
echo "<BR><B>Record has been deleted.";
}
if ($action == "edit" || $action == "add")
{
if ($action == "edit")
{
$edquery="SELECT * FROM tokens_$sid WHERE tid=$tid";
$edresult=mysql_query($edquery);
while($edrow=mysql_fetch_row($edresult))
{
$id=$edrow[0]; $firstname=$edrow[1]; $lastname=$edrow[2]; $email=$edrow[3]; $token=$edrow[4]; $sent=$edrow[5]; $completed=$edrow[6];
}
}
echo "<br>\n";
echo "<table width='550' bgcolor='#CCCCCC'>\n";
echo "<form method='post'>\n";
echo "<tr>\n";
echo "\t<td colspan='2' align='center'>$setfont<b>Edit/Add Token Entry</b></td>\n";
echo "</tr>\n";
echo "<tr>\n";
echo "\t<td align='right' width='10%'>$setfont<b>ID:</b></td><td bgcolor='#EEEEEE'>$setfont Auto</td>\n";
echo "</tr>\n";
echo "<tr>\n";
echo "\t<td align='right' width='10%'>$setfont<b>Firstname:</b></td>\n";
echo "\t<td bgcolor='#EEEEEE'>$setfont<input type='text' $slstyle size='30' name='firstname' value='$firstname'></td>\n";
echo "</tr>\n";
echo "<tr>\n";
echo "\t<td align='right' width='10%'>$setfont<b>Lastname:</b></td>\n";
echo "\t<td bgcolor='#EEEEEE'>$setfont<input type='text' $slstyle size='30' name='lastname' value='$lastname'></td>\n";
echo "</tr>\n";
echo "<tr>\n";
echo "\t<td align='right' width='10%'>$setfont<b>Email:</b></td>\n";
echo "\t<td bgcolor='#EEEEEE'>$setfont<input type='text' $slstyle size='40' name='email' value='$email'></td>\n";
echo "</tr>\n";
echo "<tr>\n";
echo "\t<td align='right' width='10%'>$setfont<b>Token:</b></td>\n";
echo "\t<td bgcolor='#EEEEEE'>$setfont<input type='text' size='10' $slstyle name='token' value='$token'></td>\n";
echo "</tr>\n";
echo "<tr>\n";
echo "\t<td align='right' width='10%'>$setfont<b>Sent?:</b></td>\n";
echo "\t<td bgcolor='#EEEEEE'>$setfont<input type='text' size='1' $slstyle name='sent' value='$sent'></td>\n";
echo "</tr>\n";
echo "<tr>\n";
echo "\t<td align='right' width='10%'>$setfont<b>Complete?:</b></td>\n";
echo "\t<td bgcolor='#EEEEEE'>$setfont<input type='text' size='1' $slstyle name='completed' value='$completed'></td>\n";
echo "</tr>\n";
echo "<tr>\n";
echo "\t<td colspan='2' align='center'>";
switch($action)
{
case "edit":
echo "\t\t<input type='submit' $btstyle name='action' value='update'>\n";
echo "\t\t<input type='hidden' name='tid' value='$tid'>\n";
break;
case "add":
echo "\t\t<input type='submit' $btstyle name='action' value='insert'>\n";
break;
}
echo "\t\t<input type='hidden' name='sid' value='$sid'>\n";
echo "\t</td>\n";
echo "</tr>\n</form>\n</table>\n";
echo "</body>\n</html>";
}
if ($action == "update")
{
echo "<BR>$setfont<B>UPDATING TOKEN ENTRY</B><BR>\n";
$udquery="UPDATE tokens_$sid SET firstname='$firstname', lastname='$lastname', email='$email', token='$token', sent='$sent', completed='$completed' WHERE tid=$tid";
$udresult=mysql_query($udquery) or die ("Update record $tid failed:<BR>$udquery<BR>".mysql_error());
echo "<BR>Entry succesfully updated!";
}
if ($action == "insert")
{
echo "<BR>$setfont<B>INSERTING TOKEN ENTRY</B><BR>\n";
$inquery = "INSERT into tokens_$sid VALUES ('', '$firstname', '$lastname', '$email', '$token', '$sent', '$completed')";
$inresult=mysql_query($inquery) or die ("Add new record failed:<BR>$inquery<BR>".mysql_error());
echo "<BR>Entry succesfully added!";
}
if ($action == "import")
{
form();
echo "<TABLE WIDTH='400' BGCOLOR='#EEEEEE'><TR><TD ALIGN='CENTER'>";
echo "<FONT SIZE='1'><B>Note:</B><BR>File should be a standard comma delimited file with no quotes in the form of:<BR><BR>";
echo "<I>Firstname, Lastname, Email, Token</I></TD></TR></TABLE>\n";
}
if ($action == "upload")
{
$the_path="$homedir";
$the_full_file_path=$homedir."/".$the_file_name;
if (!@copy($the_file, $the_path . "/" . $the_file_name))
{
form("\n<b>Something went horribly wrong, check the path to and ".
"the permissions for the upload directory</b>");
}
else
{
echo "\n<BR><B>IMPORTING FILE</B><BR>File succesfully uploaded<BR><BR>";
echo "\nReading File...<BR>";
$handle=fopen($the_full_file_path, "r");
while (!feof($handle))
{
$buffer=fgets($handle);
//echo "$xx:".$buffer."<BR>";
if (!$xx)
{
//THIS IS THE FIRST LINE. IT IS THE HEADINGS. IGNORE IT
}
else
{
$line=explode(",",$buffer);
$elements=count($line);
if ($elements > 1)
{
$xy=0;
foreach($line as $el)
{
//echo "[$el]($xy)<BR>";
if ($xy<$elements)
{
if ($xy==0){$firstname=$el;}
if ($xy==1){$lastname=$el;}
if ($xy==2){$email=$el;}
if ($xy==3){$token=$el;}
}
$xy++;
}
//CHECK FOR DUPLICATES?
$iq="INSERT INTO tokens_$sid VALUES('','$firstname', '$lastname', '$email', '$token', '', '')";
$ir=mysql_query($iq) or die ("Couldn't insert line<BR>$iq<BR>".mysql_error());
$xz++;
}
}
$xx++;
}
echo "\nProcess completed. $xz records added.<BR>";
fclose($handle);
unlink($the_full_file_path);
}
}
//echo "ACTION: $action<BR>THEFILE: $the_file<BR>THEFILENAME: $the_file_name";
function form($error=false) {
global $PHP_SELF, $sid, $btstyle, $slstyle, $setfont;
if ($error) print $error . "<br><br>";
print "\n<form ENCTYPE=\"multipart/form-data\" action=\"" . $PHP_SELF . "\" method=\"post\">";
print "\n<INPUT TYPE=\"hidden\" name=\"action\" value=\"upload\">";
print "\n<INPUT TYPE=\"hidden\" name=\"sid\" value=\"$sid\">";
print "\n<P>$setfont Upload a file";
print "\n<br><INPUT $slstyle NAME=\"the_file\" TYPE=\"file\" SIZE=\"35\"><br>";
print "\n<input type=\"submit\" $btstyle Value=\"Upload\">";
print "\n</form>";
} # END form
?>