<?PHP
include"../inc/var.php";
include "../inc/connect.php";  
include $server_inc."/affiliate_functions.php";

// allow denied affiliate requests to be reinstated
denied_timeout();

$client_report_last_ran=last_ran_client_affiliate_report($below_public);
if ($client_report_last_ran==1)
	{
	$rowuid=mysql_query("select uid from affiliate_user");
	while ($rsuid=mysql_fetch_row($rowuid))
		{
		$uid=$rsuid[0];
		affiliate_monthly_report($uid, $email_admin, $currency, $currency_type);
		# admin_monthly_report($email_admin, $currency, $currency_type);
		}
	admin_monthly_report($email_admin, $currency, $currency_type);
	}
else if (date("F", $client_report_last_ran)!=date("F"))
	{
	$rowuid=mysql_query("select uid from affiliate_user");
	while ($rsuid=mysql_fetch_row($rowuid))
		{
		$uid=$rsuid[0];
		affiliate_monthly_report($uid, $email_admin, $currency, $currency_type);
		# admin_monthly_report($email_admin, $currency, $currency_type);
		}

	admin_monthly_report($email_admin, $currency, $currency_type);

	// update the log
	write_new_last_ran_client_affiliate_report($below_public);
	}

/*

// ------------------------------------------------------------------

*/

// update the history table
update_affiliate_history_table($below_public);

mysql_close($dblink);
?>