+ function handler_ev($page, $action = 'list', $eid = null, $pound = null)
+ {
+ $page->changeTpl('events/index.tpl');
+
+ $user = S::user();
+
+ /** XXX: Tips and reminder only for user with 'email' permission.
+ * We can do better in the future by storing a userfilter
+ * with the tip/reminder.
+ */
+ if ($user->checkPerms(User::PERM_MAIL)) {
+ $page->assign('tips', $this->get_tips());
+
+ }
+
+ // Adds a reminder onebox to the page.
+ require_once 'reminder.inc.php';
+ if (($reminder = Reminder::GetCandidateReminder($user))) {
+ $reminder->Prepare($page);
+ }
+
+ // Wishes "Happy birthday" when required
+ $profile = $user->profile();
+ if (!is_null($profile)) {
+ if ($profile->next_birthday == date('Y-m-d')) {
+ $birthyear = (int)date('Y', strtotime($profile->birthdate));
+ $curyear = (int)date('Y');
+ $page->assign('birthday', $curyear - $birthyear);
+ }
+ }
+
+ // Direct link to the RSS feed, when available.
+ if (S::hasAuthToken()) {
+ $page->setRssLink('Polytechnique.org :: News',
+ '/rss/' . S::v('hruid') . '/' . S::user()->token . '/rss.xml');
+ }
+
+ // Hide the read event, and reload the page to get to the next event.
+ if ($action == 'read' && $eid) {
+ XDB::execute('DELETE ev.*
+ FROM announce_read AS ev
+ INNER JOIN announces AS e ON e.id = ev.evt_id
+ WHERE expiration < NOW()');
+ XDB::execute('INSERT IGNORE INTO announce_read (evt_id, uid)
+ VALUES ({?}, {?})',
+ $eid, S::v('uid'));
+ pl_redirect('events#'.$pound);
+ }
+
+ // Unhide the requested event, and reload the page to display it.
+ if ($action == 'unread' && $eid) {
+ XDB::execute('DELETE FROM announce_read
+ WHERE evt_id = {?} AND uid = {?}',
+ $eid, S::v('uid'));
+ pl_redirect('events#newsid'.$eid);
+ }
+
+ // Fetch the events to display, along with their metadata.
+ $array = array();
+ $it = XDB::iterator("SELECT e.id, e.titre, e.texte, e.post_id, e.uid,
+ p.x, p.y, p.attach IS NOT NULL AS img, FIND_IN_SET('wiki', e.flags) AS wiki,
+ FIND_IN_SET('important', e.flags) AS important,
+ e.creation_date > DATE_SUB(CURDATE(), INTERVAL 2 DAY) AS news,
+ e.expiration < DATE_ADD(CURDATE(), INTERVAL 2 DAY) AS end,
+ ev.uid IS NULL AS nonlu, e.promo_min, e.promo_max
+ FROM announces AS e
+ LEFT JOIN announce_photos AS p ON (e.id = p.eid)
+ LEFT JOIN announce_read AS ev ON (e.id = ev.evt_id AND ev.uid = {?})
+ WHERE FIND_IN_SET('valide', e.flags) AND expiration >= NOW()
+ ORDER BY important DESC, news DESC, end DESC, e.expiration, e.creation_date DESC",
+ S::i('uid'));
+ $cats = array('important', 'news', 'end', 'body');
+
+ $this->load('feed.inc.php');
+ $user = S::user();
+ $body = EventFeed::nextEvent($it, $user);
+ foreach ($cats as $cat) {
+ $data = array();
+ if (!$body) {
+ continue;
+ }
+ do {
+ if ($cat == 'body' || $body[$cat]) {
+ $data[] = $body;
+ } else {
+ break;
+ }
+ $body = EventFeed::nextEvent($it, $user);
+ } while ($body);
+ if (!empty($data)) {
+ $array[$cat] = $data;
+ }
+ }
+
+ $page->assign_by_ref('events', $array);
+ }
+
+ function handler_photo($page, $eid = null, $valid = null)
+ {
+ if ($eid && $eid != 'valid') {
+ $res = XDB::query("SELECT * FROM announce_photos WHERE eid = {?}", $eid);
+ if ($res->numRows()) {
+ $photo = $res->fetchOneAssoc();
+ pl_cached_dynamic_content_headers("image/" . $photo['attachmime']);
+ echo $photo['attach'];
+ exit;
+ }
+ } elseif ($eid == 'valid') {
+ $valid = Validate::get_request_by_id($valid);
+ if ($valid && $valid->img) {
+ pl_cached_dynamic_content_headers("image/" . $valid->imgtype);
+ echo $valid->img;
+ exit;
+ }
+ } else {
+ $upload = new PlUpload(S::user()->login(), 'event');
+ if ($upload->exists() && $upload->isType('image')) {
+ pl_cached_dynamic_content_headers($upload->contentType());
+ echo $upload->getContents();
+ exit;
+ }
+ }
+ global $globals;
+ pl_cached_dynamic_content_headers("image/png");
+ echo file_get_contents($globals->spoolroot . '/htdocs/images/logo.png');
+ exit;
+ }
+
+ function handler_rss(PlPage $page, PlUser $user)
+ {
+ $this->load('feed.inc.php');
+ $feed = new EventFeed();
+ return $feed->run($page, $user);
+ }
+
+ function handler_preview($page)
+ {
+ $page->changeTpl('events/preview.tpl', NO_SKIN);
+ $texte = Get::v('texte');
+ if (!is_utf8($texte)) {
+ $texte = utf8_encode($texte);
+ }
+ $titre = Get::v('titre');
+ if (!is_utf8($titre)) {
+ $titre = utf8_encode($titre);
+ }
+ $page->assign('texte', $texte);
+ $page->assign('titre', $titre);
+ pl_content_headers("text/html");
+ }
+
+ function handler_ev_submit($page)
+ {
+ $page->changeTpl('events/submit.tpl');
+
+ $wp = new PlWikiPage('Xorg.Annonce');
+ $wp->buildCache();
+
+ $titre = Post::v('titre');
+ $texte = Post::v('texte');
+ $promo_min = Post::i('promo_min');
+ $promo_max = Post::i('promo_max');
+ $expiration = Post::i('expiration');
+ $valid_mesg = Post::v('valid_mesg');
+ $action = Post::v('action');
+ $upload = new PlUpload(S::user()->login(), 'event');
+ $this->upload_image($page, $upload);
+
+ if (($promo_min > $promo_max && $promo_max != 0)||
+ ($promo_min != 0 && ($promo_min <= 1900 || $promo_min >= 2020)) ||
+ ($promo_max != 0 && ($promo_max <= 1900 || $promo_max >= 2020)))
+ {
+ $page->trigError("L'intervalle de promotions n'est pas valide");
+ $action = null;
+ }