-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreceipt.php
executable file
·56 lines (44 loc) · 1.66 KB
/
receipt.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
<?php
require_once('functions.php');
require_once('./includes/dvd.inc');
$connection = ConnectToDatabase();
$user = User::GetCurrentUser($connection);
$template = NewPage($user);
// Include the receipt template fragment
$template->addBlockFile("CONTENT", "RECEIPT", "receipt.tpl");
//Get movie and quantity from session.
$checkout = $_SESSION["checkout"];
$totalCost = 0.00;
if(empty($checkout)){
// Show empty cart message
$template->setCurrentBlock("ERROR");
$template->setVariable("MESSAGE", "Your currently have no DVD checked out.");
$template->parseCurrentBlock( );
}else{
//Show order
foreach($checkout as $movie_id => $quantity){
// Get inventory information
$inventory = getInventory($movie_id, $connection);
// Get movie name
$name = getMovieName($movie_id, $connection);
// Work with the ITEM block
$template->setCurrentBlock("ITEM");
$template->setVariable("MOVIE_NAME", $name);
$template->setVariable("QTY", $quantity);
$template->setVariable("PRICE", $inventory["cost"]);
$template->setVariable("TOTAL", $inventory["cost"] * $quantity);
$template->parseCurrentBlock( );
// Get the total cost
$totalCost += $inventory["cost"]*$quantity;
}
// Destroy session of order information
session_destroy();
// Display order date and total bill.
$template->setCurrentBlock("ORDER");
$template->setVariable("DATE", date("Y/m/d"));
$template->setVariable("ORDER_TOTAL", $totalCost);
$template->parseCurrentBlock( );
}
// Output the web page
$template->show( );
?>