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

  $from_notification_status="";

  if(isset($_POST["from_notification"])){
    $from_notification_status=addslashes($_POST["from_notification"]);
  }

  //OBJECTS
  $retrieveObj=new RETRIEVE();

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

<h4 class="page-title">
	<span class="la la-cubes"></span>
	Contacts
</h4>
<div class="row">
  <div class="col-md-12" id="contact_us_details_container">
    
  </div>

	<div class="col-md-12 mb-3" id="contact_us_msgs_container">
		<p class="font-weight-bold mb-2 text-right">
			<span>
	          <a href="#!" class="text-danger font-weight-normal mx-2" onclick="contact_us_trash_view()"><span class="fas fa-trash"></span> Removed contact messages</a>
			</span>  
 		</p>
    <div id="remove_contact_us_response">
      
    </div>
 		<table class="table table-head-bg-primary mt-4" id="contact_us_table">
			<thead>
				<tr>
          <th scope="col">Fullname</th>
          <th scope="col">Email</th>
          <th scope="col">Subject</th>
          <th scope="col">Date</th>
          <th scope="col"></th>
        </tr>
			</thead>
			<tbody>
				<?php
                    
          if($get_contact_us!="1020"){
            $element_id="element_id";
              foreach ($get_contact_us as $contact_us) {
                $element_id=$element_id."Ot";
        ?>  
            <tr id="<?php echo $element_id ?>">         
              <td>
                <?php 
                  echo $contact_us->fullname;
                ?>
              </td>
              <td>
                <a href="mailto:<?php echo $contact_us->email ?>">
                  <?php 
                    echo $contact_us->email;
                  ?>
                </a>
              </td>
              <td>
                <?php 
                  echo $contact_us->subject;
                ?>
              </td>
              <td>
                <?php 
                  echo date("d-m-Y H:i:s", strtotime($contact_us->date_added));
                ?>
              </td>
              <td id="<?php echo $element_id.'Dbtn' ?>">
                  <div class="">
                    <button title="Edit" class="btn btn-success hand_cursor" onclick="contact_us_details_view(<?php echo $contact_us->c_id ?>)"><span class="fas fa-eye"></span> View </button>
                    <form id="<?php echo 'R'.$element_id.'form' ?>" class="mb-0 hand_cursor" style="display: inline;">
                        <input type="hidden" name="remove_contact_us_note" value="<?php echo $contact_us->c_id; ?>">
                        <button id="<?php echo $element_id.'Rbtn' ?>" onclick="remove_contact_us('<?php echo 'R'.$element_id.'form' ?>','<?php echo $element_id; ?>','remove_contact_us_response')" type="submit" title="Remove" class="btn btn-warning hand_cursor"><span class="fas fa-trash"></span> Remove</button>
                    </form>
                    
                  </div>       
              </td>
            </tr>
          <?php
              }
            }
          ?>
				
			</tbody>
		</table>
	</div>
</div>
<script type="text/javascript">
  var from_notification_status = <?php echo $from_notification_status; ?>;

  $(document).ready(function () {
    var table = $('#contact_us_table').DataTable({
      columnDefs: [
        {bSortable: false, targets: [4]} 
      ]
    });

    if(from_notification_status!=0){
      contact_us_details_view(from_notification_status)
    }
  })
</script>