<?php
header('Content-Type: text/html; charset=ISO-8859-1');
require_once "db_connect.php";
$queryIs = "select sum(case when primary_form_code in (242) then 1 else 0 end) as 'excessive', 
sum(case when secondary_form_code in (243) then 1 else 0 end) as 'intervention', 
sum(case when secondary_form_code in (244) then 1 else 0 end) as 'detentionp', 
sum(case when secondary_form_code in (245) then 1 else 0 end) as 'censorship', 
sum(case when secondary_form_code in (246) then 1 else 0 end) as 'attackj', 
sum(case when secondary_form_code in (248) then 1 else 0 end) as 'restrictive', 
sum(case when secondary_form_code in (247) then 1 else 0 end) as 'detentionj', 
sum(case when secondary_form_code in (249) then 1 else 0 end) as 'attackh', 
sum(case when secondary_form_code in (250) then 1 else 0 end) as 'harassment',
sum(case when secondary_form_code in (30) then 1 else 0 end) as 'Threat/Intimidation'  
from reports_details rd join reports_tags rt on rd.report_id = rt.report_id where rt.tag_id = 20";
if($_GET['code'] == 'lock'){
 $code = '991';
 $queryIs = $queryIs." and rd.secondary_cause_code='Solidarity'";
} else if($_GET['code'] == 'qua'){
   $code = '992';
   $queryIs =  $queryIs." and rd.secondary_cause_code='Dialogue'";
} else if($_GET['code'] == 'rel'){
   $code = '993';
   $queryIs =  $queryIs." and rd.secondary_cause_code='Safety'";
} else if($_GET['code'] == 'irr'){
 $code = '994';
 $queryIs =  $queryIs." and rd.secondary_cause_code='Association'";
} else if($_GET['code'] == 'pre'){
   $code = '995';
   $queryIs =  $queryIs." and rd.secondary_cause_code='Assembly'";
} else if($_GET['code'] == 'hea'){
   $code = '996';
   $queryIs =  $queryIs." and rd.secondary_cause_code='Expression'";
} 

//echo $queryIs;

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

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

//echo $_GET['datas'];
while ($row=mysqli_fetch_array($result)) {
         
        if($row['excessive'] != '0'){
            
          array_push($numberArray,$row['excessive']);
          array_push($caseArray,'Excessive Use of Force');
        }

        if($row['intervention'] != '0'){
          array_push($numberArray,$row['intervention']);
          array_push($caseArray,'Intervention of Protest');
        }
     
        if($row['detentionp'] != '0'){
          array_push($numberArray,$row['detentionp']);
          array_push($caseArray,'Detention of Protestors');
        }
        if($row['censorship'] != '0'){
          array_push($numberArray,$row['censorship']);
          array_push($caseArray,'Censorship');
        }

        if($row['attackj'] != '0'){
          array_push($numberArray,$row['attackj']);
          array_push($caseArray,'Attack on Journalist');
        }

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

        if($row['detentionj'] != '0'){
          array_push($numberArray,$row['detentionj']);
          array_push($caseArray,'Detention of Journalist');
        }

        if($row['attackh'] != '0'){
          array_push($numberArray,$row['attackh']);
          array_push($caseArray,'Attack on HRD');
        }

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

        if($row['Threat/Intimidation'] != '0'){
      array_push($numberArray,$row['Threat/Intimidation']);
      array_push($caseArray,'Threat/Intimidation');
    } 
          
        }  
        
array_push($finalArray, $numberArray);
array_push($finalArray, $caseArray);

echo json_encode($finalArray);
