<?php
	require_once '../../autoload.php';

	$result = array (
			"status"	=> 'KO',
			"results"	=> array ()
	);

	$task_id			= $_POST["task_id"];
	$staff_member_id	= $_POST['staff_member_id'];
	$reminder_staff_id	= $_POST['reminder_staff_id'];

	error_log ( " task_id : " .$task_id );
	error_log ( " staff_member_id : " .$staff_member_id );

	$pdo = getPDO ();
	
	if ( $pdo )
	{
		$result['status'] = 'OK';

		error_log ( "Set last_reminder...");
		$s1 = $pdo->prepare ( "update task_link set last_reminder=NOW(), last_reminder_staff_id=:reminder_staff_id where task_id=:task_id and staff_member_id=:staff_id returning last_reminder" );
		$s1->bindParam ( ':task_id', 			$task_id 			);
		$s1->bindParam ( ':staff_id', 			$staff_member_id 	);
		$s1->bindParam ( ':reminder_staff_id', 	$reminder_staff_id 	);

		if ( $s1->execute () == true )
		{
			$last_reminder = $s1->fetchColumn ();
			error_log ( "last_reminder : " .$last_reminder );
			$result['status'] = 'OK';
			array_push ( $result['results'], array ( 	"task_id" => $task_id,
														"staff_member_id"	=> $staff_member_id,
														"last_reminder"	=> $last_reminder ) );
		}
		else
			$result['status'] = 'OK';
	}

	header('Content-type: application/json');
	
	echo json_encode ( $result );
?>