<?php

//	include_once "library.php";

	$send_it = val( $_GET, 'sendit' );

	if ($send_it <> "true")
		echo black( "TEST MODE<br><br>" );

//	$cxn = start_code( true );

	$query = "SELECT profile.* FROM profile LEFT JOIN static_data ON profile.country = static_data.value WHERE ";
	$query .= " locked = 'no' and deleted = 'no' and email_address_valid = 'yes'";
	$query .= " and membership_type = 'subscription' and subscription_valid = 'no'";
	$query .= " and paypal = 'yes'";

	$sent = date("Y-m-d H:i:s");

	$result = run_query( $query, $cxn );

	for ($i=0; $i < mysql_num_rows($result); $i++)
	{
		$data = get_row( $result );

		$member_id = $data['id'];

		if (query_has_rows( "SELECT id FROM sys_message WHERE sent_to_id = ".$member_id." AND type = 'subscription_setup_reminder'", $cxn ))
		{
			$data2 = get_first_row( "SELECT * FROM sys_message WHERE sent_to_id = ".$member_id." AND type = 'subscription_setup_reminder' ORDER BY sent DESC", $cxn );
			$last_attempt = $data2['sent'];
			$days = 10;
		}
		else
		{
			$last_attempt = $data['date_created'];
			$days = 1;
		}


			/* if 10 days since we reminded them */

		if ((time() - strtotime( $last_attempt )) > $days * 24*60*60 )
		{
			if ($send_it == "true")
			{
				$domain = val( $_SERVER, "HTTP_HOST" );

				$subject = "Please finish setting up your ".$_SESSION['sitename']." membership";

				$text_body = "Dear ".name_case( $data['first_name'] )."\n\n";
				$text_body .= "Thanks for joining ".$_SESSION['sitename'].".\n\n";
				$text_body .= "You have chosen a subscription membership.\n\n";
				$text_body .= "To finish setting up your membership please complete the following steps.\n\n";
				$text_body .= "(1) Go to the home page\n\n";
				$text_body .= "(2) Click on 'Monthly Membership'\n\n";
				$text_body .= "(3) Enter your login details and click 'Login'\n\n";
				$text_body .= "(4) Click 'Subscribe'\n\n";
				$text_body .= "(5) Enter your credit card or bank account details into the PayPal site\n\n\n";
				$text_body .= "Regards\n\n";
				$text_body .= $_SESSION['sitename']."\n\n";
				$text_body .= "www.academicdating.net";

				$html_body = "Dear ".name_case( $data['first_name'] )."<br><br>";
				$html_body .= "Thanks for joining ".$_SESSION['sitename'].".<br><br>";
				$html_body .= "You have chosen a subscription membership.<br><br>";
				$html_body .= "To finish setting up your membership please complete the following steps.<br><br>";
				$html_body .= "(1) Go to the home page<br><br>";
				$html_body .= "(2) Click on 'Monthly Membership'<br><br>";
				$html_body .= "(3) Enter your login details and click 'Login'<br><br>";
				$html_body .= "(4) Click 'Subscribe'<br><br>";
				$html_body .= "(5) Enter your credit card or bank account details into the PayPal site<br><br><br>";
				$html_body .= "Regards<br><br>";
				$html_body .= $_SESSION['sitename']."<br><br>";
				$html_body .= show_link( "www.academicdating.net", "http://".$domain );

				send_external( $member_id, $subject, $text_body, $html_body, $cxn );

				run_query( "INSERT INTO sys_message (sent_to_id, type, sent) VALUES (".$member_id.", 'subscription_setup_reminder', '".$sent."')", $cxn );
			}

			echo black( "Subscription setup reminder set to member ".$data['handle']."<br>" );
		}
	}

	echo black( "<br>Finished<br><br>" );
?>

