	<?php
	/**
	* Created by PhpStorm.
	* User: ahmad
	* Date: 20/08/2019
	* Time: 11:48 AM
	*/

	require_once("../connection.php");
	
	$key=mysqli_real_escape_string($connect, $_GET['key']);
	$date=mysqli_real_escape_string($connect, $_GET['id']);

	$getusers = mysqli_query($connect,"SELECT * FROM users WHERE id_session='$key'");
	$u	      = mysqli_fetch_array($getusers);
	$count   = mysqli_num_rows($getusers);
	
	$today	= gmdate("Y-m-d H:i:s", time()+60*60*7);
	$dates	= gmdate("Y-m-d", time()+60*60*7);
	
	$start		= gmdate("$dates 00:00:00", time()+60*60*7);
	$finish	= gmdate("$dates 23:59:00", time()+60*60*7);
	

	if ($count > 0){
	
	$query = "SELECT * FROM intial WHERE id_store='$u[id_store]' AND create_at>='$start' AND create_at<='$finish'";
	$hasil = mysqli_query($connect,$query);
	if(mysqli_num_rows($hasil) > 0 ){
	while($x = mysqli_fetch_array($hasil)){
	 
	 mysqli_query($connect,"UPDATE intial SET flag		= 'C', 
											  update_at = '$today'
										WHERE initial_date >= '$start' AND initial_date <= '$finish'");
										
	 mysqli_query($connect,"UPDATE users SET initial = 'C' WHERE phone_number = '$x[phone_number]'");
	}
							
	$json = array(
    'status' 	=> 'true',
    'errCode' 	=> '01',
	'msg' 		=> 'Success'
	);

    echo json_encode($json);
	}else{
		$response = array(
    'status' 	=> 'true',
    'errCode' 	=> '02',
	'msg' 		=> 'no data'
   );
  echo json_encode($response);
	}

	}else{
	
	
 $json = array(
    'status' 	=> 'true',
    'errCode' 	=> '00',
	'msg' 		=> 'User Not Found'
   );

    echo json_encode($json);	
	}
	?>