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