<?php
header('Content-Type: text/html; charset=ISO-8859-1');
require_once "db_connect.php";
$queryIs = "select sum(case when primary_form_code in (02,06,10) then 1 else 0 end) as 'Assault/Clash', sum(case when primary_form_code in (28) then 1 else 0 end) as 'Arrest', sum(case when primary_form_code in (32) then 1 else 0 end) as 'Banishment/Shunning', sum(case when primary_form_code in (37) then 1 else 0 end) as 'Black Marketing', sum(case when primary_form_code in (27) then 1 else 0 end) as 'Curfew', sum(case when primary_form_code in (30,31) then 1 else 0 end) as 'Other Latent Forms', sum(case when primary_form_code in (21,22,23,24,25,241) then 1 else 0 end) as 'Protest', sum(case when primary_form_code in (04,14) then 1 else 0 end) as 'Violent Protest' from reports_details rd join reports_tags rt on rd.report_id = rt.report_id where rt.tag_id = 19";
if($_GET['code'] == 'lock'){
 $code = '991';
 $queryIs = $queryIs." and rd.secondary_cause_code='991'";
} else if($_GET['code'] == 'qua'){
   $code = '992';
   $queryIs =  $queryIs." and rd.secondary_cause_code='992'";
} else if($_GET['code'] == 'rel'){
   $code = '993';
   $queryIs =  $queryIs." and rd.secondary_cause_code='993'";
} else if($_GET['code'] == 'irr'){
 $code = '994';
 $queryIs =  $queryIs." and rd.secondary_cause_code='994'";
} else if($_GET['code'] == 'pre'){
   $code = '995';
   $queryIs =  $queryIs." and rd.secondary_cause_code='995'";
} else if($_GET['code'] == 'hea'){
   $code = '996';
   $queryIs =  $queryIs." and rd.secondary_cause_code='996'";
} 

//echo "hahahaa".$queryIs;

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

$numberArray = array();
$caseArray = array();
$finalArray = array();

//echo $_GET['datas'];
while ($row=mysqli_fetch_array($result)) {
         
        if($row['Assault/Clash'] != '0'){
            
          array_push($numberArray,$row['Assault/Clash']);
          array_push($caseArray,'Assault/Clash');
        }

       

        if($row['Arrest'] != '0'){
          array_push($numberArray,$row['Arrest']);
          array_push($caseArray,'Arrest');
        }
     
        if($row['Banishment/Shunning'] != '0'){
          array_push($numberArray,$row['Banishment/Shunning']);
          array_push($caseArray,'Banishment/Shunning');
        }
        if($row['Black Marketing'] != '0'){
          array_push($numberArray,$row['Black Marketing']);
          array_push($caseArray,'Black Marketing');
        }

        if($row['Curfew'] != '0'){
          array_push($numberArray,$row['Curfew']);
          array_push($caseArray,'Curfew');
        }

        if($row['Protest'] != '0'){
          array_push($numberArray,$row['Protest']);
          array_push($caseArray,'Protest');
        }

        if($row['Violent Protest'] != '0'){
          array_push($numberArray,$row['Violent Protest']);
          array_push($caseArray,'Violent Protest');
        }

        if($row['Other Latent Forms'] != '0'){
          array_push($numberArray,$row['Other Latent Forms']);
          array_push($caseArray,'Other Latent Forms');
        }

           
        }  
        

array_push($finalArray, $numberArray);
array_push($finalArray, $caseArray);


echo json_encode($finalArray);
