2 /*=====================================================================*\
3 || ###################################################################
5 || # Copyright ©2002-2007 Blue Static
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.
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
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 \*=====================================================================*/
22 $fetchtemplates = array(
26 define('SVN', '$Id$');
28 $focus['user'] = 'focus';
30 require_once('./global.php');
31 require_once('./includes/api_user.php');
33 APIError(array(new API_Error_Handler($message), 'user_cumulative'));
35 // ###################################################################
37 if ($_POST['do'] == 'insert')
39 if (bugdar
::$userinfo['userid'])
41 $message->error(T('Sorry, you are already registered.'));
44 if (!bugdar
::$options['allownewreg'])
46 $message->error(T('Sorry, we don\'t allow new registrations.'));
49 if ($input->in
['email'] != $input->in
['confirmemail'])
51 $message->addError(T('The emails you entered do not match.'));
54 if ($input->in
['password'] != $input->in
['confirmpassword'])
56 $message->addError(T('The passwords you entered did not match.'));
59 if (bugdar
::$options['verifyemail'])
65 if (bugdar
::$options['moderatenewusers'])
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);
85 if (!$message->hasErrors())
89 $userid = $user->insertid
;
91 // Verify email address
92 if ($usergroupid == 3)
94 $activationid = BSFunctions
::random(25);
96 $db->query("INSERT INTO " . TABLE_PREFIX
. "useractivation (userid, activator, dateline, usergroupid) VALUES ($userid, '$activationid', " . TIMENOW
. ", 2)");
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']);
103 $mail->send($input->in
['email'], $input->in
['displayname']);
105 $message->message(T('You now need to activate your account via email.'));
107 else if ($usergroupid == 4 OR $usergroupid == 2)
109 if (bugdar
::$options['sendwelcomemail'])
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']);
119 if ($usergroupid == 4)
121 $message->message(T('Your account is pending approval.'));
125 $message->message(T('Thank you for registering. You may now use your account.'));
131 $_REQUEST['do'] = '';
132 $show['errors'] = true
;
136 // ###################################################################
138 if (empty($_REQUEST['do']))
140 if (bugdar
::$userinfo['userid'])
142 $message->error(T('Sorry, you are already registered.'));
145 if (!bugdar
::$options['allownewreg'])
147 $message->error(T('Sorry, we don\'t allow new registrations.'));
150 foreach (bugdar
::$datastore['language'] AS $value => $temp)
152 $label = $temp['title'];
153 $selected = ($value == $input->in
['languageid']);
154 eval('$opts .= "' . $template->fetch('selectoption') . '";');
157 eval('$template->flush("' . $template->fetch('register') . '");');
160 // ###################################################################
162 if ($_REQUEST['do'] == 'activate')
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') . "'"))
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']);
171 if (bugdar
::$options['sendwelcomemail'])
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']);
181 $message->message(T('Your account is now activated and you can now login.'));
185 $message->error(T('Sorry, we could not match your registration string. Please make sure you entered the correct URL.'));
189 /*=====================================================================*\
190 || ###################################################################
193 || ###################################################################
194 \*=====================================================================*/