<?php

	include "library.php";

	$cxn = start_code();

	$cxn_common = db_common_login();


			/* get variables */

	$verifyid = val( $_GET, "verifyid" );

	$code = val( $_GET, "code" );


		/* kill anything hanging around in the URL etc as this is an external entry point */

	session_destroy();

	session_start();

	$_SESSION['session_active'] = "yes";

	$_SESSION['sitename'] = "Chat City";

	page_header( "", $cxn, $cxn_common, "", true );


		/* check parameters */

	crash_if_missing( $verifyid, "verify id missing in verify email address", $cxn );

//	crash_if_missing( $code, "verification code missing in verify email address", $cxn );


		/* look for member */

//	$query = "SELECT id FROM profile WHERE id = ".$verifyid." AND email_verification_code = '".$code."'";

	$query = "SELECT id, email, email_verification_code FROM profile WHERE id = ".$verifyid;

	if (! query_has_rows( $query, $cxn ) )
		echo red( "ERROR: Invalid parameters" );
	else
	{
		$result = run_query( $query, $cxn );

		$data = get_row( $result );

//		$ok = "false";

            // verify all profiles with this email address
            
		$query = "UPDATE profile SET email_address_valid = 'yes', returned_mail = 'no' WHERE email = '".$data['email']."'";

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

		echo black( "<br>Email address verified<br><br>Your account has been activated<br><br><br>" );


//		if ($data['email_verification_code'] == "")		// problem occasionally the email verification in the profile record is blank
//			$ok = "true";
//
//		if ($data['email_verification_code'] == $code)
//			$ok = "true";
//		
//		if ($ok == "true")
//		{		
//			$query = "UPDATE profile SET email_address_valid = 'yes', returned_mail = 'no' WHERE id = ".$verifyid;
//
//			$result = run_query( $query, $cxn );
//
//			echo black( "<br>Email address verified<br><br>Your account has been activated<br><br><br>" );
//		}
//		else
//			echo red( "ERROR: invalid email verification code<br><br>" );	

	}
	

	echo show_home_link();
		
?>