I am to take the following code and make it use two user defined functions.
One function is supposed to process the "order" information. The second is supposed to write the information to a text file. Problem is, I don't know where to start, and the writing of the information technically already uses the non-user defined fopen function.
<?php
require('header.inc');
?>
<?php
$DOCUMENT_ROOT = $_SERVER['DOCUMENT_ROOT']//."/genesis/web_pages/joviyach";
?>
<html>
<head>
<title>Bob's Auto Parts - Order Results</title>
</head>
<body>
<h1>Bob's Auto Parts</h1>
<h2>Order Results</h2>
<?php
$date = date('H:i, jS F');
echo '<p>Order processed at ';
echo $date;
echo '</p>';
echo '<p>Your order is as follows: </p>';
$totalqty = 0;
$totalqty = $POST['tireqty'] + $POST['oilqty'] + $POST['sparkqty']
+ $POST['coolqty'] + $_POST['wiperqty'];
echo 'Items ordered: '.$totalqty.'<br />';
if( $totalqty == 0)
{
echo 'You did not order anything on the previous page!<br />';
}
else
{
if ( $POST['tireqty']>0 )
echo $POST['tireqty'].' tires<br />';
if ( $POST['oilqty']>0 )
echo $POST['oilqty'].' bottles of oil<br />';
if ( $POST['sparkqty']>0 )
echo $POST['sparkqty'].' spark plugs<br />';
if ( $POST['coolqty']>0 )
echo $POST['coolqty'].' coolant<br />';
if ( $POST['wiperqty']>0 )
echo $POST['wiperqty'].' wiper blades<br />';
}
$totalamount = 0.00;
define('TIREPRICE', 100);
define('OILPRICE', 10);
define('SPARKPRICE', 4);
define('COOLPRICE', 1);
define('WIPERPRICE', 3);
$totalamount = $POST['tireqty'] TIREPRICE + $POST['oilqty'] OILPRICE + $POST['sparkqty'] SPARKPRICE
+ $POST['coolqty'] COOLPRICE + $_POST['wiperqty'] * WIPERPRICE;
$totalamount = $totalamount + ($totalamount * .10);
$totalamount=number_format($totalamount, 2, '.', ' ');
echo '<p>Total of order is '.$totalamount.'</p>';
echo '<p>Address to ship to is '.$_POST['address'].'</p>';
$outputstring = $date."\t".$POST['tireqty']." tires \t".$POST['oilqty']." oil\t"
.$POST['sparkqty']." spark plugs\t".$POST['coolqty']." coolant\t"
.$POST['wiperqty']." wiper blades\t\$".$totalamount
."\t". $POST['address']."\n";
// open file for appending
@ $fp = fopen("$DOCUMENT_ROOT/folder2/orders.txt", 'ab');
flock($fp, LOCK_EX);
if (!$fp)
{
echo '<p><strong> Your order could not be processed at this time. '
.'Please try again later.</strong></p></body></html>';
exit;
}
fwrite($fp, $outputstring, strlen($outputstring));
flock($fp, LOCK_UN);
fclose($fp);
echo '<p>Order written.</p>';
?>
<p> Click <A HREF="vieworders2.php"><I>HERE</I></A> to see all submitted orders.</p>
<p> Click <A HREF="bobs_front_page.php"><I>HERE</I></A> to go to the home page.</p>
<p> Or click <A HREF="orderform-c.php"><STRONG>HERE</STRONG></A> to spend some more money.</p>
</body>
<?php
require('footer.inc');
?>
</html>
[/B][/COLOR]