<?php
/**
 *
 *
 * PHP version 5.0
 *
 * @category	Anova
 * @package		ContactUsHandler
 * @author 		selvaraj_47ag04
 * @copyright 	Copyright (c) 2009 {@link http://www.agriya.com Agriya Infoway}
 * @license		http://www.agriya.com Agriya Infoway Licence
 * @version		SVN: $Id:
 * @since 		2008-12-19
 **/
//-------------- Class ContactUsHandler begins --------------->>>>>//
/**
 * Class to handle the contact us page
 */
class ContactUsHandler extends FormHandler
    {
		/**
		 * To send mail to admin
		 *
		 * @param		string $to_mail receiver email address
		 * @return 		boolean
		 * @access		public
		**/
		public function sendEmailToAdmin($to_mail)
			{
				$this->buildEmailTemplate($this->fields_arr['subject'], $this->fields_arr['message'], false, true);
				$EasySwift = new EasySwift($this->getSwiftConnection());
				$EasySwift->flush();
				$EasySwift->addPart($this->getEmailContent(), "text/html");
				return $EasySwift->send($to_mail, $this->fields_arr['useremail'], $this->getEmailSubject());
			}
    }
//<<<<<---------------- Class ContactUsHandler ends -------------//
//--------------------- Code begins -------------------->>>>>//
$contactus = new ContactUsHandler();
$contactus->setPageBlockNames(array('block_contactus'));
//set the form field
$contactus->setFormField('useremail', '');
$contactus->setFormField('subject', '');
$contactus->setFormField('message', '');
$contactus->setAllPageBlocksHide();
$contactus->setPageBlockShow('block_contactus');
$contactus->sanitizeFormInputs($_REQUEST);

if ($contactus->isFormPOSTed($_POST, 'submit_contactus'))
	{
		$contactus->chkIsNotEmpty('useremail', $contactus->LANG['err_tip_compulsory']) and
			 $contactus->chkIsValidEmail('useremail', $contactus->LANG['common_err_tip_invalid_email_format']);
		$contactus->chkIsNotEmpty('subject', $contactus->LANG['err_tip_compulsory']);
		$contactus->chkIsNotEmpty('message', $contactus->LANG['err_tip_compulsory']);
		if ($contactus->isValidFormInputs())
			{
				if ($contactus->sendEmailToAdmin($contactus->CFG['site']['support_email']))
					{
						Redirect2URL(getUrl('contactus', '?invited', '?invited'));
					}
				else
					{
						$contactus->setCommonSuccessMsg($contactus->LANG['common_email_failure']);
						$contactus->setPageBlockShow('block_msg_form_success');
					}
			}
		else
			{
				$contactus->setCommonErrorMsg($contactus->LANG['common_msg_error_sorry']);
				$contactus->setPageBlockShow('block_msg_form_error');
			}
	}
elseif ($contactus->isFormGETed($_GET, 'invited'))
	{
		$contactus->setPageBlockShow('block_msg_form_success');
		$contactus->setCommonSuccessMsg($LANG['common_email_sent_success']);
	}
//<<<<--------------------Code Ends----------------------//

//--------------------Page block templates begins-------------------->>>>>//
//include the header file
$contactus->includeHeader();
//include the content of the page
setTemplateFolder('general/');
$smartyObj->display('contactUs.tpl');
//includ the footer of the page
//<<<<<<--------------------Page block templates Ends--------------------//
$contactus->includeFooter();
?>