<?

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

*************************************************
*			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');

$numPhotoAdd = $cfg['addPhoto'] - 3;

for ( $ph = 4; $ph <= $numPhotoAdd + 3; $ph++ )
{
        $pho .= '<tr><td><input type="file" name="photo_'.$ph.'" value="" style="width: 450px;" /></td></tr>';
}
$smarty -> assign('ph', $pho);

$object = new obj;

if ( isset( $_POST['add'] ) )
{
        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 = '';
        }
		
	
$smarty -> assign('type', $_SESSION['type']);
$smarty -> assign('state', $_SESSION['state']);
$smarty -> assign('name', $_SESSION['name']);
$smarty -> assign('adress', $_SESSION['adress']);
$smarty -> assign('city', $_SESSION['city']);
$smarty -> assign('dzielnica', $_SESSION['dzielnica']);
$smarty -> assign('tel', $_POST['tel']);
$smarty -> assign('email', $_POST['email']);
$smarty -> assign('www', $_POST['www']);
		

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



$smarty -> assign('budulec', $_SESSION['budulec']);
$smarty -> assign('dach', $_SESSION['dach']);
$smarty -> assign('dojazd', $_SESSION['dojazd']);
$smarty -> assign('kanalizacja', $_SESSION['kanalizacja']);
$smarty -> assign('kat', $_SESSION['kat']);
$smarty -> assign('ogrodzenie', $_SESSION['ogrodzenie']);
$smarty -> assign('stan', $_SESSION['stan']);
$smarty -> assign('ogrzewanie', $_SESSION['ogrzewanie']);
$smarty -> assign('okna', $_SESSION['okna']);
$smarty -> assign('rynek', $_SESSION['rynek']);


$smarty -> assign('rok', $_SESSION['rok']);
$smarty -> assign('pom', $_SESSION['pom']);
$smarty -> assign('poc', $_SESSION['poc']);
$smarty -> assign('pietra', $_SESSION['pietra']);
$smarty -> assign('pietro', $_SESSION['pietro']);
$smarty -> assign('pokoje', $_SESSION['pokoje']);
$smarty -> assign('pow', $_SESSION['pow']);

        $smarty -> assign('a', $a);
        $smarty -> assign('b', $b);
        $smarty -> assign('c', $c);


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



                $objectId = $mysql -> insert();
                $smarty -> assign('success', 'Obiekt został poprawnie dodany! Będzie widoczny po weryfikacji przez administrację. Dziękujemy!');
                
                for ( $p = 1; $p <= $cfg['addPhoto']; $p++ )
                {
                        if ( $_FILES['photo_'.$p.'']['tmp_name'] !== '' )
                        {
                                if ( $object -> walidPhoto( $_FILES['photo_'.$p.'']['name'] ) )
                                {
                                        $object -> uploadPhoto ( $_FILES['photo_'.$p.'']['name'], $_FILES['photo_'.$p.'']['tmp_name'], $objectId, $mysql );
                                }
                        }
                }
                
                $smarty -> assign('type', '');
                $smarty -> assign('state', '');
                $smarty -> assign('name', '');
                $smarty -> assign('adress', '');
                $smarty -> assign('city', '');
				
                $smarty -> assign('tel', '');
                $smarty -> assign('email', '');
                $smarty -> assign('www', '');
                $smarty -> assign('priceOn', '');
				$smarty -> assign('a', '');
                $smarty -> assign('b', '');
                $smarty -> assign('c', '');
                $smarty -> assign('region', '');
                $smarty -> assign('droga', '');
                $smarty -> assign('txt', '');
				

$smarty -> assign('budulec', '');
$smarty -> assign('dach', '');;
$smarty -> assign('dojazd', '');
$smarty -> assign('kanalizacja', '');
$smarty -> assign('kat', '');
$smarty -> assign('ogrodzenie', '');
$smarty -> assign('stan', '');
$smarty -> assign('ogrzewanie', '');
$smarty -> assign('okna', '');
$smarty -> assign('rynek', '');

$smarty -> assign('rok', '');
$smarty -> assign('pom', '');
$smarty -> assign('poc', '');
$smarty -> assign('pietra', '');
$smarty -> assign('pietro', '');
$smarty -> assign('pokoje', '');
$smarty -> assign('pow', '');
        }
}

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