<?php


include '../db_api.php';





header('Access-Control-Allow-Origin: *');


header('Content-Type: application/json');





$url="https://".$_SERVER['HTTP_HOST']."/api/user/profile";


$curl = curl_init($url);


curl_setopt($curl, CURLOPT_URL, $url);


curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);


$rev=0;

$user_id=$_GET['user_id'];
$headers = array(


   "X-Api-Key: ".$_GET['X-Api-Key'],


   "X-Token: ".$_GET['X-Token'],


);


curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);


//for debug only!


curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);


curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);





$resp = curl_exec($curl);


curl_close($curl);





$re= json_decode($resp, true);





$re= json_decode($resp, true);





if ($re['status']==1){


$arr_hay="";


$arr_nchi="";


$arr_tot="";


$total="a";


$vente="a";


$hay_kg="a";


$hay_chkara="a";


$nchira_kg="a";


$nchira_chkara="a";


$total3="a";


$sum_nbr_pieds="a";





// Perform query


mysqli_set_charset($conn,"utf8mb4");


	


$sql = "SELECT * FROM `agritun_masra_sortant` where user_id='$user_id'";





$result = $conn->query($sql);





if ($result->num_rows > 0) {


  // output data of each row


  $i=0;


  $j=0;


  $arr_hayy="";


  $arr_nchira="";


  


  while($row = $result->fetch_assoc()) {


		if ($row["qualite_zit"]=="حي"){


			$i=$i+1;


			$arr_hayy=$arr_hayy."ab".($i);


			$arr_hay=$arr_hay."ab".number_format((intval($row["qte_zit"])/intval($row["qte_zitoun"]))*100,3);		


		}else{


			$j=$j+1;


			$arr_nchira=$arr_nchira."ab".($j);


			$arr_nchi=$arr_nchi."ab".number_format((intval($row["qte_zit"])/intval($row["qte_zitoun"]))*100,3);


		}


  }


  


  if($j>=$i){


	$arr_tot=$arr_nchira;


}else{


	$arr_tot=$arr_hayy;


}





} else {


  


}





$conn -> close();





echo '{"arr":"'.$arr_hay.'","arrn":"'.$arr_nchi.'","arrtot":"'.$arr_tot.'","total":"'.$total.'","vente":"'.$vente.'","rev":"'.$rev.'","hay_kg":"'.$hay_kg.'","hay_chkara":"'.$hay_chkara.'","nchira_kg":"'.$nchira_kg.'","nchira_chkara":"'.$nchira_chkara.'","nbr_p_r":"'.$total3.'","nbr_p_t":"'.$sum_nbr_pieds.'"}';








}


?>