forked from renlok/WeBid
-
Notifications
You must be signed in to change notification settings - Fork 0
/
search.php
97 lines (84 loc) · 3.22 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
<?php
/***************************************************************************
* copyright : (C) 2008 - 2013 WeBid
* site : http://www.webidsupport.com/
***************************************************************************/
/***************************************************************************
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version. Although none of the code may be
* sold. If you have been sold this script, get a refund.
***************************************************************************/
include 'common.php';
include $main_path . 'language/' . $language . '/categories.inc.php';
include $include_path . 'dates.inc.php';
$NOW = time();
$term = $system->cleanvars(trim($_GET['q']));
$cat_id = intval($_GET['id']);
if (strlen($term) == 0)
{
$template->assign_vars(array(
'ERROR' => $ERR_037,
'NUM_AUCTIONS' => 0,
'TOP_HTML' => ''
));
}
else
{
$catSQL = '';
if ($cat_id > 0)
{
$catscontrol = new MPTTcategories();
$query = "SELECT right_id, left_id FROM " . $DBPrefix . "categories WHERE cat_id = " . $cat_id;
$res = mysql_query($query);
$system->check_mysql($res, $query, __LINE__, __FILE__);
$parent_node = mysql_fetch_assoc($res);
$children = $catscontrol->get_children_list($parent_node['left_id'], $parent_node['right_id']);
$childarray = array($cat_id);
foreach ($children as $k => $v)
{
$childarray[] = $v['cat_id'];
}
$catalist = '(';
$catalist .= implode(',', $childarray);
$catalist .= ')';
$catSQL = " AND (category IN " . $catalist;
if ($system->SETTINGS['extra_cat'] == 'y')
{
$catSQL .= " OR secondcat IN " . $catalist;
}
$catSQL .= ")";
}
$query = "SELECT * FROM " . $DBPrefix . "auctions WHERE
(title LIKE '%" . $term . "%' OR id = " . intval($term) . ")
" . $catSQL . "
AND closed = 0 AND suspended = 0 AND starts <= " . $NOW . " AND ends > " . $NOW;
// retrieve records corresponding to passed page number
$PAGE = isset($_GET['PAGE']) ? intval($_GET['PAGE']) : 1;
if ($PAGE == 0) $PAGE = 1;
// determine limits for SQL query
$left_limit = ($PAGE - 1) * $system->SETTINGS['perpage'];
// get total number of records
$res = mysql_query($query);
$system->check_mysql($res, $query, __LINE__, __FILE__);
$total = mysql_num_rows($res);
// get number of pages
$PAGES = ceil($total / $system->SETTINGS['perpage']);
$query_ = $query . " ORDER BY ends LIMIT " . $left_limit . ", " . $system->SETTINGS['perpage'];
$res = mysql_query($query_);
$system->check_mysql($res, $query_, __LINE__, __FILE__);
$query_ = $query . " AND featured = 'y' ORDER BY ends LIMIT " . intval(($PAGE - 1) * 5) . ", 5";
$feat_res = mysql_query($query_);
$system->check_mysql($feat_res, $query_, __LINE__, __FILE__);
// to be sure about items format, I've unified the call
include $include_path . 'browseitems.inc.php';
browseItems($res, $feat_res, $total, 'search.php', 'q=' . $term . '&id=' . $cat_id);
}
include 'header.php';
$template->set_filenames(array(
'body' => 'search.tpl'
));
$template->display('body');
include 'footer.php';
?>