<?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/toolLists_presentation.php';

    // Init some variables
    $userRow=null;

    // Assume NOT gtg
    $gtg = false;

    // init variables. 
    // Set category as tools by default. 
    // Set type to a negative number indicate no specific type.
    // set sort to be diameter as the first 
    $category=1;
    $toolType = -1;
    $searchPhrase="";
    $sort="Diameter";
    
    // Create and Setup the database
    $db = new Database();
    $db->setupTmsDB();

    // Attempt to log in with this user
    $currentUser = $db->getLoggedInSessionUser(session_id());
    
    // 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){
        // Set the good to go until they log out
        $gtg = true;
        
        // Attempt to get the user row
        $userRow = $currentUser->fetch_assoc();

        // Determine if this user has access to this page
        if ($userRow["UserLevel"]=='TIMECARD ONLY' || 
            $userRow["SUEmployee"]!=1 ||
            $userRow["AccountStatus"]!='ACTIVE'){
            // redirect to the invalid access page
            echo ('<script>window.location = "invalid_access.php";</script>');

            exit;
        }
        
        // now determine if it was posted via get.  That will override it.
        if (isset($_GET['c'])){
            // Hold onto the category in a local variable
            $category=rawurldecode($_GET['c']);
        }

        // now determine if it was posted via get.  That will override it.
        if (isset($_GET['tt'])){
            // Hold onto the category in a local variable
            $toolType=rawurldecode($_GET['tt']);
        }
        
        // Determine if there is a search phrase
        if (isset($_GET['sp'])){
            // Set the search phrase
            $searchPhrase=rawurldecode($_GET['sp']);
        }

        // Determine if there is a sort preference
        if (isset($_GET['sn']) ){
            // Hold onto the sort info
            $sort = rawurldecode($_GET['sn']);
        }
    }
?>
﻿<!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 - Tools</title>

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

    <script src="./SpryAssets/SpryMenuBar.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%;
        }
        .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;
            vertical-align: middle;
        }
        .nameCell
        {
            text-align: center;
        }
        .toolsDiameterCell
        {
            width: 9%;
            text-align: center;
        }
        .toolsCuttingLengthCell
        {
            width: 9%;
            text-align: center;
        }
        .toolsCornerRadiusCell
        {
            width: 9%;
            text-align: center;
        }
        .toolsAngleCell
        {
            width: 9%;
            text-align: center;
        }
        .toolsFluteNumberCell
        {
            width: 5%;
            text-align: center;
        }
        .toolsTypeCell
        {
            width: 14%;
            text-align: center;
        }
        .hoverHand
        {
            cursor: hand;
        }
        .updateCell
        {
            width: 14%;
            text-align: center;
        }
        span {
          display: inline-block;
          vertical-align: middle;
          line-height: normal;      
        }
        /*----------------------------------------------
        CSS settings for low quantity background
        ------------------------------------------------*/
        .lowQuantityBackground {
            background-color: white;
            background:repeating-linear-gradient(
                90deg,
                rgba(255, 0, 127, 1),
                rgba(255, 0, 127, 1) 10px,
                rgba(255, 255, 255, 1) 10px,
                rgba(255, 255, 255, 1) 20px
            );
        }

    </style>
    <script type="text/javascript">
        function CreateURLSearchVariables() {
            // Get all of the variables
            var category = document.getElementById('category').value===null?'&c=-1':'&c=' + encodeURIComponent(document.getElementById('category').value);
            var $toolType = document.getElementById('typeForAll').value===null?'&tt=-1':'&tt='+encodeURIComponent(document.getElementById('typeForAll').value);
            var sortNumber = document.getElementById('sortNumber').value===null?'&sn=1':'&sn='+encodeURIComponent(document.getElementById('sortNumber').value);
            var searchPhrase = document.getElementById('searchPhrase').value===''?'':'&sp=' + encodeURIComponent(document.getElementById('searchPhrase').value);
        
            // Return what we can build up
            return '\?' + category + sortNumber + $toolType + searchPhrase;
        }
        
        function CreateAndGotoSearchOptions() {
            // Get the base location
            var goToLocation = window.location.href.split('?')[0];

            // Build the location to go to with get variables
            goToLocation = goToLocation + CreateURLSearchVariables();
            
            // Go to the location built
            window.location=goToLocation;
        }
        
//        function displayCorrectTypesAll() {
//            // get the type combo now by ID
//            var cmbTypes = document.getElementById('typeForAll');
//
//            // Loop through the values in the combo box
//            for(i = 0; i < cmbTypes.length; i++) {
//                // Go onto next index if we are on the ALL TYPES one
//                if (cmbTypes[i].value === "ALL TYPES"){
//                    // Move to the next element
//                    continue;
//                }
//                
//                // assume that the type will become invisible
//                var visible = false;
//                
//                // get value with spaces changed to underscores
//                var loopTypeID = cmbTypes[i].value.split(" ").join("_")
//                
//                // Determine if it is the selected one to be visible or all visible
//                if (cmbTypes[i].selected ||
//                    cmbTypes[0].selected) {
//                    // This is the one to be visible
//                    var visible = true;
//                }
//
//                // Call the function to set visibility
//                setDivVisibility(loopTypeID, visible);
//            }
//        } 
//        
//        function setDivVisibility(){
//            // Set the div to hide as the ID passed in.  Assume good ID.
//            var divToHide = document.getElementById(arguments[0]);
//            
//            // Determine if it is to be visible
//            if (arguments[1]) {
//                // show it
//                divToHide.style.display = 'block';
//            } else {
//                // Hide it
//                divToHide.style.display = 'none';
//            }
//        }
</script>    
</head>

<body class="thrColElsHdr">

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

<div id="topContent">
</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, 'equipment');
        }
      ?>       
      <br class="clearfloat" />
  <!-- end #sidebar1 -->
  </div>
  
  <!-- start #mainContent -->
  <div id="mainContent">
    <div class="maintitle">Task Management System - Tools</div>
    <div class="breadcrumb"> <a href="../index.html"> Home </a> > <a href=
        "<?php echo ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on'?"https" : "http") . "://" . $_SERVER['HTTP_HOST'] .  $_SERVER['REQUEST_URI']); ?>"> Task Management System - Tools </a></div>

    <br>
        
    <?php
        // Determine if they are GTG
        if ($gtg){
            // Time to query for their tasks
            echo(retrieveToolsAsList($db, $userRow, $toolType, $category, $sort, $searchPhrase));
        }
        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>