<?php

include './core.php';

if( isset( $_POST['send_form'] ) )
{
    flood_protect( 'contact' );

    $form_errors = array();

    if( !check_fields( 'name', 'email', 'area', 'message' ) )
    	$form_errors[] = form_error( 'uncomplete' );
    else
    {
    	if( !eregi( '@' , $_POST['email'] ) || !eregi( '.' ,$_POST['email'] ) )
        	$form_errors[] = form_error( 'unvalid_email' );
    }

    if( count( $form_errors ) > 0 )
    {
        $Smarty->assign( 'form_errors', $form_errors );
        assign_formvalues( 'name', 'email', 'message', 'area' );
    }
    else
    {
    	switch( $_POST['area'] )
        {
        	case 'Technik':
                $to_mail = $settings['tech_support_email'];
                break;
            default:
            	$to_mail = $settings['contact_form_email'];
        }

        $mailenv = array();
        $mailenv['name'] = $_POST['name'];
        $mailenv['email'] = $_POST['email'];
        $mailenv['message'] = $_POST['message'];

        if( send_mail( $to_mail, 'contact', $_POST['name']." <".$_POST['email'].">" ) )
        {
            $exp_time = time() + intval( $settings['flood_protect_contact'] );
            $MySQL->query( "INSERT INTO flood_protect (ip_address, performed_action, expire) VALUES ('".$_SERVER['REMOTE_ADDR']."','contact',".$exp_time.")" );

            display_message( 'contact_success' );
        }
        else
        	display_message( 'contact_failure' );
    }
}

$area_options = make_assoc_array( 'Technik', 'Inhalt', 'Design', 'Anderes' );
$Smarty->assign( 'area_options', $area_options );

$page['content'] = $Smarty->fetch( 'contact.tpl' );

$Smarty->assign( 'page', $page );
$Smarty->display( 'main.tpl' );

?>