Location: PHPKode > projects > Bcom > bcom-1.99.1/bcom/ordermanager.php
<?
require_once('lib/libmain.inc');
bcom_init('NORMAL');

require_once('lib/libgeneral.inc');
require_once('lib/liblayout.inc');
require_once('lib/libeditor.inc');
require_once('lib/libui.inc');
require_once('lib/libsite.inc');
require_once('lib/libpages.inc');
require_once('lib/liborder.inc');
require_once('lib/libpayment.inc');
require_once('lib/libclients.inc');
require_once('lib/libmsg.inc');
require_once('lib/libdelivery.inc');

iheader('title=Order manager|javascript');

if(!isset($viewstatus)) { $viewstatus = 'PENDING'; }

if(!session_is_registered('viewstatus')) { $viewstatus = 'PENDING'; }
session_register('viewstatus');
if(isset($set_viewstatus)) { $viewstatus = $set_viewstatus; }

if(!session_is_registered('ord_liststart')) { $ord_liststart = 1; }
session_register('ord_liststart');
if(isset($set_liststart)) { $ord_liststart = $set_liststart; }


if(isset($action)) {
    if($action == 'deleteorder') {
		bsql_query('UPDATE orders SET o_value = \'DELETED\' WHERE o_field = \'status\' AND o_id = '.$orderid);
    }
    if($action == 'savecolors') {
		$save = array('ord_template','ord_font','ord_color','ord_size',
		'ord_titlebgcolor','ord_titlefont','ord_titlecolor','ord_titlesize',
		'ord_bar1color','ord_bar2color','ord_commentrows','ord_commentcols','ord_commentpre','ord_commentpost',
		'ord_tmp_account','ord_tmp_products','ord_tmp_personal','ord_tmp_payment','ord_tmp_shipping',
		'ord_tmp_finish','ord_tmp_complete');
		foreach($save as $item) {
			setoption('site',$item,$HTTP_POST_VARS[$item]);
		}
		$display = 'colors';
    }
	if($action == 'updateorder') {
		if(waspressed('setcomplete')) {
			if(getoption('site','ord_fromaddress') != '') {
				$ORD = new order($orderid);
				$cid = $ORD->getval('clientid');
				if(client_getval($cid,'email') != '') {
					$err = $GLOBALS['_mailer']->send(array(client_getval($cid,'email')),
						array(
							'To' => client_getval($cid,'email'),
							'Subject' => 'Order Completed!',
							'From' => getoption('site','ord_fromaddress'),
							'Content-type' => 'text/html'
						),"Your order has been processed!<BR>\n".$ORD->formatorder('email')
					);
					if(is_object($err)) {
						print($err->getMessage().getoption('site','ord_fromaddress'));
					}
				}
			}
			bsql_query('UPDATE orders SET o_value = \'completed\' WHERE o_field = \'status\' AND o_id = '.$orderid);
			$display = 'orders';
		}
		if($mode == 'close') {
			ui_windowclose();
		}
    }
    if($action == 'openorder') {
		if(!isset($mode)) { $mode = 'normal'; }
		$ORD = new order($orderid);
		print '<FORM METHOD=POST ACTION="'.$PHP_SELF.'" ENCTYPE="multipart/form-data">
		<TABLE BORDER="0" CELLSPACING="2" CELLPADDING="2">
		<TR><TH>Update</TH></TR>
		<TR><TD CLASS="bar1">
		<INPUT TYPE=SUBMIT NAME=setcomplete VALUE="Set to Complete">
		<INPUT TYPE=SUBMIT NAME=exit VALUE="Exit">
		<BR>
		<H3>'.getbutton('delete',$PHP_SELF.'?action=deleteorder&orderid='.$orderid).'</H3>
		<INPUT TYPE=HIDDEN NAME=action VALUE=updateorder>
		<INPUT TYPE=HIDDEN NAME=orderid VALUE="'.$orderid.'">
		<INPUT TYPE=HIDDEN NAME="mode" VALUE="'.$mode.'"><BR>'.$ORD->formatorder('full').'
		</TR></TABLE></FORM>';
		ui_end();
    }
    if($action == 'saveoptions') {
		if(waspressed('activate_signin')) {
			setoption('site','ordermode',1);
		}
		if(waspressed('save')) {
			$PAY = unserialize(getoption('site','paytypes'));
			foreach($PAY as $id => $data) {
				if(isset($GLOBALS["payid$id"])) {
					$PAY[$id]['active'] = 1;
				} else {
					$PAY[$id]['active'] = 0;
				}
			}
			setoption('site','paytypes',serialize($PAY));
			setoption('site','clientgroup',$clientgroup);
			if(!isset($site_taxmode)) { $site_taxmode = 0; }
			setoption('site','site_taxmode',$site_taxmode);
			setoption('site','site_taxname',$site_taxname);
			setoption('site','ord_emailorders',$ord_emailorders);
			setoption('site','ord_fromaddress',$ord_fromaddress);
			setoption('site','ord_backcalcgst',$ord_backcalcgst);
			setoption('site','basecurrency',$basecurrency);
		}
		$display = 'ooptions';
    }
    if($action == 'Disable Shipping') {
		$ord_shipping = 0;
		setoption('site','ord_shipping',0);
		$display = 'shipping'; 
    }
    if($action == 'Enable Shipping') {
		setoption('site','ord_shipping',1);
		$display = 'shipping'; 
    }
    if($action == 'Create Shipping') {
		$SHIPTYPES = unserialize(getoption('site','shiptypes'));
		$lastid++;
		$SHIPTYPES[$lastid]['name'] = $name;
		$SHIPTYPES[$lastid]['charge'] = doubleval($charge);
		setoption('site','shiptypes',serialize($SHIPTYPES));		
		$display = 'shipping';
    }
    if($action == 'deleteshipping') {
		$SHIPTYPES = unserialize(getoption('site','shiptypes'));
		unset($SHIPTYPES[$sid]);
		setoption('site','shiptypes',serialize($SHIPTYPES));		
		$display = 'shipping';
    }
    if($action == 'editshipping') {
		$SHIPTYPES = unserialize(getoption('site','shiptypes'));
		$data = $SHIPTYPES[$sid];
		print '<FORM METHOD=POST ACTION="'.$PHP_SELF.'" ENCTYPE="multipart/form-data">
		<H3>Edit Shipping Entry</H3>
		<TABLE BORDER=0 CELLPADDING=2 CELLSPACING=2><TR><TH>Name</TH><TH>Charge</TH><TH>'.LL('gen-commands').'</TH></TR>
		<TR class=bar1><TD>'.ui_textbox('name',$data['name'],12).'</TD>
		<TD CLASS="bar1">'.ui_textbox('charge',sprintf('%.02f',$data['charge']),6).'</TD>
		<TD CLASS="bar1"><INPUT TYPE="HIDDEN" NAME=action VALUE="updateshipping">'.formbutton('save','save').'</TD></TR>
		<INPUT TYPE=HIDDEN NAME=sid VALUE="'.$sid.'">
		</TABLE></FORM>';
		ui_end();
    }
    if($action == 'updateshipping') {
		$SHIPTYPES = unserialize(getoption('site','shiptypes'));
		$SHIPTYPES[$sid]['name'] = $name;
		$SHIPTYPES[$sid]['charge'] = doubleval($charge);
		setoption('site','shiptypes',serialize($SHIPTYPES));		
		$display = 'shipping';
    }
}

$menu = array('orders' => 'Orders','ooptions' => 'Ordering Options','shipping' => 'Shipping','colors' => 'Colors & Layout');
ui_displaymenu($PHP_SELF.'?display',$menu,'orders');

if($display == 'orders')
{
    print '<TABLE BORDER="0" CELLSPACING="1" CELLPADDING="1">
    <FORM METHOD="POST" ACTION="'.$PHP_SELF.'">
    <TR><TH>Display</TH>
    </TR><TR>
    <TD CLASS="bar1">
    <SELECT NAME="set_viewstatus" onchange="this.form.submit();">
    <OPTION VALUE=pending '.($viewstatus == 'pending'?'SELECTED':'').'>Pending orders
    <OPTION VALUE=completed '.($viewstatus == 'completed'?'SELECTED':'').'>Complete orders
    <OPTION VALUE=inprogress '.($viewstatus == 'inprogress'?'SELECTED':'').'>Orders in progress
    </SELECT>
    <INPUT TYPE=SUBMIT VALUE="Go">
    </TD></TR></FORM></TABLE>';
    
    print '<BR>';
    if($viewstatus == 'pending') { print '<H3>Viewing pending orders</H3>'; }
    if($viewstatus == 'completed') { print '<H3>Viewing completed orders</H3>'; }
    if($viewstatus == 'inprogress') { print '<H3>Viewing orders in progress</H3>'; }
	$result = bsql_query('SELECT a.o_id FROM orders a, orders b
	WHERE a.o_id = b.o_id and a.o_field = \'status\'
	AND a.o_value = \''.$viewstatus.'\' AND b.o_field = \'m_date\'
	ORDER BY b.o_value LIMIT '.($ord_liststart-1).','.($ord_liststart+4)) or sdie('order main',__FILE__,__LINE__);
	$ORD = new order();
	$total = bsql_numrows($result);
	ui_listnav($ord_liststart,$total,5);

	print '<TABLE BORDER="0" CELLSPACING="2" CELLPADDING="2"><TR>
    <TH>Order No</TH>
    <TH>Time</TH>
    <TH>Items</TH>
    <TH>Total $</TH>
    <TH>Customer</TH>
    <TH>Email</TH>
    <TH>Phone</TH>
    <TH>commands</TH></TR>';
    $bar = 1;

	while($row = bsql_getirow($result)) {
		$ORD->loadorder($row[0]);
		$items = 0; $total = 0;
		foreach($ORD->items as $id => $item) {
			$items = $items + $item->getval('quantity');
			$total = $total + $item->getval('quantity') * $item->getval('p_price');
		}
		$clientid = $ORD->getval('clientid');

		$total = sprintf('$%0.2f',$total);
		if($bar == 1) { $bar = 2; } else { $bar = 1; }
		print '<TD CLASS=bar'.$bar.'>'.$ORD->orderid.'</TD>
		<TD CLASS=bar'.$bar.'><B>'.date('h:ia',$ORD->getval('m_date')).'</B>, '.date('dS F Y',$ORD->getval('m_date')).'</B></TD>
		<TD CLASS=bar'.$bar.'>'.$items.'</TD>
		<TD CLASS=bar'.$bar.'>'.$total.'</TD>
		<TD CLASS=bar'.$bar.'>'.client_getval($clientid,'c_name').'&nbsp;</TD>
		<TD CLASS=bar'.$bar.'>'.client_getval($clientid,'email').'&nbsp;</TD>
		<TD CLASS=bar'.$bar.'>'.client_getval($clientid,'phone').'&nbsp;</TD>
		<TD CLASS=bar'.$bar.'>'.getbutton('open',$PHP_SELF.'?action=openorder&orderid='.$ORD->orderid). 
		getbutton('delete',$PHP_SELF.'?action=deleteorder&orderid='.$ORD->orderid).'</TD></TR>';
    }
    bsql_free($result);
    print '</TABLE>';
}

if($display == 'colors')
{
    print '<FORM METHOD=POST ACTION="'.$PHP_SELF.'" ENCTYPE="multipart/form-data">
	<TABLE BORDER="0" CELLSPACING="0" CELLPADDING="0"><TR><TD VALIGN="top">
	<TABLE BORDER="0" CELLSPACING="2" CELLPADDING="2">
    <TR><TH COLSPAN="2">'.LL('gen-commands').'</TH></TR>
    <TR><TD CLASS="bar1" COLSPAN="2">
    <INPUT TYPE=SUBMIT VALUE=Save>
    </TD></TR><TR><TH COLSPAN="2">Ordering templates</TH></TR>
    <TR><TD CLASS="bar1">default:</TD><TD CLASS="bar1">'.ui_smartselect('page','read','ord_template',getoption('site','ord_template')).' (required)<BR><BR></TD></TR>
	<TR><TD CLASS="bar2">products:</TD><TD CLASS="bar2"> '.ui_smartselect('page','read','ord_tmp_products',getoption('site','ord_tmp_products')).'</TD></TR>
	<TR><TD CLASS="bar1">personal:</TD><TD CLASS="bar1"> '.ui_smartselect('page','read','ord_tmp_personal',getoption('site','ord_tmp_personal')).'</TD></TR>
	<TR><TD CLASS="bar2">payment:</TD><TD CLASS="bar2"> '.ui_smartselect('page','read','ord_tmp_payment',getoption('site','ord_tmp_payment')).'</TD></TR>
	<TR><TD CLASS="bar1">shipping:</TD><TD CLASS="bar1"> '.ui_smartselect('page','read','ord_tmp_shipping',getoption('site','ord_tmp_shipping')).'</TD></TR>
	<TR><TD CLASS="bar2">finish:</TD><TD CLASS="bar2"> '.ui_smartselect('page','read','ord_tmp_finish',getoption('site','ord_tmp_finish')).'</TD></TR>
	<TR><TD CLASS="bar1">complete:</TD><TD CLASS="bar1"> '.ui_smartselect('page','read','ord_tmp_complete',getoption('site','ord_tmp_complete')).'</TD></TR>
	<TR><TD CLASS="bar2">account:</TD><TD CLASS="bar2"> '.ui_smartselect('page','read','ord_tmp_account',getoption('site','ord_tmp_account')).'</TD></TR>
	</TABLE></TD><TD VALIGN="top"><TABLE BORDER="0" CELLSPACING="2" CELLPADDING="2">
    <TR><TH>Text Style</TH></TR>
    <TR><TD CLASS="bar2"><B>Font:</B> '.fontfield('ord_font',getoption('site','ord_font'));
    print '<B>Color:</B> '.colorfield('ord_color',getoption('site','ord_color'));
    print '<B>Size:</B> '.sizefield('ord_size',getoption('site','ord_size'));

    echo '</TD></TR>
    <TR><TH>Title Style</TH></TR>
    <TR><TD CLASS=bar1><B>BG Color:</B> '.colorfield('ord_titlebgcolor',getoption('site','ord_titlebgcolor')).'<BR>';
    print '<B>Font:</B> '.fontfield('ord_titlefont',getoption('site','ord_titlefont'));
    print '<B>Color:</B> '.colorfield('ord_titlecolor',getoption('site','ord_titlecolor'));
    print '<B>Size:</B> '.sizefield('ord_titlesize',getoption('site','ord_titlesize'));
    echo '</TD></TR>
    <TR><TH>Alternating Bar Colors</TH></TR>
    <TR><TD CLASS=bar1>';
    print '<B>Bar1:</B> '.colorfield('ord_bar1color',getoption('site','ord_bar1color'));
    print '<B>Bar2:</B> '.colorfield('ord_bar2color',getoption('site','ord_bar2color'));
    print '</TD></TR><TR><TH>Comments Section</TH></TR><TR><TD CLASS="bar1">
    Comments box size: '.ui_textbox('ord_commentcols',getoption('site','ord_commentcols'),3,3).' cols by '.ui_textbox('ord_commentrows',getoption('site','ord_commentrows'),3,3).' rows<BR>
    Comments box prefix: '.ui_textbox('ord_commentpre',getoption('site','ord_commentpre'),40).'<BR>
    Comments box postfix: '.ui_textbox('ord_commentpost',getoption('site','ord_commentpost'),40).'<BR>
	</TD></TR></TABLE></TD></TR></TABLE><INPUT TYPE=HIDDEN NAME="action" VALUE="savecolors"></FORM>';
}

if($display == 'ooptions')
{
    print '<FORM METHOD=POST ACTION="'.$PHP_SELF.'" ENCTYPE="multipart/form-data">
    <TABLE BORDER="0" CELLSPACING="2" CELLPADDING="2" WIDTH="600">
    <TR><TH>Commands</TH><TH>General Options</TH></TR>
    <TR>
	<TD CLASS=bar1>'.formbutton('save','save').'</TD>
	<TD CLASS="bar1" COLSPAN="2" NOWRAP>
		<B>Base site client group:</B>'.ui_smartselect('clientgroup','write','clientgroup',getoption('site','clientgroup',$BTYPE['defgroup']['client'])).'<BR>
		';
	if(getoption('site','ordermode') != 1) {
		print'	<B>Activate signin ordering mode: </B>'.formbutton('activate_signin','activate','Are you sure you wish to enable\nsignin ordering mode?\n\nThis action cannot be reversed.').'<BR>
			note: once enabled, signin ordering mode cannot be disabled!!';	
	}
	print '</TD>
	</TR>
    <TR>
    <TH COLSPAN="2">Emailing options</TH>
    </TR>
	<TR>
    <TD CLASS="bar1" COLSPAN="2"><B>Order notification address: </B>'.ui_textbox('ord_emailorders',getoption('site','ord_emailorders'),30).'
    <BR>If set, this will send an order notification to the address above. For security reasons, it will not send credit card details, so order
    processing must still be done from within bcom.<BR>
	<B>Order return address: </B>'.ui_textbox('ord_fromaddress',getoption('site','ord_fromaddress'),30).'
    <BR>This is the address that  client order notifaction is sent from when an order is created
    or completed. If not set, no email is sent.</TD>
    </TR>
    <TR>
		<TH>Payment Types</TH>
		<TH>Tax Options</TH>
	</TR>
    <TR>
		<TD VALIGN="TOP" CLASS="bar1" ROWSPAN="3">
			<TABLE BORDERS="0" CELLPADDING="2" CELLSPACING="2">
	<TR><TD CLASS=bar1><B>Type</B></TD><TD CLASS=bar1><B>Name</B></TD><TD CLASS=bar1><B>Available</B></TD></TR>';
    $PAY = unserialize(getoption('site','paytypes'));
    $bar = 2;
	foreach($PAY as $id => $data) {
		if($bar == 1) { $bar = 2; } else { $bar = 1; } 
		print '<TR><TD CLASS="bar'.$bar.'">'.$data['type'].'</TD><TD CLASS="bar'.$bar.'">'.$data['name'].'</TD><TD CLASS="bar'.$bar.'">';
		if($data['active'] != 0) {
			print '<INPUT TYPE=CHECKBOX NAME=payid'.$id.' CHECKED>';
		} else {
			print '<INPUT TYPE=CHECKBOX NAME=payid'.$id.'>';
		}
		print '</TD></TR>';
    }
    if(getoption('site','site_taxmode') == 1) { $taxcheck = 'CHECKED'; } else { $taxcheck = ''; }
    print '</TABLE></TD>
    <TD VALIGN=TOP  CLASS=bar1>
	<B>Show Tax: </B><INPUT TYPE=CHECKBOX NAME=site_taxmode VALUE=1 '.$taxcheck.'>
	<B>Tax Name: </B>'.ui_textbox('site_taxname',getoption('site','site_taxname')).'<BR>
	<B>Perform Tax Total at </B>'.ui_textbox('ord_backcalcgst',getoption('site','ord_backcalcgst'),3,3).'%<BR>
	<SPAN STYLE="font-size: '.(getuseroption('theme','fontsize',10)*.8).'pt">(set to 0 to remove GST total)</SPAN>
    </TD>
    </TR><TR><TH>Currency Settings</TH></TR>
	    <TR>
	<TD CLASS="bar1">
	<B>Default Currency:</B><BR><SELECT NAME="basecurrency">';
    foreach($CURRENCIES as $code => $name) {
		print '<OPTION VALUE="'.$code.'" '.($code==getoption('site','basecurrency')?'SELECTED':'').'>'.$name;
    }
    print '</SELECT>
    </TD>
	</TR>
	</TABLE>
        <INPUT TYPE=HIDDEN NAME=action VALUE=saveoptions>
    </FORM>';
}
if($display == 'shipping')
{
    print '<FORM METHOD=POST ACTION="'.$PHP_SELF.'" ENCTYPE="multipart/form-data">
    <TABLE BORDER=0 CELLSPACING=2 CELLPADDING=2>
    <TR><TH>Shipping Enable/Disable</TH>
    <TR><TD CLASS=bar1>';
    if(getoption('site','ord_shipping') == 1) {
		print 'Shipping is <B>currently enabled</B>. Press the disable button to disable it.
		<INPUT TYPE=SUBMIT NAME=action VALUE="Disable Shipping">';
    } else {
    	print 'Shipping is <B>currently disabled</B>. Press the enable button to enable it.
		<INPUT TYPE=SUBMIT NAME=action VALUE="Enable Shipping">';
    }
    print '</TD></TR></TABLE>'; $bar = 'bar1';
    print '<H3>Shipping Types</H3><TABLE BORDER=0 CELLSPACING=2 CELLPADDING=2>
    <TR><TH>Name</TH><TH>Charge</TH><TH>Commands</TH></TR>';
	$SHIPTYPES = unserialize(getoption('site','shiptypes')); $id = 0;
	if(is_array($SHIPTYPES)) {
		foreach($SHIPTYPES as $id => $data) {
			if($bar == 'bar1') { $bar = 'bar2'; } else { $bar = 'bar1'; }
			print '<TR><TD CLASS='.$bar.'>'.$data['name'].'</TD><TD CLASS='.$bar.'>'.sprintf('$%.02f',$data['charge']).'</TD>
			<TD CLASS='.$bar.'>'.getbutton('edit',$PHP_SELF.'?action=editshipping&sid='.$id)
			.getbutton('delete',$PHP_SELF.'?action=deleteshipping&sid='.$id).'</TD></TR>';
		}
	}
	print '</TABLE>
    <H3>Add Shipping Type</H3>
    <TABLE BORDER=0 CELLPADDING=2 CELLSPACING=2><TR><TH>Name</TH><TH>Charge</TH><TH>Create</TH></TR>
    <TR><TD CLASS=bar1>'.ui_textbox('name','').'</TD><TD CLASS=bar1>'.ui_textbox('charge','',6).'</TD><TD CLASS=bar1><INPUT TYPE=SUBMIT NAME=action VALUE="Create Shipping"></TD></TR>
    </TABLE><INPUT TYPE="HIDDEN" NAME="lastid" VALUE="'.$id.'"></FORM>';
}

ui_autodisplay();
ui_end();
?>
Return current item: Bcom