 <?php
    $iduser= $_SESSION['user_idd']; 
    $sql=mysqli_query($con,"SELECT * FROM users WHERE userid='$iduser'");
    while($row=mysqli_fetch_array($sql))
    {
    $lev=$row["Level"];
    }
    
    $date = new DateTime("now", new DateTimeZone('Africa/Nairobi') );
    $timenow=$date->format('Y-m-d H:i:s');
    $timenow2=$date->format('Y-m-d');
    $month=$date->format('M');
  ?>

<div class="content-wrapper">
    <!-- Content Header (Page header) -->
    <div class="content-header">
      <div class="container-fluid">
        <div class="row mb-2">
          <div class="col-sm-6">
            <h4 class="m-0">Profile</h4>
          </div><!-- /.col -->
          <div class="col-sm-6">
            <ol class="breadcrumb float-sm-right">
                <li class="breadcrumb-item">Dashboard</li>
                <li class="breadcrumb-item active">Profile</li>
            </ol>
          </div><!-- /.col -->
        </div><!-- /.row -->
      </div><!-- /.container-fluid -->
    </div>
    <section class="content">
      <div class="container-fluid">
      <?php
            $sql1=mysqli_query($con,"SELECT * FROM Staffs WHERE id='$idauto'");
            while($row=mysqli_fetch_array($sql1))
            {
            $idno=$row["IDNo"];
            $phn=$row["Phone"];
            $emp=$row["EmpDate"];
            $posi=$row["Position"];
            $em=$row["Email"];
            }
      ?>
        <div class="row">
          <div class="col-md-3">
            <!-- 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="../images/admin.png"
                       alt="User profile picture">
                </div>

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

                <p class="text-muted text-center"><?php echo $posi; ?></p>
              </div>
              <!-- /.card-body -->
            </div>
            <!-- /.card -->

            <!-- About Me Box -->
            <div class="card card-primary">
              <div class="card-header">
                <h3 class="card-title">About Me</h3>
              </div>
              <!-- /.card-header -->
              <div class="card-body">
            <strong><i class="fas fa-phone-volume mr-1"></i> Contact</strong>
                <p class="text-muted">
                  <?php echo $phn; ?>
                </p>
                <hr>
                <strong><i class="fas fa-address-card mr-1"></i> ID Number</strong>
                <p class="text-muted"> <?php echo $idno; ?></p>
                <hr>
                <strong><i class="fas fa-pencil-alt mr-1"></i> Employment Date</strong>

                <p class="text-muted">
                  <span class="tag tag-danger"> <?php echo $emp; ?></span>
                </p>
                <hr>
                <strong><i class="far fa-paper-plane mr-1"></i> Email</strong>

                <p class="text-muted"><?php echo $em; ?></p>
              </div>
              <!-- /.card-body -->
            </div>
            <!-- /.card -->
          </div>
          <!-- /.col -->
          <div class="col-md-9">
            <div class="card">
              <div class="card-header p-2">
                <ul class="nav nav-pills">
                  <li class="nav-item"><a class="nav-link active" href="#activity" data-toggle="tab">Activity </a></li>
                  <li class="nav-item"><a class="nav-link" href="#settings" data-toggle="tab">Change Password</a></li>
                  <li class="nav-item"><a class="nav-link" href="#thepin" data-toggle="tab">Change Pin</a></li>
                </ul>
              </div><!-- /.card-header -->
              <div class="card-body">
                <div class="tab-content">
                  <div class="active tab-pane" id="activity">
                    <!-- Post -->
                    <div class="">
                        
                    <div class="table-responsive" id="divtableact">
                    <table class="table table-sm table-hover" id="divactivity" style="font-size:12px;font-family:">
                    <thead>
                    <tr>
                        <th>#</th>
                        <th>Time</th>
                        <th>Activity</th>
                    </tr>
                    </thead>
                     <tbody>
                        
                    <?php
                    $newDate = date('Y-m-d', strtotime($timenow. ' - 30 days'));
                    if($lev=='Admin')
                    {
                    $sql1=mysqli_query($con,"SELECT activity.*, Staffs.Name as nm FROM activity JOIN Staffs ON Staffs.id=activity.user WHERE activity.user !='1' AND Dat > '$newDate' order by activity.id DESC limit 200");
                    $cnt=1;
                    while($row=mysqli_fetch_array($sql1))
                    {
        
                      if($us==$idauto)
                      {
                        ?>
                        <tr class='alert-warning'>
                        <td>
                        <?php
                         $ti=$row["Tim"];
                         $timm=substr($ti, -8); 
                        
                        echo $cnt; ?></td>
                        <?php
                        $da=$row["Dat"];
                        if($timenow2==$da)
                        {
                        ?>
                        <td><span class="badge bg-primary"><?php echo 'Today '. $timm; ?></span></td>
                        <?php
                        }else
                        {
                        ?>
                        <td><?php echo $row["Tim"]; ?></td>
                        <?php
                        }
                        ?>
                        <td><?php echo 'You '.$row["Action"]; ?></td>
                        </tr>
                        <?php
                      }else
                      {
                        ?>
                        <tr>
                        <td>
                        <?php 
                        $ti=$row["Tim"];
                        $timm=substr($ti, -8);
                            
                          echo $cnt; ?></td>
                         <?php
                        $da=$row["Dat"];
                        if($timenow2==$da)
                        {
                        ?>
                        <td><span class="badge bg-primary"><?php echo 'Today '. $timm; ?></span></td>
                        <?php
                        }else
                        {
                        ?>
                        <td><?php echo $row["Tim"]; ?></td>
                        <?php
                        }
                        ?>
                        <td><?php echo $row["nm"].' '.$row["Action"]; ?></td>
                        </tr>
                        <?php
                      }
                      ?>
                      
                      <?php
                      $cnt=$cnt+1;
                    }
                    
                    }else
                    {
                       $newDate = date('Y-m-d', strtotime($timenow. ' - 30 days'));
                      $sql1=mysqli_query($con,"SELECT activity.*, Staffs.Name as nm FROM activity JOIN Staffs ON Staffs.id=activity.user where Staffs.id='$iduser' AND Dat > ' $newDate' order by activity.id DESC limit 100");
                    $cnt=1;
                    while($row=mysqli_fetch_array($sql1))
                    {
                     $us=$row["user"];
                     
                    ?>  
                        
                      <?php
                      if($us==$idauto)
                      {
                        ?>
                        <tr class='alert-warning'>
                        <td><?php echo $cnt; ?></td>
                        <td><?php echo $row["Tim"]; ?></td>
                        <td><?php echo 'You '.$row["Action"]; ?></td>
                        </tr>
                        <?php
                      }else
                      {
                        ?>
                        <tr>
                        <td><?php echo $cnt; ?></td>
                        <td><?php echo $row["Tim"]; ?></td>
                        <td><?php echo $row["nm"].' '.$row["Action"]; ?></td>
                        </tr>
                        <?php
                      }
                      ?>
                        </tbody> 
                      <?php
                      $cnt=$cnt+1;
                    } 
                      
                    }
                    ?>
                             
                    </table>
                      </div>
                      <!-- /.user-block -->
                   

                    </div>
                    <!-- /.post -->

                    <!-- Post -->
                    <div class="post clearfix">
                   
                    </div>
                    <!-- /.post -->

                    <!-- Post -->
                    <div class="post">
                     
                      <!-- /.user-block -->
                      <div class="row mb-3">
                        
                        <!-- /.col -->
                        <div class="col-sm-6">
                          <div class="row">
                          
                            <!-- /.col -->
                          </div>
                          <!-- /.row -->
                        </div>
                        <!-- /.col -->
                      </div>
                      <!-- /.row -->

                    </div>
                    <!-- /.post -->
                  </div>
                  
                 <div class="tab-pane" id="thepin">
                    <form class="form-horizontal" onsubmit="return false">
                      <div class="form-group">
                        <label for="inputName" class=" col-sm-6 col-form-label">Enter Pin</label>
                        
                        <div class="col-sm-4">
                          <input type="password" name="thepin" value="" style="font-size:18px;color:red" class="form-control" onkeyup="if (/\D/g.test(this.value)) this.value = this.value.replace(/\D/g,'')"  id="mypin" maxlength="4" required placeholder="" />
                        </div>
                      </div>

                      <div class="col-sm-2">
                            <div class="form-group">
                              <input class="form-check-input" type="checkbox" name="remember" value="true" onclick="myFunction()" id="rememberMe">
                              <label class="form-check-label" for="rememberMe">Show Pin</label>
                            </div>
                       </div>
                 
                      <div class="form-group">
                        <div class="col-sm-4">
                            <center><label id="updatepassfeedback"></label></center>
                          <button type="submit" id="btnchangepassword" class="btn btn-dark pull-right btn-sm"><i class="far fa-refresh"></i> Change</button>
                        </div>
                      </div>
                    </form>
                  </div>

                  <div class="tab-pane" id="settings">
                    <form class="form-horizontal" onsubmit="return false">
                      <div class="form-group row">
                        <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="cpass" placeholder="" required>
                          <input type="hidden" value="<?php echo $idauto;?>" id="idholder" />
                        </div>
                      </div>
                      <div class="form-group row">
                        <label for="inputEmail" class="col-sm-2 col-form-label">New Password</label>
                        <div class="col-sm-10">
                          <input type="password" class="form-control" id="newpassword" placeholder="" required>
                        </div>
                      </div>
                      <div class="form-group row">
                        <label for="inputName2" class="col-sm-2 col-form-label">Confirm new Password</label>
                        <div class="col-sm-10">
                          <input type="password" class="form-control" id="copass" required />
                        </div>
                      </div>
                   
                      <div class="form-group row">
                        <div class="offset-sm-2 col-sm-10">
                            <center><label id="updatepassfeedbackk"></label></center>
                          <button type="submit" id="btnchangepasswordd" class="btn btn-danger"><i class="far fa-refresh"></i> Change</button>
                        </div>
                      </div>
                    </form>
                  </div>
                  <!-- /.tab-pane -->
                </div>
                <!-- /.tab-content -->
              </div><!-- /.card-body -->
            </div>
            <!-- /.card -->
          </div>
          <!-- /.col -->
        </div>
        <!-- /.row -->
      </div><!-- /.container-fluid -->
    </section>
  
</div>

