-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathShowMsgBox.php
124 lines (117 loc) · 3.53 KB
/
ShowMsgBox.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
<?php
define('IN_MSG_CALL',true);
require("LowFunction.php");
//Flags
$SQLIntroFlag=false;
$UserAcceptFlag=false;
//Die output
$errormsg="Known Error";
//Post value
$uid=0;
$name="";
$skey="";
$room="";
if(SQLIntro())
{
$SQLIntroFlag=true;
//check user
if( isset($_GET['uid'])&&
isset($_GET['name'])&&
isset($_GET['skey'])&&
isset($_GET['room'])){
$uid=@$_GET['uid'];
$name=@$_GET['name'];
$skey=@$_GET['skey'];
$room=@$_GET['room'];$room=intval($room);
if(checkUid($uid)&&MakeSKey($name,$uid)==$skey&&checkRoomAcc($uid,$room)){
$UserAcceptFlag=true;
}
}
}
if(!$SQLIntroFlag)
{
//For Debug
echo mysql_error();
die ('error:SQL error');
}
if(!$UserAcceptFlag)
{
die ("error:User information error. Please login first!");
}
//All is ok ,get room data
//$sqldata=mysql_query("SELECT * FROM msgdata WHERE roomid=1 ORDER BY sid DESC");
$sqldata=mysql_query("SELECT * FROM msgdata WHERE roomid=1 ORDER BY sid DESC LIMIT 20");
if(!$sqldata){
die("<p>存取被拒</p>");
}
?>
<!DOCTYPE html>
<head>
<meta charset='utf-8'>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js"></script>
<link rel="stylesheet" href="msgstyle.css">
</head>
<body onload="location.href='#ButtonFlag'" class='mnbdy'>
<table border="0" cellpadding="2" cellspacing="0" width="100%" class="hbtbl" id="tab">
<tbody>
<?php
$output="";
$lastsid=-1;
if($sqldata!=false)
{
while($row = mysql_fetch_array($sqldata))
{
if($row['sid']>$lastsid){
$lastsid=$row['sid'];
}
$LineData="<tr><td>";
$LineData=$LineData."<div class='dtxt'>".$row['timestamp']."</div>".
"<a href='http://forum.tfcis.org/home.php?mod=space&uid=$row[userid]' target='_BLANK'><b>".htmlspecialchars($row["username"])."</b></a>: ".nl2br(htmlspecialchars($row["content"]));
$LineData=$LineData."</td></tr>";
$output=$LineData.$output;
}
echo $output;
}
?>
</tbody>
</table>
<a name="ButtonFlag"></a>
<script>
var lastsid=<?php echo $lastsid; ?>;
var uid=<?php echo $uid;?>;
var uname=<?php $name=htmlspecialchars($name);echo"'$name'"; ?>;
var skey=<?php $skey=htmlspecialchars($skey);echo"'$skey'"; ?>;
var roomid=<?php echo $room;?>;
function addmsg(element, index, array){
lastsid=Math.max(lastsid,element.sid);
html="<div class='dtxt'>"+element.timestamp+"</div><a href='http://forum.tfcis.org/home.php?mod=space&uid="+element.userid+"' target='_BLANK'><b>"+element.username+"</b></a>: "+element.content;
//alert(html);
//insert
var trnum = document.getElementById("tab").rows.length;
var Tr = document.getElementById("tab").insertRow(trnum);
Td = Tr.insertCell(Tr.cells.length);
Td.innerHTML=html;
//alert(element.sid);
}
function update(){
var postdata={uid:uid,name:uname,skey:skey,room:roomid,lastSid:lastsid};
$.ajax({
url:"UpdateMsg.php",
type: "POST",
data: postdata,
dataType: "json",
timeout: 600000,
success : function(res){
//alert(res.status);
res.info.data.forEach(addmsg);
location.href='#ButtonFlag';
update();
},
error:function(x,t,m){
update();
}
});
}
update();
</script>
</body>