preferences.php
7.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
<?php
/**
* $Id$
*
* The contents of this file are subject to the KnowledgeTree Public
* License Version 1.1 ("License"); You may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.ktdms.com/KPL
*
* Software distributed under the License is distributed on an "AS IS"
* basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is: KnowledgeTree Open Source
*
* The Initial Developer of the Original Code is The Jam Warehouse Software
* (Pty) Ltd, trading as KnowledgeTree.
* Portions created by The Jam Warehouse Software (Pty) Ltd are Copyright
* (C) 2006 The Jam Warehouse Software (Pty) Ltd;
* All Rights Reserved.
*
*/
// main library routines and defaults
require_once("config/dmsDefaults.php");
require_once(KT_LIB_DIR . "/unitmanagement/Unit.inc");
require_once(KT_LIB_DIR . "/templating/templating.inc.php");
require_once(KT_LIB_DIR . "/templating/kt3template.inc.php");
require_once(KT_LIB_DIR . "/dispatcher.inc.php");
require_once(KT_LIB_DIR . '/widgets/fieldWidgets.php');
class PreferencesDispatcher extends KTStandardDispatcher {
var $sSection = 'preferences';
function check() {
$oConfig =& KTConfig::getSingleton();
if ($this->oUser->getId() == -2 ||
($oConfig->get('user_prefs/restrictPreferences', false) && !Permission::userIsSystemAdministrator($this->oUser->getId()))) {
return false;
}
return parent::check();
}
function PreferencesDispatcher() {
$this->aBreadcrumbs = array(
array('action' => 'preferences', 'name' => _kt('Preferences')),
);
return parent::KTStandardDispatcher();
}
function do_main() {
$this->oPage->setBreadcrumbDetails(_kt("Your Preferences"));
$this->oPage->title = _kt("Dashboard");
$oUser =& $this->oUser;
$aOptions = array('autocomplete' => false);
$edit_fields = array();
$edit_fields[] = new KTStringWidget(_kt('Name'), _kt('Your full name. This is shown in reports and listings. e.g. <strong>John Smith</strong>'), 'name', $oUser->getName(), $this->oPage, true, null, null, $aOptions);
$edit_fields[] = new KTStringWidget(_kt('Email Address'), _kt('Your email address. Notifications and alerts are mailed to this address if <strong>email notifications</strong> is set below. e.g. <strong>jsmith@acme.com</strong>'), 'email_address', $oUser->getEmail(), $this->oPage, false, null, null, $aOptions);
$edit_fields[] = new KTCheckboxWidget(_kt('Email Notifications'), _kt('If this is specified then the you will receive certain notifications. If it is not set, then you will only see notifications on the <strong>Dashboard</strong>'), 'email_notifications', $oUser->getEmailNotification(), $this->oPage, false, null, null, $aOptions);
$edit_fields[] = new KTStringWidget(_kt('Mobile Number'), _kt('Your mobile phone number. e.g. <strong>+27 99 999 9999</strong>'), 'mobile_number', $oUser->getMobile(), $this->oPage, false, null, null, $aOptions);
$oTemplating =& KTTemplating::getSingleton();
$oTemplate = $oTemplating->loadTemplate("ktcore/principals/preferences");
$iSourceId = $oUser->getAuthenticationSourceId();
$bChangePassword = true;
if ($iSourceId) {
$bChangePassword = false;
}
$aTemplateData = array(
"context" => $this,
'edit_fields' => $edit_fields,
"show_password" => $bChangePassword,
);
return $oTemplate->render($aTemplateData);
}
function do_setPassword() {
$this->oPage->setBreadcrumbDetails(_kt("Your Password"));
$this->oPage->title = _kt("Dashboard");
$oUser =& $this->oUser;
$aOptions = array('autocomplete' => false);
$edit_fields = array();
$edit_fields[] = new KTPasswordWidget(_kt('Password'), _kt('Specify your new password.'), 'password', null, $this->oPage, true, null, null, $aOptions);
$edit_fields[] = new KTPasswordWidget(_kt('Confirm Password'), _kt('Confirm the password specified above.'), 'confirm_password', null, $this->oPage, true, null, null, $aOptions);
$oTemplating =& KTTemplating::getSingleton();
$oTemplate = $oTemplating->loadTemplate("ktcore/principals/password");
$aTemplateData = array(
"context" => $this,
'edit_fields' => $edit_fields,
);
return $oTemplate->render($aTemplateData);
}
function do_updatePassword() {
$password = KTUtil::arrayGet($_REQUEST, 'password');
$confirm_password = KTUtil::arrayGet($_REQUEST, 'confirm_password');
if (empty($password)) {
$this->errorRedirectTo("setPassword", _kt("You must specify a password."));
} else if ($password !== $confirm_password) {
$this->errorRedirectTo("setPassword", _kt("The passwords you specified do not match."));
}
$KTConfig =& KTConfig::getSingleton();
$minLength = ((int) $KTConfig->get('user_prefs/passwordLength', 6));
if (strlen($password) < $minLength) {
$this->errorRedirectTo("setPassword", sprintf(_kt("Your password is too short - passwords must be at least %d characters long."), $minLength));
}
// FIXME more validation would be useful.
// validated and ready..
$this->startTransaction();
$oUser =& $this->oUser;
// FIXME this almost certainly has side-effects. do we _really_ want
$oUser->setPassword(md5($password)); //
$res = $oUser->update();
//$res = $oUser->doLimitedUpdate(); // ignores a fix blacklist of items.
if (PEAR::isError($res) || ($res == false)) {
$this->errorRedirectoToMain(_kt('Failed to update user.'));
}
$this->commitTransaction();
$this->successRedirectToMain(_kt('Your password has been changed.'));
}
function do_updatePreferences() {
$aErrorOptions = array(
'redirect_to' => array('main'),
);
$oUser =& $this->oUser;
$name = $this->oValidator->validateString(KTUtil::arrayGet($_REQUEST, 'name'),
KTUtil::meldOptions($aErrorOptions, array('message' => _kt('You must specify your name.'))));
$email_address = KTUtil::arrayGet($_REQUEST, 'email_address');
if(strlen(trim($email_address))) {
$email_address = $this->oValidator->validateEmailAddress(
$email_address,
KTUtil::meldOptions($aErrorOptions,
array('message' => _kt('Invalid email address.')))
);
}
$email_notifications = KTUtil::arrayGet($_REQUEST, 'email_notifications', false);
if ($email_notifications !== false) $email_notifications = true;
$mobile_number = KTUtil::arrayGet($_REQUEST, 'mobile_number');
$this->startTransaction();
$oUser->setName($name);
$oUser->setEmail($email_address);
$oUser->setEmailNotification($email_notifications);
$oUser->setMobile($mobile_number);
// old system used the very evil store.php.
// here we need to _force_ a limited update of the object, via a db statement.
//
// $res = $oUser->update();
$res = $oUser->doLimitedUpdate(); // ignores a fix blacklist of items.
if (PEAR::isError($res) || ($res == false)) {
$this->errorRedirectoToMain(_kt('Failed to update your details.'));
}
$this->commitTransaction();
$this->successRedirectToMain(_kt('Your details have been updated.'));
}
}
$oDispatcher = new PreferencesDispatcher();
$oDispatcher->dispatch();
?>