forked from pus2inbo2ts/mmubee-server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcomment.php
executable file
·170 lines (141 loc) · 3.69 KB
/
comment.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
<?php
include 'config.php';
//sleep(9);
$mysql = db();
verify($mysql);
$mysql->set_charset('utf8mb4');
//$content = htmlentities($_POST['content'], ENT_HTML5);
$content = $_POST['content'];
$plane_id = $_POST['plane_id'];
$comment_id = @$_POST['comment_id'];
/*
//check if this plane not exists
$stmt = $mysql->prepare("SELECT EXISTS(SELECT * FROM plane WHERE id = ?);");
if ($stmt === false) {
err('mysql', $mysql->error, true);
}
$stmt->bind_param('s', $plane_id);
$stmt->bind_result($exists);
$stmt->execute();
$stmt->fetch();
$stmt->close();
if($exists == 0){
err('Error', "This post has been deleted", true);
}
*/
$detail = array('plane'=>1, 'mmls'=>0, 'center'=>0, 'news'=>0);
if($comment_id == '' || isset($comment_id) == false){
$comment_id = NULL;
}
//var_dump($comment_id);
$stmt = $mysql->prepare("INSERT INTO `comment`(content, sid, plane_id, comment_id) VALUES(?, ?, ?, ?)");
if ($stmt === false) {
err('mysql', $mysql->error, true);
}
$stmt->bind_param('ssss',$content, $sid, $plane_id, $comment_id);
$result = $stmt->execute();
if($result){
//ok();
ignore();
}else{
//err('mysql', $mysql->error);
err('Error', "This post has been deleted", true);
}
//insert notice
notice($mysql, $plane_id, $mysql->insert_id, 1);
/*select details for push notification*/
//whos plane? get token
$stmt = $mysql->prepare("SELECT s.sid, d.iostoken, d.androidtoken FROM `student` as s, `device` as d, `plane` as p WHERE p.sid = s.sid and p.sid = d.sid and p.id = ?;");
if ($stmt === false) {
err('mysql', $mysql->error, true);
}
$stmt->bind_param('s', $plane_id);
$stmt->bind_result($id, $itoken, $atoken);
$stmt->execute();
/*
$stmt->fetch();
if($itoken != ''){
$platform = 'iOS';
$token = array($itoken);
}else{
$platform = 'Android';
$token = array($atoken);
}
*/
$itokenArr = array();
$atokenArr = array();
while ($stmt->fetch()) {
if($itoken != ''){
$itokenArr[] = $itoken;
}else{
$atokenArr[] = $atoken;
}
}
$stmt->close();
//from who? get name
$stmt = $mysql->prepare("SELECT name from student where student.sid = ?;");
if ($stmt === false) {
err('mysql', $mysql->error, true);
}
$stmt->bind_param('s', $sid);
$stmt->bind_result($name);
$stmt->execute();
$stmt->fetch();
$stmt->close();
if($sid != $id){
if(!empty($atokenArr)){
// echo "ANDROID";
// print_r($atokenArr);
push($name." comments: ", $content, 1, $atokenArr, 'Android', $detail);
}
if(!empty($itokenArr)){
// echo "IOS";
//print_r($itokenArr);
push($name." comments: ", $content, 1, $itokenArr, 'iOS', $detail);
}
}
//push notification for replie
if($comment_id != NULL){
//whos comment? get token
$stmt = $mysql->prepare("SELECT s.sid, d.iostoken, d.androidtoken FROM `student` as s, `device` as d, `comment` as c WHERE c.sid = s.sid and c.sid = d.sid and c.id = ?;");
if ($stmt === false) {
err('mysql', $mysql->error, true);
}
$stmt->bind_param('s', $comment_id);
$stmt->bind_result($cid, $itoken, $atoken);
$stmt->execute();
/*
$stmt->fetch();
if($itoken != ''){
$platform = 'iOS';
$token = array($itoken);
}else{
$platform = 'Android';
$token = array($atoken);
}
*/
$itokenArr = array();
$atokenArr = array();
while ($stmt->fetch()) {
if($itoken != ''){
$itokenArr[] = $itoken;
}else{
$atokenArr[] = $atoken;
}
}
$stmt->close();
if($id != $cid){ //if plane's owner and this comment's owner are differnt people. (To avoid push twice when repliying plane's owner )
if(!empty($atokenArr)){
// echo "ANDROID";
// print_r($atokenArr);
push($name." replies: ", $content, 1, $atokenArr, 'Android', $detail);
}
if(!empty($itokenArr)){
// echo "IOS";
//print_r($itokenArr);
push($name." replies: ", $content, 1, $itokenArr, 'iOS', $detail);
}
}
}
$mysql->close();
?>