<?php
    function createCutTypeRadioButton($controlName, $associatedControlName, $clean, $precise, $blankID, $disabledHTML){
        // Initialize the return HTML
        $returnHTML = '';

        // Set the value for the select boxes to be the first one for now
        $radioRoughHTML = '<input ' . $disabledHTML . ' type="radio" OnClick="javascript:addBorder(\'' . 
                              $associatedControlName . $blankID . '\', \'#00b33c\');" name="' . 
                              $controlName . $blankID . '" id="' . $controlName . $blankID . 
                              '" value="Rough"/>';
        $radioCleanHTML = '<input ' . $disabledHTML . ' type="radio" OnClick="javascript:addBorder(\'' . 
                              $associatedControlName . $blankID . '\', \'#ffcc00\');" name="' . 
                              $controlName . $blankID . '" id="' . $controlName . $blankID . 
                              '" value="Clean"/>';
        $radioPreciseHTML = '<input ' . $disabledHTML . ' type="radio" OnClick="javascript:addBorder(\'' . 
                              $associatedControlName . $blankID . '\', \'#e62e00\');" name="' . 
                              $controlName . $blankID . '" id="' . $controlName . $blankID . 
                              '" value="Precise"/>';

        // Determine the state of the checks to determine the radio 
        // button value for the first Dimension
        if ($clean){
            // This is the selected one
            $radioCleanHTML = '<input ' . $disabledHTML . ' type="radio" OnClick="javascript:addBorder(\'' . 
                              $associatedControlName . $blankID . '\', \'#ffcc00\');" name="' . 
                              $controlName . $blankID . '" id="' . $controlName . $blankID . 
                              '" value="Clean" checked="checked"/>';
        }
        else if ($precise){
            // This is the selected one
            $radioPreciseHTML = '<input ' . $disabledHTML . ' type="radio" OnClick="javascript:addBorder(\'' . 
                              $associatedControlName . $blankID . '\', \'#e62e00\');" name="' . 
                              $controlName . $blankID . '" id="' . $controlName . $blankID . 
                              '" value="Precise" checked="checked"/>';
        }
        else {
            // This is the selected one
            $radioRoughHTML = '<input ' . $disabledHTML . ' type="radio" OnClick="javascript:addBorder(\'' . 
                              $associatedControlName . $blankID . '\', \'#00b33c\');" name="' . 
                              $controlName . $blankID . '" id="' . $controlName . $blankID . 
                              '" value="Rough" checked="checked"/>';
        }

        // Now build it
        $returnHTML = '
            <label>Rough</label>
              ' . $radioRoughHTML . '
            <label>Clean</label>
              ' . $radioCleanHTML . '
            <label>Precise</label>
              ' . $radioPreciseHTML . '
            ';

        // Return the HTML
        return $returnHTML;
    }

    function createGenericTypeRadioButton($controlName, $associatedControlName, $clean, $precise){
        // Initialize the return HTML
        $returnHTML = '';

        // Set the value for the select boxes to be the first one for now
        $radioRoughHTML = '<input type=\'radio\' OnClick=\'javascript:addBorder(\"' . 
                              $associatedControlName . '\", \"#00b33c\");\' name=\'' . $controlName . '\'' . 
                              ' id=\'' . $controlName . '\' value=\'Rough\'/>';
        $radioCleanHTML = '<input type=\'radio\' OnClick=\'javascript:addBorder(\"' . 
                              $associatedControlName . '\", \"#ffcc00\");\' name=\'' . $controlName . '\'' . 
                              ' id=\'' . $controlName . '\' value=\'Clean\'/>';
        $radioPreciseHTML = '<input type=\'radio\' OnClick=\'javascript:addBorder(\"' . 
                              $associatedControlName . '\", \"#e62e00\");\' name=\'' . $controlName . '\'' . 
                              ' id=\'' . $controlName . '\' value=\'Precise\'/>';

        // Determine the state of the checks to determine the radio 
        // button value for the first Dimension
        if ($clean){
            // This is the selected one
            $radioCleanHTML = '<input type=\'radio\' OnClick=\'javascript:addBorder(\"' . 
                              $associatedControlName . '\", \"#ffcc00\");\' name=\'' . $controlName . '\'' . 
                              ' id=\'' . $controlName . '\' value=\'Clean\' ' . 
                              'checked=\'checked\'/>';
        }
        else if ($precise){
            // This is the selected one
            $radioPreciseHTML = '<input type=\'radio\' OnClick=\'javascript:addBorder(\"' . 
                              $associatedControlName . '\", \"#e62e00\");\' name=\'' . $controlName . '\'' . 
                              ' id=\'' . $controlName . '\' value=\'Precise\' ' . 
                              'checked=\'checked\'/>';
        }
        else {
            // This is the selected one
            $radioRoughHTML = '<input type=\'radio\' OnClick=\'javascript:addBorder(\"' . 
                              $associatedControlName . '\", \"#00b33c\");\' name=\'' . $controlName . '\'' . 
                              ' id=\'' . $controlName . '\' value=\'Rough\' ' . 
                              'checked=\'checked\'/>';
        }

        // Now build it
        $returnHTML = '<label>Rough</label>' . $radioRoughHTML . '<label>Clean</label>' . $radioCleanHTML . '<label>Precise</label>' . $radioPreciseHTML;

        // Return the HTML
        return $returnHTML;
    }

    function createJavaArrayOfMaterialAsSelectOptions($db, $userRow, $addAllOption){
        // Initialize the return
        $result = '';

        try {
            // Determine if the ALL option is added
            if ($addAllOption) {
                // Add ALL to the beginning array
                $result = '<option value=\'-1\'>ALL MATERIAL</option>,';
            }

            // Create the query to run
            $sql='SELECT * FROM material ORDER BY LOWER(Category), LOWER(Name);';

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

            // Ensure we got rows back.
            if ($rows == null){
                return '';
            }
            else{
                // Create a variable outside the loop ro keep track of changing categories
                $loopCategory='';

                // Loop through the returned results
                while ($row=mysqli_fetch_array($rows)){
                    // Determine if the category has changed
                    if ($loopCategory!=$row["Category"]){
                        // Change the current category that we are populating
                        $loopCategory=$row["Category"];

                        // Make a group for this category
                        $result=$result . '<optgroup label=\'' . $loopCategory . '\'>';
                    }

                    // Determine if this option is the one they have as default and make it checked
                    $isDefaultHTML='';
                    if ($row["NewBlankDropDownDefault"]==1){
                        // Set this as the selected one
                        $isDefaultHTML='selected';
                    }

                    // Add this option to the select
                    $result=$result . '<option value=\'' . $row["MaterialID"] . '\' ' . $isDefaultHTML . '>' . $row["Category"] . ' - ' .$row["Name"] . '</option>,';
                }
            }
        } catch (Exception $ex) {
            // Assign the output string as to what happened
            return '';
        }

        // Determine if there is a string created
        if ($result!=''){
            // Remove the last comma
            $result=substr($result ,0,-1);
        }

        // Return whatever we got
        return 'var AvailableMaterialsAsSelectOptions="' . $result . '";';
    }

    function createJavaArrayOfMaterialTypesAsSelectOptions ($db, $userRow, $addAllOption, $selected){
        // Initialize the return
        $result = '';

        try {
            // Attempt to get the type array from the database table field
            $typesEnumArray = $db->getTypeAsArray('materialstock', 'Type', $addAllOption);

            // Loop through values, clean them up and create options
            foreach($typesEnumArray as $key => $loopType) {
                // Trim it down
                $loopType=trim($loopType, "'");

                // Determine what this one is selected
                if ($loopType==$selected){
                    // Set this as the selected one
                    $selectedText = "selected";
                }

                // Add this option
                $result = '<option value=\'' . $loopType . '\' ' . $selectedText . '>' . $loopType . '</option>,' . $result;
            }
        } catch (Exception $ex) {
            // Assign the output string as to what happened
            return '';
        }

        // Determine if there is a string created
        if ($result!=''){
            // Remove the last comma
            $result=substr($result ,0,-1);
        }

        // Return whatever we got
        return 'var AvailableMaterialTypesAsSelectOptions="' . $result . '";';
    }

    function RecommendTubeBlankStock($db, $userRow, $assocBlank){
        // Set the return result to be as though there is no recommendation
        $result = '<br><br>Recommendations:<br>There is NO ONE in-stock material that will work to create ALL of these blanks. ';

        try {
            // Category = 'Titanium','Steel','Stainless Steel','Plastic','Other','Glass','Ceramic','Cast Iron','Aluminum','Acrylic'
            // Type = 'Tube','Round','Plate','Other','Extrusion','Cast'        

            // Init the dimensions to negative numbers
            $diameter = -1;
            $idealDimensionCut = -1;
            $bladeThickness = 0.04;

            // Determinewhich dimension is the cut dimension
            switch ($assocBlank["QuantityDimension"]){
                case 'Dimension 1':
                    // Set the cut dimension to be the blank amount multiplied by length
                    $idealDimensionCut = ($assocBlank["Dimension1"] + $bladeThickness) * $assocBlank["Quantity"];

                    // Set one of the dimensions to go for as the diameter. They should set both.
                    $diameter = $assocBlank["Dimension2"];

                    break;
                case 'Dimension 2':
                    // Set the cut dimension to be the blank amount multiplied by length
                    $idealDimensionCut = ($assocBlank["Dimension2"] + $bladeThickness) * $assocBlank["Quantity"];

                    // Set one of the dimensions to go for as the diameter. They should set both.
                    $diameter = $assocBlank["Dimension1"];

                    break;
                case 'Dimension 3':
                    // Set the cut dimension to be the blank amount multiplied by length
                    $idealDimensionCut = ($assocBlank["Dimension3"] + $bladeThickness) * $assocBlank["Quantity"];

                    // Set one of the dimensions to go for as the diameter. They should set both.
                    $diameter = $assocBlank["Dimension1"];

                    break;
                default:
                    // Leave the method because this is an invalid state
                    return '<br><br>Recommendations:<br>A dimension for quantity was not specified, so the query cannot be done.';
            }

            // Create the initial query of the material table for the material to recommend
            $sqlInitial = 'SELECT ms.*, m.Category, m.Description, m.Name AS MaterialName ' .
                          'FROM materialstock ms ' . 
                          'LEFT JOIN material m ON ms.MaterialID = m.MaterialID ' .
                          'WHERE ms.MaterialID=' . $assocBlank["MaterialID"] . ' ' .
                          'AND   ms.Type = "' . $assocBlank["Type"] . '" ' .
                          'AND   ms.Amount >= ' . $idealDimensionCut . ' ' .
                          'AND   ms.Diameter >= ' . ($diameter-0.02) . ' ' .
                          'AND   ms.Diameter <= ' . ($diameter+0.02) . ' ' .
                          'AND   ms.WallThickness >= ' . ($assocBlank["WallThickness"]-0.008) . ' ' .
                          'AND   ms.WallThickness <= ' . ($assocBlank["WallThickness"]+0.008) . ';';

            // Run the query
            $recommendation = $db->queryDB($sqlInitial, $userRow, "blank_presentation Form occurance 8.");

            // Determine if there are any rows before attempting to loop through them
            if ($recommendation != null && 
                mysqli_num_rows($recommendation)>0){
                // Let them know that there IS stock
                $result = '<br><br>Recommendations:<br>There IS enough stock in house for this job.';
            }
        } catch (Exception $ex) {
            // Set the return result to an error state
            $result='<br><br>Recommendations:<br>There was an error executing the query';

            // Assign the output string as to what happened
            return $result;
        }

        // Return the created HTML
        return $result;
    }

    function RecommendRoundsBlankStock($db, $userRow, $assocBlank){
        // Set the return result to be as though there is no recommendation
        $result = '<br><br>Recommendations:<br>There is NO ONE in-stock material that will work to create ALL of these blanks. ';

        try {
            // Category = 'Titanium','Steel','Stainless Steel','Plastic','Other','Glass','Ceramic','Cast Iron','Aluminum','Acrylic'
            // Type = 'Tube','Round','Plate','Other','Extrusion','Cast'        

            // Init the dimensions to negative numbers
            $diameter = -1;
            $idealDimensionCut = -1;
            $bladeThickness = 0.04;

            // Determine which dimension is the cut dimension
            switch ($assocBlank["QuantityDimension"]){
                case 'Dimension 1':
                    // Set the cut dimension to be the blank amount multiplied by length
                    $idealDimensionCut = ($assocBlank["Dimension1"] + $bladeThickness) * $assocBlank["Quantity"];

                    // Set one of the dimensions to go for as the diameter. They should set both.
                    $diameter = $assocBlank["Dimension2"];

                    break;
                case 'Dimension 2':
                    // Set the cut dimension to be the blank amount multiplied by length
                    $idealDimensionCut = ($assocBlank["Dimension2"] + $bladeThickness) * $assocBlank["Quantity"];

                    // Set one of the dimensions to go for as the diameter. They should set both.
                    $diameter = $assocBlank["Dimension1"];

                    break;
                case 'Dimension 3':
                    // Set the cut dimension to be the blank amount multiplied by length
                    $idealDimensionCut = ($assocBlank["Dimension3"] + $bladeThickness) * $assocBlank["Quantity"];

                    // Set one of the dimensions to go for as the diameter. They should set both.
                    $diameter = $assocBlank["Dimension1"];

                    break;
                default:
                    // Leave the method because this is an invalid state
                    return '<br><br>Recommendations:<br>A dimension for quantity was not specified, so the query cannot be done.';
            }

            // Create the initial query of the material table for the material to recommend
            $sqlInitial = 'SELECT ms.*, m.Category, m.Description, m.Name AS MaterialName ' .
                          'FROM materialstock ms ' . 
                          'LEFT JOIN material m ON ms.MaterialID = m.MaterialID ' .
                          'WHERE ms.MaterialID=' . $assocBlank["MaterialID"] . ' ' .
                          'AND   ms.Type = "' . $assocBlank["Type"] . '" ' .
                          'AND   ms.Amount >= ' . $idealDimensionCut . ' ' .
                          'AND   ms.Diameter >= ' . ($diameter-0.02) . ' ' .
                          'AND   ms.Diameter <= ' . ($diameter+0.52) . ' ' .
                          'ORDER BY ms.Diameter;';

            // Run the query
            $recommendation = $db->queryDB($sqlInitial, $userRow, "blank_presentation Form occurance 8.");

            // Determine if there are any rows before attempting to loop through them
            if ($recommendation != null && 
                mysqli_num_rows($recommendation)>0){
                // Loop through the returned results to create the selections
                $amount=0;
                while ($recommendation1=mysqli_fetch_array($recommendations1)){
                    // Increase the amount recorded
                    $amount++;

                    // Add to the result string
                    $result = $result . '<a href="https://www.eestms.com/' . getTMSHome() . '/updateStockedMaterial.php?updateStockedMaterialID=' . 
                              $recommendation1["MaterialStockID"] . '">' . $amount . ') ' . htmlspecialchars_decode($recommendation1["Name"]) . '</a><br>';

                    // Determine if we are at the third one yet
                    if ($amount==3){
                        // Break out of this loop because we only want three
                        break;
                    }
                }

                // Complete the least waste string
                $result = '<br><br>The top blank candidates recommendations are listed here in order of LEAST WASTE.<br>' . $result;
            }
        } catch (Exception $ex) {
            // Set the return result to an error state
            $result='<br><br>Recommendations:<br>There was an error executing the query';

            // Assign the output string as to what happened
            return $result;
        }

        // Return the created HTML
        return $result;
    }

    function RecommendOtherBlankStock($db, $userRow, $blank){
        // Set the return result to be what is returned
        $result='<br><br>This blank type is setup as \'other\', so a recommendation query will not be run. ' .
                'Just look for the blank in the most efficient way.';

        // Return the created HTML
        return $result;
    }

    function RecommendExtrusionBlankStock($db, $userRow, $assocBlank){
        // Set the return result to be as though there is no recommendation
        $result = '<br><br>Recommendations:<br>There is NO ONE in-stock material that will work to create ALL of these blanks. ';

        // initialize the seperate query results
        $resultLeastWaste = '';
        $resultClosestCleanDimension1 = '';
        $resultClosestCleanDimension2 = '';

        try {
            // Category = 'Titanium','Steel','Stainless Steel','Plastic','Other','Glass','Ceramic','Cast Iron','Aluminum','Acrylic'
            // Type = 'Tube','Round','Plate','Other','Extrusion','Cast'        

            // Init the dimensions to negative numbers
            $idealDimension1 = -1;
            $idealDimension2 = -1;
            $idealDimensionCut = -1;
            $bladeThickness = 0.04;

            // Determinewhich dimension is the cut dimension
            switch ($assocBlank["QuantityDimension"]){
                case 'Dimension 1':
                    // Set the cut dimension to be the blank amount multiplied by length
                    $idealDimensionCut = ($assocBlank["Dimension1"] + $bladeThickness) * $assocBlank["Quantity"];

                    // Set the dimensions to go for as the other dimensions
                    $idealDimension1 = $assocBlank["Dimension2"];
                    $idealDimension2 = $assocBlank["Dimension3"];

                    // Determine if the dimension 2 is precise
                    if ($assocBlank["Dimension2Precise"]){
                        // Add 1/8th of an inch to this dimension for surfacing
                        $idealDimension1 += 0.125;
                    }

                    // Determine if the dimension 3 is precise
                    if ($assocBlank["Dimension3Precise"]){
                        // Add 1/8th of an inch to this dimension for surfacing
                        $idealDimension2 += 0.125;
                    }

                    break;
                case 'Dimension 2':
                    // Set the cut dimension to be the blank amount multiplied by length
                    $idealDimensionCut = ($assocBlank["Dimension2"] + $bladeThickness) * $assocBlank["Quantity"];

                    // Set the dimensions to go for as the other dimensions
                    $idealDimension1 = $assocBlank["Dimension1"];
                    $idealDimension2 = $assocBlank["Dimension3"];

                    // Determine if the dimension 1 is precise
                    if ($assocBlank["Dimension1Precise"]){
                        // Add 1/8th of an inch to this dimension for surfacing
                        $idealDimension1 += 0.125;
                    }

                    // Determine if the dimension 3 is precise
                    if ($assocBlank["Dimension3Precise"]){
                        // Add 1/8th of an inch to this dimension for surfacing
                        $idealDimension2 += 0.125;
                    }

                    break;
                case 'Dimension 3':
                    // Set the cut dimension to be the blank amount multiplied by length
                    $idealDimensionCut = ($assocBlank["Dimension3"] + $bladeThickness) * $assocBlank["Quantity"];

                    // Set the dimensions to go for as the other dimensions
                    $idealDimension1 = $assocBlank["Dimension1"];
                    $idealDimension2 = $assocBlank["Dimension2"];

                    // Determine if the dimension 1 is precise
                    if ($assocBlank["Dimension1Precise"]){
                        // Add 1/8th of an inch to this dimension for surfacing
                        $idealDimension1 += 0.125;
                    }

                    // Determine if the dimension 2 is precise
                    if ($assocBlank["Dimension2Precise"]){
                        // Add 1/8th of an inch to this dimension for surfacing
                        $idealDimension2 += 0.125;
                    }

                    break;
                default:
                    // Leave the method because this is an invalid state
                    return '<br><br>Recommendations:<br>A dimension for quantity was not specified, so the query cannot be done.';
            }

            // Create the initial query of the material table for the material to recommend
            $sqlInitial = 'SELECT ms.*, (ms.Dimension1 * ms.Dimension2) AS Area, m.Category, m.Description, m.Name AS MaterialName ' .
                          'FROM materialstock ms ' . 
                          'LEFT JOIN material m ON ms.MaterialID = m.MaterialID ' .
                          'WHERE ms.MaterialID=' . $assocBlank["MaterialID"] . ' ' .
                          'AND   ms.Type = "' . $assocBlank["Type"] . '" ' .
                          'AND   ms.Amount >= ' . $idealDimensionCut . ' ' .
                          'AND   ( 
                                   (ms.Dimension1 >= ' . $idealDimension1 . ' AND ms.Dimension2 >= ' . $idealDimension2 . ') 
                                   OR
                                   (ms.Dimension1 >= ' . $idealDimension2 . ' AND ms.Dimension2 >= ' . $idealDimension1 . ') 
                                 ) ';

            // Order the query by area first
            $sql = $sqlInitial . 'ORDER BY Area, ms.Dimension1, ms.Dimension2;';

            // Run the query
            $recommendations1 = $db->queryDB($sql, $userRow, "blank_presentation Form occurance 8.");

            // Determine if there are any rows before attempting to loop through them
            if ($recommendations1 != null && 
                mysqli_num_rows($recommendations1)>0){

                // Loop through the returned results to create the selections
                $amount=0;
                while ($recommendation1=mysqli_fetch_array($recommendations1)){
                    // Increase the amount recorded
                    $amount++;

                    // Add to the result string
                    $resultLeastWaste = $resultLeastWaste . '<a href="https://www.eestms.com/' . getTMSHome() . '/updateStockedMaterial.php?updateStockedMaterialID=' . 
                                        $recommendation1["MaterialStockID"] . '">' . $amount . ') ' . htmlspecialchars_decode($recommendation1["Name"]) . '</a><br>';

                    // Determine if we are at the third one yet
                    if ($amount==3){
                        // Break out of this loop because we only want three
                        break;
                    }
                }

                // Complete the least waste string
                $resultLeastWaste = '<br><br>The top blank candidates recommendations are listed here in order of LEAST WASTE.<br>' . $resultLeastWaste;
            }

            // Order the query by dimension 1 first
            $sql = $sqlInitial . 'ORDER BY ms.Dimension1, ms.Dimension2, Area;';

            // Run the query
            $recommendations2 = $db->queryDB($sql, $userRow, "blank_presentation Form occurance 8.");

            // Determine if there are any rows before attempting to loop through them
            if ($recommendations2 != null && 
                mysqli_num_rows($recommendations2)>0){

                // Loop through the returned results to create the selections
                $amount=0;
                while ($recommendation2=mysqli_fetch_array($recommendations2)){
                    // Increase the amount recorded
                    $amount++;

                    // Add to the result string
                    $resultClosestCleanDimension1 = $resultClosestCleanDimension1 . '<a href="https://www.eestms.com/' . getTMSHome() . '/updateStockedMaterial.php?updateStockedMaterialID=' . 
                                                         $recommendation2["MaterialStockID"] . '">' . $amount . ') ' . htmlspecialchars_decode($recommendation2["Name"]) . '</a><br>';

                    // Determine if we are at the third one yet
                    if ($amount==3){
                        // Break out of this loop because we only want three
                        break;
                    }
                }

                    // Complete the dimension 1 string
                    $resultClosestCleanDimension1 = '<br><br>The top blank candidates are listed here in order of DIMENSION 1.<br>' . $resultClosestCleanDimension1;
                }

                // Order the query by dimension 2 first
                $sql = $sqlInitial . 'ORDER BY ms.Dimension2, ms.Dimension1, Area;';

                // Run the query
                $recommendations3 = $db->queryDB($sql, $userRow, "blank_presentation Form occurance 8.");

            // Determine if there are any rows before attempting to loop through them
            if ($recommendations3 != null && 
                mysqli_num_rows($recommendations3)>0){

                // Loop through the returned results to create the selections
                $amount=0;
                while ($recommendation3=mysqli_fetch_array($recommendations3)){
                    // Increase the amount recorded
                    $amount++;

                    // Add to the result string
                    $resultClosestCleanDimension2 = $resultClosestCleanDimension2 . '<a href="https://www.eestms.com/' . getTMSHome() . '/updateStockedMaterial.php?updateStockedMaterialID=' . 
                                                         $recommendation3["MaterialStockID"] . '">' . $amount . ') ' . htmlspecialchars_decode($recommendation3["Name"]) . '</a><br>';

                    // Determine if we are at the third one yet
                    if ($amount==3){
                        // Break out of this loop because we only want three
                        break;
                    }
                }

                // Complete the dimension 1 string
                $resultClosestCleanDimension2 = '<br><br>The top blank candidates are listed here in order of DIMENSION 2.<br>' . $resultClosestCleanDimension2;
            }

            // Determine if we have anything from any query (TODO: Currently the same query except order, but it could change.
            if ($resultLeastWaste != '' || $resultClosestCleanDimension1 != '' || $resultClosestCleanDimension2 != ''){
                // Combine them all
                $result = '<br><br>Recommendations:' . $resultLeastWaste . $resultClosestCleanDimension1 . $resultClosestCleanDimension2;
            }
        } catch (Exception $ex) {
            // Set the return result to an error state
            $result='<br><br>Recommendations:<br>There was an error executing the query';

            // Assign the output string as to what happened
            return $result;
        }

        // Return the created HTML
        return $result;
    }

    function HowManyBlanksCanFitBySimpleCuts($outerRectangleX, $outerRectangleY, $innerRectangleX, $innerRectangleY){
        // Setup the returns to be none
        $returnAmount = 0;
        $returnString = "";
        // Get the largest and smallest dimensions of all passed in
        $outerLargestDim = ($outerRectangleX >= $outerRectangleY)?$outerRectangleX:$outerRectangleY;
        $outerSmallestDim = ($outerRectangleX <= $outerRectangleY)?$outerRectangleX:$outerRectangleY;
        $innerLargestDim = ($innerRectangleX >= $innerRectangleY)?$innerRectangleX:$innerRectangleY;
        $innerSmallestDim = ($innerRectangleX <= $innerRectangleY)?$innerRectangleX:$innerRectangleY;

        // Determine if ANY can fit
        if (($outerLargestDim >= $innerLargestDim && $outerSmallestDim >= $innerSmallestDim) ||
            ($outerLargestDim >= $innerSmallestDim && $outerSmallestDim >= $innerLargestDim)){
            // Set variables for first and second case
            $firstAmount = 0;
            $firstString = "";
            $secondAmount = 0;
            $secondString = "";

            // Check the first orientation
            if ($outerLargestDim >= $innerLargestDim && $outerSmallestDim >= $innerSmallestDim){
                // The amount in the largest dimension multiplied by the amount in the smallest dimension should give us our first amount
                $firstAmount += floor($outerLargestDim/$innerLargestDim) * floor($outerSmallestDim/$innerSmallestDim);

                // Get the leftover amount in the largest outer dimension
                $leftoverLargestDim = $outerLargestDim % $innerLargestDim;

                // Try to make rectangles from the leftovers. Largest inner dimension takes care of itself with the floor function.
                $firstAmount += floor($leftoverLargestDim/$innerSmallestDim) * floor($outerSmallestDim/$innerLargestDim);

                // Say this is the largest stock dimension matching the largest blank dimension
                $firstString = "Most blanks will be made with the largest dimension of the " . 
                               "stock orientated with the largest dimension of the blank. " .
                               "Remaining stock in the largest direction should then be used " .
                               "rotating the blank ninety degrees. ";
            }

            // Check the second orientation
            if ($outerLargestDim >= $innerSmallestDim && $outerSmallestDim >= $innerLargestDim){
                // The amount in the largest dimension multiplied by the amount in the smallest dimension should give us our first amount
                $secondAmount += floor($outerSmallestDim/$innerLargestDim) * floor($outerLargestDim/$innerSmallestDim);

                // Get the leftover amount in the smallest outer dimension
                $leftoverSmallestDim = $outerSmallestDim % $innerLargestDim;

                // Try to make rectangles from the leftovers. Largest inner dimension takes care of itself with the floor function.
                $secondAmount += floor($leftoverSmallestDim/$innerSmallestDim) * floor($outerLargestDim/$innerLargestDim);

                // Say this is the largest stock dimension matching the largest blank dimension
                $secondString = "Most blanks will be made with the smallest dimension of the " . 
                               "stock orientated with the largest dimension of the blank. " .
                               "Remaining stock in the smallest direction should then be used " .
                               "rotating the blank ninety degrees. ";
            }


            // Save the amount as the first amount by default
            $returnAmount = $firstAmount;

            // determine which got the most blanks
            if ($firstAmount > $secondAmount) {
                // set the appropriate return string
                $returnString = $firstString;
            }
            else if ($firstAmount < $secondAmount) {
                // set the appropriate return string
                $returnString = $secondString;
            }
            else {
                // set the appropriate return string
                $returnString = "It does not matter which way you orient the stock and blanks. " .
                                "You will get the same amount out of either direction. ";

                // Save the amount
                $returnAmount = $secondAmount;
            }
        }

        // Return an array of amount and the string
        return array($returnAmount, $returnString);
    }

    function CompareWasteCellNumericAsc($a,$b) 
    {
        // Determine if a is larger or equal
        if($a["Waste"] - $b["Waste"] >= 0){
            // Return higher response
            return 1;
        }

        // Return lower response
        return -1;
    }

    function CompareWasteCellNumericDesc($a,$b) 
    {
        // Determine if a is larger or equal
        if($b["Waste"] - $a["Waste"] >= 0){
            // Return higher response
            return 1;
        }

        // Return lower response
        return -1;
    }

    function CompareQuantityCellNumericAsc($a,$b) 
    {
        // Determine if a is larger or equal
        if($a["MaxBlanks"] - $b["MaxBlanks"] >= 0){
            // Return higher response
            return 1;
        }

        // Return lower response
        return -1;
    }

    function CompareQuantityCellNumericDesc($a,$b) 
    {
        // Determine if a is larger or equal
        if($b["MaxBlanks"] - $a["MaxBlanks"] >= 0){
            // Return higher response
            return 1;
        }

        // Return lower response
        return -1;
    }

    function RecommendPlateAndCastStock($db, $userRow, $assocBlank){
        // Set the return result to be as though there is no recommendation
        $result = '<br><br><b>Recommendations</b>:<br>There is NO ONE or COMBINED in-stock material(s) that will work to create ALL of these blanks. You would either need to order the material or see what can be made from the scraps combined with what we have.';

        // initialize the seperate query results
        $resultStockThatCanFillFullOrder = '<br><br><b>Stocked material that can fill full order with one blank</b>: <br>  There is NONE that can fill the order completely.';
        $resultStockCombinationThatFillFullOrderExactly = '<br><br><b>Stocked material that can fill full order EXACTLY with multiple blanks</b>: <br>  There are NO COMBINATIONS that can fill the order completely to the exact blank amount.';
        $resultStockThatCannotFillFullOrder = '<br><br><b>Stocked material that cannot fill full order (used to help pick from a human standpoint)</b>: <br>  There is NO stock that can fit the blank size.';

        try {
            // Category = 'Titanium','Steel','Stainless Steel','Plastic','Other','Glass','Ceramic','Cast Iron','Aluminum','Acrylic'
            // Type = 'Tube','Round','Plate','Other','Extrusion','Cast'        

            // Init the variables
            $totalMakableByBlanksThatCannotHandleAll = 0;
            $thicknessPrecisionSQL = 'AND   ms.Dimension3 = ' . $assocBlank["Dimension3"] . ' ';

            // Determine if this is thick or thin (over 1" being considered thick).
            if ($assocBlank["Dimension3"]>1){
                // Set to include thicker blanks
                $thicknessPrecisionSQL = 'AND   ms.Dimension3 > ' . $assocBlank["Dimension3"] . ' ';
            }

            // Create the initial query of the material table for the material to recommend
            $sqlInitial = 'SELECT ms.*, (ms.Dimension1 * ms.Dimension2) AS Area, m.Category, m.Description, m.Name AS MaterialName 
                           FROM materialstock ms 
                           LEFT JOIN material m ON ms.MaterialID = m.MaterialID 
                           WHERE ms.MaterialID=' . $assocBlank["MaterialID"] . ' 
                           AND   ms.Type = "' . $assocBlank["Type"] . '" 
                           ' . $thicknessPrecisionSQL . '
                           AND   ms.Dimension3 >= ' . $assocBlank["Dimension3"] . ' 
                           AND   ( 
                                    (ms.Dimension1 >= ' . $assocBlank["Dimension1"] . ' AND ms.Dimension2 >= ' . $assocBlank["Dimension2"] . ') 
                                    OR 
                                    (ms.Dimension1 >= ' . $assocBlank["Dimension2"] . ' AND ms.Dimension2 >= ' . $assocBlank["Dimension1"] . ') 
                                  ) 
                           ';

            // Order the query by Thickness first
            $sql = $sqlInitial . 'ORDER BY ms.Dimension3, Area, ms.Dimension1, ms.Dimension2;';

            // Run the query
            $recommendations1 = $db->queryDB($sql, $userRow, "blank_presentation Form occurance 8.");

            // Determine if there are any rows before attempting to loop through them
            if ($recommendations1 != null && 
                mysqli_num_rows($recommendations1)>0){
                // Create arrays to hold the possible stock I will be looking at
                $partialFillStockArray = array();
                $fullyFillStockArray = array();

                // Loop through the returned results to create the selections
                $amount=0;
                while ($recommendation1=mysqli_fetch_array($recommendations1)){
                    // Init variables
                    $blankArea = $assocBlank["Dimension1"] * $assocBlank["Dimension2"];           // Simple area calculation
                    $stockArea = $recommendation1["Dimension1"] * $recommendation1["Dimension2"]; // Simple area calculation
                    $needMoreStock = false;

                    // Increase the amount recorded
                    $amount++;

                    // Get the return array
                    $simpleCutBlanksArray = HowManyBlanksCanFitBySimpleCuts($recommendation1["Dimension1"], $recommendation1["Dimension2"], 
                                                                            $assocBlank["Dimension1"], $assocBlank["Dimension2"]);

                    // Get the max blanks we can fit cutting simply
                    $maxBlanksSimply = $simpleCutBlanksArray[0];

                    // Determine if all blanks can be made from this piece
                    if ($maxBlanksSimply >= $assocBlank["Quantity"]){
                        // Calculate the waste on this one using the ideal blank amount
                        $wasteInSqInches = $stockArea - ($assocBlank["Quantity"] * $blankArea);

                        // Add this one to the array
                        array_push($fullyFillStockArray, [
                                                            'MaterialStockID'=>$recommendation1["MaterialStockID"],
                                                            'Name'=>$recommendation1["Name"],
                                                            'Waste'=>$wasteInSqInches,
                                                            'MaxBlanks'=>$maxBlanksSimply,
                                                            'Instructions'=>$simpleCutBlanksArray[1],
                                                            'NeedsMore'=>$needMoreStock, 
                                                            'Units'=>$recommendation1["Units"]
                                                       ] 
                                  );
                    }
                    else{
                        // Set the flag that we need more stock in order to make this one
                        $needMoreStock = true;

                        // Calculate the waste on this one using up to the max from this stock
                        $wasteInSqInches = $stockArea - ($maxBlanksSimply * $blankArea);

                        // Add this one to the array
                        array_push($partialFillStockArray, [
                                                                'MaterialStockID'=>$recommendation1["MaterialStockID"],
                                                                'Name'=>$recommendation1["Name"],
                                                                'Waste'=>$wasteInSqInches,
                                                                'MaxBlanks'=>$maxBlanksSimply,
                                                                'Instructions'=>$simpleCutBlanksArray[1],
                                                                'NeedsMore'=>$needMoreStock, 
                                                                'Units'=>$recommendation1["Units"]
                                                           ] 
                                  );

                        // Increase the total blanks that can be made out of stock that cannot fit all
                        $totalMakableByBlanksThatCannotHandleAll += $maxBlanksSimply;
                    }
                }

                // Check to see if we can make all out of any blanks
                if (count($fullyFillStockArray) > 0){
                    // Change the ring to be somethings about being able to fill order fully with single blanks
                    $resultStockThatCanFillFullOrder = '<br><br><b>Stocked material that can fill ' . 
                            'full order with one blank</b>: <br> There are ' . count($fullyFillStockArray) . 
                            ' that can fill the order completely. Showing up to three of them ' .
                            'in order of least waste after filling the order.<br>';

                    // Sort the array on waste lowest waste to highest
                    usort($fullyFillStockArray, "CompareWasteCellNumericAsc");

    //foreach ( $fullyFillStockArray as $key => $row ){
    //    print "$row[Name]: Waste $row[Waste]<BR>\n";
    //}
    //
                    // Loop through the now sorted list of blanks that can fully make the order
                    $amount=0;
                    foreach ($fullyFillStockArray as $fullyFillStockRow) {
                        // Increase the amount recorded
                        $amount++;

                        // Add to the result string
                        $resultStockThatCanFillFullOrder .= '   <a href="https://www.eestms.com/' . getTMSHome() . '/updateStockedMaterial.php?updateStockedMaterialID=' . 
                                                            $fullyFillStockRow["MaterialStockID"] . '">' . $amount . ') ' . htmlspecialchars_decode($fullyFillStockRow["Name"]) . 
                                                            '</a> *** Cut instructions: "'. $fullyFillStockRow["Instructions"] . '" <font color="red">Waste Amount</font>: <font color="Green">' . $fullyFillStockRow["Waste"] . 
                                                            '</font> units (usually sq inches) <font color="red">Max Blanks</font>: <font color="LimeGreen">' . $fullyFillStockRow["MaxBlanks"] . '</font><br>';

                        // Determine if we are at the third one yet
                        if ($amount==3){
                            // Break out of this loop because we only want to look at three
                            break;
                        }
                    }                
                }

                // Check to see if we can even make enough out of the blanks that cannot do all 
                if ($totalMakableByBlanksThatCannotHandleAll >= $assocBlank["Quantity"]){
                    // Create the object that will handle chacking for combination candidates
                    $subsetsum = new sortArrayProblems();

                    // Run the method to attempt to populate the array
                    $subsetsum->printAllSubsets($partialFillStockArray, $assocBlank["Quantity"]);

                    // Determine if there is any combination of blanks that will work
                    if ($subsetsum->allExactCombinations != NULL &&
                        count($subsetsum->allExactCombinations) > 0){

                        // Create a return string for this case
                        $resultStockCombinationThatFillFullOrderExactly = '<br><br><b>Stocked material that can fill full order EXACTLY with multiple blanks</b>: <br>';

                        // Loop through the main array
                        for ($loopNumber1=0; $loopNumber1<count($subsetsum->allExactCombinations); $loopNumber1++){
                            // Add the start of this blank's information'
                            $resultStockCombinationThatFillFullOrderExactly .= '   Combo ' . ($loopNumber1+1) . ' is made up of ' . 
                                    count($subsetsum->allExactCombinations[$loopNumber1]) . ' blanks with ' . 
                                    $subsetsum->allExactCombinations[$loopNumber1][count($subsetsum->allExactCombinations[$loopNumber1])-1]["TotalWaste"] .
                                    ' units (usually sq inches) of total waste.<br>';

                            // Loop through the blanks it takes to get the exact amount
                            $internalRowNumber=0;
                            foreach ($subsetsum->allExactCombinations[$loopNumber1] as $combo) {
                                // Determine if we are at the row that has the TOTAL amount
                                if ($combo["TotalWaste"] == null) {
                                    // Increment the internal row number
                                    $internalRowNumber++;

                                    // Add to the result string
                                    $resultStockCombinationThatFillFullOrderExactly .= ' ' .
                                                                  '<a href="https://www.eestms.com/' . getTMSHome() . '/updateStockedMaterial.php?updateStockedMaterialID=' . 
                                                                  $combo["MaterialStockID"] . '">' . $internalRowNumber . ') ' . htmlspecialchars_decode($combo["Name"]) . 
                                                                  '</a> *** Cut instructions: "'. $combo["Instructions"] . '" <font color="red">Waste Amount</font>: <font color="LimeGreen">' . $combo["Waste"] . 
                                                                  '</font> units (usually sq inches)  <font color="red">Max Blanks</font>: <font color="LimeGreen">' . $combo["MaxBlanks"] . '</font><br>';
                                }
                            }   

                            // Put a break between each combo
                            $resultStockCombinationThatFillFullOrderExactly .= '<br>';

                            // Determine if we are at the third one yet
                            if ($loopNumber1==2){
                                // Break out of this loop because we only want to look at three
                                break;
                            }
                        }
                    }
                }


                // Check to see if there is ANY stock that can do ANY blanks 
                if (count($partialFillStockArray) > 0){
                    // Sort the array on quantity highest to lowest
                    usort($partialFillStockArray, "CompareQuantityCellNumericDesc");

                    // Init the variable that tells how many possibilities there could be that will make at least one blank
                    $stockCanMakeABlank = count($partialFillStockArray);

                    // Get the amount we are actually going to show
                    $showedBlankAmount=10;
                    if ($stockCanMakeABlank<=10){
                        // Set the showed amount to the array amount
                        $stockCanMakeABlank=count($partialFillStockArray);
                    }

                    // Determine if the amount of stock s less than 10
                    $resultStockThatCannotFillFullOrder = '<br><br><b>Stocked material that cannot fill full order</b> ' . 
                            '(used to help pick from a human standpoint): <br>There are a total of ' . 
                            $stockCanMakeABlank . ' recorded stock blanks that can make at least one blank. ' .    
                            'This list shows ' . $stockCanMakeABlank . ' blanks.<br>';

                    // Loop through the now sorted list of blanks that can fully make the order
                    $amount=0;
                    foreach ($partialFillStockArray as $partiallyFillStockRow) {
                        // Increase the amount recorded
                        $amount++;

                        // Add to the result string
                        $resultStockThatCannotFillFullOrder .= '  <a href="https://www.eestms.com/' . getTMSHome() . '/updateStockedMaterial.php?updateStockedMaterialID=' . 
                                                               $partiallyFillStockRow["MaterialStockID"] . '">' . $amount . ') ' . htmlspecialchars_decode($partiallyFillStockRow["Name"]) . 
                                                               '</a> *** Cut instructions: "'. $partiallyFillStockRow["Instructions"] . '" <font color="red">Waste Amount</font>: <font color="LimeGreen">' . $partiallyFillStockRow["Waste"] . 
                                                               '</font> units (usually sq inches) <font color="red">Max Blanks</font>: <font color="LimeGreen">' . $partiallyFillStockRow["MaxBlanks"] . '</font><br>';

                        // Determine if we are at the third one yet
                        if ($amount==10){
                            // Break out of this loop because we only want to look at three
                            break;
                        }
                    }                
                }
            }

            // Combine them all
            $result = '<br><br>Recommendations:' . $resultStockThatCanFillFullOrder . $resultStockCombinationThatFillFullOrderExactly . $resultStockThatCannotFillFullOrder;
        } catch (Exception $ex) {
            // Set the return result to an error state
            $result='<br><br>Recommendations:<br>  There was an error executing the query';

            // Assign the output string as to what happened
            return $result;
        }

        // Return the created HTML
        return wordwrap($result);
    }

    function RecommendBlankStock($db, $blankID, $userRow){
        // TODO: Remove this and make sure the logic is clear for getting the appropriate blank size.
        // IDEAS: 1. Look at the dimensions that are precise or clean and use those first in the query (both must be bigger than)
        //        2. Look at the type to determine what dimension is the most variable (i.e. length for extrusion & rounds)
        //        3. Use the volume of the dimensions that are precise/or clean to help deliniate choices

        // Set the return result to nothing in case nothing is passed in for task number
        $result='';

        try {
            // determine if we have a blank ID
            if ($blankID!= null && $blankID>0)
            {
                // Create the query to get the the blank to query about
                $sql = 'SELECT * ' .
                            'FROM jobblanks ' . 
                            'WHERE JobBlanksID=' . $blankID . ';';

                // Attempt to get the row
                $row = $db->queryDB($sql, $userRow, "stocklist_presentation Form occurance 3");

                // Determine if the blank is found
                if ($row != NULL &&
                    $row instanceof mysqli_result){
                    // Attempt to get the blank row
                    $assocBlank = $row->fetch_assoc();

                    // Determine what type of blank they are requesting
                    switch ($assocBlank["Type"]){
                        case 'Tube':
                            // Use the appropriate function to handle picking Tube
                            $result = RecommendTubeBlankStock($db, $userRow, $assocBlank);

                            break;
                        case 'Round':
                            // Use the appropriate function to handle picking Round
                            $result = RecommendRoundsBlankStock($db, $userRow, $assocBlank);

                            break;
                        case 'Other':
                            // Use the appropriate function to handle picking Other
                            $result = RecommendOtherBlankStock($db, $userRow, $assocBlank);

                            break;
                        case 'Extrusion':
                            // Use the appropriate function to handle picking Extrusion
                            $result = RecommendExtrusionBlankStock($db, $userRow, $assocBlank);

                            break;
                        case 'Cast':
                        case 'Plate':
                            // Use the appropriate function to handle picking Plate
                            $result = RecommendPlateAndCastStock($db, $userRow, $assocBlank);

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

        // Return the created HTML
        return $result;
    }

    function ShowSuggested($db, $userRow, $suggestStockID=-1){
        // Set the return result to be nothing at first
        $result = '';

        // First and foremost, determine if we even need to do anything
        if ($suggestStockID!=null && $suggestStockID>0){
            try {
                // Category = 'Titanium','Steel','Stainless Steel','Plastic','Other','Glass','Ceramic','Cast Iron','Aluminum','Acrylic'
                // Type = 'Tube','Round','Plate','Other','Extrusion','Cast'        

                // Create the initial query of the material table for the material to recommend
                $sql = 'SELECT * ' .
                       'FROM materialstock ' . 
                       'WHERE MaterialStockID=' . $suggestStockID . ';';

                // Run the query
                $theSuggested = $db->queryDB($sql, $userRow, "blank_presentation Form occurance 8.");

                // Determine if there are any rows before attempting to loop through them
                if ($theSuggested != null && 
                    mysqli_num_rows($theSuggested)>0){

                    // Get the current task row to work with as the assoc style
                    $theSuggestedAssocRow = $theSuggested->fetch_assoc();

                    // Set the return result to be as though there is no recommendation
                    $result = '<br><br>Blank to use:<br>' . 
                              '<a href="https://www.eestms.com/' . getTMSHome() . 
                                   '/updateStockedMaterial.php?updateStockedMaterialID=' . 
                                   $suggestStockID . '">' . $theSuggestedAssocRow["Name"] . 
                              '</a><br>';
                }
            } catch (Exception $ex) {
                // Assign the output string as to what happened
                return $result;
            }
        }
        // Return the created HTML
        return $result;
    }

    function retrieveBlank($db, $userRow, $currentBlankID=-1){
        // Set the return result to nothing in case nothing is passed in for task number
        $result='';

        try {
            // Determine if this person is of the main company
            if ($userRow["CompanyID"]!=1){
                // Just leave
                return $result;
            }

            // Determine if I am supposed to check for current blanks or not
            if ($currentBlankID!=null && is_numeric($currentBlankID)){
                // Determine if this is a SU
                $suUser=0;
                if ($userRow["UserLevel"]==="SU"){
                    // Set the su user to 1
                    $suUser=1;
                }

                // Create the query to get the the blanks and the user that created the blanks
                $sql = 'SELECT jb.*, ' .
                       '       cu.FirstName AS CreatedByFirstName, cu.LastName AS CreatedByLastName, ' .
                       '       su.FirstName AS SubmittedByFirstName, su.LastName AS SubmittedByLastName, ' .
                       '       ru.FirstName AS ReadiedByFirstName, ru.LastName AS ReadiedByLastName, ' .
                       '       qu.FirstName AS QuoteRequestedByFirstName, qu.LastName AS QuoteRequestedByLastName, ' .
                       '       wsu.FirstName AS IsPendingStockByFirstName, wsu.LastName AS IsPendingStockByLastName, ' .
                       '       t.ParentID, t.CompanyID, t.TypeID AS TaskTypeID, t.StatusID, ' .
                       '       usvl.ViewCategory ' .
                       'FROM jobblanks jb ' . 
                       'LEFT JOIN users cu ON jb.CreatedByID = cu.UserID ' .
                       'LEFT JOIN users su ON jb.SubmittedByID = su.UserID ' .
                       'LEFT JOIN users ru ON jb.BlankReadiedByID = ru.UserID ' .
                       'LEFT JOIN users qu ON jb.QuoteRequestedByID = qu.UserID ' .
                       'LEFT JOIN users wsu ON jb.IsPendingStockByID = wsu.UserID ' .
                       'LEFT JOIN tasks t  ON jb.TaskID = t.TaskID ' .
                       'LEFT JOIN (SELECT * FROM usertostatusviewinglinker WHERE UserID=' . $userRow["UserID"] . ') usvl ON t.StatusID = usvl.StatusID ' .
                       'WHERE jb.JobBlanksID=' . $currentBlankID . ' ' .
                       'ORDER BY jb.TaskID;';

    //echo '<script>alert("' . addslashes($sql) . '");</script>';

                // Attempt to get the row
                $row = $db->queryDB($sql, $userRow, "blank_presentation Form occurance 5");

                // Attempt to get the blank row
                $assocBlank = $row->fetch_assoc();

                // Set the things we can
                $jobBlanksID = $assocBlank["JobBlanksID"];
                $taskID = $assocBlank["TaskID"];
                $parentTaskID = $assocBlank["ParentID"];
                $companyID =  $assocBlank["CompanyID"];
                $materialID = $assocBlank["MaterialID"];
                $createdByID = $assocBlank["CreatedByID"];
                $taskTypeID = $assocBlank["TaskTypeID"];
                $createdByFirstName = $assocBlank["CreatedByFirstName"];
                $createdByLastName = $assocBlank["CreatedByLastName"];
                $submittedByID = $assocBlank["SubmittedByID"];
                $submittedByFirstName = $assocBlank["SubmittedByFirstName"];
                $submittedByLastName = $assocBlank["SubmittedByLastName"];
                $readiedByID = $assocBlank["BlankReadiedByID"];
                $readiedByFirstName = $assocBlank["ReadiedByFirstName"];
                $readiedByLastName = $assocBlank["ReadiedByLastName"];
                $quoteRequested = $assocBlank["QuoteRequested"];
                $quoteRequestedByID = $assocBlank["QuoteRequestedByID"];
                $quoteRequestedDate = $assocBlank["QuoteRequestedDate"];
                $quoteRequestedByFirstName = $assocBlank["QuoteRequestedByFirstName"];
                $quoteRequestedByByLastName = $assocBlank["QuoteRequestedByLastName"];
                $type = $assocBlank["Type"];
                $dimension1 = $assocBlank["Dimension1"];
                $dimension1Precise = $assocBlank["Dimension1Precise"];
                $dimension1Clean = $assocBlank["Dimension1Clean"];
                $dimension2 = $assocBlank["Dimension2"];
                $dimension2Precise = $assocBlank["Dimension2Precise"];
                $dimension2Clean = $assocBlank["Dimension2Clean"];
                $dimension3 = $assocBlank["Dimension3"];
                $dimension3Precise = $assocBlank["Dimension3Precise"];
                $dimension3Clean = $assocBlank["Dimension3Clean"];
                $quantityDimension = $assocBlank["QuantityDimension"];
                $wallThickness = $assocBlank["WallThickness"];
                $blankReady = $assocBlank["BlankReady"];
                $blankReadiedDate = $assocBlank["BlankReadiedDate"];
                $rush = $assocBlank["Rush"];
                $submitted = $assocBlank["Submitted"];
                $submittedDate = $assocBlank["SubmittedDate"];
                $reason = $assocBlank["Reason"];
                $quantity = $assocBlank["Quantity"];
                $suggestStockID = $assocBlank["SuggestedMaterialStockID"];
                $isPendingStock = $assocBlank["IsPendingStock"];
                $isPendingStockByID = $assocBlank["IsPendingStockByID"];
                $isPendingStockDate = $assocBlank["IsPendingStockDate"];
                $isPendingStockByFirstName = $assocBlank["IsPendingStockByFirstName"];
                $isPendingStockByLastName = $assocBlank["IsPendingStockByLastName"];

                // Determine if this one has been submitted already for disabling
                $disabledHTML='';
                if ($submitted && $userRow["UserLevel"]!='SU'){
                    // The fields should be disabled
                    $disabledHTML = "class='disable' readonly";
                }

                // Ready checkbox has to see if it has already been finished and then it is disabled
                $readyDisabledHTML='';
                $reasonDisabledHTML='';
                $readyLabelHTML='style="color:LimeGreen;"';
                $readyByLabel='Ready';
                $quoteRequestedByLabel='Quote Requested';
                $waitingForStockByLabel='Waiting For Stock';
                if($blankReady){
                    // Determine if we are an SU
                    if ($userRow["UserLevel"]!='SU'){
                        // Disable the checkbox
                        $readyDisabledHTML = "class='disable' readonly";

                        // disable the reason textbox
                        $reasonDisabledHTML = "class='disablewithpointer' readonly";
                    }

                    // set the lable color red to denote inability to enable
                    $readyLabelHTML='style="color:black;"';

                    // Create the date string off of the timestamp in the database
                    $blankReadiedDateString = (new DateTime($blankReadiedDate))->format('Y-m-d\ @ H:i:s');

                    // Set the label to be indicative of who readied it
                    $readyByLabel='Ready (Readied By ' . $readiedByFirstName . '  ' . 
                                  $readiedByLastName . ' on ' . $blankReadiedDateString . ')';
                }

                // Quote requested checkbox has to see if it has already been quoted and create label
                if($quoteRequested){
                    // Create the date string off of the timestamp in the database
                    $quoteRequestedDateString = (new DateTime($quoteRequestedDate))->format('Y-m-d\ @ H:i:s');

                    // Set the label to be indicative of who quoted it
                    $quoteRequestedByLabel='Quote Requested (Quoted By ' . $quoteRequestedByFirstName . '  ' . 
                                  $quoteRequestedByByLastName . ' on ' . $quoteRequestedDateString . ')';
                }

                // Is pending stock checkbox has to see if it is waiting stock
                if($isPendingStock){
                    // Create the date string off of the timestamp in the database
                    $isPendingStockDateString = (new DateTime($isPendingStockDate))->format('Y-m-d\ @ H:i:s');

                    // Set the label to be indicative of who put it as waiting for stock
                    $waitingForStockByLabel='Waiting For Stock (Waiting For Stock By ' . $isPendingStockByFirstName . '  ' . 
                                  $isPendingStockByLastName . ' on ' . $isPendingStockDateString . ')';
                }

                // Setup the buttons to be correct for NOT having a suggestion
                $suggestButtonStyleHTML = "";
                $suggestedControlsReadOnlyHTML = "";
                $resetSuggestionButtonStyleHTML = " disabled ";
                $suggestedFieldsDisabledHTML=$disabledHTML;

                // Determine if this blank has a suggestion already
                $suggestedMaterialStyle='';
                if ($suggestStockID!=null && $suggestStockID>0){
                    // Setup the style to be of the style that there is a suggestion
                    $suggestedMaterialStyle = 'color:red;';

                    // Set them to be redonly
                    $suggestedControlsReadOnlyHTML = ' readonly ';

                    // The fields should be disabled and red
                    $suggestedFieldsDisabledHTML = "class='disable' readonly";

                    // Setup the buttons to be correct for having a suggestion
                    $suggestButtonStyleHTML = " disabled ";
                    $resetSuggestionButtonStyleHTML = "";

                    // Determine the level and state of the blank
                    if ($submitted && $userRow["UserLevel"]!='SU'){
                        // Setup the buttons to be correct for having a suggestion
                        $suggestButtonStyleHTML = " disabled ";
                        $resetSuggestionButtonStyleHTML = " disabled ";
                    }
                }

                // Set dimension one text box html border to be rough color
                $dimension1StyleHTML = ' border:solid LimeGreen 2px;' . $suggestedMaterialStyle;

                // Determine if it is other than rough
                if ($dimension1Precise){
                    // Set dimension one text box html border to be precise color
                    $dimension1StyleHTML = ' border:solid red 2px;'. $suggestedMaterialStyle;
                }
                else if ($dimension1Clean){
                    // Set dimension one text box html border to be clean color
                    $dimension1StyleHTML = ' border:solid yellow 2px;'. $suggestedMaterialStyle;
                }

                // Set dimension one text box html border to be rough color
                $dimension2StyleHTML = ' border:solid LimeGreen 2px;' . $suggestedMaterialStyle;

                // Determine if it is other than rough
                if ($dimension2Precise){
                    // Set dimension two text box html border to be precise color
                    $dimension2StyleHTML = ' border:solid red 2px;' . $suggestedMaterialStyle;
                }
                else if ($dimension2Clean){
                    // Set dimension two text box html border to be clean color
                    $dimension2StyleHTML = ' border:solid yellow 2px;' . $suggestedMaterialStyle;
                }

                // Set dimension one text box html border to be rough color
                $dimension3StyleHTML = ' border:solid LimeGreen 2px;' . $suggestedMaterialStyle;

                // Determine if it is other than rough
                if ($dimension3Precise){
                    // Set dimension three text box html border to be precise color
                    $dimension3StyleHTML = ' border:solid red 2px;' . $suggestedMaterialStyle;
                }
                else if ($dimension3Clean){
                    // Set dimension three text box html border to be clean color
                    $dimension3StyleHTML = ' border:solid yellow 2px;' . $suggestedMaterialStyle;
                }

                // Get the type select drop down
                $materialSelectHTML=getUsedMaterialAsSelectOptions($db, $userRow, $materialID, '', $suggestedMaterialStyle, false, false, 'materialID' . $jobBlanksID, $suggestedFieldsDisabledHTML);

                // Init checked values
                $submittedHTML='';
                $rushHTML='';
                $blankReadyHTML='';
                $quoteRequestedHTML='';

                // Create the remove blank checkbox for this blank in green
                $removeBlankHTML = '  
                                <tr>
                                    <td colspan=4 align="right">
                                        <label id="removeBlankLabel' . $jobBlanksID . '" style="color:LimeGreen;">Remove Blank</label>
                                        <input class="notinput" type="checkbox" id="removeBlank' . $jobBlanksID . '" name="removeBlank' . $jobBlanksID . '" title="This being checked on update will remove the whole blank on update." value="' . $jobBlanksID . '"></input>
                                        <br>
                                    </td>
                                </tr>
                                <tr>
                                </tr>
                             ';

                // Determine if we have values for the submitted checked flag
                if ($submitted != null and $submitted==true){
                    // Set it to what we got in
                    $submittedHTML = 'checked';

                    // determine if this is a SU or not
                    if ($userRow["UserLevel"]!="SU" && $userRow["UserLevel"]!="EXECUTIVE" && $userRow["UserLevel"]!="MANAGEMENT"){
                        // Not allowed to be deleted or modified at this point by this user
                        $removeBlankHTML = '';
                    }
                }

                // Determine if we have values for the rush checked flag
                if ($rush != null and $rush==true){
                    // Set it to what we got in
                    $rushHTML = 'checked';
                }

                // Determine if we have values for the blank ready checked flag
                // SUs can still fix it for people
                if ($blankReady != null and $blankReady==true){
                    // Set it to what we got in
                    $blankReadyHTML = 'checked';
                }

                // Determine if we have values for the quote requested checked flag
                if ($quoteRequested != null and $quoteRequested==true){
                    // Set it to what we got in
                    $quoteRequestedHTML = 'checked';
                }

                // Determine if the parent button should be displayed based on it's state and assigned to person
                $parentButtonHTML = '<button type="button" onClick="javascript: window.open(\'updateTask.php?updateTaskID=' . $taskID . '&parentTaskId=' . $parentTaskID . '&cs=' . $companyID . '&ts=' . $taskTypeID . '\', \'_parent\');" align="right">View Task</button>';
                if ($assocBlank["ViewCategory"] == "NOT VIEWABLE" &&
                    $assocBlank["UserID"] != $userRow["UserID"]){
                    // Set the button to nothing
                    $parentButtonHTML = '';
                }

                // Create the query to check the amount of sticky notes on this blank
                $testSql = 'SELECT count(*) as noteCount FROM notes ' . 
                           'WHERE AssociatedCategoryID = ' . $jobBlanksID . ' ' .
                           'AND   IsSticky=1 ' .
                           'AND   Category = "BLANK";';

                // Attempt to get all of the notes on this blank
                $testRows = $db->queryDB($testSql, $userRow, "blank_presentation Form occurance 11");

                // Determine if there were rows for the notes on this task
                $haveStickyNotes=false;
                $stickyNotesButtonStyling='';
                if ($testRows != null && 
                    mysqli_num_rows($testRows)>0){
                    // Get the row as an assoc row
                    $testRowAssoc = $testRows->fetch_assoc();

                    // Determine if we have more than zero
                    if ($testRowAssoc["noteCount"]>0){
                        // set the flag to say there are blanks
                        $haveStickyNotes = true;
                    }
                }

                // Determine if we have any notes for this blank
                $stickyNoteDivHTML='';
                $stickyNoteValidationHTML='';
                $stickyNoteTabOnClick='';
                if ($haveStickyNotes){
                    // Setup the styling to be green text
                    $stickyNotesButtonStyling .= 'color:LimeGreen;';

                    // Get something for sticky notes
                    $stickyNoteDivHTML=checkThenGetStickyNotesDiv($db, $userRow, $jobBlanksID, 'BLANK', $stickyNoteValidationHTML);

                    // Setup an onclick to show the first note
                    $stickyNoteTabOnClick="openChildPage('stickyNote1', document.getElementById('stickyNoteTabButton1'));";
                }

                // Determine if this is on a machine
                $isOrderedHTML='';
                if ($isPendingStock!=null){
                    // Determine if it is on order
                    if ($isPendingStock==1){
                        $isOrderedHTML='checked';
                    }
                }

                // Start adding the blanks that are in the database
                $result =  
                        '   
                            <form action="updateBlank.php?updateBlankID=' . $jobBlanksID . '" method="post" name="updateBlank" id="updateBlank" enctype="multipart/form-data">  
                                <button class="tablink" type="button" onclick="openPage(\'GeneralInfo\');" id="defaultOpen">General Info</button>
                                <button class="tablink" type="button" onclick="openPage(\'StickyNotes\'); ' . $stickyNoteTabOnClick . '" style="' . $stickyNotesButtonStyling . '">Sticky Notes</button>
                                <div id="GeneralInfo" name="GeneralInfo" class="tabcontent">
                                    <br><br>
                                    <table style="font-size: 11px; font-weight: bold;">
                                        <tr>
                                            <td width="15%">
                                                <strong>Task ID: </strong> &nbsp; &nbsp;
                                            </td>
                                            <td width="20%" colspan=3>
                                                ' . $taskID . '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ' . $parentButtonHTML .'
                                            </td>
                                        </tr>
                                        <tr>
                                            <td width="15%">
                                                <input type="hidden" name="jobBlanksID' . $jobBlanksID . '" id="jobBlanksID' . $jobBlanksID . '" value="' . $jobBlanksID . '">
                                                <input type="hidden" name="createdByID' . $jobBlanksID . '" id="createdByID' . $jobBlanksID . '" value="' . $createdByID . '">
                                                <input type="hidden" name="taskID' . $jobBlanksID . '" id="taskID' . $jobBlanksID . '" value="' . $taskID . '">
                                                <input type="hidden" name="parentTaskID' . $jobBlanksID . '" id="parentTaskID' . $jobBlanksID . '" value="' . $parentTaskID . '">
                                                <label style="width:100%;">Created By:</label>
                                            </td>
                                            <td width="20%">
                                                <label style="width:100%;">' . $createdByFirstName . '  ' . $createdByLastName . '</label>
                                            </td>
                                            <td width="15%">
                                                <label style="width:100%;">Quantity:</label>
                                            </td>
                                            <td width="50%">
                                                <input ' . $disabledHTML . ' style="width:30%;" type="text" maxlength="11" name="quantity' . $jobBlanksID . '" id="quantity' . $jobBlanksID . '" value="' . $quantity . '"/>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td width="15%">
                                                <input ' . $disabledHTML . ' type="hidden" name="submittedByID' . $jobBlanksID . '" id="submittedByID' . $jobBlanksID . '" value="' . $submittedByID . '">
                                                <label style="width:100%;">Submitted By:</label>
                                            </td>
                                            <td width="20%">
                                                <label style="width:100%;">' . $submittedByFirstName . '  ' . $submittedByLastName . '</label>
                                            </td>
                                            <td width="15%">
                                                <label style="width:100%;">Quantity Dimension:</label>
                                            </td>
                                            <td width="35%" colspan=1>
                                                ' 
                                                . 
                                                $db->getTypeAsSelectOptions('jobblanks', 'QuantityDimension', 'quantityDimension' . $jobBlanksID, $quantityDimension, null, '', false, $disabledHTML) 
                                                . 
                                                '
                                            </td>
                                        </tr>
                                        <tr>
                                            <td width="15%">
                                                <label style="width:100%;">Submitted Date:</label>
                                            </td>
                                            <td width="20%">
                                                <input ' . $disabledHTML . ' style="width:100%;" type="datetime-local" name="submittedDate' . $jobBlanksID . '" id="submittedDate' . $jobBlanksID . '" value="' . str_replace(" ","T",$submittedDate) . '"/>
                                            </td>
                                            <td width="15%">
                                                <label style="width:100%;">Type:</label>
                                            </td>
                                            <td width="35%" colspan=1>
                                                ' 
                                                . 
                                                $db->getTypeAsSelectOptions('jobblanks', 'Type', 'type' . $jobBlanksID, $type, null, $suggestedMaterialStyle, false, $suggestedFieldsDisabledHTML) 
                                                . 
                                                '
                                                <button name="suggestStock' . $jobBlanksID . '" id="suggestStock' . $jobBlanksID . '" class="suggestStock" type="button" ' . $suggestButtonStyleHTML . '>Recommend</button>
                                                <button name="resetSuggestion' . $jobBlanksID . '" id="resetSuggestion' . $jobBlanksID . '" type="button" onclick="resetBlank(' . $jobBlanksID . ', 0);" ' . $resetSuggestionButtonStyleHTML . '>Reset</button>
                                                <input type="hidden" name="suggestStockID' . $jobBlanksID . '" id="suggestStockID' . $jobBlanksID . '" value=' . $suggestStockID . '>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td width="50%" colspan=2>
                                            </td>
                                            <td width="15%">
                                                <label style="width:100%;">Category:</label>
                                            </td>
                                            <td width="35%" colspan=1>
                                                '
                                                . 
                                                $materialSelectHTML 
                                                . 
                                                '
                                            </td>
                                        </tr>
                                        <tr>
                                            <td width="15%" >
                                                <label style="width:100%;">Reason:</label>
                                            </td>
                                            <td width="20%" >
                                                <textarea '. $reasonDisabledHTML .' name="reason' . $jobBlanksID . '" id="reason' . $jobBlanksID . '" maxlength="500" class="intext" style="width: 100%; height: 50px; overflow: auto; resize:none" ' . $allFieldsAccess . '>' .
                                                $reason .
                                                '</textarea>
                                            </td>
                                            <td width="15%">
                                                <label style="width:100%;">Dimension 1:</label>
                                            </td>
                                            <td width="35%">
                                                <input ' . $disabledHTML . ' style="width:100%;' . $dimension1StyleHTML . '" ' . $suggestedControlsReadOnlyHTML . ' type="text" maxlength="15" name="dimension1' . $jobBlanksID . '" id="dimension1' . $jobBlanksID . '" value="' . $dimension1 . '" />
                                                <br>
                                                '
                                                .
                                                createCutTypeRadioButton('dimension1Radio', 'dimension1', $dimension1Clean, $dimension1Precise, $jobBlanksID, $disabledHTML)
                                                .
                                                '
                                            </td>
                                        </tr>
                                        <tr>
                                            <td width="35%" colspan=2>
                                            </td>
                                            <td width="15%">
                                                <label style="width:100%;">Dimension 2:</label>
                                            </td>
                                            <td width="50%">
                                                <input ' . $disabledHTML . ' style="width:100%; ' . $dimension2StyleHTML . '" ' . $suggestedControlsReadOnlyHTML . ' type="text" maxlength="15" name="dimension2' . $jobBlanksID . '" id="dimension2' . $jobBlanksID . '" value="' . $dimension2 . '"/>
                                                <br>
                                                '
                                                .
                                                createCutTypeRadioButton('dimension2Radio', 'dimension2', $dimension2Clean, $dimension2Precise, $jobBlanksID, $disabledHTML)
                                                .
                                                '
                                            </td>
                                        </tr>
                                        <tr>
                                            <td width="35%" colspan=2>
                                            </td>
                                            <td width="15%">
                                                <label style="width:100%;">Dimension 3:</label>
                                            </td>
                                            <td width="50%" colspan=3>
                                                <input ' . $disabledHTML . ' style="width:100%;' . $dimension3StyleHTML . '" ' . $suggestedControlsReadOnlyHTML . ' type="text" maxlength="15" name="dimension3' . $jobBlanksID . '" id="dimension3' . $jobBlanksID . '" value="' . $dimension3 . '"/>
                                                <br>
                                                '
                                                .
                                                createCutTypeRadioButton('dimension3Radio', 'dimension3', $dimension3Clean, $dimension3Precise, $jobBlanksID,  $disabledHTML )
                                                .
                                                '
                                            </td>
                                        </tr>
                                        <tr>
                                            <td colspan=1>
                                                <input type="hidden" name="submittedTouched' . $jobBlanksID . '" id="submittedTouched' . $jobBlanksID . '" value=0>
                                                <input ' . $disabledHTML . ' name="submitted' . $jobBlanksID . '" id="submitted' . $jobBlanksID . '" type="checkbox" ' . $submittedHTML . 
                                                                                                ' onchange="javascript:document.getElementById(\'submittedTouched' . $jobBlanksID . '\').value = 1;">
                                                <strong><label for="submitted' . $jobBlanksID . '"  ' . $disabledHTML . '>Submit</label></strong>
                                            </td>
                                            <td colspan=1 align="center">
                                                <input ' . $disabledHTML . ' name="rush' . $jobBlanksID . '" id="rush' . $jobBlanksID . '" type="checkbox" ' . $rushHTML . '>
                                                <strong><label for="rush' . $jobBlanksID . '"  ' . $disabledHTML . '>Rush</label></strong>
                                            </td>
                                            <td width="15%">
                                                <label style="width:100%;">Wall Thickness:</label>
                                            </td>
                                            <td width="50%" colspan=3>
                                                <input ' . $disabledHTML . ' style="width:100%;' . $suggestedMaterialStyle . '" ' . $suggestedControlsReadOnlyHTML . ' type="text" maxlength="10" name="wallThickness' . $jobBlanksID . '" id="wallThickness' . $jobBlanksID . '" value="' . $wallThickness . '"/>
                                                <br><br>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td colspan=4 align="left">
                                                <input type="hidden" name="quoteRequestedTouched' . $jobBlanksID . '" id="quoteRequestedTouched' . $jobBlanksID . '" value=0>
                                                <input type="hidden" name="quoteRequestedByID' . $jobBlanksID . '" id="quoteRequestedByID' . $jobBlanksID . '" value="' . $quoteRequestedByID . '">
                                                <input type="hidden" name="quoteRequestedDate' . $jobBlanksID . '" id="quoteRequestedDate' . $jobBlanksID . '" value="' . $quoteRequestedDate . '">
                                                <input ' . $readyDisabledHTML . ' name="quoteRequested' . $jobBlanksID . '" id="quoteRequested' . $jobBlanksID . '" type="checkbox" ' . $quoteRequestedHTML . 
                                                       ' onchange="javascript:document.getElementById(\'quoteRequestedTouched' . $jobBlanksID . '\').value = 1;">
                                                <strong><label ' . $readyLabelHTML . ' for="quoteRequested' . $jobBlanksID . '"  ' . $disabledHTML . '>' . $quoteRequestedByLabel . '</label></strong>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td colspan=4 align="left">
                                                <input type="hidden" name="blankReadiedTouched' . $jobBlanksID . '" id="blankReadiedTouched' . $jobBlanksID . '" value=0>
                                                <input type="hidden" name="blankReadiedByID' . $jobBlanksID . '" id="blankReadiedByID' . $jobBlanksID . '" value="' . $readiedByID . '">
                                                <input type="hidden" name="blankReadiedDate' . $jobBlanksID . '" id="blankReadiedDate' . $jobBlanksID . '" value="' . $blankReadiedDate . '">
                                                <input ' . $readyDisabledHTML . ' name="blankReady' . $jobBlanksID . '" id="blankReady' . $jobBlanksID . '" type="checkbox" ' . $blankReadyHTML .
                                                       ' onchange="javascript:checkPendingStockBoxesDependingOnOthers(this, ' . $jobBlanksID . '); document.getElementById(\'blankReadiedTouched' . $jobBlanksID . '\').value = 1;' . 
                                                       ' document.getElementById(\'isPendingStockTouched' . $jobBlanksID . '\').value = 1;">
                                                <strong><label ' . $readyLabelHTML . ' for="blankReady' . $jobBlanksID . '"  ' . $disabledHTML . '>' . $readyByLabel . '</label></strong>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td colspan=4 align="left">
                                                <input type="hidden" name="isPendingStockTouched' . $jobBlanksID . '" id="isPendingStockTouched' . $jobBlanksID . '" value=0>
                                                <input type="hidden" name="isPendingStockByID' . $jobBlanksID . '" id="isPendingStockByID' . $jobBlanksID . '" value="' . $isPendingStockByID . '">
                                                <input type="hidden" name="isPendingStockDate' . $jobBlanksID . '" id="isPendingStockDate' . $jobBlanksID . '" value="' . $isPendingStockDate . '">
                                                <input ' . $readyDisabledHTML . ' name="isPendingStock' . $jobBlanksID . '" id="isPendingStock' . $jobBlanksID . '" type="checkbox" ' . $isOrderedHTML . 
                                                       ' onchange="checkPendingStockBoxesDependingOnOthers(this, ' . $jobBlanksID . '); document.getElementById(\'isPendingStockTouched' . $jobBlanksID . '\').value = 1; ' . 
                                                       ' document.getElementById(\'blankReadiedTouched' . $jobBlanksID . '\').value = 1;">
                                                <strong><label ' . $readyLabelHTML . ' for="isPendingStock' . $jobBlanksID . '"  ' . $disabledHTML . '>' . $waitingForStockByLabel . '</label></strong>
                                            </td>
                                        </tr>
                                    </table>
                                </div>
                                <div id="StickyNotes" name="StickyNotes" style="display:none;" class="tabcontent">
                                    <br><br>
                                    '
                                    .
                                    $stickyNoteDivHTML
                                    .
                                    '
                                </div>
                                <br>
                                <input type="hidden" name="formSubmitted" value="TRUE">
                                <input name="formSubmit" id="formSubmit" type="submit" onclick="this.disabled=true; this.form.submit();" style="pointer-events: auto; cursor: hand; cursor: pointer;" value="update blank" title="Update this blank."/>
                            </form>

                            <script language="JavaScript">
                                frmvalidator.addValidation("quantity' . $jobBlanksID . '",
                                                           "req",
                                                           "Please enter a quantity for all blanks.");
                                frmvalidator.addValidation("quantity' . $jobBlanksID . '",
                                                           "num",
                                                           "Please enter the quantity for all blanks as a number.");
                                frmvalidator.addValidation("quantity' . $jobBlanksID . '",
                                                           "greaterthan=0",
                                                           "The quantity for all blanks should be greater than 0.");
                                frmvalidator.addValidation("dimension1' . $jobBlanksID . '",
                                                           "req",
                                                           "Please enter dimension 1 for all blanks.");
                                frmvalidator.addValidation("dimension1' . $jobBlanksID . '",
                                                           "num",
                                                           "Please enter dimension 1 for all blanks as a number.");
                                frmvalidator.addValidation("dimension1' . $jobBlanksID . '",
                                                           "greaterthan=-.0000000001",
                                                           "Dimension 1 for all blanks should be greater than 0.");
                                frmvalidator.addValidation("dimension2' . $jobBlanksID . '",
                                                           "req",
                                                           "Please enter dimension 2 for all blanks.");
                                frmvalidator.addValidation("dimension2' . $jobBlanksID . '",
                                                           "num",
                                                           "Please enter dimension 2 for all blanks as a number.");
                                frmvalidator.addValidation("dimension2' . $jobBlanksID . '",
                                                           "greaterthan=-.0000000001",
                                                           "Dimension 2 for all blanks should be greater than 0.");
                                frmvalidator.addValidation("dimension3' . $jobBlanksID . '",
                                                           "req",
                                                           "Please enter dimension 3 for all blanks.");
                                frmvalidator.addValidation("dimension3' . $jobBlanksID . '",
                                                           "num",
                                                           "Please enter dimension 3 for all blanks as a number.");
                                frmvalidator.addValidation("dimension3' . $jobBlanksID . '",
                                                           "greaterthan=-.0000000001",
                                                           "Dimension 3 for all blanks should be greater than 0.");
                                '
                                .
                                $stickyNoteValidationHTML
                                .
                                '
                            </script>
                    ';

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

        // Return the created HTML
        return $result;
    }

    function retrieveCurrentBlanks($db, $userRow, $inTaskID, &$validationHTML=""){
        // Set the return result to nothing in case nothing is passed in for task number
        $result='';

        try {
            // Determine if this person is of the main company
            if ($userRow["CompanyID"]!=1){
                // Just leave
                return $result;
            }

            // Init necessary variables
            $taskID=$inTaskID;

            // Determine if I am supposed to check for current blanks or not
            if ($taskID!=null && is_numeric($taskID)){
                // Determine if this is a SU
                $suUser=0;
                if ($userRow["UserLevel"]==="SU"){
                    // Set the su user to 1
                    $suUser=1;
                }

                // Create the query to get the the blanks and the user that created the blanks
                $sql = 'SELECT jb.*, ' .
                       '       cu.FirstName AS CreatedByFirstName, cu.LastName AS CreatedByLastName, ' .
                       '       su.FirstName AS SubmittedByFirstName, su.LastName AS SubmittedByLastName, ' .
                       '       ru.FirstName AS ReadiedByFirstName, ru.LastName AS ReadiedByLastName, ' .
                       '       qu.FirstName AS QuoteRequestedByFirstName, qu.LastName AS QuoteRequestedByLastName, ' .
                       '       wsu.FirstName AS IsPendingStockByFirstName, wsu.LastName AS IsPendingStockByLastName ' .
                       'FROM jobblanks jb ' . 
                       'LEFT JOIN users cu ON jb.CreatedByID = cu.UserID ' .
                       'LEFT JOIN users su ON jb.SubmittedByID = su.UserID ' .
                       'LEFT JOIN users ru ON jb.BlankReadiedByID = ru.UserID ' .
                       'LEFT JOIN users qu ON jb.QuoteRequestedByID = qu.UserID ' .
                       'LEFT JOIN users wsu ON jb.IsPendingStockByID = wsu.UserID ' .
                       'WHERE jb.TaskID=' . $taskID . ' ' .
                       'AND (0=' . $userRow["CannotViewUnsubmittedBlanks"] . ' OR jb.Submitted=1 OR 1=' . $suUser . ') '  .
                       'ORDER BY jb.TaskID;';

                // Attempt to get all of the blanks for this category type and ID
                $rows = $db->queryDB($sql, $userRow, "blank_presentation Form occurance 5");

                // Determine if there were rows for the task(s)
                if ($rows != null && 
                    mysqli_num_rows($rows)>0){
                    // Init some variables
                    $blanksIDArray=null;

                    // Reset the validation HTML
                    $validationHTML='';

                    // Loop through the returned results
                    while ($row=mysqli_fetch_array($rows)){
                        // Set the things we can
                        $jobBlanksID = $row["JobBlanksID"];
                        $materialID = $row["MaterialID"];
                        $createdByID = $row["CreatedByID"];
                        $createdByFirstName = $row["CreatedByFirstName"];
                        $createdByLastName = $row["CreatedByLastName"];
                        $submittedByID = $row["SubmittedByID"];
                        $submittedByFirstName = $row["SubmittedByFirstName"];
                        $submittedByLastName = $row["SubmittedByLastName"];
                        $readiedByID = $row["BlankReadiedByID"];
                        $readiedByFirstName = $row["ReadiedByFirstName"];
                        $readiedByLastName = $row["ReadiedByLastName"];
                        $quoteRequested = $row["QuoteRequested"];
                        $quoteRequestedByID = $row["QuoteRequestedByID"];
                        $quoteRequestedDate = $row["QuoteRequestedDate"];
                        $quoteRequestedByFirstName = $row["QuoteRequestedByFirstName"];
                        $quoteRequestedByByLastName = $row["QuoteRequestedByLastName"];
                        $type = $row["Type"];
                        $dimension1 = $row["Dimension1"];
                        $dimension1Precise = $row["Dimension1Precise"];
                        $dimension1Clean = $row["Dimension1Clean"];
                        $dimension2 = $row["Dimension2"];
                        $dimension2Precise = $row["Dimension2Precise"];
                        $dimension2Clean = $row["Dimension2Clean"];
                        $dimension3 = $row["Dimension3"];
                        $dimension3Precise = $row["Dimension3Precise"];
                        $dimension3Clean = $row["Dimension3Clean"];
                        $quantityDimension = $row["QuantityDimension"];
                        $wallThickness = $row["WallThickness"];
                        $blankReady = $row["BlankReady"];
                        $blankReadiedDate = $row["BlankReadiedDate"];
                        $rush = $row["Rush"];
                        $submitted = $row["Submitted"];
                        $submittedDate = $row["SubmittedDate"];
                        $reason = $row["Reason"];
                        $quantity = $row["Quantity"];
                        $suggestStockID = $row["SuggestedMaterialStockID"];
                        $isPendingStock = $row["IsPendingStock"];
                        $isPendingStockByID = $row["IsPendingStockByID"];
                        $isPendingStockDate = $row["IsPendingStockDate"];
                        $isPendingStockByFirstName = $row["IsPendingStockByFirstName"];
                        $isPendingStockByLastName = $row["IsPendingStockByLastName"];

                        // Determine if this one has been submitted already for disabling
                        $disabledHTML='';
                        if ($submitted && $userRow["UserLevel"]!='SU'){
                            // The fields should be disabled
                            $disabledHTML = "class='disable' readonly";
                        }

                        // Ready checkbox has to see if it has already been finished and then it is disabled
                        $readyDisabledHTML='';
                        $reasonDisabledHTML='';
                        $readyLabelHTML='style="color:LimeGreen;"';
                        $readyByLabel='Ready';
                        $quoteRequestedByLabel='Quote Requested';
                        $waitingForStockByLabel='Waiting For Stock';
                        if($blankReady){
                            // Determine if we are an SU
                            if ($userRow["UserLevel"]!='SU'){
                                // Disable the checkbox
                                $readyDisabledHTML = "class='disable' readonly";

                                // disable the reason textbox
                                $reasonDisabledHTML = "class='disablewithpointer' readonly";
                            }

                            // set the lable color red to denote inability to enable
                            $readyLabelHTML='style="color:black;"';

                            // Create the date string off of the timestamp in the database
                            $blankReadiedDateString = (new DateTime($blankReadiedDate))->format('Y-m-d\ @ H:i:s');

                            // Set the label to be indicative of who readied it
                            $readyByLabel='Ready (Readied By ' . $readiedByFirstName . '  ' . 
                                          $readiedByLastName . ' on ' . $blankReadiedDateString . ')';
                        }

                        // Quote requested checkbox has to see if it has already been quoted and create label
                        if($quoteRequested){
                            // Create the date string off of the timestamp in the database
                            $quoteRequestedDateString = (new DateTime($quoteRequestedDate))->format('Y-m-d\ @ H:i:s');

                            // Set the label to be indicative of who quoted it
                            $quoteRequestedByLabel='Quote Requested (Quoted By ' . $quoteRequestedByFirstName . '  ' . 
                                          $quoteRequestedByByLastName . ' on ' . $quoteRequestedDateString . ')';
                        }

                        // Is pending stock checkbox has to see if it is waiting stock
                        if($isPendingStock){
                            // Create the date string off of the timestamp in the database
                            $isPendingStockDateString = (new DateTime($isPendingStockDate))->format('Y-m-d\ @ H:i:s');

                            // Set the label to be indicative of who put it as waiting for stock
                            $waitingForStockByLabel='Waiting For Stock (Waiting For Stock By ' . $isPendingStockByFirstName . '  ' . 
                                          $isPendingStockByLastName . ' on ' . $isPendingStockDateString . ')';
                        }

                        // Setup the buttons to be correct for NOT having a suggestion
                        $suggestButtonStyleHTML = "";
                        $suggestedControlsReadOnlyHTML = "";
                        $resetSuggestionButtonStyleHTML = " disabled ";
                        $suggestedFieldsDisabledHTML=$disabledHTML;

                        // Determine if this blank has a suggestion already
                        $suggestedMaterialStyle='';
                        if ($suggestStockID!=null && $suggestStockID>0){
                            // Setup the style to be of the style that there is a suggestion
                            $suggestedMaterialStyle = 'color:red;';

                            // Set them to be redonly
                            $suggestedControlsReadOnlyHTML = ' readonly ';

                            // The fields should be disabled and red
                            $suggestedFieldsDisabledHTML = "class='disable' readonly";

                            // Setup the buttons to be correct for having a suggestion
                            $suggestButtonStyleHTML = " disabled ";
                            $resetSuggestionButtonStyleHTML = "";

                            // Determine the level and state of the blank
                            if ($submitted && $userRow["UserLevel"]!='SU'){
                                // Setup the buttons to be correct for having a suggestion
                                $suggestButtonStyleHTML = " disabled ";
                                $resetSuggestionButtonStyleHTML = " disabled ";
                            }
                        }

                        // Set dimension one text box html border to be rough color
                        $dimension1StyleHTML = ' border:solid LimeGreen 2px;' . $suggestedMaterialStyle;

                        // Determine if it is other than rough
                        if ($dimension1Precise){
                            // Set dimension one text box html border to be precise color
                            $dimension1StyleHTML = ' border:solid red 2px;'. $suggestedMaterialStyle;
                        }
                        else if ($dimension1Clean){
                            // Set dimension one text box html border to be clean color
                            $dimension1StyleHTML = ' border:solid yellow 2px;'. $suggestedMaterialStyle;
                        }

                        // Set dimension one text box html border to be rough color
                        $dimension2StyleHTML = ' border:solid LimeGreen 2px;' . $suggestedMaterialStyle;

                        // Determine if it is other than rough
                        if ($dimension2Precise){
                            // Set dimension two text box html border to be precise color
                            $dimension2StyleHTML = ' border:solid red 2px;' . $suggestedMaterialStyle;
                        }
                        else if ($dimension2Clean){
                            // Set dimension two text box html border to be clean color
                            $dimension2StyleHTML = ' border:solid yellow 2px;' . $suggestedMaterialStyle;
                        }

                        // Set dimension one text box html border to be rough color
                        $dimension3StyleHTML = ' border:solid LimeGreen 2px;' . $suggestedMaterialStyle;

                        // Determine if it is other than rough
                        if ($dimension3Precise){
                            // Set dimension three text box html border to be precise color
                            $dimension3StyleHTML = ' border:solid red 2px;' . $suggestedMaterialStyle;
                        }
                        else if ($dimension3Clean){
                            // Set dimension three text box html border to be clean color
                            $dimension3StyleHTML = ' border:solid yellow 2px;' . $suggestedMaterialStyle;
                        }

                        // Get the type select drop down
                        $materialSelectHTML=getUsedMaterialAsSelectOptions($db, $userRow, $materialID, '', $suggestedMaterialStyle, false, false, 'materialID' . $jobBlanksID, $suggestedFieldsDisabledHTML);

                        // Init checked values
                        $submittedHTML='';
                        $rushHTML='';
                        $blankReadyHTML='';
                        $quoteRequestedHTML='';

                        // Create the remove blank checkbox for this blank in green
                        
                        $removeBlankHTML = '  
                                        <tr>
                                            <td colspan=2 align="left">
                                                <input type="button" style="font-size:9px; vertical-align: middle;" value="+" title="This will copy the blank to a specified quantity for prepping." onclick="javascript:copyBlankRequestDialog(' . $jobBlanksID . ');"/>
                                                <button style="font-size:9px; vertical-align: middle;" title="Print the blank request." onclick="javascript: window.open(\'pdf_templates/blank_request.php?jbid=' . $row["JobBlanksID"] . '&sessionID=' . session_id() . '\', \'_blank\'); return true;"><img src="images/print.png" width="8" height="11"></button>
                                                <br>
                                            </td>
                                            <td colspan=2 align="right">
                                                <label id="removeBlankLabel' . $jobBlanksID . '" style="color:LimeGreen;">Remove Blank</label>
                                                <input class="notinput" type="checkbox" id="removeBlank' . $jobBlanksID . '" name="removeBlank' . $jobBlanksID . '" title="This being checked on update will remove the whole blank on update." value="' . $jobBlanksID . '"></input>
                                                <br>
                                            </td>
                                        </tr>
                                        <tr>
                                        </tr>
                                     ';

                        // Determine if we have values for the submitted checked flag
                        if ($submitted != null and $submitted==true){
                            // Set it to what we got in
                            $submittedHTML = 'checked';

                            // determine if this is a SU or not
                            if ($userRow["UserLevel"]!="SU" && $userRow["UserLevel"]!="EXECUTIVE" && $userRow["UserLevel"]!="MANAGEMENT"){
                                // Not allowed to be deleted or modified at this point by this user
                                $removeBlankHTML = '  
                                        <tr>
                                            <td colspan=4 align="left">
                                                <input type="button" style="font-size:9px; vertical-align: middle;" value="+" title="This will copy the blank to a specified quantity for prepping." onclick="javascript:copyBlankRequestDialog(' . $jobBlanksID . ');"/>
                                                <button style="font-size:9px; vertical-align: middle;" title="Print the blank request." onclick="javascript: window.open(\'pdf_templates/blank_request.php?jbid=' . $row["JobBlanksID"] . '&sessionID=' . session_id() . '\', \'_blank\'); return true;"><img src="images/print.png" width="8" height="11"></button>
                                                <br>
                                            </td>
                                        </tr>
                                        <tr>
                                        </tr>
                                     ';
                            }
                        }

                        // Determine if we have values for the rush checked flag
                        if ($rush != null and $rush==true){
                            // Set it to what we got in
                            $rushHTML = 'checked';
                        }

                        // Determine if we have values for the blank ready checked flag
                        // SUs can still fix it for people
                        if ($blankReady != null and $blankReady==true){
                            // If it is a SU then allow for the removal, but color it red
                            if ($userRow["UserLevel"]=="SU"){
                                // Create the remove blank checkbox for this blank inred
                                $removeBlankHTML = '  
                                                <tr>
                                                    <td colspan=2 align="left">
                                                        <input type="button" style="font-size:9px; vertical-align: middle;" value="+" title="This will copy the blank to a specified quantity for prepping." onclick="javascript:copyBlankRequestDialog(' . $jobBlanksID . ');"/>
                                                        <button style="font-size:9px; vertical-align: middle;" title="Print the blank request." onclick="javascript: window.open(\'pdf_templates/blank_request.php?jbid=' . $row["JobBlanksID"] . '&sessionID=' . session_id() . '\', \'_blank\'); return true;"><img src="images/print.png" width="8" height="11"></button>
                                                        <br>
                                                    </td>
                                                    <td colspan=2 align="right">
                                                        <label id="removeBlankLabel' . $jobBlanksID . '" style="color:red;">Remove Blank</label>
                                                        <input ' . $disabledHTML . ' class="notinput" type="checkbox" id="removeBlank' . $jobBlanksID . '" name="removeBlank' . $jobBlanksID . '" title="This being checked on update will remove the whole blank on update." value="' . $jobBlanksID . '"></input>
                                                        <br>
                                                    </td>
                                                </tr>
                                                <tr>
                                                </tr>
                                             ';

                            }

                            // Set it to what we got in
                            $blankReadyHTML = 'checked';
                        }

                        // Determine if we have values for the quote requested checked flag
                        if ($quoteRequested != null and $quoteRequested==true){
                            // Set it to what we got in
                            $quoteRequestedHTML = 'checked';
                        }

                        // Determine if this is on a machine
                        $isOrderedHTML='';
                        if ($isPendingStock!=null){
                            // Determine if it is on order
                            if ($isPendingStock==1){
                                $isOrderedHTML='checked';
                            }
                        }

                        // Start adding the blanks that are in the database
                        $result = $result . 
                                '   
                                    <div id="currentBlank' . $jobBlanksID . '" name="currentBlank' . $jobBlanksID . '" style="margin-left: 20px; margin-top:10px; border-top-style:dashed; border-width: 1px;">
                                        <table style="font-size: 11px; font-weight: bold;">
                                            '
                                            .
                                             $removeBlankHTML  
                                            .
                                            '
                                            <tr>
                                                <td width="15%">
                                                    <input type="hidden" name="jobBlanksID' . $jobBlanksID . '" id="jobBlanksID' . $jobBlanksID . '" value="' . $jobBlanksID . '">
                                                    <input type="hidden" name="createdByID' . $jobBlanksID . '" id="createdByID' . $jobBlanksID . '" value="' . $createdByID . '">
                                                    <label style="width:100%;">Created By:</label>
                                                </td>
                                                <td width="20%">
                                                    <label style="width:100%;">' . $createdByFirstName . '  ' . $createdByLastName . '</label>
                                                </td>
                                                <td width="15%">
                                                    <label style="width:100%;">Quantity:</label>
                                                </td>
                                                <td>
                                                    <input ' . $disabledHTML . ' style="width:100%;" type="text" maxlength="11" name="quantity' . $jobBlanksID . '" id="quantity' . $jobBlanksID . '" value="' . $quantity . '"/>
                                                </td>
                                            </tr>
                                            <tr>
                                                <td width="15%">
                                                    <input ' . $disabledHTML . ' type="hidden" name="submittedByID' . $jobBlanksID . '" id="submittedByID' . $jobBlanksID . '" value="' . $submittedByID . '">
                                                    <label style="width:100%;">Submitted By:</label>
                                                </td>
                                                <td width="20%">
                                                    <label style="width:100%;">' . $submittedByFirstName . '  ' . $submittedByLastName . '</label>
                                                </td>
                                                <td>
                                                    <label style="width:100%;">Quantity Dimension:</label>
                                                </td>
                                                <td colspan=1>
                                                    ' 
                                                    . 
                                                    $db->getTypeAsSelectOptions('jobblanks', 'QuantityDimension', 'quantityDimension' . $jobBlanksID, $quantityDimension, null, '', false, $disabledHTML) 
                                                    . 
                                                    '
                                                </td>
                                            </tr>
                                            <tr>
                                                <td width="15%">
                                                    <label style="width:100%;">Submitted Date:</label>
                                                </td>
                                                <td width="20%">
                                                    <input ' . $disabledHTML . ' style="width:100%;" type="datetime-local" name="submittedDate' . $jobBlanksID . '" id="submittedDate' . $jobBlanksID . '" value="' . str_replace(" ","T",$submittedDate) . '"/>
                                                </td>
                                                <td>
                                                    <label style="width:100%;">Type:</label>
                                                </td>
                                                <td colspan=1>
                                                    ' 
                                                    . 
                                                    $db->getTypeAsSelectOptions('jobblanks', 'Type', 'type' . $jobBlanksID, $type, null, $suggestedMaterialStyle, false, $suggestedFieldsDisabledHTML) 
                                                    . 
                                                    '
                                                    <button name="suggestStock' . $jobBlanksID . '" id="suggestStock' . $jobBlanksID . '" class="suggestStock" type="button" ' . $suggestButtonStyleHTML . '>Recommend</button>
                                                    <button name="resetSuggestion' . $jobBlanksID . '" id="resetSuggestion' . $jobBlanksID . '" type="button" onclick="resetBlank(' . $jobBlanksID . ', 0);" ' . $resetSuggestionButtonStyleHTML . '>Reset</button>
                                                    <input type="hidden" name="suggestStockID' . $jobBlanksID . '" id="suggestStockID' . $jobBlanksID . '" value=' . $suggestStockID . '>
                                                </td>
                                            </tr>
                                            <tr>
                                                <td width="35%" colspan=2>
                                                </td>
                                                <td>
                                                    <label style="width:100%;">Category:</label>
                                                </td>
                                                <td colspan=1>
                                                    '
                                                    . 
                                                    $materialSelectHTML 
                                                    . 
                                                    '
                                                </td>
                                            </tr>
                                            <tr>
                                                <td width="15%" >
                                                    <label style="width:100%;">Reason:</label>
                                                </td>
                                                <td width="20%" >
                                                    <textarea '. $reasonDisabledHTML .' name="reason' . $jobBlanksID . '" id="reason' . $jobBlanksID . '" maxlength="500" class="intext" style="width: 100%; height: 50px; overflow: auto; resize:none" ' . $allFieldsAccess . '>' .
                                                    $reason .
                                                    '</textarea>
                                                </td>
                                                <td>
                                                    <label style="width:100%;">Dimension 1:</label>
                                                </td>
                                                <td>
                                                    <input ' . $disabledHTML . ' style="width:100%;' . $dimension1StyleHTML . '" ' . $suggestedControlsReadOnlyHTML . ' type="text" maxlength="15" name="dimension1' . $jobBlanksID . '" id="dimension1' . $jobBlanksID . '" value="' . $dimension1 . '" />
                                                    <br>
                                                    '
                                                    .
                                                    createCutTypeRadioButton('dimension1Radio', 'dimension1', $dimension1Clean, $dimension1Precise, $jobBlanksID, $disabledHTML)
                                                    .
                                                    '
                                                </td>
                                            </tr>
                                            <tr>
                                                <td width="35%" colspan=2>
                                                </td>
                                                <td>
                                                    <label style="width:100%;">Dimension 2:</label>
                                                </td>
                                                <td>
                                                    <input ' . $disabledHTML . ' style="width:100%; ' . $dimension2StyleHTML . '" ' . $suggestedControlsReadOnlyHTML . ' type="text" maxlength="15" name="dimension2' . $jobBlanksID . '" id="dimension2' . $jobBlanksID . '" value="' . $dimension2 . '"/>
                                                    <br>
                                                    '
                                                    .
                                                    createCutTypeRadioButton('dimension2Radio', 'dimension2', $dimension2Clean, $dimension2Precise, $jobBlanksID, $disabledHTML)
                                                    .
                                                    '
                                                </td>
                                            </tr>
                                            <tr>
                                                <td width="35%" colspan=2>
                                                </td>
                                                <td>
                                                    <label style="width:100%;">Dimension 3:</label>
                                                </td>
                                                <td colspan=1>
                                                    <input ' . $disabledHTML . ' style="width:100%;' . $dimension3StyleHTML . '" ' . $suggestedControlsReadOnlyHTML . ' type="text" maxlength="15" name="dimension3' . $jobBlanksID . '" id="dimension3' . $jobBlanksID . '" value="' . $dimension3 . '"/>
                                                    <br>
                                                    '
                                                    .
                                                    createCutTypeRadioButton('dimension3Radio', 'dimension3', $dimension3Clean, $dimension3Precise, $jobBlanksID,  $disabledHTML )
                                                    .
                                                    '
                                                </td>
                                            </tr>
                                            <tr>
                                                <td colspan=1>
                                                    <input type="hidden" name="submittedTouched' . $jobBlanksID . '" id="submittedTouched' . $jobBlanksID . '" value=0>
                                                    <input ' . $disabledHTML . ' name="submitted' . $jobBlanksID . '" id="submitted' . $jobBlanksID . '" type="checkbox" ' . $submittedHTML . 
                                                                                                    ' onchange="javascript:document.getElementById(\'submittedTouched' . $jobBlanksID . '\').value = 1;">
                                                    <strong><label for="submitted' . $jobBlanksID . '"  ' . $disabledHTML . '>Submit</label></strong>
                                                </td>
                                                <td colspan=1 align="center">
                                                    <input ' . $disabledHTML . ' name="rush' . $jobBlanksID . '" id="rush' . $jobBlanksID . '" type="checkbox" ' . $rushHTML . '>
                                                    <strong><label for="rush' . $jobBlanksID . '"  ' . $disabledHTML . '>Rush</label></strong>
                                                </td>
                                                <td>
                                                    <label style="width:100%;">Wall Thickness:</label>
                                                </td>
                                                <td>
                                                    <input ' . $disabledHTML . ' style="width:100%;' . $suggestedMaterialStyle . '" ' . $suggestedControlsReadOnlyHTML . ' type="text" maxlength="10" name="wallThickness' . $jobBlanksID . '" id="wallThickness' . $jobBlanksID . '" value="' . $wallThickness . '"/>
                                                    <br><br>
                                                </td>
                                            </tr>
                                            <tr>
                                                <td colspan=4 align="left">
                                                    <input type="hidden" name="quoteRequestedTouched' . $jobBlanksID . '" id="quoteRequestedTouched' . $jobBlanksID . '" value=0>
                                                    <input type="hidden" name="quoteRequestedByID' . $jobBlanksID . '" id="quoteRequestedByID' . $jobBlanksID . '" value="' . $quoteRequestedByID . '">
                                                    <input type="hidden" name="quoteRequestedDate' . $jobBlanksID . '" id="quoteRequestedDate' . $jobBlanksID . '" value="' . $quoteRequestedDate . '">
                                                    <input ' . $readyDisabledHTML . ' name="quoteRequested' . $jobBlanksID . '" id="quoteRequested' . $jobBlanksID . '" type="checkbox" ' . $quoteRequestedHTML . 
                                                           ' onchange="javascript:document.getElementById(\'quoteRequestedTouched' . $jobBlanksID . '\').value = 1;">
                                                    <strong><label ' . $readyLabelHTML . ' for="quoteRequested' . $jobBlanksID . '"  ' . $disabledHTML . '>' . $quoteRequestedByLabel . '</label></strong>
                                                </td>
                                            </tr>
                                            <tr>
                                                <td colspan=4 align="left">
                                                    <input type="hidden" name="blankReadiedTouched' . $jobBlanksID . '" id="blankReadiedTouched' . $jobBlanksID . '" value=0>
                                                    <input type="hidden" name="blankReadiedByID' . $jobBlanksID . '" id="blankReadiedByID' . $jobBlanksID . '" value="' . $readiedByID . '">
                                                    <input type="hidden" name="blankReadiedDate' . $jobBlanksID . '" id="blankReadiedDate' . $jobBlanksID . '" value="' . $blankReadiedDate . '">
                                                    <input ' . $readyDisabledHTML . ' name="blankReady' . $jobBlanksID . '" id="blankReady' . $jobBlanksID . '" type="checkbox" ' . $blankReadyHTML .
                                                           ' onchange="javascript:checkPendingStockBoxesDependingOnOthers(this, ' . $jobBlanksID . '); document.getElementById(\'blankReadiedTouched' . $jobBlanksID . '\').value = 1;' . 
                                                           ' document.getElementById(\'isPendingStockTouched' . $jobBlanksID . '\').value = 1;">
                                                    <strong><label ' . $readyLabelHTML . ' for="blankReady' . $jobBlanksID . '"  ' . $disabledHTML . '>' . $readyByLabel . '</label></strong>
                                                </td>
                                            </tr>
                                            <tr>
                                                <td colspan=4 align="left">
                                                    <input type="hidden" name="isPendingStockTouched' . $jobBlanksID . '" id="isPendingStockTouched' . $jobBlanksID . '" value=0>
                                                    <input type="hidden" name="isPendingStockByID' . $jobBlanksID . '" id="isPendingStockByID' . $jobBlanksID . '" value="' . $isPendingStockByID . '">
                                                    <input type="hidden" name="isPendingStockDate' . $jobBlanksID . '" id="isPendingStockDate' . $jobBlanksID . '" value="' . $isPendingStockDate . '">
                                                    <input ' . $readyDisabledHTML . ' name="isPendingStock' . $jobBlanksID . '" id="isPendingStock' . $jobBlanksID . '" type="checkbox" ' . $isOrderedHTML . 
                                                           ' onchange="checkPendingStockBoxesDependingOnOthers(this, ' . $jobBlanksID . '); document.getElementById(\'isPendingStockTouched' . $jobBlanksID . '\').value = 1; ' . 
                                                           ' document.getElementById(\'blankReadiedTouched' . $jobBlanksID . '\').value = 1;">
                                                    <strong><label ' . $readyLabelHTML . ' for="isPendingStock' . $jobBlanksID . '"  ' . $disabledHTML . '>' . $waitingForStockByLabel . '</label></strong>
                                                </td>
                                            </tr>
                                        </table>
                                    </div>
                            ';

                        // Add something to the array list
                        $blanksIDArray = $blanksIDArray . $row["JobBlanksID"] . '|';

                        // Add the validators for these
                        $validationHTML = $validationHTML . '
                                            frmvalidator.addValidation("quantity' . $jobBlanksID . '",
                                                                       "req",
                                                                       "Please enter a quantity for all blanks.");
                                            frmvalidator.addValidation("quantity' . $jobBlanksID . '",
                                                                       "num",
                                                                       "Please enter the quantity for all blanks as a number.");
                                            frmvalidator.addValidation("quantity' . $jobBlanksID . '",
                                                                       "greaterthan=0",
                                                                       "The quantity for all blanks should be greater than 0.");
                                            frmvalidator.addValidation("dimension1' . $jobBlanksID . '",
                                                                       "req",
                                                                       "Please enter dimension 1 for all blanks.");
                                            frmvalidator.addValidation("dimension1' . $jobBlanksID . '",
                                                                       "num",
                                                                       "Please enter dimension 1 for all blanks as a number.");
                                            frmvalidator.addValidation("dimension1' . $jobBlanksID . '",
                                                                       "greaterthan=-.0000000001",
                                                                       "Dimension 1 for all blanks should be greater than 0.");
                                            frmvalidator.addValidation("dimension2' . $jobBlanksID . '",
                                                                       "req",
                                                                       "Please enter dimension 2 for all blanks.");
                                            frmvalidator.addValidation("dimension2' . $jobBlanksID . '",
                                                                       "num",
                                                                       "Please enter dimension 2 for all blanks as a number.");
                                            frmvalidator.addValidation("dimension2' . $jobBlanksID . '",
                                                                       "greaterthan=-.0000000001",
                                                                       "Dimension 2 for all blanks should be greater than 0.");
                                            frmvalidator.addValidation("dimension3' . $jobBlanksID . '",
                                                                       "req",
                                                                       "Please enter dimension 3 for all blanks.");
                                            frmvalidator.addValidation("dimension3' . $jobBlanksID . '",
                                                                       "num",
                                                                       "Please enter dimension 3 for all blanks as a number.");
                                            frmvalidator.addValidation("dimension3' . $jobBlanksID . '",
                                                                       "greaterthan=-.0000000001",
                                                                       "Dimension 3 for all blanks should be greater than 0.");
                                        ';
                    }

                    // Add the hidden field to the form
                    $result = 
                            '<label style="font-size: 20px;"><strong>Current Blanks: </strong></label>
                             <div id="currentBlanksDiv" style="">
                                 <input type="hidden" name="currentBlanksArray" id="currentBlanksArray" value="' . $blanksIDArray . '"></input>
                                 <input type="hidden" name="deleteCurrentBlanks" id="deleteCurrentBlanks" value=""></input>
                                 ' .
                                 $result . 
                            '</div>';
                }
            }
        } catch (Exception $ex) {
            // Assign the output string as to what happened
            return $result;
        }

        // Return the created HTML
        return $result;
    }

    function updateOldBlanks($db, $userRow, $taskID, $parentTaskNumber){
        // Determine if there are current blanks to look at
        if (isset($_POST['currentBlanksArray']) and $_POST['currentBlanksArray']!=0){
            // Create today's Date as string
            $currentDate = new DateTime();
            $currentDate->modify('-1 hour');
            $currentDateString = $currentDate->format('Y-m-d H:i:s');

            // Create the visualized task orientation as though this IS the parent
            $firstFour = str_pad($taskID,4,"0",STR_PAD_LEFT);
            $lastFour = '0000';

            // Determine if we are making a child of the parent right now
            if ($parentTaskNumber != 0){
                // Create the visualized task orientation as though this IS the parent
                $firstFour = str_pad($parentTaskNumber,4,"0",STR_PAD_LEFT);
                $lastFour = str_pad($taskID,4,"0",STR_PAD_LEFT);
            }

            // Remove the last delimiter
            $numbersToRemoveAsString = substr($_POST['currentBlanksArray'], 0, -1);

            // Get the amount of current blanks as a variable
            $blankNums=explode('|', $numbersToRemoveAsString);

            // Loop through and get all new blank elements
            foreach ($blankNums as $loopNumber){
                // Get the value of the blank removal flag
                $removeBlank = (isset($_POST['removeBlank'.$loopNumber])?1:0);

                // Create a flag for newly quote requested, submitted and newly readied blanks
                $newlyQuoteRequested = 0; 
                $newlyReadied = 0; 
                $newlySubmitted = 0; 

                // Determine if we are removing this note
                if ($removeBlank){
                    // Let's create a query to delete the blank
                    $sql='DELETE FROM jobblanks WHERE JobBlanksID=' . $loopNumber . ';';
                }
                else {
                    // Set the things we can
                    $materialID = htmlspecialchars($_POST['materialID'.$loopNumber], ENT_QUOTES, 'UTF-8');
                    $createdByID = htmlspecialchars($_POST['createdByID'.$loopNumber], ENT_QUOTES, 'UTF-8');
                    $type = htmlspecialchars($_POST['type'.$loopNumber], ENT_QUOTES, 'UTF-8');
                    $dimension1 = htmlspecialchars($_POST['dimension1'.$loopNumber], ENT_QUOTES, 'UTF-8');
                    $dimension2 = htmlspecialchars($_POST['dimension2'.$loopNumber], ENT_QUOTES, 'UTF-8');
                    $dimension3 = htmlspecialchars($_POST['dimension3'.$loopNumber], ENT_QUOTES, 'UTF-8');
                    $quantityDimension = htmlspecialchars($_POST['quantityDimension'.$loopNumber], ENT_QUOTES, 'UTF-8');
                    $wallThickness = htmlspecialchars($_POST['wallThickness'.$loopNumber], ENT_QUOTES, 'UTF-8');
                    $rush = (isset($_POST['rush'.$loopNumber])?1:0);
                    $submitted = (isset($_POST['submitted'.$loopNumber])?1:0);
                    $submittedByID = htmlspecialchars($_POST['submittedByID'.$loopNumber], ENT_QUOTES, 'UTF-8');
                    $submittedDate=str_replace("T"," ",htmlspecialchars($_POST['submittedDate'.$loopNumber]));
                    $submittedTouched = $_POST['submittedTouched'.$loopNumber];
                    $quoteRequested = (isset($_POST['quoteRequested'.$loopNumber])?1:0);
                    $quoteRequestedByID = htmlspecialchars($_POST['quoteRequestedByID'.$loopNumber], ENT_QUOTES, 'UTF-8');
                    $quoteRequestedTouched = $_POST['quoteRequestedTouched'.$loopNumber];
                    $quoteRequestedDate = htmlspecialchars($_POST['quoteRequestedDate'.$loopNumber], ENT_QUOTES, 'UTF-8');;
                    $blankReady = (isset($_POST['blankReady'.$loopNumber])?1:0);
                    $blankReadiedByID = htmlspecialchars($_POST['blankReadiedByID'.$loopNumber], ENT_QUOTES, 'UTF-8');
                    $blankReadiedDate = htmlspecialchars($_POST['blankReadiedDate'.$loopNumber], ENT_QUOTES, 'UTF-8');;
                    $blankReadiedTouched = $_POST['blankReadiedTouched'.$loopNumber];
                    $isPendingStock = (isset($_POST['isPendingStock'.$loopNumber])?1:0);
                    $isPendingStockByID = htmlspecialchars($_POST['isPendingStockByID'.$loopNumber], ENT_QUOTES, 'UTF-8');
                    $isPendingStockDate = htmlspecialchars($_POST['isPendingStockDate'.$loopNumber], ENT_QUOTES, 'UTF-8');;
                    $isPendingStockTouched = $_POST['isPendingStockTouched'.$loopNumber];
                    $reason = htmlspecialchars($_POST['reason'.$loopNumber], ENT_QUOTES, 'UTF-8');
                    $quantity = htmlspecialchars($_POST['quantity'.$loopNumber], ENT_QUOTES, 'UTF-8');
                    $suggestStockID = htmlspecialchars($_POST['suggestStockID'.$loopNumber], ENT_QUOTES, 'UTF-8');

                    // Set the good values flag to true
                    $goodValues = true;

                    // Init Set the bad values to show back to the user
                    $badValuesString = '';

                    // Check if the dimension 1 is good
                    if (!is_numeric($dimension1)){
                        // Add to the string to show
                        $badValuesString = $badValuesString . ' Dimension 1 was not a decimal,';

                        // Set it as a bad post
                        $goodValues=false;
                    }

                    // Check if the dimension 2 is good
                    if (!is_numeric($dimension2)){
                        // Add to the string to show
                        $badValuesString = $badValuesString . ' Dimension 2 was not a decimal,';

                        // Set it as a bad post
                        $goodValues=false;
                    }

                    // Check if the dimension 3 is good
                    if (!is_numeric($dimension3)){
                        // Add to the string to show
                        $badValuesString = $badValuesString . ' Dimension 3 was not a decimal,';

                        // Set it as a bad post
                        $goodValues=false;
                    }

                    // Check if the quantity is good
                    if (!is_numeric($quantity) || fmod($quantity, (int)$quantity)!=0){
                        // Add to the string to show
                        $badValuesString = $badValuesString . ' Quantity was not an integer,';

                        // Set it as a bad post
                        $goodValues=false;
                    }


                    // determine that the quote requested flag is not checked without the submit flag
                    if ($quoteRequested && !$submitted){
                        // Add to the string to show
                        $badValuesString = $badValuesString . ' Blank cannot be in quote requested state without being in submitted state,';

                        // Set it as a bad post
                        $goodValues=false;
                    }

                    // Determine if they are trying to ready and quote request at the same time
                    if (((!is_numeric($quoteRequestedByID) || $quoteRequestedByID<=0) && $quoteRequested) &&
                        ((!is_numeric($blankReadiedByID  ) || $blankReadiedByID  <=0) && $blankReady    )){
                        // Add to the string to show
                        $badValuesString = $badValuesString . ' Blank cannot be set to quote requested and Readied state at the same time,';

                        // Set it as a bad post
                        $goodValues=false;
                    }


                    // determine that the ready flag is not checked without the submit flag
                    if ($blankReady && !$submitted){
                        // Add to the string to show
                        $badValuesString = $badValuesString . ' Blank cannot be in ready state without being in submitted state,';

                        // Set it as a bad post
                        $goodValues=false;
                    }

                    // Determine if we have bad values for this blank
                    if (!$goodValues && $badValuesString != ''){
                        // Remove the trailing comma and first blank
                        $badValuesString = substr($badValuesString, 0, -1);
                        $badValuesString = substr($badValuesString, 1);

                        // Create the alert string
                        $alertString = 'There were bad values in an already saved blank ' .
                                       'with the reason of ' . $reason . '. The bad values ' .
                                       'were (' . $badValuesString . ').  This one was not ' .
                                       'saved. Try again.';

                        // Send out the alert
                        echo '<script>alert("' . $alertString . '");</script>';

                    }
                    else {
                        // Determine if this one is set to submitted
                        if ($submitted){
                            // Determine if this is newly submitted
                            if (!is_numeric($submittedByID) || $submittedByID<=0){
                                // Set the flag to be that it is being newly submitted
                                $newlySubmitted=1;
                            }

                            // Determine if this has been touched by this user
                            if ($submittedTouched==1){
                                // Set the user ID to this one no matter what. Nulling it will be taken care of later
                                $submittedByID = $userRow["UserID"];

                                // Set the submitted date as the current date
                                $submittedDate = $currentDateString;
                            }
                        }
                        // Determine if this has been previously submitted and now is being unsubmitted
                        else{
                            // Submitted by ID should be removed
                            $submittedByID = 'NULL';

                            // Submitted date should be removed as well
                            $submittedDate = null;

                            // quote requested should be unchecked be unchecked, since it needs to be resubmitted
                            $quoteRequested = 0;

                            // Quote Requested by ID should be removed as well
                            $quoteRequestedByID = 'NULL';

                            // Set the quote requested date as nothing
                            $quoteRequestedDate = null;

                            // Blank ready should be unchecked, since it needs to be resubmitted
                            $blankReady = 0;

                            // Blank readied by ID should be removed as well
                            $blankReadiedByID = 'NULL';

                            // Set the readied date as nothing
                            $blankReadiedDate = null;
                        }

                        // Determine if quote requested is checked
                        if ($quoteRequested){
                            // Determine if this is newly request for quote
                            if (!is_numeric($quoteRequestedByID) || $quoteRequestedByID<=0){
                                // Set the flag to be that it is being newly request for quote
                                $newlyQuoteRequested=1;
                            }

                            // Determine if this has been touched by this user
                            if ($quoteRequestedTouched==1){
                                // Set the user ID to this one no matter what. Nulling it will be taken care of later
                                $quoteRequestedByID = $userRow["UserID"];

                                // Set the quote requested date as the current date
                                $quoteRequestedDate = $currentDateString;
                            }   
                        }
                        else{
                            // Quote Requested by ID should be removed as well
                            $quoteRequestedByID = 'NULL';

                            // Set the quote requested date as nothing
                            $quoteRequestedDate = null;
                        }

                        // Determine if quote requested is checked
                        if ($blankReady){
                            // Determine if this is newly readied
                            if (!is_numeric($blankReadiedByID) || $blankReadiedByID<=0){
                                // Set the flag to be that it is being newly readied
                                $newlyReadied=1;
                            }

                            // Determine if this has been touched by this user
                            if ($blankReadiedTouched==1){
                                // Set the user ID to this one no matter what. Nulling it will be taken care of later
                                $blankReadiedByID = $userRow["UserID"];

                                // Set the readied date as the current date
                                $blankReadiedDate = $currentDateString;
                            }
                        }
                        // Determine if the blank was previously checked readied and is now being reversed
                        else {
                            // Blank readied by ID should be removed as well
                            $blankReadiedByID = 'NULL';

                            // Set the readied date as nothing
                            $blankReadiedDate = null;
                        }

                        // Determine if Is Pending Stock is checked
                        if ($isPendingStock){
                            // Determine if this has been touched by this user
                            if ($isPendingStockTouched==1){
                                // Set the user ID to this one no matter what. Nulling it will be taken care of later
                                $isPendingStockByID = $userRow["UserID"];

                                // Set the readied date as the current date
                                $isPendingStockDate = $currentDateString;
                            }
                        }
                        // Determine if the blank was previously checked readied and is now being reversed
                        else {
                            // Is Pending Stock ID should be removed as well
                            $isPendingStockByID = 'NULL';

                            // Set the is pending stock as nothing
                            $isPendingStockDate = null;
                        }

                        // Set the default values as not selected for all at first
                        $dimension1Precise = 0;
                        $dimension1Clean = 0;
                        $dimension2Precise = 0;
                        $dimension2Clean = 0;
                        $dimension3Precise = 0;
                        $dimension3Clean = 0;

                        // Get the combo box values
                        $dimension1ComboValue = htmlspecialchars($_POST['dimension1Radio'.$loopNumber], ENT_QUOTES, 'UTF-8');
                        $dimension2ComboValue = htmlspecialchars($_POST['dimension2Radio'.$loopNumber], ENT_QUOTES, 'UTF-8');
                        $dimension3ComboValue = htmlspecialchars($_POST['dimension3Radio'.$loopNumber], ENT_QUOTES, 'UTF-8');

                        // Check the combo values to set which one is selected for dimension 1
                        switch ($dimension1ComboValue) {
                            case "Clean":
                                // Clean is selected so set it to true
                                $dimension1Clean = 1;

                                // break out 
                                break;
                            case "Precise":
                                // Precise is selected so set it to true
                                $dimension1Precise = 1;

                                // break out 
                                break;
                        }                

                        // Check the combo values to set which one is selected for dimension 2
                        switch ($dimension2ComboValue) {
                            case "Clean":
                                // Clean is selected so set it to true
                                $dimension2Clean = 1;

                                // break out 
                                break;
                            case "Precise":
                                // Precise is selected so set it to true
                                $dimension2Precise = 1;

                                // break out 
                                break;
                        }                

                        // Check the combo values to set which one is selected for dimension 3
                        switch ($dimension3ComboValue) {
                            case "Clean":
                                // Clean is selected so set it to true
                                $dimension3Clean = 1;

                                // break out 
                                break;
                            case "Precise":
                                // Precise is selected so set it to true
                                $dimension3Precise = 1;

                                // break out 
                                break;
                        }                

                        // Create the update query
                        $sql='UPDATE jobblanks SET';
                        if ($materialID!=null) {$sql = $sql . ' MaterialID=' . $materialID;}
                        if ($createdByID!=null) {$sql = $sql . ' ,CreatedByID=' . $createdByID;}
                        if ($suggestStockID!=null) {$sql = $sql . ' ,SuggestedMaterialStockID=' . $suggestStockID;}
                        if ($type!=null) {$sql = $sql . ' ,Type=\'' . $type . '\'';}
                        if ($dimension1!=null) {$sql = $sql . ' ,Dimension1=' . $dimension1;}
                        $sql = $sql . ' ,Dimension1Precise=' . $dimension1Precise;
                        $sql = $sql . ' ,Dimension1Clean=' . $dimension1Clean;
                        if ($dimension2!=null) {$sql = $sql . ' ,Dimension2=' . $dimension2;}
                        $sql = $sql . ' ,Dimension2Precise=' . $dimension2Precise;
                        $sql = $sql . ' ,Dimension2Clean=' . $dimension2Clean;
                        if ($dimension3!=null) {$sql = $sql . ' ,Dimension3=' . $dimension3;}
                        $sql = $sql . ' ,Dimension3Precise=' . $dimension3Precise;
                        $sql = $sql . ' ,Dimension3Clean=' . $dimension3Clean;
                        if ($quantityDimension!=null) {$sql = $sql . ' ,QuantityDimension=\'' . $quantityDimension . '\'';}
                        $sql = $sql . ' ,WallThickness=' . $wallThickness;

                        // Determine if the ready checkbox has been changed by this user
                        if ($blankReadiedTouched==1){
                            // Modify appropriately
                            $sql = $sql . ' ,BlankReady=' . $blankReady;
                            if ($blankReadiedByID!=null) {$sql = $sql . ' ,BlankReadiedByID=' . $blankReadiedByID;}
                            $sql = $sql . ($blankReadiedDate==null?(' ,BlankReadiedDate=NULL '):(' ,BlankReadiedDate=\'' . $blankReadiedDate . '\' '));
                        }

                        // Determine if the pending stock checkbox has been changed by this user
                        if ($isPendingStockTouched==1){
                            // Modify appropriately
                            $sql = $sql . ' ,IsPendingStock=' . $isPendingStock;
                            if ($isPendingStockByID!=null) {$sql = $sql . ' ,IsPendingStockByID=' . $isPendingStockByID;}
                            $sql = $sql . ($isPendingStockDate==null?(' ,IsPendingStockDate=NULL '):(' ,IsPendingStockDate=\'' . $submittedDate .'\' '));
                        }

                        // Determine if the quote requested checkbox has been changed by this user
                        if ($quoteRequestedTouched==1){
                            // Modify appropriately
                            $sql = $sql . ' ,QuoteRequested=' . $quoteRequested;
                            if ($quoteRequestedByID!=null) {$sql = $sql . ' ,QuoteRequestedByID=' . $quoteRequestedByID;}
                            $sql = $sql . ($quoteRequestedDate==null?(' ,QuoteRequestedDate=NULL '):(' ,QuoteRequestedDate=\'' . $quoteRequestedDate . '\' '));
                        }

                        // Determine if the submitted checkbox has been changed by this user
                        if ($submittedTouched==1){
                            // Modify appropriately
                            $sql = $sql . ' ,Submitted=' . $submitted;
                            if ($submittedByID!=null) {$sql = $sql . ' ,SubmittedByID=' . $submittedByID;}
                            $sql = $sql . ($submittedDate==null?(' ,SubmittedDate=NULL '):(' ,SubmittedDate=\'' . $submittedDate .'\' '));
                        }

                        $sql = $sql . ' ,Rush=' . $rush;
                        if ($reason!=null) {$sql = $sql . ' ,Reason=\'' . $reason . '\'';}
                        if ($quantity!=null) {$sql = $sql . ' ,Quantity=' . $quantity;}
                        $sql=$sql .' WHERE JobBlanksID=' . $loopNumber . ';';
                    }
                }

                // Attempt to run the query and get the response
                if ($db->queryDB($sql, $userRow, "blank_presentation Form occurance 6.")){
                    // Determine if it has been newly submitted or newly readied or new quote requested
                    if ($newlySubmitted || $newlyReadied || $newlyQuoteRequested){
                        // Determine if this is a rush part
                        $rushSubjectString = '';
                        $rushHeaderString = 'NOT rushed. ';
                        if ($rush){
                            // Create the rush strings
                            $rushSubjectString = "** RUSH **";
                            $rushHeaderString = " a RUSH job. ";
                        }

                        // We need to query the material
                        $materialSQL="SELECT * FROM material WHERE MaterialID = " . $materialID . ";";
                        $row = $db->queryDB($materialSQL, $userRow, "blank_presentation Form occurance 9");
                        $assocMaterial = $row->fetch_assoc();

                        // Create blank specs
                        $blankSpecs = $quantity . " blanks of " . 
                                      $dimension1 . " (" . $dimension1ComboValue . 
                                      ") x " . $dimension2 . " (" . $dimension2ComboValue . 
                                      ") x " . $dimension3 . " (" . $dimension3ComboValue . ") " .
                                      $assocMaterial["Category"] . " " . $assocMaterial["Name"] . 
                                      " " . $type;

                        // Init the quoted string
                        $quotedString = '';

                        // Determine if this blank is newly quoted and set a default message for that
                        if ($newlyQuoteRequested){
                            // Set the default to be as though this was NOT the only thing done
                            $quotedString = '<br><br>Quote Requested:<br> This blank has just had QUOTE REQUESTED. ' . 
                                            ' We must wait for quote and delivery before readying blank.<br><br>';
                        }

                        // Determine if it is newly submitted
                        if ($newlySubmitted){
                            // Create the generic subject for just a submitted blank
                            $subject = $rushSubjectString . " TaskID " . $taskID . ": " . 
                                       $blankSpecs . " SUBMITTED. " . $rushSubjectString;

                            // Determine if this blank has a recommended stock ID and change message appropriately
                            $blankInformation="";
                            if ($suggestStockID!=null && $suggestStockID>0){
                                // Only show the the blank that was suggest information to get
                                $blankInformation=ShowSuggested($db, $userRow, $suggestStockID);
                            }
                            else {
                                // Show them any recommendations that we can figure out
                                $blankInformation=RecommendBlankStock($db, $loopNumber, $userRow);
                            }

                            // Create the generic message for just a submitted blank
                            $messageToSend= 'There has been a blank creation SUBMITTED by ' . 
                                    $userRow['FirstName'] . ' ' . $userRow['LastName'] . 
                                    ' for task ID ' . $taskID . '<a href="https://www.eestms.com/' . 
                                    getTMSHome() . '/updateTask.php?updateTaskID=' . 
                                    $taskID . '&parentTaskId=' . $parentTaskNumber . 
                                    '">     (Click To View)</a>' . '. ' . $quotedString . 
                                    'This blank is ' . $rushHeaderString . '.<br><br>The specs are:<br>' . 
                                    $blankSpecs . $blankInformation . 
                                    '<br><br>Cut Dimension is:<br>' . $quantityDimension . '<br><br>' . 
                                    '<br><br>Reason is:<br>' . $reason . '<br><br>' . 
                                    'If you would like to check on this blank, you can ' .
                                    'do so at www.eestms.com/' . getTMSHome() . '.<br><br>' .
                                    'If you need help with your user name or password, you can ' .
                                    'reply to this e-mail or call us at (720)552-7997.<br><br>' .
                                    'Regards, <br><br>Evolve Engineering and Software Support Team<br>' .
                                    '(720)552-7997';

                            // Add the condition to not include submittor
                            $extraConditionalSQL = ' AND   UserID <> ' . $submittedByID . ' ';

                            // Determine if this blank is newly quoted and set a default message for that
                            if ($newlyQuoteRequested){
                                // Add the condition to not include quoter
                                $extraConditionalSQL .= ' AND   UserID <> ' . $quoteRequestedByID . ' ';
                            }

                            // Determine if the submittor also readied the blank
                            if ($newlyReadied){
                                // Create the subject for just a submitted and readied blank
                                $subject = $rushSubjectString . " TaskID " . $taskID . ": " . 
                                           $blankSpecs . " to be HAS BEEN READIED. " . $rushSubjectString;

                                // Create the generic message for just a submitted blank
                                $messageToSend= 'There has been a blank creation SUBMITTED by ' . 
                                        $userRow['FirstName'] . ' ' . $userRow['LastName'] . 
                                        ' for task ID ' . $taskID . '<a href="https://www.eestms.com/' . 
                                        getTMSHome() . '/updateTask.php?updateTaskID=' . 
                                        $taskID . '&parentTaskId=' . $parentTaskNumber . 
                                        '">  (Click To View)</a>' . '.  This blank has already ' . 
                                        'been cut.<br><br>The specs were:<br>' . $blankSpecs . 
                                        '<br><br>Cut Dimension is:<br>' . $quantityDimension . '<br><br>' . 
                                        '<br><br>Reason is: ' . $reason . '<br><br>' . 
                                        'If you would like to check on this blank, you can ' .
                                        'do so at www.eestms.com/' . getTMSHome() . '.<br><br>' .
                                        'If you need help with your user name or password, you can ' .
                                        'reply to this e-mail or call us at (720)552-7997.<br><br>' .
                                        'Regards, <br><br>Evolve Engineering and Software Support Team<br>' .
                                        '(720)552-7997';
                            }
                        }
                        else{
                            // Determine if this blank is newly quoted and set a default message for that
                            if ($newlyQuoteRequested){
                                // Set the default to be as though this was NOT the only thing done
                                $quotedString = '<br><br>Quote Requested:<br> This blank has just had QUOTE REQUESTED. ' . 
                                                ' We must wait for quote and delivery before readying blank.<br><br>';

                                // Create the subject for just a Quoted
                                $subject = " Blank for TaskID " . $taskID . ": With specs of - " . 
                                           $blankSpecs . " HAS BEEN QUOTED. ";

                                // Create the generic message for just a quoted blank
                                $messageToSend= 'There has been a QUOTE REQUESTED by ' . 
                                        $userRow['FirstName'] . ' ' . $userRow['LastName'] . 
                                        ' for task ID ' . $firstFour . '-' . $lastFour . 
                                        '<a href="https://www.eestms.com/' . 
                                        getTMSHome() . '/updateTask.php?updateTaskID=' . 
                                        $taskID . '&parentTaskId=' . $parentTaskNumber . 
                                        '">     (Click To View)</a>' . '.<br><br>The specs were:<br>' . 
                                        $blankSpecs . '<br><br>Reason is:<br>' . $reason . '<br><br>' . 
                                        'If you would like to check on this blank, ' . 
                                        'you can do so at www.eestms.com/' . getTMSHome() . '.<br><br>' .
                                        'If you need help with your user name or password, you can ' .
                                        'reply to this e-mail or call us at (720)552-7997.<br><br>' .
                                        'Regards, <br><br>Evolve Engineering and Software Support Team<br>' .
                                        '(720)552-7997';

                                // Add the condition to not include quoter
                                $extraConditionalSQL = ' AND   UserID <> ' . $quoteRequestedByID . ' ';
                            }
                            else {
                                // Create the subject for just a readied blank
                                $subject = " Blank for TaskID " . $taskID . ": With specs of - " . 
                                           $blankSpecs . " HAS BEEN readied. ";

                                // Create the generic message for just a submitted blank
                                $messageToSend= 'There has been a blank READIED by ' . 
                                        $userRow['FirstName'] . ' ' . $userRow['LastName'] . 
                                        ' for task ID ' . $firstFour . '-' . $lastFour . 
                                        '<a href="https://www.eestms.com/' . 
                                        getTMSHome() . '/updateTask.php?updateTaskID=' . 
                                        $taskID . '&parentTaskId=' . $parentTaskNumber . 
                                        '"> (Click To View)</a>' . '.<br><br>The specs were:<br>' . 
                                        $blankSpecs . '<br><br>Reason is: ' . $reason . '<br><br>' . 
                                        'If you would like to check on this blank, ' . 
                                        'you can do so at www.eestms.com/' . getTMSHome() . '.<br><br>' .
                                        'If you need help with your user name or password, you can ' .
                                        'reply to this e-mail or call us at (720)552-7997.<br><br>' .
                                        'Regards, <br><br>Evolve Engineering and Software Support Team<br>' .
                                        '(720)552-7997';

                                // Add the condition to not include submittor
                                $extraConditionalSQL = ' AND   UserID <> ' . $blankReadiedByID . ' AND SUEmployee=1 AND AccountStatus="Active" ';
                            }
                        }

                        // Add Headers
                        $headers = "From: EES Mail Admin"." <admin@eestms.com>\r\n"; 
                        $headers .= "MIME-Version: 1.0\r\n";
                        $headers .= "Content-type: text/html; charset=iso-8859-1\r\n";

                        // Let's create and get the users to inform
                        $sql='SELECT * 
                              FROM users 
                              WHERE (UserID = ' . $createdByID . '  
                                     OR ReceiveBlankCutNotificationUpdate = 1) 
                              AND UserTemplateOnly=0 '
                              .
                              $extraConditionalSQL
                              . ';';
                        $usersToNotify = $db->queryDB($sql, $userRow, "blank_presentation Form occurance 9.");

                        // Loop through the returned results
                        while ($userToNofity=mysqli_fetch_array($usersToNotify)){
                            try {
                                // Attempt to mail it
                                mail($userToNofity["EMail"],$subject,$messageToSend,$headers);
                            } 
                            catch (Exception $e) {
                                echo("The notification was not sent to " . $assocUser["EMail"] .
                                     " because of an error.");
                            }
                        }
                    }
                }
            }
        }
    }

    function addNewBlanksToDB($db, $userRow, $taskID, $parentTaskNumber){
        // Determine if there are new blanks
        if (isset($_POST['newBlankNumbers']) && $_POST['newBlankNumbers']!=0 &&
            $taskID != null && is_numeric($taskID)){
            // Get the amount of new blanks as a variable
            $blankNumStrings=$_POST['newBlankNumbers'];
            $blankNums=explode('|', $blankNumStrings);

            // Create the visualized task orientation as though this IS the parent
            $firstFour = str_pad($taskID,4,"0",STR_PAD_LEFT);
            $lastFour = '0000';

            // Determine if we are making a child of the parent right now
            if ($parentTaskNumber != 0){
                // Create the visualized task orientation as though this IS the parent
                $firstFour = str_pad($parentTaskNumber,4,"0",STR_PAD_LEFT);
                $lastFour = $taskID;
            }

            // Loop through and get all new note elements
            foreach ($blankNums as $loopNumber){
                // Set the things we can
                $materialID = htmlspecialchars($_POST['newBlankMaterialID'.$loopNumber], ENT_QUOTES, 'UTF-8');
                $createdByID = $userRow["UserID"];
                $type = htmlspecialchars($_POST['newType'.$loopNumber], ENT_QUOTES, 'UTF-8');
                $dimension1 = htmlspecialchars($_POST['newBlankDimension1'.$loopNumber], ENT_QUOTES, 'UTF-8');
                $dimension2 = htmlspecialchars($_POST['newBlankDimension2'.$loopNumber], ENT_QUOTES, 'UTF-8');
                $dimension3 = htmlspecialchars($_POST['newBlankDimension3'.$loopNumber], ENT_QUOTES, 'UTF-8');
                $quantityDimension = htmlspecialchars($_POST['newBlankQuantityDimension'.$loopNumber], ENT_QUOTES, 'UTF-8');
                $wallThickness = htmlspecialchars($_POST['newWallThickness'.$loopNumber], ENT_QUOTES, 'UTF-8');
                $rush = (isset($_POST['newBlankRush'.$loopNumber])?1:0);
                $submitted = (isset($_POST['newBlankSubmitted'.$loopNumber])?1:0);
                $submittedByID = null;
                $submittedDate = null;
                $blankReady = (isset($_POST['newBlankReady'.$loopNumber])?1:0);
                $blankReadiedByID = null;
                $blankReadiedDate = null;
                $isWaitingForStock = (isset($_POST['newIsPendingStock'.$loopNumber])?1:0);
                $isWaitingForStockByID = null;
                $isWaitingForStockDate = null;
                $reason = htmlspecialchars($_POST['newBlankReason'.$loopNumber], ENT_QUOTES, 'UTF-8');
                $quantity = htmlspecialchars($_POST['newBlankQuantity'.$loopNumber], ENT_QUOTES, 'UTF-8');
                $suggestStockID = htmlspecialchars($_POST['newSuggestStockID'.$loopNumber], ENT_QUOTES, 'UTF-8');

                // Set the good values flag to true
                $goodValues = true;

                // Init Set the bad values to show back to the user
                $badValuesString = '';

                // Check if the dimension 1 is good
                if (!is_numeric($dimension1)){
                    // Add to the string to show
                    $badValuesString = $badValuesString . ' Dimension 1 was not a decimal,';

                    // Set it as a bad post
                    $goodValues=false;
                }

                // Check if the dimension 2 is good
                if (!is_numeric($dimension2)){
                    // Add to the string to show
                    $badValuesString = $badValuesString . ' Dimension 2 was not a decimal,';

                    // Set it as a bad post
                    $goodValues=false;
                }

                // Check if the dimension 3 is good
                if (!is_numeric($dimension3)){
                    // Add to the string to show
                    $badValuesString = $badValuesString . ' Dimension 3 was not a decimal,';

                    // Set it as a bad post
                    $goodValues=false;
                }

                // Check if the quantity is good
                if (!is_numeric($quantity) || fmod($quantity, (int)$quantity)!=0){
                    // Add to the string to show
                    $badValuesString = $badValuesString . ' Quantity was not an integer,';

                    // Set it as a bad post
                    $goodValues=false;
                }

                // determine that the ready flag is not checked without the submit flag
                if ($blankReady && !$submitted){
                    // Add to the string to show
                    $badValuesString = $badValuesString . ' Blank cannot be in ready state without being in submitted state,';

                    // Set it as a bad post
                    $goodValues=false;
                }

                // Determine if we have bad values for this blank
                if (!$goodValues && $badValuesString != ''){
                    // Remove the trailing comma and first blank
                    $badValuesString = substr($badValuesString, 0, -1);
                    $badValuesString = substr($badValuesString, 1);

                    // Create the alert string
                    $alertString = 'There were bad values in a newly created blank ' .
                                   'with the reason of ' . $reason . '. The bad values ' .
                                   'were (' . $badValuesString . ').  This one was not ' .
                                   'saved. Try again.';

                    // Send out the alert
                    echo '<script>alert("' . $alertString . '");</script>';

                }
                else {
                    // Set the default values as not selected for all at first
                    $dimension1Precise = 0;
                    $dimension1Clean = 0;
                    $dimension2Precise = 0;
                    $dimension2Clean = 0;
                    $dimension3Precise = 0;
                    $dimension3Clean = 0;

                    // Get the combo box values
                    $dimension1ComboValue = htmlspecialchars($_POST['newBlankDimension1Radio'.$loopNumber], ENT_QUOTES, 'UTF-8');
                    $dimension2ComboValue = htmlspecialchars($_POST['newBlankDimension2Radio'.$loopNumber], ENT_QUOTES, 'UTF-8');
                    $dimension3ComboValue = htmlspecialchars($_POST['newBlankDimension3Radio'.$loopNumber], ENT_QUOTES, 'UTF-8');

                    // Check the combo values to set which one is selected for dimension 1
                    switch ($dimension1ComboValue) {
                        case "Clean":
                            // Clean is selected so set it to true
                            $dimension1Clean = 1;

                            // break out 
                            break;
                        case "Precise":
                            // Precise is selected so set it to true
                            $dimension1Precise = 1;

                            // break out 
                            break;
                    }                

                    // Check the combo values to set which one is selected for dimension 2
                    switch ($dimension2ComboValue) {
                        case "Clean":
                            // Clean is selected so set it to true
                            $dimension2Clean = 1;

                            // break out 
                            break;
                        case "Precise":
                            // Precise is selected so set it to true
                            $dimension2Precise = 1;

                            // break out 
                            break;
                    }                

                    // Check the combo values to set which one is selected for dimension 3
                    switch ($dimension3ComboValue) {
                        case "Clean":
                            // Clean is selected so set it to true
                            $dimension3Clean = 1;

                            // break out 
                            break;
                        case "Precise":
                            // Precise is selected so set it to true
                            $dimension3Precise = 1;

                            // break out 
                            break;
                    }        

                    // Get a current date value
                    $currentDate = new DateTime();
                    $currentDate->modify('-1 hour');
                    $currentDateString = $currentDate->format('Y-m-d H:i:s');

                    // Determine if this is being submitted
                    if ($submitted){
                        // Set the user submitting this as the person creating this
                        $submittedByID = $userRow["UserID"];

                        // Set the submission date to now
                        $submittedDate = $currentDateString;

                        // Determine if this is already ready
                        if ($blankReady){
                            // Set the user readying this as the person creating this
                            $blankReadiedByID = $userRow["UserID"];

                            // Set the readied date to now
                            $blankReadiedDate = $currentDateString;
                        }
                    }

                    // Determine if this is waiting for stock
                    if ($isWaitingForStock){
                        // Set the user saying it is waiting for stock as the person creating this
                        $isWaitingForStockByID = $userRow["UserID"];

                        // Set the waiting for stock date to now
                        $isWaitingForStockDate = $currentDateString;
                    }

                    // Let's create the insert query off of what we have
                    $sql='INSERT INTO jobblanks (TaskID ';
                    if ($materialID!=null) {$sql = $sql . ', MaterialID';}
                    if ($createdByID!=null) {$sql = $sql . ', CreatedByID';}
                    if ($suggestStockID!=null) {$sql = $sql . ', SuggestedMaterialStockID';}
                    if ($type!=null) {$sql = $sql . ', Type';}
                    if ($dimension1!=null) {$sql = $sql . ', Dimension1';}
                    $sql = $sql . ', Dimension1Precise';
                    $sql = $sql . ', Dimension1Clean';
                    if ($dimension2!=null) {$sql = $sql . ', Dimension2';}
                    $sql = $sql . ', Dimension2Precise';
                    $sql = $sql . ', Dimension2Clean';
                    if ($dimension3!=null) {$sql = $sql . ', Dimension3';}
                    $sql = $sql . ', Dimension3Precise';
                    $sql = $sql . ', Dimension3Clean';
                    if ($quantityDimension!=null) {$sql = $sql . ', QuantityDimension';}
                    if ($wallThickness!=null) {$sql = $sql . ', WallThickness';}
                    $sql = $sql . ', BlankReady';
                    if ($blankReady) {$sql = $sql . ', BlankReadiedByID';}
                    if ($blankReady) {$sql = $sql . ', BlankReadiedDate';}
                    $sql = $sql . ', Rush';
                    $sql = $sql . ', Submitted';
                    if ($submitted) {$sql = $sql . ', SubmittedByID';}
                    if ($submitted) {$sql = $sql . ', SubmittedDate';}
                    $sql = $sql . ', IsPendingStock';
                    if ($isWaitingForStock) {$sql = $sql . ', IsPendingStockByID';}
                    if ($isWaitingForStock) {$sql = $sql . ', IsPendingStockDate';}
                    if ($reason!=null) {$sql = $sql . ', Reason';}
                    if ($quantity!=null) {$sql = $sql . ', Quantity';}
                    $sql=$sql .') VALUES (' . $taskID;
                    if ($materialID!=null) {$sql = $sql . ', ' . $materialID;}
                    if ($createdByID!=null) {$sql = $sql . ', ' . $createdByID;}
                    if ($suggestStockID!=null) {$sql = $sql . ', ' . $suggestStockID;}
                    if ($type) {$sql = $sql . ', \'' . $type . '\'';}
                    if ($dimension1!=null) {$sql = $sql . ', ' . $dimension1;}
                    $sql = $sql . ', ' . $dimension1Precise;
                    $sql = $sql . ', ' . $dimension1Clean;
                    if ($dimension2!=null) {$sql = $sql . ', ' . $dimension2;}
                    $sql = $sql . ', ' . $dimension2Precise;
                    $sql = $sql . ', ' . $dimension2Clean;
                    if ($dimension3!=null) {$sql = $sql . ', ' . $dimension3;}
                    $sql = $sql . ', ' . $dimension3Precise;
                    $sql = $sql . ', ' . $dimension3Clean;
                    if ($quantityDimension) {$sql = $sql . ', \'' . $quantityDimension . '\'';}
                    if ($wallThickness!=null) {$sql = $sql . ', ' . $wallThickness;}
                    $sql = $sql . ', ' . $blankReady;
                    if ($blankReady) {$sql = $sql . ', ' . $blankReadiedByID;}
                    if ($blankReady) {$sql = $sql . ', \'' . $blankReadiedDate . '\'';}
                    $sql = $sql . ', ' . $rush;
                    $sql = $sql . ', ' . $submitted;
                    if ($submitted) {$sql = $sql . ', ' . $submittedByID;}
                    if ($submitted) {$sql = $sql . ', \'' . $submittedDate . '\'';}
                    $sql = $sql . ', ' . $isWaitingForStock;
                    if ($isWaitingForStock) {$sql = $sql . ', ' . $isWaitingForStockByID;}
                    if ($isWaitingForStock) {$sql = $sql . ', \'' . $isWaitingForStockDate . '\'';}
                    if ($reason!=null) {$sql = $sql . ', \'' . $reason . '\'';}
                    if ($quantity!=null) {$sql = $sql . ', ' . $quantity;}
                    $sql=$sql .');';

                    // Attempt to run the query and get the response
                    if ($db->queryDB($sql, $userRow, "blank_presentation Form occurance 7.")){
                        // Get the most recent ID (task)
                        $newBlankID = mysqli_insert_id($db->getDBConnection());

                        // Determine if this person has submitted blank
                        if ($submitted){
                            // Determine if this blank is awaiting stock
                            $rushSubjectString = '';
                            if ($isWaitingForStock){
                                // Determine if this is a rush part
                                $rushString = 'in due time. It is not rushed';
                                if ($rush){
                                    // Create the rush strings
                                    $rushSubjectString = "** RUSH **";
                                    $rushString = " with the greatest of haste. This is a rush job";
                                }

                                // Finish off the rush string
                                $rushString='This blank material is <b>NOT IN STOCK</b>, but will come ' . $rushString . '.';
                            }
                            else {
                                // Determine if this is a rush part
                                $rushString = 'in a timely mannner. It is not rushed';
                                if ($rush){
                                    // Create the rush strings
                                    $rushSubjectString = "** RUSH **";
                                    $rushString = " with the greatest of haste. This is a rush job";
                                }

                                // Finish off the rush string
                                $rushString='This blank is to be cut ' . $rushString . '.';
                            }

                            // We need to query the material
                            $materialSQL="SELECT * FROM material WHERE MaterialID = " . $materialID . ";";
                            $row = $db->queryDB($materialSQL, $userRow, "blank_presentation Form occurance 9");
                            $assocMaterial = $row->fetch_assoc();

                            // Create blank specs
                            $blankSpecs = $quantity . " blanks of " . 
                                          $dimension1 . " (" . $dimension1ComboValue . 
                                          ") x " . $dimension2 . " (" . $dimension2ComboValue . 
                                          ") x " . $dimension3 . " (" . $dimension3ComboValue . ") " .
                                          $assocMaterial["Category"] . " " . $assocMaterial["Name"] . 
                                          " " . $type;

                            // Create the generic subject for just a submitted blank
                            $subject = $rushSubjectString . " TaskID " . $taskID . ": " . 
                                       $blankSpecs . " to be cut. " . $rushSubjectString;

                            // Determine if this blank has a recommended stock ID and change message appropriately
                            $blankInformation="";
                            if ($suggestStockID!=null && $suggestStockID>0){
                                // Only show the the blank that was suggest information to get
                                $blankInformation=ShowSuggested($db, $userRow, $suggestStockID);
                            }
                            else {
                                // Show them any recommendations that we can figure out
                                $blankInformation=RecommendBlankStock($db, $newBlankID, $userRow);
                            }

                            // Create the generic message for just a submitted blank
                            $messageToSend= 'There has been a blank creation submitted by ' . 
                                    $userRow['FirstName'] . ' ' . $userRow['LastName'] . 
                                    ' for task ID ' . $firstFour . '-' . $lastFour . 
                                    '<a href="https://www.eestms.com/' . getTMSHome() . 
                                    '/updateTask.php?updateTaskID=' . $taskID . '&parentTaskId=' . 
                                    $parentTaskNumber . '"> (Click To View)</a>' .
                                    '.  ' . $rushString . '<br><br>The specs are:<br>' . 
                                    $blankSpecs . '<br><br>Reason is: ' . $reason . $blankInformation . 
                                    '<br><br>Cut Dimension is:<br>' . $quantityDimension . '<br><br>' . 
                                    '<br><br>If you would like to check on this blank, you can ' .
                                    'do so at www.eestms.com/' . getTMSHome() . '.<br><br>' .
                                    'If you need help with your user name or password, you can ' .
                                    'reply to this e-mail or call us at (720)552-7997.<br><br>' .
                                    'Regards, <br><br>Evolve Engineering and Software Support Team<br>' .
                                    '(720)552-7997';

                            // Determine if the submittor also readied the blank
                            if ($blankReady){
                                // Create the subject for just a submitted and readied blank
                                $subject = $rushSubjectString . " TaskID " . $taskID . ": " . 
                                           $blankSpecs . " to be HAS BEEN cut. " . $rushSubjectString;

                                // Create the generic message for just a submitted blank
                                $messageToSend= 'There has been a blank creation submitted by ' . 
                                        $userRow['FirstName'] . ' ' . $userRow['LastName'] . 
                                        ' for task ID ' . $firstFour . '-' . $lastFour . 
                                        '<a href="https://www.eestms.com/' . 
                                        getTMSHome() . '/updateTask.php?updateTaskID=' . 
                                        $taskID . '&parentTaskId=' . $parentTaskNumber . 
                                        '">  (Click To View)</a>' . '.  This blank has already ' . 
                                        'been cut.<br><br>The specs were:<br>' . $blankSpecs . 
                                        '<br><br>Cut Dimension is:<br>' . $quantityDimension . '<br><br>' . 
                                        '<br><br>Reason is: ' . $reason . '<br><br>' . 
                                        'If you would like to check on this blank, you can ' .
                                        'do so at www.eestms.com/' . getTMSHome() . '.<br><br>' .
                                        'If you need help with your user name or password, you can ' .
                                        'reply to this e-mail or call us at (720)552-7997.<br><br>' .
                                        'Regards, <br><br>Evolve Engineering and Software Support Team<br>' .
                                        '(720)552-7997';
                            }

                            // Add Headers
                            $headers = "From: EES Mail Admin"." <admin@eestms.com>\r\n"; 
                            $headers .= "MIME-Version: 1.0\r\n";
                            $headers .= "Content-type: text/html; charset=iso-8859-1\r\n";

                            // Let's create and get the users to inform
                            $sql='SELECT * 
                                  FROM users 
                                  WHERE (UserID = ' . $createdByID . ' 
                                  OR    ReceiveBlankCutNotificationUpdate = 1) 
                                  AND   UserTemplateOnly=0 
                                  AND   UserID <> ' . $submittedByID . ' AND SUEmployee=1 AND AccountStatus="Active";';
                            $usersToNotify = $db->queryDB($sql, $userRow, "blank_presentation Form occurance 9.");

                            // Loop through the returned results
                            while ($userToNofity=mysqli_fetch_array($usersToNotify)){
                                try {
                                    // Attempt to mail it
                                    mail($userToNofity["EMail"],$subject,$messageToSend,$headers);
                                } 
                                catch (Exception $e) {
                                    echo("The notification was not sent to " . $assocUser["EMail"] .
                                         " because of an error.");
                                }
                            }
                        }
                    }
                }
            }
        }
    }

    function retrieveBlanksDiv($db, $userRow, $inTaskID, &$validationHTML=null){
        // Get any current blanks
        $results=retrieveCurrentBlanks($db, $userRow, $inTaskID, $validationHTML);

        // Determine if we added some blanks
        $blankColorHtml = '';
        if ($results != '') {
            // Change the color of the Blanks Title font
            $blankColorHtml = 'style="color:LimeGreen;"';
        }

        // Init all of the settings to the appropriate values
        $blankDiv = '   
                        <script type="text/javascript">
                            ' 
                            . 
                            createJavaArrayOfMaterialAsSelectOptions($db, $userRow, false) 
                            . 
                            createJavaArrayOfMaterialTypesAsSelectOptions($db, $userRow, false, 'Extrusion') 
                            . 
                            '
                            var genericDimensionRadio = "' . createGenericTypeRadioButton('genericDimension1Radio', 'genericDimension1', false, false) . '";
                        </script>
                        <br><br>
                        <table width="100%">
                            <tr width="100%">
                                <td align="left" width="50%">
                                    <label style="font-size: 20px;"><strong>New Blanks: </strong></label>
                                </td>
                                <td align="right" width="50%">
                                    <input type="hidden" id="newBlankNumbers" name="newBlankNumbers" value="0"></input>
                                    <button type="button" onClick="addNewBlank(\'USER\'); if (typeof _isDirty !== \'undefined\' && _isDirty !== null) {_isDirty=true;};" align="right">Add New Blank</button>
                                </td>
                            </tr>
                        </table>
                        <div id="newBlanks" style="border-top-style:dashed; border-width: 1px; ">
                        </div>
                        ' .
                        $results .
                        '
                    ';

        // Return the result
        return $blankDiv;
    }

    function copyBlanks($db, $userRow, &$currentSuccess, $newTaskID, $taskIDToCopy=null){
        try {
            // Determine if they are currently successful as well as the proper variables are passed in
            if ($currentSuccess && 
                $taskIDToCopy!= null && $taskIDToCopy>0 && 
                $newTaskID!= null && $newTaskID>0){
                    // Create the query as if there is a parent
                    $sql='INSERT INTO jobblanks(TaskID, MaterialID, CreatedByID, ' . 
                            'SuggestedMaterialStockID, Category, Type, Reason, ' . 
                            'Dimension1, Dimension1Precise, Dimension1Clean, ' . 
                            'Dimension2, Dimension2Precise, Dimension2Clean, ' . 
                            'Dimension3, Dimension3Precise, Dimension3Clean, ' . 
                            'QuantityDimension, WallThickness, Quantity) ' . 
                          'SELECT ' . $newTaskID . ', MaterialID, CreatedByID, ' . 
                            'SuggestedMaterialStockID, Category, Type, Reason, ' . 
                            'Dimension1, Dimension1Precise, Dimension1Clean, ' . 
                            'Dimension2, Dimension2Precise, Dimension2Clean, ' . 
                            'Dimension3, Dimension3Precise, Dimension3Clean, ' . 
                            'QuantityDimension, WallThickness, 0 ' . 
                            'FROM jobblanks WHERE TaskID=' . $taskIDToCopy . ';';

                // Attempt to update the task
                if (!$db->queryDB($sql, $userRow, "blank_presentation Form occurance 10")){
                    // Set all as a fail
                    $currentSuccess=false;
                }
            }
        } 
        catch (Exception $ex) {
            // Assign the output string as to what happened
            return $currentSuccess;
        } 
        finally {
            // Return the result
            return $currentSuccess;
        }
    }

    function createBlankCopyContent($userRow){
        // determine if this is a user in the super company. The company 
        // with it's ID as '1' in the TMS is the Super Company. Non-SU
        // users cannot see tasks on machines.
        if ($userRow["CompanyID"]!=1){
            // Return nothing back
            return "";
        }

        try {
            // Create the content
            $result = '
                <table width="100%" border="0">
                    <tr>
                        <td height="39" align="left" colspan=2>
                            <strong>What is the reason for copying the blank? </strong>
                            <br>
                            <textarea name="addedBlankReason" id="addedBlankReason" maxlength="2000" style="width: 100%; height: 100px; overflow: auto; resize:none" value=""/></textarea>
                        </td>
                    </tr>
                    <tr>
                        <td height="39" colspan=1>
                            <strong>Amount Of Blanks:</strong>
                        </td>
                        <td height="39" colspan=1>
                            <input type="text" maxlength="5" name="blankQuantity" id="blankQuantity" value=""/>
                        </td>
                    </tr>
                    <tr>
                        <td height="39" align="left" colspan=1>
                            <strong>Rushed:</strong>
                        </td>
                        <td height="39" colspan=1>
                            <input class="notinput" name="blankRushed" id="blankRushed" type="checkbox"/>
                        </td>
                    </tr>
                </table>
                ';
        } catch (Exception $ex) {
            // Return nothing
            return "";
        }

        // Return whatever we got
        return $result;
    }
    
?>   
