<?php
include_once ("_dirinfo.php");

include_once (PATH_TO_ROOT."init.php");
include_once (PATH_TO_ROOT."_ajaxManipulators/_class/class.gridData.php");
include_once (PATH_TO_ROOT.'webuserspool/UsersPoolinit.php');

$interviewer = '_Interviewer';
$intStructure = '_InterviewerStructure';

class mailCatcherManipulator extends GridDataManipulator
{
	
	function updateAction()
	{
		
		if($_POST['field'] == 'mail_address')
		{//we find out the user ID...if it exists, we have to change the user email as well _MailCatcher email
			$sql = "SELECT b.interviewer_id  FROM _MailCatcher a INNER JOIN _MailStatistic b ON b.id = a.sendStatistic_id  WHERE a.id = " . $_POST['id'];
		If (!$this->rs = $this->db->SQLexecute($sql)) {	return '{success:false,error:"'.$this->db->GetError().'", STATEMENT: "'.$sql.'"}';}
				
				if($obj = $this->db->fetchArray($this->rs)){
					$intId = $obj[0];
					if($intId)
					{
						$sql = "UPDATE _Interviewer SET email = '".$_POST['value']."' WHERE id = $intId";
						If (!$this->rs = $this->db->SQLexecute($sql)) {	return '{success:false,error:"'.$this->db->GetError().'", STATEMENT: "'.$sql.'"}';}
		
					}
				}
				else
				{
					return "{success:false}";	 
				}
			
		}
		return parent::updateAction();
	}

}

	

$db->ChangeDatabase($_REQUEST['database']);

	$manipulator = new mailCatcherManipulator($db,$_REQUEST['RMtable']);

$comm = $_REQUEST['action'].'Action';
if(method_exists($manipulator,$comm))
	echo $manipulator->$comm();
else 
{
	
	echo '{success:false,error:"Unknown action!"}';	
	
}


?>
