<?php    
function retrieveCurrentChildNotes($db, $userRow, $inAssociatedCategoryID, $inCategoryType, $inNameLabel="", &$validationHTML="", $allowSUCompanyDeletion=false){
    // Set the return result to nothing in case nothing is passed in for task number
    $result='';

    try {
        // Init necessary variables
        $type=$inCategoryType;
        $associatedCategoryID = $inAssociatedCategoryID;

        // Determine if I am supposed to check for current notes or not
        if ($associatedCategoryID!=null && is_numeric($associatedCategoryID) &&
            $type!=null){
            $levelsAllowedToSee='';

            // Determine if they want to see employee notes
            if ($type=='EMPLOYEE'){
                // Create condition that only the higher levels see lower levels notes
                $levelsAllowedToSee = 'AND (u.UserLevel IN ('; 
                switch ($userRow["UserLevel"]){
                    case 'SU':
                        // Allow SU's to See SU's and Exec's
                        $levelsAllowedToSee = $levelsAllowedToSee . '"SU", "EXECUTIVE", ';
                    case 'EXECUTIVE':
                        // Allow EXECUTIVE's to See MANAGEMENT's
                        $levelsAllowedToSee = $levelsAllowedToSee . '"MANAGEMENT", ';
                    case 'MANAGEMENT':
                        // Allow MANAGEMENT's to See MID-MANAGEMENT's
                        $levelsAllowedToSee = $levelsAllowedToSee . '"MID-MANAGEMENT", ';
                    case 'MID-MANAGEMENT' :
                        // Allow MID-MANAGEMENT's to See TYPICAL's
                        $levelsAllowedToSee = $levelsAllowedToSee . '"TYPICAL", ';
                    case 'TYPICAL' :
                        // Allow TYPICAL's to See MINIMAL's
                        $levelsAllowedToSee = $levelsAllowedToSee . '"MINIMAL") ' . 
                                      'OR n.EnteredByID = ' . $userRow["UserID"] . ') ';

                        // Exit from adding to the string, since minimal canot see anything
                        break;
                    case 'MINIMAL' :
                        // Allow these to see none
                        $levelsAllowedToSee = ' '; 
                }
            }
                
            // Create the query to get the the notes and the user that created the notes
            $sql = 'SELECT n.*, u.FirstName, u.LastName, u.UserLevel ' .
                   'FROM notes n ' . 
                   'INNER JOIN users u ON n.EnteredByID = u.UserID ' .
                   'WHERE n.AssociatedCategoryID=' . $associatedCategoryID . ' ' .
                   $levelsAllowedToSee . ' AND n.Category="' . $type . '" '. 
                   'AND n.IsSticky=0 ' .
                   'ORDER BY n.NoteOrder, n.Date DESC;';
            
            // Attempt to get all of the notes for this category type and ID
            $rows = $db->queryDB($sql, $userRow, "child_presentation Form occurance 1");

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

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

                // Loop through the returned results
                $amount=0;
                while ($row=mysqli_fetch_array($rows)){
                    // Increment the amount
                    $amount++;

                    // Set the things we can
                    $noteID = $row["NoteID"];
                    $noteDate=$row["Date"];
                    $noteTitle = $row["Title"];
                    $note=$row["Note"];
                    $noteEnteredByID=$row["EnteredByID"];
                    $noteEnteredByFirstName = $row["FirstName"];
                    $noteEnteredByLastName = $row["LastName"];
                    $noteOrder = $row["NoteOrder"];
                    
                    // Start adding the notes that are in the database
                    $result = $result . 
                                '   <div class="Table" id="' . $type . $associatedCategoryID . 'CurrentNote' . $noteID . '" name="' . $type . $associatedCategoryID . 'CurrentNote' . $noteID . '" style="margin-top:10px; border-top-style:dashed; border-width: 1px; text-align: left;">
                                        <div class="Row" id="' . $type . $associatedCategoryID . 'NoteEnteredByLineDiv' . $noteID . '" name="' . $type . $associatedCategoryID . 'NoteEnteredByLineDiv' . $noteID . '"> 
                                            <input type="hidden" name="' . $type . $associatedCategoryID . 'EnteredBy' . $noteID . '" id="' . $type . $associatedCategoryID . 'EnteredBy' . $noteID . '" value="' . $noteEnteredByID . '">
                                            <input type="hidden" name="' . $type . $associatedCategoryID . 'NoteID' . $noteID . '" id="' . $type . $associatedCategoryID . 'NoteID' . $noteID . '" value="' . $noteID . '">
                                            <input type="hidden" name="' . $type . $associatedCategoryID . 'AssociatedCategoryID' . $noteID . '" id="' . $type . $associatedCategoryID . 'AssociatedCategoryID' . $noteID . '" value="' . $associatedCategoryID . '">
                                            <input type="hidden" name="' . $type . $associatedCategoryID . 'CategoryType' . $noteID . '" id="' . $type . $associatedCategoryID . 'CategoryType' . $noteID . '" value="' . $type . '">
                                            <div class="noteTableCell fullNoteLabelCell" style="width: 15%;"><label style="width:100%;">Created By:</label></div>
                                            <div class="noteTableCell fullNoteTextCell" style="width: 85%;"><label style="width:100%;">' . $noteEnteredByFirstName . '  ' . $noteEnteredByLastName . '</label></div>
                                        </div>
                                        <div class="Row" id="' . $type . $associatedCategoryID . 'NoteOrderLineDiv' . $noteID . '" name="' . $type . $associatedCategoryID . 'NoteOrderLineDiv' . $noteID . '"> 
                                            <div class="noteTableCell fullNoteLabelCell" style="width: 15%;"><label style="width:100%;">Order:</label></div>
                                            <div class="noteTableCell fullNoteTextCell" style="width: 85%;"><input style="width:100%;" type="text" maxlength="3" name="' . $type . $associatedCategoryID . 'NoteOrder' . $noteID . '" id="' . $type . $associatedCategoryID . 'NoteOrder' . $noteID . '" value="' . $noteOrder . '"/></div>
                                        </div>
                                        <div class="Row" id="' . $type . $associatedCategoryID . 'NoteDateLineDiv' . $noteID . '" name="' . $type . $associatedCategoryID . 'NoteDateLineDiv' . $noteID . '"> 
                                            <div class="noteTableCell fullNoteLabelCell" style="width: 15%;"><label style="width:100%;">Date:</label></div>
                                            <div class="noteTableCell fullNoteTextCell" style="width: 85%;"><input style="width:100%;" type="datetime-local" name="' . $type . $associatedCategoryID . 'NoteDate' . $noteID . '" id="' . $type . $associatedCategoryID . 'NoteDate' . $noteID . '" value="' . str_replace(" ","T",$noteDate) . '"/></div>
                                        </div>
                                        <div class="Row" id="' . $type . $associatedCategoryID . 'NoteTitleLineDiv' . $noteID . '" name="' . $type . $associatedCategoryID . 'NoteTitleLineDiv' . $noteID . '"> 
                                            <div class="noteTableCell fullNoteLabelCell" style="width: 15%;"><label style="width:100%;">Title (required):</label></div>
                                            <div class="noteTableCell fullNoteTextCell" style="width: 85%;"><input style="width:100%;" type="text" maxlength="30" name="' . $type . $associatedCategoryID . 'NoteTitle' . $noteID . '" id="' . $type . $associatedCategoryID . 'NoteTitle' . $noteID . '" value="' . $noteTitle . '"/></div>
                                        </div>
                                        <div class="Row" id="' . $type . $associatedCategoryID . 'NoteLineDiv' . $noteID . '" name="' . $type . $associatedCategoryID . 'NoteLineDiv' . $noteID . '"> 
                                            <div class="noteTableCell fullNoteLabelCell" style="width: 15%;"><label style="width:100%;">Note (required):</label></div>
                                            <div class="noteTableCell fullNoteTextCell" style="width: 85%;">
                                                <textarea name="' . $type . $associatedCategoryID . 'Note' . $noteID . '" id="' . $type . $associatedCategoryID . 'Note' . $noteID . '" maxlength="2000" class="intext" style="width: 100%; height: 111px; overflow: auto; resize:none">' .
                                                $note .
                                                '</textarea>
                                            </div>
                                        </div>
                                ';

                    // Get the size of the file
                    $fileSize = $row["ByteSize"]; 
                    $fname    = $row["FileName"]; 
                    $fileType = $row["FileType"]; 

                    //Init variables
                    $viewtag = '';
                    $removeNoteTag='';
                    $removeAttachmentTag=' 
                                    Replace Attachment
                                    <br>
                                    <input type="file" name="' . $type . $associatedCategoryID . 'AttachmentElement' . $noteID . '" id="' . $type . $associatedCategoryID . 'AttachmentElement' . $noteID . '" onChange="currentChildAttachmentOnChange(\'' . $type . '\', ' . $inAssociatedCategoryID . ', ' . $noteID . ');">
                                 ';
                                            
                    // Determine if the user is an executive or not
                    if ($userRow["UserLevel"]=='SU' || ($allowSUCompanyDeletion && $userRow["CompanyID"]==1)){
                        $removeNoteTag = $removeNoteTag . '  
                                        <br>
                                        <label id="' . $type . $associatedCategoryID . 'RemoveNoteLabel' . $noteID . '">Remove ' . $inNameLabel . '</label>
                                        <input class="notinput" type="checkbox" id="' . $type . $associatedCategoryID . 'RemoveNote' . $noteID . '" name="' . $type . $associatedCategoryID . 'RemoveNote' . $noteID . '" title="This being checked on update will remove the note." value="' . $noteID . '"></input>
                                     ';
                    }

                    // Determine if this is an image type or not
                    if ($fileType !== null) {
                        if (strpos($fileType, 'image') !== false){
                            // setup the view tag to show this image
                            $viewtag = '<a href="view_note_image.php?id=' . $noteID . '" target="_blank">
                                            View <img src="php_only_scripts/show_blob.php?id=' . $noteID . '&tbl=notes&idf=NoteID&bf=Datum&tyf=FileType&nmf=FileName&szf=ByteSize" height=45 style="vertical-align: middle;">
                                        </a>';
                        }
                        
                        // Determine if the user is an executive or not
                        if ($userRow["UserLevel"]=='SU' ){
                            $removeAttachmentTag = $removeAttachmentTag . '  
                                            <br>
                                            <label id="' . $type . $associatedCategoryID . 'RemoveAttachmentLabel' . $noteID . '">Remove Attachment</label>
                                            <input class="notinput" type="checkbox" id="' . $type . $associatedCategoryID . 'RemoveAttachment' . $noteID . '" name="' . $type . $associatedCategoryID . 'RemoveAttachment' . $noteID . '" title="This being checked on update will remove the attachment." value="' . 
                                            $noteID . '"  onclick="javascript:div_toggleVisibilityOnCheckbox(\'' . $type . $associatedCategoryID . 'RemoveAttachment' . $noteID . '\',\'' . $type . $associatedCategoryID . 'ImageCell' . $noteID . '\', \'OPPOSITE\');"></input>
                                         ';
                        }

                        // Add the attachment to the table
                        $result = $result .
                            '   <div class="Row" name="' . $type . $associatedCategoryID . 'ImageLineDiv' . $noteID . '" id="' . $type . $associatedCategoryID . 'ImageLineDiv' . $noteID . '">
                                    <div class="noteTableCell" style="width: 20%; text-align: left;"> ' . 
                                    $removeAttachmentTag .
                                    $removeNoteTag .
                                    '
                                    </div>
                                    <div class="noteTableCell" name="' . $type . $associatedCategoryID . 'ImageCell' . $noteID . '" id="' . $type . $associatedCategoryID . 'ImageCell' . $noteID . '" style="width: 80%; text-align: center;">
                                        ' . $fname . '
                                        <br>
                                        <a href="php_only_scripts/show_blob.php?id=' . $noteID . '&tbl=notes&idf=NoteID&bf=Datum&tyf=FileType&nmf=FileName&szf=ByteSize">Download</a>' .
                                        $viewtag . '
                                        <br>
                                        Type=' . $fileType . '  
                                        <br> 
                                        Size=' . $fileSize . ' KB
                                    </div>
                                </div>';
                    }
                    else {
                        // Don't show anything about any attachment except adding one
                        $result = $result .
                            '   <div class="Row" name="' . $type . $associatedCategoryID . 'ImageLineDiv' . $noteID . '" id="' . $type . $associatedCategoryID . 'ImageLineDiv' . $noteID . '">
                                    <div class="noteTableCell" style="width: 20%; text-align: left;"> ' . 
                                    $removeAttachmentTag .
                                    $removeNoteTag .
                                    '
                                    </div>
                                    <div class="noteTableCell" name="' . $type . $associatedCategoryID . 'ImageCell' . $noteID . '" id="' . $type . $associatedCategoryID . 'ImageCell' . $noteID . '" style="width: 80%; text-align: center;">
                                    </div>
                                </div>';
                    }

                    // Finish the tag
                    $result = $result . '</div>';
                    
                    // Add something to the array list
                    $notesIDArray = $notesIDArray . $row["NoteID"] . '|';
                    
                    
                    // Add the validators for these
                    $validationHTML = $validationHTML . '
                                        frmvalidator.addValidation("' . $type . $associatedCategoryID . 'NoteTitle' . $noteID . '",
                                                                   "req",
                                                                   "Please enter a title for all notes.");
                                        frmvalidator.addValidation("' . $type . $associatedCategoryID . 'Note' . $noteID . '",
                                                                   "req",
                                                                   "Please enter note text for all.");
                                        frmvalidator.addValidation("' . $type . $associatedCategoryID . 'NoteOrder' . $noteID . '",
                                                                   "req",
                                                                   "Please enter an order for all notes.");
                                        frmvalidator.addValidation("' . $type . $associatedCategoryID . 'NoteOrder' . $noteID . '",
                                                                   "num",
                                                                   "Please enter the order for all notes as a number.");
                                        frmvalidator.addValidation("' . $type . $associatedCategoryID . 'NoteOrder' . $noteID . '",
                                                                   "greaterthan=-.0000000001",
                                                                   "The order for all blanks should be greater than 0.");
                                    ';
                    
                }
                
                // Add the hidden field to the form
                $result = 
                        '<label style="font-size: 20px;"><strong>Current ' . $inNameLabel . 's: </strong></label>
                         <div id="' . $type . $associatedCategoryID . 'CurrentNotesDiv" style="width: 95%;">
                             <input type="hidden" name="' . $type . $associatedCategoryID . 'CurrentNotesArray" id="' . $type . $associatedCategoryID . 'CurrentNotesArray" value="' . $notesIDArray . '"></input>
                             <input type="hidden" name="' . $type . $associatedCategoryID . 'DeleteCurrentNotes" id="' . $type . $associatedCategoryID . 'DeleteCurrentNotes" value=""></input>
                             ' .
                             $result .
                        '</div>';
            }
        }
    } catch (Exception $ex) {
        // Assign the output string as to what happened
        return $result;
    }

    // Return the created HTML
    return $result;
}
    
function updateOldChildNotes($db, $userRow, $type, $parent){
    // Determine if there are current notes to look at
    if (isset($_POST[$type . $parent . 'CurrentNotesArray']) and $_POST[$type . $parent . 'CurrentNotesArray']!=0){
        // Remove the last delimiter
        $currentNoteNumbersAsString = substr($_POST[$type . $parent . 'CurrentNotesArray'], 0, -1);

        // Get the amount of current notes as a variable
        $notesNums=explode('|', $currentNoteNumbersAsString);

        // Loop through and get all new note elements
        foreach ($notesNums as $loopNumber){
            // Get the value of the not removal flag
            $removeNote = (isset($_POST[$type . $parent . 'RemoveNote'.$loopNumber])?1:0);
            
            // Determine if we are removing this note
            if ($removeNote){
                // Let's create a query to delete the note
                $sql='DELETE FROM notes WHERE NoteID=' . $loopNumber . ';';
            }
            else {
                $noteOrder=htmlspecialchars($_POST[$type . $parent . 'NoteOrder' . $loopNumber], ENT_QUOTES, 'UTF-8');
                $noteDate=htmlspecialchars($_POST[$type . $parent . 'NoteDate' . $loopNumber], ENT_QUOTES, 'UTF-8');
                $noteTitle=htmlspecialchars($_POST[$type . $parent . 'NoteTitle' . $loopNumber], ENT_QUOTES, 'UTF-8');
                $note=htmlspecialchars($_POST[$type . $parent . 'Note' . $loopNumber], ENT_QUOTES, 'UTF-8');
                $fname    = null; 
                $fileSize = null; 
                $fileType = null; 
                $content  = null;
                $removeAttachment = (isset($_POST[$type . $parent . 'RemoveAttachment' . $loopNumber])?1:0);
                $fileSQL = '';

                // determine if they are asking to remove the image
                if($removeAttachment) {
                    // Set the values for removal of the file for now
                    $fileSQL = ',FileName=null ,ByteSize=null ,FileType=null,Datum=null';
                }
                elseif (is_uploaded_file($_FILES[$type . $parent . 'AttachmentElement' . $loopNumber]['tmp_name'])) {
                    // Get the properties of the file to upload
                    $fname    = $db->getDBConnection()->real_escape_string($_FILES[$type . $parent . 'AttachmentElement' . $loopNumber]['name']); 
                    $tmpName  = $db->getDBConnection()->real_escape_string($_FILES[$type . $parent . 'AttachmentElement' . $loopNumber]['tmp_name']);
                    $fileSize = intval($_FILES[$type . $parent . 'AttachmentElement' . $loopNumber]['size']);
                    $fileType = $db->getDBConnection()->real_escape_string($_FILES[$type . $parent . 'AttachmentElement' . $loopNumber]['type']);

                    // Determine if the file size is such that the database han handle storing it. The database can handle 4GB (4,294,967,296 Bytes)
                    if ($fileSize < 4294967296){
                        //process the file
                        $content = $db->getDBConnection()->real_escape_string(file_get_contents($tmpName));

                        // Determine if we got any data
                        if ($content!=null) {
                            // Determine if the magic quotes option is on
                            if(!get_magic_quotes_gpc()){
                                // Add slashes to the name
                                $fname = addslashes($fname);
                            }

                            // Create the file sqlpart of this
                            if ($fname!=null) {$fileSQL = $fileSQL . ',FileName="' . $fname . '"';}
                            if ($fileSize!=null) {$fileSQL = $fileSQL . ',ByteSize="' . $fileSize . '"';}
                            if ($fileType!=null) {$fileSQL = $fileSQL . ',FileType="' . $fileType . '"';}
                            if ($content!=null) {$fileSQL = $fileSQL . ',Datum="' . $content . '"';}
                        }
                    }
                    else {
                        // Let the user know the file was NOT uploaded
                        echo("The file ('" . $fname . "') will not be uploaded, because it is too large. File must be under 4GB. Old file (if any) will remain.");
                    }
                }   

                // Let's create the update query off of what we have
                $sql='UPDATE notes SET ';
                if ($noteOrder!=null) {$sql = $sql . 'NoteOrder=' . $noteOrder;}
                if ($noteTitle!=null) {$sql = $sql . ',Title="' . $noteTitle . '"';}
                if ($note!=null) {$sql = $sql . ',Note="' . $note . '"';}
                if ($noteDate!=null) {$sql = $sql . ', Date="' . $noteDate . '"';}
                if ($fileSQL!="") {$sql = $sql . $fileSQL;}
                $sql=$sql .' WHERE NoteID=' . $loopNumber . ';';
            }

            // Attempt to run the query and get the response
            if ($db->queryDB($sql, $userRow, "child_presentation Form occurance 2.")){
            }
        }
    }
}

function addNewChildNotesToDB($db, $userRow, $category, $parentID, $parentNotSavedExtention="", $updatedParentID=-1){
    // Determine if there are new notes    $_POST['new' . $category . $parentID . 'NoteNumbers']
    if (isset($_POST['new' . $category . $parentID . $parentNotSavedExtention . 'NoteNumbers']) && 
        $_POST['new' . $category . $parentID . $parentNotSavedExtention . 'NoteNumbers']!=0){
        // Get the amount of new notes as a variable
        $noteNumStrings=$_POST['new' . $category . $parentID . $parentNotSavedExtention . 'NoteNumbers'];
        $noteNums=explode('|', $noteNumStrings);

        // Loop through and get all new note elements
        foreach ($noteNums as $loopNumber){
            // Get the posted items that I am worried about
            $noteOrder=htmlspecialchars($_POST['new' . $category . $parentID . $parentNotSavedExtention . 'NoteOrder'.$loopNumber], ENT_QUOTES, 'UTF-8');
            $noteDate=htmlspecialchars($_POST['new' . $category . $parentID . $parentNotSavedExtention . 'NoteDate'.$loopNumber], ENT_QUOTES, 'UTF-8');
            $noteTitle=htmlspecialchars($_POST['new' . $category . $parentID . $parentNotSavedExtention . 'NoteTitle'.$loopNumber], ENT_QUOTES, 'UTF-8');
            $note=htmlspecialchars($_POST['new' . $category . $parentID . $parentNotSavedExtention . 'Note'.$loopNumber], ENT_QUOTES, 'UTF-8');
            $fname    = null; 
            $fileSize = null; 
            $fileType = null; 
            $content  = null;
            
            // determine if the image has been uploaded
            if(is_uploaded_file($_FILES['new' . $category . $parentID . $parentNotSavedExtention . 'AttachmentElement' . $loopNumber]['tmp_name'])) {
                // Get the properties of the file to upload
                $fname    = $db->getDBConnection()->real_escape_string($_FILES['new' . $category . $parentID . $parentNotSavedExtention . 'AttachmentElement' . $loopNumber]['name']); 
                $tmpName  = $db->getDBConnection()->real_escape_string($_FILES['new' . $category . $parentID . $parentNotSavedExtention . 'AttachmentElement' . $loopNumber]['tmp_name']);
                $fileSize = intval($_FILES['new' . $category . $parentID . $parentNotSavedExtention . 'AttachmentElement' . $loopNumber]['size']);
                $fileType = $db->getDBConnection()->real_escape_string($_FILES['new' . $category . $parentID . $parentNotSavedExtention . 'AttachmentElement' . $loopNumber]['type']);

                // Determine if the file size is such that the database han handle storing it. The database can handle 4GB (4,294,967,296 Bytes)
                if ($fileSize < 4294967296){
                    //process the file
                    $content = $db->getDBConnection()->real_escape_string(file_get_contents($tmpName));

                    // Determine if we got any data
                    if ($content!=null) {
                        // Determine if the magic quotes option is on
                        if(!get_magic_quotes_gpc()){
                            // Add slashes to the name
                            $fname = addslashes($fname);
                        }
                    }
                }
                else {
                    // reset all values to nothing
                    $fname    = null; 
                    $fileSize = null; 
                    $fileType = null; 
                    $content  = null;
                    
                    // Let the user know the file was NOT uploaded
                    echo("The file ('" . $fname . "') will not be uploaded, because it is too large. File must be under 4GB.");
                }
            }   
                                
            // Determine if the parent is new as well
            $realParentIDToSaveUnder=$parentID;
            if ($parentNotSavedExtention!=""){ 
                // set the update ID as the one to use to update the parent
                $realParentIDToSaveUnder=$updatedParentID;
            }
                                
            // Let's create the insert query off of what we have
            $sql='INSERT INTO notes (';
            $sql = $sql . 'AssociatedCategoryID';
            if ($noteOrder!=null) {$sql = $sql . ', NoteOrder';}
            if ($noteDate!=null) {$sql = $sql . ', Date';}
            if ($noteTitle!=null) {$sql = $sql . ', Title';}
            if ($note!=null) {$sql = $sql . ',Note';}
            if ($fname!=null) {$sql = $sql . ',FileName';}
            if ($fileSize!=null) {$sql = $sql . ',ByteSize';}
            if ($fileType!=null) {$sql = $sql . ',FileType';}
            if ($content!=null) {$sql = $sql . ',Datum';}
            if ($userRow["UserID"]!=null) {$sql = $sql . ', EnteredByID';}
            if ($category!=null) {$sql = $sql . ', Category';}
            $sql=$sql .') VALUES (';
            $sql = $sql . $realParentIDToSaveUnder . ' ';
            if ($noteOrder!=null) {$sql = $sql . ', "' . $noteOrder . '"';}
            if ($noteDate!=null) {$sql = $sql . ', "' . $noteDate . '"';}
            if ($noteTitle!=null) {$sql = $sql . ', "' . $noteTitle . '"';}
            if ($note!=null) {$sql = $sql . ', "' . $note . '"';}
            if ($fname!=null) {$sql = $sql . ', "' . $fname . '"';}
            if ($fileSize!=null) {$sql = $sql . ', "' . $fileSize . '"';}
            if ($fileType!=null) {$sql = $sql . ', "' . $fileType . '"';}
            if ($content!=null) {$sql = $sql . ', "' . $content . '"';}
            if ($userRow["UserID"]!=null) {$sql = $sql . ', ' . $userRow["UserID"] . ' ';}
            if ($category!=null) {$sql = $sql . ', "' . $category . '" ';}
            $sql=$sql .');';
            
            // Attempt to run the query and get the response
            if ($db->queryDB($sql, $userRow, "child_presentation Form occurance 3.")){
            }
        }
    }
}

function retrieveChildNotesDiv($db, $userRow, $inAssociatedCategoryID, $type, $inNameLabelSingular="", &$validationHTML="", $allowSUCompanyDeletion=true){
    // Get any current notes
    $results=retrieveCurrentChildNotes($db, $userRow, $inAssociatedCategoryID, $type, $inNameLabelSingular, $validationHTML, $allowSUCompanyDeletion);
    
    // Set the variavle defines as parent to the passed in category ID
    $parentID = $inAssociatedCategoryID;
    
    // Determine if we added some notes
    $noteColorHtml = '';
    if ($results != '') {
        // Change the color of the Notes Title font
        $noteColorHtml = 'style="color:LimeGreen;"';
    }
    
    // Set the name to be what was passed in and pluralized.  Not accounting for all varieties of pluralization.
    $pluralizedNameLabel = $inNameLabelSingular . 's';

    // Init all of the settings to the appropriate values
    $noteDiv = '
                    <input name="hide' . $type . $parentID . 'Notes" id="hide' . $type . $parentID . 'Notes" class="notinput" type="checkbox" onclick="javascript:div_toggleVisibilityOnCheckbox(\'hide' . $type . $parentID . 'Notes\',\'' . $type . $parentID . 'Notes\', \'NORMAL\');"></input>
                    <strong><label for="hide' . $type . $parentID . 'Notes" ' . $noteColorHtml . '>' . $pluralizedNameLabel . '</label></strong>
                    <div id="' . $type . $parentID . 'Notes" style="display: none; text-align:center; font-weight: bold; font-size: 12px;">
                        <label style="font-size: 20px;"><strong>New ' . $pluralizedNameLabel . ': </strong></label>
                        <p align="right" style="">
                            <input type="hidden" id="new' . $type . $parentID . 'NoteNumbers" name="new' . $type . $parentID . 'NoteNumbers" value="0"></input>
                            <button type="button" onClick="addNewChild(\'' . $type . '\', ' . $inAssociatedCategoryID . '   );" align="right" title="This will add a new ' . $inNameLabelSingular . '.">Add New</button>
                        </p>
                        <div id="new' . $type . $parentID . 'Notes" style="width: 90%;">
                        </div>
                        ' .
                        $results .
                    '</div>
                ';
    
    // Return the result
    return $noteDiv;
}
?>   
