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

  //OBJECTS
  $retrieveObj=new RETRIEVE();

  $get_notifications=$retrieveObj->retriever("admin_notifications JOIN admin_notification_targets ON admin_notifications.an_id=admin_notification_targets.an_id WHERE admin_notification_targets.user_id='$user_id' ORDER BY admin_notifications.an_id DESC","*","fetchAll");
?>
<h4 class="page-title">
	<span class="fas fa-bell"></span>
	Notifications
</h4>
<div class="row">
	<div class="col-md-12 mb-3">
		<table class="table table-head-bg-primary mt-4 table-hover" id="notifications_table">
          	<thead>
	            <tr>
	              <th>Notification Source</th>
	              <th>Message</th>
	              <th>Date</th>
	              <th></th>
	            </tr>
      		</thead>
      		<tbody>
      			<?php
              $element_id="REI";
              $checkboxStatus="";
              $onclick_event_function="";
              if($get_notifications!="1020"){
                foreach ($get_notifications as $notification) {
                  $element_id=$element_id."I";

                    /*$cn_source_id=$notification->cn_source_id;
                    if($notification->cn_source=="meeting"){
                        $notification_icon_properties="fas fa-calendar bg-primary text-light";
                        $onclick_event_function=" meeting_details_view($cn_source_id) ";
                    }else if($notification->cn_source=="project"){
                        $notification_icon_properties="fas fa-tasks bg-info text-light";
                        $onclick_event_function=" project_details_view($cn_source_id) ";
                    }else if($notification->cn_source=="quotation"){
                        $notification_icon_properties="fas fa-file-alt bg-success text-light";
                        $onclick_event_function=" quotation_details_view($cn_source_id) ";
                    }else if($notification->cn_source=="invoice"){
                        $notification_icon_properties="fas fa-file bg-danger text-light";
                        $onclick_event_function=" invoice_details_view($cn_source_id) ";
                    }*/

                    $an_source_id=$notification->an_source_id;
                    if($notification->an_source=="blog_comment"){
                       
                        $notification_icon_properties="text-light bg-primary fas fa-blog ";
                        $onclick_event_function=" blog_post_comment_reply_view($an_source_id) ";
                    }else if($notification->an_source=="blog_reply"){
                        
                        $notification_icon_properties="text-light bg-primary fas fa-blog ";
                        $onclick_event_function=" blog_post_comment_reply_view($an_source_id) ";
                    }else if($notification->an_source=="contact_us_message"){
                       
                        $notification_icon_properties="text-light bg-success fas fa-envelope";
                        $onclick_event_function=" not_contact_us_details_view($an_source_id) ";
                    }
              ?>
                <tr class="" >
                  <td class="text-capitalize"><span class="p-2 rounded-circle m-2 <?php echo $notification_icon_properties; ?>"></span> <?php echo str_replace("_", " ", $notification->an_source);  ?></td>
                  <td><?php echo $notification->an_message;  ?></td>
                  <td><?php echo date("d-m-Y H:i:s", strtotime($notification->an_date_time));  ?></td>
                  <!--td></td-->
                  <td class="d-sm-flex align-items-center justify-content-between mb-4" id="<?php echo $element_id ?>">
                    <a title="Details" href="#!" class="btn btn-sm btn-info" onclick="<?php echo $onclick_event_function ?>"> 
                      <span class="fa fa-eye"></span>
                      View
                    </a>
                  </td>
                </tr>
              <?php
                }
              } 
            ?>
		  	  </tbody>
        </table>
	</div>
</div>

<script type="text/javascript">
  $(document).ready(function () {
    var table = $('#notifications_table').DataTable({
      columnDefs: [
        {bSortable: false, targets: [3]} 
      ]
    });
    set_all_notifications_to_seen()
  })
</script>