-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathautomatic.php
66 lines (54 loc) · 1.92 KB
/
automatic.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<?php
/**
* Created by PhpStorm.
* User: Shalitha Suranga
* Date: 4/20/2017
* Time: 6:51 AM
*/
require("includes/config.php");
header("Access-Control-Allow-Origin: *");
header('Content-Type: application/json');
if(isset($_GET["token"])){
if($_GET["token"]==AP_TOKEN){
$lecturer_id=$db->real_escape_string($_GET["lecturer"]);
$notif=$db->real_escape_string($_GET["notif"]);
/* -------- get student info --------- */
$result=$db->query("
SELECT
sm_lecturer.dept_id AS department,
sm_department.fac_id AS faculty
FROM
sm_lecturer
INNER JOIN sm_department ON sm_department.id=sm_lecturer.dept_id
WHERE sm_lecturer.id='$lecturer_id' LIMIT 1
");
$node=$result->fetch_assoc();
$dep_id=$node["department"];
$fac_id=$node["faculty"];
//var_dump($node);
$result=$db->query("SELECT COUNT(id) AS messagecount FROM sm_message WHERE to_user='$lecturer_id' AND is_open=0;");
$node=$result->fetch_assoc();
$messagecount=$node["messagecount"];
$result=$db->query("SELECT * FROM sm_notification WHERE type IN(4,5,6) AND id>'$notif' ORDER BY id DESC;");
$notifications=array();
while($node=$result->fetch_assoc()){
/* ------- filtering ------ */
if($node["type"]=="4") {
$notifications[] = $node;
}
else if($node["type"]=="5") {
if($node["type_id"]==$fac_id)
$notifications[] = $node;
}
else if($node["type"]=="6") {
if($node["type_id"]==$dep_id)
$notifications[] = $node;
}
}
echo(json_encode(array(
"messagecount" => $messagecount,
"notificationcount" => sizeof($notifications),
"notifications" => $notifications
)));
}
}