<?

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

*************************************************
*			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('inc/config.inc.php');
require_once('class/mail.class.php');

$mail = new sendMail;

$sql = "SELECT obId FROM object WHERE obPromo = '1' AND obPromoDateEnd < NOW()";
$q = $mysql -> q( $sql );
while ( $db = mysql_fetch_array( $q ) )
{
        $promo = "UPDATE `object` SET `obPromoDateEnd` = '0000-00-00 00:00:00', `obPromo` = '0' WHERE obId = ".$db[0]."";
        $mysql -> q( $promo );
}



$sql = "SELECT obId FROM object WHERE obLastMinute = '1' AND obLastMinuteDateEnd < NOW()";
$q = $mysql -> q( $sql );
while ( $db = mysql_fetch_array( $q ) )
{
        $last = "UPDATE `object` SET `obLastMinuteDateEnd` = '0000-00-00 00:00:00', `obLastMinute` = '0' WHERE obId = ".$db[0]."";
        $mysql -> q( $last );
}

$sql = "SELECT obId FROM object WHERE obWyroz = '1' AND obWyrozDateEnd < NOW()";
$q = $mysql -> q( $sql );
while ( $db = mysql_fetch_array( $q ) )
{
        $wyr = "UPDATE `object` SET `obWyrozDateEnd` = '0000-00-00 00:00:00', `obWyroz` = '0' WHERE obId = ".$db[0]."";
        $mysql -> q( $wyr );
}


$datePlus = date("Y-m-d H:i:s", strtotime('+' . $cfg['mailInfo'] . ' days'));
$datePlus = substr( $datePlus, 0, 10 );

$sql = "SELECT obUserId, obEmail, obDateEnd FROM object WHERE obConfirm = '1'";
$q = $mysql -> q( $sql );
while ( $db = mysql_fetch_array( $q ) )
{
        $dateEnd =  substr( $db['obDateEnd'], 0, 10 );
        
        if ( trim( $datePlus ) == trim( $dateEnd ) )
        {
                $war = "SELECT userEmail, userName FROM users WHERE userId = '".$db['obUserId']."'";
                $q2 = $mysql -> q( $war );
                $dbWar = mysql_fetch_array( $q2 );
                $warEmail = $db['obEmail'];
                $warLogin = $dbWar['userName'];
        
                $temat = 'Twoja oferta wygasa ['.$cfg['wwwSubStr'].']';
                $tresc = 'Twoja oferta na '.$cfg['wwwSubStr'].' wygaśnie za '.$cfg['mailInfo'].' dni, jeśli jesteż zainteresowany/a dalszą współpracą prosimy o opłacenie abonamentu.';
        
                $mail -> mailer ( $warEmail, $warLogin, '', $temat, $tresc );
        }
}

?>
