si, ya lo consegui, pero ahora ocurre otro problema, y es que no me deja desplazar la barra lateral de la pagina la barra de scroll, que puede ser?
Código PHP:
Ver original<?php
define ('DBPATH', '*********');
require_once 'functions.inc.php';
$_SESSION['username'] = $user->userData['usuario'];
global $dbh;
if ($_GET['action'] == "chatheartbeat") { chatHeartbeat(); }
if ($_GET['action'] == "sendchat") { sendChat(); }
if ($_GET['action'] == "closechat") { closeChat(); }
if ($_GET['action'] == "startchatsession") { startChatSession(); }
if (!isset($_SESSION['chatHistory'])) { $_SESSION['chatHistory'] = array(); }
if (!isset($_SESSION['openChatBoxes'])) { $_SESSION['openChatBoxes'] = array(); }
function chatHeartbeat() {
$sql = "select * from chat where (chat.to = '".mysql_real_escape_string($_SESSION['username'])."' AND recd = 0) order by id ASC"; $items = '';
if (!isset($_SESSION['openChatBoxes'][$chat['from']]) && isset($_SESSION['chatHistory'][$chat['from']])) { $items = $_SESSION['chatHistory'][$chat['from']];
}
$chat['message'] = sanitize($chat['message']);
$items .= <<<EOD
{
"s": "0",
"f": "{$chat['from']}",
"m": "{$chat['message']}"
},
EOD;
if (!isset($_SESSION['chatHistory'][$chat['from']])) { $_SESSION['chatHistory'][$chat['from']] = '';
}
$_SESSION['chatHistory'][$chat['from']] .= <<<EOD
{
"s": "0",
"f": "{$chat['from']}",
"m": "{$chat['message']}"
},
EOD;
unset($_SESSION['tsChatBoxes'][$chat['from']]); $_SESSION['openChatBoxes'][$chat['from']] = $chat['sent'];
}
if (!empty($_SESSION['openChatBoxes'])) { foreach ($_SESSION['openChatBoxes'] as $chatbox => $time) {
if (!isset($_SESSION['tsChatBoxes'][$chatbox])) {
$message = "Enviado a las ".$time22."";
if ($now > 180) {
$items .= <<<EOD
{
"s": "2",
"f": "$chatbox",
"m": "{$message}"
},
EOD;
if (!isset($_SESSION['chatHistory'][$chatbox])) { $_SESSION['chatHistory'][$chatbox] = '';
}
$_SESSION['chatHistory'][$chatbox] .= <<<EOD
{
"s": "2",
"f": "$chatbox",
"m": "{$message}"
},
EOD;
$_SESSION['tsChatBoxes'][$chatbox] = 1;
}
}
}
}
if ($items != '') {
$items = substr($items, 0, -1); }
header('Content-type: application/json'); ?>
{
"items": [
<?php echo $items;?>
]
}
<?php
}
function chatBoxSession($chatbox) {
$items = '';
if (isset($_SESSION['chatHistory'][$chatbox])) { $items = $_SESSION['chatHistory'][$chatbox];
}
return $items;
}
function startChatSession() {
$items = '';
if (!empty($_SESSION['openChatBoxes'])) { foreach ($_SESSION['openChatBoxes'] as $chatbox => $void) {
$items .= chatBoxSession($chatbox);
}
}
if ($items != '') {
$items = substr($items, 0, -1); }
header('Content-type: application/json'); ?>
{
"username": "<?php echo $_SESSION['username'];?>",
"items": [
<?php echo $items;?>
]
}
<?php
}
function sendChat() {
$from = $_SESSION['username'];
$to = $_POST['to'];
$message = $_POST['message'];
$_SESSION['openChatBoxes'][$_POST['to']] = date('Y-m-d H:i:s', time());
$messagesan = sanitize($message);
if (!isset($_SESSION['chatHistory'][$_POST['to']])) { $_SESSION['chatHistory'][$_POST['to']] = '';
}
$_SESSION['chatHistory'][$_POST['to']] .= <<<EOD
{
"s": "1",
"f": "{$to}",
"m": "{$messagesan}"
},
EOD;
unset($_SESSION['tsChatBoxes'][$_POST['to']]);
echo "1";
}
function closeChat() {
unset($_SESSION['openChatBoxes'][$_POST['chatbox']]);
echo "1";
}
function sanitize($text) {
return $text;
}
?>