	<?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 news Order By id_news DESC LIMIT 6";
	$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)){
	  
				$content_news = strip_tags($x['detail']); // membuat paragraf pada isi berita dan mengabaikan tag html
                $content = substr($content_news,0,100); // ambil sebanyak 220 karakter
                $content = substr($content_news,0,strrpos($content," ")); // potong per spasi kalimat
				
				
    $h['id_news'] 	= $x["id_news"];
    $h['title'] = $x["title"];
    $h['detail'] = $x["detail"];
    $h['desc'] = $content;
    $h['img'] = $x["img"];
    array_push($response["data"], $h);
  }
  echo json_encode($response);
	}

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

    echo json_encode($json);	
	}
	?>