r836: Implementing user API in userctrl.php
[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 require_once('./includes/api_user.php');
32
33 if (!$bugsys->userinfo['userid'])
34 {
35 $message->error_permission();
36 }
37
38 $userapi = new UserAPI($bugsys);
39 $userapi->set('userid', $bugsys->userinfo['userid']);
40 $userapi->set_condition();
41
42 $userinfo = $bugsys->userinfo;
43
44 // ###################################################################
45
46 if (empty($_REQUEST['do']))
47 {
48 $_REQUEST['do'] = 'modify';
49 }
50
51 // ###################################################################
52
53 if ($_POST['do'] == 'update')
54 {
55 // -------------------------------------------------------------------
56 // authentication
57 if (!empty($bugsys->in['password']) OR !empty($bugsys->in['email']))
58 {
59 if (empty($bugsys->in['validate']))
60 {
61 $message->items[] = $lang->string('You need to enter your current password to change your email or password');
62 }
63 else
64 {
65 if (md5(md5($bugsys->in['validate']) . md5($bugsys->userinfo['salt'])) != $bugsys->userinfo['password'])
66 {
67 $message->items[] = $lang->string('Your authentication password does not match the one in our records');
68 }
69 }
70 }
71
72 // -------------------------------------------------------------------
73 // email validation
74 if (!empty($bugsys->in['email']))
75 {
76 if (!empty($bugsys->in['email']) AND empty($bugsys->in['email_confirm']))
77 {
78 $message->items[] = $lang->string('You need to enter both the email and confirm email fields to change your address');
79 }
80
81 if ($bugsys->in['email'] != $bugsys->in['email_confirm'])
82 {
83 $message->items[] = $lang->string('Your email and confirm email addresses do not match');
84 }
85
86 $userapi->set('email', $bugsys->in['email']);
87
88 $email = true;
89 }
90
91 // -------------------------------------------------------------------
92 // password validation
93 if (!empty($bugsys->in['password']))
94 {
95 if (!empty($bugsys->in['password']) AND empty($bugsys->in['password_confirm']))
96 {
97 $message->items[] = $lang->string('You need to enter both the password and confirm password fields to change your password');
98 }
99 else
100 {
101 if ($bugsys->in['password'] != $bugsys->in['password_confirm'])
102 {
103 $message->items[] = $lang->string('Your password and confirm password do not match');
104 }
105 }
106
107 $userapi->set('password', $bugsys->in['password']);
108
109 $password = true;
110 }
111
112 $userapi->set('displayname', $bugsys->in['displayname']);
113 $userapi->set('showemail', $bugsys->in['showemail']);
114 $userapi->set('showcolours', $bugsys->in['showcolours']);
115 $userapi->set('languageid', $bugsys->in['languageid']);
116 $userapi->set('timezone', $bugsys->in['timezone']);
117
118 // -------------------------------------------------------------------
119 // copy fields
120 $userinfo['displayname'] = $bugsys->in['displayname'];
121 $userinfo['showemail'] = $bugsys->in['showemail'];
122 $userinfo['showcolours'] = $bugsys->in['showcolours'];
123 $userinfo['languageid'] = $bugsys->in['languageid'];
124 $userinfo['timezone'] = $bugsys->in['timezone'];
125
126 $email = $bugsys->in['email'];
127 $email_confirm = $bugsys->in['email_confirm'];
128
129 // -------------------------------------------------------------------
130 // error handling
131 if ($message->items)
132 {
133 $message->error_list_process();
134
135 $show['errors'] = true;
136 $_REQUEST['do'] = 'modify';
137 }
138 else
139 {
140 $userapi->update();
141
142 if (can_perform('canbeassignedto'))
143 {
144 require_once('./includes/functions_datastore.php');
145 build_assignedto();
146 }
147
148 $message->redirect($lang->string('The changes to your account have been made.'), 'userctrl.php');
149 }
150 }
151
152 // ###################################################################
153
154 if ($_REQUEST['do'] == 'modify')
155 {
156 $langselect = construct_datastore_select('language', 'title', 'languageid', $userinfo['languageid']);
157
158 foreach ($datef->fetch_timezone_list() AS $value => $label)
159 {
160 $selected = ($value == $userinfo['timezone']);
161 eval('$tzselect .= "' . $template->fetch('selectoption') . '";');
162 }
163
164 eval('$template->flush("' . $template->fetch('userctrl') . '");');
165 }
166
167 /*=====================================================================*\
168 || ###################################################################
169 || # $HeadURL$
170 || # $Id$
171 || ###################################################################
172 \*=====================================================================*/
173 ?>