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