<?
if($action == process_search)
{
// Collecting search tokens & search tables
$sql_from = dt_profile;
$sql_where = "";
$sql_vars = "*";
switch($search_type)
{
case member_code:
$sID = $membercode;
$sID[ 0 ] = " ";
for($i = 0; $i < strlen($sID);$i++)
{
if($sID[ $i ] != "0" && $sID[ $i ] != " ")
{
$sID = (int)$sID;
break;
}
$sID[ $i ] = " ";
}
$sql_from = "dt_profile AS p";
$sql_where = "member_id='$sID'";
break;
case profile_name:
$sql_from = "dt_profile AS p";
$sql_where = "name LIKE '%$profile_name%'";
break;
default:
$nWas = 0;
if($gender != "couple" && $gender != "couple")
{
$sql_from = dt_profile; ( "$gender != 'couple' AND looking_for= $gender != 'couple'");
}
else if($gender != "Male" && $gender != "female")
{
$sql_from = dt_profile; ( "$gender != 'Male' AND looking_for= $gender != 'female''");
}
if($age_from != "")
{
$year = date("Y") - $age_from;
$sql_where .= ($nWas ? "and " : "")."p.birth_year<='$year' ";
$nWas = 1;
}
if($age_to != "")
{
$year = date("Y") - $age_to;
$sql_where .= ($nWas ? "and " : "")."p.birth_year>='$year' ";
$nWas = 1;
}
if($country != "")
{
$sql_where .= ($nWas ? "and " : "")."p.country='$country' ";
$nWas = 1;
}
if($city != "")
{
$sql_where .= ($nWas ? "and " : "")."p.city LIKE '%$city%' ";
$nWas = 1;
}
if($state != "")
{
$sql_where .= ($nWas ? "and " : "")."p.state LIKE '%$state%' ";
$nWas = 1;
}
if ($piconly != "")
{
$sql_where .= ($nWas ? "and " : "")."f.member_id = p.member_id and f.filename_1 <> ''";
$nWas = 1;
$sql_from = "dt_profile AS p, dt_photos as f";
}
else
{
$sql_from = "dt_profile AS p";
}
// Easily it is EASY SEARCH
}
$search_query = "SELECT $sql_vars, p.id FROM $sql_from WHERE (p.status='1' ".($sql_where == "" ? ")" : " AND $sql_where)");
$profiles = q($search_query);
include "templates/search_results.ihtml";
}
else if($action == process_quicksearch)
{
if($gender != "any" && $gender != "")
{
$sql_where = "gender='".($gender[ 0 ] == M ? "Man" : "Vrouw")."' and looking_for='".($gender[1] == V ? "Vrouw" : "Man")."' ";
$nWas = 1;
}
if($age_from != "")
{
$year = date("Y") - $age_from;
$sql_where .= ($nWas ? "and " : "")."birth_year>='$year' ";
$nWas = 1;
}
if($age_to != "")
{
$year = date("Y") - $age_to;
$sql_where .= ($nWas ? "and " : "")."birth_year<='$year' ";
$nWas = 1;
}
if ($radius != "" && $zipcode != "")
{
$zipsrch = "select longw,latn from dt_zips where zipcode = '$zipcode'";
$ARET = f(q($zipsrch));
$istartlong = $ARET["longw"];
$istartlat = $ARET["latn"];
$iRadius = $radius;
$LatRange = ($iRadius / ((6076 / 5280) * 60));
$LongRange = ($iRadius / (double)(((cos($istartlat * 3.141592653589 / 180) * 6076) / 5280) * 60));
$LowLatitude = $istartlat - $LatRange;
$HighLatitude = $istartlat + $LatRange;
$LowLongitude = $istartlong - $LongRange;
$HighLongitude = $istartlong + $LongRange;
$distsrch = "SELECT zipcode FROM dt_zips WHERE (latn <= '$HighLatitude') AND (latn >= '$LowLatitude') AND (longw >= '$LowLongitude') AND (longw <= '$HighLongitude')";
$QRETURN1= q($distsrch);
$QNUM = (int)nr($QRETURN1);
$i = 0;
while ($ARET1 = f($QRETURN1))
{
if ($i == 0)
{
$zip = "zipcode = '" . $ARET1["zipcode"] . "'";
$i = 1;
}
else
{
$zip .= " OR zipcode = '" . $ARET1["zipcode"] . "'";
}
}
$sql_where .= ($nWas ? "and " : ""). $zip." ";
$nWas = 1;
}
if ($piconly != "")
{
$sql_where .= ($nWas ? "and " : "")."f.member_id = p.member_id and f.filename_1 <> ''";
$nWas = 1;
$sql_from = "dt_profile AS p, dt_photos as f";
}
else
{
$sql_from = "dt_profile AS p";
}
$search_query = "SELECT *, p.id FROM $sql_from WHERE (p.status='1' ".($sql_where == "" ? ")" : " AND $sql_where)");
$profiles = q($search_query);
include "templates/search_results.ihtml";
}
else
{
include "templates/easy_search.ihtml";
}
?>