<?php
include("db_connect.php");
$data = mysqli_real_escape_string($db,$_GET['code']);

$queryIs = "select COUNT(CASE WHEN rl.province_id = 1 THEN 1 END) AS province_1, COUNT(CASE WHEN rl.province_id = 2 THEN 1 END) AS province_2,COUNT(CASE WHEN rl.province_id = 3 THEN 1 END) AS Bagmati,COUNT(CASE WHEN rl.province_id = 4 THEN 1 END) AS Gandaki,COUNT(CASE WHEN rl.province_id = 5 THEN 1 END) AS province_5,COUNT(CASE WHEN rl.province_id = 6 THEN 1 END) AS Karnali, COUNT(CASE WHEN rl.province_id = 7 THEN 1 END) AS sudur_paschim from reports_locations rl join reports_details rd on rd.report_id = rl.report_id join reports_tags rt on rd.report_id = rt.report_id join reports r on r.id = rd.report_id where rt.tag_id = 20 and r.approve_status = 'approved'";

if($data == 'lock'){
 
   $queryIs = $queryIs." and rd.secondary_cause_code='Solidarity'";
} else if($data == 'qua'){
  
   $queryIs =  $queryIs." and rd.secondary_cause_code='Dialogue'";
} else if($data == 'rel'){
  
   $queryIs =  $queryIs." and rd.secondary_cause_code='Safety'";
} else if($data == 'irr'){
 
   $queryIs =  $queryIs." and rd.secondary_cause_code='Association'";
} else if($data == 'pre'){
   
   $queryIs =  $queryIs." and rd.secondary_cause_code='Assembly'";
} else if($data == 'hea'){
   
   $queryIs =  $queryIs." and rd.secondary_cause_code='Expression'";
}




$result = mysqli_query($db,$queryIs);

$province = array();
//echo $queryIs;
while ($row=mysqli_fetch_assoc($result)) {

array_push($province, $row['province_1']);
array_push($province, $row['province_2']);
array_push($province, $row['Bagmati']);
array_push($province, $row['Gandaki']);
array_push($province, $row['province_5']);
array_push($province, $row['Karnali']);
array_push($province, $row['sudur_paschim']);

}

echo json_encode($province);
?>