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