r444: Fixing parse errors
[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, 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 " . intval($bugsys->in['languageid']) . ",
125 $usergroupid
126 )"
127 );
128
129 $userid = $db->insert_id();
130
131 // Verify email address
132 if ($usergroupid == 3)
133 {
134 $activationid = $funct->rand(25);
135
136 $db->query("INSERT INTO " . TABLE_PREFIX . "useractivation (userid, activator, dateline, usergroupid) VALUES ($userid, '$activationid', " . TIMENOW . ", 2)");
137
138 $mail->to = $bugsys->in['email'];
139 $mail->subject = sprintf($lang->string('Welcome to %1$s'), $bugsys->options['trackertitle']);
140 $mail->body = sprintf($lang->string('Hi %1$s,
141
142 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:
143
144 %3$s/register.php?do=activate&userid=%4$s&activator=%5$s'),
145
146 $bugsys->in['displayname'],
147 'Avalon Development', // #*# change
148 'http://devbox/bugtrack', // #*# change
149 $userid,
150 $activationid
151 );
152
153 $mail->send();
154
155 $message->message($lang->string('You now need to activate your account via email.'));
156 }
157 else if ($usergroupid == 4 OR $usergroupid == 2)
158 {
159 if ($bugsys->options['sendwelcomemail'])
160 {
161 $mail->to = $bugsys->in['email'];
162 $mail->subject = sprintf($lang->string('Welcome to %1$s'), $bugsys->options['trackertitle']);
163 $mail->body = sprintf($lang->string('Hi %1$s,
164
165 Thank you for taking the time to register at %2$s. We look forward to your contributations to making our products better.
166
167 If you have any questions, please don\'t hesitate to contact the webmaster.'),
168 $bugsys->in['displayname'],
169 $bugsys->options['trackertitle']
170 );
171
172 $mail->send();
173 }
174
175 if ($usergroupid == 4)
176 {
177 $message->message($lang->string('Your account is pending approval.'));
178 }
179 else
180 {
181 $message->message($lang->string('Thank you for registering. You may now use your account.'));
182 }
183 }
184 }
185
186 // ###################################################################
187
188 if ($_REQUEST['do'] == 'activate')
189 {
190 if ($useractivation = $db->query_first("SELECT * FROM " . TABLE_PREFIX . "useractivation WHERE userid = " . intval($bugsys->in['userid']) . " AND activator = '" . $bugsys->in['activator'] . "'"))
191 {
192 $user = $db->query_first("SELECT * FROM " . TABLE_PREFIX . "user WHERE userid = " . intval($bugsys->in['userid']));
193 $db->query("UPDATE " . TABLE_PREFIX . "user SET usergroupid = $useractivation[usergroupid] WHERE userid = " . intval($bugsys->in['userid']));
194 $db->query("DELETE FROM " . TABLE_PREFIX . "useractivation WHERE userid = " . intval($bugsys->in['userid']));
195
196 if ($bugsys->options['sendwelcomemail'])
197 {
198 $mail->to = $user['email'];
199 $mail->subject = sprintf($lang->string('Welcome to %1$s'), $bugsys->options['trackertitle']);
200 $mail->body = sprintf($lang->string('Hi %1$s,
201
202 Thank you for taking the time to register at %2$s. We look forward to your contributations to making our products better.
203
204 If you have any questions, please don\'t hesitate to contact the webmaster.'),
205 $user['displayname'],
206 $bugsys->options['trackertitle']
207 );
208 $mail->send();
209 }
210
211 $message->message($lang->string('Your account is now activated and you can now login.'));
212 }
213 else
214 {
215 $message->error($lang->string('Sorry, we could not match your registration string. Please make sure you entered the correct URL.'));
216 }
217 }
218
219 /*=====================================================================*\
220 || ###################################################################
221 || # $HeadURL$
222 || # $Id$
223 || ###################################################################
224 \*=====================================================================*/
225 ?>