<?php
/*
* @package LabCMS
* @copyright (c) 2006 Alexander Levin aka Loki (loki_angel@mail.ru)
* @support http://labcms.ru
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
*/

Hook::call('lc_chat_before');

$chat=Factory::create('lc_chat.main');

if (LabCMS::i()->isAjax()) {
	$json_response=array('error'=>'Метод '.$_POST['action'].' не найден');
	LabCMS::i()->setModuleTemplate('');
	if (method_exists($chat, $method = 'lc_'.$_POST['action'])) {
		$json_response['error']=0;
		if ($response=call_user_func(array($chat, $method)))
					$json_response=$response;
		if (!LabCMS::i()->no_errors) $json_response=array('error'=>LabCMS::i()->errors[0]);
	}
	
	echo real_json_encode($json_response);
	exit;
}
elseif (!method_exists($chat, $method = 'lc_'.empty($_POST['action'])?'':$_POST['action'])) $method='lc_main';
call_user_func(array($chat, $method));

Hook::call('lc_chat_after');
