<?php
session_start();
header('Content-Type: text/html; charset=utf-8');

//set_time_limit(900);

$client_id = $_SESSION['client_id'];

$dbset = json_decode($_SESSION['settingsApp'],true);
$db = new mysqli ($dbset['DB']['DB_HOST'],$dbset['DB']['DB_USER'],$dbset['DB']['DB_PASS'],$dbset['DB']['DB_NAME']);

/*$DB_HOST='194.0.150.90';
$DB_USER='ilog';
$DB_PASS='1111';
$DB_NAME='tms37';
$db = new mysqli ($DB_HOST,$DB_USER,$DB_PASS,$DB_NAME);*/

$db->query("SET CHARSET SET utf8");
$db->query("SET NAMES 'utf8'");
if (mysqli_connect_errno()) {
	echo "Error connecting to DB";
	exit;
}

	$id = $_REQUEST['id'];
	

		if( !isset($id) || $id=="" || $id=='false' ){
			echo json_encode(array('success'=>false, 'message'=>'Id is empty', 'data'=>array()));
		}else{
			$query = "SELECT `id`,`in_progress`,`progress_percent`,`result_message` FROM `tms_web_tasks_autoplan` WHERE user_id = ".$client_id." AND `id` = ".$id.";";	
		}


	if(!$stmt = $db->query($query)){
		//echo '{"success":false,"message":"'.$db->errno.' '.$db->error.'","data":[]}';
		echo json_encode(array('success'=>false, 'message'=>$db->errno . ' ' . $db->error, 'data'=>array()));
	}else{
		//$result = $stmt->fetch_all(MYSQLI_ASSOC);
		for ($result = array(); $tmp = $stmt->fetch_array(MYSQLI_ASSOC);) $result[] = $tmp;
		$stmt->close();
		//echo '{"success":true,"message":"","data":'.json_encode($result).'}';
		echo json_encode(array('success'=>true, 'message'=>'', 'data'=>$result));
	}
	$db->close();
	exit;
	



?>
