1 area was for shipped items and one was for unshipped items.
I've been readling lately about OOP and how I should be maximizing code re-use etc and I think this is a good one to start on.
How wold you guys go about rewriting this?
Is your coding style vastly different from mine?
Would you actually use a framework that consists of dozens and dozens of files just to build this simple thing?
So please give me your suggestions and I'll try apply them to this and see if I can wind up with something easier to read, and with a hell of a lot less duplication.
The output can be seen here:
http://thinsoldier.com/wip/php/ref1.png
http://thinsoldier.com/wip/php/ref2.png
The only differences between the 2 files are on lines:
6
8
21
36
42
44
86
pending.php
Code: Select all
<?php
include_once('../scripts/php/config.php');
include_once('../scripts/php/admin.session.php');
if($cmd == 'markshipped')
{
$today = date("Y-m-d");
$sql = "UPDATE orders SET status='shipped',date_shipped=$today WHERE order_id=$orderID LIMIT 1";
mysql_query($sql);
}
if($cmd == 'markcancelled')
{
$sql = "UPDATE orders SET status='cancelled' WHERE order_id=$orderID LIMIT 1";
mysql_query($sql);
}
$H = new HTMLHead($ADMINHEAD);
$H->PrefixTitle("Pending Orders - ");
$H->LinkCSS('orders.css');
$H->ExtraCSS('#leftbar li#orders-sub, #leftbar li#orders-sub .sub-menu{display:block;}');
echo $H->Output();
?>
<div id="admin-container">
<?php
include('../includes/inc.admin_header.php');
include('../includes/inc.admin_navigation.php');
?>
<div id="content">
<h2>Pending Orders</h2>
<?
include_once('order_classes.php');
$sql = "SELECT * FROM orders WHERE status='pending' ORDER BY date_ordered DESC";
$pgn8 = new pagination($sql, 5, 'pgn8_pending_sql');
$pageResult = $pgn8->findPageResult();
while ($allorders = mysql_fetch_assoc($pageResult))
{
$o = new OrderInfo($allorders[order_id]);
$Orders[] = $o;
}
?>
<? echo $pgn8->showingFromTo();?>
<? echo $pgn8->displayPagination(); ?>
<table class="datatable">
<thead>
<th scope="col">Order</th>
<th scope="col">Purchased Items</th>
<th scope="col">Status</th>
<th></th>
<th></th>
<thead>
<?
foreach($Orders as $O)
{
echo '<tr>';
echo '<td>';
echo '<b>'.date(" F d, Y", strtotime($O->Order[date_ordered])).'</b><br />';
echo 'Order ID: '.str_replace('-','',$O->Order[date_ordered]).'-'.$O->Order['order_id'].'<br />';
echo 'Bill to: '.$O->Billing[card_name]. '<br />';
echo 'Ship to: '.$O->Shipping[name];
echo '</td><td>';
foreach($O->Purchased as $P)
{echo $P[name].' x '.$P[quantity].'<br />'; }
echo '<b>Subtotal: $'.number_format($O->Order[subtotal],2).'</b>';
echo '</td><td>';
echo ucwords($O->Order[status]);
echo '</td><td>';
echo '<ul>';
printf('<li><a href="%s?page=%s&cmd=markshipped&orderID=%s">Mark as Shipped</a></li>',thispage(),$page,$O->Order['order_id'] );
printf('<li><a href="%s?page=%s&cmd=markcancelled&orderID=%s">Cancel Order</a></li>',thispage(),$page,$O->Order['order_id'] );
echo '</ul>';
echo '</td><td>';
printf('<a class="view" href="order_view.php?page=%s&orderID=%s">View Details</a>',$page,$O->Order['order_id'] );
echo '</td></tr>';
echo '<tr><td colspan="5" class="xhrdetail"></td></tr>';
}
?>
</table>
<? echo $pgn8->displayPagination(); ?>
</div>
<?php
include('../includes/inc.admin_footer.php');
?>
</div>
</body>
</html>
Code: Select all
<?php
include_once('../scripts/php/config.php');
include_once('../scripts/php/admin.session.php');
if($cmd == 'markpending')
{
$sql = "UPDATE orders SET status='pending', date_shipped='' WHERE order_id=$orderID LIMIT 1";
mysql_query($sql);
}
$H = new HTMLHead($ADMINHEAD);
$H->PrefixTitle("Shipped Orders - ");
$H->LinkCSS('orders.css');
$H->ExtraCSS('#leftbar li#orders-sub, #leftbar li#orders-sub .sub-menu{display:block;}');
echo $H->Output();
?>
<div id="admin-container">
<?php
include('../includes/inc.admin_header.php');
include('../includes/inc.admin_navigation.php');
?>
<div id="content">
<h2>Shipped Orders</h2>
<?
include_once('order_classes.php');
$sql = "SELECT * FROM orders WHERE status='shipped' ORDER BY date_ordered DESC";
$pgn8 = new pagination($sql, 5, 'pgn8_shipped_sql');
$pageResult = $pgn8->findPageResult();
while ($allorders = mysql_fetch_assoc($pageResult))
{
$o = new OrderInfo($allorders[order_id]);
$Orders[] = $o;
}
?>
<? echo $pgn8->showingFromTo();?>
<? echo $pgn8->displayPagination(); ?>
<table class="datatable">
<thead>
<th scope="col">Order</th>
<th scope="col">Purchased Items</th>
<th scope="col">Status</th>
<th></th>
<th></th>
<thead>
<?
foreach($Orders as $O)
{
echo '<tr>';
echo '<td>';
echo '<b>'.date(" F d, Y", strtotime($O->Order[date_ordered])).'</b><br />';
echo 'Order ID: '.str_replace('-','',$O->Order[date_ordered]).'-'.$O->Order['order_id'].'<br />';
echo 'Bill to: '.$O->Billing[card_name]. '<br />';
echo 'Ship to: '.$O->Shipping[name];
echo '</td><td>';
foreach($O->Purchased as $P)
{echo $P[name].' x '.$P[quantity].'<br />'; }
echo '<b>Subtotal: $'.number_format($O->Order[subtotal],2).'</b>';
echo '</td><td>';
echo ucwords($O->Order[status]);
echo '</td><td>';
echo '<ul>';
printf('<li><a href="%s?page=%s&cmd=markpending&orderID=%s">Mark as Pending</a></li>',thispage(),$page,$O->Order['order_id'] );
//printf('<li><a href="%s?page=%s&cmd=markcancelled&orderID=%s">Cancel Order</a></li>',thispage(),$page,$O->Order['order_id'] );
echo '</ul>';
echo '</td><td>';
printf('<a class="view" href="order_view.php?page=%s&orderID=%s">View Details</a>',$page,$O->Order['order_id'] );
echo '</td></tr>';
echo '<tr><td colspan="5" class="xhrdetail"></td></tr>';
}
?>
</table>
<? echo $pgn8->displayPagination(); ?>
</div>
<?php
include('../includes/inc.admin_footer.php');
?>
</div>
</body>
</html>