r765: Say hello to the GPL
[bugdar.git] / register.php
1 <?php
2 /*=====================================================================*\
3 || ###################################################################
4 || # Bugdar [#]version[#]
5 || # Copyright ©2002-[#]year[#] Iris Studios, Inc.
6 || #
7 || # This program is free software; you can redistribute it and/or modify
8 || # it under the terms of the GNU General Public License as published by
9 || # the Free Software Foundation; version [#]gpl[#] of the License.
10 || #
11 || # This program is distributed in the hope that it will be useful, but
12 || # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 || # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 || # more details.
15 || #
16 || # You should have received a copy of the GNU General Public License along
17 || # with this program; if not, write to the Free Software Foundation, Inc.,
18 || # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
19 || ###################################################################
20 \*=====================================================================*/
21
22 $fetchtemplates = array(
23 'register'
24 );
25
26 define('SVN', '$Id$');
27
28 $focus['user'] = 'focus';
29
30 require_once('./global.php');
31
32 // ###################################################################
33
34 if ($_POST['do'] == 'insert')
35 {
36 if ($bugsys->userinfo['userid'])
37 {
38 $message->error($lang->string('Sorry, you are already registered.'));
39 }
40
41 if (!$bugsys->options['allownewreg'])
42 {
43 $message->error($lang->string('Sorry, we don\'t allow new registrations.'));
44 }
45
46 if ($bugsys->in['email'] != $bugsys->in['confirmemail'])
47 {
48 $message->items[] = $lang->string('The emails you entered do not match.');
49 }
50
51 if (!$bugsys->in['email'])
52 {
53 $message->items[] = $lang->string('The email you specified was blank.');
54 }
55
56 if ($bugsys->in['password'] != $bugsys->in['confirmpassword'])
57 {
58 $message->items[] = $lang->string('The passwords you entered did not match.');
59 }
60
61 if (!$bugsys->in['password'])
62 {
63 $message->items[] = $lang->string('The password you specified was blank.');
64 }
65
66 if (!$bugsys->in['displayname'])
67 {
68 $message->items[] = $lang->string('The display name you specified was blank.');
69 }
70
71 if (!$funct->is_valid_email($bugsys->in['email']))
72 {
73 $message->items[] = $lang->string('The specified email is invalid.');
74 }
75
76 if (is_array($db->query_first("SELECT * FROM " . TABLE_PREFIX . "user WHERE email = '" . $bugsys->in['email'] . "'")))
77 {
78 $message->items[] = $lang->string('The specified email is already in use.');
79 }
80
81 if (is_array($db->query_first("SELECT * FROM " . TABLE_PREFIX . "user WHERE displayname = '" . $bugsys->in['displayname'] . "'")))
82 {
83 $message->items[] = $lang->string('That display name is already in use by another user.');
84 }
85
86 if (!$message->items)
87 {
88 $salt = $funct->rand(15);
89
90 if ($bugsys->options['verifyemail'])
91 {
92 $usergroupid = 3;
93 }
94 else
95 {
96 if ($bugsys->options['moderatenewusers'])
97 {
98 $usergroupid = 4;
99 }
100 else
101 {
102 $usergroupid = 2;
103 }
104 }
105
106 $db->query("
107 INSERT INTO " . TABLE_PREFIX . "user
108 (email, displayname, password, salt, authkey, showemail, showcolours, languageid, usergroupid)
109 VALUES
110 ('" . $bugsys->in['email'] . "',
111 '" . $bugsys->in['displayname'] . "',
112 '" . md5(md5($bugsys->in['password']) . md5($salt)) . "',
113 '$salt',
114 '" . $funct->rand() . "',
115 " . intval($bugsys->in['showemail']) . ",
116 1,
117 " . intval($bugsys->in['languageid']) . ",
118 $usergroupid
119 )"
120 );
121
122 $userid = $db->insert_id();
123
124 // Verify email address
125 if ($usergroupid == 3)
126 {
127 $activationid = $funct->rand(25);
128
129 $db->query("INSERT INTO " . TABLE_PREFIX . "useractivation (userid, activator, dateline, usergroupid) VALUES ($userid, '$activationid', " . TIMENOW . ", 2)");
130
131 $mail->to = $bugsys->in['email'];
132 $mail->subject = sprintf($lang->string('Welcome to %1$s'), $bugsys->options['trackertitle']);
133 $mail->body = sprintf($lang->string('Hi %1$s,
134
135 Welcome to the %2$s tracker. Before you can begin posting bug reports, you\'ll need to activae your account. To do this, please click this link:
136
137 %3$s/register.php?do=activate&userid=%4$s&activator=%5$s'),
138
139 $bugsys->in['displayname'],
140 $bugsys->options['trackertitle'],
141 $bugsys->options['trackerurl'],
142 $userid,
143 $activationid
144 );
145
146 $mail->send();
147
148 $message->message($lang->string('You now need to activate your account via email.'));
149 }
150 else if ($usergroupid == 4 OR $usergroupid == 2)
151 {
152 if ($bugsys->options['sendwelcomemail'])
153 {
154 $mail->to = $bugsys->in['email'];
155 $mail->subject = sprintf($lang->string('Welcome to %1$s'), $bugsys->options['trackertitle']);
156 $mail->body = sprintf($lang->string('Hi %1$s,
157
158 Thank you for taking the time to register at %2$s. We look forward to your contributations to making our products better.
159
160 If you have any questions, please don\'t hesitate to contact the webmaster.'),
161 $bugsys->in['displayname'],
162 $bugsys->options['trackertitle']
163 );
164
165 $mail->send();
166 }
167
168 if ($usergroupid == 4)
169 {
170 $message->message($lang->string('Your account is pending approval.'));
171 }
172 else
173 {
174 $message->message($lang->string('Thank you for registering. You may now use your account.'));
175 }
176 }
177 }
178 else
179 {
180 $_REQUEST['do'] = '';
181 $show['errors'] = true;
182 $message->error_list_process();
183 }
184 }
185
186 // ###################################################################
187
188 if (empty($_REQUEST['do']))
189 {
190 if ($bugsys->userinfo['userid'])
191 {
192 $message->error($lang->string('Sorry, you are already registered.'));
193 }
194
195 if (!$bugsys->options['allownewreg'])
196 {
197 $message->error($lang->string('Sorry, we don\'t allow new registrations.'));
198 }
199
200 foreach ($bugsys->datastore['language'] AS $value => $temp)
201 {
202 $label = $temp['title'];
203 $selected = ($value == $bugsys->in['languageid']);
204 eval('$opts .= "' . $template->fetch('selectoption') . '";');
205 }
206
207 eval('$template->flush("' . $template->fetch('register') . '");');
208 }
209
210 // ###################################################################
211
212 if ($_REQUEST['do'] == 'activate')
213 {
214 if ($useractivation = $db->query_first("SELECT * FROM " . TABLE_PREFIX . "useractivation WHERE userid = " . intval($bugsys->in['userid']) . " AND activator = '" . $bugsys->in['activator'] . "'"))
215 {
216 $user = $db->query_first("SELECT * FROM " . TABLE_PREFIX . "user WHERE userid = " . intval($bugsys->in['userid']));
217 $db->query("UPDATE " . TABLE_PREFIX . "user SET usergroupid = $useractivation[usergroupid] WHERE userid = " . intval($bugsys->in['userid']));
218 $db->query("DELETE FROM " . TABLE_PREFIX . "useractivation WHERE userid = " . intval($bugsys->in['userid']));
219
220 if ($bugsys->options['sendwelcomemail'])
221 {
222 $mail->to = $user['email'];
223 $mail->subject = sprintf($lang->string('Welcome to %1$s'), $bugsys->options['trackertitle']);
224 $mail->body = sprintf($lang->string('Hi %1$s,
225
226 Thank you for taking the time to register at %2$s. We look forward to your contributations to making our products better.
227
228 If you have any questions, please don\'t hesitate to contact the webmaster.'),
229 $user['displayname'],
230 $bugsys->options['trackertitle']
231 );
232 $mail->send();
233 }
234
235 $message->message($lang->string('Your account is now activated and you can now login.'));
236 }
237 else
238 {
239 $message->error($lang->string('Sorry, we could not match your registration string. Please make sure you entered the correct URL.'));
240 }
241 }
242
243 /*=====================================================================*\
244 || ###################################################################
245 || # $HeadURL$
246 || # $Id$
247 || ###################################################################
248 \*=====================================================================*/
249 ?>