<?


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

*************************************************
*			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) 2011 ArtGlobal. Wszelkie prawa zastrzeżone.

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


require_once('inc/config.inc.php');
require_once('class/object.class.php');
require_once('class/user.class.php');

$object = new obj;

$smarty -> assign('indexTitle2', '');

include('inc/seo.inc.php');
$smarty -> register_function('nopl', 'parse');
$smarty -> assign('showType', $object -> showType( $mysql ));
$smarty -> assign('showStateLicz', $object -> showStateLicz( $mysql ));
$smarty -> assign('showState', $object -> showState( $mysql ));

$smarty -> assign('showRegion', $object -> showRegion( $mysql ));
$smarty -> assign('showPages', $object -> showPages( $mysql ));
//$smarty -> assign('showMiasto', $object -> showMiasto( $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('showDiler', $object -> showDiler( $mysql ));
$smarty -> assign('showOgl', $object -> showOgl( $mysql ));
$smarty -> assign('showOglB', $object -> showOglB( $mysql ));
$smarty -> assign('reklama', $object -> showReklamaA( $mysql ));
$smarty -> assign('reklamaB', $object -> showReklamaB( $mysql ));
$smarty -> assign('reklamaC', $object -> showReklamaC( $mysql ));
$smarty -> assign('reklamaD', $object -> showReklamaD( $mysql ));
$smarty -> assign('reklamaD2', $object -> showReklamaD2( $mysql ));
$smarty -> assign('promoA', $object -> showPromoA( $mysql ));
$smarty -> assign('showPromoM', $object -> showPromoM( $mysql ));
$smarty -> assign('showTypeLicz', $object -> showTypeLicz( $mysql ));
$smarty -> assign('showKategriaLicz', $object -> showKategriaLicz( $mysql ));

///////////LICZ//////////
$sql = "SELECT COUNT(*) FROM users ";
$q = $mysql -> q( $sql );
$db = mysql_fetch_array( $q );
$smarty -> assign('licz', $db[0]);

$sql = "SELECT COUNT(*) FROM object ";
$q = $mysql -> q( $sql );
$db = mysql_fetch_array( $q );
$smarty -> assign('liczOB', $db[0]);


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


///////////////////
$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.*,   f.*, g.*, h.* 
FROM object AS a, type AS b, state AS c ,   rodzaj AS f, kategoria AS g, stan AS h 
WHERE a.obTypeId = b.typeId AND a.obStateId = c.stateId   AND a.obRodzaj = f.rodzajId  AND a.obStan = h.stanId AND a.obKat = g.katId  AND a.obPromo = '1' AND a.obConfirm = '1' AND a.obDateEnd > NOW() AND a.obPromoDateEnd > NOW() ORDER by  RAND() LIMIT ".$cfg['objectIndexPromo']."";
$q = $mysql -> q( $sql );
$smarty -> assign('nump', $mysql -> num( $sql ));
$promo = array();

$count = 0;
while ( $db = mysql_fetch_array( $q ) )
{

        $promo[$count] = $db;
        $sql2 = "SELECT photoUrl FROM photos WHERE photoObjectId = '".$db['obId']."' ORDER by photoId  DESC";
        $q2 = $mysql -> q( $sql2 );
			
				$db2 = mysql_fetch_array( $q2 );			 
        $promo[$count]['photo'] = $db2[0];

 $count++;
 
}

$smarty -> assign('promo', $promo);




$sql = "SELECT a.*, b.*, c.*, f.*, g.*, h.* 
FROM object AS a, type AS b, state AS c ,   rodzaj AS f,  kategoria AS g, stan AS h 
WHERE a.obTypeId = b.typeId AND a.obStateId = c.stateId  AND a.obRodzaj = f.rodzajId  AND a.obStan = h.stanId  AND a.obKat = g.katId  AND a.obConfirm = '1' AND a.obDateEnd > NOW() ORDER by a.obId DESC LIMIT ".$cfg['objectIndex']."";
$q = $mysql -> q( $sql );
$smarty -> assign('num', $mysql -> num( $sql ));
$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);


						
$sql = "SELECT pagesTxt FROM pages WHERE pagesId = '2'";
$q = $mysql -> q( $sql );
$db = mysql_fetch_array( $q );

$smarty -> assign('glowna', $db[0]);

//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

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