<?php 
    // continue the session
    session_start();

    // Add includes to PHP files that I will need to access
    include 'php_only_scripts/database.php';
    include 'php_only_scripts/presentation.php';
    include 'php_only_scripts/timecards_presentation.php';

    // Init some variables
    $userRow=null;
    $timecardUserAssocRow=null;

    // Assume NOT gtg
    $gtg = false;

    // Create and Setup the database
    $db = new Database();
    $db->setupTmsDB();

    // Attempt to log in with this user
    $currentUser = $db->getLoggedInSessionUser(session_id());
    
    // Set a good ID starting value
    $timecardUserID=-1;
    $paydateStart=null;
    
    // If there is only one result for a username/password combo, then they are good to go.
    if ($currentUser == null){
        exit;
    }
    elseif (mysqli_num_rows($currentUser)==1){
        // Attempt to get the user row
        $userRow = $currentUser->fetch_assoc();

        // Determine if a timecard user ID sent in the URL
        if (isset($_GET['timecardUserID']) ){
            // Hold onto the Timecard user ID to be used
            $timecardUserID = $_GET['timecardUserID'];
        }
        else {
            // Determine if a user ID sent in a post
            if (isset($_POST['UserID']) ){
                // Hold onto the Timecard user ID to be used
                $timecardUserID = $_POST['UserID'];
            }
            else {
                // Hold onto the Timecard user ID to be used
                $timecardUserID = $userRow['UserID'];
            }
        }
            
        // Determine if a start pay date was sent in the URL
        if (isset($_GET['paydateStart']) ){
            // Hold onto the start pay date to be used
            $paydateStart = $_GET['paydateStart'];
        }
        else {
            // Determine if a start pay date is sent in a post
            if (isset($_POST['paydateStart']) ){
                // Hold onto the start pay date to be used
                $paydateStart = $_POST['paydateStart'];
            }
        }
            
        // Create a query to to get timecard user information on the passed in timecard user
        $sql = 'SELECT * FROM users u ' .
               'WHERE u.UserID=' . $timecardUserID . ';';

        // Attempt to get the timecard user row
        $timecardUserRow = $db->queryDB($sql, $userRow, "paydateHours Form occurance 1");

        // Attempt to get the timecard user row
        $timecardUserAssocRow = $timecardUserRow->fetch_assoc();

        // Determine if this user is allowed here or not
        if ($userRow["AccountStatus"]=='ACTIVE' &&
            $userRow["SUEmployee"]==1 &&
            ($userRow["UserLevel"]=='SU' ||
             ($userRow["UserLevel"]=='EXECUTIVE' && $userRow["CompanyID"]==$timecardUserAssocRow["CompanyID"]) ||
             ($userRow["UserID"]==$timecardUserAssocRow["UserID"]))){
            // Set the good to go until they log out
            $gtg = true;
        }
        else {
            // redirect to the invalid access page
            echo ('<script>window.location = "invalid_access.php";</script>');

            exit;
        }
    }

?>
﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

    <title>Task Management System - Timecard Payday History</title>

    <meta name="keywords" content="GIS,data,testing,IT" />
    <meta name="description" content="EES Divisions." />

    <script src="./SpryAssets/SpryMenuBar.js" type="text/javascript"></script>
    <script src="./javascript/general.js" type="text/javascript"></script>

    <link rel="icon" href="images/ees_ico.ico"/> 
    <link href="./SpryAssets/SpryMenuBarHorizontal.css" rel="stylesheet" type="text/css" />
    <link href="./SpryAssets/SpryMenuBarVertical.css" rel="stylesheet" type="text/css" />
    <link rel = "stylesheet" type="text/css" href="./css/contentpage.css" >
        
    <style type="text/css">
        .Table
        {
            display: table;
            width: 100%;
        }
        .Title
        {
            display: table-caption;
            text-align: center;
            font-weight: bold;
            font-size: larger;
        }
        .Heading
        {
            display: table-row;
            font-weight: bold;
            text-align: center;
            width: 100%;
        }
        .Group 
        {
            display: table-row-group; 
            width: 100%; 
        }
        .Row
        {
            display: table-row;
            width: 100%;
        }
        .cell
        {
            display: table-cell;
            border: solid;
            border-width: thin;
            padding-left: 1px;
            padding-right: 1px;
            font-weight: bold;
            font-size: 12px;
        }
        .dayNumberCell
        {
            width: 15%;
            text-align: center;
        }
        .dayDateCell
        {
            width: 30%;
            text-align: center;
        }
        .dayWeekdayCell
        {
            width: 30%;
            text-align: center;
        }
        .dayTotalHoursCell
        {
            width: 20%;
            text-align: center;
        }
        .durationFiller
        {
            width: 5%;
            display: table-cell;
            border: none;
        }
        .durationTextCell
        {
            width: 20%;
            text-align: left;
        }
        .durationStartTimeCell
        {
            width: 25%;
            text-align: center;
        }
        .durationEndTimeCell
        {
            width: 25%;
            text-align: center;
        }
        .durationHoursCell
        {
            width: 17%;
            text-align: center;
        }
        .updateCell
        {
            width: 8%;
            text-align: center;
        }
        span {
          display: inline-block;
          vertical-align: middle;
          line-height: normal;      
        }
    </style>
    <script type="text/javascript">
        // Variables used for keeping track of stuff
        numberExpandedRows=0;
        
        //Function To Display Tools Popup
        function div_toggleEditableTableRowVisibility() {
            // Get the info on whether or not to show the subtask
            var toggleDiv = document.getElementById(arguments[0]);
            
            // Determine if it should be shown
            if (toggleDiv!==null){
                if (toggleDiv.style.display === "none"){
                    // Get the outer div and show it
                    div_show_tablerow(arguments[0]);
                    
                    // Increase the number of expanded rows
                    numberExpandedRows++;
                }
                else {
                    // Get the outer div and show it
                    div_hide_tablerow(arguments[0]);
                    
                    // Decreas the number of expanded rows
                    numberExpandedRows--;
                }
            }
            
            // Get the info on whether or not to show the subtask
            var timecardDetails_Header = document.getElementById('TimecardDetails_Header');

            // Determine if it is available to modify
            if (timecardDetails_Header!==null){
                // Attempt to toggle
                if (numberExpandedRows <= 0){
                    // Set it to zero exactly in case some weirdness
                    numberExpandedRows=0;

                    // Get the outer div and show it
                    div_hide_tablerow('TimecardDetails_Header');
                }
                else {
                    // Get the outer div and show it
                    div_show_tablerow('TimecardDetails_Header');
                }
            }
        }

        //Function To Display Tools Popup
        function div_toggleUneditableTableRowVisibility() {
            // Get the info on whether or not to show the subtask
            var toggleDiv = document.getElementById(arguments[0]);
            
            // Determine if it should be shown
            if (toggleDiv!==null){
                if (toggleDiv.style.display === "none"){
                    // Get the outer div and show it
                    div_show_tablerow(arguments[0]);
                    
                    // Increase the number of expanded rows
                    numberExpandedRows++;
                }
                else {
                    // Get the outer div and show it
                    div_hide_tablerow(arguments[0]);
                    
                    // Decreas the number of expanded rows
                    numberExpandedRows--;
                }
            }
            
            // Get the info on whether or not to show the subtask
            var timecardDetails_Header = document.getElementById('TimecardDetails_Header');

            // Determine if it is available to modify
            if (timecardDetails_Header!==null){
                // Attempt to toggle
                if (numberExpandedRows <= 0){
                    // Set it to zero exactly in case some weirdness
                    numberExpandedRows=0;

                    // Get the outer div and show it
                    div_hide_tablerow('TimecardDetails_Header');
                }
                else {
                    // Get the outer div and show it
                    div_show_tablerow('TimecardDetails_Header');
                }
            }
        }

        //Function To Display Popup
        function div_show_tablerow() {
            // Get the outer div and show it
            document.getElementById(arguments[0]).style.display = "table-row-group";
        }

        //Function to Hide Popup
        function div_hide_tablerow(){
            // Get the outer div and hide it
            document.getElementById(arguments[0]).style.display = "none";
        } 
    </script>
</head>

<body class="thrColElsHdr">

<div id="container">
  
<!-- start of banner wrap --->

<div id="topContent">
  
<div>
   <div class="MenuBarHorizontal" id="navBar">  <ul id="TopNav" class="MenuBarHorizontal">

    <script type="text/javascript">
    <!--
    var MenuBar2 = new Spry.Widget.MenuBar("TopNav", {imgDown:"./SpryAssets/SpryMenuBarDownHover.gif", imgRight:"./SpryAssets/SpryMenuBarRightHover.gif"});
    //-->
    </script>

    </div>
  </div>
</div>
<!-- end of banner wrap --->

  <!-- end #header -->
  <br class="clearfloat" />
  <div id="sidebar1">
      <?php 
        // Determine if we are GTG
        if ($gtg){
          // Render the appropriate presentation for the tasks sidebar
          getSidebar($userRow, 'timecard');
        }
      ?>       
      <br class="clearfloat" />
  <!-- end #sidebar1 -->
  </div>
  
  <!-- start #mainContent -->
  <div id="mainContent">
    <div class="maintitle">Task Management System - Timecard Payday History</div>
    <div class="breadcrumb"> <a href="../index.html"> Home </a> > <a href="tasks.php"> Task Management System </a> > <a href="timecardHistory.php"> Timecard History </a></div>

    <br>
        
    <?php
        // Determine if they are GTG
        if ($gtg){
            // Determine if this user is of the correct company
            if ($userRow["CompanyID"]==1){
                // Time to query for their tasks
                echo(retrievePayDateHistoryAsList($db, $userRow, $timecardUserAssocRow, $paydateStart));
            }
        }
        else {
            // Set the login failed to true
            $_SESSION['failedLogin']='TRUE';

            // Add a session variable that is this page URL
            $_SESSION['pageToGoTo']=$_SERVER['REQUEST_URI'];

            // redirect to the login page
            echo ('<script>window.location = ".";</script>');
        }
    ?>       
  <!-- end #mainContent -->
  
  <!-- This clearing element should immediately follow the #mainContent div in order to force the #container div to contain all child floats -->
  <br class="clearfloat" />
  
  <!-- start #footer --></div>
   <div id="footer">
    <p>© 2018 Evolve Engineering and Software. EES, Evolve Engineering and Software, EES Logo are registered marks of Evolve Engineering and Software.</p>
  <!-- end #footer -->
   </div>
<!-- end #container -->
</div>

</body>

</html>

