Advertisement
Guest User

UserSpice 4.3 Dev - getNotifications.php

a guest
Sep 1st, 2017
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.88 KB | None | 0 0
  1. <?php
  2. /*
  3. UserSpice 4
  4. An Open Source PHP User Management System
  5. by the UserSpice Team at http://UserSpice.com
  6.  
  7. Feb 02 2016 - Ported US3.2.1 top-nav
  8.  
  9. This program is free software: you can redistribute it and/or modify
  10. it under the terms of the GNU General Public License as published by
  11. the Free Software Foundation, either version 3 of the License, or
  12. (at your option) any later version.
  13.  
  14. This program is distributed in the hope that it will be useful,
  15. but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  17. GNU General Public License for more details.
  18.  
  19. You should have received a copy of the GNU General Public License
  20. along with this program.  If not, see <http://www.gnu.org/licenses/>.
  21. */
  22.  
  23. require_once '../init.php';
  24. $db = DB::getInstance();
  25. $response = $html = '';
  26.  
  27. if (isset($user) && $user->isLoggedIn()) {
  28.     $user_id = $user->data()->id;
  29.     $notifications = new Notification($user_id);
  30.     if ($notifications->getCount() > 0) {
  31.         $html = '<ul>';
  32.         foreach ($notifications->getNotifications() as $notif) {
  33.             $html .= '<li>';
  34.             if ($notif->is_read == 0) $html .= '<span class="badge badge-notif">NEW</span> ';
  35.             $html .= $notif->message;
  36.             $html .='&nbsp;&nbsp;<span class="small">('.date('D M j, g:i a', strtotime($notif->date_created)).')</span></li>';
  37.         }
  38.         $html .= '</ul>';
  39.     }
  40.     else {
  41.         $html = '<div class="text-center">You have no notifications at this time.</div>';
  42.     }
  43.     $notifications->setReadAll();
  44.     if ($notifications->getError() != '') $html = $notifications->getError();
  45. }
  46. else return false;
  47.  
  48. if (!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') {
  49.     header('Content-Type: application/json');
  50.     echo json_encode($html);
  51.     exit;
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement