<?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 * FROM profile WHERE ";
	$query .= " locked = 'no' and deleted = 'no' and email_address_valid = 'no'";
	$query .= " and returned_mail = 'no'";

	$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'];
		$email_verification_code = $data['email_verification_code'];

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


			/* if 10 days since we attempted a validation email */

		if ((time() - strtotime( $last_attempt )) > 10*24*60*60 )
		{
			if ($send_it == "true")
			{
				send_verification_email( $member_id, $email_verification_code, $cxn );

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

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

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

