colonymech / docs / www / colonyscout / internal / inventoryview.php @ f59acf11
History | View | Annotate | Download (5.26 KB)
1 |
<style>
|
---|---|
2 |
.sort-up {background:url('images/up.gif') no-repeat;float:left;width:12px;height:12px;margin:3px 5px 3px 10px;}
|
3 |
.sort-down {background:url('images/down.gif') no-repeat;float:right;width:12px;height:12px;margin:3px 10px 3px 5px;}
|
4 |
</style>
|
5 |
|
6 |
<?php
|
7 |
$pageNum = (isset($_GET['page'])) ? $_GET['page'] : 1; // if $_GET['page'] defined, use it as page number |
8 |
$rowsPerPage = 30; // how many rows to show per page |
9 |
$offset = ($pageNum - 1) * $rowsPerPage; // counting the offset |
10 |
|
11 |
$sortColumn="VendorID"; $sortOrder="DESC"; |
12 |
if(isset($_GET["sortby"])) { |
13 |
switch ($_GET["sortby"]) { |
14 |
case "valinc": |
15 |
$sortColumn = "Description"; $sortOrder="ASC"; |
16 |
break;
|
17 |
case "valdec": |
18 |
$sortColumn = "Description"; $sortOrder="DESC"; |
19 |
break;
|
20 |
case "manfinc": |
21 |
$sortColumn = "ManufacturerName"; $sortOrder="ASC"; |
22 |
break;
|
23 |
case "manfdec": |
24 |
$sortColumn = "ManufacturerName"; $sortOrder="DESC"; |
25 |
break;
|
26 |
case "veninc": |
27 |
$sortColumn = "VendorID"; $sortOrder="ASC"; |
28 |
break;
|
29 |
case "vendec": |
30 |
$sortColumn = "VendorID"; $sortOrder="DESC"; |
31 |
break;
|
32 |
case "qtyinc": |
33 |
$sortColumn = "qty"; $sortOrder="ASC"; |
34 |
break;
|
35 |
case "qtydec": |
36 |
$sortColumn = "qty"; $sortOrder="DESC"; |
37 |
break;
|
38 |
case "priceinc": |
39 |
$sortColumn = "cost_1"; $sortOrder="ASC"; |
40 |
break;
|
41 |
case "pricedec": |
42 |
$sortColumn = "cost_1"; $sortOrder="DESC"; |
43 |
break;
|
44 |
} |
45 |
} |
46 |
|
47 |
|
48 |
//gather the inventory based on search term or all
|
49 |
$get_inventory_sql = "SELECT ID,name,manufacturername,manufacturerpartno,VendorPartNo,description,qty,cost_1, (select name from vendors WHERE vendors.id=inventory.vendorid) as vendorname FROM inventory ORDER BY $sortColumn $sortOrder LIMIT $offset, $rowsPerPage"; |
50 |
$get_inventory_res = mysqli_query($mysqli, $get_inventory_sql) or die(mysqli_error($mysqli)); |
51 |
|
52 |
if (mysqli_num_rows($get_inventory_res) < 1) { |
53 |
$display_block = "</table><br/><h1>No inventory matched those search terms.</h1>"; |
54 |
} else {
|
55 |
//create the display string
|
56 |
$display_block = ""; |
57 |
|
58 |
while ($inv = mysqli_fetch_array($get_inventory_res)) { |
59 |
$display_block .=
|
60 |
"<tr>
|
61 |
<td><a href=\"viewpart.php?q=".$inv["VendorPartNo"]."\">".$inv["name"]."</a></td> |
62 |
<td>".$inv["description"]."</td><td>".$inv["manufacturername"]."</td> |
63 |
<td><a target=\"_blank\" href=\"".getURL($inv["VendorPartNo"],$inv["vendorname"])."\">".$inv["manufacturerpartno"]."</a></td> |
64 |
<td>".$inv["vendorname"]."</td> |
65 |
<td>".$inv["qty"]."</td> |
66 |
<td>\$".$inv["cost_1"]."</td></tr>"; |
67 |
} |
68 |
|
69 |
$display_block .= "</table><br/><br/>"; |
70 |
|
71 |
|
72 |
// how many rows we have in database
|
73 |
$get_num_inventory_sql = "SELECT COUNT(*) AS inventory_count FROM inventory"; |
74 |
$get_num_inventory_res = mysqli_query($mysqli, $get_num_inventory_sql) or die(mysqli_error($mysqli)); |
75 |
|
76 |
while ($inventory_info = mysqli_fetch_array($get_num_inventory_res)) { |
77 |
$numrows = $inventory_info['inventory_count']; |
78 |
} |
79 |
|
80 |
// how many pages we have when using paging?
|
81 |
$maxPage = ceil($numrows/$rowsPerPage); |
82 |
|
83 |
// print the link to access each page
|
84 |
$self = $_SERVER['PHP_SELF']; |
85 |
$nav = ''; |
86 |
for($page = 1; $page <= $maxPage; $page++) { |
87 |
if ($page == $pageNum) { |
88 |
$nav .= "<li class=\"currentpage\">$page</li>\n"; // no need to create a link to current page |
89 |
} else {
|
90 |
$nav .= "<li><a href=\"$self?page=$page\">$page</a></li>\n"; |
91 |
} |
92 |
} |
93 |
|
94 |
// creating previous and next link
|
95 |
// plus the link to go straight to
|
96 |
// the first and last page
|
97 |
|
98 |
if ($pageNum > 1) { |
99 |
$page = $pageNum - 1; |
100 |
$prev = "<li><a href=\"$self?page=$page\">prev</a></li>\n"; |
101 |
} else {
|
102 |
$prev = ' '; // we're on page one, don't print previous link |
103 |
} |
104 |
|
105 |
if ($pageNum < $maxPage) { |
106 |
$page = $pageNum + 1; |
107 |
$next = "<li><a href=\"$self?page=$page\">next</a></li>\n"; |
108 |
} else {
|
109 |
$next = ' '; // we're on the last page, don't print next link |
110 |
} |
111 |
|
112 |
// print the navigation link
|
113 |
$navString = "<div id=\"navcontainer\"> |
114 |
<ul>".$prev.$nav.$next."</ul>\n</div>"; |
115 |
|
116 |
|
117 |
//free results
|
118 |
mysqli_free_result($get_inventory_res);
|
119 |
|
120 |
} |
121 |
|
122 |
$address = '?tab='.$tab.'&page='.$pageNum."&"; |
123 |
?>
|
124 |
<table style="background-color:#fff;width:920px;"> |
125 |
<tr>
|
126 |
<th width="210px">Part Name<br/> |
127 |
</th>
|
128 |
<th width="70px">Value<br/> |
129 |
<a href="<?php echo $address;?>sortby=valinc"><div class="sort-up"></div></a> |
130 |
<a href="<?php echo $address;?>sortby=valdec"><div class="sort-down"></div></a> |
131 |
</th>
|
132 |
<th width="200px">Manufacturer<br/> |
133 |
<a href="<?php echo $address;?>sortby=manfinc"><div class="sort-up"></div></a> |
134 |
<a href="<?php echo $address;?>sortby=manfdec"><div class="sort-down"></div></a> |
135 |
</th>
|
136 |
<th width="220px">Manufacturer Part No<br/> |
137 |
</th>
|
138 |
<th width="60px">Vendor<br/> |
139 |
<a href="<?php echo $address;?>sortby=veninc"><div class="sort-up"></div></a> |
140 |
<a href="<?php echo $address;?>sortby=vendec"><div class="sort-down"></div></a> |
141 |
</th>
|
142 |
<th width="70px">Qty<br/> |
143 |
<a href="<?php echo $address;?>sortby=qtyinc"><div class="sort-up"></div></a> |
144 |
<a href="<?php echo $address;?>sortby=qtydec"><div class="sort-down"></div></a> |
145 |
</th>
|
146 |
<th width="70px">$/each<br/> |
147 |
<a href="<?php echo $address;?>sortby=priceinc"><div class="sort-up"></div></a> |
148 |
<a href="<?php echo $address;?>sortby=pricedec"><div class="sort-down"></div></a> |
149 |
</th>
|
150 |
</tr>
|
151 |
<?php echo $display_block; echo $navString;?> |
152 |
|
153 |
</div>
|
154 |
</div>
|