<?

if (User::i()->isGuest()) LabCMS::i()->error403();


//TODO вынести параметры в настройки
LabConfig::$mcfg['msg_at_page']=50;
LabConfig::$mcfg['max_inbox']=250;
LabConfig::$mcfg['max_outbox']=250;

Tpl::i()->assign('config', LabConfig::$mcfg);

include_once dirname(__FILE__).'/class.pm.php';
$pm=new lc_pm();

if (LabCMS::i()->isAjax())
{
	$json_response=array('error'=>'Метод '.$_POST['action'].' не найден');
	LabCMS::i()->setModuleTemplate('');
	if (method_exists($pm, $method='pm_'.$_POST['action']))
	{
		$json_response=array('error'=>0);
		if ($response=call_user_func(array($pm, $method)))
				$json_response=$response;
	}
	if (!LabCMS::i()->getModuleTemplate())
	{
		if (LabCMS::i()->errors) $json_response=array('error'=>LabCMS::i()->errors[0]);
		echo real_json_encode($json_response);
	}
	return;
}
else
{
	if (method_exists($pm, 'pm_'.$_GET['action'])) $method='pm_'.$_GET['action'];
	else $method='pm_list';
	
	$pm->$method();
}