<?php
$template_vars['header'] = array(
'TITLE' => $lang['FEEDBACK'],
'CSS' => $css
);
$template->set_vars('header', $template_vars['header']);
if( empty($_POST) == false )
{
$_SESSION['captcha_key'] = isset( $_SESSION['captcha_key'] ) ? $_SESSION['captcha_key'] : NULL;
$_SESSION['captcha_failures'] = isset( $_SESSION['captcha_failures'] ) ? $_SESSION['captcha_failures'] : 0;
$email = isset( $_POST['email'] ) ? (string) $_POST['email'] : '';
$message = isset( $_POST['message'] ) ? (string) $_POST['message'] : '';
$tr = isset( $_POST['tr'] ) ? (boolean) $_POST['tr'] : false;
$code = isset( $_POST['code'] ) ? (int) $_POST['code'] : NULL;
if( get_magic_quotes_gpc() )
{
$email = stripslashes( $email );
$message = stripslashes( $message );
}
if( $tr )
{
$message = tr( $message );
}
$message = cleanup( $message );
$message = trim( $message );
$error = '';
if( $_SESSION['captcha_key'] === NULL || ($_SESSION['captcha_key'] != $code) )
{
$error = $lang['ERR_CAPTCHA'];
if( ++$_SESSION['captcha_failures'] == 5 )
{
$error = $lang['ERR_CAPTCHA_TOO_MANY_FAILURES'];
$_SESSION['captcha_key'] = NULL;
$_SESSION['captcha_failures'] = 0;
}
}
else if( $email == '' )
{
$error = $lang['ERR_EMPTY_EMAIL'];
}
else if( !preg_match('/^[0-9a-z_]+@[0-9a-z_^\.]+\.[a-z]{2,6}$/i', $email) )
{
$error = $lang['ERR_INCORRECT_EMAIL'];
}
else if( $message == '' )
{
$error = $lang['ERR_EMPTY_MESSAGE'];
}
else if( iconv_strlen($message) > 1000 )
{
$error = $lang['ERR_TOO_LARGE_MESSAGE'];
}
if( $error == '' )
{
if( crc32($message) == $_SESSION['crc32'] )
{
$template->set_block_vars('body', 'error', array('MESSAGE' => $lang['ERR_ALREADY_SENT_MESSAGE']));
}
else
{
$_SERVER['HTTP_USER_AGENT'] = isset( $_SERVER['HTTP_USER_AGENT'] ) ? $_SERVER['HTTP_USER_AGENT'] : 'N/A';
$ip = isset( $_SERVER['HTTP_X_FORWARDED_FOR'] ) ? $_SERVER['REMOTE_ADDR'] . ' (' . $_SERVER['HTTP_X_FORWARDED_FOR'] . ')' : $_SERVER['REMOTE_ADDR'];
$ip = cleanup( $ip );
$message = "E-mail: " . $email . "\r\nMessage: " . $message . "\nIP: " . $ip . "\r\nUserAgent: " . $ua;
$headers = array();
$headers[] = "From: " . $email;
$headers[] = "Content-Type: text/plain; charset=utf-8";
if( mail($config['catalogue_email'], 'Catalogue', $message, implode("\r\n", $headers)) )
{
$_SESSION['crc32'] = crc32($message);
$_SESSION['captcha_key'] = NULL;
$_SESSION['captcha_failures'] = 0;
redirect( gen_uri('index') );
}
else
{
$template->set_block_vars('body', 'error', array('MESSAGE' => $lang['ERR_MAIL_FAILURE']));
}
}
}
else
{
$template->set_block_vars('body', 'error', array('MESSAGE' => $error));
}
}
$pic_types = array('gif', 'jpg', 'png');
$pic_type = isset( $_GET['type'] ) ? (string) $_GET['type'] : '';
$pic_type = in_array($pic_type, $pic_types) ? $pic_type : 'gif';
$pic_type_links = array();
for($i = 0; $i < count($pic_types); $i++)
{
if( $pic_type != $pic_types[$i] )
{
$pic_type_links[] = "<a href='" . gen_uri($m, '', 'type=' . $pic_types[$i]) . "'>" . strtoupper($pic_types[$i]) . "</a>";
}
}
$pic_type_links = implode(', ', $pic_type_links);
$template_vars['body'] = array(
'MESSAGE' => $lang['MESSAGE'],
'TR' => $lang['TR'],
'Y' => $lang['Y'],
'N' => $lang['N'],
'CODE' => $lang['CODE'],
'CAPTCHA_SRC' => append_sid(PATH . '/captcha/?type=' . $pic_type),
'PATH' => gen_uri($m, '', 'type=' . $pic_type . '&' . $nocache),
'SUBMIT' => $lang['SUBMIT'],
'PIC_IS_NOT_LOAD' => $lang['PIC_IS_NOT_LOAD'],
'PIC_TYPE_LINKS' => $pic_type_links,
'BACK_HREF' => gen_uri('index'),
'BACK' => $lang['BACK'],
'NOCACHE' => $nocache
);
$template_vars['footer'] = array(
'SWITCH_VERSION' => switch_version($m, '', 'type=' . $pic_type . '&' . $nocache),
'COUNTER' => ''
);
$template->set_vars('body', $template_vars['body']);
$template->set_vars('footer', $template_vars['footer']);
?>