<?

/* ------------------------------------------------------------------- */
/*

*************************************************
*			UWAGA! SKRYPT NIE JEST DARMOWY.			*
*		DALSZE ROZPOWSZECHNIANIE BEZ ZGODY 			*
*			FIRMY ArtGlobal JEST ZABRONIONE.			*
*************************************************

*************************************************
*	WWW.ArtGlobal.PL		PRODUCENT OPROGRAMOWANIA	*
*	NAZWA SKRYPTU:		NIERUCHOMOSCI 6.0			*
*	WERSJA FINALNA:	04.10.2010						*
*	KONTAKT:				kontakt@artglobal.pl			*
*************************************************

Copyright (c) 2010 ArtGlobal. Wszelkie prawa zastrzeżone.

*/
/* ------------------------------------------------------------------- */
    header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
    header("Cache-Control: public"); 
    header("Content-Description: File Transfer");
    
    session_cache_limiter("must-revalidate");
		
require_once('inc/config.inc.php');
require_once('class/object.class.php');
require_once('class/pager.class.php');
require_once('class/user.class.php');

$object = new obj;
include('inc/seo.inc.php');
$smarty -> register_function('nopl', 'parse');


$smarty -> assign('showTypeLicz', $object -> showTypeLicz( $mysql ));
$smarty -> assign('showStateLicz', $object -> showStateLicz( $mysql ));
$smarty -> assign('showKategriaLicz', $object -> showKategriaLicz( $mysql ));
$smarty -> assign('showDiler', $object -> showDiler( $mysql ));
$smarty -> assign('showType', $object -> showType( $mysql ));
$smarty -> assign('showState', $object -> showState( $mysql ));
$smarty -> assign('showRegion', $object -> showRegion( $mysql ));
$smarty -> assign('showPages', $object -> showPages( $mysql ));
$smarty -> assign('showKategoria', $object -> showKategoria( $mysql ));
$smarty -> assign('showStan', $object -> showStan( $mysql ));
$smarty -> assign('showRodzaj', $object -> showRodzaj( $mysql ));
$smarty -> assign('showRynek', $object -> showRynek( $mysql ));
$smarty -> assign('showOgl', $object -> showOgl( $mysql ));
$smarty -> assign('showOglBB', $object -> showOglBB( $mysql ));
$smarty -> assign('promoA', $object -> showPromoA( $mysql ));
$smarty -> assign('promoAA', $object -> showPromoB( $mysql ));
$smarty -> assign('reklama', $object -> showReklamaA( $mysql ));
$smarty -> assign('reklamaS', $object -> showReklamaS( $mysql ));
$smarty -> assign('reklamaD', $object -> showReklamaD( $mysql ));
$smarty -> assign('reklamaB', $object -> showReklamaB( $mysql ));
///////////////////
$login = new user;

if ( isset( $_POST['getLogin'] ) )
{
        ( $login -> isEmpty ( $_POST['login'] ) ? $smarty -> assign('login', $_POST['login']) : $error[] = 'Nie podano loginu!' );
        ( $login -> isEmpty ( $_POST['pass'] ) ? $smarty -> assign('pass', $_POST['pass']) : $error[] = 'Nie podano hasła!' );
        ( $login -> check_login ( $_POST['login'], $_POST['pass'], $mysql ) ? '' : $error[] = 'Dane są niepoprawne!' );
        
        if ( $error == null )
        {
                $session -> session_register ( $_POST['login'], $mysql );
                header('Location: panel.html');
        }
}
$smarty -> assign('error', $error);
///////////////////

					$sql = "SELECT a.*, b.*, c.*, d.*, e.*,  g.*, h.* 
					FROM object AS a, type AS b, state AS c , region AS d, kategoria AS e,  rodzaj AS g, stan AS h 
					WHERE a.obTypeId = b.typeId AND a.obStateId = c.stateId AND a.obRegion = d.regionId AND a.obKat = e.katId  AND a.obRodzaj = g.rodzajId AND a.obStan = h.stanId AND a.obPromo = '1' AND a.obConfirm = '1' AND a.obDateEnd > NOW() ORDER by  RAND() LIMIT 5";
					$q = $mysql -> q( $sql );
					
$smarty -> assign('nump', $mysql -> num( $sql ));
////////////////////
if ( $_GET['act'] == 'promowane' || $_GET['act'] == 'last' || $_GET['act'] == 'state' || $_GET['act'] == 'type' || $_GET['act'] == 'region' || $_GET['act'] == 'droga'  ) //
{
        $session -> clearSearch ();
}

$object = new obj;


	

if ( isset( $_POST['getSearch'] ) )
{
        $_SESSION['txt'] = html( $_POST['txt'] );
        $_SESSION['city'] = html( $_POST['city'] );
        $_SESSION['state'] = html( $_POST['state'] );
        $_SESSION['type'] = html( $_POST['type'] );
        $_SESSION['region'] = html( $_POST['region'] );
        $_SESSION['droga'] = html( $_POST['droga'] );
        $_SESSION['priceOn'] = html( $_POST['priceOn'] );
        $_SESSION['priceOff'] = html( $_POST['priceOff'] );

$_SESSION['pokoje'] = html( $_POST['pokoje'] );
$_SESSION['powOn'] = html( $_POST['powOn'] );
$_SESSION['powOff'] = html( $_POST['powOff'] );
$_SESSION['dziel'] = html( $_POST['dziel'] );
$_SESSION['kategoria'] = html( $_POST['kategoria'] );
$_SESSION['stan'] = html( $_POST['stan'] );
$_SESSION['rodzaj'] = html( $_POST['rodzaj'] );
$_SESSION['rynek'] = html( $_POST['rynek'] );
        $_SESSION['ulica'] = html( $_POST['ulica'] );

}

$smarty -> assign('txt', $_SESSION['txt']);
$smarty -> assign('city', $_SESSION['city']);
$smarty -> assign('state', $_SESSION['state']);
$smarty -> assign('type', $_SESSION['type']);
$smarty -> assign('region', $_SESSION['region']);
$smarty -> assign('droga', $_SESSION['droga']);
$smarty -> assign('priceOn', $_SESSION['priceOn']);
$smarty -> assign('priceOff', $_SESSION['priceOff']);

$smarty -> assign('pokoje', $_SESSION['pokoje']);
$smarty -> assign('powOn', $_SESSION['powOn']);
$smarty -> assign('powOff', $_SESSION['powOff']);
$smarty -> assign('dziel', $_SESSION['dziel']);
$smarty -> assign('kategoria', $_SESSION['kategoria']);
$smarty -> assign('stan', $_SESSION['stan']);
$smarty -> assign('rodzaj', $_SESSION['rodzaj']);
$smarty -> assign('rynek', $_SESSION['rynek']);
$smarty -> assign('ulica', $_SESSION['ulica']);

$smarty -> assign('showState', $object -> showState( $mysql ));
/*$smarty -> assign('showType', $object -> showType( $mysql ));

$smarty -> assign('showRegion', $object -> showRegion( $mysql ));
$smarty -> assign('showDroga', $object -> showDroga( $mysql ));

$smarty -> assign('showMiasto', $object -> showMiasto( $mysql ));
$smarty -> assign('showRodzaj', $object -> showRodzaj( $mysql ));
$smarty -> assign('showKategoria', $object -> showKategoria( $mysql ));
$smarty -> assign('showStan', $object -> showStan( $mysql ));
*/

	
	
$link = 'szukaj,{^link}.html';

/*$sql = "SELECT a.*, b.*, c.*, d.*, e.*, g.*, h.*, i.*, j.*, k.*,  m.*, n.*, o.*, p.*, r.*

FROM object AS a, type AS b, state AS c , region AS d, droga AS e,  rodzaj AS g, budulec AS h, dach AS i, dojazd AS j, kanalizacja AS k,  ogrzewanie AS m, okna AS n, rynek AS o, stan AS p, kategoria AS r

WHERE a.obTypeId = b.typeId AND a.obStateId = c.stateId AND a.obRegion = d.regionId AND a.obDroga = e.drogaId  AND a.obRodzaj = g.rodzajId  
AND a.obBudulec = h.budulecId  
AND a.obDach = i.dachId  
AND a.obDojazd = j.dojazdId  
AND a.obKanalizacja = k.kanalizacjaId  

AND a.obOgrzewanie = m.ogrzewanieId  
AND a.obOkna = n.oknaId  
AND a.obRynek = o.rynekId  
AND a.obStan = p.stanId  
AND a.obKat = r.katId 
AND a.obConfirm = '1' AND a.obDateEnd > NOW()";
*/

$sql = "SELECT a.*, b.*, c.*, d.*,  g.*,  o.*, p.*, r.*
FROM object AS a, type AS b, state AS c , region AS d,  rodzaj AS g, rynek AS o, stan AS p, kategoria AS r
WHERE a.obTypeId = b.typeId AND a.obStateId = c.stateId AND a.obRegion = d.regionId AND a.obRodzaj = g.rodzajId  

AND a.obRynek = o.rynekId  
AND a.obStan = p.stanId  
AND a.obKat = r.katId 
AND a.obConfirm = '1' AND a.obDateEnd > NOW()";

if ( !empty( $_SESSION['txt'] ) && $_SESSION['txt'] !== 'szukane miasto' ) { $sql .= " AND a.obCity LIKE '%".$_SESSION['txt']."%'"; }
if ( !empty( $_SESSION['dziel'] ) && $_SESSION['dziel'] !== 'szukana dzielnica' ) { $sql .= " AND a.obDzielnica LIKE '%".$_SESSION['dziel']."%'"; }
if ( !empty( $_SESSION['ulica'] ) && $_SESSION['ulica'] !== 'szukana ulica' ) { $sql .= " AND a.obAdress  LIKE '%".$_SESSION['ulica']."%'"; }

if ( !empty( $_SESSION['city'] )   && !$_GET['act']) { $sql .= " AND a.obCity LIKE '%".$_SESSION['city']."%'"; }
if ( !empty( $_SESSION['type'] ) ) { $sql .= " AND a.obTypeId = '".$_SESSION['type']."'"; }
if ( !empty( $_SESSION['state'] ) ) { $sql .= " AND a.obStateId = '".$_SESSION['state']."'"; }

////////////////
if ( !empty( $_SESSION['region'] ) ) { $sql .= " AND a.obRegion = '".$_SESSION['region']."'"; }
if ( !empty( $_SESSION['droga'] ) ) {  $sql .= " AND a.obDroga = '".$_SESSION['droga']."'"; }

if ( !empty( $_SESSION['kategoria'] ) ) {  $sql .= " AND a.obKat = '".$_SESSION['kategoria']."'"; }
if ( !empty( $_SESSION['stan'] ) ) {  $sql .= " AND a.obStan = '".$_SESSION['stan']."'"; }
if ( !empty( $_SESSION['rodzaj'] ) ) {  $sql .= " AND a.obRodzaj = '".$_SESSION['rodzaj']."'"; }

if ( !empty( $_SESSION['pokoje'] ) ) {  $sql .= " AND a.obPokoje = '".$_SESSION['pokoje']."'"; }
if ( !empty( $_SESSION['rynek'] ) ) {  $sql .= " AND a.obRynek = '".$_SESSION['rynek']."'"; }

////////////

if ( !empty( $_SESSION['priceOn'] ) && $_SESSION['priceOn'] !== 'cena od' && !empty( $_SESSION['priceOff'] ) && $_SESSION['priceOff'] !== 'cena do' )
{        $sql .= " AND a.obPriceOn BETWEEN '".$_SESSION['priceOn']."' AND '".$_SESSION['priceOff']."'"; }

if ( !empty( $_SESSION['rokOn'] ) && $_SESSION['rokOn'] !== 'rok od' && !empty( $_SESSION['rokOff'] ) && $_SESSION['rokOff'] !== 'rok do' )
{        $sql .= " AND a.obRok BETWEEN '".$_SESSION['rokOn']."' AND '".$_SESSION['rokOff']."'"; }


if ( !empty( $_SESSION['powOn'] ) && $_SESSION['powOn'] !== 'pow. od' && !empty( $_SESSION['powOff'] ) && $_SESSION['powOff'] !== 'pow. do' )
{        $sql .= " AND a.obPowM  BETWEEN '".$_SESSION['powOn']."' AND '".$_SESSION['powOff']."'"; }

////////////

if ( $_GET['act'] == 'last' )
{
        $sql .= " AND a.obLastMinute = '1'";
        $link = 'szukaj,{^link},last-minute.html';
}
if ( $_GET['act'] == 'promowane' )
{
        $sql .= " AND a.obPromo = '1'";
        $link = 'szukaj,{^link},promowane.html';
}
if ( $_GET['act'] == 'morze' )
{
        $sql .= " AND  a.obStateId = '11'";
        $link = 'szukaj,{^link},morze.html';
}



//////////NOCLEGI NAD MORZEM/////////

//////////////////////////////////////

if ( $_GET['act'] == 'state' & isset( $_GET['id'] ) )
{
        $sql .= "AND a.obStateId = '".$_GET['id']."'";
        $link = 'szukaj,state,' . $_GET['id'] . ',{^link},'. $_GET['n'] . '.html';
}


if ( $_GET['act'] == 'region' & isset( $_GET['id'] ) )
{
        $sql .= "AND a.obRegion = '".$_GET['id']."'";
        $link = 'szukaj,region,' . $_GET['id'] . ',{^link},'. $_GET['n'] . '.html';
}

if ( $_GET['act'] == 'droga' & isset( $_GET['id'] ) )
{
        $sql .= "AND a.obDroga = '".$_GET['id']."'";
        $link = 'szukaj,droga,' . $_GET['id'] . ',{^link},'. $_GET['n'] . '.html';
}
///////////

if ( $_GET['act'] == 'type' & isset( $_GET['id'] ) )
{
        $sql .= "AND a.obTypeId = '".$_GET['id']."'";
        $link = 'szukaj,type,' . $_GET['id'] . ',{^link},'. $_GET['n'] . '.html';
}
if ( $_GET['act'] == 'kategoria' & isset( $_GET['id'] ) )
{
        $sql .= "AND a.obKat = '".$_GET['id']."'";
        $link = 'szukaj,kategoria,' . $_GET['id'] . ',{^link},'. $_GET['n'] . '.html';
}

if ( $_GET['act'] == 'woj' & isset( $_GET['id'] )  )
{
        $sql .= "AND a.obStateId = '".$_GET['id']."'";
        $link = 'szukaj,woj,' . $_GET['id'] . ',{^link},'. $_GET['n'] . '.html';
}
////////////

//$sql .= " ORDER by a.obId DESC";
$sql .= " ORDER by obPromo desc, obWyroz desc, a.obId DESC";

$n = $cfg['searchOfPage'];

$smarty -> assign('n', $n);
$q = $mysql -> q( $sql );
$num = $mysql -> num( $sql ); $smarty -> assign('num', $num);
$p = new Pager('kat', $num, $n, '100');
$p -> setVar("html_link", "<a href=\"".$link."\">{^name}</a>\n");
$p -> Render();
$start = $p -> startRecord();


$sql2 = $sql . " LIMIT $start, $n";
$q = $mysql -> q( $sql2 );
$index = array();
$count = 0;
while ( $db = mysql_fetch_array( $q ) )
{
        $index[$count] = $db;
        $sql2 = "SELECT photoUrl FROM photos WHERE photoObjectId = '".$db['obId']."' ORDER by photoId ASC LIMIT 1";
        $q2 = $mysql -> q( $sql2 );
        $db2 = mysql_fetch_array( $q2 );
        $index[$count]['photo'] = $db2[0];
        $count++;
}
$smarty -> assign('index', $index);

$str = $p -> getVar("html_out"); $smarty->assign('str', $str);

$smarty -> assign('title', 'Wyniki wyszukiwania');

$smarty -> display('szukaj.tpl');
?>
