-
Notifications
You must be signed in to change notification settings - Fork 0
/
notifylist.php
52 lines (45 loc) · 2.06 KB
/
notifylist.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<?php
require_once('./config/require.php');
if (1 != $authorized) { authorize(); }
// çàïðîñ ñïèñêà ïîëüçîâàòåëåé
if (1 == $is_admin):
$r = $mysqli_->query('select id as userid, nickname from `user` order by nickname');
if (!$r) { fail(_error_mysql_query_error_code); }
$users = array();
while($f = $r->fetch_object()) { array_push($users, $f); }
data('users', $users);
$r->close();
endif; // êîíåö çàïðîñà ñïèñêà ïîëüçîâàòåëåé
// çàïðîñ ñïèñêà êîìàíä
if (1 == $is_admin):
$r = $mysqli_->query('select teamid, teamname from `teams` order by teamname');
if (!$r) { fail(_error_mysql_query_error_code); }
$teams = array();
while($f = $r->fetch_object()) { array_push($teams, $f); }
data('teams', $teams);
$r->close();
endif; // êîíåö çàïðîñà ñïèñêà êîìàíä
$rowcount = 0;
$pagesize = 10;
if (!isset($page)) { $page = 1; };
$first = ($page-1)*$pagesize;
$q = $mysqli_->prepare('SELECT M.messageid, M.date, M.header, M.message, (SELECT count(*) FROM `reads` R WHERE R.messageid=M.messageid and R.userid=?) as `read` FROM `messages` M WHERE M.kind=2 and (M.touser=? and M.touser<>-1 or M.toteam=? and M.toteam<>-1 or M.touser=-1 and M.toteam=-1) and M.date > (select U.regdate from `user` U where U.id=?) ORDER BY M.messageid DESC');
$q->bind_param('iiii', $curuserid, $curuserid, $curteamid, $curuserid);
$q->bind_result($notifyid, $date, $header, $notify, $read);
if (!$q->execute()) { fail(_error_mysql_query_error_code); } // auto-close query
$notifies = array(); $index = 0; $rowcount = 0;
while ($q->fetch()) {
$index++; $rowcount++;
$f = array();
$f['notifyid'] = $notifyid; $f['date'] = $date; $f['header'] = $header; $f['notify'] = $notify; $f['read'] = $read;
if ($index > $first && $index < $first + $pagesize + 1) { array_push($notifies, (object) $f); }
}
$pagecount = $rowcount / $pagesize;
if ($rowcount % $pagesize != 0) { $pagecount += 1; }
$q->close();
if (isset($code)) { data('message', $messages[$code]); }
data('notifies', $notifies);
data('pagecount', $pagecount);
data('page', $page);
template('notifylist', $data);
?>