-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathorders.php
More file actions
220 lines (214 loc) · 8.98 KB
/
orders.php
File metadata and controls
220 lines (214 loc) · 8.98 KB
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
<?php
session_start();
if (!isset($_SESSION['loggedin'])) {
header("Location: login.php");
exit;
}
include_once 'orders_crud.php';
$is_admin = $_SESSION['user_level'] === 'admin';
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Lenovo Ordering System : Orders</title>
<!-- Bootstrap -->
<link href="css/bootstrap.min.css" rel="stylesheet">
<link rel="shortcut icon" type="image/jpg" href="logo.png"/>
</head>
<body>
<?php include_once 'nav_bar.php'; ?>
<div class="container-fluid">
<div class="row">
<div class="col-xs-12 col-sm-8 col-sm-offset-2 col-md-6 col-md-offset-3">
<div class="page-header">
<h2>Create New Order</h2>
</div>
<form action="orders.php" method="post" class="form-horizontal">
<div class="form-group">
<label for="orderid" class="col-sm-3 control-label">Order ID</label>
<div class="col-sm-9">
<input name="oid" type="text" class="form-control" id="orderid" placeholder="Order ID" readonly value="" value="<?php if(isset($_GET['edit'])) echo $editrow['fld_order_num']; ?>" required>
</div>
</div>
<div class="form-group">
<label for="orderdate" class="col-sm-3 control-label">Order Date</label>
<div class="col-sm-9">
<input name="orderdate" type="text" class="form-control" id="orderdate" placeholder="Order Date" readonly value="" value="<?php if(isset($_GET['edit'])) echo $editrow['fld_order_date']; ?>" required>
</div>
</div>
<div class="form-group">
<label for="staffid" class="col-sm-3 control-label">Staff</label>
<div class="col-sm-9">
<select name="sid" class="form-control" id="staffid" required>
<?php
try {
$conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$stmt = $conn->prepare("SELECT * FROM tbl_staffs_a186687_pt2");
$stmt->execute();
$result = $stmt->fetchAll();
}
catch(PDOException $e){
echo "Error: " . $e->getMessage();
}
foreach($result as $staffrow) {
?>
<?php if((isset($_GET['edit'])) && ($editrow['fld_staff_num']==$staffrow['fld_staff_id'])) { ?>
<option value="<?php echo $staffrow['fld_staff_id']; ?>" selected><?php echo $staffrow['fld_staff_name'];?></option>
<?php } else { ?>
<option value="<?php echo $staffrow['fld_staff_id']; ?>"><?php echo $staffrow['fld_staff_name'];?></option>
<?php } ?>
<?php
} // while
$conn = null;
?>
</select>
</div>
</div>
<div class="form-group">
<label for="customerid" class="col-sm-3 control-label">Customer</label>
<div class="col-sm-9">
<select name="cid" class="form-control" id="customerid" required>
<?php
try {
$conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$stmt = $conn->prepare("SELECT * FROM tbl_customers_a186687_pt2");
$stmt->execute();
$result = $stmt->fetchAll();
}
catch(PDOException $e){
echo "Error: " . $e->getMessage();
}
foreach($result as $custrow) {
?>
<?php if((isset($_GET['edit'])) && ($editrow['fld_customer_num']==$custrow['fld_customer_id'])) { ?>
<option value="<?php echo $custrow['fld_customer_id']; ?>" selected><?php echo $custrow['fld_customer_name']?></option>
<?php } else { ?>
<option value="<?php echo $custrow['fld_customer_id']; ?>"><?php echo $custrow['fld_customer_name']?></option>
<?php } ?>
<?php
} // while
$conn = null;
?>
</select>
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-3 col-sm-9">
<?php if (isset($_GET['edit'])) { ?>
<button class="btn btn-default" type="submit" name="update"><span class="glyphicon glyphicon-pencil" aria-hidden="true"></span>Update</button>
<?php } else { ?>
<button class="btn btn-default" type="submit" name="create"><span class="glyphicon glyphicon-plus" aria-hidden="true"></span>Create</button>
<?php } ?>
<button class="btn btn-default" type="reset"><span class="glyphicon glyphicon-erase" aria-hidden="true"></span>Clear</button>
</div>
</div>
</form>
</div>
</div>
<div class="row">
<div class="col-xs-12 col-sm-12 col-md-10 col-md-offset-1">
<div class="page-header">
<h2>Order List</h2>
</div>
<table class="table table-striped table-bordered">
<tr>
<th>Order ID</th>
<th>Order Date</th>
<th>Staff ID</th>
<th>Customer ID</th>
<th></th>
</tr>
<?php
$per_page = 5;
if (isset($_GET["page"]))
$page = $_GET["page"];
else
$page = 1;
$start_from = ($page-1) * $per_page;
try {
$conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$sql = "SELECT * FROM tbl_orders_a186687, tbl_staffs_a186687_pt2, tbl_customers_a186687_pt2 WHERE ";
$sql = $sql."tbl_orders_a186687.fld_staff_num = tbl_staffs_a186687_pt2.fld_staff_id and ";
$sql = $sql."tbl_orders_a186687.fld_customer_num = tbl_customers_a186687_pt2.fld_customer_id ";
$sql = $sql."LIMIT $start_from, $per_page";
$stmt = $conn->prepare($sql);
$stmt->execute();
$result = $stmt->fetchAll();
}
catch(PDOException $e){
echo "Error: " . $e->getMessage();
}
foreach($result as $orderrow) {
?>
<tr>
<td><?php echo $orderrow['fld_order_num']; ?></td>
<td><?php echo $orderrow['fld_order_date']; ?></td>
<td><?php echo $orderrow['fld_staff_name']?></td>
<td><?php echo $orderrow['fld_customer_name']?></td>
<td>
<a href="orders_details.php?oid=<?php echo $orderrow['fld_order_num']; ?>"class="btn btn-warning btn-xs" role="button">Details</a>
<?php if ($is_admin) { ?>
<a href="orders.php?edit=<?php echo $orderrow['fld_order_num']; ?>"class="btn btn-success btn-xs" role="button">Edit</a>
<a href="orders.php?delete=<?php echo $orderrow['fld_order_num']; ?>" onclick="return confirm('Are you sure to delete?');"class="btn btn-danger btn-xs" role="button">Delete</a>
<?php } ?>
</td>
</tr>
<?php
}
$conn = null;
?>
</table>
</div>
</div>
<div class="row">
<div class="col-xs-12 col-sm-10 col-sm-offset-1 col-md-8 col-md-offset-2">
<nav>
<ul class="pagination">
<?php
try {
$conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$stmt = $conn->prepare("SELECT * FROM tbl_orders_a186687");
$stmt->execute();
$result = $stmt->fetchAll();
$total_records = count($result);
}
catch(PDOException $e){
echo "Error: " . $e->getMessage();
}
$total_pages = ceil($total_records / $per_page);
?>
<?php if ($page==1) { ?>
<li class="disabled"><span aria-hidden="true">«</span></li>
<?php } else { ?>
<li><a href="orders.php?page=<?php echo $page-1 ?>" aria-label="Previous"><span aria-hidden="true">«</span></a></li>
<?php
}
for ($i=1; $i<=$total_pages; $i++)
if ($i == $page)
echo "<li class=\"active\"><a href=\"orders.php?page=$i\">$i</a></li>";
else
echo "<li><a href=\"orders.php?page=$i\">$i</a></li>";
?>
<?php if ($page==$total_pages) { ?>
<li class="disabled"><span aria-hidden="true">»</span></li>
<?php } else { ?>
<li><a href="orders.php?page=<?php echo $page+1 ?>" aria-label="Previous"><span aria-hidden="true">»</span></a></li>
<?php } ?>
</ul>
</nav>
</div>
</div>
</div>
<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<!-- Include all compiled plugins (below), or include individual files as needed -->
<script src="js/bootstrap.min.js"></script>
</body>
</html>