<?php
    function retrieveUsersBenefitsAsList($db, $userRow, $currentUsersCompany){
        // Determine if this is a super user
        if ($userRow["CompanyID"]==1){
            // Calculate the first of the year.
            $dateToCheck = new DateTime();

            // Get the current year
            $currentYear = $dateToCheck->format("Y");
            
            // Determine if this user is a SU
            if (($userRow["UserLevel"]=='SU' ||
                 $userRow["UserLevel"]=='EXECUTIVE')){
                // Initialize variables to zero at first
                $hoursWorkedThisYear = 0;
                $hoursAccruedThisYear = 0;
                $ptoBalance = 0;
                $trialPeriod = 0;
                $lastPayDateUpdated = null;
                
                // Initialize the return
                $result = 
                    '<li class="ui-state-default ui-state-disabled Table">
                        <div class="Heading">
                            <div class="cell nameCell">
                                <p><b>Last Name</b></p>
                            </div>
                            <div class="cell nameCell">
                                <p><b>First Name</b></p>
                            </div>
                            <div class="cell ptoInfoCell">
                                <p><b>Average Weekly Hours</b></p>
                            </div>
                            <div class="cell ptoInfoCell">
                                <p><b>Years<br>Worked</b></p>
                            </div>
                            <div class="cell ptoInfoCell">
                                <p><b>Accrual<br>Rate</b></p>
                            </div>
                            <div class="cell ptoInfoCell">
                                <p><b>Hours Worked<br>in ' . $currentYear . '</b></p>
                            </div>
                            <div class="cell ptoInfoCell">
                                <p><b>Accumulated<br>PTO in ' . $currentYear . '</b></p>
                            </div>
                            <div class="cell ptoInfoCell">
                                <p><b>Current PTO<br>Balance</b></p>
                            </div>
                        </div>
                    </li>';

                try {
                    // Setup a query with a company name added
                    $sql='SELECT *  ' .
                         'FROM users u, companies c ' .
                         'WHERE u.CompanyID=c.CompanyID ' .
                         'AND u.CompanyID=' . $currentUsersCompany . ' ' .
                         'AND u.UserTemplateOnly=0 ' .
                         'AND SUEmployee=1 ' .
                         'AND AccountStatus="ACTIVE" ' .
                         'AND FirstPayDate<>"0000-00-00 00:00:00" ' .
                         'ORDER BY c.CompanyName ASC, u.LastName ASC, u.FirstName ASC;';

                    // Query the database for the users 
                    $rows = $db->queryDB($sql, $userRow, "benefits_presentation Form occurance 1");

                    // Loop through the returned results
                    while ($row=mysqli_fetch_array($rows)){
                        // Determine what color this row should be
                        $color='';
                        switch ($row["UserLevel"]){
                            case 'SU':
                                // Set the color to be blueish
                                $color='#708df5';

                                // Break out of this case statement
                                break;
                            case 'EXECUTIVE':
                                // Set the color to be greenish
                                $color='#2bd566';

                                // Break out of this case statement
                                break;
                            case 'MANAGEMENT':
                                // Set the color to be yellowish
                                $color='#f5fd93';

                                // Break out of this case statement
                                break;
                            case 'MID-MANAGEMENT' :
                                // Set the color to be purpleish
                                $color='#8b62cf';

                                // Break out of this case statement
                                break;
                            case 'TYPICAL' :
                                // Set the color to be orangeish
                                $color='#e9a82f';

                                // Break out of this case statement
                                break;
                            default:
                                // Set the color to be redish
                                $color='#ee4462';

                                // Break out of this case statement
                                break;
                        }

                        // Create a query to get the amount of seconds worked in current year
                        $sql = 'SELECT * ' .
                               'FROM employeebenefits ' . 
                               'WHERE UserID=' . $row["UserID"] . ';';
                        
                        // Attempt to get the most recent year seconds worked
                        $innerRow = $db->queryDB($sql, $userRow, "benefits_presentation Form occurance 2");

                        // determine if there is any current time put in
                        if ($innerRow!=null){
                            // Attempt to get the timecard amount row as an ASS
                            $innerAssocRow = $innerRow->fetch_assoc();

                            // Get the date for now
                            $nowDate = date('Y-m-d', strtotime("Now"));
                            
                            // Get the amount of mili-seconds they have currently logged
                            $hoursWorkedThisYear = round($innerAssocRow["HoursWorkedThisYear"],2);
                            $hoursAccruedThisYear = round($innerAssocRow["PTOHoursAccruedThisYear"],2);
                            $ptoBalance = round($innerAssocRow["PTOBalance"],2);
                            $trialPeriod = $innerAssocRow["TrialPeriod"];
                            $lastPayDateUpdated = $innerAssocRow["LastPayDateUpdated"]==null?$nowDate:$innerAssocRow["LastPayDateUpdated"];
                        }
                        
                        // Setup a query to determine years worked
                        $sql='SELECT DATEDIFF("' . $lastPayDateUpdated . '", u.AddDate)/365.25 AS YearsWorked ' .
                             'FROM users u ' .
                             'WHERE u.UserID = ' . $row["UserID"] . ' ' .
                             'AND u.UserLevel <> "TIMECARD ONLY";';

                        // Query the database for the user years worked
                        $yearsWorkedRow = $db->queryDB($sql, $userRow, "benefits_presentation Form occurance 3");

                        // determine if there is a row years worked
                        $yearsWorked=0;
                        if ($yearsWorkedRow!=null){
                            // Attempt to get the years worked row
                            $yearsWorkedAssocRow = $yearsWorkedRow->fetch_assoc();

                            // Set the things we can
                            $yearsWorked = (round($yearsWorkedAssocRow["YearsWorked"],2)<0?0:round($yearsWorkedAssocRow["YearsWorked"],2));
                        }

                        // Determine if this user is on trial period
                        if ($trialPeriod==1){
                            // Set the color to be grey
                            $color='grey';
                        }

                        // Create a query to get employee accrual rate
                        $sql = 'SELECT * ' .
                               'FROM EmployeePTOAccrualRate ' . 
                               'WHERE TenureYearThisStarts <= ' . $yearsWorked . ' ' .
                               'ORDER BY TenureYearThisStarts DESC ' .
                               'LIMIT 1;';

                        // Attempt to accrual rate row
                        $accrualRateRow = $db->queryDB($sql, $userRow, "benefits_presentation Form occurance 4");

                        // determine if there is a row for accrual rate
                        $accrualRate=1;
                        if ($accrualRateRow!=null){
                            // Attempt to get the accrual rate
                            $accrualRateAssocRow = $accrualRateRow->fetch_assoc();

                            // Get the accrual rate of this employee
                            $accrualRate = $accrualRateAssocRow["AccrualRate"];
                        }

                        // Create a query to get the start time closest to the add date (in the future) 
                        // for users that started a long time after added to the TMS.
                        $sql='SELECT StartTime FROM laborclock ' . 
                             'WHERE UserID=' . $row["UserID"] . ' ' .
                             'AND StartTime >= "' . $row["AddDate"] . '" ' .
                             'ORDER BY StartTime ASC ' .
                             'LIMIT 1;';

                        // Get the date they actually started working
                        $dateStartedWorkingRow = $db->queryDB($sql, $userRow, "benefits_presentation Form occurance 5");

                        // Check to see if we have any data back for a date they started working
                        $dateStartedWorking=$row["AddDate"];
                        if ($dateStartedWorkingRow!=null){
                            // Attempt to get the date they a
                            $dateStartedWorkingAssocRow = $dateStartedWorkingRow->fetch_assoc();

                            // Get the date they actually started working
                            $dateStartedWorking = $dateStartedWorkingAssocRow["StartTime"];
                        }

                        // Create the employee start date and the date 6 months ago as a DateTime.
                        $startDate=new DateTime($dateStartedWorking);
                        $sixMonthsAgo=new DateTime('-6 months');
                        $fullNowDate=new DateTime();

                        // Calculate the amount of weeks (approximately, not decimal) they have been working here
                        $workingInterval=$startDate->diff($fullNowDate);
                        $weeksSinceAddedWorking = $workingInterval->days/7;

                        // Get the six month difference amount of days 
                        $sixMonthInterval=$sixMonthsAgo->diff($fullNowDate);
                        $weeksToUseForAverage = $sixMonthInterval->days/7;

                        // Determine if the user has been added longer than 6 months ago, in weeks.
                        // $weeksToUseForAverage is currently set to 6 months in weeks.
                        $dateToUseForQuery=$sixMonthsAgo;
                        if ($weeksSinceAddedWorking<$weeksToUseForAverage){
                            // set the weeks to use for averaging to the amount of weeks working.
                            $weeksToUseForAverage=$weeksSinceAddedWorking;

                            // Set the date to use the date that they started
                            $dateToUseForQuery=$startDate;
                        }

                        // Create the query to get all of the hours worked from this user Since work start or 6 months away
                        $sql='SELECT lc.UserID, ' .
                             'SUM((UNIX_TIMESTAMP(lc.EndTime) - UNIX_TIMESTAMP(lc.StartTime)))/60/60 as HoursWorked ' .
                             'FROM laborclock lc ' .
                             'WHERE lc.StartTime >= "' . $dateToUseForQuery->format('Y-m-d H:i:s') . '" ' .
                             'AND lc.StartTime < "' . $fullNowDate->format('Y-m-d H:i:s') . '" ' .
                             'AND lc.UserID=' . $row["UserID"] . ' ' .
                             'GROUP BY lc.UserID ' .
                             'ORDER BY lc.UserID;';

                        // Get the amount of hours worked in the time period determined
                        $amountOfHoursWorkedRow = $db->queryDB($sql, $userRow, "benefits_presentation Form occurance 6");

                        // Check to see if we have any data back for the amount of hours worked in the time period
                        $averageHoursWorkedPerWeek=0;
                        if ($amountOfHoursWorkedRow!=null){
                            // Attempt to get the amount of hours worked row as an array
                            $amountOfHoursWorkedAssocRow = $amountOfHoursWorkedRow->fetch_assoc();

                            // Get the hours worked per week by taking the amount of hours and dividing it by weeks
                            $averageHoursWorkedPerWeek = $amountOfHoursWorkedAssocRow["HoursWorked"]/$weeksToUseForAverage;
                        }
                        
                        // Determine if we have a number for the average hours
                        $averageHoursWorkedPerWeekHTML=strval(round($averageHoursWorkedPerWeek,2));                            
                        if ($row["UserLevel"]=="SU"){
                            // Set the hours per not applicable
                            $averageHoursWorkedPerWeekHTML="N/A";
                        }
                        else {
                            if (is_nan($averageHoursWorkedPerWeek)==NAN){
                                // Set the hours per week to zero
                                $averageHoursWorkedPerWeekHTML="0";   
                                
                                // Set the average hours back to zero
                                $averageHoursWorkedPerWeek=0;
                            }
                        }

                        // Now determine if this user is allowed Holidays.  Our policy is 30 hours per week average.  Assume full time.
                        $holidayElegibleHTML='background-color:teal;';
                        $holidayElegibleTitle='Employee is eligible for paid holidays because the average hours is over or equal to 30 hours.';
                        if ($averageHoursWorkedPerWeek<30){
                            // Set the background to red
                            $holidayElegibleHTML='background-color:red;';

                            // Set the appropriate title
                            $holidayElegibleTitle='Employee is NOT eligible for paid holidays because the average hours is under 30 hours.';
                        }

                        
                        
                        // Add this option to the select
                        $order=1;
                        $result = $result .
                            '<li id="User_' . $order . '" class="ui-state-default Table" title="Double click to edit/view user." ondblclick="javascript:window.location=\'benefits.php?benefitsUserID=' . $row["UserID"] . '\'">
                                <div class="Row" style="background-color: '. $color . ';" border-style: solid; border-color: '. $color . ';">
                                    <div class="cell nameCell">
                                        <p>' . $row["LastName"] . '</p>
                                    </div>
                                    <div class="cell nameCell">
                                        <p>' . $row["FirstName"] . '</p>
                                    </div>
                                    <div class="cell ptoInfoCell" style="' . $holidayElegibleHTML . '" title="' . $holidayElegibleTitle . '">
                                        <p><b>' . $averageHoursWorkedPerWeekHTML . '</b></p>
                                    </div>
                                    <div class="cell ptoInfoCell">
                                        <p><b>' . $yearsWorked . '</b></p>
                                    </div>
                                    <div class="cell ptoInfoCell">
                                        <p><b>' . $accrualRate . '/30 hrs</b></p>
                                    </div>
                                    <div class="cell ptoInfoCell">
                                        <p><b>' . $hoursWorkedThisYear . ' hrs</b></p>
                                    </div>
                                    <div class="cell ptoInfoCell">
                                        <p><b>' . $hoursAccruedThisYear . ' hrs</b></p>
                                    </div>
                                    <div class="cell ptoInfoCell">
                                        <p><b>' . $ptoBalance . ' hrs</b></p>
                                    </div>
                                </div>
                            </li>';
                    }

                } catch (Exception $ex) {
                    // Assign the output string as to what happened
                    return $result;
                }
            }
            else {

            }
        }

        // Return whatever we got
        return $result;
    }

    function getUserBenefits($db, $userRow, $employeeAssocRow){
        // Set the return to nothing
        $returnValue = '';

        // Determine if there is a timecard user row and a user row or not
        if ($employeeAssocRow!=null &&
            $userRow!=null) {
            // Initialize displayed variables to zero at first
            $hoursWorkedThisYear = 0;
            $hoursAccruedThisYear = 0;
            $ptoBalance = 0;
            $nowDate = date('Y-m-d', strtotime("Now"));
            $trialPeriod=0;

            // Initialize HTML variables
            $editableHTML = 'readonly="readonly"';
            $controlsHiddenStyle = 'display: none;';

            // Fill in any variables that we can from the query
            $companyID = $employeeAssocRow["CompanyID"];

            // Create a query to to get most recent employee benefits information
            $sql = 'SELECT * FROM employeebenefits ' . 
                   'WHERE UserID=' . $employeeAssocRow["UserID"] . ';';

            // Attempt to get the most recent benefits info
            $benefitsRow = $db->queryDB($sql, $userRow, "benefits Form occurance 7");

            // determine if there is a row for the user's benefits.
            if ($benefitsRow!=null){
                // Attempt to get the timecard row
                $benefitsAssocRow = $benefitsRow->fetch_assoc();

                // Set the things we can
                $hoursWorkedThisYear = round($benefitsAssocRow["HoursWorkedThisYear"],2);
                $hoursAccruedThisYear = round($benefitsAssocRow["PTOHoursAccruedThisYear"],2);
                $ptoBalance = round($benefitsAssocRow["PTOBalance"],2);
                $lastPayDateUpdated = $benefitsAssocRow["LastPayDateUpdated"]==null?$nowDate:$benefitsAssocRow["LastPayDateUpdated"];
                $trialPeriod=$benefitsAssocRow["TrialPeriod"];
            }

            // Determine if the trial period got checked
            $trialPeriodHTML='';
            if ($trialPeriod>0){
                // Set it as checked
                $trialPeriodHTML='checked';
            }
            
            // Setup a query to determine years worked
            $sql='SELECT DATEDIFF("' . $lastPayDateUpdated . '", u.AddDate)/365.25 AS YearsWorked ' .
                 'FROM users u ' .
                 'WHERE u.UserID = ' . $employeeAssocRow["UserID"] . ' ' .
                 'AND u.UserLevel <> "TIMECARD ONLY";';

            // Query the database for the user years worked
            $yearsWorkedRow = $db->queryDB($sql, $userRow, "benefits_presentation Form occurance 8");

            // determine if there is a row years worked
            $yearsWorked=0;
            if ($yearsWorkedRow!=null){
                // Attempt to get the years worked row
                $yearsWorkedAssocRow = $yearsWorkedRow->fetch_assoc();

                // Set the things we can
                $yearsWorked = (round($yearsWorkedAssocRow["YearsWorked"],2)<0?0:round($yearsWorkedAssocRow["YearsWorked"],2));
            }

            // Create a query to get employee accrual rate
            $sql = 'SELECT * ' .
                   'FROM EmployeePTOAccrualRate ' . 
                   'WHERE TenureYearThisStarts <= ' . $yearsWorked . ' ' .
                   'ORDER BY TenureYearThisStarts DESC ' .
                   'LIMIT 1;';

            // Attempt to accrual rate row
            $accrualRateRow = $db->queryDB($sql, $userRow, "benefits_presentation Form occurance 9");

            // determine if there is a row for accrual rate
            $accrualRate=1;
            $maxAnnually=80;
            $maxOverall=120;
            if ($accrualRateRow!=null){
                // Attempt to get the accrual rate
                $accrualRateAssocRow = $accrualRateRow->fetch_assoc();

                // Fill the variables in properly now
                $accrualRate = $accrualRateAssocRow["AccrualRate"];
                $maxAnnually=$accrualRateAssocRow["MaxAnnually"];
                $maxOverall=$accrualRateAssocRow["MaxOverallPTO"];
            }

            // Create a query to get when they will get the next level
            $sql = 'SELECT (TenureYearThisStarts-' . $yearsWorked . ') AS YearsUntilNextLevel ' .
                   'FROM EmployeePTOAccrualRate ' . 
                   'WHERE AccrualRate > ' . $accrualRate . ' ' .
                   'ORDER BY TenureYearThisStarts ' .
                   'LIMIT 1;';

            // Attempt to accrual rate row
            $yearsUntilNextLevelRow = $db->queryDB($sql, $userRow, "benefits_presentation Form occurance 10");

            // Determine if there is a years until next level row
            $yearsUntilNextLevel="Unknown";
            if ($yearsUntilNextLevelRow!=null){
                // Attempt to get the accrual rate
                $yearsUntilNextLevelAssocRow = $yearsUntilNextLevelRow->fetch_assoc();

                // Fill the variables in properly now
                $yearsUntilNextLevel = $yearsUntilNextLevelAssocRow["YearsUntilNextLevel"];
            }

            // Determine if we have a super user or the bonus user's executive looking at it
            if ($userRow["UserLevel"]=='SU' ||
                ($userRow["UserLevel"]=='EXECUTIVE' &&
                 $userRow["CompanyID"]==$companyID)){
                // Allow for edits
                $editableHTML='';

                // Show controls
                $controlsHiddenStyle = 'display: table-row;';
            }

            // Create a query to get the start time closest to the add date (in the future) 
            // for users that started a long time after added to the TMS.
            $sql='SELECT StartTime FROM laborclock ' . 
                 'WHERE UserID=' . $employeeAssocRow["UserID"] . ' ' .
                 'AND StartTime >= "' . $employeeAssocRow["AddDate"] . '" ' .
                 'ORDER BY StartTime ASC ' .
                 'LIMIT 1;';

            // Get the date they actually started working
            $dateStartedWorkingRow = $db->queryDB($sql, $userRow, "benefits_presentation Form occurance 11");

            // Check to see if we have any data back for a date they started working
            $dateStartedWorking=$employeeAssocRow["AddDate"];
            if ($dateStartedWorkingRow!=null){
                // Attempt to get the date they a
                $dateStartedWorkingAssocRow = $dateStartedWorkingRow->fetch_assoc();

                // Get the date they actually started working
                $dateStartedWorking = $dateStartedWorkingAssocRow["StartTime"];
            }
            
            // Create the employee start date and the date 6 months ago as a DateTime.
            $startDate=new DateTime($dateStartedWorking);
            $sixMonthsAgo=new DateTime('-6 months');
            $fullNowDate=new DateTime();
            
            // Calculate the amount of weeks (approximately, not decimal) they have been working here
            $workingInterval=$startDate->diff($fullNowDate);
            $weeksSinceAddedWorking = $workingInterval->days/7;
            
            // Get the six month difference amount of days 
            $sixMonthInterval=$sixMonthsAgo->diff($fullNowDate);
            $weeksToUseForAverage = $sixMonthInterval->days/7;
            
            // Determine if the user has been added longer than 6 months ago, in weeks.
            // $weeksToUseForAverage is currently set to 6 months in weeks.
            $dateToUseForQuery=$sixMonthsAgo;
            if ($weeksSinceAddedWorking<$weeksToUseForAverage){
                // set the weeks to use for averaging to the amount of weeks working.
                $weeksToUseForAverage=$weeksSinceAddedWorking;
                
                // Set the date to use the date that they started
                $dateToUseForQuery=$startDate;
            }
            
            // Create the query to get all of the hours worked from this user Since work start or 6 months away
            $sql='SELECT lc.UserID, ' .
                 'SUM((UNIX_TIMESTAMP(lc.EndTime) - UNIX_TIMESTAMP(lc.StartTime)))/60/60 as HoursWorked ' .
                 'FROM laborclock lc ' .
                 'WHERE lc.StartTime >= "' . $dateToUseForQuery->format('Y-m-d H:i:s') . '" ' .
                 'AND lc.StartTime < "' . $fullNowDate->format('Y-m-d H:i:s') . '" ' .
                 'AND lc.UserID=' . $employeeAssocRow["UserID"] . ' ' .
                 'GROUP BY lc.UserID ' .
                 'ORDER BY lc.UserID;';
            
            // Get the amount of hours worked in the time period determined
            $amountOfHoursWorkedRow = $db->queryDB($sql, $userRow, "benefits_presentation Form occurance 12");

            // Check to see if we have any data back for the amount of hours worked in the time period
            $averageHoursWorkedPerWeek=0;
            if ($amountOfHoursWorkedRow!=null){
                // Attempt to get the amount of hours worked row as an array
                $amountOfHoursWorkedAssocRow = $amountOfHoursWorkedRow->fetch_assoc();

                // Get the hours worked per week by taking the amount of hours and dividing it by weeks
                $averageHoursWorkedPerWeek = $amountOfHoursWorkedAssocRow["HoursWorked"]/$weeksToUseForAverage;
            }
            
            // Determine if we have a number for the average hours
            $averageHoursWorkedPerWeekHTML=strval(round($averageHoursWorkedPerWeek,2));                            
            if ($employeeAssocRow["UserLevel"]=="SU"){
                // Set the hours per not applicable
                $averageHoursWorkedPerWeekHTML="N/A";
            }
            else {
                if (is_nan($averageHoursWorkedPerWeek)==NAN){
                    // Set the hours per week to zero
                    $averageHoursWorkedPerWeekHTML="0";                            
                                
                    // Set the average hours back to zero
                    $averageHoursWorkedPerWeek=0;
                }
            }

            // Now determine if this user is allowed Holidays.  Our policy is 30 hours per week average.  Assume full time.
            $holidayElegibleHTML='background-color:teal;';
            $holidayElegibleTitle='Employee is eligible for paid holidays because the average hours is over or equal to 30 hours.';
            if ($averageHoursWorkedPerWeek<30){
                // Set the background to red
                $holidayElegibleHTML='background-color:red;';
                
                // Set the appropriate title
                $holidayElegibleTitle='Employee is NOT eligible for paid holidays because the average hours is under 30 hours.';
            }

            $returnValue = '
                <form action="benefits.php" method="post" name="benefits" enctype="multipart/form-data" title="' . $holidayElegibleTitle . '" style="' . $holidayElegibleHTML . '">  
                    <p style="font-size: 26px; text-align: center;">
                        <font>Benefits Summary for ' . $employeeAssocRow["FirstName"] . ' ' . $employeeAssocRow["LastName"] . '</font> 
                        <input type="hidden" name="UserID" id="UserID" value="' . $employeeAssocRow["UserID"] . '"/>
                        <input type="hidden" name="formSubmitted" value="TRUE">
                    </p>
                    <table width="100%" border="0" cellspacing="0" cellpadding="0">
                        <tr align="middle" valign="top">
                            <td width="50%" valign="top" align="left">
                                <table width="100%" border="0" cellspacing="0" cellpadding="0">
                                    <tr align="middle" valign="top">
                                        <td width="65%" valign="top" align="right">
                                            <strong>Hours Worked This Year:</strong> 
                                        </td>
                                        <td width="2%" valign="middle" align="top">
                                        </td>
                                        <td width="33%" valign="top" align="left">
                                            <input name="hoursWorkedThisYear" id="hoursWorkedThisYear" type="text" maxlength="15" class="intext" style="width: 100%;" value="' . $hoursWorkedThisYear . '" ' . $editableHTML . '>
                                            <br><br>
                                        </td>
                                    </tr>
                                    <tr align="middle" valign="top">
                                        <td width="65%" valign="top" align="right">
                                            <strong>PTO Hours Accrued This Year:</strong> 
                                        </td>
                                        <td width="2%" valign="middle" align="top">
                                        </td>
                                        <td width="33%" valign="top" align="left">
                                            <input name="ptoHoursAccruedThisYear" id="ptoHoursAccruedThisYear" type="text" maxlength="15" class="intext" style="width: 100%;" value="' . $hoursAccruedThisYear . '" ' . $editableHTML . '>
                                            <br><br>
                                        </td>
                                    </tr>
                                    <tr align="middle" valign="top">
                                        <td width="65%" valign="top" align="right">
                                            <strong>PTO Hours Balance:</strong> 
                                        </td>
                                        <td width="2%" valign="middle" align="top">
                                        </td>
                                        <td width="33%" valign="top" align="left">
                                            <input name="ptoBalance" id="ptoBalance" type="text" maxlength="15" class="intext" style="width: 100%;" value="' . $ptoBalance . '" ' . $editableHTML . '>
                                            <br><br>
                                        </td>
                                    </tr>
                                    <tr align="middle" valign="top">
                                        <td width="65%" valign="top" align="right">
                                            <strong>Last Pay Period Added:</strong> 
                                        </td>
                                        <td width="2%" valign="middle" align="top">
                                        </td>
                                        <td width="33%" valign="top" align="left">
                                            <input name="lastPayDate" id="lastPayDate" type="datetime-local" step=1 class="intext" style="width: 100%;"  ' . $editableHTML . ' value="' . str_replace(" ","T",$lastPayDateUpdated) . '" />
                                            <br><br>
                                        </td>
                                    </tr>
                                    <tr align="middle" valign="top" style="' . $controlsHiddenStyle . '">
                                        <td width="65%" valign="top" align="right">
                                            <strong>Trial Period:</strong> 
                                        </td>
                                        <td width="2%" valign="middle" align="top">
                                        </td>
                                        <td width="33%" valign="top" align="left">
                                            <input type="checkbox" id="trialPeriod" name="trialPeriod" title="If checked, this user is on a trial period." ' . $trialPeriodHTML . '></input>
                                            <br><br>
                                        </td>
                                    </tr>
                                </table>
                            </td>
                            <td width="50%" valign="top" align="left">
                                <table width="100%" border="0" cellspacing="0" cellpadding="0">
                                    <tr align="middle" valign="top" Title="Years work at the start of the last pay period.">
                                        <td width="65%" valign="top" align="right">
                                            <strong>Years Worked:</strong> 
                                        </td>
                                        <td width="2%" valign="middle" align="top">
                                        </td>
                                        <td width="33%" valign="top" align="left">
                                            ' . $yearsWorked . ' Years
                                            <br><br>
                                        </td>
                                    </tr>
                                    <tr align="middle" valign="top">
                                        <td width="65%" valign="top" align="right">
                                            <strong>Years Until Next Benefits Tier:</strong> 
                                        </td>
                                        <td width="2%" valign="middle" align="top">
                                        </td>
                                        <td width="33%" valign="top" align="left">
                                            ' . $yearsUntilNextLevel . ' Years
                                            <br><br>
                                        </td>
                                    </tr>
                                    <tr align="middle" valign="top">
                                        <td width="65%" valign="top" align="right">
                                            <strong>Accrual Rate:</strong> 
                                        </td>
                                        <td width="2%" valign="middle" align="top">
                                        </td>
                                        <td width="33%" valign="top" align="left">
                                            ' . $accrualRate . '/30 hrs
                                            <br><br>
                                        </td>
                                    </tr>
                                    <tr align="middle" valign="top">
                                        <td width="65%" valign="top" align="right">
                                            <strong>Max PTO Annually:</strong> 
                                        </td>
                                        <td width="2%" valign="middle" align="top">
                                        </td>
                                        <td width="33%" valign="top" align="left">
                                            ' . $maxAnnually . ' Hours
                                            <br><br>
                                        </td>
                                    </tr>
                                    <tr align="middle" valign="top">
                                        <td width="65%" valign="top" align="right">
                                            <strong>Max PTO Overall:</strong> 
                                        </td>
                                        <td width="2%" valign="middle" align="top">
                                        </td>
                                        <td width="33%" valign="top" align="left">
                                            ' . $maxOverall . ' Hours
                                            <br><br>
                                        </td>
                                    </tr>
                                    <tr align="middle" valign="top">
                                        <td width="65%" valign="top" align="right">
                                            <strong>Average Weekly Hours Worked:</strong> 
                                        </td>
                                        <td width="2%" valign="middle" align="top">
                                        </td>
                                        <td width="33%" valign="top" align="left">
                                            ' . $averageHoursWorkedPerWeekHTML . ' Hours
                                            <br><br>
                                        </td>
                                    </tr>
                                </table>
                            </td>
                        </tr>
                        <tr align="middle" valign="top">
                            <td colspan=2 valign="bottom" align="center">
                                <input name="formSubmit" id="formSubmit" type="submit" onclick="this.disabled=true; this.form.submit();}" style="pointer-events: auto; cursor: hand; ' . $controlsHiddenStyle . '" value="Update Benefits" title="Save benefits to the database."/>
                            </td>
                        </tr>
                    </table>
                </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("benefits", "formSubmit");
                    frmvalidator.addValidation("hoursWorkedThisYear",
                                               "dec",
                                               "The hours worked for the year should be a decimal.");
                    frmvalidator.addValidation("ptoHoursAccruedThisYear",
                                               "dec",
                                               "The PTO Hours Accrued for the year should be a decimal.");
                    frmvalidator.addValidation("ptoBalance",
                                               "dec",
                                               "The PTO Balance should be a decimal.");
                </script>';
        }

        // Return whatever was created
        return $returnValue;
    }
?>
