-
Notifications
You must be signed in to change notification settings - Fork 0
/
orders-views.php
185 lines (144 loc) · 4.99 KB
/
orders-views.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
<?php
/*
VIEW.PHP
Displays all data from 'orders' table
*/
// header
include('header.php');
// connect to the database
include('linkupdb.php');
//display clean utf8 data
function clean_orders($str)
{
$str = @iconv('UTF-8', 'UTF-8//IGNORE', $str);
return $str;
}
// Sort by query results by each table header
$sorter = "";
if ($_GET['sort'] == 'customerDesc')
{
$sorter = "ORDER BY u.customerName DESC";
}
elseif ($_GET['sort'] == 'customerAsc')
{
$sorter = "ORDER BY u.customerName ASC";
}
elseif ($_GET['sort'] == 'status')
{
$sorter = "ORDER BY o.status";
}
elseif ($_GET['sort'] == 'order_Date')
{
$sorter = "ORDER BY o.orderDate";
}
elseif($_GET['sort'] == 'requiredDate')
{
$sorter = "ORDER BY o.requiredDate";
}
elseif($_GET['sort'] == 'shippedDate')
{
$sorter = "ORDER BY o.shippedDate";
}
elseif($_GET['sort'] == 'comments')
{
$sorter = "ORDER BY o.comments";
}
// number of results to show per page
$per_page = 20;
// figure out the total pages in the database
$result = mysql_query("SELECT o.orderNumber, o.orderDate, o.requiredDate, o.shippedDate, o.status, o.comments, o.customerNumber, u.customerNumber, u.customerName FROM orders o, customers u WHERE o.customerNumber = u.customerNumber $sorter");
$total_results = mysql_num_rows($result);
$total_pages = ceil($total_results / $per_page);
// check if the 'page' variable is set in the URL (ex: view-paginated.php?page=1)
if (isset($_GET['page']) && is_numeric($_GET['page']))
{
$show_page = $_GET['page'];
// make sure the $show_page value is valid
if ($show_page > 0 && $show_page <= $total_pages)
{
$start = ($show_page -1) * $per_page;
$end = $start + $per_page;
}
else
{
// error - show first set of results
$start = 0;
$end = $per_page;
}
}
else
{
// if page isn't set, show first set of results
$start = 0;
$end = $per_page;
}
?>
<div id="orders" class="fixed-wrapper"><h1 class="affix">Orders</h1></div>
<div class="container">
<ul class="nav nav-pills">
<li class="active"><a href="orders-new.php">Add a new record</a></li>
<li class="badge pull-right"><a href="orders-export.php">Export Records <i class="icon-cloud-download"></i></a></li>
</ul>
<!-- orders Section -->
<div class="content">
<div class="row-fluid">
<div class="col-md-12 col-sm-12 col-xs-12">
<?php
// pagination
echo " <ul class='pagination'> ";
for ($i = 1; $i <= $total_pages; $i++)
{
echo "<li><a href='orders-views.php?page=$i&sort=customerDesc'>$i</a></li>";
}
echo "</ul> ";
?>
<table class='table table-striped' >
<thead>
<tr>
<th colspan="2" ><a href="orders-views.php?sort=customerDesc" ><i class="icon-sort-down"></i></a> <a href="orders-views.php?sort=customerAsc" ><i class="icon-sort-up"></i></a> </th>
<th><a href="orders-views.php?sort=status" >status<i class="icon-sort"></i></a></th>
<th><a href="orders-views.php?sort=order_Date" >order_Date<i class="icon-sort"></i></a></th>
<th><a href="orders-views.php?sort=requiredDate" >requiredDate<i class="icon-sort"></i></a></th>
<th><a href="orders-views.php?sort=shippedDate" >shippedDate<i class="icon-sort"></i></a></th>
<th><a href="orders-views.php?sort=comments" >comments<i class="icon-sort"></i></a></th>
</tr>
</thead>
<tbody>
<?php
// display data in table
// loop through results of database query, displaying them in the table
for ($i = $start; $i < $end; $i++)
{
// make sure that PHP doesn't try to show results that don't exist
if ($i == $total_results) { break; }
// echo out the contents of each row into a table
echo "<tr>";
echo '<td colspan="11"><b> ' . clean_orders(mysql_result($result, $i, 'customerName')) . ' </b></td><td colspan="1">' . ' <a href="orders-del.php?orderNumber=' . mysql_result($result, $i, 'orderNumber') . '"><i class="icon-trash"></i></a></td>';
echo '<tr>';
echo '<td colspan="2"><a href="orders-edit.php?orderNumber=' . mysql_result($result, $i, 'orderNumber') . '"><i class="icon-pencil"></i></a> </td>';
echo '<td >' . clean_orders(mysql_result($result, $i, 'status')) . '</td>';
echo '<td > ' . clean_orders(mysql_result($result, $i, 'orderDate')) . '</td>';
echo '<td>' . clean_orders(mysql_result($result, $i, 'requiredDate')) . '</td>';
echo '<td>' . clean_orders(mysql_result($result, $i, 'shippedDate')) . '</td>';
echo '<td>' . clean_orders(mysql_result($result, $i, 'comments')) . '</td>';
echo "</tr>";
}
echo "</tbody>";
// close table>
echo "</table>";
// pagination
echo " <ul class='pagination'> ";
for ($i = 1; $i <= $total_pages; $i++)
{
echo "<li><a href='orders-views.php?page=$i'>$i</a></li>";
}
echo "</ul> ";
?>
</div>
</div>
</div>
<ul class="nav nav-pills">
<li class="active"><a href="orders-new.php">Add a new record</a></li>
<li class="badge pull-right"><a href="orders-export.php">Export Records <i class="icon-cloud-download"></i></a></li>
</ul>
</div>