<?php
/**
 * @package Youtech Contact
 * @version 2.5
 * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL
 * @copyright (c) 2012 YouTech Company. All Rights Reserved.
 * @author YouTech Company http://www.smartaddons.com
 * 
 */
defined('_JEXEC') or die;

$spamtext			= $params->get( 'spamtext' );
$pretext			= $params->get( 'pretext' );
$email_address 		= $params->get( 'adminemail' );
$subject_prefix 	= $params->get( 'subjectprefix' );
$nametext 			= $params->get( 'nametext' );
$emailtext 			= $params->get( 'emailtext' );
$subjecttext 		= $params->get( 'subjecttext' );
$subjectspacer 		= " ";
$bodytext 			= $params->get( 'bodytext' );
$sendtext 			= $params->get( 'sendtext' );
$width 				= $params->get( 'width' );
$height 			= $params->get( 'height' );
$thankyou 			= $params->get( 'thankyou' );
$emailerror 		= $params->get( 'emailerror' );
$spamerror 			= $params->get( 'spamerror' );
$notcomplete 		= $params->get( 'notcomplete' );
$ex1 				= $params->get( 'ex1', '_exclude_pattern_');
$ex2 				= $params->get( 'ex2', '_exclude_pattern_');
$ex3 				= $params->get( 'ex3', '_exclude_pattern_');
$ex4 				= $params->get( 'ex4', '_exclude_pattern_');
$ex5 				= $params->get( 'ex5', '_exclude_pattern_');
$ex6 				= $params->get( 'ex6', '_exclude_pattern_');
$ex7 				= $params->get( 'ex7', '_exclude_pattern_');
$ex8 				= $params->get( 'ex8', '_exclude_pattern_');
$ex9 				= $params->get( 'ex9', '_exclude_pattern_');

if (isset($_POST['name'])) {
	$name = $_POST['name'];
}
if (isset($_POST['email'])) {
	$email = $_POST['email'];
}
if (isset($_POST['message'])) {
	$message = $_POST['message'];
}
if (isset($_POST['subject'])) {
	$subject = $subject_prefix . $subjectspacer . $_POST['subject'];
}
if (isset($_POST['verif_box'])) {
	$verif_box = (md5($_POST["verif_box"]).'youtech');
}

$random_number = rand(0,9999);

$exclude_check = "valid";


// Detects mail headers to prevent spammers.

if (isset($_POST['name'])) {
	if ($name != "" && $name != " ") {
		$from = urldecode($email);


		$message2 = "1".$message;

		if (strrpos($message2,$ex1) > 0) {
			$exclude_check = "invalid";
		}
		if (strrpos($message2,$ex2) > 0) {
			$exclude_check = "invalid";
		}
		if (strrpos($message2,$ex3) > 0) {
			$exclude_check = "invalid";
		}
		if (strrpos($message2,$ex4) > 0) {
			$exclude_check = "invalid";
		}
		if (strrpos($message2,$ex5) > 0) {
			$exclude_check = "invalid";
		}
		if (strrpos($message2,$ex6) > 0) {
			$exclude_check = "invalid";
		}
		if (strrpos($message2,$ex7) > 0) {
			$exclude_check = "invalid";
		}
		if (strrpos($message2,$ex8) > 0) {
			$exclude_check = "invalid";
		}
		if (strrpos($message2,$ex9) > 0) {
			$exclude_check = "invalid";
		}
		
		if ($exclude_check == "valid") {
			if($verif_box == $_COOKIE['ytc_contact_state']){
				mail($_POST['email_address'], $subject, $message, "From: $name <$email>");
				setcookie('ytc_contact_state','');
			} else if(isset($message) and $message!=""){
				exit;
			}
		}

	}
}

require JModuleHelper::getLayoutPath($module->module);
?>