<?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
*/

/**
 * @author Alexander
 * @copyright 2007
 */

if (!isset(LabCMS::i()->params['feedback']) || !LabCMS::i()->params['feedback'])
{
	$mod_template="default.tpl";
}
else
{
	$mod_template=LabCMS::i()->params['feedback'].".tpl";
}

if ($_SERVER['REQUEST_METHOD']=='POST')
{
	User::checkToken();
	if ($_POST['name']) {sleep(20); exit();}

	if (is_array($_POST['obl'])) foreach($_POST['obl'] as $var)
	{
		if (trim($var)=='')
		{
			LabCMS::i()->error("Не все обязательные поля были заполнены");
			break;
		}
	}
	
	if (LabCMS::i()->no_errors)
	{
		Tpl::i()->assign($_POST['obl']);
		Tpl::i()->assign($_POST['nobl']);

		$mail=new Mailer(LabConfig::$mcfg['email']?LabConfig::$mcfg['email']:LabConfig::$cfg['admin_mail']);
		$mail->From = "feedback@".preg_replace('/^www\./i', '', $_SERVER["SERVER_NAME"]);
		$mail->FromName = "Обратная связь";
		$mail->WordWrap = 80;                                 // set word wrap to 80 characters
		$mail->Subject = "Обратная связь на ".preg_replace('/^www\./i', '', $_SERVER["SERVER_NAME"]);
		$mail->Body    = Tpl::i()->fetch(LabCMS::i()->getModuleName()."/email_".$mod_template);
		if(!$mail->Send())
		{
			LabCMS::i()->error(_m("Ошибка почтового робота: ").$mail->ErrorInfo, true);
		}
		else
		{
			$mod_template="success.tpl";
		}
	}

}
