<?php

//	include_once "library.php";

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

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

//	$cxn = start_code( true );


		/* kill the redirection of the email to the debugging address */
		/* if logged in as me */

	session_destroy();

	
		/* remind them every 10 days as long as they've logged in */

	$last_sent = date("Y-m-d H:i:s", time() - 10*24*60*60);

	$query = "SELECT * FROM profile WHERE ";
	$query .= " locked = 'no' and deleted = 'no' and email_address_valid = 'yes'";
	$query .= " and last_login > '".$last_sent."'";
	$query .= " and id not in (SELECT sent_to_id FROM sys_message WHERE type = 'date_of_birth_incorrect' AND sent > '".$last_sent."')";

	$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 );

		if (strtotime( $data['date_of_birth'] ) < strtotime( "1917-01-01" ) )
		{
			$domain = val( $_SERVER, "HTTP_HOST" );

			$subject = $_SESSION['sitename']." - Date of Birth problem";

			$text_body = "Dear ".name_case( $data['first_name'] )."\n\n";
			$text_body .= "During a check of our database we noticed that your date-of-birth is listed as ";
			$text_body .= $data['date_of_birth']."\n\n";
			$text_body .= "Since we guessed that you're probably not ";
			$text_body .= check_date( $data['date_of_birth'], $cxn );
			$text_body .= " years old, we thought that you might want to correct the problem in your profile.\n\n";
			$text_body .= "At present other members will probably not see your profile due to the incorrect age.\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 .= "During a check of our database we noticed that your date-of-birth is listed as ";
			$html_body .= $data['date_of_birth']."<br><br>";
			$html_body .= "Since we guessed that you're probably not ";
			$html_body .= check_date( $data['date_of_birth'], $cxn );
			$html_body .= " years old, we thought that you might want to correct the problem in your profile.<br><br>";
			$html_body .= "At present other members will probably not see your profile due to the incorrect age.<br><br><br>";
			$html_body .= "Regards<br><br>";
			$html_body .= $_SESSION['sitename']."<br><br>";
			$html_body .= show_link( "www.academicdating.net", "http://".$domain );

			if ($send_it == "true")
			{
				send_external( $data['id'], $subject, $text_body, $html_body, $cxn );

				$query2 = "INSERT INTO sys_message (sent_to_id, type, sent) VALUES (".$data['id'].", 'date_of_birth_incorrect', '".$sent."')";
				$result2 = run_query( $query2, $cxn );
			}

			echo black( "Age email sent to member ".$data['handle']."  Date-of-birth ".$data['date_of_birth']."  Age ".check_date( $data['date_of_birth'], $cxn )."<br>" );
		}
	}

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

