<?php
include 'checkUser.php';
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<!-- TemplateBeginEditable name="doctitle" -->
<title>无标题文档</title>
<style>
#chatContent{
width:500px;
height:300px;
background-color:#FFFF99;
text-align:left;
overflow:scroll;
}
table{
margin:auto auto;
background-color:#999999;
}
td,tr{
border:#CC0000 1px solid;
text-align:center;
}
#send_btn{
width:65px;
height:65px;
color:#0000FF;
}
#sp{font-size:14px;}
</style>
<script language="javascript" type="text/javascript" src="include/ajaxUtil.js"></script>
<script language="javascript" type="text/javascript" src="include/fckeditorUtil.js"></script>
<script language="javascript" type="text/javascript">
//发送用户说的内容
function sendMsg(){
var url="sendMsg.php";
var content=getEditorHtmlContents("content",true);
var params="nr="+encodeURI(content)+"&lis="+encodeURI($$('onlineuser').value)+"&name="+"<?php echo $_SESSION["username"];?>";
get(url,params,processSendMsg);
}
function processSendMsg(xhr){
if(xhr.responseText){
SetEditorContents("content","");
}else{
alert("发送失败!");
}
}
var maxid=0;
//获取内容,并且显示出来
function getContent(){
var url="getContent.php";
var params="maxid="+maxid;
get(url,params,processGetContent);
}
function processGetContent(xhr){
//把json格式的字符串转化为对象
var obj=eval("("+xhr.responseText+")");
//取出所有的聊天信息
var rows=obj.Msgs;
//取出所用用户信息
var users=obj.Users;
//--------------------显示在线用户---------------------
//获取在线用户的select的对象
var sel=$$("onlineuser");
//清空在线上次查询在线信息
sel.options.length=0;
for(var m=0;m<users.length;m++){
//产生一个选项
var op=new Option(users[m].username+"@"+users[m].theip,users[m].id);
//把选项添加到在线用户列表中
sel.options.add(op);
}
//-----------------------显示聊天信息------------
var conStr=$$("chatContent").innerHTML;
//var conStr="";
for(var i=0;i<rows.length;i++){
conStr+=" "+rows[i].speaker+"["+rows[i].theip+"] 在 "+rows[i].create_time+" 说:</span><br> "+rows[i].content+"<br>";
maxid=parseInt(rows[i].id);
}
//把最大的id值赋值给maxid
//maxid=rows[i].id;
//将内容显示到div中
$$("chatContent").innerHTML=conStr;
//$$("chatContent").scrollTop=$$("chatContent").scrollHeight;
}
setInterval("getContent()",2000);
</script>
</head>
<body>
<table width="300" border="1">
<caption>ajax+json+php+js+dom+mysql实现聊天室<br></caption>
<tr>
<td>欢迎 <?php echo $_SESSION['username']; ?>,进入聊天室</td>
<td>在线用户列表</td>
</tr>
<tr>
<td><div id="chatContent"></div></td>
<td><select id="onlineuser" size="20" style="width:150px;">
<option>所有人</option>
</select>
</td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td><?php
//引用FCKeditor.php这个文件,基本的类和数据结构都在这里
include ("fckeditor/fckeditor.php");
//创建FCKeditor对象的实例。myFCKeditor即提交后,接收数据页面 _POST['myFCKeditor']使用
$FCKeditor = new FCKeditor("content");
//FCKeditor所在的位置,这里它的位置就是'FCKeditor' 文件夹
$FCKeditor -> BasePath='./fckeditor/';
//工具按钮设置
$FCKeditor -> ToolbarSet="ChatEditor";
//设置它的宽度
$FCKeditor -> Width='500px';
//设置它的高度
$FCKeditor -> Height='120px';
$FCKeditor ->InstanceName ="content";
//生成
$FCKeditor -> Create();
?></td>
<td><input type="button" value="发送" id="send_btn" οnclick="sendMsg()" /></td>
</tr>
</table>
</body>
</html>
include 'checkUser.php';
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<!-- TemplateBeginEditable name="doctitle" -->
<title>无标题文档</title>
<style>
#chatContent{
width:500px;
height:300px;
background-color:#FFFF99;
text-align:left;
overflow:scroll;
}
table{
margin:auto auto;
background-color:#999999;
}
td,tr{
border:#CC0000 1px solid;
text-align:center;
}
#send_btn{
width:65px;
height:65px;
color:#0000FF;
}
#sp{font-size:14px;}
</style>
<script language="javascript" type="text/javascript" src="include/ajaxUtil.js"></script>
<script language="javascript" type="text/javascript" src="include/fckeditorUtil.js"></script>
<script language="javascript" type="text/javascript">
//发送用户说的内容
function sendMsg(){
var url="sendMsg.php";
var content=getEditorHtmlContents("content",true);
var params="nr="+encodeURI(content)+"&lis="+encodeURI($$('onlineuser').value)+"&name="+"<?php echo $_SESSION["username"];?>";
get(url,params,processSendMsg);
}
function processSendMsg(xhr){
if(xhr.responseText){
SetEditorContents("content","");
}else{
alert("发送失败!");
}
}
var maxid=0;
//获取内容,并且显示出来
function getContent(){
var url="getContent.php";
var params="maxid="+maxid;
get(url,params,processGetContent);
}
function processGetContent(xhr){
//把json格式的字符串转化为对象
var obj=eval("("+xhr.responseText+")");
//取出所有的聊天信息
var rows=obj.Msgs;
//取出所用用户信息
var users=obj.Users;
//--------------------显示在线用户---------------------
//获取在线用户的select的对象
var sel=$$("onlineuser");
//清空在线上次查询在线信息
sel.options.length=0;
for(var m=0;m<users.length;m++){
//产生一个选项
var op=new Option(users[m].username+"@"+users[m].theip,users[m].id);
//把选项添加到在线用户列表中
sel.options.add(op);
}
//-----------------------显示聊天信息------------
var conStr=$$("chatContent").innerHTML;
//var conStr="";
for(var i=0;i<rows.length;i++){
conStr+=" "+rows[i].speaker+"["+rows[i].theip+"] 在 "+rows[i].create_time+" 说:</span><br> "+rows[i].content+"<br>";
maxid=parseInt(rows[i].id);
}
//把最大的id值赋值给maxid
//maxid=rows[i].id;
//将内容显示到div中
$$("chatContent").innerHTML=conStr;
//$$("chatContent").scrollTop=$$("chatContent").scrollHeight;
}
setInterval("getContent()",2000);
</script>
</head>
<body>
<table width="300" border="1">
<caption>ajax+json+php+js+dom+mysql实现聊天室<br></caption>
<tr>
<td>欢迎 <?php echo $_SESSION['username']; ?>,进入聊天室</td>
<td>在线用户列表</td>
</tr>
<tr>
<td><div id="chatContent"></div></td>
<td><select id="onlineuser" size="20" style="width:150px;">
<option>所有人</option>
</select>
</td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td><?php
//引用FCKeditor.php这个文件,基本的类和数据结构都在这里
include ("fckeditor/fckeditor.php");
//创建FCKeditor对象的实例。myFCKeditor即提交后,接收数据页面 _POST['myFCKeditor']使用
$FCKeditor = new FCKeditor("content");
//FCKeditor所在的位置,这里它的位置就是'FCKeditor' 文件夹
$FCKeditor -> BasePath='./fckeditor/';
//工具按钮设置
$FCKeditor -> ToolbarSet="ChatEditor";
//设置它的宽度
$FCKeditor -> Width='500px';
//设置它的高度
$FCKeditor -> Height='120px';
$FCKeditor ->InstanceName ="content";
//生成
$FCKeditor -> Create();
?></td>
<td><input type="button" value="发送" id="send_btn" οnclick="sendMsg()" /></td>
</tr>
</table>
</body>
</html>