Guest User

UserSpice 4.3 Dev - getNotifications.php

a guest
Sep 15th, 2017
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.68 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. This program is free software: you can redistribute it and/or modify
  8. it under the terms of the GNU General Public License as published by
  9. the Free Software Foundation, either version 3 of the License, or
  10. (at your option) any later version.
  11.  
  12. This program is distributed in the hope that it will be useful,
  13. but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15. GNU General Public License for more details.
  16.  
  17. You should have received a copy of the GNU General Public License
  18. along with this program.  If not, see <http://www.gnu.org/licenses/>.
  19. */
  20.  
  21. require_once '../init.php';
  22. $db = DB::getInstance();
  23. $response = $html = '';
  24.  
  25. if (isset($user) && $user->isLoggedIn()) {
  26.     $user_id = $user->data()->id;
  27.     if ($dayLimitQ = $db->query('SELECT notif_daylimit FROM settings', array())) $dayLimit = $dayLimitQ->results()[0]->notif_daylimit;
  28.     else $dayLimit = 7;
  29.     $notifications = new Notification($user_id, false, $dayLimit);
  30.     if ($notifications->getCount() > 0) {
  31.         $html = '<ul>';
  32.         $i = 1;
  33.         foreach ($notifications->getNotifications() as $notif) {
  34.             $html .= '<li class="notification-row" data-id="'.$i.'">';
  35.             if ($notif->is_read == 0) $html .= '<span class="badge badge-notif">NEW</span> ';
  36.             $html .= $notif->message;
  37.             $html .='&nbsp;&nbsp;<span class="small">('.time2str($notif->date_created).')</span></li>';
  38.             $i++;
  39.         }
  40.         $html .= '</ul>';
  41.         $totalPages = ceil(round($notifications->getCount() / 10));
  42.         if ($totalPages > 1) {
  43.             $html .= '<div class="text-center"><ul class="pagination" id="notif-pagination">';
  44.             if ($totalPages > 5) $html .= '<li class="first disabled"><a><<</a></li>';
  45.             for ($i=1; $i<=$totalPages; $i++) {
  46.                 $active = '';
  47.                 if ($i == 1) $active = ' class="active"';
  48.                 $html .= '<li '.$active.'><a>'.$i.'</a></li>';
  49.             }
  50.             if ($totalPages > 5) $html .= '<li class="last"><a>>></a></li>';
  51.             $html .= '</ul></div>';
  52.         }
  53.     }
  54.     else {
  55.         $html = '<div class="text-center">You have no notifications at this time.</div>';
  56.     }
  57.     $notifications->setReadAll();
  58.     if ($notifications->getError() != '') $html = $notifications->getError();
  59. }
  60. else return false;
  61.  
  62. if (!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') {
  63.     header('Content-Type: application/json');
  64.     echo json_encode($html);
  65.     exit;
  66. }
Advertisement
Add Comment
Please, Sign In to add comment