PDA

View Full Version : Reload a tree (menu chat) PHP



dani_vlz
23 Mar 2011, 4:27 AM
I have a tree menu that I use for a chat. but do not know how I can do to recharge it every so often to update the users connecting. the structure is this: I have a. js that makes the tree and another file. php is the one doing the json by calling database.

this is the. js:


/ / here I set the East panel that is where I'll put the chat menu
var panelEast = new Ext.Panel({
region: 'east',
id: 'panelEast',
name: 'panelEast',
title: 'Chat',
split: true,
width: 250,
minSize: 200,
maxSize: 400,
collapsible: true,
margins: '0 0 0 5',
layout: {
type: 'accordion',
animate: true
},
items: []
});

//from here I call the functions to build the tree nodes
for(var i=0; i< datosAcordionChat.length; i++)
{
addAcordionItemChat(datosAcordionChat[i]);
}
viewport.render();

for(var i=0; i< datosAcordionChat.length; i++)
{
addAcordionTreeChat(datosAcordionChat[i]);
}

/ / these are the functions that assemble the tree
function addAcordionItemChat (index)
{
panelEast.add({
title: index[0],
html: '<div id="treeChat'+index[1]+'"></div>',
cls: 'empty',
autoHeight: false,
containerScroll: true,
overflow: true,
cls : "overflowmenu",
iconCls: index[2]
}).show();
};

function addAcordionTreeChat (index)
{
var TreeChat = Ext.tree;
var treeChat = new TreeChat.TreePanel
(
{
lines :false,
el : 'treeChat'+index[1],
animate : true,
autoScroll : true,
containerScroll : true,
loader : treeChat_loader,
containerScroll : true,
rootVisible : false,
listeners:
{
click: function(n)
{

}
},
autoHeight:true,
enableDD : true,
border: false
}
);
var rootChat = new TreeChat.AsyncTreeNode(
{
text: index[0],
draggable:false,
id:'treeRChat'+index[1],
children: eval('jsonChat_'+index[1])

}
);
treeChat.setRootNode(rootChat);

treeChat.render();
rootChat.expand();
};

this is causing the json php:


<?PHP
session_start();
include_once("../../../Config/config.inc.php");
include_once($_SESSION['path_site']."Classes/PCMsite.class.php");
header("content-type: application/x-javascript");


$conx = new PCMDataBase();

//try
//{
$query_menu="SELECT ID,DESCR FROM COREGRUP000";
$conx->executeQuery($query_menu);
$array_datos = $conx->vlist[0];
$cadena_menuChat="
var datosAcordionChat =
[\n";
for($a=0;$a<count($array_datos);$a++)
{
$query_totalUsers = "SELECT COUNT (*) FROM COREUSR000 WHERE IDAREA = ".$array_datos[$a][0]." AND DEBAJA = 'N'";
$conx->executeQuery($query_totalUsers);
$total_Users = $conx->vlist[0][0][0];

$query_UsersOnline = "SELECT COUNT (*) FROM COREUSR000 WHERE IDAREA = ".$array_datos[$a][0]." AND LOGGEDIN = 'S' AND DEBAJA = 'N'";
$conx->executeQuery($query_UsersOnline);
$users_online = $conx->vlist[0][0][0];

$query_User = "SELECT COUNT (*) FROM COREUSR000 WHERE IDAREA = ".$array_datos[$a][0]." AND DEBAJA = 'N' AND IDUSUARIO = '".$_SESSION['userid']."'";
$conx->executeQuery($query_User);
$users_actual = $conx->vlist[0][0][0];

if ($users_actual != 0)
{
$users_online = $users_online - 1;
}


$cadena_menuChat.=" ['".$array_datos[$a][1]." ".$users_online."/".$total_Users."','".$array_datos[$a][0]."','menuchat']";
if($a<(count($array_datos)-1)){
$cadena_menuChat.=",\n";
}
else{
$cadena_menuChat.="\n";
}
}
$cadena_menuChat.=" ];";
/*
}
catch (Exception $e)
{
$cadena_menuChat = "alert(\"".str_replace("\r", "", str_replace("\n", "", $e->getMessage()))."\");" ;
}
*/
for($a=0;$a<count($array_datos);$a++)
{
$query_sub_menu="SELECT IDUSUARIO, NOMBRE, LOGGEDIN FROM COREUSR000 WHERE IDAREA = ".$array_datos[$a][0]." AND DEBAJA = 'N'";
$conx->executeQuery($query_sub_menu);
$array_sub_datos=$conx->vlist[0];
$fun = "javascript:chatWith('".$array_sub_datos[$b][0]."')";
$cadena_jsonChat.='
var jsonChat_'.$array_datos[$a][0].' =[';
for($b=0;$b<count($array_sub_datos);$b++)
{
if ($array_sub_datos[$b][2] == 'S' && $array_sub_datos[$b][0] != $_SESSION['userid'])
{
$cadena_jsonChat.='
{"text" : "'.$array_sub_datos[$b][1].'", "id" : "'.$array_sub_datos[$b][0].'", "leaf" : true, "iconCls" : "online", "href": "javascript:chatWith(\''.$array_sub_datos[$b][0].'\')" }';

if($b<(count($array_sub_datos)-1))
{
$cadena_jsonChat.=',';
}
}
}
for($b=0;$b<count($array_sub_datos);$b++)
{
if ($array_sub_datos[$b][2] == 'N' && $array_sub_datos[$b][0] != $_SESSION['userid'])
{
$cadena_jsonChat.='
{"text" : "'.$array_sub_datos[$b][1].'", "id" : "'.$array_sub_datos[$b][0].'", "leaf" : true, "iconCls" : "offline"}';

if($b<(count($array_sub_datos)-1))
{
$cadena_jsonChat.=',';
}
}
}
$cadena_jsonChat.=']';
}

echo $cadena_menuChat;
echo $cadena_jsonChat;
?>

Since already many thanks =)
PS: Sorry for the English is so wrong that I wrote with a translator.