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