public function __construct($userId = null) { parent::__construct('formUpdateProfile', 'Update profile'); if ($userId == null) { $user = Session::getUser(); } else { if ($userId != Session::getUser()->getId()) { requirePrivOrRedirect('EDIT_USERS', 'index.php'); $user = User::getUserById($userId); } else { $user = Session::getUser(); } } $this->user = $user; $this->addSection('Bio'); $this->addElement(new ElementHidden('action', null, 'edit')); $this->addElement(new ElementHidden('user', null, $user->getId())); $this->addElement(new ElementEmail('email', 'E-Mail Address', $user->getData('email'))); $elementRealName = $this->addElement(new ElementAlphaNumeric('realName', 'Real Name', $user->getData('real_name'))); $elementRealName->setMinMaxLengths(0, 32); $elementLocation = $this->addElement(new ElementAlphaNumeric('location', 'Location', $user->getData('location'))); $elementLocation->setMinMaxLengths(0, 64); $this->addElement(new ElementInputRegex('mobileNo', 'Mobile No.', $user->getData('mobileNo')))->setMinMaxLengths(0, 16); $this->getElement('mobileNo')->setPattern('#^[\\d ]+$#', 'numbers and spaces'); $this->getElement('mobileNo')->setMinMaxLengths(11, 15); $this->addSection('Preferences'); $this->addElement(new ElementCheckbox('mailingList', 'Mailing list', $user->getData('mailingList'))); $now = date_create(); $elementDateFormat = $this->addElement(new ElementSelect('dateFormat', 'Date format', $user->getData('dateFormat'))); $elementDateFormat->addOption('ISO date format (recommended): ' . formatDt($now, 'Y-m-d'), 'Y-m-d H:i'); $elementDateFormat->addOption('UK, numeric date format: ' . formatDt($now, 'd-m-Y'), 'd-m-Y'); $elementDateFormat->addOption('UK, long date format: ' . formatDt($now, 'jS M Y'), 'jS M Y'); $elementDateFormat->addOption('USA, numeric date format: ' . formatDt($now, 'm-d-Y'), 'm-d-Y'); $elementDateFormat->addOption('Opus date format: ' . formatDtOpus($now), 'opus'); $this->addSection('Change password'); if (Session::getUser()->getUsername() == $user->getUsername()) { $this->addElement(new ElementPassword('passwordCurrent', 'Current password', null, 'Fill this field out if you would like to change your password.')); $this->getElement('passwordCurrent')->setOptional(true); } $this->addElement(new ElementPassword('password1', 'New Password', null))->setOptional(true); $this->addElement(new ElementPassword('password2', 'New Password (confirm)', null))->setOptional(true); if (Session::getUser()->hasPriv('EDIT_BANS')) { $this->addSection('Banning and admin stuff'); $this->addElement(new ElementInput('bannedReason', 'Banned reason', $user->getData('bannedReason'), 'Enter a reason to ban this user. Leave it blank to keep the user active.')); $this->getElement('bannedReason')->addSuggestedValue('', 'Clear ban'); $this->getElement('bannedReason')->setMinMaxLengths(0, 256); $this->addElement(new ElementCheckbox('emailFlagged', 'Email flagged?', $user->getData('emailFlagged'))); } $this->addButtons(Form::BTN_SUBMIT); }
function formatDt(DateTime $date, $format = null) { if (empty($format)) { if (Session::isLoggedIn()) { $dateFormat = Session::getUser()->getData('dateFormat'); } else { $dateFormat = 'Y-m-d H:i'; } } else { $dateFormat = $format; } if ($dateFormat == "opus") { return formatDtOpus($date); } $dateTime = empty($dateTime) ? 'Y-m-d H:i' : $dateFormat; return $date->format($dateFormat); }