<?php
header ( "Expires: Mon, 26 Jul 1997 05:00:00 GMT" );
header ( "Last-Modified: ". gmdate("D, d M Y H:i:s")." GMT" );
header ( "Cache-Control: no-cache, must-revalidate" );
header ( "Pragma: no-cache" );
?>
<?php
include_once( 'dsn.php' );
include_once( 'HTML/Table.php' );
function capitalize( $unformatted_name )
{
$parts = explode( " ", $unformatted_name );
for( $i = 0; $i < count( $parts ); $i++ )
{
if( $i == 0 )
$formatted_name = ucfirst( strtolower( trim( $parts[$i] ) ) );
else
if( trim( $parts[$i] ) != "" ) // Empty string
$formatted_name .= " ".ucfirst( strtolower( trim( $parts[$i] ) ) );
}
return $formatted_name;
}
$passed_form = $GLOBALS['HTTP_POST_VARS'];
$db = DB::connect( $dsn );
if( DB::isError( $db ) )
{
die( $db->getMessage().' '.__FILE__.' '.__LINE__."\n" );
exit;
}
$query_string = "SELECT delivery_suburb, delivery_price FROM delivery WHERE delivery_id = '".$passed_form['form_delivery_id']."'";
$delivery_data = $db->getRow( $query_string, DB_FETCHMODE_ASSOC );
if( DB::isError( $db ) )
{
die( $db->getMessage().' '.__FILE__.' '.__LINE__."\n" );
exit;
}
$day_array = array( "DAY", 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21,
22, 23, 24, 25, 26, 27, 28, 29, 30, 31 );
$month_array = array( "MONTH", "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct",
"Nov", "Dec" );
$this_year = date( 'Y' );
$year_array = array( "YEAR", $this_year, $this_year+1, $this_year+2, $this_year+3, $this_year+4,
$this_year+5 );
$delivery_day = $day_array[$passed_form['form_delivery_day']];
$delivery_month = $month_array[$passed_form['form_delivery_month']];
$delivery_year = $year_array[$passed_form['form_delivery_year']];
$total_price = str_replace( '$', '', $passed_form['form_total_price'] );
$query_string = "INSERT INTO soc_order
(
order_id,
item_id,
order_gift1_id,
order_gift2_id,
order_gift3_id,
order_card_id,
order_subtotal_price,
order_card_from,
order_card_to,
order_card_message,
order_customer_company,
order_customer_christian,
order_customer_surname,
order_customer_email,
order_customer_phone,
order_delivery_recipient,
order_delivery_company,
order_delivery_address,
order_delivery_suburb,
order_delivery_day,
order_delivery_month,
order_delivery_year,
order_delivery_notes,
order_delivery_cost,
order_total_price
)
VALUES
(
'".$passed_form['order_id']."',
'".$passed_form['form_item_id']."',
'".$passed_form['form_gift1_id']."',
'".$passed_form['form_gift2_id']."',
'".$passed_form['form_gift3_id']."',
'".$passed_form['form_card_id']."',
'".str_replace( '$', '', $passed_form['form_subtotal_price'] )."',
'".$passed_form['form_card_from']."',
'".$passed_form['form_card_to']."',
'".$passed_form['form_card_message']."',
'".$passed_form['form_customer_company']."',
'".ucfirst( strtolower( $passed_form['form_customer_christian'] ) )."',
'".ucfirst( strtolower( $passed_form['form_customer_surname'] ) )."',
'".$passed_form['form_customer_email']."',
'".$passed_form['form_customer_phone']."',
'".$passed_form['form_delivery_recipient']."',
'".$passed_form['form_delivery_company']."',
'".$passed_form['form_delivery_address']."',
'".$delivery_data['delivery_suburb']."',
'$delivery_day',
'$delivery_month',
'$delivery_year',
'".$passed_form['form_delivery_notes']."',
'".$delivery_data['delivery_price']."',
'$total_price'
)";
$result = $db->query( $query_string );
if( DB::isError( $result ) )
{
die( $result->getMessage().' '.__FILE__.' '.__LINE__."\n" );
exit;
}
$formatted_name = capitalize( $passed_form['form_customer_christian']." ".$passed_form['form_customer_surname'] );
$dollars = substr( $total_price, 0, strpos( $total_price, "." ) );
$cents = substr( $total_price, strpos( $total_price, "." )+1 );
// Send an email
$email = "sales@sunflowersoncollins.com.au";
$tablestyle = array( "width"=>"80%", "border"=>1, "cellpadding"=>1, "cellspacing"=>2, "align"=>"center" );
$table = new HTML_Table( $tablestyle );
$table->addRow( array( "Order Number:", $order_id ) );
$table->addRow( array( "Item Name:", $passed_form['form_item_name'] ) );
$table->addRow( array( "Item Code:", $passed_form['form_item_code'] ) );
$table->addRow( array( "Item Price:", $passed_form['form_item_price'] ) );
if( $passed_form['form_gift1_id'] > 0 )
{
$query_string = "SELECT item_name from items WHERE item_id = '".
$passed_form['form_gift1_id']."'";
$item_name = $db->getOne( $query_string ); // There can be only one!
if( DB::isError( $db ) )
{
die( $db->getMessage().' '.__FILE__.' '.__LINE__."\n" );
exit;
}
$table->addRow( array( "Gift1 Name:", $item_name ) );
$table->addRow( array( "Gift1 Code:", $passed_form['form_gift1_code'] ) );
$table->addRow( array( "Gift1 Price:", $passed_form['form_gift1_price'] ) );
}
if( $passed_form['form_gift2_id'] > 0 )
{
$query_string = "SELECT item_name from items WHERE item_id = '".
$passed_form['form_gift2_id']."'";
$item_name = $db->getOne( $query_string ); // There can be only one!
if( DB::isError( $db ) )
{
die( $db->getMessage().' '.__FILE__.' '.__LINE__."\n" );
exit;
}
$table->addRow( array( "Gift2 Name:", $item_name ) );
$table->addRow( array( "Gift2 Code:", $passed_form['form_gift2_code'] ) );
$table->addRow( array( "Gift2 Price:", $passed_form['form_gift2_price'] ) );
}
if( $passed_form['form_gift3_id'] > 0 )
{
$query_string = "SELECT item_name from items WHERE item_id = '".
$passed_form['form_gift3_id']."'";
$item_name = $db->getOne( $query_string ); // There can be only one!
if( DB::isError( $db ) )
{
die( $db->getMessage().' '.__FILE__.' '.__LINE__."\n" );
exit;
}
$table->addRow( array( "Gift3 Name:", $item_name ) );
$table->addRow( array( "Gift3 Code:", $passed_form['form_gift3_code'] ) );
$table->addRow( array( "Gift3 Price:", $passed_form['form_gift3_price'] ) );
}
if( $passed_form['form_card_id'] > 0 )
{
$query_string = "SELECT item_name from items WHERE item_id = '".
$passed_form['form_card_id']."'";
$item_name = $db->getOne( $query_string ); // There can be only one!
if( DB::isError( $db ) )
{
die( $db->getMessage().' '.__FILE__.' '.__LINE__."\n" );
exit;
}
$table->addRow( array( "card Name:", $item_name ) );
$table->addRow( array( "card Code:", $passed_form['form_card_code'] ) );
$table->addRow( array( "card Price:", $passed_form['form_card_price'] ) );
}
// Card details
$table->addRow( array( "Card From:", stripslashes( $passed_form['form_card_from'] ) ) );
$table->addRow( array( "Card To:", stripslashes( $passed_form['form_card_to'] ) ) );
$table->addRow( array( "Card Message:", "<pre>".stripslashes( $passed_form['form_card_message'] )."</pre>" ) );
// Sender details
$table->addRow( array( "Company Name:", stripslashes( $passed_form['form_customer_company'] ) ) );
$table->addRow( array( "First Name:", stripslashes( $passed_form['form_customer_christian'] ) ) );
$table->addRow( array( "Last Name:", stripslashes( $passed_form['form_customer_surname'] ) ) );
$table->addRow( array( "Email Address:", stripslashes( $passed_form['form_customer_email'] ) ) );
$table->addRow( array( "Contact Phone No.:", stripslashes( $passed_form['form_customer_phone'] ) ) );
// Recipient details
$table->addRow( array( "Attention To:", stripslashes( $passed_form['form_delivery_recipient'] ) ) );
$table->addRow( array( "Company Name:", stripslashes( $passed_form['form_delivery_company'] ) ) );
$table->addRow( array( "Address:", stripslashes( $passed_form['form_delivery_address'] ) ) );
$query_string = "SELECT delivery_suburb, delivery_price FROM delivery WHERE delivery_id = '".$passed_form['form_delivery_id']."'";
$delivery_data = $db->getRow( $query_string, DB_FETCHMODE_ASSOC );
if( DB::isError( $db ) )
{
die( $db->getMessage().' '.__FILE__.' '.__LINE__."\n" );
exit;
}
continued below