<?php    
include('connection.php');
if (isset($_POST['comment_n'])){ 
$name = $_POST['name']; 
$mobile = $_POST['mobile'];
$roll_number = $_POST['roll_number'];
$comment = $_POST['comment'];  
$thumbnail = $_POST['thumbnail'];
$role = $_POST['role'];
$date=date("d/m/Y");
$assessor=mysqli_query($conn,"INSERT INTO `comment`(  `name`,`roll_number`, `mobile`,  `comment`, `role`,`thumbnail`,`time`) VALUES('$name','$roll_number','$mobile','$comment','$role','$thumbnail','$date')");
  
  if($assessor){ 
         ?>
         <script type="text/javascript">
             alert("Comment Success Fully Sent");
         </script>
        <?php  
      }  
      else{
        ?>  
        <script type="text/javascript">
         alert("Sorry Comment Failed to sent Try Again");
        </script>
        <?php
    }
  } 
?> 
<?php  
 $query= mysqli_query($conn,"select * from teacher_srms where user_contact_no = '$session_id'")or die(mysqli_error());
 $row = mysqli_fetch_array($query);     
 ?>
 <!-- Navbar -->
  <nav class="main-header navbar navbar-expand navbar-white fixed-top navbar-light">
    <!-- Left navbar links -->
    <ul class="navbar-nav">
      <li class="nav-item">
        <a class="nav-link" data-widget="pushmenu" href="#" role="button"><i class="fas fa-bars"></i></a>
      </li> 
       <li class="nav-item d-none d-sm-inline-block">
        <a href="#" class="nav-link"><i class="fa fa-user"></i> Welcome | <?php echo $row['user_name'];  ?>  As <b style="color: red;"><?php echo $row['user_type'] ?></b></a> 
      </li>
    </ul>
     <?php   
      $count= mysqli_query($conn,"SELECT count(comment) as number1 FROM `comment` WHERE role='Academic Master'")or die(mysqli_error());    
      $count = mysqli_fetch_array($count);?>
    <!-- Right navbar links -->
    <ul class="navbar-nav ml-auto"> 
       <li class="nav-item dropdown">
        <a class="nav-link" data-toggle="dropdown" href="#"> 
          <i class="far fa-comments"></i>
          <span class="badge badge-danger navbar-badge"><?php echo $count['number1'] ?></span>
        </a> 
        <div class="dropdown-menu dropdown-menu-lg dropdown-menu-right">
          <?php   
          $query1= mysqli_query($conn,"SELECT * FROM `comment` WHERE role='Academic Master'")or die(mysqli_error());    
           while($coll1 = mysqli_fetch_array($query1)){ ?>
          <a href="#" class="dropdown-item">
            <!-- Message Start -->
            <div class="media"> 
              <img src="../<?php echo $coll1['thumbnail'] ?>" alt="User Avatar" class="img-size-50 mr-3 img-circle">
              <div class="media-body">
                <h3 class="dropdown-item-title">
                  <?php echo $coll1['name'];  ?>
                  <div class="dropdown-divider"></div>
                  <span class="float-right text-sm text-danger"><i class="fas fa-star"></i></span>
                </h3>
                <p class="text-sm"><?php echo $coll1['comment'] ?></p>
                <p class="text-sm text-muted"><i class="far fa-clock mr-1"></i><?php echo $coll1['date'] ?></p>
              </div>
            </div>
            <!-- Message End -->
          </a>
          <div class="dropdown-divider"></div> 
          <?php }?>  
        </div>
      
      </li> 
      <?php 
          include('includes/connection.php');
          $query= mysqli_query($conn,"select * from teacher_srms where user_contact_no = '$session_id' and user_status='Enable'")or die(mysqli_error());
          $q = mysqli_fetch_array($query); 
          $categ="Academic Master";
          if ($q['user_type']=="$categ") {
        ?>   
       <li class="nav-item">
        <a class="nav-link"  data-toggle="modal" href="#comment" role="button"> 
          <span class="badge badge-danger">Comment</span>
        </a>
      </li> 
       <?php }?> 
      <li class="nav-item">
        <a class="nav-link" data-widget="fullscreen" href="#" role="button">
          <i class="fas fa-expand-arrows-alt"></i> 
        </a>
      </li>
      <li class="nav-item">  
      <li><a class="nav-link" href="../logout.php" role="button"><i class="fa fa-sign-out-alt"></i> Logout</a></li> 
    </ul>
  </nav>
  <br><br> 
  <!-- /.navbar -->
    <!-- /.navbar -->
   <div class="modal fade" id="comment">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <h4 class="modal-title">Send a comment to respective student</h4>
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                </div> 
                <div class="modal-body">  
                  <form action="" method="post"> 
                        <input type="hidden" name="name" value="<?php echo $row['user_name'];  ?>"> 
                         <input type="hidden" name="thumbnail" value="<?php echo $row['user_profile'] ?>"> 
                        <input type="hidden" name="mobile" value="<?php echo $row['user_contact_no'] ?>"> 
                        <input type="hidden" name="role" value="<?php echo $row['user_type'] ?>">  
                        <input type="hidden" name="roll_number" value="<?php echo $row['teacher_roll_no'] ?>">
                        <label for="fa-comment" class="form-label">Comment Here <span style="color: red;">*</span></label>
                        <textarea name="comment" required="required"  class="form-control" placeholder="Enter Your Comment Here"></textarea> <br> 
                        <div class="row" style="text-align: right">
                            <div class="col-md-12"> 
                                <button type="submit" name="comment_n" class="btn btn-secondary btn-sm">  <i class="fa fa far fa-envelope"></i> Send</button>
                            </div>
                        </div>
                    </form>
                </div> 
            </div><!-- /.modal-content -->
        </div><!-- /.modal-dialog -->
    </div><!-- /.modal -->
    