<?php
header('Content-Type: text/html; charset=ISO-8859-1');
include("db_connect.php");
$start = mysqli_real_escape_string($db,$_GET['start_date']);
$end = mysqli_real_escape_string($db,$_GET['end_date']);
$province = mysqli_real_escape_string($db,$_GET['province']);
$type = mysqli_real_escape_string($db,$_GET['type']);
//$output = array();
$types = "All Incidents related to Covid-19";
$provinces = " ";
$queryIs = "select r.id as report_id,rd.primary_form_code as form,r.title as incident, rl.municipality_id, r.eventdate as date, rl.province_id as province, ld.title as district,rd.violent_nonviolent as types from reports_details rd join reports_tags rt on rd.report_id = rt.report_id join reports r on r.id = rd.report_id join reports_locations rl on rl.report_id = r.id join location_districts ld on ld.id = rl.district_id join districts_codes dc on dc.district_id = ld.id where r.approve_status = 'approved' and rt.tag_id = 19 and r.eventdate between '$start' and '$end'";

if($province != "all"){
  $queryIs = $queryIs." and rl.province_id = $province";
  $provinces = " Province ".$province;
 }

if($type == 'lock'){
 
   $queryIs = $queryIs." and rd.secondary_cause_code='991'";
   $type = "Incidents during Lockdown Implementation";
} else if($type == 'qua'){
  
   $queryIs =  $queryIs." and rd.secondary_cause_code='992'";
   $types = "Incidents during Quarentine Implementation";
} else if($type == 'rel'){
  $types = "Incidents during government Relief Distribution";
   $queryIs =  $queryIs." and rd.secondary_cause_code='993'";
} else if($type == 'irr'){
   $types = "Incidents during Irregulrities in Comodity Market";
   $queryIs =  $queryIs." and rd.secondary_cause_code='994'";
} else if($type == 'pre'){
   $types = "Incidents during Prejudice and Discrimination";
   $queryIs =  $queryIs." and rd.secondary_cause_code='995'";
} else if($type == 'hea'){
   $types = "Incidents during Healthcare Management";
   $queryIs =  $queryIs." and rd.secondary_cause_code='996'";
}
$queryIs = $queryIs." group by r.id order by r.eventdate desc";
$query = mysqli_query($db,$queryIs);

?>
<!DOCTYPE html>
<html lang="en">

<head>
  <!-- Meta -->
  <meta charset="utf-8" />
  <meta http-equiv="X-UA-Compatible" content="IE=edge" />
  <meta name="keywords" content="SITE KEYWORDS HERE" />
  <meta name="description" content="" />
  <meta name="copyright" content="" />
  <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" />
  <!-- Title -->
  <title><?php echo $types." (".$start." to ".$end.") in".$provinces; ?></title>
  <!-- Favicon -->
  <link rel="icon" type="image/png" />
  <!-- Web Font -->
  <link href="https://fonts.googleapis.com/css?family=Roboto:300,400,500,700,900" rel="stylesheet" />
  <!-- Bootstrap CSS -->
  <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css"
    integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous">

  <!-- Font Awesome CSS -->
  <!-- Font Awesome Icons -->
  <link rel="stylesheet" href="fontawesome-free/css/all.min.css">
  <link rel="stylesheet" type="text/css" href="css/bootstrap-datepicker.css" />
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.9.3/Chart.min.css" />

  <link rel="stylesheet" href="https://cartodb-libs.global.ssl.fastly.net/cartodb.js/v3/3.15/themes/css/cartodb.css" />
  <!-- Google Font: Source Sans Pro -->
  <link href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,400,400i,700" rel="stylesheet" />
  <link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
  <link rel="stylesheet" type="text/css" href="//fonts.googleapis.com/css?family=Vollkorn" />
  <link href='https://api.mapbox.com/mapbox-gl-js/v1.8.1/mapbox-gl.css' rel='stylesheet' />
  <link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/npm/daterangepicker/daterangepicker.css" />
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/toastr.js/latest/toastr.min.css" />

  <link rel="stylesheet" href="css/style.css" />
  

  
     <link rel="stylesheet" href="https://cdn.datatables.net/1.10.21/css/jquery.dataTables.min.css" />
      <link rel="stylesheet" href= "https://cdn.datatables.net/buttons/1.6.2/css/buttons.dataTables.min.css" />
  <style type="text/css">
    .useIt {
      font-family: Vollkorn;
      font-style: normal;
      font-variant: normal;
      font-weight: 400;
    }


    h1 {
      font-family: Vollkorn;
      font-size: 24px;
      font-style: normal;
      font-variant: normal;
      font-weight: 700;
      line-height: 26.4px;
    }

    h3 {
      font-family: Vollkorn;
      font-size: 14px;
      font-style: normal;
      font-variant: normal;
      font-weight: 700;
      line-height: 15.4px;
    }

    p {
      font-family: Vollkorn;
      font-size: 14px;
      font-style: normal;
      font-variant: normal;
      font-weight: 400;
      line-height: 20px;
    }

    blockquote {
      font-family: Vollkorn;
      font-size: 21px;
      font-style: normal;
      font-variant: normal;
      font-weight: 400;
      line-height: 30px;
    }

    pre {
      font-family: Vollkorn;
      font-size: 13px;
      font-style: normal;
      font-variant: normal;
      font-weight: 400;
      line-height: 18.5714px;
    }

    .card-header {
      background-color: #417DC1;
      color: white;
    }

   img {vertical-align: middle;}

/* Slideshow container */
.slideshow-container {
  max-width: 1000px;
  position: relative;
  margin: auto;
}

/* Next & previous buttons */
/*.prev, .next {
  cursor: pointer;
  position: absolute;
  top: 50%;
  width: auto;
  padding: 16px;
  margin-top: -22px;
  margin-right:56px;
  margin-left:41px;
  color: white;
  font-weight: bold;
  font-size: 18px;
  transition: 0.6s ease;
  border-radius: 0 3px 3px 0;
  user-select: none;
}
.next {
  right: 0;
  border-radius: 3px 0 0 3px;
}*/

/* On hover, add a black background color with a little bit see-through */
.prev:hover, .next:hover {
  background-color: rgba(0,0,0,0.8);
}

/* Caption text */
.text1 {
  color: #f2f2f2;
  font-size: 15px;
  padding: 8px 12px;
  position: absolute;
  bottom: 8px;
  width: 100%;
  text-align: center;
}

/* Number text (1/3 etc) */
.numbertext {
  color: #f2f2f2;
  font-size: 12px;
  padding: 8px 12px;
  position: absolute;
  top: 0;
}

/* The dots/bullets/indicators */
.dot {
  cursor: pointer;
  height: 15px;
  width: 15px;
  margin: 0 2px;
  background-color: #bbb;
  border-radius: 50%;
  display: inline-block;
  transition: background-color 0.6s ease;
}

.active{
    background-color: rgb(225, 231, 240);
}

 .dot:hover {
  background-color: #717171;
}

/* Fading animation */
.fade {
  -webkit-animation-name: fade;
  -webkit-animation-duration: 1.5s;
  animation-name: fade;
  animation-duration: 1.5s;
}

a{
  color: blue;
 }

 .standardHeight{
  height:338px;
}

 .myButton {
    margin-top: 18px;
    margin-left: -25px;
    width: 105px;
}

  </style>

</head>

<body>
  <div class="row">
    <div class="container-fluid">
     <?php include("header.php");?>
    </div>
  </div>
  <div class="content-wrapper" style="margin-left:100px;">
    <!-- content-header -->
    <div class="content-header">
      <div class="container-fluid" style="margin-top: 20px;">
       
      </div>
    </div>
    <section class="content">
      <div class="container-fluid">
        <div class="row">
          <div class="col-lg-12 col-md-12">
          
            <div class="row">
         
         
         

           <table id="print_table" class="table" style="margin-right:20px;">
    <thead>
        <tr>
            <th>Date</th>
            <th>Incident</th>
            <th>Type</th>
            <th>Form</th>
            
            <th>Province</th>
            <th>District</th>
            <th>Municipality</th>
            <th>Source</th>
        </tr>
    </thead>
    <tbody>
      <?php while($row = mysqli_fetch_assoc($query)){?>
      
        <tr>
            <td><?php echo $row['date']; ?></td>
            <td><a href="<?php echo 'https://nepalmonitor.org/reports/view/'.$row['report_id'];?>" target="_blank"><?php echo $row['incident']; ?></a></td>
            <td><?php echo $row['types'];?></td>
            <td>
              <?php
                $f = $row['form'];
                $for = mysqli_query($db,"select name from forms where code = $f");
                $forms = mysqli_fetch_assoc($for);
                echo $forms['name'];
                ?>
            </td>
            <td style="text-align: center;"><?php echo $row['province']; ?></td>
            <td style="text-align: center;"><?php echo $row['district']; ?></td>
            <td style="text-align: center;"><?php 
              if($row['municipality_id'] == NULL){
                echo "Unknown";
              } else {
                $muni = $row['municipality_id'];
                $mun = mysqli_query($db,"select title from location_municipalities where id = $muni");
                $municipality = mysqli_fetch_assoc($mun);
                echo $municipality['title'];
              }
            ?></td>
            <td>
              <?php
               $rsl = $row['report_id'];
               //echo "Hello ".$row['id'];
                $muni = mysqli_query($db,"select source_link from reports_source_links where report_id = $rsl");
                $link = mysqli_fetch_assoc($muni);
                $parse = parse_url($link['source_link']);
               echo "<a href='$link[source_link]' target='_blank'>".$parse['host']."</a>";
              ?>
            </td>
        </tr>
    <?php } ?>
        
    </tbody>
</table> 
      

              


            </div>
          
          </div>

     
      
         </div>
        </div>
    </section>
     
    
  </div>

  




  <!-- Jquery JS-->
  <script src="js/jquery.min.js"></script>
  <script src="js/jquery-migrate.min.js"></script>
  <!-- Popper JS-->
  <script src="js/popper.min.js"></script>
  <!-- Bootstrap JS-->
  <script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.0/dist/umd/popper.min.js"
    integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo" crossorigin="anonymous">
  </script>
  <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js"
    integrity="sha384-wfSDF2E50Y2D1uUdj0O3uMBJnjuUD4Ih7YwaYd1iqfktj0Uod8GCExl3Og8ifwB6" crossorigin="anonymous">
  </script>
<script src="js/main.js"></script>
  <!-- Province map JS-->
  <script src="js/province.js"></script>
  <script src="js/province-select.js"></script>

  <!-- District map JS-->
  <script src="js/districts.js"></script>
  <script src="js/district-select.js"></script>

  <!-- Handle data change-->
  <script src="js/data-select.js"></script>
  <script src="js/data-select-change.js"></script>
  <script src="js/data-load.js"></script>

  <!-- Handle date picker change-->
  <script src="js/date-picker-select.js"></script>

  <!-- Toaster to show messages -->
  <script src="https://cdnjs.cloudflare.com/ajax/libs/toastr.js/latest/toastr.min.js"></script>

  <!-- chartjs -->
  <script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.9.3/Chart.min.js"></script>

  <script src='https://api.mapbox.com/mapbox-gl-js/v1.8.1/mapbox-gl.js'></script>
  <!-- Bootstrap select JS-->
  <script src="js/bootstrap-select.js"></script>

  <!-- Date range picker -->
  <script type="text/javascript" src="https://cdn.jsdelivr.net/momentjs/latest/moment.min.js"></script>
  <script type="text/javascript" src="https://cdn.jsdelivr.net/npm/daterangepicker/daterangepicker.min.js"></script>
   <script type="text/javascript" src="https://cdn.datatables.net/1.10.21/js/jquery.dataTables.min.js"></script>
   <script type="text/javascript" src=" https://cdn.datatables.net/buttons/1.6.2/js/dataTables.buttons.min.js"></script>
   <script type="text/javascript" src=" https://cdn.datatables.net/buttons/1.6.2/js/buttons.flash.min.js"></script>
   <script type="text/javascript" src=" https://cdnjs.cloudflare.com/ajax/libs/jszip/3.1.3/jszip.min.js"></script>
   <script type="text/javascript" src=" https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.53/pdfmake.min.js"></script>
   <script type="text/javascript" src=" https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.53/vfs_fonts.js"></script>
    <script type="text/javascript" src=" https://cdn.datatables.net/buttons/1.6.2/js/buttons.print.min.js"></script>
     <script type="text/javascript" src=" https://cdn.datatables.net/buttons/1.6.2/js/buttons.html5.min.js
"></script>






</body>
<script>
    $(document).ready( function () {
    $('#print_table').DataTable({
       "lengthMenu": [[50, 100, 200,-1], [50,100,200, "All"]],

       dom: 'Bfrtip',
        buttons: [
            'pageLength','copy', 'csv', 'excel', 'pdf', 'print' 
        ],
      

    });
} );
  </script>
</html>
