<?php
include'../includes/connection.php';
include'../includes/sidebar.php';
  $query = 'SELECT ID, t.TYPE
            FROM users u
            JOIN type t ON t.TYPE_ID=u.TYPE_ID WHERE ID = '.$_SESSION['MEMBER_ID'].'';
  $result = mysqli_query($db, $query) or die (mysqli_error($db));
  
  while ($row = mysqli_fetch_assoc($result)) {
            $Aa = $row['TYPE'];
                   
  if ($Aa=='User'){
?>
  <script type="text/javascript">
    //then it will be redirected
    alert("Restricted Page! You will be redirected to POS");
    window.location = "pos.php";
  </script>
<?php
  }           
}
            ?>
            
   <?php
   
   $sql3 = "SELECT DISTINCT CUST_ID, COMPANY FROM customer order by CUST_ID asc";
$result3 = mysqli_query($db, $sql3) or die ("Bad SQL: $sql3");

$cust = "<select class='form-control' name='Company' required>
        <option disabled selected hidden>Select Customer</option>";
  while ($row = mysqli_fetch_assoc($result3)) {
      
    $cust .= "<option value='".$row['CUST_ID']."'>".$row['COMPANY']."</option>";
     
  }

$cust .= "</select>";
   
    $query1 = " SELECT COUNT(*) FROM Message ";
        $result1 = mysqli_query($db, $query1) or die (mysqli_error($db));
      
            while ($row = mysqli_fetch_assoc($result1)) {
                
            $Message_id=date(dmyh);
            $Date=date("d-m-y");
            }
   
            if($row[0]==0)
{
    
   echo' <div class="card shadow mb-4">
            <div class="card-header py-3">
              <h4 class="m-2 font-weight-bold text-primary">Send A Message</h4>
            </div>
            <form method="post" action="Send.php?action=add">
            <div class="card-body">
              <div class="table-responsive">
                <table style="color:black" class="table table-borderless"  width="100%" cellspacing="0"> 
               <thead>
                   <tr>
                     <th width="20%">Company</th>
                     <th width="80%">Message</th>
                     
                   </tr>
               </thead>
          <tbody>

                            <td>'.$cust.'</td>
                            <td><textarea rows="4" name="Message" class="form-control" type="text"></textarea></td>
                                    
                                </tbody>
                            </table>
                            <input value="Send" name="Send" type="Submit" class="btn btn-primary" type="text">
                            <input type="hidden" name="admin" value="'.$_SESSION['MEMBER_ID'].'">
                            <input type="hidden" name="CUST_ID" value="'.$CUSTID.'">
                            </form>
                            
                            
                        </div>
                    </div>
                  </div>  ';
} 

elseif ($itemValues!=0) {
   
}
else
{

}
          
            ?>
            
            <div class="card shadow mb-4">
            <div class="card-header py-3">
              <h4 class="m-2 font-weight-bold text-primary">Inbox</h4>
            </div>
            <div class="card-body">
              <div class="table-responsive">
                <table style="color:black" class="table table-bordered" id="dataTable" width="100%" cellspacing="0"> 
               <thead>
                   <tr>
                     <th width="20%">Sent To</th>
                     <th width="20%">Date</th>
                     <th width="10%">Action</th>
                   </tr>
               </thead>
          <tbody>


<?php       

$Year=  date(Y) ;

    $query = "SELECT MESSAGES_ID, COMPANY, Year, Date,REPLY,M_ID, MESSAGES FROM Message 
              WHERE Year=".$Year."
              ORDER BY Date ASC";
        $result = mysqli_query($db, $query) or die (mysqli_error($db));
      
            while ($row = mysqli_fetch_assoc($result)) {
                $Message_id=$row['M_ID'];
                $Message=$row['MESSAGES'];
                $Company=$row['COMPANY'];
                $you='You';
                echo '<tr>';
                echo '<td>'. $Company.'</td>';
                echo '<td>'. $row['Date'].'</td>';

                
                      echo '
                      
                      <td align="right"> <div class="btn-group">
                              <a type="button" class="