<?php
//-------------- Class ContactUsHandler begins --------------->>>>>//
/**
 * Class to handle the contact us page
 */
class BugHandler extends FormHandler
    {
		/**
		 * To send mail to admin
		 *
		 * @param		string $to_mail receiver email address
		 * @return 		boolean
		 * @access		public
		**/
		public function sendEmailToAdmin()
			{
				$this->setEmailTemplateValue('VAR_REPORTER_NAME', $this->getFormField('username')?$this->getFormField('username'):$this->LANG['reportbugs_no_name']);
				$this->setEmailTemplateValue('VAR_REPORTER_EMAIL', $this->getFormField('useremail')?$this->getFormField('useremail'):$this->LANG['reportbugs_no_email']);
				$this->setEmailTemplateValue('VAR_CATEGORY', $this->CFG['lists_array']['bug_category'][$this->getFormField('subject')]);
				$this->setEmailTemplateValue('VAR_CONTENT', $this->getFormField('message'));
				$this->setEmailTemplateValue('VAR_SITE_IP', $this->CFG['remote_client']['ip']);
				$this->buildEmailTemplate($this->LANG['report_bugs_email_subject'], $this->LANG['report_bugs_email_content'], false, true);
				$EasySwift = new EasySwift($this->getSwiftConnection());
				$EasySwift->flush();
				$EasySwift->addPart($this->getEmailContent(), "text/html");
				$from_email = $this->getFormField('useremail')?$this->getFormField('useremail'):$this->CFG['site']['noreply_email'];
				$EasySwift->send($this->CFG['site']['support_email'], $from_email, $this->getEmailSubject());
				return true;
			}

		public function resetFieldsArr()
			{
				$this->setFormField('username', '');
				$this->setFormField('useremail', '');
				$this->setFormField('subject', '');
				$this->setFormField('message', '');
			}
    }
//<<<<<---------------- Class BugHandler ends -------------//
//--------------------- Code begins -------------------->>>>>//
$BugHandler = new BugHandler();
$BugHandler->setPageBlockNames(array('block_reportbugs'));
//set the form field
$BugHandler->resetFieldsArr();
$BugHandler->setAllPageBlocksHide();
$BugHandler->setPageBlockShow('block_reportbugs');
$BugHandler->sanitizeFormInputs($_REQUEST);

if ($BugHandler->isFormPOSTed($_POST, 'submit_reportbugs'))
	{
		$BugHandler->getFormField('useremail') and
			$BugHandler->chkIsValidEmail('useremail', $BugHandler->LANG['common_err_tip_invalid_email_format']);
		$BugHandler->chkIsNotEmpty('subject', $BugHandler->LANG['err_tip_compulsory']);
		$BugHandler->chkIsNotEmpty('message', $BugHandler->LANG['err_tip_compulsory']);

		if ($BugHandler->isValidFormInputs())
			{
				if ($BugHandler->sendEmailToAdmin())
					{
						$BugHandler->setAllPageBlocksHide();
						$BugHandler->setCommonSuccessMsg($BugHandler->LANG['reportbugs_success']);
						$BugHandler->setPageBlockShow('block_msg_form_success');
						$BugHandler->resetFieldsArr();
						$BugHandler->setPageBlockShow('block_reportbugs');
					}
				else
					{
						$BugHandler->setAllPageBlocksHide();
						$BugHandler->setCommonSuccessMsg($BugHandler->LANG['reportbugs_failure']);
						$BugHandler->setPageBlockShow('block_msg_form_success');
						$BugHandler->setPageBlockShow('block_reportbugs');
					}
			}
		else
			{
				$BugHandler->setAllPageBlocksHide();
				$BugHandler->setCommonErrorMsg($BugHandler->LANG['common_msg_error_sorry']);
				$BugHandler->setPageBlockShow('block_msg_form_error');
				$BugHandler->setPageBlockShow('block_reportbugs');
			}
	}
//<<<<--------------------Code Ends----------------------//

//--------------------Page block templates begins-------------------->>>>>//
setPageTitle($LANG['reportbugs_title']);
//include the header file
$BugHandler->includeHeader();
//include the content of the page
setTemplateFolder('general/');
$smartyObj->display('reportBugs.tpl');
//includ the footer of the page
//<<<<<<--------------------Page block templates Ends--------------------//
$BugHandler->includeFooter();
?>