<?php

include_once("_dirinfo.php");
include_once(PATH_TO_ROOT."init.php");



if ($_POST['action'] == 'update') {
	
	$sql = "UPDATE   ".DB_WARPIT_WEBCATI_BASE."._Capi_interviewer_visits   
				SET 
					".$_POST['field']." = '".$_POST['value']."' 
				WHERE  id = ".$_POST['id'];
	$db->SQLexecute($sql);
	echo "{ success : true, sql: '".$sql."'}";
	
}  else {
	if (!$_SESSION['capi']['id_project']) {
		echo "{
				success: true,
			    results: 0 			          	    
			  }";
		
		exit;
	}
	$sql = "SELECT * FROM ".DB_WARPIT_WEBCATI_BASE."._Capi_interviewer_visits WHERE status_obiska = 8";
		
	$result = $db->SQLexecute($sql);
	while ($dat = $db->fetchAssoc($result)) {
		
		$data[] = $dat;
	}
?>
	
	{
		success: true,
	    results: <?php echo sizeof($data);?>, 
	    rows: <?php echo json_encode($data); ?>        	    
	}
<?php 
}
?>