<?

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

*************************************************
*			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.

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


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


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

$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('promoA', $object -> showPromoA( $mysql ));
$smarty -> assign('reklamaB', $object -> showReklamaB( $mysql ));
$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('showPromoM', $object -> showPromoM( $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.*,   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);
///////////////////
$smarty -> assign('maps', '');

/////////////////////
					$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 ));

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

$error = null;
$success = null;

$id = html( $_GET['id'] );

if($_GET['wizytadd'] == 'true')  
	{ 
			$sql = "UPDATE `object` SET `wizyt`=`wizyt`+1 WHERE obId = '$id' ";
			$q = $mysql -> q( $sql );
	}


$sql = "SELECT a.*, b.*, c.*, d.*, e.*, f.*, g.*, h.*, i.*, j.*, k.*, l.*, m.*, n.*, o.*, p.*
FROM object AS a, type AS b, state AS c , region AS d, droga AS e,  rodzaj AS f, kategoria AS g, stan AS h, 
rynek AS i, budulec AS j, dach AS k, dojazd AS l, ogrodzenie AS m, ogrzewanie AS n, kanalizacja AS o, okna AS p
WHERE a.obTypeId = b.typeId AND a.obStateId = c.stateId AND a.obRegion = d.regionId AND a.obDroga = e.drogaId  AND a.obRodzaj = f.rodzajId AND a.obKat = g.katId AND a.obStan = h.stanId  
AND a.obRynek = i.rynekId  
AND a.obBudulec = j.budulecId 
AND a.obDach = k.dachId
AND a.obDojazd = l.dojazdId
AND a.obOgrodzenie = m.ogrodzenieId
AND a.obOgrzewanie = n.ogrzewanieId
AND a.obKanalizacja = o.kanalizacjaId
AND a.obOkna = p.oknaId 
AND a.obId = '$id'";

$q = $mysql -> q( $sql );
$index = array();
$count = 0;
while ( $db = mysql_fetch_array( $q ) )
{
        $index[$count] = $db;
        $count++;
}
$smarty -> assign('index', $index);

$googleAdress = $index[0]['stateName'] . ', ' . $index[0]['obCity']. ', ' . $index[0]['obAdress'];
//$googleAdress = $index[0]['stateName'] . ', ' . $index[0]['obCity'];
$smarty -> assign('googleAdress', $googleAdress);

				$sql = "SELECT * FROM photos WHERE photoObjectId = '$id' ORDER by photoId DESC";
				$q = $mysql -> q( $sql );
				$photos = array();
							while ( $db = mysql_fetch_array( $q ) )
							{
											$photos[] = $db;
							}
				$smarty -> assign('photos', $photos);





if ( isset( $_POST['sendMessage'] ) )
{
        $contact = new sendMail;
        
        ( $contact -> isEmpty( $_POST['email'] ) ? $smarty -> assign('email', $_POST['email']) : $error[] = 'Nie podano adresu email!' );
        ( $contact -> isEmpty( $_POST['temat'] ) ? $smarty -> assign('temat', $_POST['temat']) : $error[] = 'Nie podano tematu!' );
        ( $contact -> isEmpty( $_POST['txt'] ) ? $smarty -> assign('txt', $_POST['txt']) : $error[] = 'Nie podano treści!' );
				( $contact -> isEmpty( $_POST['security_code'] ) ? $smarty -> assign('security_code', $_POST['security_code']) : $error[] = 'Podaj prawidłowy kod bezpieczeństwa!' );

        						 
				if ( $error == null )
						{
			
						if($_POST['countadd'] == 'true')  
						{ 
						$sql = "UPDATE `object` SET `clicked`=`clicked`+1 WHERE obId = '$id' ";
						$q = $mysql -> q( $sql );
						}

					 
							if( $_SESSION['security_code'] == $_POST['security_code'] && !empty($_SESSION['security_code'] ) ) 
							{

				$sql = "SELECT obEmail, obName FROM object WHERE obId = '$id'";
        $q = $mysql -> q( $sql );
        $db = mysql_fetch_array( $q );
        $email = $db[0];
				$obName = $db[1];
				

					 unset($_SESSION['security_code']);
                $tresc = "<br><br>Tresc: " .html( $_POST['txt'] ). "<br><br> email od : <a href=mailto:".html( $_POST['email'] )."> " .html( $_POST['email'] ). "</a><br>";
								
								$contact ->  mailer ( $email, $obName, '', html( $_POST['temat'] ), $tresc ); 

                $smarty -> assign('success', 'Wiadomość została wysłana poprawnie! ');
                $smarty -> assign('email', '');
                $smarty -> assign('temat', '');
                $smarty -> assign('txt', '');
								
							} 

        }

}




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

$smarty -> assign('title', $index[0]['typeName'] . ' &raquo; ' . $index[0]['obCity'] . ' &raquo; ' . $index[0]['obName']);

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