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