<?php    
include ('../includes/connection.php'); 

if (isset($_POST['change'])){  
$current_password = md5($_POST['current_password']);
$retype_password = md5($_POST['retype_password']);
$new_password =md5($_POST['new_password']); 
$password =$_POST['password'];

if ($password != $current_password)
{ 
 ?>
 <script type="text/javascript">
     alert("Password does not match with your current password");
 </script>
<?php 
}else if  ($new_password != $retype_password){
   ?>
   <script type="text/javascript">
       alert("Password does not match with your new password");
   </script>
  <?php  
}else if (($password == $current_password) && ($new_password == $retype_password)){

  $query=mysqli_query($conn,"update teacher_srms set user_password = '$new_password' where user_contact_no = '$session_id'")or die(mysqli_error());
  if($query){ 
         ?>
         <script type="text/javascript">
             alert("Your password is successfully change");
         </script>
        <?php  
      }  
      else{
        ?>  
        <script type="text/javascript">
         alert("Sorry Your password is not changed");
        </script>
        <?php
    }
}
}  


if (isset($_POST['save'])){ 
$discription = $_POST['discription']; 
$duties = $_POST['duties'];  

 $query=mysqli_query($conn,"INSERT INTO `duties`(`discription`, `duties`) VALUES ('$discription','$duties')");
      if($query){ 
         ?>
         <script type="text/javascript">
             alert("Duties Success Fully Sent");
         </script>
        <?php  
      }  
      else{
        ?>  
        <script type="text/javascript">
         alert("Sorry Duties Failed to sent Try Again");
        </script>
        <?php
    }
  } 

if(isset($_GET['del']))
{
  
$id= $_GET['del'];
$q =mysqli_query($conn,"DELETE FROM `duties` WHERE dute_id = $id ");
header('location:admin.php?page=dashboad');
}  
?>
 <div class="content-wrapper">
    <!-- Content Header (Page header) --> 
    <section class="content-header bg-info" style=" color: white;">
      <div class="container-fluid">
        <div class="row mb-2">
          <div class="col-sm-6">
            <a><strong>Administration Site</strong></a>
          </div> 
        </div>
      </div><!-- /.container-fluid -->
    </section> 
    <br>
    <section class="content">
      <div class="container-fluid">
        <?php    
            $categ="Academic Master";  
            if ($user_row['user_type']=="$categ") {
          ?> 
        <h5 class="mb-2">Users Detail</h5>
         <hr>
        <div class="row">
          <div class="col-md-8">
          <div class="row">
          <div class="col-md-6">
            <div class="info-box">
              <span class="info-box-icon bg-info"><i class="fas fa-users"></i></span>

              <div class="info-box-content">
                <span class="info-box-text">Total Student Registered</span>
                 <?php  
                  $selected = mysqli_query($conn,"SELECT count(student_id) as student  FROm  student_srms");
                  $sel = mysqli_fetch_array($selected); 
                  ?> 
                <span class="info-box-number"><?php echo $sel['student']; ?></span>
              </div>
              <!-- /.info-box-content -->
            </div>
            <!-- /.info-box -->
          </div>
          <!-- /.col -->
          <div class="col-md-6">
            <div class="info-box">
              <span class="info-box-icon bg-success"><i class="fas fa-users"></i></span>

              <div class="info-box-content">
                <span class="info-box-text">Staff Registered</span>
                <?php  
                  $tutor = mysqli_query($conn,"SELECT count(user_id) as user_name  FROm  teacher_srms WHERE teacher_roll_no LIKE 'SARMS/ST/%'");
                  $sel = mysqli_fetch_array($tutor); 
                  ?> 
                <span class="info-box-number"><?php echo $sel['user_name']; ?></span>
              </div>
              <!-- /.info-box-content -->
            </div>
            <!-- /.info-box -->
          </div>
        </div>
        <div class="row">
          <!-- /.col -->
          <div class="col-md-6">
            <div class="info-box">
              <span class="info-box-icon bg-warning"><i class="fas fa-users"></i></span>

              <div class="info-box-content">
                <span class="info-box-text">Non-staff Registered</span>
                 <?php  
                  $short = mysqli_query($conn,"SELECT count(user_id) as user_name  FROm  teacher_srms WHERE teacher_roll_no LIKE '%N-ST%'" );
                  $non = mysqli_fetch_array($short); 
                  ?> 
                <span class="info-box-number"><?php echo $non['user_name']; ?></span>
              </div>
              <!-- /.info-box-content -->
            </div>
            <!-- /.info-box -->
          </div>
          <!-- /.col -->
          <div class="col-md-6">
            <div class="info-box">
              <span class="info-box-icon bg-info"><i class="fas fa-file"></i></span>

              <div class="info-box-content">
                <span class="info-box-text">Teacher Assigned subject</span>
               <?php  
                  $sub = mysqli_query($conn,"SELECT count(teacher_exam_id) as teacher  FROm  teacher_course" );
                  $sel = mysqli_fetch_array($sub); 
                  ?> 
                   <span class="info-box-number"><?php echo $sel['teacher']; ?></span>
              </div>
              <!-- /.info-box-content -->
            </div>
            <!-- /.info-box -->
          </div>
         </div>
         <h5 class="mb-2">Examination Detail</h5>
         <hr>
         <div class="row">
          <div class="col-lg-4 col-6">
            <!-- small card -->
            <div class="small-box bg-primary">
              <div class="inner">
              <?php   
                  $selected = mysqli_query($conn,"SELECT count(marks_id) as result  FROm  marks_srms");
                  $row = mysqli_fetch_array($selected); 
                  ?>
                <h3><?php echo $row['result']; ?></h3> 
                <p>Result Uploaded</p>
              </div>
              <div class="icon">
                <i class="fas fa-graduation-cap"></i>
              </div>  
              <a href="#" class="small-box-footer">
                More info <i class="fas fa-arrow-circle-right"></i>
              </a> 
            </div>
          </div>
          <!-- ./col -->
          <div class="col-lg-4 col-6">
            <!-- small card -->
            <div class="small-box bg-info">
              <div class="inner">
                <?php  
                  $arrive = mysqli_query($conn,"SELECT count(report_id) as report  FROm  exam_report");
                  $arr = mysqli_fetch_array($arrive); 
                  ?>
                <h3><?php echo $arr['report']; ?></h3> 
                <p>Examination Uploaded</p>
              </div>
              <div class="icon">
                <i class="fas fa-edit"></i>
              </div> 
              <a href="admin.php?page=exam_time" class="small-box-footer">
                More info <i class="fas fa-arrow-circle-right"></i>
              </a> 
            </div>
          </div>
          <!-- ./col -->
          <!-- ./col -->
          <div class="col-lg-4 col-6">
            <!-- small card -->
            <div class="small-box bg-primary">
              <div class="inner">
                <?php  
                  $year=date("Y");
                  $selected = mysqli_query($conn,"SELECT count(sub_id) as sub  FROm  general_subject");
                  $sel = mysqli_fetch_array($selected); 
                  ?>
                <h3><?php echo $sel['sub']; ?></h3> 
                <p>Total Subject</p>
              </div>
              <div class="icon">
                <i class="fas fa-users"></i>
              </div> 
                <a href="admin.php?page=program" class="small-box-footer">
                More info <i class="fas fa-arrow-circle-right"></i>
              </a> 
            </div>
          </div>
          
          <!-- ./col -->
          
          <div class="col-lg-4 col-6">
            <!-- small card -->
            <div class="small-box bg-info">
              <div class="inner">
                <?php  
                  $Classes = mysqli_query($conn,"SELECT count(class_id) as Classes  FROm  class_srms");
                  $sel = mysqli_fetch_array($Classes); 
                  ?>
                <h3><?php echo $sel['Classes']; ?></h3> 
                <p>Total Classes</p>
              </div>
              <div class="icon">
                <i class="fas fa-university"></i>
              </div>  
                <a href="admin.php?page=class" class="small-box-footer">
                More info <i class="fas fa-arrow-circle-right"></i>
              </a> 
            </div>
          </div> 
          <div class="col-lg-4 col-6">
            <!-- small card -->
            <div class="small-box bg-secondary">
              <div class="inner">
                <?php  
                  $Classes = mysqli_query($conn,"SELECT count(id) as sub  FROm  subject");
                  $sel = mysqli_fetch_array($Classes); 
                  ?>
                <h3><?php echo $sel['sub']; ?></h3> 
                <p>Subject assigned</p>
              </div>
              <div class="icon">
                <i class="fas fa-university"></i>
              </div>  
                <a href="admin.php?page=program" class="small-box-footer">
                More info <i class="fas fa-arrow-circle-right"></i>
              </a> 
            </div>
          </div> 
          <div class="col-lg-4 col-6">
            <!-- small card -->
            <div class="small-box bg-info">
              <div class="inner">
                <?php  
                  $Classes = mysqli_query($conn,"SELECT count(exam_id) as exam  FROm  exam_srms");
                  $sel = mysqli_fetch_array($Classes); 
                  ?>
                <h3><?php echo $sel['exam']; ?></h3> 
                <p>Total Exam</p>
              </div>
              <div class="icon">
                <i class="fas fa-university"></i>
              </div>  
                <a href="admin.php?page=exam" class="small-box-footer">
                More info <i class="fas fa-arrow-circle-right"></i>
              </a> 
            </div>
          </div> 
        </div>
        
        </div>
          <div class="col-md-4">
            <div class="card card-primary card-outline">
              <div class="card-header">
                <h3 class="card-title">CLASS WITH THEIR CAPACITY</h3>
              </div>
              <!-- /.card-header -->
              <div class="card-body">
                <table class="table table-bordered">
                  <thead>
                    <tr>
                      <th style="width: 10px">#</th>
                      <th>CLASS NAME</th> 
                      <th>ST CAPACITY</th>
                    </tr>
                  </thead>
                  <tbody>
                     <?php  
                      $i = 1;
                      $no = mysqli_query($conn,"SELECT * FROM class_srms");
                       while($no_1 = mysqli_fetch_array($no)){ 
                       $cl_id=$no_1['class_id'] 
                      ?> 
                      <tr>
                       <td class="text-center"><?php echo $i++ ?></td>
                      <td><?php echo $no_1['class_name']; ?></td> 
                      <td><?php 
                        $count = mysqli_query($conn,"SELECT count(student_roll_no) as no_3 FROM student_srms where class_id='$cl_id'");
                        $no_2 = mysqli_fetch_array($count);
                        if($no_2['no_3'] > 0){
                        ?> 
                        <span class="badge bg-success">  
                         <?php 
                           echo $no_2['no_3'];
                          ?> 
                       </span>
                        <?php }else{?> 
                         <span class="badge bg-danger">  
                         <?php 
                           echo "--Nill--";
                          ?> 
                       </span>
                       <?php } ?> 
                    </td>
                    </tr> 
                    <?php } ?>
                  </tbody> 
                </table>
              </div> 
            </div>
          </div>
          <!-- /.col -->
        </div>
        
        
     <?php }?>
        <h5 class="mb-2">User Profile</h5>
         <hr>
        <div class="row">
          <div class="col-md-4">

            <!-- Profile Image -->

            <div class="card card-primary card-outline"> 
              <div class="card-body box-profile"> 
                <div class="text-center">
                  <img class="profile-user-img img-fluid img-circle"
                       src="../<?php echo $q['user_profile']; ?>"
                       alt="User profile picture">
                </div>

                <h3 class="profile-username text-center"><?php echo $q['user_name']; ?></h3> 

                <ul class="list-group list-group-unbordered mb-3">
                  <li class="list-group-item">
                    <b>Name</b> <a class="float-right"><?php echo $q['user_name']; ?></a>
                  </li>
                  <li class="list-group-item">
                    <b>Mobile</b> <a class="float-right"><?php echo $q['user_contact_no']; ?></a>
                  </li>
                   
                  <li class="list-group-item">
                    <b>Email</b> <a class="float-right"><?php echo $q['user_email']; ?></a>
                  </li>
                </ul>

                <a data-toggle="modal" href="#upload-picture" class="btn btn-primary btn-block"><i class="fa fa-upload"></i>  Change profile </a>
              </div>
              <!-- /.card-body -->
            </div>
            <!-- /.card -->
             <div class="modal fade" id="upload-picture">
                    <div class="modal-dialog">
                        <div class="modal-content">
                            <div class="modal-header">
                                <h4 class="modal-title">Change Your Profile Picture</h4>
                                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                            </div>
                            <div class="modal-body">
                              <form method="post" class="form-horizontal" enctype="multipart/form-data"> 
                                    <div class="col-sm-10">
                                      <input type="file" class="form-control" name="image"  id="fileInput" type="file" placeholder="Change profile picture">
                                    </div>

                                    <div class="row" style="text-align: right">
                                        <div class="col-md-12">
                                            <button type="submit" name="picture" class="btn btn-secondary btn-sm">  <i class="fa fa-upload"></i> Change</button>
                                        </div>
                                    </div>
                                </form>
                            </div>

                        </div><!-- /.modal-content -->
                    </div><!-- /.modal-dialog -->
                </div><!-- /.modal --> 
       
          </div>
          <!-- /.col -->
          <div class="col-md-8">
            <div class="card">
              <div class="card-header p-2">
                <ul class="nav nav-pills">  
                  <li class="nav-item"><a class="nav-link" href="#settings" data-toggle="tab">Change Password</a></li>
                </ul>
              </div><!-- /.card-header -->
              <div class="card-body">
                <div class="tab-content"> 
                  <div class="active tab-pane" id="settings">
                    <form method="post" action="" class="form-horizontal">
                      <div class="form-group row">
                        <input type="hidden" id="password" name="password" value="<?php echo $q['user_password']; ?>"> 
                         
                        <label for="inputName" class="col-sm-2 col-form-label">Current Password</label>
                        <div class="col-sm-10">
                          <input type="password" class="form-control" id="current_password" name="current_password"  placeholder="Current Password" required/>
                        </div>
                      </div>
                      <div class="form-group row">
                        <label for="inputName" class="col-sm-2 col-form-label">New Password </label>
                        <div class="col-sm-10">
                          <input type="password" class="form-control" id="new_password" name="new_password" placeholder="New Password">
                        </div>
                      </div> 
                      <div class="form-group row">
                        <label for="inputName" class="col-sm-2 col-form-label">Re Enter Password</label>
                        <div class="col-sm-10">
                          <input type="password" class="form-control" id="retype_password" name="retype_password" placeholder="Re-type Password" required/>
                        </div>
                      </div>  
                      <div class="form-group row">
                        <div class="offset-sm-2 col-sm-10">
                          <button type="submit" id="change_password" name="change" class="btn btn-primary">Submit</button>
                        </div>
                      </div>
                    </form>
                  </div>
                  <!-- /.tab-pane -->
                </div>
                <!-- /.tab-content -->
              </div><!-- /.card-body -->
            </div>
            <!-- /.card -->
          </div>
          <!-- /.col -->
        </div>

         <?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") {
        ?> 
         <h5 class="mb-2">Staff Duties</h5>
         <hr>
        <div class="row">
          <div class="col-12">
            <div class="card">
              <div class="card-header">
                <h3 class="card-title">List of Duties</h3>
                <a data-toggle="modal" href="#duties" class="btn btn-info btn-xs float-left ml-2" >
                    <i class="fa fa-edit"></i>  Add Duties Here
                </a>
                <div class="card-tools">
                  <div class="input-group input-group-sm" style="width: 150px;">
                    <input type="text" name="table_search" class="form-control float-right" placeholder="Search">

                    <div class="input-group-append">
                      <button type="submit" class="btn btn-default">
                        <i class="fas fa-search"></i>
                      </button>
                    </div>
                  </div>
                </div>

              </div>
              <!-- /.card-header -->
               <div class="card-body">
              <div class="card-body table-responsive p-0" style="height: 400px;">
                <table  class="table table-head-fixed text-nowrap table-bordered">
                  <thead>
                    <tr>
                      <th>ID</th>
                      <th>Discription</th>  
                      <th>Duties</th>
                      <th>Date</th>
                      <th>Status</th>
                    </tr>
                  </thead>
                  <tbody>
                  <?php  
                  $i = 1;
                  $selected1 = mysqli_query($conn,"SELECT *  FROm  duties");
                   while($com1 = mysqli_fetch_array($selected1)){ 

                  ?>
                    <tr>
                      <td><?php echo $i++ ?></td>
                      <td><?php echo $com1['discription']; ?></td> 
                      <td><?php echo $com1['date']; ?></td>
                      <td><?php echo $com1['duties']; ?></td>
                      <td> 
                        <a href="admin.php?page=dashboad&del=<?php echo $com1['dute_id']; ?>" onclick="return confirm('Are you sure you want to delete duties?');" class="btn btn-danger btn-flat delete_student">
                              <i class="fas fa-trash"></i>
                            </a>   
                          </td>
                    </tr>
                    <?php }?> 
                  </tbody>
                </table>
              </div>
               </div>
              <!-- /.card-body -->
            </div>
            <!-- /.card -->
          </div>
        </div>
        <h5 class="mb-2">Comments</h5>
         <hr>
         <div class="row">
          <div class="col-12">
            <div class="card">
              <div class="card-header">
                <h3 class="card-title">List of Comments</h3> 
                <div class="card-tools">
                 <div class="input-group input-group-sm" style="width: 150px;">
                    <input type="text" name="table_search" class="form-control float-right" placeholder="Search">

                    <div class="input-group-append">
                      <button type="submit" class="btn btn-default">
                        <i class="fas fa-search"></i>
                      </button>
                    </div>
                  </div>
                </div>

              </div>
              <!-- /.card-header -->
              <div class="card-body">
              <div class="card-body table-responsive p-0" style="height: 200px;">
                <table  class="table table-head-fixed text-nowrap">
                  <thead>
                    <tr>
                      <th>ID</th>
                      <th>Name of Sender</th> 
                      <th>Date</th>
                      <th>comments</th>
                      <th>Status</th>
                    </tr>
                  </thead>
                  <tbody>
                    <?php  
                            $selected = mysqli_query($conn,"SELECT *  FROm  comment");
                             while($com = mysqli_fetch_array($selected)){ 
                        
                            ?>
                      <tr>
                      <td ><?php echo $com['a_id']; ?></td>
                      <td><?php echo $com['name']; ?></td> 
                      <td><?php echo $com['date']; ?></td>
                      <td><?php echo $com['comment']; ?></td>
                      <td> 
                        <a href="delete_comment.php?del=<?php echo $com['a_id']; ?>" onclick="return confirm('Are you sure you want to delete comment?');" class="btn btn-danger btn-flat delete_student">
                              <i class="fas fa-trash"></i>
                            </a>   
                          </td>
                    </tr>
                    <?php }?> 
                  </tbody>
                </table>
              </div>
            </div>
              <!-- /.card-body -->
            </div>
            <!-- /.card -->
          </div>
        </div>
      <?php }?>
       <div class="modal fade" id="duties">
        <div class="modal-dialog modal-lg">
          <div class="modal-content">
            <div class="modal-header">
              <h4 class="modal-title">Staff Duties and Information</h4>
              <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                <span aria-hidden="true">&times;</span>
              </button>
            </div>
           
              <form method="post" action="" enctype="multipart/form-data"> 
                 <div class="modal-body">
                <div class="modal-body">
                  <span id="form_message"></span>  
                    <div class="form-group">
                       <label>Tittle Discription<span style="color: red;">*</span></label> 
                       <input type="text" name="discription" class="form-control select2" placeholder="Please Enter a Title Eg: Staff Timetable" required> 
                      </div>
                      <div class="form-group">
                       <label>Duties Description <span style="color: red;">*</span></label> 
                            <textarea id="summernote" name="duties" class="form-control select2">
                              Place <em>some</em> <u>text</u> <strong>here</strong>
                            </textarea> 
                      </div> 
                    </div>  
                </div>
              <div class="modal-footer justify-content-between">
              <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
              <button type="submit"  name="save" class="btn btn-primary">Save</button>
            </div>
            </form>
          </div>
          <!-- /.modal-content -->
        </div>
        <!-- /.modal-dialog -->
      </div>
        <!-- /.row --> 
      </div><!-- /.container-fluid --> 

    </section>
    <!-- /.content -->
  </div>
  <!-- jQuery -->
 <!-- jQuery -->
<script src="../stp_con/jquery/jquery.min.js"></script>
<!-- Bootstrap 4 -->
<script src="../stp_con/bootstrap/js/bootstrap.bundle.min.js"></script>
<!-- DataTables  & Plugins -->
<script src="../stp_con/datatables/jquery.dataTables.min.js"></script>
<script src="../stp_con/datatables-bs4/js/dataTables.bootstrap4.min.js"></script>
<script src="../stp_con/datatables-responsive/js/dataTables.responsive.min.js"></script>
<script src="../stp_con/datatables-responsive/js/responsive.bootstrap4.min.js"></script>
<script src="../stp_con/datatables-buttons/js/dataTables.buttons.min.js"></script>
<script src="../stp_con/datatables-buttons/js/buttons.bootstrap4.min.js"></script>
<script src="../stp_con/jszip/jszip.min.js"></script>
<script src="../stp_con/pdfmake/pdfmake.min.js"></script>
<script src="../stp_con/pdfmake/vfs_fonts.js"></script>  
<script src="../stp_con/datatables-buttons/js/buttons.html5.min.js"></script>
<script src="../stp_con/datatables-buttons/js/buttons.print.min.js"></script>
<script src="../stp_con/datatables-buttons/js/buttons.colVis.min.js"></script>
<script src="../stp_con/summernote/summernote-bs4.min.js"></script>  
<script src="../assets/js/adminlte.min.js"></script>
</body>
</html> 
 <?php 
          $row = mysqli_fetch_array($query);  
          if (isset($_POST['picture'])){   

          $image = addslashes(file_get_contents($_FILES['image']['tmp_name']));
          $image_name = addslashes($_FILES['image']['name']);
          $image_size = getimagesize($_FILES['image']['tmp_name']);

          move_uploaded_file($_FILES["image"]["tmp_name"], "../assets/img/" . $_FILES["image"]["name"]);
          $adminthumbnails = "assets/img/" . $_FILES["image"]["name"];
                
                mysqli_query($conn,"update teacher_srms set user_profile = '$adminthumbnails' where user_contact_no = '$session_id'")or die(mysqli_error());

          mysqli_query($conn,"UPDATE teacher_srms SET  user_profile='$adminthumbnails' where user_contact_no = '$session_id'") 
          or die(mysqli_error()); 
          ?>
          <script type="text/javascript">
             alert("Your profile is successfully change");
         </script>
          <?php
        }
     ?>
<script>
  $(function () {
    // Summernote
    $('#summernote').summernote()

    // CodeMirror
    CodeMirror.fromTextArea(document.getElementById("codeMirrorDemo"), {
      mode: "htmlmixed",
      theme: "monokai"
    });
  })
</script>
 <script defer async>
  document.addEventListener('DOMContentLoaded', function() {
    // setting global variables
    window.botId = 3207
    
    // create div with id = sarufi-chatbox
    const div = document.createElement("div")
    div.id = "sarufi-chatbox"
    document.body.appendChild(div)

    // create and attach script tag
    const script = document.createElement("script")
    script.crossOrigin = true
    script.type = "module"
    script.src = "https://cdn.jsdelivr.net/gh/flexcodelabs/sarufi-chatbox/example/vanilla-js/script.js"
    document.head.appendChild(script)

    // create and attach css
    const style = document.createElement("link")
    style.crossOrigin = true
    style.rel = "stylesheet"
    style.href = "https://cdn.jsdelivr.net/gh/flexcodelabs/sarufi-chatbox/example/vanilla-js/style.css"
    document.head.appendChild(style)
  });
</script>