STRING, 'low' => STRING, 'high' => STRING, 'radius' => INT, 'dist' => STRING, 'si' => STRING, 'name' => STRING, 'cat' => STRING, 'catp' => STRING, 'page' => INT,
'ppuser' => INT, 'what' => STRING, 'when' => STRING,'mcats' => STRING, 'sorttime' => INT,
'whenterm' => STRING, 'perpage' => INT, 'sort' => INT, 'myzipcode' => STRING, 'date' => INT));
typecast($_COOKIE, array('cpperpage' => INT, 'zipcode' => STRING));
if ( isset($myzipcode) )
{
@setcookie( "zipcode", $myzipcode, time()+2592000, $Globals['cookie_path'], $Globals['domain_path'] );
}
elseif ( !empty($dist) )
{
@setcookie( "zipcode", $dist, time()+2592000, $Globals['cookie_path'], $Globals['domain_path'] );
}
function deg_to_rad($deg)
{
$radians = 0.0;
$radians = $deg * M_PI/180.0;
return($radians);
}
// Init some variables
if ( !isset($cat) || empty($cat) )
{
$cat = "all";
}
if ( !isset($page) )
{
$page = 1;
}
if ( !isset($what) || empty($what) )
{
$what = "allfields";
}
list($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime();
$mon = $mon + 1;
$year = $year + 1900;
$today = mktime($hour,$min,$sec,$mon,$mday,$year);
if ( isset($perpage) && is_numeric($perpage) )
{
if ( $perpage != $cpperpage )
{
@setcookie( "cpperpage", $perpage, time()+2592000 );
$page = 1;
}
}
$hasintro = "no";
authenticate();
if ( $Globals['ppboards'] == "closed" && $User['adminedit'] != 1 )
{
diewell( $Globals['closedmsg'] );
}
if ( is_numeric($cat) )
{
$ctitleq = ppmysql_query("SELECT id,catname,thumbs,parent,intro,introtitle,introcopy,theme,sortorder,frames FROM {$Globals['pp_db_prefix']}categories WHERE id=$cat", $link);
list( $thecatid, $thecatname, $catthumbs, $catparent, $catinfo['intro'], $catinfo['introtitle'], $catinfo['introcopy'], $cattheme, $catsortorder, $catinfo['frames'] ) = mysql_fetch_row($ctitleq);
if ( $CatPerms['ugview'][$cat] == 1 )
{
diewell( $Globals['pp_lang']['noview'] );
}
if ( !preg_match("/([\<])([^\>]{1,})*([\>])/i", $catinfo['introtitle']) )
{
$catinfo['introtitle'] = preg_replace("/(\r\n|\r|\n)/i","
",$catinfo['introtitle']);
}
if ( !preg_match("/([\<])([^\>]{1,})*([\>])/i", $catinfo['introcopy']) )
{
$catinfo['introcopy'] = preg_replace("/(\r\n|\r|\n)/i","
",$catinfo['introcopy']);
}
// Nonstandard theme
if ( $cattheme && $Globals['forumstyle'] == "no" )
{
$Globals['theme'] = $cattheme;
if ( is_dir( "{$Globals['PP_PATH']}/stylesheets/{$Globals['theme']}" ) ) {
$Globals['idir'] = "{$Globals['maindir']}/stylesheets/{$Globals['theme']}";
}
}
// Non standard frames
if ( !empty($catinfo['frames']) )
{
unset( $Globals['thumbstd'] );
include( "{$Globals['TMPL_PATH']}/{$catinfo['frames']}.tmpl" );
}
// do they have permission to be here?
is_cat_protected( $cat );
if ( $User['userid'] > 0 && $Globals['displaynew'] == "yes" )
{
list($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime();
$mon = $mon + 1;
$year = $year + 1900;
$lasttimeon = mktime($hour,$min,$sec,$mon,$mday,$year);
$resultb = ppmysql_query("REPLACE INTO {$Globals['pp_db_prefix']}laston VALUES($cat,{$User['userid']},$lasttimeon)", $link);
}
}
$perpage1x = $Globals['thumbcols'];
$perpage3x = ($perpage1x * 3);
$perpage4x = ($perpage1x * 4);
$perpage5x = ($perpage1x * 5);
$perpage6x = ($perpage1x * 6);
if ( !empty($perpage) )
{
if ( $perpage > 90 ) {
$perpage = 90;
}
if ($perpage < $perpage1x) {
$perpage = $perpage1x;
}
}
else
{
if ( isset($cpperpage) )
{
$perpage = $cpperpage;
}
else
{
$perpage = $perpage3x;
}
}
if ( isset($page) && $page > 0 )
{
$startnumb = ($page*$perpage)-$perpage+1;
}
else
{
$page=1;
$startnumb=1;
}
// do the sort box //
$sortoptions = ""; $sortdefault=""; $catrows="";
if ( empty($sort) )
{
$sortparam = ( isset($catsortorder) && $catsortorder > 0 ? $catsortorder : 2 );
}
else
{
$sortparam = $sort;
}
$resultc = ppmysql_query("SELECT * FROM {$Globals['pp_db_prefix']}sort", $link);
while ( list($sortid, $sortname, $sortc) = mysql_fetch_row($resultc) )
{
if ($sortparam == $sortid)
{
$sortdefault = "";
$sortcode = "$sortc";
}
else
{
$sortoptions .= "";
}
}
$sort = "";
// end sort box //
$subcats="";
$searchterms = $si;
$searchcat = $cat;
if ( $ppuser > 0 )
{
list( $tuserid, $tusername, $tmail ) = get_userinfo( "", $ppuser);
$thecatname = "$tusername's {$Globals['pp_lang']['ads']}";
$titlereplace = "$tusername's {$Globals['pp_lang']['ads']}";
}
else
{
if ( $cat == "fav" )
{
list( $tuserid, $tusername, $tmail ) = get_userinfo( "", $User['userid']);
$thecatname = "$tusername's {$Globals['pp_lang']['favorites']}";
}
elseif ( $cat == "all" )
{
$thecatname = $Globals['pp_lang']['callimages'];
}
elseif ( $cat == "last1" )
{
$thecatname = $Globals['pp_lang']['clastday'];
}
elseif ( $cat == "last7" )
{
$thecatname = $Globals['pp_lang']['clast7'];
}
elseif ( $cat == "last14" )
{
$thecatname = $Globals['pp_lang']['clast14'];
}
elseif ( is_numeric($cat) )
{
$ctitleq = ppmysql_query("SELECT c.id,c.catname,c.template,n.userid
FROM {$Globals['pp_db_prefix']}categories c
LEFT JOIN {$Globals['pp_db_prefix']}notify n ON (n.userid='{$User['userid']}' AND n.product=c.id AND n.type=1)
WHERE c.id=$cat", $link);
if ( $ctitleq )
{
list( $catid, $thecatname, $Globals['cattemp'], $notify ) = mysql_fetch_row($ctitleq);
}
}
}
if ( $Globals['cattemp'] > 0 )
{
// We're using a different template here
require "{$Globals['PP_PATH']}/languages/$pplang/showcat{$Globals['cattemp']}.php";
}
else
{
$Globals['cattemp'] = "";
}
if ( empty($si) && is_numeric($cat) )
{
catrow( $cat, "showcat" );
}
$cols = $Globals['thumbcols'];
$phrase = null;
if ( $si || $name || $when || $low || $high)
{
if ( !$what )
{
$what = "allfields";
}
if ( !$when || $when < 1 )
{
$when = null;
}
if ( !$mcats )
{
$mcats = null;
}
$userphrase = $keyphrase = $whenphrase = $multicats = null;
// searching for names
if ( $name )
{
$userphrase .= " AND (user LIKE '%$name%')";
}
// price range search (low and high)
if ( !empty($low) )
{
$pricerange .= " AND price >= $low";
}
if ( !empty($high) )
{
$pricerange .= " AND price <= $high";
}
// time frame (days is default)
if ( $when )
{
if ( !isset($whenterm) ) $whenterm = "d";
if ( $whenterm == "w" ) $days = ($when * 7);
elseif ( $whenterm == "m" ) $days = ($when * 30);
elseif ( $whenterm == "y" ) $days = ($when * 365);
else $days = $when;
$timeq = time() - (($days * 24) * 3600);
$whenphrase = "AND date > $timeq";
}
// search terms
$sterms = trim($si);
$searchterms = explode(" ", $sterms);
$htmlsi = htmlspecialchars($si);
foreach ($searchterms as $key)
{
$key = trim($key);
$key = str_replace( "%", "\%", $key);
if ( $key )
{
if ( !isset($condition) )
{
$scond = "AND";
}
if ( $condition == "or" )
{
$scond = "OR";
}
else
{
$scond = "AND";
}
if ( $what == "allfields" )
{
$keyphrase .= ( empty($keyphrase) ? "AND " : "$scond " );
$keyphrase .= "((title LIKE \"% $key%\" OR description LIKE \"% $key%\" OR keywords LIKE \"% $key%\" OR bigimage LIKE \"% $key%\"
OR extra1 LIKE \"% $key%\" OR extra2 LIKE \"% $key%\" OR extra3 LIKE \"% $key%\" OR extra4 LIKE \"% $key%\" OR extra5 LIKE \"% $key%\" OR extra6 LIKE \"% $key%\")";
$keyphrase .= " OR (title LIKE \"$key%\" OR description LIKE \"$key%\" OR keywords LIKE \"$key%\" OR bigimage LIKE \"$key%\"
OR extra1 LIKE \"%$key%\" OR extra2 LIKE \"%$key%\" OR extra3 LIKE \"%$key%\" OR extra4 LIKE \"%$key%\" OR extra5 LIKE \"%$key%\" OR extra6 LIKE \"%$key%\"))";
}
elseif ( $what == "title" )
{
$keyphrase .= ( empty($keyphrase) ? "AND " : "$scond " );
$keyphrase .= "((title LIKE \"% $key%\")";
$keyphrase .= " OR (title LIKE \"$key%\"))";
}
elseif ( $what == "titledesc" )
{
$keyphrase .= ( empty($keyphrase) ? "AND " : "$scond " );
$keyphrase .= "((title LIKE \"% $key%\" OR description LIKE \"% $key%\")";
$keyphrase .= " OR (title LIKE \"$key%\" OR description LIKE \"$key%\"))";
}
else
{
unset($what);
}
}
}
$phrase = "$keyphrase$userphrase$whenphrase$pricerange";
}
$searchcodes = null;
$catcheck = null;
$mcats = null;
if ( isset($_REQUEST['mcats']) )
{
if ( is_array($_REQUEST['mcats']) )
{
for ( $i = 0; $i < count($_REQUEST['mcats']); $i++ )
{
if ( $mcats != null )
{
$mcats .= ",";
}
$mcats .= (int)$_REQUEST['mcats'][$i];
}
}
else
{
typecast($_REQUEST, array('mcats' => STRING));
}
}
if ( $mcats != "" && !strstr($mcats,"all") )
{
$catcheck = " AND cat IN ($mcats)";
}
elseif ( is_numeric($cat) )
{
$catcheck = " AND cat=$cat";
}
$query = "SELECT id,user,userid,cat,date,title,description,keywords,bigimage,views,approved,rating,price,status,extra1,extra2,extra3,extra4,extra5,extra6,disporder,zipcode,adoptions,isauction,enddate,highbidder,maxbid,currency FROM {$Globals['pp_db_prefix']}products ";
if ( !empty($dist) )
{
$resultc = ppmysql_query("SELECT lat,lon FROM zipData WHERE zipcode='$dist' LIMIT 1", $link);
list($lat,$lon) = mysql_fetch_row($resultc);
if ( empty($lat) || empty($lon) )
{
diewell( $Globals['pp_lang']['nozipfound'] );
}
$result = ppmysql_query("SELECT * FROM zipData WHERE (POW((69.1*(lon-\"$lon\")*cos($lat/57.3)),\"2\")+POW((69.1*(lat-\"$lat\")),\"2\"))<($radius*$radius) GROUP BY zipcode ", $link);
while ( list($searchzip) = mysql_fetch_row($result) )
{
$searchcodes .= "'$searchzip',";
}
$searchcodes = substr($searchcodes, 0, -1);
}
$datecheck = null;
if ( !empty($limit) && $limit != "all" )
{
if ( $limit == "last14" )
{
$days = 14;
}
elseif ( $limit == "last7" )
{
$days = 7;
}
else
{
$days = 1;
}
$timeq = time() - (($days * 24) * 3600);
$datecheck = "AND date > $timeq";
}
elseif ( !empty($date) )
{
$thisdate = getdate($date);
$thismonth = $thisdate["mon"];
$thisyear = $thisdate["year"];
$thisday = $thisdate["mday"];
$lowdate = mktime(0, 0, 0, $thismonth, $thisday, $thisyear);
$highdate = mktime(0, 0, 0, $thismonth, $thisday+1, $thisyear);
$datecheck = "AND date >= $lowdate AND date < $highdate";
}
if ( $cat == "fav" )
{
// My Favorites
if ( empty($si) )
{
$query = "SELECT f.userid,p.id,p.user,p.userid,p.cat,p.date,p.title,p.description,p.keywords,
p.bigimage,p.views,p.approved,p.rating,p.price,p.status,p.extra1,p.extra2,p.extra3,p.extra4,p.extra5,p.extra6,p.disporder,p.zipcode,p.adoptions,p.isauction,p.enddate,p.highbidder,p.maxbid,p.currency
FROM {$Globals['pp_db_prefix']}favorites f, {$Globals['pp_db_prefix']}products p
WHERE f.userid={$User['userid']} AND f.product=p.id $datecheck $sortcode";
}
else
{
$phrase = substr($phrase,4);
$query = "SELECT f.userid,p.id,p.user,p.userid,p.cat,p.date,p.title,p.description,p.keywords,
p.bigimage,p.views,p.approved,p.rating,p.price,p.status,p.extra1,p.extra2,p.extra3,p.extra4,p.extra5,p.extra6,p.disporder,p.zipcode,p.adoptions,p.isauction,p.enddate,p.highbidder,p.maxbid,p.currency
FROM {$Globals['pp_db_prefix']}favorites f, {$Globals['pp_db_prefix']}products p
WHERE ($phrase) AND f.userid={$User['userid']} AND f.product=p.id $datecheck $sortcode";
}
}
elseif ( !is_numeric($cat) )
{
if ( $cat == "all" )
{
$ppquery = "";
if ( $ppuser > 0 )
{
$ppquery = "AND userid='$ppuser'";
}
if ( !empty($dist) )
$query .= "WHERE zipcode IN ($searchcodes) AND approved=1 $catcheck $ppquery $phrase $datecheck $exclude_cat ORDER BY zipcode";
else
$query .= "WHERE approved=1 $catcheck $ppquery $phrase $datecheck $exclude_cat $sortcode";
}
else
{
// Last 1 days
if ( $cat == "last14" ) $days = 14;
elseif ( $cat == "last7" ) $days = 7;
else $days = 1;
list($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime();
$mon = $mon + 1;
$year = $year + 1900;
$hour = $hour - ($days * 24);
$searchdate = mktime($hour,$min,$sec,$mon,$mday,$year);
$query .= "WHERE approved=1 $catcheck AND date > $searchdate $datecheck $exclude_cat $sortcode";
}
}
elseif (empty($si) && empty($name))
{
if ( empty($ppuser) )
{
if ( $cat == 500 )
{
$query .= "WHERE approved=1 $catcheck AND cat=$cat $datecheck $exclude_cat $sortcode";
}
else
{
$query .= "WHERE approved=1 $catcheck AND cat=$cat $datecheck $exclude_cat $sortcode";
}
}
else
{
$query .= "WHERE ";
if ( $ppuser != $User['userid'] )
{
$query .= "approved=1 $forcat AND ";
}
$query .= "approved=1 AND userid=$ppuser $datecheck $exclude_cat $sortcode";
}
}
else
{
if ( !empty($dist) )
$query .= "WHERE zipcode IN ($searchcodes) AND approved=1 $catcheck $phrase $datecheck $exclude_cat ORDER BY zipcode";
else
$query .= "WHERE approved=1 $catcheck $phrase $datecheck $exclude_cat $sortcode";
}
$queryv = ppmysql_query($query,$link);
$rowcnt = mysql_num_rows($queryv);
$count=0; $cntresults=0;
$numcols = $Globals['thumbcols'] + 1;
$pwidth = intval(100/($numcols-1));
list($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime();
$mon = $mon + 1;
$year = $year + 1900;
$hour = $hour - ($Globals['numdays'] * 24);
$cutoffdate = mktime($hour,$min,$sec,$mon,$mday,$year);
if ( $Globals['zipcode'] == "yes" )
{
$pickcode = "