Ejemplo n.º 1
0
 function handler_reminder($page, $reminder_name = null, $action = null)
 {
     require_once 'reminder.inc.php';
     $user = S::user();
     // If no reminder name was passed, or if we don't know that reminder name,
     // just drop the request.
     if (!$reminder_name || !($reminder = Reminder::GetByName($user, $reminder_name))) {
         return PL_NOT_FOUND;
     }
     // Otherwise, the request is dispatched, and a new reminder, if any, is
     // displayed.
     $reminder->HandleAction($action);
     $previous_reminder = $reminder->title();
     if ($new_reminder = Reminder::GetCandidateReminder($user)) {
         $new_reminder->DisplayStandalone($page, $previous_reminder);
     } else {
         $reminder->NotifiesAction($page);
     }
 }
Ejemplo n.º 2
0
 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,\n                                     p.x, p.y, p.attach IS NOT NULL AS img, FIND_IN_SET('wiki', e.flags) AS wiki,\n                                     FIND_IN_SET('important', e.flags) AS important,\n                                     e.creation_date > DATE_SUB(CURDATE(), INTERVAL 2 DAY) AS news,\n                                     e.expiration < DATE_ADD(CURDATE(), INTERVAL 2 DAY) AS end,\n                                     ev.uid IS NULL AS nonlu, e.promo_min, e.promo_max\n                               FROM  announces       AS e\n                          LEFT JOIN  announce_photos AS p  ON (e.id = p.eid)\n                          LEFT JOIN  announce_read   AS ev ON (e.id = ev.evt_id AND ev.uid = {?})\n                              WHERE  FIND_IN_SET('valide', e.flags) AND expiration >= NOW()\n                           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);
 }