Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- //error_reporting(E_ALL); ini_set('display_errors', '1');
- if(! $logged_in ) {
- require_once('form-login.php');
- } else { ?>
- <div class="col-md-10 col-md-offset-2 col-sm-9 main">
- <h1 class="page-header">Timesheets</h1>
- <form action="https://portal.designloud.com/index.php?do=timesheets" method="POST" class="form-horizontal" role="form">
- <div class="form-group">
- <legend>View Timesheet</legend>
- </div>
- <div class="form-group">
- <?php if($level === '5') { ?>
- <label for="employee" class="col-sm-2 col-lg-1 control-label">Employee</label>
- <div class="col-sm-10 col-lg-11">
- <select name="employee" id="employee" class="form-control">
- <option value="" disabled selected>Select an Employee</option>
- <?php
- $connect = mysqli_connect(HOST, USER, PASSWORD, DATABASE);
- if (mysqli_connect_errno()) {
- echo "Failed to connect to Database: " . mysqli_connect_error();
- }
- $check = mysqli_query($connect, "SELECT id, firstname, lastname
- FROM members") or die('Error: ' . mysqli_error($connect));
- if(mysqli_num_rows($check)>0){
- while ($row = mysqli_fetch_array($check, MYSQL_ASSOC)) {
- $firstname = $row['firstname'];
- $lastname = $row['lastname'];
- $userID = $row['id'];
- echo '<option value="' . $userID . '">' . $firstname . ' ' . $lastname . '</option>';
- }
- } ?>
- </select>
- </div>
- <?php }
- else {
- $user_id = $_SESSION['user_id'];
- echo '<input type="hidden" name="employee" id="employee" value="' . $user_id . '" />';
- } ?>
- </div>
- <div class="form-group col-sm-12 col-md-6 col-lg-6">
- <label for="from_date" class="col-sm-6 col-md-3 col-lg-3 control-label">From Date</label>
- <div class="col-sm-6 col-md-9 col-lg-9">
- <input type="text" name="from_date" id="from_date" class="form-control">
- </div>
- </div>
- <div class="form-group col-sm-12 col-md-6 col-lg-6">
- <label for="to_date" class="col-sm-6 col-md-3 col-lg-3 control-label">To Date</label>
- <div class="col-sm-6 col-md-9 col-lg-9">
- <input type="text" name="to_date" id="to_date" class="form-control">
- </div>
- </div>
- <div class="form-group col-sm-12 col-md-12 col-lg-12">
- <div class="col-sm-offset-10 col-sm-2 col-lg-offset-11 col-lg-1">
- <button type="submit" class="btn btn-primary">Submit</button>
- </div>
- </div>
- </form>
- <?php
- if (isset($_POST['employee']) && isset($_POST['to_date']) && isset($_POST['from_date']) ) {
- include_once 'includes/db_connect.php';
- include_once 'includes/psl-config.php';
- $employee = $_POST['employee'];
- $fromDate = $_POST['from_date'];
- $toDate = $_POST['to_date'];
- $connect = mysqli_connect(HOST, USER, PASSWORD, DATABASE);
- if (mysqli_connect_errno()) {
- echo "Failed to connect to Database: " . mysqli_connect_error();
- }
- /**************************************************
- General Timesheet
- **************************************************/
- $timesheet = mysqli_query($connect, "SELECT DATE_FORMAT(punch, '%Y/%m/%d') AS punch_date, DATE_FORMAT(punch, '%H:%i:%s') AS punch_time, comment
- FROM timesheet WHERE user_id = '$employee' AND punch BETWEEN '$fromDate' AND '$toDate'") or die('Error: ' . mysqli_error($connect));
- if(mysqli_num_rows($timesheet)>0){
- $output = '<table class="table table-striped">
- <thead>
- <tr>
- <th>Date</th>
- <th>Time</th>
- <th>Status</th>
- </tr>
- </thead>
- <tbody>';
- $iterations = mysqli_num_rows($timesheet) % 2 == 0 ? mysqli_num_rows($timesheet) : mysqli_num_rows($timesheet) - 1;
- $total = 0;
- while ($row = mysqli_fetch_array($timesheet, MYSQL_ASSOC)) {
- $date = $row['punch_date'];
- $time = $row['punch_time'];
- $status = $row['comment'];
- $output .= '<tr>
- <td>' . $date . '</td>
- <td ';
- $parts = explode(':', $row['punch_time']);
- $seconds = (int) $parts[0] * 3600 + (int) $parts[1] * 60 + (int) $parts[2];
- if($status === 'In'){
- $output .= 'class="in-time"';
- $total -= $iterations ? $seconds : 0; // Subtract from total when in and there is out coming
- } else if($status === 'Out') {
- $output .= 'class="out-time"';
- $total += $seconds; // Add to total when out
- }
- $output .= '>' . $time . '</td>
- <td>' . $status . '</td>
- </tr>';
- $iterations--;
- } //end while
- $output .= '</tbody>
- </table>';
- echo $output;
- $hours = floor($total / 3600);
- $minutes = floor(($total / 60) % 60);
- $seconds = $total % 60;
- echo "<strong>Total: </strong> $hours:$minutes:$seconds";
- } //end if mysqli_num_rows
- } // end if isset
- ?>
- </div> <!-- /.main -->
- <?php
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement