	<?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']);

	$getusers	= mysqli_query($connect,"SELECT * FROM users WHERE id_session='$key'");
	$u	   		= mysqli_fetch_array($getusers);
	$jumlah   	= mysqli_num_rows($getusers);
	
	$masterakun = mysqli_query($connect,"SELECT * FROM users WHERE phone_number='$u[master]'");
	$m=mysqli_fetch_array($masterakun);


	if ($jumlah > 0){

	$query = "SELECT * FROM store WHERE user='$m[phone_number]' AND status = '0'";
	$hasil = mysqli_query($connect,$query);


	if(mysqli_num_rows($hasil) > 0 ){
  $response = array(
    'status' 	=> 'true',
    'errCode' 	=> '01',
	'msg' 		=> 'Success'
   );
  $response["data"] = array();
  while($x = mysqli_fetch_array($hasil)){
	  
	$mastertoko = mysqli_query($connect,"SELECT * FROM store WHERE user='$u[master]'");
	$mt=mysqli_fetch_array($mastertoko);
	
	 if($x['img']==''){
          $img= "";
      }else{
          $img= "http://$_SERVER[HTTP_HOST]/geten/images/logo/$x[img]";
      }
	
	$h['id_store'] 			= $x["id_store"];
    $h['name_store'] 		= $x["name_store"];
    $h['number_store'] 		= $x["number_store"];
    $h['address'] 			= $x["address"];
    $h['email'] 			= $x["email"];
    $h['nohp'] 				= $x["nohp"];
    $h['tax'] 				= $x["tax"];
    $h['type'] 				= $x["type"];
    $h['service_charge'] 	= $x["service_charge"];
	$h['province'] 			= $x["province"];
    $h['city'] 				= $x["city"];
    $h['shift'] 			= $x["shift"];
    $h['currency'] 			= $x["currency"];
    $h['footer'] 			= $x["footer"];
	$h['img'] 				= $img;
    array_push($response["data"], $h);
  }
  echo json_encode($response);
	}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);	
	}
	?>