-
Notifications
You must be signed in to change notification settings - Fork 0
/
product.php
208 lines (194 loc) · 6.96 KB
/
product.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
<?php
$page_title = 'All Product';
require_once('includes/load.php');
// Checkin What level user has permission to view this page
page_require_level(2);
$all_categories = find_all('categories');
?>
<?php
$sql = "SELECT id FROM products p";
if(isset($_POST['show_part_product'])){
$req_fields = array('product-categorie');
validate_fields($req_fields);
if(empty($errors)){
$p_cat = remove_junk($db->escape($_POST['product-categorie']));
$sql = "SELECT id FROM products p WHERE p.categorie_id=";
$sql .= $p_cat;
}
else{
$sql = "SELECT id FROM products p";
}
}
// 总记录数
$totalnums = totalnums($sql);
// 每页显示条数
$fnum = 20;
// 翻页数
$pagenum = ceil($totalnums / $fnum);
// 页数常量
try {
if(isset($_GET['page'])){$page = $_GET['page'];}
else{$page = '';}
} catch (Exception $e){
redirect('add_product.php',false);
}
if ( $page == '' ) {
$page = 1;
}
//防止恶意翻页
if ($page > $pagenum)
echo "<script>window.location.href='add_product.php'</script>";
//计算分页起始值
if ($page == "") {
$num = 0;
} else {
$num = ($page-1) * $fnum;
}
$stime = microtime(true);
$products = join_product_table_part($num,$fnum);
$etime = microtime(true);
$total=$etime-$stime;
if(isset($_POST['show_part_product'])){
$req_fields = array('product-categorie');
validate_fields($req_fields);
if(empty($errors)){
$p_cat = remove_junk($db->escape($_POST['product-categorie']));
$stime = microtime(true);
$products = join_product_table_part_categorie($p_cat,$num,$fnum);
$etime = microtime(true);
$total=$etime-$stime;
}
else{
$stime = microtime(true);
$products = join_product_table_part($num,$fnum);
$etime = microtime(true);
$total=$etime-$stime;}}
?>
<?php include_once('layouts/header.php'); ?>
<div class="row">
<div class="col-md-12">
<?php echo display_msg($msg); ?>
</div>
<div class="col-md-12">
<div class="panel panel-default">
<div class="panel-heading clearfix">
<form method="post" action="product.php" class="clearfix">
<div class="pull-left">
<div class="col-md-12">
<select class="form-control" name="product-categorie">
<option value="">Select Product Category</option>
<?php foreach ($all_categories as $cat): ?>
<option value="<?php echo (int)$cat['id'] ?>">
<?php echo $cat['name'] ?></option>
<?php endforeach; ?>
</select>
</div>
</div>
<button type="submit" name="show_part_product" class="btn btn-danger">Submit</button>
</form>
<div class="pull-right">
<a href="add_product.php" class="btn btn-primary">Add New</a>
</div>
</div>
<div class="panel-body">
<table class="table table-bordered">
<thead>
<tr>
<th class="text-center" style="width: 50px;">#</th>
<th> Photo</th>
<th> Product Title </th>
<th class="text-center" style="width: 10%;"> Categorie </th>
<th class="text-center" style="width: 10%;"> Instock </th>
<th class="text-center" style="width: 10%;"> Buying Price </th>
<th class="text-center" style="width: 10%;"> Saleing Price </th>
<th class="text-center" style="width: 10%;"> Product Added </th>
<th class="text-center" style="width: 100px;"> Actions </th>
</tr>
</thead>
<tbody>
<?php foreach ($products as $product):?>
<tr>
<td class="text-center"><?php echo count_id();?></td>
<td>
<?php if($product['media_id'] === '0'): ?>
<img class="img-avatar img-circle" src="uploads/products/no_image.jpg" alt="">
<?php else: ?>
<img class="img-avatar img-circle" src="uploads/products/<?php echo $product['image']; ?>" alt="">
<?php endif; ?>
</td>
<td> <?php echo remove_junk($product['name']); ?></td>
<td class="text-center"> <?php echo remove_junk($product['categorie']); ?></td>
<td class="text-center"> <?php echo remove_junk($product['quantity']); ?></td>
<td class="text-center"> <?php echo remove_junk($product['buy_price']); ?></td>
<td class="text-center"> <?php echo remove_junk($product['sale_price']); ?></td>
<td class="text-center"> <?php echo read_date($product['date']); ?></td>
<td class="text-center">
<div class="btn-group">
<a href="edit_product.php?id=<?php echo (int)$product['id'];?>" class="btn btn-info btn-xs" title="Edit" data-toggle="tooltip">
<span class="glyphicon glyphicon-edit"></span>
</a>
<a href="delete_product.php?id=<?php echo (int)$product['id'];?>" class="btn btn-danger btn-xs" title="Delete" data-toggle="tooltip">
<span class="glyphicon glyphicon-trash"></span>
</a>
</div>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</tabel>
</div>
</div>
</div>
</div>
<?php
//上一页
$pagestr="";
$bothNum=4;
if($page==1){
$pagestr.='<span>首页 </span>';
}else{
$lastPage=$page-1;
$pagestr.="<a href='product.php?page=1'>首页</a>"." ";
}
if($page-$bothNum>1){
$pagestr.="<a href='product.php?page=$lastPage'>上一页</a>";
$pagestr.="<span>...</span>";
}
//当前页的左边
for($i=$bothNum;$i>=1;$i--){
if(($page - $i) < 1 ) { // 当前页左边花最多 bothnum 个数字
continue;
}
$lastPage=$page-$i;
$pagestr.="<a href='product.php?page=$lastPage'>$lastPage</a>"." ";
}
//当前页
$pagestr.="<span>$page</span>"." ";
//当前页右边
for($i=1;$i<=$bothNum;$i++){
if(($page + $i) > $pagenum) { // 当前页右边最多 bothnum 个数字
break;
}
$lastPage=$page+$i;
$pagestr.="<a href='product.php?page=$lastPage'>$lastPage</a>"." ";
}
if(($page+$bothNum)<$pagenum){
$pagestr.="<span>...</span>"." ";
}
//下一页
if($page == $pagenum) {
$pagestr .= '<span> 下一页 </span>';
} else {
$nextPage=$page+1;
$pagestr .= "<a href='product.php?page={$nextPage}'> 下一页 </a>";
}
//尾页
if(($page+$bothNum)<$pagenum){
$pagestr .= '<a href="product.php?page='.$pagenum.'">尾页</a>'." ";
}
echo $pagestr;
echo "<hr/>";
echo '当前页数为:'.$page.',总页数为:'.$pagenum;
echo "查询执行了",round($total,3),"秒";
?>
<?php include_once('layouts/footer.php'); ?>