/
output_fns.php
429 lines (406 loc) · 12.8 KB
/
output_fns.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
<?php
function do_html_header($title = '') {
// print an HTML header
// declare the session variables we want access to inside the function
if (!session_id()){
session_start();
}
if(isset($_SESSION['items']))
if (!$_SESSION['items']) {
$_SESSION['items'] = '0';
}
if(isset($_SESSION['total_price']))
if (!$_SESSION['total_price']) {
$_SESSION['total_price'] = '0.00';
}
?>
<html>
<head>
<title><?php echo $title; ?></title>
<style>
h2 { font-family: Arial, Helvetica, sans-serif; font-size: 22px; color: red; margin: 6px }
body { font-family: Arial, Helvetica, sans-serif; font-size: 13px }
li, td { font-family: Arial, Helvetica, sans-serif; font-size: 13px }
hr { color: #FF0000; width=70%; text-align=center}
a { color: #000000 }
</style>
</head>
<body>
<table width="100%" border="0" cellspacing="0" bgcolor="#cccccc">
<tr>
<td rowspan="2">
<a href="index.php"><img src="images/Book-O-Rama.gif" alt="Bookorama" border="0"
align="left" valign="bottom" height="55" width="325"/></a>
</td>
<td align="right" valign="bottom">
<?php
if(isset($_SESSION['admin_user'])) {
echo " ";
} else {
if(isset($_SESSION['items']))
echo "Total Items = ".$_SESSION['items'];
}
?>
</td>
<td align="right" rowspan="2" width="135">
<?php
if(isset($_SESSION['admin_user'])) {
display_button('logout.php', 'log-out', 'Log Out');
} else {
display_button('show_cart.php', 'view-cart', 'View Your Shopping Cart');
}
?>
</tr>
<tr>
<td align="right" valign="top">
<?php
if(isset($_SESSION['admin_user'])) {
echo " ";
} else {
if(isset($_SESSION['total_price']))
echo "Total Price = $".number_format($_SESSION['total_price'],2);
}
?>
</td>
</tr>
</table>
<?php
if($title) {
do_html_heading($title);
}
}
function do_html_footer() {
// print an HTML footer
?>
</body>
</html>
<?php
}
function do_html_heading($heading) {
// print heading
?>
<h2><?php echo $heading; ?></h2>
<?php
}
function do_html_URL($url, $name) {
// output URL as link and br
?>
<a href="<?php echo $url; ?>"><?php echo $name; ?></a><br />
<?php
}
function display_categories($cat_array) {
if (!is_array($cat_array)) {
echo "<p>No categories currently available</p>";
return;
}
echo "<ul>";
foreach ($cat_array as $row) {
$url = "show_cat.php?catid=".$row['catid'];
$title = $row['catname'];
echo "<li>";
do_html_url($url, $title);
echo "</li>";
}
echo "</ul>";
echo "<hr />";
}
function display_books($book_array) {
//display all books in the array passed in
if (!is_array($book_array)) {
echo "<p>No books currently available in this category</p>";
} else {
//create table
echo "<table width=\"100%\" border=\"0\">";
//create a table row for each book
foreach ($book_array as $row) {
$url = "show_book.php?isbn=".$row['isbn'];
echo "<tr><td>";
if (@file_exists("images/".$row['isbn'].".jpg")) {
$title = "<img src=\"images/".$row['isbn'].".jpg\"
style=\"border: 1px solid black\"/>";
do_html_url($url, $title);
} else {
echo " ";
}
echo "</td><td>";
$title = $row['title']." by ".$row['author'];
do_html_url($url, $title);
echo "</td></tr>";
}
echo "</table>";
}
echo "<hr />";
}
function display_book_details($book) {
// display all details about this book
if (is_array($book)) {
echo "<table><tr>";
//display the picture if there is one
if (@file_exists("images/".$book['isbn'].".jpg")) {
$size = GetImageSize("images/".$book['isbn'].".jpg");
if(($size[0] > 0) && ($size[1] > 0)) {
echo "<td><img src=\"images/".$book['isbn'].".jpg\"
style=\"border: 1px solid black\"/></td>";
}
}
echo "<td><ul>";
echo "<li><strong>Author:</strong> ";
echo $book['author'];
echo "</li><li><strong>ISBN:</strong> ";
echo $book['isbn'];
echo "</li><li><strong>Our Price:</strong> ";
echo number_format($book['price'], 2);
echo "</li><li><strong>Description:</strong> ";
echo $book['description'];
echo "</li></ul></td></tr></table>";
} else {
echo "<p>The details of this book cannot be displayed at this time.</p>";
}
echo "<hr />";
}
function display_checkout_form() {
//display the form that asks for name and address
?>
<br />
<table border="0" width="100%" cellspacing="0">
<form action="purchase.php" method="post">
<tr><th colspan="2" bgcolor="#cccccc">Your Details</th></tr>
<tr>
<td>Name</td>
<td><input type="text" name="name" value="" maxlength="40" size="40"/></td>
</tr>
<tr>
<td>Address</td>
<td><input type="text" name="address" value="" maxlength="40" size="40"/></td>
</tr>
<tr>
<td>City/Suburb</td>
<td><input type="text" name="city" value="" maxlength="20" size="40"/></td>
</tr>
<tr>
<td>State/Province</td>
<td><input type="text" name="state" value="" maxlength="20" size="40"/></td>
</tr>
<tr>
<td>Postal Code or Zip Code</td>
<td><input type="text" name="zip" value="" maxlength="10" size="40"/></td>
</tr>
<tr>
<td>Country</td>
<td><input type="text" name="country" value="" maxlength="20" size="40"/></td>
</tr>
<tr><th colspan="2" bgcolor="#cccccc">Shipping Address (leave blank if as above)</th></tr>
<tr>
<td>Name</td>
<td><input type="text" name="ship_name" value="" maxlength="40" size="40"/></td>
</tr>
<tr>
<td>Address</td>
<td><input type="text" name="ship_address" value="" maxlength="40" size="40"/></td>
</tr>
<tr>
<td>City/Suburb</td>
<td><input type="text" name="ship_city" value="" maxlength="20" size="40"/></td>
</tr>
<tr>
<td>State/Province</td>
<td><input type="text" name="ship_state" value="" maxlength="20" size="40"/></td>
</tr>
<tr>
<td>Postal Code or Zip Code</td>
<td><input type="text" name="ship_zip" value="" maxlength="10" size="40"/></td>
</tr>
<tr>
<td>Country</td>
<td><input type="text" name="ship_country" value="" maxlength="20" size="40"/></td>
</tr>
<tr>
<td colspan="2" align="center"><p><strong>Please press Purchase to confirm
your purchase, or Continue Shopping to add or remove items.</strong></p>
<?php display_form_button("purchase", "Purchase These Items"); ?>
</td>
</tr>
</form>
</table><hr />
<?php
}
function display_shipping($shipping) {
// display table row with shipping cost and total price including shipping
?>
<table border="0" width="100%" cellspacing="0">
<tr><td align="left">Shipping</td>
<td align="right"> <?php echo number_format($shipping, 2); ?></td></tr>
<tr><th bgcolor="#cccccc" align="left">TOTAL INCLUDING SHIPPING</th>
<th bgcolor="#cccccc" align="right">$ <?php echo number_format($shipping+$_SESSION['total_price'], 2); ?></th>
</tr>
</table><br />
<?php
}
function display_card_form($name) {
//display form asking for credit card details
?>
<table border="0" width="100%" cellspacing="0">
<form action="process.php" method="post">
<tr><th colspan="2" bgcolor="#cccccc">Credit Card Details</th></tr>
<tr>
<td>Type</td>
<td><select name="card_type">
<option value="VISA">VISA</option>
<option value="MasterCard">MasterCard</option>
<option value="American Express">American Express</option>
</select>
</td>
</tr>
<tr>
<td>Number</td>
<td><input type="text" name="card_number" value="" maxlength="16" size="40"></td>
</tr>
<tr>
<td>AMEX code (if required)</td>
<td><input type="text" name="amex_code" value="" maxlength="4" size="4"></td>
</tr>
<tr>
<td>Expiry Date</td>
<td>Month
<select name="card_month">
<option value="01">01</option>
<option value="02">02</option>
<option value="03">03</option>
<option value="04">04</option>
<option value="05">05</option>
<option value="06">06</option>
<option value="07">07</option>
<option value="08">08</option>
<option value="09">09</option>
<option value="10">10</option>
<option value="11">11</option>
<option value="12">12</option>
</select>
Year
<select name="card_year">
<?
for ($y = date("Y"); $y < date("Y") + 10; $y++) {
echo "<option value=\"".$y."\">".$y."</option>";
}
?>
</select>
</tr>
<tr>
<td>Name on Card</td>
<td><input type="text" name="card_name" value = "<?php echo $name; ?>" maxlength="40" size="40"></td>
</tr>
<tr>
<td colspan="2" align="center">
<p><strong>Please press Purchase to confirm your purchase, or Continue Shopping to
add or remove items</strong></p>
<?php display_form_button('purchase', 'Purchase These Items'); ?>
</td>
</tr>
</table>
<?php
}
function display_cart($cart, $change = true, $images = 1) {
// display items in shopping cart
// optionally allow changes (true or false)
// optionally include images (1 - yes, 0 - no)
echo "<table border=\"0\" width=\"100%\" cellspacing=\"0\">
<form action=\"show_cart.php\" method=\"post\">
<tr><th colspan=\"".(1 + $images)."\" bgcolor=\"#cccccc\">Item</th>
<th bgcolor=\"#cccccc\">Price</th>
<th bgcolor=\"#cccccc\">Quantity</th>
<th bgcolor=\"#cccccc\">Total</th>
</tr>";
//display each item as a table row
foreach ($cart as $isbn => $qty) {
$book = get_book_details($isbn);
echo "<tr>";
if($images == true) {
echo "<td align=\"left\">";
if (file_exists("images/".$isbn.".jpg")) {
$size = GetImageSize("images/".$isbn.".jpg");
if(($size[0] > 0) && ($size[1] > 0)) {
echo "<img src=\"images/".$isbn.".jpg\"
style=\"border: 1px solid black\"
width=\"".($size[0]/3)."\"
height=\"".($size[1]/3)."\"/>";
}
} else {
echo " ";
}
echo "</td>";
}
echo "<td align=\"left\">
<a href=\"show_book.php?isbn=".$isbn."\">".$book['title']."</a>
by ".$book['author']."</td>
<td align=\"center\">\$".number_format($book['price'], 2)."</td>
<td align=\"center\">";
// if we allow changes, quantities are in text boxes
if ($change == true) {
echo "<input type=\"text\" name=\"".$isbn."\" value=\"".$qty."\" size=\"3\">";
} else {
echo $qty;
}
echo "</td><td align=\"center\">\$".number_format($book['price']*$qty,2)."</td></tr>\n";
}
// display total row
echo "<tr>
<th colspan=\"".(2+$images)."\" bgcolor=\"#cccccc\"> </td>
<th align=\"center\" bgcolor=\"#cccccc\">".$_SESSION['items']."</th>
<th align=\"center\" bgcolor=\"#cccccc\">
\$".number_format($_SESSION['total_price'], 2)."
</th>
</tr>";
// display save change button
if($change == true) {
echo "<tr>
<td colspan=\"".(2+$images)."\"> </td>
<td align=\"center\">
<input type=\"hidden\" name=\"save\" value=\"true\"/>
<input type=\"image\" src=\"images/save-changes.gif\"
border=\"0\" alt=\"Save Changes\"/>
</td>
<td> </td>
</tr>";
}
echo "</form></table>";
}
function display_login_form() {
// dispaly form asking for name and password
?>
<form method="post" action="admin.php">
<table bgcolor="#cccccc">
<tr>
<td>Username:</td>
<td><input type="text" name="username"/></td></tr>
<tr>
<td>Password:</td>
<td><input type="password" name="passwd"/></td></tr>
<tr>
<td colspan="2" align="center">
<input type="submit" value="Log in"/></td></tr>
<tr>
</table></form>
<?php
}
function display_admin_menu() {
?>
<br />
<a href="index.php">Go to main site</a><br />
<a href="insert_category_form.php">Add a new category</a><br />
<a href="insert_book_form.php">Add a new book</a><br />
<a href="change_password_form.php">Change admin password</a><br />
<?php
}
function display_button($target, $image, $alt) {
echo "<div align=\"center\"><a href=\"".$target."\">
<img src=\"images/".$image.".gif\"
alt=\"".$alt."\" border=\"0\" height=\"50\"
width=\"135\"/></a></div>";
}
function display_form_button($image, $alt) {
echo "<div align=\"center\"><input type=\"image\"
src=\"images/".$image.".gif\"
alt=\"".$alt."\" border=\"0\" height=\"50\"
width=\"135\"/></div>";
}
?>