<?php
require_once('../config/config.php');
require_once(CLASS_DIR.'dbClass.php');
require_once('datetime.php');
//echo date('D-m-Y H:i:s');
$userros = mysql_fetch_array(mysql_query("select * from `mychat_user` WHERE `id`!='".$_SESSION['userid']."'"));
if(isset($_GET['deleteid']) && ($_GET['deleteid']!='')){
     mysql_query("UPDATE `mychat` SET `deletedby`='".$_SESSION['userid']."' WHERE  id= '".$_GET['deleteid']."'");
}else if(isset($_GET['str']) && ($_GET['str']!='')){
     mysql_query("INSERT INTO `mychat`(`userid`, `msg`, `datetime`) VALUES ('".$_SESSION['userid']."','".$_GET['str']."','".date("Y-m-d H:i:s")."')");
	 mysql_query("UPDATE `mychat` SET `viewstatus`=1' WHERE  userid= '".$_SESSION['userid']."'");
}else if(isset($_GET['take']) && ($_GET['take']!='')){
	$sqls = mysql_query("SELECT * FROM `mychat` order by `id` ASC limit 0,50");
	while($rows = mysql_fetch_row($sqls)){
		mysql_query("INSERT INTO `mychat1`(`id`, `userid`, `msg`, `datetime`, `viewstatus`, `status`, `deletedby`) VALUES ('".$rows[0]."','".$rows[1]."','".$rows[2]."','".$rows[3]."','".$rows[4]."','".$rows[5]."','".$rows[6]."')");
		mysql_query("DELETE FROM `mychat` WHERE `id`='".$rows[0]."'");
	}
	header("Location:admin.php");
	exit;
}
$sql = mysql_query("SELECT * FROM `mychat` WHERE `id`> '".$_GET['totalNum']."'  order by `id` asc limit 1");
if(mysql_num_rows($sql)>0){
	while($r=mysql_fetch_array($sql)){
		$img 		= ($r['userid']==2)?"deeptisoni.png":"pradoshsoni.png";
		$spanClass 	= ($userros['status']==1 && $r['userid']!=$_SESSION['userid'])?"onlineusershow":($r['userid']==$_SESSION['userid'])?"onlineusershow":"offlineusershow";
		$userName 	= ($r['userid']==2)?"Deepti Soni":"Pradosh Soni";
		$msg 		= DisplayContent($r['msg']);
		$time 		= time2str($r['datetime']);
		echo $img.'~'.$spanClass.'~'.$userName.'~'.$msg.'~'.$time.'~'.$r['id'];
	}
}else{
	echo "fail";
}
?>