/
register.php
205 lines (180 loc) · 7.18 KB
/
register.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
<?php
/*
#############################################################
# >>> PHPSurveyor #
#############################################################
# > 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. #
#############################################################
*/
//THESE WILL BEMOVED INTO THE LANGUAGE FILE ONCE COMPLETED
require_once(dirname(__FILE__).'/config.php');
require_once($rootdir.'/classes/core/language.php');
$surveyid=returnglobal('sid');
//This next line is for security reasons. It ensures that the $surveyid value is never anything but a number.
if (_PHPVERSION >= '4.2.0') {settype($surveyid, "int");} else {settype($surveyid, "integer");}
//Check that there is a SID
if (!isset($surveyid))
{
//You must have an SID to use this
include "index.php";
exit;
}
session_start();
$thissurvey=getSurveyInfo($surveyid);
// Get passed language from form, so that we dont loose this!
if (!isset($_POST['lang']) || $_POST['lang'] == "")
{
$baselang = GetBaseLanguageFromSurveyID($surveyid);
$clang = new phpsurveyor_lang($baselang);
} else {
$clang = new phpsurveyor_lang($_POST['lang']);
}
$register_errormsg = "";
// Check the security question's answer
if (!isset($_POST['loadsecurity']) || $_POST['loadsecurity'] != $_SESSION['secanswer'])
{
$register_errormsg .= $clang->gT("The answer to security question is incorrect")."<br />\n";
}
//Check that the email is a valid style address
if (!validate_email(returnglobal('register_email')))
{
$register_errormsg .= $clang->gT("The email you used is not valid. Please try again.");
}
if ($register_errormsg != "")
{
include "index.php";
exit;
}
//Check if this email already exists in token database
$query = "SELECT email FROM {$dbprefix}tokens_$surveyid\n"
. "WHERE email = '".returnglobal('register_email')."'";
$result = $connect->Execute($query) or die ($query."<br />".htmlspecialchars($connect->ErrorMsg()));
if (($result->RecordCount()) > 0)
{
$register_errormsg=$clang->gT("The email you used has already been registered.");
include "index.php";
exit;
}
if (_PHPVERSION < "4.2.0")
{
srand((double)microtime()*1000000);
}
$insert = "NO";
while ($insert != "OK")
{
if (isset($THISOS) && $THISOS == "solaris")
{
$nt1=db_execute_num("SELECT RAND()");
while ($row=$nt1->FetchRow()) {$newtoken="R".(int)(sprintf("%09s", $row[0]*100000000));}
}
else
{
$newtoken = "R".sprintf("%09s", rand(1, 1000000000));
}
$ntquery = "SELECT * FROM {$dbprefix}tokens_$surveyid WHERE token='$newtoken'";
$ntresult = $connect->Execute($ntquery);
if (!$ntresult->RecordCount()) {$insert = "OK";}
}
//Insert new entry into tokens db
$query = "INSERT INTO {$dbprefix}tokens_$surveyid\n"
. "(`firstname`, `lastname`, `email`, `token`, `attribute_1`, `attribute_2`)\n"
. "VALUES (?, ?, ?, ?, ?, ?)";
$result = $connect->Execute($query, array(returnglobal('register_firstname'), returnglobal('register_lastname'),
returnglobal('register_email'), $newtoken,
returnglobal('register_attribute1'), returnglobal('register_attribute2'))
) or die ($query."<br />".htmlspecialchars($connect->ErrorMsg()));
$tid=$connect->Insert_ID();
$fieldsarray["{ADMINNAME}"]=$thissurvey['adminname'];
$fieldsarray["{ADMINEMAIL}"]=$thissurvey['adminemail'];
$fieldsarray["{SURVEYNAME}"]=$thissurvey['name'];
$fieldsarray["{SURVEYDESCRIPTION}"]=$thissurvey['description'];
$fieldsarray["{SURVEYURL}"]="$publicurl/index.php?sid=$surveyid&token=$newtoken";
$fieldsarray["{FIRSTNAME}"]=returnglobal('register_firstname');
$fieldsarray["{LASTNAME}"]=returnglobal('register_lastname');
$fieldsarray["{ATTRIBUTE_1}"]=returnglobal('register_attribute1');
$fieldsarray["{ATTRIBUTE_2}"]=returnglobal('register_attribute2');
$message=$thissurvey['email_register'];
$subject=$thissurvey['email_register_subj'];
$message=Replacefields($message, $fieldsarray);
$subject=Replacefields($subject, $fieldsarray);
$from = "{$thissurvey['adminname']} <{$thissurvey['adminemail']}>";
$html=""; //Set variable
if (MailtextMessage($message, $subject, returnglobal('register_email'), $from, $sitename))
{
// TLR change to put date into sent
// $query = "UPDATE {$dbprefix}tokens_$surveyid\n"
// ."SET sent='Y' WHERE tid=$tid";
$today = date("Y-m-d Hi");
$query = "UPDATE {$dbprefix}tokens_$surveyid\n"
."SET sent='$today' WHERE tid=$tid";
$result=$connect->Execute($query) or die ("$query<br />".htmlspecialchars($connect->ErrorMsg()));
$html="<center>".$clang->gT("Thank you for registering to participate in this survey.")."<br /><br />\n".$clang->gT("An email has been sent to the address you provided with access details for this survey. Please follow the link in that email to proceed.")."<br /><br />\n".$clang->gT("Survey Administrator")." {ADMINNAME} ({ADMINEMAIL})";
$html=Replacefields($html, $fieldsarray);
$html .= "<br /><br />\n<input type='submit' onclick='javascript: self.close()' value='".$clang->gT("Close this Window")."'></center>\n";
}
else
{
$html="Email Error";
}
//PRINT COMPLETED PAGE
if (!$publicdir) {$publicdir=".";}
if (!$thissurvey['template']) {$thistpl="$publicdir/templates/default";} else {$thistpl="$publicdir/templates/{$thissurvey['template']}";}
if (!is_dir($thistpl)) {$thistpl="$publicdir/templates/default";}
sendcacheheaders();
doHeader();
foreach(file("$thistpl/startpage.pstpl") as $op)
{
echo templatereplace1($op);
}
foreach(file("$thistpl/survey.pstpl") as $op)
{
echo "\t".templatereplace1($op);
}
echo $html;
foreach(file("$thistpl/endpage.pstpl") as $op)
{
echo templatereplace1($op);
}
doFooter();
function templatereplace1($line)
{
global $thissurvey, $surveyid;
global $publicurl, $templatedir, $token;
if ($thissurvey['template']) {$templateurl="$publicurl/templates/{$thissurvey['template']}/";}
else {$templateurl="$publicurl/templates/default/";}
$line=str_replace("{SURVEYNAME}", $thissurvey['name'], $line);
$line=str_replace("{SURVEYDESCRIPTION}", $thissurvey['description'], $line);
$line=str_replace("{TOKEN}", $token, $line);
$line=str_replace("{SID}", $surveyid, $line);
$line=str_replace("{TEMPLATEURL}", $templateurl, $line);
$line=str_replace("{PERCENTCOMPLETE}", "", $line);
return $line;
}
?>