<?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();

	$query = "SELECT * FROM profile WHERE visibility <> 'Hidden'";
	$query .= " and locked = 'no' and deleted = 'no' and email_address_valid = 'yes'";
	$query .= " and id not in (SELECT DISTINCT member_id FROM photos)";
	$query .= " and id not in (SELECT sent_to_id FROM sys_message WHERE type = 'post_photo_email')";
	$query .= " and id not in (SELECT sent_to_id FROM sys_message WHERE type = 'post_photo_email_not_needed')";

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


			/* only process members who have been a member for more than 3 days */

		if ((time() - strtotime( $data['date_created'] )) > 7*24*60*60 )
		{
			$domain = val( $_SERVER, "HTTP_HOST" );

			$subject = "Hi from ".$_SESSION['sitename'];

			$text_body = "Dear ".name_case( $data['first_name'] )."\n\n";
			$text_body .= "We noticed that you joined our website a few days ago. Thanks for joining.\n\n";
			$text_body .= "We were wondering if you had considered posting a photo on your profile. Members usually have much more success on the site if they have a photo posted on their profile.\n\n";
			$text_body .= "If you would like to post a photo you will need a file in JPG format.\n\n";
			$text_body .= "Just go to the home page and click on 'Manage Photos' to upload your photo.\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 .= "We noticed that you joined our website a few days ago. Thanks for joining.<br><br>";
			$html_body .= "We were wondering if you had considered posting a photo on your profile. Members usually have much more success on the site if they have a photo posted on their profile.<br><br>";
			$html_body .= "If you would like to post a photo you will need a file in JPG format.<br><br>";
			$html_body .= "Just go to the home page and click on 'Manage Photos' to upload your photo.<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 = "UPDATE profile SET photo_email_sent = 'yes' WHERE id = ".$data['id'];
//				$result2 = run_query( $query2, $cxn );

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

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

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

