<?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>
                </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" id="divactivity">
                    <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 Dat > '$newDate' order by activity.id DESC limit 100");
                    $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>
                  <!-- /.tab-pane -->
                  <div class="tab-pane" id="timeline">
                    <!-- The timeline -->
                    <div class="timeline timeline-inverse">
                      <!-- timeline time label -->
                      <div class="time-label">
                        <span class="bg-danger">
                          10 Feb. 2014
                        </span>
                      </div>
                      <!-- /.timeline-label -->
                      <!-- timeline item -->
                      <div>
                        <i class="fas fa-envelope bg-primary"></i>

                        <div class="timeline-item">
                          <span class="time"><i class="far fa-clock"></i> 12:05</span>

                          <h3 class="timeline-header"><a href="#">Support Team</a> sent you an email</h3>

                          <div class="timeline-body">
                         
                          </div>
                          <div class="timeline-footer">
                            <a href="#" class="btn btn-primary btn-sm">Read more</a>
                            <a href="#" class="btn btn-danger btn-sm">Delete</a>
                          </div>
                        </div>
                      </div>
                      <!-- END timeline item -->
                      <!-- timeline item -->
                      <div>
                        <i class="fas fa-user bg-info"></i>

                        <div class="timeline-item">
                          <span class="time"><i class="far fa-clock"></i> 5 mins ago</span>

                          <h3 class="timeline-header border-0"><a href="#">Sarah Young</a> accepted your friend request
                          </h3>
                        </div>
                      </div>
                      <!-- END timeline item -->
                      <!-- timeline item -->
                      <div>
                        <i class="fas fa-comments bg-warning"></i>

                        <div class="timeline-item">
                          <span class="time"><i class="far fa-clock"></i> 27 mins ago</span>

                          <h3 class="timeline-header"><a href="#">Jay White</a> commented on your post</h3>

                          <div class="timeline-body">
                            Take me to your leader!
                            Switzerland is small and neutral!
                            We are more like Germany, ambitious and misunderstood!
                          </div>
                          <div class="timeline-footer">
                            <a href="#" class="btn btn-warning btn-flat btn-sm">View comment</a>
                          </div>
                        </div>
                      </div>
                      <!-- END timeline item -->
                      <!-- timeline time label -->
                      <div class="time-label">
                        <span class="bg-success">
                          3 Jan. 2014
                        </span>
                      </div>
                      <!-- /.timeline-label -->
                      <!-- timeline item -->
                      <div>
                        <i class="fas fa-camera bg-purple"></i>

                        <div class="timeline-item">
                          <span class="time"><i class="far fa-clock"></i> 2 days ago</span>

                          <h3 class="timeline-header"><a href="#">Mina Lee</a> uploaded new photos</h3>

                          <div class="timeline-body">
                            <img src="https://placehold.it/150x100" alt="...">
                            <img src="https://placehold.it/150x100" alt="...">
                            <img src="https://placehold.it/150x100" alt="...">
                            <img src="https://placehold.it/150x100" alt="...">
                          </div>
                        </div>
                      </div>
                      <!-- END timeline item -->
                      <div>
                        <i class="far fa-clock bg-gray"></i>
                      </div>
                    </div>
                  </div>
                  <!-- /.tab-pane -->

                  <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="updatepassfeedback"></label></center>
                          <button type="submit" id="btnchangepassword" 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>

