aBreadcrumbs = array( array('action' => 'preferences', 'name' => _('Preferences')), ); return parent::KTStandardDispatcher(); } function do_main() { $this->oPage->setBreadcrumbDetails(_("Your Preferences")); $this->oPage->title = _("Dashboard"); $oUser =& $this->oUser; $aOptions = array('autocomplete' => false); $edit_fields = array(); $edit_fields[] = new KTStringWidget(_('Name'),_('Your full name. This is shown in reports and listings. e.g. John Smith'), 'name', $oUser->getName(), $this->oPage, true, null, null, $aOptions); $edit_fields[] = new KTStringWidget(_('Email Address'),_('Your email address. Notifications and alerts are mailed to this address if email notifications is set below. e.g. jsmith@acme.com'), 'email_address', $oUser->getEmail(), $this->oPage, false, null, null, $aOptions); $edit_fields[] = new KTCheckboxWidget(_('Email Notifications'),_('If this is specified then the you will receive certain notifications. If it is not set, then you will only see notifications on the Dashboard'), 'email_notifications', $oUser->getEmailNotification(), $this->oPage, false, null, null, $aOptions); $edit_fields[] = new KTStringWidget(_('Mobile Number'), _('Your mobile phone number. If the system is configured to send notifications to cellphones, then this number will be sent an SMS with notifications. e.g. +27 99 999 9999'), 'mobile_number', $oUser->getMobile(), $this->oPage, false, null, null, $aOptions); $oTemplating = new KTTemplating; $oTemplate = $oTemplating->loadTemplate("ktcore/principals/preferences"); $aTemplateData = array( "context" => $this, 'edit_fields' => $edit_fields, ); return $oTemplate->render($aTemplateData); } function do_setPassword() { $this->oPage->setBreadcrumbDetails(_("Your Password")); $this->oPage->title = _("Dashboard"); $oUser =& $this->oUser; $aOptions = array('autocomplete' => false); $edit_fields = array(); $edit_fields[] = new KTPasswordWidget(_('Password'), _('Specify your new password.'), 'password', null, $this->oPage, true, null, null, $aOptions); $edit_fields[] = new KTPasswordWidget(_('Confirm Password'), _('Confirm the password specified above.'), 'confirm_password', null, $this->oPage, true, null, null, $aOptions); $oTemplating = new KTTemplating; $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", _("You must specify a password.")); } else if ($password !== $confirm_password) { $this->errorRedirectTo("setPassword", _("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(_("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(_('Failed to update user.')); } $this->commitTransaction(); $this->successRedirectToMain(_('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' => _('You must specify your name.')))); $email_address = $this->oValidator->validateEmailAddress(KTUtil::arrayGet($_REQUEST, 'email_address'), $aErrorOptions); $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(_('Failed to update your details.')); } $this->commitTransaction(); $this->successRedirectToMain(_('Your details have been updated.')); } } $oDispatcher = new PreferencesDispatcher(); $oDispatcher->dispatch(); ?>