<?php

$sessionHandling = true;

include ("_dirinfo.php");
include (PATH_TO_ROOT."init.php");
include (PATH_TO_ROOT."webuserspool/UsersPoolinit.php");

$sql = "SELECT a.id, a.email, b.definedStatus  FROM ".DB_WARPIT_USERSPOOL.".".WUP_INTERVIEWER." as a 
			LEFT JOIN ".DB_WARPIT_USERSPOOL."._InterviewerStatuses as b ON a.id = b.interviewer_id AND definedStatus = 9
				
		WHERE a.email = '".strip_tags(htmlentities($_GET['email'],ENT_QUOTES))."' LIMIT 1";
$res = $db->SQLexecute($sql);

if ($db->NumRows($res)) {
	$zad = $db->fetchAssoc($res);
	
	if (md5($zad['email'].$zad['id']) == $_GET['secureToken']) {
		
		if ($zad['definedStatus'] == 9) {
			include("_documents/template.removalRequest.removal-exists.php");
		} else {		
			// everything is ok.... I show thank you message and define user as removed in webuserspool	
			$sql = "INSERT INTO ".DB_WARPIT_USERSPOOL."._InterviewerStatuses SET interviewer_id = ".$zad['id'].", definedStatus = 9, definedDate = NOW() ";
			$db->SQLexecute($sql);
			include("_documents/template.removalRequest.php");
		}
				
		
	} else {
		// something is wrong with security token
		include("_documents/template.removalRequest.error.php");
	}
} else {
	// something was wrong with email
	include("_documents/template.removalRequest.error.php");
}


?>