<?

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

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

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

class pay
{
        function isEmpty ( $string )
        {
                if ( empty( $string ) )
                {
                        return false;
                }
                else
                {
                        return true;
                }
        }
        function ifEnd ( $objectId, $mysql ) // sprawdza czy ogloszenie wygaslo czy nie
        {
                $sql = "SELECT obDateEnd FROM object WHERE obId = '$objectId'";
                $q = $mysql -> q( $sql );
                $db = mysql_fetch_array( $q );
                $now = time();
                $end = strtotime( $db[0] );
                
                if ( $end < $now )
                {
                        return 0; // ogloszenie wygaslo
                }
                else
                {
                        return 1;
                }
        }
        function datePlus ( $dateEnd, $objectId, $mysql ) // uaktualnia date, 1 opcja
        {
                $sql = "UPDATE `object` SET `obDateEnd` = '$dateEnd' WHERE obId = '$objectId'";
                $mysql -> q( $sql );
        }
        function checkSmsCode ( $codeSms, $dotpayId, $payCodeSms )
        {
                $id = $dotpayId;
                $code = $payCodeSms;
                $check = $codeSms;
                $type = "c1,sms";
                $del = 1;
                $handle = fopen("http://dotpay.pl/check_code.php?id=".$id."&code=".$code."&check=".$check."&type=".$type."&del=".$del, 'r');
                $status = fgets($handle, 8);
                $czas_zycia = fgets($handle, 24);
                fclose($handle);
                
                if ( $status == 0 )
                {
                        return false;
                }
                else
                {
                        return true;
                }
        }
        function getDay ( $payId, $mysql )
        {
                $sql = "SELECT payDay FROM payment WHERE payId = '$payId'";
                $q = $mysql -> q( $sql );
                $db = mysql_fetch_array( $q );
                return $db[0];
        }
        function ifPromoEnd ( $objectId, $mysql )
        {
                $sql = "SELECT obPromoDateEnd FROM object WHERE obId = '$objectId'";
                $q = $mysql -> q( $sql );
                $db = mysql_fetch_array( $q );
                $date = $db[0];
                
                if ( $date == '0000-00-00 00:00:00' )
                {
                        return 0;
                }
                else
                {
                       $end = strtotime( date );
                
                        if ( $end < $now )
                        {
                                return 0; // ogloszenie wygaslo
                        }
                        else
                        {
                                return 1;
                        }
                }
        }
				
        function ifWyrozEnd ( $objectId, $mysql )
        {
                $sql = "SELECT obWyrozDateEnd FROM object WHERE obId = '$objectId'";
                $q = $mysql -> q( $sql );
                $db = mysql_fetch_array( $q );
                $date = $db[0];
                
                if ( $date == '0000-00-00 00:00:00' )
                {
                        return 0;
                }
                else
                {
                       $end = strtotime( date );
                
                        if ( $end < $now )
                        {
                                return 0; // ogloszenie wygaslo
                        }
                        else
                        {
                                return 1;
                        }
                }
        }
				
        function datePromoPlus ( $dateEnd, $objectId, $mysql ) // uaktualnia date, 2 opcja
        {
                $sql = "UPDATE `object` SET `obPromo` = '1', `obPromoDateEnd` = '$dateEnd' WHERE obId = '$objectId'";
                $mysql -> q( $sql );
        }
        function dateWyrozPlus ( $dateEnd, $objectId, $mysql ) // uaktualnia date, 2 opcja
        {
                $sql = "UPDATE `object` SET `obWyroz` = '1', `obWyrozDateEnd` = '$dateEnd' WHERE obId = '$objectId'";
                $mysql -> q( $sql );
        }
				
        function ifLastEnd ( $objectId, $mysql )
        {
                $sql = "SELECT obLastMinuteDateEnd FROM object WHERE obId = '$objectId'";
                $q = $mysql -> q( $sql );
                $db = mysql_fetch_array( $q );
                $date = $db[0];
                
                if ( $date == '0000-00-00 00:00:00' )
                {
                        return 0;
                }
                else
                {
                       $end = strtotime( date );
                
                        if ( $end < $now )
                        {
                                return 0; // ogloszenie wygaslo
                        }
                        else
                        {
                                return 1;
                        }
                }
        }
        function dateLastPlus ( $dateEnd, $objectId, $mysql ) // uaktualnia date, 2 opcja
        {
                $sql = "UPDATE `object` SET `obLastMinute` = '1', `obLastMinuteDateEnd` = '$dateEnd' WHERE obId = '$objectId'";
                $mysql -> q( $sql );
        }
        
}
