<?php
  require_once("../../session_check.php");
  require_once("../../../classes/main_classes.php");

  if(!isset($_POST["c_id"])){
    die("<p class='alert alert-warning'>Invalid request</p>");
  }

  $c_id=addslashes($_POST["c_id"]);

  //OBJECTS
  $retrieveObj=new RETRIEVE();
  $updateObj=new UPDATE();

  $get_contact_us=$retrieveObj->retriever("contact_us WHERE contact_us.c_id='$c_id' ORDER BY contact_us.c_id DESC","*","fetch");
?>


<div class="row">
  <div class="col-md-12 mb-3">
    <p><a href="#" class="bold" onclick="contact_us_view()">Contacts</a> <span class="fas fa-angle-right"></span> <a href="#" class="bold" onclick="contact_us_details_view_back()">Contact Messages</a> <span class="fas fa-angle-right"></span> Contact message details</p>
    <h6 class="text-center">Contact message details</h6>
  </div>
  <div class="col-md-12">
    <div class="card-deck">
      <div class="card mb-3 p-2">
        <table class="table borderless">
          <tr>
            <th>Fullname</th>
            <td><?php echo $get_contact_us->fullname ?></td>
          </tr>
          <tr>
            <th>Email</th>
            <td>
              <a href="mailto:<?php echo $get_contact_us->email ?>">
                <?php echo $get_contact_us->email ?>
              </a>
            </td>
          </tr>
          <tr>
            <th>Date</th>
            <td><?php echo $get_contact_us->date_added ?></td>
          </tr>
        </table>
      </div>
      <div class="card mb-3 p-2">
        <p><span class="font-weight-bold">Subject </span>: <span><?php echo $get_contact_us->subject; ?></span></p>
        <div class="border border-light p-2 bg-light" style="height: 100%;">
          <label class="font-weight-bold">Message : </label>
          <div  class="p-2">
            <?php echo $get_contact_us->message; ?>
          </div>
        </div>
      </div>
    </div>
  </div>
</div>

<?php
    //check if there is a notofication
    $get_notification=$retrieveObj->retriever("admin_notifications JOIN admin_notification_targets ON admin_notifications.an_id=admin_notification_targets.an_id","*","an_source='contact_us_message' and admin_notification_targets.ant_seen_status='0' and admin_notifications.an_source_id='$c_id' and admin_notification_targets.user_id",$user_id,"fetch");
    if($get_notification!="1020"){
      $updateObj->updater("admin_notification_targets","ant_seen_status='1'","an_id",$get_notification->an_id);
    }
  ?>

<script type="text/javascript">
$(document).ready(function () {
  refresh_notifications_count()
})
</script>
