r765: Say hello to the GPL
[bugdar.git] / userctrl.php
1 <?php
2 /*=====================================================================*\
3 || ###################################################################
4 || # Bugdar [#]version[#]
5 || # Copyright ©2002-[#]year[#] Iris Studios, Inc.
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 [#]gpl[#] 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 'userctrl'
24 );
25
26 define('SVN', '$Id$');
27
28 $focus['user'] = 'focus';
29
30 require_once('./global.php');
31
32 if (!$bugsys->userinfo['userid'])
33 {
34 $message->error_permission();
35 }
36
37 $userinfo = $bugsys->userinfo;
38
39 // ###################################################################
40
41 if (empty($_REQUEST['do']))
42 {
43 $_REQUEST['do'] = 'modify';
44 }
45
46 // ###################################################################
47
48 if ($_POST['do'] == 'update')
49 {
50 // -------------------------------------------------------------------
51 // display name validation
52 $count = $db->query_first("SELECT * FROM " . TABLE_PREFIX . "user WHERE displayname = '" . $bugsys->in['displayname'] . "' AND userid <> " . $bugsys->userinfo['userid']);
53 if ($count)
54 {
55 $message->items[] = $lang->string('That display name is already in use by another user');
56 }
57
58 // -------------------------------------------------------------------
59 // authentication
60 if (!empty($bugsys->in['password']) OR !empty($bugsys->in['email']))
61 {
62 if (empty($bugsys->in['validate']))
63 {
64 $message->items[] = $lang->string('You need to enter your current password to change your email or password');
65 }
66 else
67 {
68 if (md5(md5($bugsys->in['validate']) . md5($bugsys->userinfo['salt'])) != $bugsys->userinfo['password'])
69 {
70 $message->items[] = $lang->string('Your authentication password does not match the one in our records');
71 }
72 }
73 }
74
75 // -------------------------------------------------------------------
76 // email validation
77 if (!empty($bugsys->in['email']))
78 {
79 if (!empty($bugsys->in['email']) AND empty($bugsys->in['email_confirm']))
80 {
81 $message->items[] = $lang->string('You need to enter both the email and confirm email fields to change your address');
82 }
83
84 if ($bugsys->in['email'] != $bugsys->in['email_confirm'])
85 {
86 $message->items[] = $lang->string('Your email and confirm email addresses do not match');
87 }
88
89 if ($bugsys->in['email'])
90 {
91 $count = $db->query_first("SELECT * FROM " . TABLE_PREFIX . "user WHERE email = '" . $bugsys->in['email'] . "' AND userid <> " . $bugsys->userinfo['userid']);
92 if ($count)
93 {
94 $message->items[] = $lang->string('That email address is already in use');
95 }
96 }
97
98 $email = true;
99 }
100
101 // -------------------------------------------------------------------
102 // password validation
103 if (!empty($bugsys->in['password']))
104 {
105 if (!empty($bugsys->in['password']) AND empty($bugsys->in['password_confirm']))
106 {
107 $message->items[] = $lang->string('You need to enter both the password and confirm password fields to change your password');
108 }
109 else
110 {
111 if ($bugsys->in['password'] != $bugsys->in['password_confirm'])
112 {
113 $message->items[] = $lang->string('Your password and confirm password do not match');
114 }
115 }
116
117 $password = true;
118 }
119
120 // -------------------------------------------------------------------
121 // copy fields
122 $userinfo['displayname'] = $bugsys->in['displayname'];
123 $userinfo['showemail'] = $bugsys->in['showemail'];
124 $userinfo['showcolours'] = $bugsys->in['showcolours'];
125 $userinfo['languageid'] = $bugsys->in['languageid'];
126 $userinfo['timezone'] = $bugsys->in['timezone'];
127
128 $email = $bugsys->in['email'];
129 $email_confirm = $bugsys->in['email_confirm'];
130
131 // -------------------------------------------------------------------
132 // error handling
133 if ($message->items)
134 {
135 $message->error_list_process();
136
137 $show['errors'] = true;
138 $_REQUEST['do'] = 'modify';
139 }
140 else
141 {
142 $db->query("
143 UPDATE " . TABLE_PREFIX . "user
144 SET displayname = '" . $bugsys->in['displayname'] . "',
145 showemail = " . intval($bugsys->in['showemail']) . ",
146 showcolours = " . intval($bugsys->in['showcolours']) . ",
147 languageid = " . intval($bugsys->in['languageid']) . ",
148 timezone = " . intval($bugsys->in['timezone']) . ($email ? ",
149 email = '" . $bugsys->in['email'] . "'" : '') . ($password ? ",
150 password = '" . md5(md5($bugsys->in['password']) . md5($bugsys->userinfo['salt'])) . "'" : '') . "
151 WHERE userid = " . $bugsys->userinfo['userid']
152 );
153
154 if (can_perform('canbeassignedto'))
155 {
156 require_once('./includes/functions_datastore.php');
157 build_assignedto();
158 }
159
160 $message->redirect($lang->string('The changes to your account have been made.'), 'userctrl.php');
161 }
162 }
163
164 // ###################################################################
165
166 if ($_REQUEST['do'] == 'modify')
167 {
168 $langselect = construct_datastore_select('language', 'title', 'languageid', $userinfo['languageid']);
169
170 foreach ($datef->fetch_timezone_list() AS $value => $label)
171 {
172 $selected = ($value == $userinfo['timezone']);
173 eval('$tzselect .= "' . $template->fetch('selectoption') . '";');
174 }
175
176 eval('$template->flush("' . $template->fetch('userctrl') . '");');
177 }
178
179 /*=====================================================================*\
180 || ###################################################################
181 || # $HeadURL$
182 || # $Id$
183 || ###################################################################
184 \*=====================================================================*/
185 ?>