<?php

$table_name = 'questions';
$redirection_page = "index.php?action=Assigned";
$action_name = "action=Assigned";
$type = $_REQUEST['type'];
$edit_id = $_REQUEST['edit_id'];
$delete_id = $_REQUEST['delete_id'];


// For Submitting The Form

if (isset($_POST['submit'])) {

  $field1    =  $_POST['field1'];
  $field2    =  $_POST['field2'];
  $field3    =  $_POST['field3'];
  $field4    =  $_POST['field4'];
  $field5    =  $_POST['field5'];
  $field6    =  $_POST['field6'];
  $field7    =  $_POST['field7'];
  $field8    =  $_POST['field8'];
  $field9    =  $_POST['field9'];
  $field10    =  $_POST['field10'];



    $insert_bookings = "UPDATE `$table_name` SET
        sub_admin_reply   = '" . addslashes($field1) . "',        
        sub_admin_designation   = '" . addslashes($field2) . "',
        status = 'Replied By Sub-Admin'
        where id='" . $edit_id . "'";


    $sql_insert = $dbconn->prepare($insert_bookings);
    $sql_insert->execute();


    $message = "Details successfully updated.";
    $status = "success";
    header("Location: $redirection_page&id=$edit_id");

}

// For Displaying the table

if (isset($_GET['pageno'])) {
  $pageno = $_GET['pageno'];
} else {
  $pageno = 1;
}
$no_of_records_per_page = 7;
$offset = ($pageno - 1) * $no_of_records_per_page;


$select_enquiry = "SELECT * FROM $table_name where status = 'Active' order by id desc";
$sql = $dbconn->prepare($select_enquiry);
$sql->execute();


$total_rows = $sql->fetchColumn();
$total_pages = ceil($total_rows / $no_of_records_per_page);

$select_enquiry = "SELECT * FROM $table_name where status = 'Assigned To Sub-Admin' order by id desc LIMIT $offset, $no_of_records_per_page";
$sql = $dbconn->prepare($select_enquiry);
$sql->execute();
$wlvd = $sql->fetchAll(PDO::FETCH_OBJ);


$select_bookings = "SELECT * FROM `$table_name` WHERE id = '$edit_id'";
$sql1 = $dbconn->prepare($select_bookings);
$sql1->execute();
$wlvd1 = $sql1->fetchAll(PDO::FETCH_OBJ);
foreach ($wlvd1 as $rows1);


?>

<style>
  .widthh {
    width: 22vw;
  }

  .custom {
    border: 1px soild red;
    padding: 10px;
  }
</style>


<div class="container-fluid">
  <div class="content-wrapper">
    <div class="container-fluid">
      <!-- Breadcrumb-->
      <div class="row pt-2 pb-2">
        <div class="col-sm-9">
          <h4 class="page-title"><?php echo $page_name; ?></h4>
          <ol class="breadcrumb">
            <li class="breadcrumb-item"><a href="index.php?action=Welcome">Dashboard</a></li>

            <li class="breadcrumb-item active" aria-current="page"><a href="index.php?action=<?php echo $page_name; ?>"><?php echo $page_name; ?></a></li>
          </ol>
        </div>

        <div class="col-sm-3">
          <?php include('plugins/alert.php'); ?>
          <!-- Button trigger modal -->
        </div>

      </div>
      <!-- End Breadcrumb-->
      <?php if ($type == 'Delete') {

        $delete_statement = "UPDATE `$table_name` SET
      status   = 'Inactive'
      where id='" . $delete_id . "'";


        $sql_insert = $dbconn->prepare($delete_statement);
        $sql_insert->execute();


        $message = "Details successfully updated.";
        $status = "success";
        header("Location: $redirection_page&id=$delete_id");
      } else {


        $select_bookings = "SELECT * FROM `questions` where id='$edit_id' and status = 'Assigned To Sub-admin'";
        $sql11 = $dbconn->prepare($select_bookings);
        $sql11->execute();
        $wlvd11 = $sql11->fetchAll(PDO::FETCH_OBJ);
        foreach ($wlvd11 as $rows11);
        $question_id = $rows11->id;
        $question_cus_name = $rows11->question_cus_name;
        $question_cus_name = $rows11->question_cus_name;



      ?>
      <style>
  .widthh {
    width: 22vw;
  }

  .custom {
    border: 1px soild red;
    padding: 10px;
  }

  .length {
    width: 8vw !important;

  }
  
  .design {
    display: flex;
    column-gap: 30px;
  }
</style>


        <!-- reply  -->
        <div class="container-fluid">
          <div class="row">
            <div class="card">
              <form id="formID" class="m-t-30" method="POST" action="" enctype="multipart/form-data">
              <div class="card-body">
                <div class="table-responsive">
        <div class="col-md-12">                    
                    <div class="row">
                      <div class="col-md-4 col-12">
                        <div class="form-group">
                          <label for="inputName" class="col-form-label">Customer Name</label>
                          <input type="text" id="inputName" class="form-control widthh" value="<?php echo $question_cus_name; ?>" aria-describedby="name" readonly>
                        </div>
                      </div>
                      <div class="col-md-4 col-12">
                        <div class="form-group">
                          <label for="inputName" class="col-form-label">Customer Mobile</label>
                          <input type="text" id="inputName" class="form-control widthh" value="<?= $rows11->question_cus_mobile; ?>" aria-describedby="name" readonly>
                        </div>
                      </div>

                      <div class="col-md-4 col-12">
                        <?php
                            $question_cus_name = $rows11->question_cus_name;
                            $select_user = "SELECT u.user_district FROM `questions` q
                                            INNER JOIN `users` u ON q.question_cus_name = u.user_name
                                            WHERE q.id = :edit_id AND q.status = 'Assigned To Sub-Admin'";
                            $sql_user = $dbconn->prepare($select_user);
                            $sql_user->bindParam(':edit_id', $edit_id, PDO::PARAM_INT);
                            $sql_user->execute();
                            $user_district = $sql_user->fetchColumn();
                        ?>
                        <div class="form-group">
                            <label for="inputName" class="col-form-label">Customer District</label>
                            <input type="text" id="inputName" class="form-control widthh" value="<?= $user_district; ?>" aria-describedby="name" readonly>
                        </div>
                      </div>
                    </div>

                    <div class="row">
                      <div class="col-md-4 col-12">
                        <div class="form-group">
                          <label for="inputName" class="col-form-label">Question Sub-Category</label>
                          <input type="text" id="inputName" class="form-control widthh" value="<?= $rows11->question_subcat; ?>" aria-describedby="name" readonly>
                        </div>
                      </div>
                      <div class="col-md-4 col-12">
                        <div class="form-group">
                          <label for="inputName" class="col-form-label">Question Category</label>
                          <input type="text" id="inputName" class="form-control widthh" value="<?= $rows11->question_cat; ?>" aria-describedby="name" readonly>
                        </div>
                      </div>
                      <div class="col-md-4 col-12 design">
                            <div class="form-group">
                                <label for="inputName" class="col-form-label">Age</label>
                                <input type="text" id="inputName" class="form-control" value="<?= $rows11->question_age_no; ?>" aria-describedby="name" readonly>
                            </div>
                            <div class="form-group">
                                <label for="inputName" class="col-form-label">day/month</label>
                                <input type="text" id="inputName" class="form-control" value="<?= $rows11->question_age_period; ?>" aria-describedby="name" readonly>
                            </div>
                        </div>
                    </div>

                    <div class="row">
                      <div class="col-md-12 col-12">
                        <div class="form-group">
                          <label for="inputDescription" class="col-form-label">Question Description</label>
                          <textarea class="form-control " cols="5" rows="5" style="width: 73vw;" readonly><?= $rows11->question_question_description; ?></textarea>
                        </div>
                      </div>
                    </div>

                    <style>
                      .image-section img {
                        background-image: url();
                        border: 2px solid black;
                        height: 50vh;
                        width: 800px;
                      }
                    </style>
                    <div class="row text-center d-flex justify-content-around">
                      <div class="col-md-2 image-section">
                      <a href="../mobile/Flutter/<?php echo $rows11->question_photo_1; ?>" target="_blank" title="Image 1">
                        <img src="../mobile/Flutter/<?php echo $rows11->question_photo_1; ?>" alt="" style="width: 100%; height: 100%;">
                      </div>
                      <div class="col-md-2">
                      <a href="../mobile/Flutter/<?php echo $rows11->question_photo_2; ?>" target="_blank" title="Image 2">
                        <img src="../mobile/Flutter/<?php echo $rows11->question_photo_2; ?>" alt="" style="width: 100%; height: 100%;">
                      </div>
                      <div class="col-md-2">
                        <a href="../mobile/Flutter/<?php echo $rows11->question_photo_3; ?>" target="_blank" title="Image 3">
                        <img src="../mobile/Flutter/<?php echo $rows11->question_photo_3; ?>" alt="" style="width: 100%; height: 100%;">
                      </div>
                      <div class="col-md-2">
                        <a href="../mobile/Flutter/<?php echo $rows11->question_photo_4; ?>" target="_blank" title="Image 4">
                        <img src="../mobile/Flutter/<?php echo $rows11->question_photo_4; ?>" alt="" style="width: 100%; height: 100%;">
                      </div>
                      <div class="col-md-2">
                        <a href="../mobile/Flutter/<?php echo $rows11->question_photo_5; ?>" target="_blank" title="Image 5">
                        <img src="../mobile/Flutter/<?php echo $rows11->question_photo_5; ?>" alt="" style="width: 100%; height: 100%;">
                      </div>
                    </div>

                    <div class="row">
                      <div class="col-md-12">
                        <div class="form-group">
                          <label for="inputDescription" class="col-form-label">Expert Suggestion</label>
                          <textarea class="form-control" name="field1" id="editor" style="width: 73vw;"></textarea>
                        </div>
                      </div>
                    </div>

                    <div class="row">
                      <div class="col-md-6">
                        <div class="form-group">
                          <label for="inputName" class="col-form-label"> Replied by</label>
                          <input type="text" id="inputName" class="form-control" value="<?php echo $master_user_name; ?>" aria-describedby="name" readonly>
                        </div>
                      </div>
                      <div class="col-md-6">
                        <div class="form-group">
                          <label for="inputName" class="col-form-label"> Designation</label>
                          <input type="text" id="inputName" name="field2" class="form-control" value="Sub-Admin" aria-describedby="name" readonly>
                        </div>
                      </div>
                    </div>

                    <button type="submit" name="submit" value="Submit" class="btn btn-primary btn-lg btn-block waves-effect waves-light m-1">Submit</button>

                  </form>
                </div>
              </div>
            </div>
          </div>
        </div>
        </div>
      <?php
      };
      ?>


    </div><!-- End Row-->


  </div><!--End content-wrapper-->
  </div>
  <!--Start Back To Top Button-->
  <a href="javaScript:void();" class="back-to-top"><i class="fa fa-angle-double-up"></i> </a>
  <!--End Back To Top Button-->