<?

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

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

if ( isset( $_POST['changeSeq'] ) )
{
        $paySeq = $_POST['paySeq'];
        $payId = $_POST['payId'];

        foreach ( $paySeq as $i => $edit )
        {
                $sql = "UPDATE `payment` SET `paySeq` = '$edit' WHERE `payId` = '".$payId[$i]."'";
                mysql_query( $sql );
        }
                
        $smarty -> assign('success', 'Poprawnie zapisano zmiany!');
}

if ( $_GET['act'] == 'delete' )
{
        $id = $_GET['id'];
        $sql = "DELETE FROM `payment` WHERE payId = '$id'";
        mysql_query( $sql );
        $smarty -> assign('success', 'Poprawnie usunięto abonament!');
}

if ( isset( $_POST['addPay'] ) )
{
        $type = $_POST['type'];
        $smarty -> assign('type', $type);
        $pay = $_POST['pay'];
        $smarty -> assign('pay', $pay);
        $idSms = $_POST['idSms'];
        $smarty -> assign('idSms', $idSms);
        $day = $_POST['day'];
        $smarty -> assign('day', $day);
        $price = $_POST['price'];
        $smarty -> assign('price', $price);
        $desc = $_POST['desc'];
        $smarty -> assign('desc', $desc);
        $txt = $_POST['txt'];
        $smarty -> assign('txt', $txt);
        
        if ( !empty( $txt ) && !empty( $desc ) && !empty( $price ) && !empty( $day ) )
        {
                if ( $pay == 'sms' )
                {
                        if ( !empty( $idSms ) )
                        {
                                $sql = "INSERT INTO `payment` (`payToo`, `payOption`, `payCodeSms`, `payDay`, `payPrice`, `payTxt`, `payDesc`) VALUES ('$type', '$pay', '$idSms', '$day', '$price', '$txt', '$desc')";
                                mysql_query( $sql );
                                $smarty -> assign('success', 'Poprawnie dodano nowy abonament!');
                                
                                $smarty -> assign('type', '');
                                $smarty -> assign('pay', '');
                                $smarty -> assign('idSms', '');
                                $smarty -> assign('day', '');
                                $smarty -> assign('price', '');
                                $smarty -> assign('desc', '');
                                $smarty -> assign('txt', '');
                        }
                        else
                        {
                                $smarty -> assign('error', 'Wypełnij wszystkie pola!');
                        }
                }
                else
                {
                        $sql = "INSERT INTO `payment` (`payToo`, `payOption`, `payCodeSms`, `payDay`, `payPrice`, `payTxt`, `payDesc`) VALUES ('$type', '$pay', '$idSms', '$day', '$price', '$txt', '$desc')";
                        mysql_query( $sql );
                        $smarty -> assign('success', 'Poprawnie dodano nowy abonament!');
                        
                        $smarty -> assign('type', '');
                        $smarty -> assign('pay', '');
                        $smarty -> assign('idSms', '');
                        $smarty -> assign('day', '');
                        $smarty -> assign('price', '');
                        $smarty -> assign('desc', '');
                        $smarty -> assign('txt', '');
                }
        }
        else
        {
                $smarty -> assign('error', 'Wypełnij wszystkie pola!');
        }
}
if ( $_GET['act'] == 'edit' )
{
        $smarty -> assign('edit' ,'');
        $id = $_GET['id'];
        $smarty -> assign('id', $id);
        
        if ( isset( $_POST['editPay'] ) )
        {
                $type = $_POST['type'];
                $pay = $_POST['pay'];
                $idSms = $_POST['idSms'];
                $day = $_POST['day'];
                $price = $_POST['price'];
                $desc = $_POST['desc'];
                $txt = $_POST['txt'];
                
                if ( !empty( $txt ) && !empty( $desc ) && !empty( $price ) && !empty( $day ) )
                {
                        if ( $pay == 'sms' )
                        {
                                if ( !empty( $idSms ) )
                                {
                                        $sql = "UPDATE `payment` SET `payToo` = '$type', `payOption` = '$pay', `payCodeSms` = '$idSms', `payDay` = '$day', `payPrice` = '$price', `payTxt` = '$txt', `payDesc` = '$desc' WHERE payId = '$id'";
                                        mysql_query( $sql );
                                        $smarty -> assign('success', 'Poprawnie zapisano zmiany!');
                                }
                                else
                                {
                                        $smarty -> assign('error', 'Wypełnij wszystkie pola!');
                                }
                        }
                        else
                        {
                                $sql = "UPDATE `payment` SET `payToo` = '$type', `payOption` = '$pay', `payCodeSms` = '$idSms', `payDay` = '$day', `payPrice` = '$price', `payTxt` = '$txt', `payDesc` = '$desc' WHERE payId = '$id'";
                                mysql_query( $sql );
                                $smarty -> assign('success', 'Poprawnie zapisano zmiany!');
                        }
                }
                else
                {
                        $smarty -> assign('error', 'Wypełnij wszystkie pola!');
                }
        }
        
        $sql = "SELECT * FROM payment WHERE payId = '$id'";
        $q = mysql_query( $sql );
        $ed = array();
        
        while ( $db = mysql_fetch_array( $q ) )
        {
                $ed[] = $db;
        }
        
        $smarty ->assign('ed', $ed);
}

$sql = "SELECT * FROM payment ORDER by payId DESC";
$q = mysql_query( $sql );
$smarty -> assign('num', mysql_num_rows( $q ));
$p = array();

while ( $db = mysql_fetch_array( $q ) )
{
        $p[] = $db;
}

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