Remove includes/class_api_error.php and all of the places we require() it
[bugdar.git] / register.php
1 <?php
2 /*=====================================================================*\
3 || ###################################################################
4 || # Bugdar
5 || # Copyright ©2002-2007 Blue Static
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 2 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 require_once('./includes/api_user.php');
32
33 APIError(array(new API_Error_Handler($message), 'user_cumulative'));
34
35 // ###################################################################
36
37 if ($_POST['do'] == 'insert')
38 {
39 if (bugdar::$userinfo['userid'])
40 {
41 $message->error(T('Sorry, you are already registered.'));
42 }
43
44 if (!bugdar::$options['allownewreg'])
45 {
46 $message->error(T('Sorry, we don\'t allow new registrations.'));
47 }
48
49 if ($input->in['email'] != $input->in['confirmemail'])
50 {
51 $message->addError(T('The emails you entered do not match.'));
52 }
53
54 if ($input->in['password'] != $input->in['confirmpassword'])
55 {
56 $message->addError(T('The passwords you entered did not match.'));
57 }
58
59 if (bugdar::$options['verifyemail'])
60 {
61 $usergroupid = 3;
62 }
63 else
64 {
65 if (bugdar::$options['moderatenewusers'])
66 {
67 $usergroupid = 4;
68 }
69 else
70 {
71 $usergroupid = 2;
72 }
73 }
74
75 $user = new UserAPI();
76 $user->set('email', $input->in['email']);
77 $user->set('displayname', $input->in['displayname']);
78 $user->set('password', $input->in['password']);
79 $user->set('showemail', $input->in['showemail']);
80 $user->set('showcolors', 1);
81 $user->set('languageid', $input->in['languageid']);
82 $user->set('timezone', bugdar::$options['defaulttimezone']);
83 $user->set('usergroupid', $usergroupid);
84
85 if (!$message->hasErrors())
86 {
87 $user->insert();
88
89 $userid = $user->insertid;
90
91 // Verify email address
92 if ($usergroupid == 3)
93 {
94 $activationid = BSFunctions::random(25);
95
96 $db->query("INSERT INTO " . TABLE_PREFIX . "useractivation (userid, activator, dateline, usergroupid) VALUES ($userid, '$activationid', " . TIMENOW . ", 2)");
97
98 eval('$email = "' . $template->fetch(FetchEmailPath('activateaccount.xml', bugdar::$datastore['language'][$input->in['languageid']]['langcode'])) . '";');
99 $email = $bugsys->xml->parse($email);
100 $mail->setSubject($email['email']['subject']['value']);
101 $mail->setBodyText($email['email']['bodyText']['value']);
102
103 $mail->send($input->in['email'], $input->in['displayname']);
104
105 $message->message(T('You now need to activate your account via email.'));
106 }
107 else if ($usergroupid == 4 OR $usergroupid == 2)
108 {
109 if (bugdar::$options['sendwelcomemail'])
110 {
111 $displayName = $input->in['displayname'];
112 eval('$email = "' . $template->fetch(FetchEmailPath('welcome.xml', bugdar::$datastore['language'][$input->in['languageid']]['langcode'])) . '";');
113 $email = $bugsys->xml->parse($email);
114 $mail->setSubject($email['email']['subject']['value']);
115 $mail->setBodyText($email['email']['bodyText']['value']);
116 $mail->send($input->in['email'], $input->in['displayname']);
117 }
118
119 if ($usergroupid == 4)
120 {
121 $message->message(T('Your account is pending approval.'));
122 }
123 else
124 {
125 $message->message(T('Thank you for registering. You may now use your account.'));
126 }
127 }
128 }
129 else
130 {
131 $_REQUEST['do'] = '';
132 $show['errors'] = true;
133 }
134 }
135
136 // ###################################################################
137
138 if (empty($_REQUEST['do']))
139 {
140 if (bugdar::$userinfo['userid'])
141 {
142 $message->error(T('Sorry, you are already registered.'));
143 }
144
145 if (!bugdar::$options['allownewreg'])
146 {
147 $message->error(T('Sorry, we don\'t allow new registrations.'));
148 }
149
150 foreach (bugdar::$datastore['language'] AS $value => $temp)
151 {
152 $label = $temp['title'];
153 $selected = ($value == $input->in['languageid']);
154 eval('$opts .= "' . $template->fetch('selectoption') . '";');
155 }
156
157 eval('$template->flush("' . $template->fetch('register') . '");');
158 }
159
160 // ###################################################################
161
162 if ($_REQUEST['do'] == 'activate')
163 {
164 $input->inputClean('userid', TYPE_UINT);
165 if ($useractivation = $db->queryFirst("SELECT * FROM " . TABLE_PREFIX . "useractivation WHERE userid = " . $input->in['userid'] . " AND activator = '" . $bugsys->input_escape('activator') . "'"))
166 {
167 $user = $db->queryFirst("SELECT * FROM " . TABLE_PREFIX . "user WHERE userid = " . $input->in['userid']);
168 $db->query("UPDATE " . TABLE_PREFIX . "user SET usergroupid = $useractivation[usergroupid] WHERE userid = " . $input->in['userid']);
169 $db->query("DELETE FROM " . TABLE_PREFIX . "useractivation WHERE userid = " . $input->in['userid']);
170
171 if (bugdar::$options['sendwelcomemail'])
172 {
173 $displayName = $user['displayname'];
174 eval('$email = "' . $template->fetch(FetchEmailPath('welcome.xml', bugdar::$datastore['language'][$user['languageid']]['langcode'])) . '";');
175 $email = $bugsys->xml->parse($email);
176 $mail->setSubject($email['email']['subject']['value']);
177 $mail->setBodyText($email['email']['bodyText']['value']);
178 $mail->send($user['email'], $user['displayname']);
179 }
180
181 $message->message(T('Your account is now activated and you can now login.'));
182 }
183 else
184 {
185 $message->error(T('Sorry, we could not match your registration string. Please make sure you entered the correct URL.'));
186 }
187 }
188
189 /*=====================================================================*\
190 || ###################################################################
191 || # $HeadURL$
192 || # $Id$
193 || ###################################################################
194 \*=====================================================================*/
195 ?>