<?
$O['HEADING'] = 'Customer Details / My Account';
if(isset($_REQUEST['acc_action'])) { $action = $_REQUEST['acc_action']; } else { $action = ''; }
if(isset($_REQUEST['sub_display'])) { $sub_display = $_REQUEST['sub_display']; } else { $sub_display = 'personal'; }
$O['BODY'] = '
<TABLE><TR>
<TD><A HREF="order.php?display=account&sub_display=personal">Your Details</A></TD>
<TD><A HREF="order.php?display=account&sub_display=current">Current Orders</A></TD>
<TD><A HREF="order.php?display=account&sub_display=past">Past Orders</A></TD>
<TD><A HREF="order.php?display=account&sub_display=options">Options</A></TD>
</TR></TABLE>';
if($action == 'savepersonal') {
//we only save selected fields so bad people cant fuck with login/passwords.
$errormessage = ''; $missingfields = '';
$fields = array('firstname','lastname','email','address','suburb','state','postcode','country','phone','fax');
foreach($fields as $field) {
if(isset($_POST[$field])) {
client_setval($SITECLIENT,$field,$_POST[$field]);
}
if((!isset($_POST[$field]) || $_POST[$field] == '') && $field != 'fax') {
$missingfields .= $field.',';
}
}
client_setval($SITECLIENT,'c_name',$lastname.','.$firstname);
$ORD->setval('clientid',$SITECLIENT);
search_reindex('client',$SITECLIENT);
}
if($action == 'vieworder') {
$sub_display = '';
$ORD = new order();
$ORD->loadorder($_GET['ordid']);
$details = $ORD->getdetails();
$O['BODY'] .= $font.'<B>Viewing Order</B><BR>Order Number: '.$ORD->orderid.'<BR></FONT>';
$O['BODY'] .= '<TABLE BORDER="0" CELLPADDING="3" CELLSPACING="2">
<TR BGCOLOR="#'.getoption('site','ord_titlebgcolor').'">
<TD>'.$tfont.'<B>Units</B></TD>
<TD>'.$tfont.'<B>Product</B></TD><TD>'.$tfont.'<B>Unit Price</B></TD>';
if(getoption('site','site_taxmode') == 1) {
$O['BODY'] .= '<TD>'.$tfont.'<B>'.getoption('site','site_taxname').'</B></TD>';
}
$O['BODY'] .= '<TD>'.$tfont.'<B>Total Price</B></TD></TR>';
foreach($details['items'] as $id => $item) {
if($bar == $bar1) { $bar = $bar2; } else { $bar = $bar1; }
$O['BODY'] .= '<TR '.$bar.'>
<TD>'.$font.$item['quantity'].'</TD>
<TD>'.$font.$item['desc'].'</TD>
<TD>'.$font.cur_formatamount($item['price']).'</TD>';
if(getoption('site','site_taxmode') == 1) {
$O['BODY'] .= '<TD>'.$font.doubleval($item['tax']).'%</TD>';
}
$O['BODY'] .= '<TD>'.$font.cur_formatamount($item['tprice']).'</TD></TR>';
}
$O['BODY'] .= '</TABLE>';
$O['BODY'] .= $font.'<B>Items Cost = <I>'.cur_formatamount($details['itemsprice']).'</I></B><BR>';
$O['BODY'] .= '<BR><B>Payment Method:</B> '.$details['paymethod'].'<BR>';
$O['BODY'] .= format_text($details['paydetails'],array('indent' => 4,'bold' => 1));
//payment details here!
$O['BODY'] .= '<B>Shipping Cost:</B> '.cur_formatamount($details['shippingcost']);
$O['BODY'] .= '<TABLE BORDER="0" CELLSPACING="0" CELLPADDING="0">
<TR><TD VALIGN="TOP" COLSPAN="2">'.$font.'<B>'.getoption('site','lbl_shipping').' Address</B></TD></TR>
<TR><TD>'.$font.''.format_text($details['shippingaddress'],array('indent' => 4)).'</FONT>
</TD></TR></TABLE>';
if(getoption('site','ord_backcalcgst') != 0) {
$O['BODY'] .= 'GST = <I>'.cur_formatamount($details['sumprice'] - ($details['sumprice'] / (1+getoption('site','ord_backcalcgst')/100))).'</I><BR>';
}
$O['BODY'] .= '<B>Total Cost = <I>'.cur_formatamount($details['sumprice']).'</I></B><BR>';
$O['BODY'] .= '<BR><B>Comments:</B><BR>'.$details['comments'];
}
if($sub_display == 'personal') {
$O['BODY'] .= $font.'Your Personal Details</FONT><BR>
<TABLE BORDER="0" CELLSPACING="1" CELLPADDING="1"><TR>
<TD BGCOLOR="#'.getoption('site','ord_titlebgcolor').'">'.$tfont.'
<B>First Name</TD>
<TD '.$bar1.'>'.$font.'
'.ui_textbox('firstname',client_getval($SITECLIENT,'firstname'),20).'</TD>
</TR><TR>
<TD BGCOLOR="#'.getoption('site','ord_titlebgcolor').'">'.$tfont.'
<B>Last Name</TD>
<TD '.$bar1.'>'.$font.'
'.ui_textbox('lastname',client_getval($SITECLIENT,'lastname'),20).'</TD>
</TR><TR>
<TD BGCOLOR="#'.getoption('site','ord_titlebgcolor').'">'.$tfont.'
<B>Email</TD>
<TD '.$bar1.'>'.$font.'
'.ui_textbox('email',client_getval($SITECLIENT,'email'),30).'<BR>
</TR><TR>
<TD BGCOLOR="#'.getoption('site','ord_titlebgcolor').'">'.$tfont.'
<B>Address</TD>
<TD '.$bar1.'>'.$font.'
'.ui_textbox('address',client_getval($SITECLIENT,'address'),30).'<BR>
</TR><TR>
<TD BGCOLOR="#'.getoption('site','ord_titlebgcolor').'">'.$tfont.'
<B>City/Suburb</TD>
<TD '.$bar1.'>'.$font.'
'.ui_textbox('suburb',client_getval($SITECLIENT,'suburb'),20).'<BR>
</TR><TR>
<TD BGCOLOR="#'.getoption('site','ord_titlebgcolor').'">'.$tfont.'
<B>Post Code</TD>
<TD '.$bar1.'>'.$font.'
'.ui_textbox('postcode',client_getval($SITECLIENT,'postcode'),6).'<BR>
</TR><TR>
<TD BGCOLOR="#'.getoption('site','ord_titlebgcolor').'">'.$tfont.'
<B>State/Province</TD>
<TD '.$bar1.'>'.$font.'
'.ui_textbox('state',client_getval($SITECLIENT,'state'),5).'<BR>
</TR><TR>
<TD BGCOLOR="#'.getoption('site','ord_titlebgcolor').'">'.$tfont.'
<B>Country</TD>
<TD '.$bar1.'>'.$font.'
'.ui_selectbox('country',unserialize(getoption('locale','countries')),client_getval($SITECLIENT,'country','AU')).'
</TR><TR>
<TD BGCOLOR="#'.getoption('site','ord_titlebgcolor').'">'.$tfont.'
<B>Phone</TD>
<TD '.$bar1.'>'.$font.'
'.ui_textbox('phone',client_getval($SITECLIENT,'phone'),15).'<BR>
</TR><TR>
<TD BGCOLOR="#'.getoption('site','ord_titlebgcolor').'">'.$tfont.'
<B>Fax</TD>
<TD '.$bar1.'>'.$font.'
'.ui_textbox('fax',client_getval($SITECLIENT,'fax'),15).'<BR>
</TR></TABLE>';
$O['BODY'] .= '
<INPUT TYPE="HIDDEN" NAME="display" VALUE="account">
<INPUT TYPE="HIDDEN" NAME="sub_display" VALUE="personal">
<INPUT TYPE="HIDDEN" NAME="acc_action" VALUE="savepersonal">';
$O['NEXT'] = formbutton('save','save');
}
if($sub_display == 'current' || $sub_display == 'past') {
if($sub_display == 'past') {
$O['BODY'] .= "<B>Completed Orders</B>";
$result = bsql_query('SELECT a.o_id FROM orders a, orders c
WHERE a.o_id = c.o_id
AND a.o_field = \'clientid\' AND a.o_value = \''.$SITECLIENT.'\'
AND c.o_field = \'status\' AND c.o_value = \'completed\'
ORDER BY a.o_id DESC LIMIT 10') or sdie();
} else {
$O['BODY'] .= "<B>Pending orders and orders in progress.</B>";
$result = bsql_query('SELECT a.o_id FROM orders a, orders c
WHERE a.o_id = c.o_id
AND a.o_field = \'clientid\' AND a.o_value = \''.$SITECLIENT.'\'
AND c.o_field = \'status\' AND (c.o_value = \'inprogress\' OR c.o_value = \'pending\')
ORDER BY a.o_id DESC LIMIT 10') or sdie();
}
$O['BODY'] .= '<TABLE>';
$ORD = new order();
$O['BODY'] .= '<TR><TD CLASS="bar1"><B>Order No:</B></TD><TD CLASS="bar1"><B>Status</B></TD><TD CLASS="bar1"><B>Total Price</B></TD></TR>';
$bar = 1;
while($row = bsql_getrow($result)) {
$ORD->loadorder($row[0]);
if($bar == 1) { $bar = 2; } else { $bar = 1; }
$details = $ORD->getdetails();
$O['BODY'] .= '<TR>
<TD CLASS="bar'.$bar.'"><A HREF="order.php?display=account&acc_action=vieworder&ordid='.$row[0].'">Order No: '.$row[0].'</A></TD>
<TD CLASS="bar'.$bar.'">'.$ORD->getval('status').'</TD>
<TD CLASS="bar'.$bar.'">'.cur_formatamount($details['sumprice']).'</TD></TR>';
}
$O['BODY'] .= '</TABLE>';
}
if($sub_display == 'options') {
$O['BODY'] .= 'Options Currently Un-available';
}
$O['BUTTONS'] = '';
order_display('account',$O);
?>