<?php 
	include('code.php'); 
	session_start(); 
	include('../conn/connect.php');
	$sql_place = "SELECT * FROM place WHERE ID_place = '".$_POST['placeID']."' and keycode_text = '".$_POST['confirm_number_text']."' ";
	$query_place = mysqli_query($conn,$sql_place);
	if (mysqli_num_rows($query_place) > 0 || $_POST['type']=="update") {
		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_text,
					status,
					time_create,
					time_finish,
					quatity,
					remark_img,
					finish_img_1,
					finish_img_2,
					finish_img_3,
					remark_finish
				)VALUES(
					'".$_POST["placeID"]."',
					'".$_POST["work"]."',
					'".$_POST["detail"]."',
					'no_text',
					'1',
					'".$date." ".$time."',
					'0000-00-00 00:00:00',
					'1',
					'no_img',
					'no_img',
					'no_img',
					'no_img',
					'no_text'
				)";
			}
		}else if($_POST['type']=="vote"){
			$sql = "INSERT INTO satisfaction (
				placeID, 
				level, 
				time_create
			)VALUES(
				'".$_POST["placeID"]."',
				'".$_POST["work"]."',
				'".$date." ".$time."'
			)";
		}else if($_POST['type']=='1'){
			$sql = "INSERT INTO request (
				placeID, 
				request_typeID, 
				request_type,
				remark_text,
				status,
				time_create,
				time_finish,
				quatity,
				remark_img,
				finish_img_1,
				finish_img_2,
				finish_img_3,
				remark_finish
			)VALUES(
				'".$_POST["placeID"]."',
				'1',
				'".$_POST["detail"]."',
				'".$_POST["work"]."',
				'1',
				'".$date." ".$time."',
				'0000-00-00 00:00:00',
				'1',
				'".$_POST["url_img"]."',
				'no_img',
				'no_img',
				'no_img',
				'no_text'
			)";
		}else if($_POST['type']=="update"){
			$sql =" UPDATE request SET 
				status = '3',
				remark_finish = '".$_POST["work"]."' ,
				finish_img_1 = '".$_POST['url_ok_1']."',
				finish_img_2 ='".$_POST['url_ok_2']."',
				finish_img_3 ='".$_POST['url_ok_3']."'
			WHERE ID = '".$_POST['work_ID']."' ";
		}
		

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