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); }
public function __construct($eventId) { parent::__construct('eventUpdate', 'Event update'); $event = Events::getById($eventId); $this->addElement(new ElementHidden('action', null, 'update')); $this->addElement(new ElementHidden('id', null, $event['id'])); $this->addSection('Basics'); $this->addElement(new ElementInput('name', 'Event name', $event['name'])); $this->addElement($this->getElementGalleries($event['gallery'])); $this->addElement(new ElementNumeric('totalSeats', 'Total seats', $event['totalSeats'])); $this->addElement(new ElementInput('comment', 'Comment', $event['comment'])); $this->addElement(new ElementCheckbox('published', 'Published', $event['published'])); $this->addSection('When and where?'); $this->addElement($this->getElementVenues($event['venueId'])); $this->addElement(new ElementDate('dateStart', 'Start', formatDt($event['start']))); $this->addElement(new ElementNumeric('duration', 'Duration', $event['duration'])); $this->addSection('Tickets'); $this->addElement($this->getElementSeatingplan($event['seatingPlan'])); $this->addElement(new ElementNumeric('priceInAdv', 'Price in advance', $event['priceInAdv'])); $this->addElement(new ElementNumeric('priceOnDoor', 'Price on door', $event['priceOnDoor'])); $this->addElement($this->getElementSignups($event['signups'])); $this->requireFields(array('name', 'totalSeats')); $this->addButtons(Form::BTN_SUBMIT); }
public static function getAllUpcommingEvents() { global $db; $sql = 'SELECT e.id, e.published, e.name, e.date, e.duration, v.name "venue" FROM events e, venues v WHERE e.venue = v.id AND date > curdate() ORDER BY date ASC '; $result = $db->query($sql); $result = $result->fetchAll(); foreach ($result as $k => $event) { // Calculate event ending time. $finish = date_create($event['date']); $finish->modify('+' . $event['duration'] . ' hours'); $result[$k]['date'] = formatDtString($result[$k]['date']); $result[$k]['finish'] = formatDt($finish); } return $result; }
function formatDtString($dateAsString, $format = null) { return formatDt(date_create($dateAsString), $format); }
break; case 'delete': if (!Session::hasPriv('NEWS_DELETE')) { throw new PermissionException(); } $id = intval($_REQUEST['id']); $sql = 'DELETE FROM news WHERE id = :id '; $stmt = $db->prepare($sql); $stmt->bindValue(':id', $id); $stmt->execute(); logAndRedirect('news.php', 'News deleted: ' . $id); break; default: require_once 'includes/widgets/header.php'; require_once 'includes/widgets/sidebar.php'; $news = new News(); $news->setCount(10); while ($article = $news->getNext()) { startBox(); echo '<p><span class = "subtle">Posted on ' . formatDt(new DateTime($article['date'])) . ' by <a href = "profile.php?id=' . $article['author'] . '">' . $article['username'] . '</a>.</span></p>'; echo htmlify($article['content']); if (Session::hasPriv('NEWS_DELETE')) { echo '<dl class = "subtle">'; echo '<dt><a href = "news.php?action=delete&id=' . $article['id'] . '">Delete</a></dt>'; echo '<dt><a href = "news.php?action=edit&id=' . $article['id'] . '">Edit</a></dt>'; echo '</dl>'; } stopBox(htmlify($article['title'], false)); } } require_once 'includes/widgets/footer.php';