 <?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
    }
}
} 

$query= mysqli_query($conn,"select * from teacher_srms,class_srms where class_srms.class_id=teacher_srms.class_id AND user_contact_no = '$session_id'")or die(mysqli_error());
$q = mysqli_fetch_array($query); 
?>
  <!-- Content Wrapper. Contains page content -->
  <div class="content-wrapper">
    <!-- Content Header (Page header) -->
    <section class="content-header bg-info">
      <div class="container-fluid">
        <div class="row mb-2">
          <div class="col-sm-6">
            <h1>Profile</h1>
          </div> 
        </div>
      </div><!-- /.container-fluid -->
    </section>

    <!-- Main content -->
    <br><br>
    <section class="content">
      <div class="container-fluid">
        <div class="row">
          <div class="col-lg-3 col-6">
            <!-- small card -->
            <div class="small-box bg-info">
              <div class="inner">
                <h3>150</h3>

                <p>Current Result Uploaded</p>
              </div>
              <div class="icon">
                <i class="fas fa-tachometer-alt"></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-3 col-6">
            <!-- small card -->
            <div class="small-box bg-success">
              <div class="inner">
                <h3>53<sup style="font-size: 20px">%</sup></h3>

                <p>Overall Task</p>
              </div>
              <div class="icon">
                <i class="fas fa-chart-pie"></i>
              </div>
              <a href="admin.php?page=crsheet&Id_2=<?php echo $q['teacher_roll_no']; ?>" class="small-box-footer">
                More info <i class="fas fa-arrow-circle-right"></i>
              </a>
            </div>
          </div>
          <!-- ./col -->
          <div class="col-lg-3 col-6">
            <!-- small card -->
            <div class="small-box bg-warning">
              <div class="inner">
                <h3>44</h3>

                <p>Subject Allocated</p>
              </div>
              <div class="icon">
                <i class="fas fa-file"></i>
              </div>
              <a href="admin.php?page=t_allocation&Id_2=<?php echo $q['user_id']; ?>" class="small-box-footer">
                More info <i class="fas fa-arrow-circle-right"></i>
              </a>
            </div>
          </div>
          <!-- ./col -->
          <div class="col-lg-3 col-6">
            <!-- small card -->
            <div class="small-box bg-info">
              <div class="inner">
                <h3>65</h3>

                <p>Student's Allocated</p>
              </div>
              <div class="icon">
                <i class="fas fa-user-plus"></i>
              </div>
              <a href="admin.php?page=student_list&Id_2=<?php echo $q['teacher_roll_no']; ?>" class="small-box-footer">
                More info <i class="fas fa-arrow-circle-right"></i>
              </a>
            </div>
          </div>
          <!-- ./col -->
        </div>
        <div class="row">
          <div class="col-md-4">

            <!-- Profile Image -->

            <div class="card card-info 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>Reg No:</b> <a class="float-right"><?php echo $q['teacher_roll_no']; ?></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-secondary 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 card-info card-outline">
                <div class="card-header p-2">
                  <ul class="nav nav-pills">  
                    <li class="nav-item"><a class="nav-link" href="#settings" data-toggle="tab">Task Status</a></li>
                    <hr>
                  </ul>
                </div><!-- /.card-header -->
                <div class="card-body">
                  <div class="tab-content">  
                     <div class="table-responsive">
                      <div class="card-body p-0">
                        <table class="table table-striped display table-bordered">
                          <thead>
                            <tr>
                              <th style="width: 10px">#</th>
                              <th>SUB TASK</th> 
                              <th>TOTAL</th> 
                              <th>REMAIN</th> 
                              <th>PER (%)</th>  
                            </tr>
                          </thead>
                          <tbody>
                             <?php  
                              $i = 1;
                                $selected2 = mysqli_query($conn,"SELECT * FROM `general_subject`,`class_srms`,teacher_course WHERE teacher_course.class_id=class_srms.class_id AND general_subject.sub_id=teacher_course.code AND teacher_course.teacher_roll_no='$reg_number';");
                               while($row = mysqli_fetch_array($selected2)){  
                              ?> 
                            <tr>
                              <td><?php echo $i++ ?></td>
                              <td><?php echo $row['subject_name']; ?></td> 
                              <td><?php echo $row['class_name']; ?></td>
                              <td><?php echo $row['class_name']; ?></td>
                              <td><?php echo $row['class_name']; ?></td>   
                            </tr>
                            <?php } ?>
                          </tbody> 
                        </table>
                      </div>
                    </div>
                    <!-- /.tab-pane -->
                  </div>
                  <!-- /.tab-content -->
                </div><!-- /.card-body -->
              </div>
              <!-- /.card -->
            </div> 
          

          <!-- /.col -->
        </div>
        <div class="row">
          <div class="col-md-8">
            <div class="card">
              <div class="card-header">
                <h3 class="card-title">List of Duties</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: 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> 
                    </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> 
                    </tr>
                    <?php }?> 
                  </tbody>
                </table>
              </div>
               </div>
              <!-- /.card-body -->
            </div>
            <!-- /.card -->
          </div>
          <div class="col-md-4">
            <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-6 col-form-label">Current Password</label>
                        <div class="col-sm-6">
                          <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-6 col-form-label">New Password </label>
                        <div class="col-sm-6">
                          <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-6 col-form-label">Re Enter Password</label>
                        <div class="col-sm-6">
                          <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-secondary">Submit</button>
                        </div>
                      </div>
                    </form>
                  </div>
                  <!-- /.tab-pane -->
                </div>
                <!-- /.tab-content -->
              </div><!-- /.card-body -->
            </div>
            <!-- /.card -->
          </div>
        </div>

        <!-- /.row -->
      </div><!-- /.container-fluid -->
    </section>

     <!-- jQuery -->
<script src="../stp_con/jquery/jquery.min.js"></script>
<!-- Bootstrap 4 -->
<script src="../stp_con/bootstrap/js/bootstrap.bundle.min.js"></script>
<!-- overlayScrollbars -->
<script src="../stp_con/overlayScrollbars/js/jquery.overlayScrollbars.min.js"></script>
<!-- AdminLTE App -->
<script src="../assets/js/adminlte.min.js"></script>
 <?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"], "../upload/" . $_FILES["image"]["name"]);
          $adminthumbnails = "upload/" . $_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 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>