forked from SnowHall/Silurus-Classifieds-Script
-
Notifications
You must be signed in to change notification settings - Fork 0
/
search.php
executable file
·201 lines (185 loc) · 6.61 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
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
<?php
/**
* Silurus Classifieds Builder
*
*
* @author SnowHall - http://snowhall.com
* @website http://snowhall.com/silurus
* @email support@snowhall.com
*
* @version 1.0
* @date May 7, 2009
*
* Silurus is a professionally developed PHP Classifieds script that was built for you.
* Whether you are running classifieds for autos, motorcycles, bicycles, rv's, guns,
* horses, or general merchandise, our product is the right package for you.
* It has template system and no limit to usage with free for any changes.
*
* Copyright (c) 2009
*/
include("./include_php/init.php");
include("./include_php/TemplVotingView.php");
$oVotingView = new TemplVotingView ('gvoting', 0);
if(isset($_REQUEST['go']))
{
$where = '';
$inid = array();
if(trim($_REQUEST['keywords'])!='')
{
if(isset($_REQUEST['keywords'])&&trim($_REQUEST['keywords'])!='')
{
$masskey = explode(" ",mysql_escape_string($_REQUEST['keywords']));
if(count($masskey) > 0)
{
$inid[0] = array();
$in = 0;
$where .= " AND ( ";
foreach($masskey as $word)
{
if($in > 0) $where .= " OR ";
$where .= " ss.Title like '%$word%' ";
$in++;
}
$where .= ") ";
$cq = mysql_query("select ss.* from Store ss where ss.type=0 ".$where);
while($carr = mysql_fetch_assoc($cq)) $inid[0][] = $carr['ID'];
$cq = mysql_query("select v.* from StorePropValues v inner join StoreProp p on p.ID=v.PropID where p.Type<3 and p.InSearch=1 ".str_replace("ss.Title","v.Value",$where));
while($carr = mysql_fetch_assoc($cq)) $inid[0][] = $carr['itemID'];
}
}
}
$categoryID = intval($_REQUEST['categoryID']);
$propq = mysql_query("select * from StoreProp where categoryID=".$categoryID." and InSearch=1 and Type>3 ");
while($masprop = mysql_fetch_assoc($propq))
{
if(isset($_REQUEST['prop'.$masprop['ID']]))
{
$inid[$masprop['ID']] = array();
if($masprop['Type'] > 4)
{
if(is_array($_REQUEST['prop'.$masprop['ID']]) && count($_REQUEST['prop'.$masprop['ID']])>0)
{
$twhere = " AND ( ";
$in = 0;
foreach($_REQUEST['prop'.$masprop['ID']] as $item)
{
if($in > 0) $twhere .= " OR ";
$twhere .= " Value = '".intval($item)."' ";
$in++;
}
$twhere .= ") ";
$cq = mysql_query("select * from StorePropValues where PropID=".$masprop['ID']." $twhere");
while($carr = mysql_fetch_assoc($cq)) $inid[$masprop['ID']][] = $carr['itemID'];
}
}
if($masprop['Type'] == 4)
{
$cq = mysql_query("select * from StorePropValues where PropID=".$masprop['ID']." and Value='".mysql_escape_string($_REQUEST['prop'.$masprop['ID']])."'");
while($carr = mysql_fetch_assoc($cq)) $inid[$masprop['ID']][] = $carr['itemID'];
}
$masprop['subprop'] = $subitems;
$properties[] = $masprop;
}
}
$inid_w = array();
if(count($inid)>0)
foreach ($inid as $val)
{
if(empty($inid_w))
{
$inid_w = $val;
if(empty($inid_w)) break;
}
else
{
$inid_w = array_intersect($inid_w,$val);
if(empty($inid_w)) break;
}
}
$order = (isset($_REQUEST['border'])?$_REQUEST['border']:'title');
$desc = (isset($_REQUEST['bdesc'])?true:false);
$books = array('order'=>$order, 'desc'=>$desc, 'cur_url'=>$curUrl, 'prefix'=>'b', 'list'=>array());
if($order == 'date') {$order = 's.date';}
elseif($order == 'price') {$order = 's.price';}
elseif($order == 'quality') {$order = 'c.Title';}
else {$order = 's.Title';}
if(isset($_REQUEST['bdesc'])) $order .= ' desc ';
$iDivis = 10;
$iCurr = 1;
if (!isset($_REQUEST['commPage']))
{
$sLimit = ' LIMIT 0,'.$iDivis;
}
else
{
if($_REQUEST['commPage']<=0) $_REQUEST['commPage'] = 1;
$iCurr = (int)$_REQUEST['commPage'];
$sLimit = ' LIMIT '.($iCurr - 1)*$iDivis.','.$iDivis;
}
$sQuery = ("select s.*,c.Title as ctitle from Store s inner join StoreCategories c on c.ID=s.categoryID where ".($_SESSION['location']['condition']!=''?'s.userID in '.$_SESSION['location']['condition'].' and ':'')." s.type=0 and s.status=0 ".(intval($_REQUEST['categoryID'])>0?" and categoryID=".intval($_REQUEST['categoryID']):"")." and s.ID in (-1".(count($inid_w)>0?','.implode(",",$inid_w):'').") order by $order ");
$rElems = mysql_query( $sQuery );
$iNums = mysql_num_rows($rElems);
$count = (int)($iNums/$iDivis);
if(($iNums/$iDivis) > (int)($iNums/$iDivis)) $count++;
$aPaging = ($iNums > $iDivis ? MakePaging($iNums,$iCurr,$iDivis,4,'commPage','') : '');
$rElems = mysql_query( $sQuery.$sLimit );
while($book = mysql_fetch_assoc($rElems))
{
if($color == 'f5f5f5') $color = 'ffffff'; else $color = 'f5f5f5';
$temp = array();
$temp['Color'] = $color;
$temp['ID'] = $book['ID'];
$temp['url'] = 'javascript:void(0);" onclick="show_book_info(\''.$book['ID'].'\',this,\'1\')';
$temp['Title'] = htmlspecialchars($book['Title']);
$temp['Date'] = date("F jS, Y",$book['date']);
$temp['Price'] = number_format($book['price'],2,".","");
$temp['ctitle'] = $book['ctitle'];
$books['list'][] = $temp;
}
$smarty->assign("sbooks", $books);
$smarty->assign("aPaging", $aPaging);
}
else
{
$categoryID = intval($_REQUEST['categoryID']);
$ret = '';
$q = mysql_query("select * from StoreCategories where Type=0 order by Title");
while($arr = mysql_fetch_array($q))
{
if($categoryID==0) $categoryID = $arr['ID'];
$ret .= '<option value="'.$arr['ID'].'" '.($categoryID==$arr['ID']?'selected':'').'>'.$arr['Title'].'</option>';
}
$smarty->assign("categ_list", $ret);
$properties = array();
$propq = mysql_query("select * from StoreProp where categoryID=".$categoryID." and InSearch=1 and Type>3 order by Prior ");
while($masprop = mysql_fetch_assoc($propq))
{
$subitems = array();
if($masprop['Type'] > 4)
{
$qq = mysql_query("select * from StorePropMulti where PropID=".intval($masprop['ID'])." order by Name");
while($subprop = mysql_fetch_assoc($qq))
$subitems[] = $subprop;
}
if($masprop['Type'] == 4)
{
$oVotingView->_fRate = 1;
$voter = $oVotingView->getBigVoting (1,'',$masprop['ID']);
$subitems = '<input type="hidden" name="prop'.$masprop['ID'].'" id="gvotingbig'.$masprop['ID'].'" value="1">'.$voter;
}
$masprop['subprop'] = $subitems;
$properties[] = $masprop;
}
$smarty->assign("props", $properties);
}
if(isset($_REQUEST['go']))
$HEADERTEXT = 'Search Results'.(trim($_REQUEST['keywords'])!=''?' for "'.$_GET['keywords'].'"':'');
else
$HEADERTEXT = 'Advanced Search';
$contact_type = 1;
include("./ap_contact.php");
addNavigation('','Advanced Search');
$smarty->assign("site_title", $HEADERTEXT." :: ".$gConfig['site_title']);
$smarty->assign("HEADERTEXT", $HEADERTEXT);
show_smarty_template('search');
?>