<?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;
    $machineID = -1;

    // 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());
    
    // 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 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;
        }
        
        // Set the good to go until they log out
        $gtg = true;
        
        // Determine if this person is of appropriate level and company
        if ($userRow["CompanyID"]!=1){
            // redirect to the invalid access page
            echo ('<script>window.location = "invalid_access.php";</script>');

            exit;
        }

        // Determine if the machine ID is posted
        if (isset($_GET['toolsMachineID']) ){
            // Hold onto the machine ID and name for the tool list
            $machineID = $_GET['toolsMachineID'];
        }
    }

?>
﻿<!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 - Machine Tool List</title>

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

    <?php
        // determine if the refresh rate is a positive number
        if ($userRow["RefreshRate"]>0){
            // Add the refresh rate line
            echo('<meta http-equiv="refresh" content="' . $userRow["RefreshRate"] . '"/>');
        }
    ?>
    
    <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: 13px;
        }
        .assignedToolsPositionCell
        {
            text-align: center;
            width: 3%;
        }
        .nameCell
        {
            text-align: center;
        }
        .assignedToolsDiameterCell
        {
            width: 7%;
            text-align: center;
        }
        .assignedToolsCuttingLengthCell
        {
            width: 7%;
            text-align: center;
        }
        .assignedToolsCornerRadiusCell
        {
            width: 7%;
            text-align: center;
        }
        .assignedToolsAngleCell
        {
            width: 7%;
            text-align: center;
        }
        .assignedToolsFluteNumberCell
        {
            width: 5%;
            text-align: center;
        }
        .assignedToolsTypeCell, .brandCell, .pnCell
        {
            width: 9%;
            text-align: center;
        }
        .assignedToolsExposedLengthCell
        {
            width: 7%;
            text-align: center;
        }
        .updateCell
        {
            width: 10%;
            text-align: center;
        }
        .suggestedBackground {
            background:repeating-linear-gradient(
                45deg,
                rgba(77, 77, 77, .5),
                rgba(77, 77, 77, .5) 10px,
                rgba(230, 230, 0, .5) 10px,
                rgba(230, 230, 0, .5) 20px
            );
        }
        .commonToolBackground {
            background:repeating-linear-gradient(
                45deg,
                rgba(204, 0, 0, .5),
                rgba(204, 0, 0, .5) 10px,
                rgba(77, 77, 77, .5) 10px,
                rgba(77, 77, 77, .5) 20px
            );
        }
        span {
          display: inline-block;
          vertical-align: middle;
          line-height: normal;      
        }
        
        /*----------------------------------------------
        CSS settings for HTML div Exact Center
        ------------------------------------------------*/
        #showAllAssignedTools {
            align-items: center;
            width:100%;
            height:100%;
            top:0;
            left:0;
            position:fixed;
            background-color: rgba(49, 49, 49, .95);
            overflow:hidden;
        }
        
        #showAllAssignedToolsBackground {
            background-color: rgba(255, 255, 255, 1); 
            overflow-y: scroll; 
            top: 1%;
            left: 4%;
            right: 4%;
            width: 90%; 
            height: 95%; 
            padding: 5px; 
            margin: 0 auto;
            position:absolute;
        }
        
        #closeAssignedBtn:hover {
            float:right;
            display:inline-block;
            padding:2px 5px;
            background-color: rgba(60, 108, 155, 1);
        }    
        
        #closeAssignedToolsDiv {
            position: fixed;
            left: 95%;
            top: 48%;
            float:right;
            display:inline-block;
            padding:2px 5px;
            background-color: rgba(49, 49, 49, 0);
        }   
    </style>
</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, 'equipment');
        }
      ?>       
      <br class="clearfloat" />
  <!-- end #sidebar1 -->
  </div>
  
  <!-- start #mainContent -->
  <div id="mainContent">
    <div class="maintitle">Task Management System - Machine Tool List</div>
    <div class="breadcrumb"> <a href="../index.html"> Home </a> > <a href="machines.php"> Task Management System - Machines </a> > <a href=
        "<?php echo ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on'?"https" : "http") . "://" . $_SERVER['HTTP_HOST'] .  $_SERVER['REQUEST_URI']); ?>"> Machine Tool List </a></div>
    <br>
    <div id="showAllAssignedTools">
        <div id="showAllAssignedToolsBackground" style="text-align:center; vertical-align: middle; font-size: 33; background-color: Gainsboro;">
            <div id="closeAssignedToolsDiv">
                <button id="closeAssignedBtn" onclick="javascript:window.close();">Close</button>
            </div>        
            <?php
                // Determine if they are GTG
                if ($gtg){
                    // Time to query for the machines tools
                    echo(retrieveAssignedToolsAsList($db, $userRow, $machineID));
                }
                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>');
                }
            ?>  
        </div>
    <!-- Popup Div Ends Here -->
    </div>
    
  <!-- 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>