<?

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

*************************************************
*			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('class/object.class.php');


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

$object = new obj;

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

if ( isset( $_POST['edit'] ) )
{
        if ( !empty( $_POST['a'] ) )
        {
                $lpa = 0;
                foreach ( $_POST['a'] as $showA )
                {
                        $lpa++;
                        if ( $lpa == 1 )
                        {
                                $a = $showA;
                        }
                        else
                        {
                                $a .= '-' . $showA;
                        }
                }
        }
        else
        {
                $a = '';
        }
        if ( !empty( $_POST['b'] ) )
        {
                $lpb = 0;
                foreach ( $_POST['b'] as $showB )
                {
                        $lpb++;
                        if ( $lpb == 1 )
                        {
                                $b = $showB;
                        }
                        else
                        {
                                $b .= '-' . $showB;
                        }
                }
        }
        else
        {
                $b = '';
        }
        if ( !empty( $_POST['c'] ) )
        {
                $lpc = 0;
                foreach ( $_POST['c'] as $showC )
                {
                        $lpc++;
                        if ( $lpc == 1 )
                        {
                                $c = $showC;
                        }
                        else
                        {
                                $c .= '-' . $showC;
                        }
                }
        }
        else
        {
                $c = '';
        }
        if (   empty( $_POST['priceOn'] )  )
        {
                $error = 'Pola oznaczone \'*\' są obowiązkowe!';
        }
        else
        {
		
$object -> edit  (  html( $_POST['type'] ), html( $_POST['state'] ),  html( $_POST['name'] ), html( $_POST['adress'] ),  html( $_POST['city'] ), html( $_POST['tel'] ),  html( $_POST['email'] ),  html( $_POST['www'] ),  html( $_POST['priceOn'] ),   html( $a ), html( $b ), html( $c ),  html( $_POST['region'] ),  html( $_POST['droga'] ),   $_POST['txt'] ,  $cfg['freeDay'],  html( $_POST['budulec'] ),   html( $_POST['dach'] ),  html( $_POST['dojazd'] ), html( $_POST['kanalizacja'] ),  html( $_POST['kat'] ), html( $_POST['ogrodzenie'] ), html( $_POST['stan'] ), html( $_POST['ogrzewanie'] ), html( $_POST['okna'] ), html( $_POST['rynek'] ), html( $_POST['rodzaj'] ), html( $_POST['rok'] ), html( $_POST['pom'] ), html( $_POST['poc'] ), html( $_POST['pietra'] ), html( $_POST['pokoje'] ), html( $_POST['pietro'] ), html( $_POST['pow'] ), html( $_POST['dzielnica'] ), $id, $mysql );



                if ( !empty( $_POST['delete'] ) )
                {
                        foreach ( $_POST['delete'] as $photoId )
                        {
                                $object -> deletePhoto ( $photoId, $mysql );
                        }
                }

                $smarty -> assign('success', 'Poprawnie zapisano zmiany!');
        }
}

if ( isset( $_POST['new_photo'] ) )
{
        
        if ( $_FILES['photo']['tmp_name'] !== '' )
        {
                if ( $object -> walidPhoto( $_FILES['photo']['name'] ) )
                {
                        $object -> uploadPhoto ( $_FILES['photo']['name'], $_FILES['photo']['tmp_name'], $id, $mysql );
                        $smarty -> assign('success', 'Poprawnie dodano nowe zdjęcie!');
                }
                else
                {
                        $error = 'Zdjęcie posiada niedozwolony format!';
                }
        }
        else
        {
                $error = 'Nie wybrano pliku zdjęcia!';
        }
}

$sql = "SELECT * FROM object WHERE obUserId = '".$_SESSION['userId']."' AND obId = '$id'";
$q = $mysql -> q( $sql );
$edit = array();
while ( $db = mysql_fetch_array( $q ) )
{
        $edit[] = $db;
}
$smarty -> assign('edit', $edit);

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

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

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

$smarty -> assign('showRynek', $object -> showRynek( $mysql ));
$smarty -> assign('showOkna', $object -> showOkna( $mysql ));
$smarty -> assign('showOgrzewanie', $object -> showOgrzewanie( $mysql ));
$smarty -> assign('showOgrodzenie', $object -> showOgrodzenie( $mysql ));
$smarty -> assign('showKanalizacja', $object -> showKanalizacja( $mysql ));
$smarty -> assign('showDojazd', $object -> showDojazd( $mysql ));
$smarty -> assign('showBudulec', $object -> showBudulec( $mysql ));
$smarty -> assign('showDach', $object -> showDach( $mysql ));




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