<?

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

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

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

$id = html( $_GET['id'] );
$smarty -> assign('id', $id);

$pay = new pay;

if ( $_GET['too'] == 1 )
{
        $smarty -> assign('pl_1', '');
        
        if ( isset( $_POST['getCode'] ) )
        {
                $payId = $_POST['payId'];
                $payCodeSms = $_POST['payCodeSms'];
                $code = html( $_POST['code'] );
                $day = $pay -> getDay( $payId, $mysql );
                
                $smarty -> assign('payId', $payId);
                
                if ( $pay -> isEmpty ( $code ) )
                {
                        if ( $pay -> checkSmsCode ( $code, $cfg['dotpayId'], $payCodeSms ) )
                        {
                                if ( $pay -> ifEnd ( $id, $mysql ) == 0 ) // wygaslo
                                {
                                        $dateEnd = date("Y-m-d H:i:s", strtotime('+' . $day . ' days'));
                                }
                                else
                                {
                                        $sql = "SELECT obDateEnd FROM object WHERE obId = '$id'";
                                        $q = $mysql -> q( $sql );
                                        $db = mysql_fetch_array( $q );
                                        $date = $db[0];
                                        $newDate = strtotime( $date ) + ( $day * 86400 );
                                        $dateEnd = date("Y-m-d H:i:s", $newDate);
                                }
                                
                                $pay -> datePlus ( $dateEnd, $id, $mysql );
                                
                                $smarty -> assign('success', 'Emisja obiektu została przedłużona o '.$day.' dni!');
                        }
                        else
                        {
                                $error = 'Podany kod sms premium jest niepoprawny!';
                        }
                }
                else
                {
                        $error = 'Nie podano kodu sms premium!';
                }
        }
        
        $sql = "SELECT * FROM payment WHERE payToo = '1' ORDER by paySeq ASC";
        $q = $mysql -> q( $sql );
        $smarty -> assign('num_1', $mysql -> num( $sql ));
        $pay_1 = array();
        while ( $db = mysql_fetch_array( $q ) )
        {
                $pay_1[] = $db;
        }
        $smarty -> assign('pay_1', $pay_1);
        
        $smarty -> assign('error', $error);
        
        $smarty -> display('panel-platnosci-abonament.tpl');
}
if ( $_GET['too'] == 2 )
{
        $smarty -> assign('pl_2', '');
        
        if ( isset( $_POST['getCode'] ) )
        {
                $payId = $_POST['payId'];
                $payCodeSms = $_POST['payCodeSms'];
                $code = html( $_POST['code'] );
                $day = $pay -> getDay( $payId, $mysql );
                
                $smarty -> assign('payId', $payId);
                
                if ( $pay -> isEmpty ( $code ) )
                {
                        if ( $pay -> checkSmsCode ( $code, $cfg['dotpayId'], $payCodeSms ) )
                        {
                                if ( $pay -> ifPromoEnd ( $id, $mysql ) == 0 ) // wygaslo
                                {
                                        $dateEnd = date("Y-m-d H:i:s", strtotime('+' . $day . ' days'));
                                }
                                else
                                {
                                        $sql = "SELECT obPromoDateEnd FROM object WHERE obId = '$id'";
                                        $q = $mysql -> q( $sql );
                                        $db = mysql_fetch_array( $q );
                                        $date = $db[0];
                                        $newDate = strtotime( $date ) + ( $day * 86400 );
                                        $dateEnd = date("Y-m-d H:i:s", $newDate);
                                }
                                
                                $pay -> datePromoPlus ( $dateEnd, $id, $mysql );
                                
                                $smarty -> assign('success', 'Promocja obiektu została przedłużona o '.$day.' dni!');
                        }
                        else
                        {
                                $error = 'Podany kod sms premium jest niepoprawny!';
                        }
                }
                else
                {
                        $error = 'Nie podano kodu sms premium!';
                }
        }
        
        $sql = "SELECT * FROM payment WHERE payToo = '2' ORDER by paySeq ASC";
        $q = $mysql -> q( $sql );
        $smarty -> assign('num_2', $mysql -> num( $sql ));
        $pay_2 = array();
        while ( $db = mysql_fetch_array( $q ) )
        {
                $pay_2[] = $db;
        }
        $smarty -> assign('pay_2', $pay_2);
        
        $sql = "SELECT obPromo, obPromoDateEnd FROM object WHERE obId = '$id'";
        $q = $mysql -> q( $sql );
        $db = mysql_fetch_array( $q );
        $smarty -> assign('obPromo', $db['obPromo']);
        $smarty -> assign('obPromoDateEnd', $db['obPromoDateEnd']);
        
        $smarty -> assign('error', $error);
        
        $smarty -> display('panel-platnosci-promo.tpl');
}
if ( $_GET['too'] == 3 )
{
        $smarty -> assign('pl_3', '');
        
        if ( isset( $_POST['getCode'] ) )
        {
                $payId = $_POST['payId'];
                $payCodeSms = $_POST['payCodeSms'];
                $code = html( $_POST['code'] );
                $day = $pay -> getDay( $payId, $mysql );
                
                $smarty -> assign('payId', $payId);
                
                if ( $pay -> isEmpty ( $code ) )
                {
                        if ( $pay -> checkSmsCode ( $code, $cfg['dotpayId'], $payCodeSms ) )
                        {
                                if ( $pay -> ifLastEnd ( $id, $mysql ) == 0 ) // wygaslo
                                {
                                        $dateEnd = date("Y-m-d H:i:s", strtotime('+' . $day . ' days'));
                                }
                                else
                                {
                                        $sql = "SELECT obLastMinuteDateEnd FROM object WHERE obId = '$id'";
                                        $q = $mysql -> q( $sql );
                                        $db = mysql_fetch_array( $q );
                                        $date = $db[0];
                                        $newDate = strtotime( $date ) + ( $day * 86400 );
                                        $dateEnd = date("Y-m-d H:i:s", $newDate);
                                }
                                
                                $pay -> dateLastPlus ( $dateEnd, $id, $mysql );
                                
                                $smarty -> assign('success', 'Oferta Last Minute obiektu została przedłużona o '.$day.' dni!');
                        }
                        else
                        {
                                $error = 'Podany kod sms premium jest niepoprawny!';
                        }
                }
                else
                {
                        $error = 'Nie podano kodu sms premium!';
                }
        }
        
        $sql = "SELECT * FROM payment WHERE payToo = '3' ORDER by paySeq ASC";
        $q = $mysql -> q( $sql );
        $smarty -> assign('num_3', $mysql -> num( $sql ));
        $pay_3 = array();
        while ( $db = mysql_fetch_array( $q ) )
        {
                $pay_3[] = $db;
        }
        $smarty -> assign('pay_3', $pay_3);
        
        $sql = "SELECT obLastMinute, obLastMinuteDateEnd FROM object WHERE obId = '$id'";
        $q = $mysql -> q( $sql );
        $db = mysql_fetch_array( $q );
        $smarty -> assign('obLastMinute', $db['obLastMinute']);
        $smarty -> assign('obLastMinuteDateEnd', $db['obLastMinuteDateEnd']);
        
        $smarty -> assign('error', $error);
        
        $smarty -> display('panel-platnosci-last.tpl');
}
if ( $_GET['too'] == 4 )
{
        $smarty -> assign('pl_4', '');
        
        if ( isset( $_POST['getCode'] ) )
        {
                $payId = $_POST['payId'];
                $payCodeSms = $_POST['payCodeSms'];
                $code = html( $_POST['code'] );
                $day = $pay -> getDay( $payId, $mysql );
                
                $smarty -> assign('payId', $payId);
                
                if ( $pay -> isEmpty ( $code ) )
                {
                        if ( $pay -> checkSmsCode ( $code, $cfg['dotpayId'], $payCodeSms ) )
                        {
                                if ( $pay -> ifWyrozEnd ( $id, $mysql ) == 0 ) // wygaslo
                                {
                                        $dateEnd = date("Y-m-d H:i:s", strtotime('+' . $day . ' days'));
                                }
                                else
                                {
                                        $sql = "SELECT obWyrozDateEnd FROM object WHERE obId = '$id'";
                                        $q = $mysql -> q( $sql );
                                        $db = mysql_fetch_array( $q );
                                        $date = $db[0];
                                        $newDate = strtotime( $date ) + ( $day * 86400 );
                                        $dateEnd = date("Y-m-d H:i:s", $newDate);
                                }
                                
                                $pay -> dateWyrozPlus ( $dateEnd, $id, $mysql );
                                
                                $smarty -> assign('success', 'Promocja obiektu została przedłużona o '.$day.' dni!');
                        }
                        else
                        {
                                $error = 'Podany kod sms premium jest niepoprawny!';
                        }
                }
                else
                {
                        $error = 'Nie podano kodu sms premium!';
                }
        }
        
        $sql = "SELECT * FROM payment WHERE payToo = '4' ORDER by paySeq ASC";
        $q = $mysql -> q( $sql );
        $smarty -> assign('num_4', $mysql -> num( $sql ));
        $pay_4 = array();
        while ( $db = mysql_fetch_array( $q ) )
        {
                $pay_4[] = $db;
        }
        $smarty -> assign('pay_4', $pay_4);
        
        $sql = "SELECT obWyroz, obWyrozDateEnd FROM object WHERE obId = '$id'";
        $q = $mysql -> q( $sql );
        $db = mysql_fetch_array( $q );
        $smarty -> assign('obWyroz', $db['obWyroz']);
        $smarty -> assign('obWyrozDateEnd', $db['obWyrozDateEnd']);
        
        $smarty -> assign('error', $error);
        
        $smarty -> display('panel-platnosci-wyroz.tpl');
}
?>
