<?
/******************************************************************************/
// ICM v 2.0 for InstantCMS 1.7 //
// 2011 FREEWARE //
// gener@i.ua //
// //
// //
/******************************************************************************/
define('PATH', $_SERVER['DOCUMENT_ROOT']); define('HOST', 'http://' . $_SERVER['HTTP_HOST']); //header('Content-Type: text/html;charset=windows-1251');
include('core/cms.php');
include('components/users/includes/usercore.php');
$inCore = cmsCore::getInstance();
$inCore->loadClass('user');
$inDB= cmsDatabase::getInstance();
$inUser= cmsUser::getInstance();
$inUser->update();
$inCore->onlineStats();
$user_id=$inUser->id;
$inCore->loadModel('users');
$dom=new DOMDocument('1.0', 'UTF-8');
function idtonick($uid){
$inDB= cmsDatabase::getInstance();
$sq="SELECT nickname FROM cms_users WHERE id=$uid LIMIT 1";
$result=$inDB->query($sq);
if ($inDB->num_rows($result)){
$nick = $inDB->fetch_assoc($result);
return $nick['nickname'];
}
else return "";
}
if ($user_id){
if ($inCore->inRequest('cmd')){
$cmd = $inCore->request('cmd', 'str');
if ($cmd=='enter'){
$sq="DELETE FROM cms_imchat_online WHERE user=$user_id";
$inDB->query($sq);
$sq="INSERT INTO cms_imchat_online (user) VALUES ($user_id)";
$inDB->query($sq);
}
if ($cmd=="exit"){
$sq="DELETE FROM cms_imchat_online WHERE user=$user_id";
$inDB->query($sq);
}
if ($cmd=="refresh"){
if($inCore->inRequest('lmes')){$lastmsg=$inCore->request('lmes','int');}
$sq="SELECT * FROM cms_imchat where id>$lastmsg ORDER BY id";
$result=$inDB->query($sq);
$root=$dom->createElement('response');
if ($inDB->num_rows($result)){
while($nmes = $inDB->fetch_assoc($result)){
if($nmes['to']<>$user_id && $nmes['privat']==1&& $nmes['from']<>$user_id){}
else{
$name=$dom->createElement('name');
$root->appendChild($name);
$nsender=idtonick($nmes['from']);
$nto=idtonick($nmes['to']);
$name->appendChild($dom->createElement('sender',iconv ("windows-1251","utf-8",$nsender))); $name->appendChild($dom->createElement('to',iconv ("windows-1251","utf-8",$nto))); $name->appendChild($dom->createElement('time',$nmes['time']));
$name->appendChild($dom->createElement('msg',iconv ("windows-1251","utf-8",$nmes['msg']))); $name->appendChild($dom->createElement('privat',$nmes['privat']));
$name->appendChild($dom->createElement('lastmsg',$nmes['id']));
}
}
}
$dom->appendChild($root);
echo $dom->saveXML();
}
if ($cmd=='say'){
$to=$inCore->request('to','int');
$time=date('m.d.y H:i:s'); $msg=$inCore->request('msg','str');
$prv=$inCore->request('prv','int');
if($to>=0){
$sq="INSERT INTO cms_imchat (`from`,`to`,`time`,msg,privat) VALUES ($user_id,$to,'{$time}','{$msg}',$prv)";
$inDB->query($sq);
$lastid=$inDB->get_last_id('cms_imchat');
$sq="DELETE FROM cms_imchat WHERE id <$lastid-20";
$inDB->query($sq);
}
}
if ($cmd=='online'){
$sq="SELECT user from cms_imchat_online";
$result=$inDB->query($sq);
$root=$dom->createElement('response');
if ($inDB->num_rows($result)){
while($rec = $inDB->fetch_assoc($result)){
$name=$dom->createElement('name');
$root->appendChild($name);
$nick=idtonick($rec['user']);
$name->appendChild($dom->createElement('id',$rec['user']));
$name->appendChild($dom->createElement('nick',iconv ("windows-1251","utf-8",$nick)));
}
}
$dom->appendChild($root);
echo $dom->saveXML();
}
}
}
?>