<?

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

*************************************************
*			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:				artglobal@wp.pl			*
*************************************************

Copyright (c) 2010 ArtGlobal. Wszelkie prawa zastrzeżone.

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



require_once('inc/config.inc.php');
require_once('class/pay.class.php');

if ( isset( $_POST['id'] ) && $_POST['id'] == $cfg['dotpayId'] )
{
        $pay = new pay;
        
        $pin = ''; //podane rowniez w dotpay
        
        $md5 = md5($pin.':'.$_POST['id'].':'.$_POST['control'].':'.$_POST['t_id'].':'.$_POST['amount'].':'.$_POST['email'].':'.$_POST['service'].':'.$_POST['code'].':'.$_POST['username'].':'.$_POST['password'].':'.$_POST['t_status']);

        if ( $md5 == $_POST['md5'] )
        {
                echo 'OK';
                
                $payStatus = $_POST['t_status'];
                $control = $_POST['control'];
                
                $ex = explode('-', $control);
                $id = $ex[0];
                $day = $ex[1];
                $option = $ex[2];

                if ( $payStatus == 2 )
                {
                        if ( $option == 1 )
                        {
                                if ( $pay -> ifEnd ( $id, $mysql ) == 0 )
                                {
                                        $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 );
                        }
                        if ( $option == 2 )
                        {
                                if ( $pay -> ifPromoEnd ( $id, $mysql ) == 0 )
                                {
                                        $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 );
                        }
                        if ( $option == 3 )
                        {
                                if ( $pay -> ifLastEnd ( $id, $mysql ) == 0 )
                                {
                                        $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 );
                        }
                       if ( $option == 4 )
                        {
                                if ( $pay -> ifWyrozEnd ( $id, $mysql ) == 0 )
                                {
                                        $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 );
                        }
                }

        }
}
else
{
        echo 'OK';
}


?>
