<?php
    include '../connection.php';
    session_start();
    $user=$_SESSION['user'];
    if (!isset($user)) {
        header('location:../officer-login.php');
        die();
    }
    $current_date = date("Y-m-d")

?>
<?php
    $g_id=$_GET['gr_id'];
    $grievance="SELECT * FROM grievence_from";
    $gr_query=mysqli_query($con,$grievance);
    while ($row=mysqli_fetch_assoc($gr_query)) {
      $grievance_id=$row['grievance_id'];
      $_SESSION['gr_id']=$grievance_id;
      $mobile=$row['mobile'];
      $alternate_mobile=$row['alternate_mobile'];
      $first_name=$row['first_name'];
      $middle_name=$row['middle_name'];
      $last_name=$row['last_name'];
      $guardian_name=$row['guardian_name'];
      $email=$row['email'];
      $gender=$row['gender'];
      $aadhar=$row['aadhar'];
      $district=$row['district'];
      $occupation=$row['occupation'];
      $area=$row['area'];
      $muncipility=$row['muncipility'];
      $block=$row['block'];
      $panchayat=$row['panchayat'];
      $village=$row['village'];
      $ward=$row['ward'];
      $landmark=$row['landmark'];
      $police_station=$row['police_station'];
      $vidhan_sabha=$row['vidhan_sabha'];
      $lok_sabha=$row['lok_sabha'];
      $complain_mode=$row['complain_mode'];
      $call_nature=$row['call_nature'];
      $c_area=$row['c_area'];
      $c_muncipility=$row['c_muncipility'];
      $c_block=$row['c_block'];
      $c_panchayat=$row['c_panchayat'];
      $c_village=$row['c_village'];
      $c_ward=$row['c_ward'];
      $c_landmark=$row['c_landmark'];
      $description=$row['description'];
      $reg_date=$row['reg_date'];

    }
?>
<!doctype html>
<html lang="en">
  <head>
    <!-- Required meta tags -->
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>जिला लोक शिकायत केंद्र</title>
    <!-- Bootstrap CSS -->
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
  <link href="https://fonts.googleapis.com/css2?family=Material+Icons" rel="stylesheet">
  <style type="text/css">
  body{
    background: #CBDFE5;
  }
  #noder-topbar{
    background: #27AFD4;
  }
  #noder-topbar div img{
    width: 100%;
    height: auto;
  }
  #noder-topbar .users span{
    color: #fff;
  }
  </style>
</head>
<body>
  <section id="noder-topbar">
    <div class="container-fluid">
      <div class="row">
       <div class="col-md-10">
         <div>
          <img src="topbar.jpg">
        </div>
       </div> 
       <div class="col-md-2">
         <div class="users">
          <span><b><?php echo $user ?></b></span>
        </div>
        <div class="text-warning">
          <b>Allocator (L-2)</b>
        </div>
       </div>
      </div>
    </div>
  </section>
<!-------------Grievance Form----------->
<div class="container col-lg-8 m-auto">
  <div class="row">
    <div class="col-md-12"><h3 class="text-center mt-5 mb-3">Grievance Registration Form</h3></div>
    <div class="col-md-6 col-lg-6 col-12 col-sm-12">
      <span>Mode of Complaint</span>
      <input type="text" name="" value="<?php echo $complain_mode; ?>" class="form-control" readonly="">
    </div>
    <div class="col-md-6 col-lg-6 col-12 col-sm-12">
      <span>Nature of Call</span>
      <input type="text" name="" value="<?php echo $call_nature; ?>" class="form-control" readonly="">
    </div>
    <div class="col-md-12 col-lg-12 col-sm-12 col-12">
      <h4 class="text-danger">Complainant Information:</h4>
    </div>
    <div class="col-md-6 col-lg-6 col-12 col-sm-12">
      <span>Mobile Number</span>
      <input type="text" name="" value="<?php echo $mobile; ?>" class="form-control" readonly="">
    </div>
    <div class="col-md-6 col-lg-6 col-12 col-sm-12">
      <span>Alternate Mobile Number</span>
      <input type="text" name="" value="<?php echo $alternate_mobile; ?>" class="form-control" readonly="">
    </div>
    <div class="col-md-4 col-lg-4 col-12 col-sm-12">
      <span>First Name</span>
      <input type="text" name="" value="<?php echo $first_name; ?>" class="form-control" readonly="">
    </div>
    <div class="col-md-4 col-lg-4 col-12 col-sm-12">
      <span>Middle Name</span>
      <input type="text" name="" value="<?php echo $middle_name; ?>" class="form-control" readonly="">
    </div>
    <div class="col-md-4 col-lg-4 col-12 col-sm-12">
      <span>Last Name</span>
      <input type="text" name="" value="<?php echo $last_name; ?>" class="form-control" readonly="">
    </div>
    <div class="col-md-6 col-lg-6 col-12 col-sm-12">
      <span>Guardian name</span>
      <input type="text" name="" value="<?php echo $guardian_name; ?>" class="form-control" readonly="">
    </div>
    <div class="col-md-6 col-lg-6 col-12 col-sm-12">
      <span>Email</span>
      <input type="text" name="" value="<?php echo $email; ?>" class="form-control" readonly="">
    </div>
    <div class="col-md-6 col-lg-6 col-12 col-sm-12">
      <span>Gender</span>
      <input type="text" name="" value="<?php echo $gender; ?>" class="form-control" readonly="">
    </div>
    <div class="col-md-6 col-lg-6 col-12 col-sm-12">
      <span>Aadhar</span>
      <input type="text" name="" value="<?php echo $aadhar; ?>" class="form-control" readonly="">
    </div>
    <div class="col-md-6 col-lg-6 col-12 col-sm-12">
      <span>District</span>
      <input type="text" name="" value="<?php echo $district; ?>" class="form-control" readonly="">
    </div>
    <div class="col-md-6 col-lg-6 col-12 col-sm-12">
      <span>Occupation</span>
      <input type="text" name="" value="<?php echo $occupation; ?>" class="form-control" readonly="">
    </div>
    <div class="col-md-6 col-lg-6 col-12 col-sm-12">
      <span>Area</span>
      <input type="text" name="" value="<?php echo $area; ?>" class="form-control" readonly="">
    </div>
    <div class="col-md-6 col-lg-6 col-12 col-sm-12">
      <span>Municipility</span>
      <input type="text" name="" value="<?php echo $muncipility; ?>" class="form-control" readonly="">
    </div>
    <div class="col-md-6 col-lg-6 col-12 col-sm-12">
      <span>Block</span>
      <input type="text" name="" value="<?php echo $block; ?>" class="form-control" readonly="">
    </div>
    <div class="col-md-6 col-lg-6 col-12 col-sm-12">
      <span>Panchayat</span>
      <input type="text" name="" value="<?php echo $panchayat; ?>" class="form-control" readonly="">
    </div>
    <div class="col-md-6 col-lg-6 col-12 col-sm-12">
      <span>Village</span>
      <input type="text" name="" value="<?php echo $village; ?>" class="form-control" readonly="">
    </div>
    <div class="col-md-6 col-lg-6 col-12 col-sm-12">
      <span>Ward</span>
      <input type="text" name="" value="<?php echo $ward; ?>" class="form-control" readonly="">
    </div>
    <div class="col-md-6 col-lg-6 col-12 col-sm-12">
      <span>Landmark</span>
      <input type="text" name="" value="<?php echo $landmark; ?>" class="form-control" readonly="">
    </div>
    <div class="col-md-6 col-lg-6 col-12 col-sm-12">
      <span>Police Station</span>
      <input type="text" name="" value="<?php echo $police_station; ?>" class="form-control" readonly="">
    </div>
    <div class="col-md-6 col-lg-6 col-12 col-sm-12">
      <span>Vidhan Sabha</span>
      <input type="text" name="" value="<?php echo $vidhan_sabha; ?>" class="form-control" readonly="">
    </div>
    <div class="col-md-6 col-lg-6 col-12 col-sm-12">
      <span>Lok Sabha</span>
      <input type="text" name="" value="<?php echo $lok_sabha; ?>" class="form-control" readonly="">
    </div>
    <div class="col-md-6 col-lg-6 col-12 col-sm-12">
      <h4 class="text-danger">Complain Location</h4>
    </div>
    <div class="col-md-12 col-lg-12 col-12 col-sm-12">
      <span>Area</span>
      <input type="text" name="" value="<?php echo $c_area; ?>" class="form-control" readonly="">
    </div>
    <div class="col-md-6 col-lg-6 col-12 col-sm-12">
      <span>Municipility</span>
      <input type="text" name="" value="<?php echo $c_muncipility; ?>" class="form-control" readonly="">
    </div>
    <div class="col-md-6 col-lg-6 col-12 col-sm-12">
      <span>Block</span>
      <input type="text" name="" value="<?php echo $c_block; ?>" class="form-control" readonly="">
    </div>
    <div class="col-md-6 col-lg-6 col-12 col-sm-12">
      <span>Panchayat</span>
      <input type="text" name="" value="<?php echo $c_panchayat; ?>" class="form-control" readonly="">
    </div>
    <div class="col-md-6 col-lg-6 col-12 col-sm-12">
      <span>Village</span>
      <input type="text" name="" value="<?php echo $c_panchayat; ?>" class="form-control" readonly="">
    </div>
    <div class="col-md-6 col-lg-6 col-12 col-sm-12">
      <span>Ward</span>
      <input type="text" name="" value="<?php echo $c_ward; ?>" class="form-control" readonly="">
    </div>
    <div class="col-md-6 col-lg-6 col-12 col-sm-12">
      <span>Landmark</span>
      <input type="text" name="" value="<?php echo $c_ward; ?>" class="form-control" readonly="">
    </div>
    <div class="col-md-12 col-lg-12 col-12 col-sm-12">
      <span>Comment/Message</span>
      <textarea class="form-control" placeholder="<?php echo $description; ?>" readonly=""></textarea>
    </div>
    <div class="col-md-12 col-lg-12 col-12 col-sm-12">
      <hr>
    </div>
  </div>

<form method="post">
  <div class="row"> 
     <div class="col-md-6 col-lg-6 col-12 col-sm-12">
      <span>Complaint Priority</span>
      <select class="form-control" id="f1" name="f1">
        <option value=""></option>
        <option value="Emergency">Emergency</option>
        <option value="Urgent">Urgent</option>
        <option value="Moderate">Moderate</option>
      </select>
      <span class="text-danger" id="f1-error"></span>
    </div>
     <div class="col-md-6 col-lg-6 col-12 col-sm-12">
      <span>Class Of Grievance</span>
      <select class="form-control" id="f2" name="f2">
        <option></option>
        <option value="Individual">Individual</option>
        <option value="Common/Public interest">Common/Public interest</option>
        <option value="Institutional">Institutional</option>
      </select>
    </div>
    <div class="col-md-6 col-lg-6 col-12 col-sm-12">
      <span>Complainant Category</span>
      <select class="form-control" id="f3" name="f3">
        <option value=""></option>
        <?php
          $display="SELECT * FROM complaint_category";
          $query=mysqli_query($con,$display);
          while ($row=mysqli_fetch_assoc($query)) {
        ?>
          <option value="<?php echo $row['name']; ?>"><?php echo $row['name']; ?></option>

        <?php
          }
        ?>
      </select>
    </div>
     <div class="col-md-6 col-lg-6 col-12 col-sm-12">
      <span>Department</span>
      <select class="form-control" id="f4" name="f4">
        <option></option>
        <?php
          $display="SELECT * FROM grievance_department";
          $query=mysqli_query($con,$display);
          while ($row=mysqli_fetch_assoc($query)) {
        ?>
          <option value="<?php echo $row['name']; ?>"><?php echo $row['name']; ?></option>

        <?php
          }
        ?>
      </select>
    </div>
    <div class="col-md-6 col-lg-6 col-12 col-sm-12">
      <span>Grievance Category</span>
      <select class="form-control" id="f5" name="f5">
        <option></option>
        <?php
          $display="SELECT * FROM grievance_category";
          $query=mysqli_query($con,$display);
          while ($row=mysqli_fetch_assoc($query)) {
        ?>
          <option value="<?php echo $row['name']; ?>"><?php echo $row['name']; ?></option>

        <?php
          }
        ?>
      </select>
    </div>
    <div class="col-md-6 col-lg-6 col-12 col-sm-12">
      <span>Grievance Sub Category</span>
      <select class="form-control" id="f6" name="f6">
        <option></option>
        <option value="Administrative">cat1</option>
        <option value="Corruption">Cat2</option>
        <option value="Agriculture">Cat3</option>
      </select>
    </div>
    <div class="col-md-12 col-lg-12 col-12 col-sm-12">
      <hr>
    </div>
    <div class="col-md-6 col-lg-6 col-12 col-sm-12">
      <span>Action</span>
      <select class="form-control" id="f7" name="f7">
        <option></option>
        <?php
          $display="SELECT * FROM grievance_action";
          $query=mysqli_query($con,$display);
          while ($row=mysqli_fetch_assoc($query)) {
        ?>
          <option value="<?php echo $row['action_type']; ?>"><?php echo $row['action_type']; ?></option>

        <?php
          }
        ?>
      </select>
    </div>
    <div class="col-md-6 col-lg-6 col-12 col-sm-12">
      <span>Select Officers/Desposed Type</span>
      <select class="form-control" id="f8" name="f8">
        <option></option>
      </select>
    </div>
    
    <div class="col-md-6 col-lg-6 col-12 col-sm-12">
      <span>Forward Officers</span>
      <select class="form-control" id="f9" name="f9">
        <option></option>
      </select>
    </div>

    <div class="col-md-12 col-lg-12 col-12 col-sm-12">
      <span>Remark</span>
      <textarea class="form-control" id="f10" name="f10"></textarea>
    </div>
    <div class="col-md-6 col-lg-6 col-12 col-sm-12 mb-5">
      <input type="submit" name="gr_forword" id="gr_forword" class="form-control btn btn-success mt-3">
    </div>
    <div class="col-md-6 col-lg-6 col-12 col-sm-12 mb-5">
      <button type="button" class="form-control btn-danger mt-3"><a href="index.php" class="text-white">Cancle</a></button>
    </div>
  </div>
  </form>
</div>

</body>

  <!-- Option 1: Bootstrap Bundle with Popper -->
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js"></script>

    <!-- Option 2: Separate Popper and Bootstrap JS -->
    <script src="https://cdn.jsdelivr.net/npm/@popperjs/core@2.10.2/dist/umd/popper.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.min.js"></script>
     <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.0/jquery.min.js" ></script>
    <script type="text/javascript">
      $('#f7').on('change',function(){
        var action_id = this.value;
        // console.log(services_id);
          $.ajax({
            url: 'load-officers.php',
            type: 'post',
            data: { action_id:action_id },
            success: function(data){
              $('#f8').html(data);
              // console.log(data);
            }
          });
        if (action_id=="Disposed") {
            $('#f9').attr('disabled','disabled');
            $('#f9').val('');
        }
        else if (action_id=="Forward") {
            $('#f9').removeAttr('disabled');
        }
        else{
           $('#f9').removeAttr('disabled');
           $('#f10').removeAttr('disabled');
        }

      });
       $('#f8').on('change',function(){
        var action_type = this.value;
        // console.log(services_id);
          $.ajax({
            url: 'load-forwardofficers.php',
            type: 'post',
            data: { action_id:action_type },
            success: function(data){
              $('#f9').html(data);
              // console.log(data);
            }
          });
        });
       $(document).ready(function(){
        $('#gr_forword').click(function(e){
          e.preventDefault();
          $('#f10').html("");
          if ($('#f10').val()=='') {
            alert('Field Required');
            $('#f10').focus();
            return false;
          }
          else{
            $.ajax({
                url:'update_grievance.php',
                method:'post',
                data:$('form').serialize(),
                dataType:"text",
                success:function(strMessage){
                  alert(strMessage);
              }
            });
          }
        })
       })
    </script>
  </body>
</html>