<?php
	
	include_once("_dirinfo.php");
	include_once(PATH_TO_ROOT."init.php");
	include_once(PATH_TO_ROOT."_support/stringFunctions.php");

	
	if ($_POST['action'] == "save") {
		
		// ------------ CHECKING VARIABLES
		$CheckVariable = sf_CheckForMySQL($_POST);
		
		$sql = "UPDATE ".DB_WARPIT_WEBCATI_BASE."._Capi_interviewer_visits 
					SET 
						priimek_gosp = '".$CheckVariable['priimek_gosp']."',
						komentar = '".$CheckVariable['komentar']."',
						ponovni_dogovor = '".$CheckVariable['input_date']." ".$CheckVariable['input_time'].":00',
						status_obiska = 8
				 WHERE id = ".$_POST['id_visit'];
		
		$db->SQLexecute($sql);
		
		
	//	file_put_contents("/tmp1/capi.txt",print_r($sql,true),FILE_APPEND);
		
		$sql = 	" SELECT a.id, a.id_user, a.id_site, b.proj_name FROM ".DB_WARPIT_WEBCATI_BASE."._www_ids as a
						LEFT JOIN ".DB_WARPIT_WEBCATI_BASE."._Projects as b ON a.id_project = b.id
							WHERE 
										id_project 	= ".$_SESSION['capi']['id_project']."
									AND id_user 	= ".$_SESSION['UserInfo']['id']."
									AND user_type 	= 4
									AND id_site		IN 	(SELECT quest_id FROM ".DB_WARPIT_WEBCATI_BASE."._Capi_interviewer_visits WHERE id = ".$_POST['id_visit'].")";
		
	//	file_put_contents("/tmp1/capi.txt",print_r($sql,true),FILE_APPEND);
		$res = $db->SQLexecute($sql);
		$zad = $db->fetchAssoc($res);
		
		//file_put_contents("/tmp1/capi.txt",print_r($sql,true),FILE_APPEND);
		
		
		$sql = "UPDATE `".DB_WARPIT_WEBCATI_BASE."`.`".$zad['proj_name']."_structure` 
					SET 
							`status` = 91, 
							`status_rec` = 0
					WHERE 
									user_id 		= ".$zad['id_user']."
							AND		id_site			= '".$zad['id_site']."'
							AND 	id_loginSID		= ".$zad['id'];
							
		$db->SQLexecute($sql);
		
		//file_put_contents("/tmp1/capi.txt",print_r($sql,true),FILE_APPEND);
		
	}
	echo "{ success: true }";
	
?>