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

    // Add includes to PHP files that I will need to access
    include_once dirname(__FILE__) . '/php_only_scripts/global_after_session.php';
    include_once dirname(__FILE__) . '/php_only_scripts/global_functions.php';
    include_once dirname(__FILE__) . '/php_only_scripts/database.php';
    include_once dirname(__FILE__) . '/php_only_scripts/presentation.php';
    include_once dirname(__FILE__) . '/php_only_scripts/note_presentation.php';

    // Init some variables
    $userRow=null;
    $validationHTML="";

    // 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());
    
    // now determine if it was posted via get.  That will override it.
    $acid=-1;
    if (isset($_GET['acid']) ){
        // Hold on to the associated category ID
        $acid = $_GET['acid'];
    }

    // Determine if the type is passed in
    $c='TASK';
    if (isset($_GET['c'])){
        // Set the session variable category to the one passed in
        $c = $_GET['c'];
    }

    // Determine if we only have one one user with this session ID
    if (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 BOTH the user name AND password has been set
        if (isset($_POST['formSubmitted']) && 
            htmlspecialchars($_POST['formSubmitted'])=='TRUE'){
            // Determine if this user can even modify
            if (!$userRow["CanModify"]){
                // redirect to the tasks page
                echo ('<script>window.location = "' . $fromWhatBaseURL . '";</script>');
            }
            else {
                // Change the form back to NOT being submitted
                $_SESSION['formSubmitted']='FALSE';

                // Check if there are any mods to old sticky notes
                updateOldStickyNotes($db, $userRow);
            }
            
//            // Determine who the calling page was
//            if ( strpos($_SERVER['HTTP_REFERER'], 'machiningTasks.php')!==false) {
//                // Refresh the machines with the real data
//                refreshMachineTasks();
//            } 
            
            // Close the popup dialog
            echo "<script>window.close('','_parent','');</script>";
        }
        else {
            // Set the form submitted session variable to FALSE
            $_POST['formSubmitted']='FALSE';
        }
    }
?>
        
﻿<!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 - View Sticky Notes</title>

    <script src="javascript/general.js" type="text/javascript"></script>
    <script src="javascript/attachments.js" type="text/javascript"></script>
    <script src="javascript/notes.js" type="text/javascript"></script>
    <script src="javascript/notes_inner.js" type="text/javascript"></script>
    <script src="javascript/tools.js" type="text/javascript"></script>
    <script src="javascript/setups.js" type="text/javascript"></script>
    <script src="javascript/blanks.js" type="text/javascript"></script>
    
<!--    <script src="scripts/jquery-ui-1.10.4.custom/js/jquery-1.10.2.js" type="text/javascript"></script>
    <script src="scripts/jquery-ui-1.11.4.custom/jquery-ui.js" type="text/javascript"></script>-->
    <script src="scripts/gen_validatorv4.js" type="text/javascript"></script>

    <script src="scripts/jquery.min.js" type="text/javascript"></script>
<!--    <link href="scripts/jquery-ui-1.10.4.custom/development-bundle/themes/smoothness/jquery-ui.css" rel="stylesheet" type="text/css"/>-->
    
    <style>
        .Table
        {
            display: table;
            width: 100%;
        }
        .Title
        {
            display: table-caption;
            text-align: center;
            font-weight: bold;
            font-size: larger;
            width: 100%;
        }
        .Heading
        {
            display: table-row;
            font-weight: bold;
            text-align: center;
            width: 100%;
        }
        .Row
        {
            display: table-row;
            width: 100%;
        }
        .cell
        {
            color: black;
            display: table-cell;
            border: solid;
            border-width: thin;
            padding-left: 1px;
            padding-right: 1px;
            font-weight: bold;
            font-size: 11px;
            vertical-align: middle;
        }
        .noteTableCell
        {
            display: table-cell;
        }
        .fullNoteLabelCell
        {
            text-align: right;
        }
        .fullNoteTextCell
        {
            width: 80%;
            text-align: left;
        }
        
        /* Style tab links */
        .tablink {
          float: left;
          border: 1px solid gray;
          outline: none;
          cursor: pointer;
          padding: 5px 5px;
          font-size: 11px;
          width: 25%;
        }
        .tablink:hover {
          background-color: #777;
        }
        /* Style the tab content (and add height:100% for full page content) */
        .tabcontent {
          border: 1px solid gray;
          padding: 5px 5px;
        }
        .childtablink {
          float: left;
          border-left: 1px solid gray;
          border-right: 1px solid gray;
          border-top: 1px solid gray;
          border-bottom: 2px solid forestgreen;
          outline: none;
          cursor: pointer;
          padding: 5px 5px;
          font-size: 8px;
        }
        .childtablinkred {
          color:red;
        }
        .childtablinkgreen {
          color:green;
        }
        .childtablink:hover {
          background-color: #bababa;
        }
        .childtabcontent {
          border-left: 2px solid forestgreen;
          border-right: 2px solid forestgreen;
          border-top: none;
          border-bottom: 2px solid forestgreen;
          text-align: left;
        }
    </style>
    <script type="text/javascript">
        $(document).ready(function(){
            // Activate the first tab
            $("#stickyNoteTabButton1").trigger('click'); 
        });    
    </script>
</head>

<body>
    <script>var sessionID = "<?php echo session_id(); ?>";</script>

  <!-- end #header -->
  <br class="clearfloat" />
  
  <!-- start #mainContent -->
  <div id="mainContent" align="center">
    <form action="" method="post" name="updateStickyNoteTask" id="updateStickyNoteTask" enctype="multipart/form-data" >  
        <?php
            // Determine if they are GTG
            if ($gtg){
                // Show just the info for the task
                echo viewAllStickyNoteContent($db, $userRow, $acid, $c, 'ReadCheckboxOnly', $validationHTML);
            }
            else {
                // Close this window
                echo ('<script>window.close();</script>');
            }
        ?>       
        <br>
        <div align="right">
            <input type="hidden" id="formSubmitted" name="formSubmitted" value="TRUE">
            <input name="formSubmit" id="formSubmit" type="submit"  align="right" style="pointer-events: auto; cursor: hand; " value="Update Sticky Note" title="This will update the sticky notes shown here."/>
        </div>
    </form>
    <script language="JavaScript">
        // Code for validating the form
        // Visit http://www.javascript-coder.com/html-form/javascript-form-validation.phtml
        // for details
        var frmvalidator = new Validator("updateStickyNoteTask", "formSubmit");
        <?php
            echo $validationHTML;
        ?>
    </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" />
  
<!-- end #container -->
</div>
</body>

</html>