<?php 
	session_start(); 
	include('conn/connect.php'); // ติดต่อฐานข้อมูล 
	if($_POST['type']=="Inform"){

		$sql_request = "SELECT * FROM request WHERE placeID = '".$_POST["placeID"]."' and request_typeID = '".$_POST['work']."' ";
		$query_request = mysqli_query($conn,$sql_request);
		$result_request=mysqli_fetch_array($query_request);
		if($result_request){
			$quatity = $result_request['quatity']+1;
			$sql =" UPDATE request SET quatity = '".$quatity."'  WHERE ID = '".$result_request['ID']."' ";
		}else{
			$sql = "INSERT INTO request (
				placeID, 
				request_typeID, 
				request_type,
				remark,
				status,
				time_create,
				time_finish,
				quatity,
				remark_img,
				finish_img_1,
				finish_img_2,
				finish_img_3
			)VALUES(
				'".$_POST["placeID"]."',
				'".$_POST["work"]."',
				'".$_POST["detail"]."',
				' ',
				'1',
				'".$date." ".$time."',
				'0000-00-00 00:00:00',
				'1',
				' ',
				' ',
				' ',
				' '
			)";
		}


		
	}else if($_POST['type']=="vote"){
		$sql = "INSERT INTO satisfaction (
			placeID, 
			level, 
			time_create
		)VALUES(
			'".$_POST["placeID"]."',
			'".$_POST["work"]."',
			'".$date." ".$time."'
		)";
	}else{
		$sql = "INSERT INTO request (
			placeID, 
			request_typeID, 
			request_type,
			remark,
			status,
			time_create,
			time_finish,
			quatity,
			remark_img,
			finish_img_1,
			finish_img_2,
			finish_img_3
		)VALUES(
			'".$_POST["placeID"]."',
			'1',
			'".$_POST["detail"]."',
			'".$_POST["work"]."',
			'1',
			'".$date." ".$time."',
			'0000-00-00 00:00:00',
			'1',
			'".$_POST["url_img"]."',
			' ',
			' ',
			' '
		)";
	}
	

	$query = mysqli_query($conn,$sql);
	if($query){
		echo "ok";
	}else{
		echo "no";
	}
	
?>
