<?php
require_once "db_connect.php";
$cArray = "('Solidarity','Dialogue','Safety','Association','Assembly','Expression')";
if($_GET['type'] == 'hea'){
$cArray = "('Expression')";
} else if($_GET['type'] == 'irr') {
$cArray = "('Association')";
} else if($_GET['type'] == 'pre') {
$cArray = "('Assembly')";
} else if($_GET['type'] == 'lock') {
$cArray = "('Solidarity')";
} else if($_GET['type'] == 'qua') {
$cArray = "('Dialogue')";
} else if($_GET['type'] == 'rel') {
$cArray = "('Safety')";
}

$result = mysqli_query($db,"select r.eventdate, rd.violent_nonviolent from reports_details rd join reports r on rd.report_id = r.id where r.approve_status = 'approved' and secondary_cause_code in ".$cArray." and eventdate > '2020-12-31'");


$jan = 0;
$feb = 0;
$mar = 0;
$apr=0;
$may=0;
$jun=0;
$jul=0;
$aug=0;
$sep=0;
$oct=0;
$nov=0;
$dec=0;

$jand = 0;
$febd = 0;
$mard = 0;
$aprd=0;
$mayd=0;
$jund=0;
$juld=0;
$augd=0;
$sepd=0;
$octd=0;
$novd=0;
$decd=0;

$jano = 0;
$febo = 0;
$maro = 0;
$apro=0;
$mayo=0;
$juno=0;
$julo=0;
$augo=0;
$sepo=0;
$octo=0;
$novo=0;
$deco=0;

$janh = 0;
$febh = 0;
$marh = 0;
$aprh=0;
$mayh=0;
$junh=0;
$julh=0;
$augh=0;
$seph=0;
$octh=0;
$novh=0;
$dech=0;

$jando = 0;
$febdo = 0;
$mardo = 0;
$aprdo=0;
$maydo=0;
$jundo=0;
$juldo=0;
$augdo=0;
$sepdo=0;
$octdo=0;
$novdo=0;
$decdo=0;

$monthArray = array();

while ($row = mysqli_fetch_assoc($result)) {

      $time=strtotime($row['eventdate']);
      $month=date("F",$time);
      //echo $month;
    /*  if($month == 'December'){
        if (in_array("December", $monthArray))
          {
         
          } else{
              array_push($monthArray,"December"); 
          } 
            if($row['primary_cause_code'] == '801'){
             $dec = $dec + 1;
            } else if($row['primary_cause_code'] == '803'){
             $decd = $decd + 1;
            } else if($row['primary_cause_code'] == '806'){
             $deco = $deco + 1;
            }else if($row['primary_cause_code'] == '802'){
             $dech = $dech + 1;
            }else if($row['primary_cause_code'] == '804'){
             $decdo = $decdo + 1;
            }

      } else*/ if($month == 'October'){
            if($row['violent_nonviolent'] == 'violent'){
             $jan = $jan + 1;
            } else {
              $jand = $jand + 1;
            }
      
      } else if($month == 'November'){
          
            if($row['violent_nonviolent'] == 'violent'){
             $feb = $feb + 1;
            } else {
              $febd = $febd + 1;
            }
            
      }else if($month == 'December'){
          if($row['violent_nonviolent'] == 'violent'){
             $mar = $mar + 1;
            } else {
              $mard = $mard + 1;
            }
          
      }else if($month == 'January'){
          if($row['violent_nonviolent'] == 'violent'){
             $apr = $apr + 1;
            } else {
              $aprd = $aprd + 1;
            }
      }else if($month == 'February'){
         if($row['violent_nonviolent'] == 'violent'){
             $may = $may + 1;
            } else {
              $mayd = $mayd + 1;
            }
            
      }else if($month == 'March'){
          if($row['violent_nonviolent'] == 'violent'){
             $jun = $jun + 1;
            } else {
              $jund = $jund + 1;
            } 
      }/*else if($month == 'July'){
          if (in_array("July", $monthArray))
          {
         
          } else{
          array_push($monthArray,"July");
          }    
            if($row['primary_cause_code'] == '801'){
             $jul = $jul + 1;
            } else if($row['primary_cause_code'] == '803'){
             $juld = $juld + 1;
            } else if($row['primary_cause_code'] == '806'){
             $julo = $julo + 1;
            }else if($row['primary_cause_code'] == '802'){
             $julh = $julh + 1;
            } else if($row['primary_cause_code'] == '806'){
             $juldo = $juldo + 1;
            }
      }else if($month == 'August'){
          if (in_array("August", $monthArray))
          {
         
          } else{
          array_push($monthArray,"August");
          }    
            if($row['primary_cause_code'] == '801'){
             $aug = $aug + 1;
            } else if($row['primary_cause_code'] == '803'){
             $augd = $augd + 1;
            } else if($row['primary_cause_code'] == '806'){
             $augo = $augo + 1;
            }else if($row['primary_cause_code'] == '802'){
             $augh = $augh + 1;
            } else if($row['primary_cause_code'] == '806'){
             $augdo = $augdo + 1;
            }
      }*/



       
}

$vArray = array($jan, $feb, $mar, $apr, $may, $jun);
$nvArray = array($jand, $febd, $mard, $aprd, $mayd, $jund);

$finalArray = array();

array_push($finalArray, $vArray);
array_push($finalArray, $nvArray);

echo json_encode($finalArray);
