From 71b74b0fced53d87ca25508971d9699be6371390 Mon Sep 17 00:00:00 2001 From: Michael Save Date: Sat, 7 Jan 2012 12:31:59 +1100 Subject: [PATCH] "mark all as read" button in PM inbox --- mod.php | 46 +++++++++++++++++++++++++++------------------- 1 file changed, 27 insertions(+), 19 deletions(-) diff --git a/mod.php b/mod.php index 71053d23..a2dc5a42 100644 --- a/mod.php +++ b/mod.php @@ -87,7 +87,6 @@ if(hasPermission($config['mod']['noticeboard'])) { if(!$config['cache']['enabled'] || !($fieldset['Noticeboard'] = cache::get('noticeboard_preview'))) { - $query = prepare("SELECT `noticeboard`.*, `username` FROM `noticeboard` LEFT JOIN `mods` ON `mods`.`id` = `mod` ORDER BY `id` DESC LIMIT :limit"); $query->bindValue(':limit', $config['mod']['noticeboard_dashboard'], PDO::PARAM_INT); $query->execute() or error(db_error($query)); @@ -115,27 +114,26 @@ if(!empty($_body)) { $fieldset['Noticeboard'] .= '
  • '; } - - $fieldset['Noticeboard'] .= '' . _('View all entries') . '
  • '; - - $query = prepare("SELECT COUNT(*) AS `count` FROM `pms` WHERE `to` = :id AND `unread` = 1"); - $query->bindValue(':id', $mod['id']); - $query->execute() or error(db_error($query)); - $count = $query->fetch(); - $count = $count['count']; - - $fieldset['Noticeboard'] .= '
  • ' . _('PM Inbox') . - ($count > 0 - ? - ' (' . $count . ' unread)' - : '') . - '
  • '; - - $fieldset['Noticeboard'] .= '
  • ' . _('News') . '
  • '; - if($config['cache']['enabled']) cache::set('noticeboard_preview', $fieldset['Noticeboard']); } + + $fieldset['Noticeboard'] .= '' . _('View all entries') . ''; + + $query = prepare("SELECT COUNT(*) AS `count` FROM `pms` WHERE `to` = :id AND `unread` = 1"); + $query->bindValue(':id', $mod['id']); + $query->execute() or error(db_error($query)); + $count = $query->fetch(); + $count = $count['count']; + + $fieldset['Noticeboard'] .= '
  • ' . _('PM Inbox') . + ($count > 0 + ? + ' (' . $count . ' unread)' + : '') . + '
  • '; + + $fieldset['Noticeboard'] .= '
  • ' . _('News') . '
  • '; } @@ -709,6 +707,12 @@ 'mod'=>true ) ); + } elseif(preg_match('/^\/inbox\/readall$/', $query, $match)) { + $query = prepare("UPDATE `pms` SET `unread` = 0 WHERE `to` = :id"); + $query->bindValue(':id', $mod['id'], PDO::PARAM_INT); + $query->execute() or error(db_error($query)); + + header('Location: ?/inbox', true, $config['redirect_http']); } elseif(preg_match('/^\/inbox$/', $query, $match)) { $query = prepare("SELECT `unread`,`pms`.`id`, `time`, `sender`, `to`, `message`, `username` FROM `pms` LEFT JOIN `mods` ON `mods`.`id` = `sender` WHERE `to` = :mod ORDER BY `unread` DESC, `time` DESC"); $query->bindValue(':mod', $mod['id'], PDO::PARAM_INT); @@ -732,6 +736,10 @@ $unread_pms++; } $body .= ''; + + if($unread_pms) { + $body = '

    (Mark all as read)

    ' . $body; + } }