<?

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

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

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


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

if ( $_GET['act'] == 'mail' )
{
        if ( isset( $_POST['update_2'] ) )
        {
                $config = $_POST['config'];
                $configId = $_POST['id'];

                foreach ( $config as $i => $edit )
                {
                        $sql = "UPDATE `config` SET `cfgTxt` = '$edit' WHERE `cfgId` = '".$configId[$i]."'";
                        mysql_query( $sql );
                }
                
                $smarty -> assign('success', 'Poprawnie zapisano zmiany!');
        }
        $sql = "SELECT * FROM config";
        $q = mysql_query( $sql );
        
        while ( $db = mysql_fetch_array( $q ) )
        {
                $smarty -> assign($db['cfgName'], $db['cfgTxt']);
                $smarty -> assign('id_'.$db['cfgName'], $db['cfgId']);
        }
        
        $smarty -> display('adm-config-mail.tpl');
}
else if ( $_GET['act'] == 'kategoria' )
{
        if ( isset( $_POST['addKat'] ) )
        {
                $katName = $_POST['newKat'];
                if ( !empty( $katName ) )
                {
                        $sql = "INSERT INTO `kategoria` (`katName`) VALUES ('$katName')";
                        mysql_query( $sql );
                        $smarty -> assign('success', 'Poprawnie dodano nowy Typ transakcji!');
                }
                else
                {
                        $smarty -> assign('error', 'Nie podano nazwy!');
                }
        }
        if ( isset( $_POST['update_4'] ) )
        {
                $katName = $_POST['katName'];
                $katId = $_POST['katId'];

                foreach ( $katName as $i => $edit )
                {
                        $sql = "UPDATE `kategoria` SET `katName` = '$edit' WHERE `katId` = '".$katId[$i]."'";
                        mysql_query( $sql );
                }
                
                $smarty -> assign('success', 'Poprawnie zapisano zmiany!');
        }
        
        if ( isset( $_GET['delete'] ) )
        {
                $id = $_GET['delete'];
                $sql = "DELETE FROM `kategoria` WHERE `katId` = '$id'";
                mysql_query( $sql );
                $smarty -> assign('success', 'Typ transakcji  został poprawnie usunięty!');
        }
        
        $sql = "SELECT * FROM kategoria ORDER by katName ASC";
        $q = mysql_query( $sql );
        $kat = array();
        
        while ( $db = mysql_fetch_array( $q ) )
        {
                $kat[] = $db;
        }
        
        $smarty -> assign('kat', $kat);
        
        $smarty -> display('adm-config-transakcja.tpl');
}

//////////
else if ( $_GET['act'] == 'stan' )
{
        if ( isset( $_POST['addStan'] ) )
        {
                $stanName = $_POST['newStan'];
                if ( !empty( $stanName ) )
                {
                        $sql = "INSERT INTO `stan` (`stanName`) VALUES ('$stanName')";
                        mysql_query( $sql );
                        $smarty -> assign('success', 'Poprawnie dodano nowy stan obiektu!');
                }
                else
                {
                        $smarty -> assign('error', 'Nie podano nazwy!');
                }
        }
        if ( isset( $_POST['update_7'] ) )
        {
                $stanName = $_POST['stanName'];
                $stanId = $_POST['stanId'];

                foreach ( $stanName as $i => $edit )
                {
                        $sql = "UPDATE `stan` SET `stanName` = '$edit' WHERE `stanId` = '".$stanId[$i]."'";
                        mysql_query( $sql );
                }
                
                $smarty -> assign('success', 'Poprawnie zapisano zmiany!');
        }
        
        if ( isset( $_GET['delete'] ) )
        {
                $id = $_GET['delete'];
                $sql = "DELETE FROM `stan` WHERE `stanId` = '$id'";
                mysql_query( $sql );
                $smarty -> assign('success', 'Stan obiektu został poprawnie usunięty!');
        }
        
        $sql = "SELECT * FROM stan ORDER by stanName ASC";
        $q = mysql_query( $sql );
        $stan = array();
        
        while ( $db = mysql_fetch_array( $q ) )
        {
                $stan[] = $db;
        }
        
        $smarty -> assign('stan', $stan);
        
        $smarty -> display('adm-config-stan.tpl');
}
/////////
//////////
else if ( $_GET['act'] == 'dach' )
{
        if ( isset( $_POST['addDach'] ) )
        {
                $dachName = $_POST['newDach'];
                if ( !empty( $dachName ) )
                {
                        $sql = "INSERT INTO `dach` (`dachName`) VALUES ('$dachName')";
                        mysql_query( $sql );
                        $smarty -> assign('success', 'Poprawnie dodano nowy dach obiektu!');
                }
                else
                {
                        $smarty -> assign('error', 'Nie podano nazwy!');
                }
        }
        if ( isset( $_POST['update_8'] ) )
        {
                $dachName = $_POST['dachName'];
                $dachId = $_POST['dachId'];

                foreach ( $dachName as $i => $edit )
                {
                        $sql = "UPDATE `dach` SET `dachName` = '$edit' WHERE `dachId` = '".$dachId[$i]."'";
                        mysql_query( $sql );
                }
                
                $smarty -> assign('success', 'Poprawnie zapisano zmiany!');
        }
        
        if ( isset( $_GET['delete'] ) )
        {
                $id = $_GET['delete'];
                $sql = "DELETE FROM `dach` WHERE `dachId` = '$id'";
                mysql_query( $sql );
                $smarty -> assign('success', 'Dach obiektu został poprawnie usunięty!');
        }
        
        $sql = "SELECT * FROM dach ORDER by dachName ASC";
        $q = mysql_query( $sql );
        $dach = array();
        
        while ( $db = mysql_fetch_array( $q ) )
        {
                $dach[] = $db;
        }
        
        $smarty -> assign('dach', $dach);
        
        $smarty -> display('adm-config-dach.tpl');
}
/////////
//////////
else if ( $_GET['act'] == 'budulec' )
{
        if ( isset( $_POST['addBudulec'] ) )
        {
                $budulecName = $_POST['newBudulec'];
                if ( !empty( $budulecName ) )
                {
                        $sql = "INSERT INTO `budulec` (`budulecName`) VALUES ('$budulecName')";
                        mysql_query( $sql );
                        $smarty -> assign('success', 'Poprawnie dodano nowy budulec obiektu!');
                }
                else
                {
                        $smarty -> assign('error', 'Nie podano nazwy!');
                }
        }
        if ( isset( $_POST['update_9'] ) )
        {
                $budulecName = $_POST['budulecName'];
                $budulecId = $_POST['budulecId'];

                foreach ( $budulecName as $i => $edit )
                {
                        $sql = "UPDATE `budulec` SET `budulecName` = '$edit' WHERE `budulecId` = '".$budulecId[$i]."'";
                        mysql_query( $sql );
                }
                
                $smarty -> assign('success', 'Poprawnie zapisano zmiany!');
        }
        
        if ( isset( $_GET['delete'] ) )
        {
                $id = $_GET['delete'];
                $sql = "DELETE FROM `budulec` WHERE `budulecId` = '$id'";
                mysql_query( $sql );
                $smarty -> assign('success', 'Budulec obiektu został poprawnie usunięty!');
        }
        
        $sql = "SELECT * FROM budulec ORDER by budulecName ASC";
        $q = mysql_query( $sql );
        $budulec = array();
        
        while ( $db = mysql_fetch_array( $q ) )
        {
                $budulec[] = $db;
        }
        
        $smarty -> assign('budulec', $budulec);
        
        $smarty -> display('adm-config-budulec.tpl');
}
/////////
else if ( $_GET['act'] == 'rodzaj' )
{
        if ( isset( $_POST['addRodzaj'] ) )
        {
                $rodzajName = $_POST['newRodzaj'];
                if ( !empty( $rodzajName ) )
                {
                        $sql = "INSERT INTO `rodzaj` (`rodzajName`) VALUES ('$rodzajName')";
                        mysql_query( $sql );
                        $smarty -> assign('success', 'Poprawnie dodano nowy rodzaj obiektu!');
                }
                else
                {
                        $smarty -> assign('error', 'Nie podano nazwy!');
                }
        }
        if ( isset( $_POST['update_5'] ) )
        {
                $rodzajName = $_POST['rodzajName'];
                $rodzajId = $_POST['rodzajId'];

                foreach ( $rodzajName as $i => $edit )
                {
                        $sql = "UPDATE `rodzaj` SET `rodzajName` = '$edit' WHERE `rodzajId` = '".$rodzajId[$i]."'";
                        mysql_query( $sql );
                }
                
                $smarty -> assign('success', 'Poprawnie zapisano zmiany!');
        }
        
        if ( isset( $_GET['delete'] ) )
        {
                $id = $_GET['delete'];
                $sql = "DELETE FROM `rodzaj` WHERE `rodzajId` = '$id'";
                mysql_query( $sql );
                $smarty -> assign('success', 'Rodzaj obiektu został poprawnie usunięta!');
        }
        
        $sql = "SELECT * FROM rodzaj ORDER by rodzajName ASC";
        $q = mysql_query( $sql );
        $rodzaj = array();
        
        while ( $db = mysql_fetch_array( $q ) )
        {
                $rodzaj[] = $db;
        }
        
        $smarty -> assign('rodzaj', $rodzaj);
        
        $smarty -> display('adm-config-rodzaj.tpl');
}
else if ( $_GET['act'] == 'type' )
{
        if ( isset( $_POST['addType'] ) )
        {
                $typeName = $_POST['newType'];
                if ( !empty( $typeName ) )
                {
                        $sql = "INSERT INTO `type` (`typeName`) VALUES ('$typeName')";
                        mysql_query( $sql );
                        $smarty -> assign('success', 'Poprawnie dodano nowy typ obiektu!');
                }
                else
                {
                        $smarty -> assign('error', 'Nie podano nazwy!');
                }
        }
        if ( isset( $_POST['update_3'] ) )
        {
                $typeName = $_POST['typeName'];
                $typeId = $_POST['typeId'];

                foreach ( $typeName as $i => $edit )
                {
                        $sql = "UPDATE `type` SET `typeName` = '$edit' WHERE `typeId` = '".$typeId[$i]."'";
                        mysql_query( $sql );
                }
                
                $smarty -> assign('success', 'Poprawnie zapisano zmiany!');
        }
        
        if ( isset( $_GET['delete'] ) )
        {
                $id = $_GET['delete'];
                $sql = "DELETE FROM `type` WHERE `typeId` = '$id'";
                mysql_query( $sql );
                $smarty -> assign('success', 'Typ obiektu został poprawnie usunięty!');
        }
        
        $sql = "SELECT * FROM type ORDER by typeName ASC";
        $q = mysql_query( $sql );
        $type = array();
        
        while ( $db = mysql_fetch_array( $q ) )
        {
                $type[] = $db;
        }
        
        $smarty -> assign('type', $type);
        
        $smarty -> display('adm-config-type.tpl');
}
else if ( $_GET['act'] == 'state' )
{
        if ( isset( $_POST['addState'] ) )
        {
                $stateName = $_POST['newState'];
                if ( !empty( $stateName ) )
                {
                        $sql = "INSERT INTO `state` (`stateName`) VALUES ('$stateName')";
                        mysql_query( $sql );
                        $smarty -> assign('success', 'Poprawnie dodano nowy region!');
                }
                else
                {
                        $smarty -> assign('error', 'Nie podano nazwy!');
                }
        }
        
        if ( isset( $_POST['update_4'] ) )
        {
                $stateName = $_POST['stateName'];
                $stateId = $_POST['stateId'];

                foreach ( $stateName as $i => $edit )
                {
                        $sql = "UPDATE `state` SET `stateName` = '$edit' WHERE `stateId` = '".$stateId[$i]."'";
                        mysql_query( $sql );
                }
                
                $smarty -> assign('success', 'Poprawnie zapisano zmiany!');
        }
        
        if ( isset( $_GET['delete'] ) )
        {
                $id = $_GET['delete'];
                $sql = "DELETE FROM `state` WHERE `stateId` = '$id'";
                mysql_query( $sql );
                $smarty -> assign('success', 'Region został poprawnie usunięty!');
        }
        
        $sql = "SELECT * FROM state ORDER by stateName ASC";
        $q = mysql_query( $sql );
        $state = array();
        
        while ( $db = mysql_fetch_array( $q ) )
        {
                $state[] = $db;
        }
        
        $smarty -> assign('state', $state);
        
        $smarty -> display('adm-config-state.tpl');
}
else
{
        if ( isset( $_POST['update_1'] ) )
        {
                $config = $_POST['config'];
                $configId = $_POST['id'];

                foreach ( $config as $i => $edit )
                {
                        $sql = "UPDATE `config` SET `cfgTxt` = '$edit' WHERE `cfgId` = '".$configId[$i]."'";
                        mysql_query( $sql );
                }
                
                $smarty -> assign('success', 'Poprawnie zapisano zmiany!');
        }
        
        $sql = "SELECT * FROM config";
        $q = mysql_query( $sql );
        
        while ( $db = mysql_fetch_array( $q ) )
        {
                $smarty -> assign($db['cfgName'], $db['cfgTxt']);
                $smarty -> assign('id_'.$db['cfgName'], $db['cfgId']);
        }

        $smarty -> display('adm-config.tpl');
}
?>
