/
search.php
170 lines (160 loc) · 6.79 KB
/
search.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
<?php
if (!isset($_SESSION)) {
session_start();
}
require_once './helper/Page.php';
require_once './entities/Product.php';
$page = new Page();
$page->setTitle('Tìm Kiếm');
$page->addCSS("assets/js/jRange-master/jquery.range.css");
$page->addJavascript("assets/js/jRange-master/jquery.range.js");
$page->startBody();
$ListPro = array();
$flag = false;
$rowsPerPage = 9; // số lượng dòng được hiển thị 1 trang
$curPage = 1; // Trang hiện tại
$numberOfRows = 0;
if (isset($_GET['page']) && !empty(($_GET['page']))) {
$curPage = $_GET['page'];//truyền thứ tự trang cần xem
}
$offset = ($curPage - 1) * $rowsPerPage;// tính offset bắt đầu load
if (isset($_GET["btnSearch"])) {
$Product = new Product();
$Product->setProName($_GET["txtProName"]);
$Price = $_GET["txtPrice"];
$Price = explode(',', $Price);
$Product->setPrice($Price);
require_once './entities/Category.php';
require_once './entities/Brand.php';
require_once './entities/Device.php';
$CatPro = new Category();
$CatPro->setBrand(new Brand($_GET["cboBra"]));
$CatPro->setDevice(new Device($_GET["cboDevice"]));
$Product->setCatPro($CatPro);
$ListPro = $Product->loadLimit($rowsPerPage, $offset, "ProName");
$numberOfRows = $Product->countRecords();
$flag = true;
}
?>
<div class="box clearfix">
<ol class="breadcrumb box-top">
<li><a href="index.php"><i class="fa fa-home"></i></a></li>
<li class="active">Tìm Kiếm</li>
</ol>
<div id="searchBody">
<form action="search.php" method="get">
<div class="col-md-12 row">
<div class="form-group col-md-6">
<label for="txtProName">Tên Sản Phẩm:</label>
<input type="text" class="form-control note" name="txtProName" id="txtProName">
</div>
<div class="form-group col-md-6">
<label for="txtPrice">Giá:</label>
<input type="hidden" class="form-control" name="txtPrice" id="txtPrice" value="1"/>
</div>
</div>
<div class="col-md-12 row">
<div class="form-group col-md-6">
<label for="cboDevice">Thiết Bị:</label>
<select class="form-control" name="cboDevice" id="cboDevice">
<?php
require_once "entities/Device.php";
$ListDevices = Device::loadAll();
echo '<option value="-1">Chọn ...</option>';
foreach ($ListDevices as $ItemDev) {
echo '<option value=' . $ItemDev->getDeviceID() . '>';
echo $ItemDev->getDeviceName();
echo '</option>';
}
?>
</select>
</div>
<div class="form-group col-md-6">
<label for="cboBra">Nhà Sản Xuất</label>
<select class="form-control" name="cboBra" id="cboBra">
<option value="-1">Chọn ...</option>
<?php
require_once "entities/Brand.php";
$ListBrands = Brand::loadAll();
foreach ($ListBrands as $ItemBrand) {
?>
<option value=<?php echo $ItemBrand->getBraID(); ?>>
<?php echo $ItemBrand->getBraName(); ?>
</option>
<?php
}
?>
</select>
</div>
</div>
<div class="col-md-12 row">
<div class="form-group col-md-2">
<button type="submit" class="btn btn-primary" id="btnSearch" name="btnSearch">Tìm Kiếm</button>
</div>
</div>
</form>
</div>
</div>
<?php if ($flag) { ?>
<div id="searchResult" class="box clearfix">
<div class="box-top">
Kết quả tìm kiếm
</div>
<div class="">
<form id="addToCart-form" method="post" action=""><input type="hidden" id="txtProID"
name="txtProID"/></form>
<?php if (empty($ListPro)) {
echo "<div style='margin: 10px;' class=\"alert alert-info\" role=\"alert\"><i class=\"fa fa-bullhorn\"></i>Không tìm thấy sản phẩm nào !</div>";
} else {
Product::printListProduct($ListPro);
require_once './helper/Pagination.php';
$self = $_SERVER['PHP_SELF']; // Lay dia chi truc tiep cua PHP dang mo
$pagination = new Pagination($curPage, $rowsPerPage, $offset, $numberOfRows, $self);
?>
<!--pagination-->
<nav id="paging" class="text-center">
<?php $pagination->printPaging(); ?>
</nav>
<!--/pagination-->
<?php } ?>
</div>
</div>
<?php } ?>
<script type="text/javascript">
$().ready(function () {
$('#paging .pull-right').removeClass('pull-right');
$('#paging a').click(function () {
var page = $(this).text();
if (page.length === 0) {
page = $(this).find('.sr-only').text();
}
var url = window.location.href;
if (url.indexOf("&&page=") > 0) {
url = url.substr(0, url.indexOf("&&page="));
}
window.location.assign(url + '&&page=' + page);
});
$('button.btn-shopping-cart').on('click', function () {
var proID = $(this).data('proid');
$('#txtProID').val(proID);
$('#addToCart-form').submit();
});
var rangePrice = $('#txtPrice').jRange({
from: 0,
to: 25,
step: 1,
scale: [0, 5, 10, 15, 20, 25],
format: function (value, type) {
var text = value.format(0, 3, ',') + ' tr';
return text;
},
showLabels: true,
isRange: true
});
rangePrice.jRange('updateRange', '0,' + 25, '0,' + 25);
$('.slider-container').css('width', '100%');
});
</script>
<?php
$page->endBody();
echo $page->render('Templates/Template.php');