<?php
require_once "db_connect.php";

$result = mysqli_query($db,"select * from reports_details rd join reports r on rd.report_id = r.id where r.approve_status = 'approved' and primary_cause_code in ('801','802','804','803','806') and eventdate > '2020-11-30'");


$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 == 'January'){
      	if (in_array("January", $monthArray))
          {
         
          } else{
              array_push($monthArray,"January"); 
          } 
            if($row['primary_cause_code'] == '801'){
             $jan = $jan + 1;
            } else if($row['primary_cause_code'] == '803'){
             $jand = $jand + 1;
            } else if($row['primary_cause_code'] == '806'){
             $jano = $jano + 1;
            }else if($row['primary_cause_code'] == '802'){
             $janh = $janh + 1;
            }else if($row['primary_cause_code'] == '804'){
             $jando = $jando + 1;
            }
      } else if($month == 'February'){
          if (in_array("February", $monthArray))
          {
         
          } else{
              array_push($monthArray,"February"); 
          }   
            
            if($row['primary_cause_code'] == '801'){
             $feb = $feb + 1;
            } else if($row['primary_cause_code'] == '803'){
             $febd = $febd + 1;
            } else if($row['primary_cause_code'] == '806'){
             $febo = $febo + 1;
            }else if($row['primary_cause_code'] == '802'){
             $febh = $febh + 1;
            }else if($row['primary_cause_code'] == '804'){
             $febdo = $febdo + 1;
            }
      }else if($month == 'March'){
          if (in_array("March", $monthArray))
          {
         
          } else{
          array_push($monthArray,"March");
          }    
            if($row['primary_cause_code'] == '801'){
             $mar = $mar + 1;
            } else if($row['primary_cause_code'] == '803'){
             $mard = $mard + 1;
            } else if($row['primary_cause_code'] == '806'){
             $maro = $maro + 1;
            }else if($row['primary_cause_code'] == '802'){
             $marh = $marh + 1;
            }else if($row['primary_cause_code'] == '804'){
             $mardo = $mardo + 1;
            }
      }else if($month == 'April'){
          if (in_array("April", $monthArray))
          {
         
          } else{
          array_push($monthArray,"April");
          }
            if($row['primary_cause_code'] == '801'){
             $apr = $apr + 1;
            } else if($row['primary_cause_code'] == '803'){
             $aprd = $aprd + 1;
            } else if($row['primary_cause_code'] == '806'){
             $apro = $apro + 1;
            }else if($row['primary_cause_code'] == '802'){
             $aprh = $aprh + 1;
            } else if($row['primary_cause_code'] == '804'){
             $aprdo = $aprdo + 1;
            }
      }else if($month == 'May'){
          if (in_array("May", $monthArray))
          {
         
          } else{
          array_push($monthArray,"May");
          }    
            if($row['primary_cause_code'] == '801'){
             $may = $may + 1;
            } else if($row['primary_cause_code'] == '803'){
             $mayd = $mayd + 1;
            } else if($row['primary_cause_code'] == '806'){
             $mayo = $mayo + 1;
            }else if($row['primary_cause_code'] == '802'){
             $mayh = $mayh + 1;
            } else if($row['primary_cause_code'] == '804'){
             $maydo = $maydo + 1;
            }
      }/*else if($month == 'June'){
          if (in_array("June", $monthArray))
          {
         
          } else{
          array_push($monthArray,"June");
          }    
            if($row['primary_cause_code'] == '801'){
             $jun = $jun + 1;
            } else if($row['primary_cause_code'] == '803'){
             $jund = $jund + 1;
            } else if($row['primary_cause_code'] == '806'){
             $juno = $juno + 1;
            }else if($row['primary_cause_code'] == '802'){
             $junh = $junh + 1;
            } else if($row['primary_cause_code'] == '804'){
             $jundo = $jundo + 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;
            }
      }*/



       
}


$sexualArray = array($dec,$jan,$feb, $mar, $apr, $may);
$domesticArray = array($decd,$jand,$febd, $mard, $aprd, $mayd);
$humanArray = array($dech,$janh,$febh, $marh, $aprh, $mayh);
$dowryArray = array($decdo,$jando,$febdo, $mardo, $aprdo, $maydo);
$otherArray = array($deco,$jano,$febo, $maro, $apro, $mayo);


$finalArray = array();

array_push($finalArray, $sexualArray);
array_push($finalArray, $domesticArray);
array_push($finalArray, $otherArray);
array_push($finalArray, $humanArray);
array_push($finalArray, $dowryArray);
array_push($finalArray, $monthArray);


echo json_encode($finalArray);
