include ('includes/rthf_functions.php');
//if we are selling online, then redirect the user to the secure section
if(online_selling==1)
{
//check where user came from
if(isset($_GET['ref'])&&(is_numeric($_GET['ref'])))
{
$referrer = $_GET['ref'];
}
else
{
$referrer = '1';
}
//create the absolute url for the redirect
$url = secure_section.secure_order_form."?ref=$referrer";
//redirect the user to the login page
header("Location: $url");
}
//else, display the preorder form
else
{
$title = 'Buy the humorous book about France, the French and French history by Jules Eden and Alex Clarke';
$desc = 'Buy the book 50 reasons to hate the French by Jules Eden and Alex Clarke. A hilarious book about France, the French and French History.';
//display the top_nav and banner
do_top_nav_banner($title, $desc);
//if the preorder form was submitted
if(isset($_POST['form_submitted']))
{
//display the sub_nav
display_sub_nav();
//display the side_nav
display_side_nav();
//open the main content div
echo "\t
\n";
//the form was submitted
//put the post array into vars
$firstname = strip_tags(trim($_POST['fname']));
$surname = strip_tags(trim($_POST['sname']));
$phone = strip_tags(trim($_POST['phone']));
$email = strip_tags(trim($_POST['email']));
//values from the hidden vars
$identifier = $_POST['identifier'];
//inititialise an error array
$errors = array();
//validate the user input
if(!valid_textfield($firstname))
{
$errors[] = '
Firstname must be filled in and contain text only';
}
if(!valid_textfield($surname))
{
$errors[] = '
Surname must be filled in and contain text only';
}
if(!is_numeric($phone)||(strlen($phone)<6))
{
$errors[] = '
Telephone must be a number at least 6 digits long';
}
if(!valid_email($email))
{
$errors[] = '
Email must be in the following format - name@yourdomain.com';
}
//check the value of the error variable
//if there were no errors, then we process
if (count($errors)== 0)
{
//attempt to insert into the db
if(insert_user_registration($firstname, $surname, $email, $phone, $identifier))
{
//send the email to the admin address
send_preorder_email($firstname, $surname, $email, $phone);
echo "\t\t
Thankyou…
\n";
echo "\t\t
Your details have been submitted. We will contact you via email prior to the release date of August 3rd 2006, so that you are one of the first to have the chance to purchase online.
\n";
}
else
{
echo "\t\t
Error…
\n";
echo "\t\t
There was a problem submitting your details. Please try again later.
\n";
}
}
else
{
//there were errors so display them
echo "\t\t
The following errors occurred:
\n";
echo "\t\t
\n";
foreach($errors as $error)
{
echo "\t\t\t- ".$error."
\n";
}
echo "\t\t
\n";
//display the form
display_preorder_forms($_POST);
}
}
//preorder form was NOT submitted
else
{
//display the sub_nav
display_sub_nav();
//display the side_nav
display_side_nav();
echo "\t
\n";
//display the form to pre order the book
display_preorder_forms($_POST);
}
//close main content div
echo "\t
\n";
//display the html footer
display_html_footer();
}
?>