<?php
$mainhtml .= '<h1>Thank you</h1><p>Your order was successful &mdash; an email has been sent to your nominated email address containing more information about your order and dispatch.</p>';
//order total
$order = $mysql->get_array($mysql->query("email_address,shipping,sales_tax,discount_value,payment_method", "fs_shop_orderdata", "owner = '{$_SESSION['owner']}' LIMIT 1"));
$subtotal = 0;
$query = $mysql->query("(price*qty) as price", "fs_shop_cart", "owner = '{$_SESSION['owner']}'");
while($data = $mysql->get_array($query))
{
$subtotal += $data['price'];
}
$total = number_format($subtotal+$order['shipping']-$order['sales_tax']-$order['discount_value'], 2);
//if order is bank type, show the bank details
if($order['payment_method'] == 'bank')
{
$bank = $site->shop_settings('bankpaymentmethod_bankname,bankpaymentmethod_accountname,bankpaymentmethod_accountnumber,bankpaymentmethod_bsb');
$mainhtml .= '<form id="basket" name="basket" method="post" action="">
<p>Please remember to use your order reference number <b>'.$_SESSION['owner'].'</b> when making your payment. Please print or copy and paste below details for your reference.</p>
<table border="0" cellspacing="0" cellpadding="2" style="width:400px;">
<tr>
<th colspan="2">Our bank account details</th>
</tr>
<tr>
<td><strong>Bank Name</strong></td>
<td>'.$bank['bankpaymentmethod_bankname'].'</td>
</tr>
<tr>
<td><strong>Account Name</strong></td>
<td>'.$bank['bankpaymentmethod_accountname'].'</td>
</tr>
<tr>
<td><strong>Account Number</strong></td>
<td>'.$bank['bankpaymentmethod_accountnumber'].'</td>
</tr>
<tr>
<td><strong>BSB</strong></td>
<td>'.$bank['bankpaymentmethod_bsb'].'</td>
</tr>
<tr>
<td><strong>Amount Due</strong></td>
<td>$'.$total.'</td>
</tr>
<tr>
<td><strong>Ref</strong></td>
<td>'.$_SESSION['owner'].'</td>
</tr>
</table></form>
<p><a href="javascript:window.print()">PRINT THIS PAGE</a></p>';
}
//pick up from store
if($order['payment_method'] == 'pickup')
{
$address = $site->shop_settings('shop_address');
$mainhtml .= '<p><b>Our store address:</b><br />'.stripslashes(nl2br($address['shop_address'])).'<br><br>Order total: $'.$total.'</p>
<p><a href="javascript:window.print()">PRINT THIS PAGE</a></p>';
}
//pay by phone
if($order['payment_method'] == 'phonePay')
{
$num = $site->shop_settings('payByPhone_payment_method_phonenum');
$mainhtml .= '<p>Please remember to quote your order reference number <b>'.$_SESSION['owner'].'</b> when calling us.</p><p><b>Our phone number:</b> '.stripslashes($num['payByPhone_payment_method_phonenum']).'<br>Order total: $'.$total.'</p><p><a href="javascript:window.print()">PRINT THIS PAGE</a></p>';
}
//junk msg
$mainhtml .= '<p style="font-weight:bold;">If you do not receive the confirmation message within a few minutes, please check your Junk/Spam E-mail folder just in case the confirmation email got delivered there instead of your inbox. If so, select the confirmation message and click Not Junk, which will allow future messages to get through.</p><p style="font-weight:bold;">Order number: '.$_SESSION['owner'].'</p>';
//add any code that was added from the shopping settings for thank you page
$code = $site->shop_settings('thankyoupage_code');
if(!empty($code['thankyoupage_code']))
{
$find = array("{email_address}", "{total}", "{orderOwner}", "{owner}");
$replace = array($order['email_address'], $total, $_SESSION['owner'], $_SESSION['owner']);
$mainhtml .= str_replace($find, $replace, stripslashes($code['thankyoupage_code']));
}
//include this add-ons's overwrite css file from the template being used, if there is one
$t = settings('template');
if(file_exists('templates/'.$t['template'].'/addons/shop.css'))
{
$mainhtml = str_replace("</head>", '<link rel="stylesheet" type="text/css" href="/templates/'.$t['template'].'/addons/shop.css" /></head>', $mainhtml);
}
else
{
$mainhtml = str_replace("</head>", '<link rel="stylesheet" type="text/css" href="//www.freesites.com.au/addons/shop.css" /></head>', $mainhtml);
}
//myshopping.com.au tracking code
$track = $site->shop_settings('myshoppingcomau_tracking');
if($track['myshoppingcomau_tracking'] != '')
{
$code = '<img height="0" width="0" src ="//www.myshopping.com.au/sale.asp?mid='.$track['myshoppingcomau_tracking'].'&amount='.$total.'&order='.$_SESSION['owner'].'" />';
$mainhtml = str_replace("<body>", '</body>'.$code, $mainhtml);
}
//facebook_conversion_tracking
$track = $site->shop_settings('facebook_conversion_tracking');
if($track['facebook_conversion_tracking'] != '')
{
$code = "<script type=\"text/javascript\">(function()
{
var _fbq = window._fbq || (window._fbq = []);
if (!_fbq.loaded) {
var fbds = document.createElement('script');
fbds.async = true;
fbds.src = '//connect.facebook.net/en_US/fbds.js';
var s = document.getElementsByTagName('script')[0];
s.parentNode.insertBefore(fbds, s);
_fbq.loaded = true;
}
})();
window._fbq = window._fbq || [];
window._fbq.push(['track', '".$track['facebook_conversion_tracking']."', {'value':'".$total."','currency':'AUD'}]);
</script>
<noscript><img height='1' width='1' alt='' style='display:none' src='//www.facebook.com/tr?ev=".$track['facebook_conversion_tracking']."&amp;cd[value]=".$total."&amp;cd[currency]=AUD&amp;noscript=1' /></noscript>";
$mainhtml = str_replace("</body>", $code.'</body>', $mainhtml);
}
//twitter_conversion_tracking
$track = $site->shop_settings('twitter_conversion_tracking');
if($track['twitter_conversion_tracking'] != '')
{
$code = "<script src=\"//platform.twitter.com/oct.js\" type=\"text/javascript\"></script><script type=\"text/javascript\">twttr.conversion.trackPid('".$track['twitter_conversion_tracking']."', { tw_sale_amount: ".$total.", tw_order_quantity: 1 });</script><noscript><img style=\"display:none;\" src=\"//analytics.twitter.com/i/adsct?txn_id=".$track['twitter_conversion_tracking']."&p_id=Twitter&tw_sale_amount=0&tw_order_quantity=0\" /><img style=\"display:none;\" src=\"//t.co/i/adsct?txn_id=".$track['twitter_conversion_tracking']."&p_id=Twitter&tw_sale_amount=".$total."&tw_order_quantity=1\" /></noscript>";
$mainhtml = str_replace("</body>", $code.'</body>', $mainhtml);
}
//google_analytics_ecommerce_tracking
$track = $site->shop_settings('google_analytics_ecommerce_tracking');
if($track['google_analytics_ecommerce_tracking'] != '')
{
$o = $mysql->get_array($mysql->query("town,state,country", "fs_shop_orderdata", "owner = '{$_SESSION['owner']}' LIMIT 1"));
$code = "<script type=\"text/javascript\">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', '".$track['google_analytics_ecommerce_tracking']."']);
_gaq.push(['_trackPageview']);
_gaq.push(['_addTrans',
'".$_SESSION['owner']."',
'',
'".$total."',
'".$order['sales_tax']."',
'".$order['shipping']."',
'".$o['town']."',
'".$o['state']."',
'".$o['country']."'
]);";
$q = $mysql->query("pid,item_name,`option`,price,qty", "fs_shop_cart", "owner = '{$_SESSION['owner']}'");
while($d = $mysql->get_array($q))
{
$code .= "_gaq.push(['_addItem',
'".$_SESSION['owner']."',
'".$d['pid']."',
'".addslashes($d['item_name'])."',
'".addslashes($d['option'])."',
'".$d['price']."',
'".$d['qty']."'
]);";
}
$code .= "_gaq.push(['_trackTrans']);
(function()
{
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>";
$mainhtml = str_replace("</head>", $code.'</head>', $mainhtml);
}
//sign up person to m2news.com.au newsletter
$o = $mysql->get_array($mysql->query("first_name,last_name,email_address,newsletter", "fs_shop_orderdata", "owner = '{$_SESSION['owner']}' LIMIT 1"));
if($o['newsletter'] == 'y')
{
$s = $site->shop_settings('m2news_signup_checkout_group');
$f = array('autoconfirm' => 'n', 'first' => urlencode($o['first_name']), 'last' => urlencode($o['last_name']), 'email' => urlencode($o['email_address']), 'group' => $s['m2news_signup_checkout_group']);
$fields_string = '';
foreach($f as $key=>$value){$fields_string .= $key.'='.$value.'&';}
rtrim($fields_string,'&');
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL, 'https://www.m2news.com.au/tools/subscribe.php');
curl_setopt($ch,CURLOPT_POST, count($f));
curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string);
$result = curl_exec($ch);
}
//kill order session
$_SESSION['owner'] = '';
?>