<?php
    function getVendor($db, $userRow, $vendorNumber){
        // Init all of the settings to the appropriate values
        $vendorName = '';
        $vendorRowColor = 'e2ddcf';
        $vendorEMail = '';
        $vendorInformation = '';
        $modifyType = 'add';
        
        // Determine if this is an update or not
        $vendorAssocTask = null;
        if ($vendorNumber){
            // Create the query to get the the vendor
            $sql = 'SELECT * FROM vendors WHERE VendorID = ' . $vendorNumber . ';';

            // Attempt to get the vendors
            $vendorRow = $db->queryDB($sql, $userRow, "vendor_presentation Form occurance 1");

            // Attempt to get the vendor row
            $vendorAssocTask = $vendorRow->fetch_assoc();

            // Set the things we can
            $vendorName = $vendorAssocTask["VendorName"];
            $vendorRowColor = $vendorAssocTask["VendorRowColor"];
            $vendorEMail = $vendorAssocTask["VendorEMail"];
            $vendorInformation = $vendorAssocTask["VendorInformation"];

            $modifyType = 'update';
        }
        
        return '
            <form action="' . $modifyType . 'Vendor.php?updateVendorID=' . $vendorNumber . '"  method="post" name="' . $modifyType . 'Vendor" enctype="multipart/form-data">  
                <table width=100%>
                    <tr width=100%>
                        <td colspan=1 height="41" align="right" valign="middle">
                            <strong>Vendor Name:</strong>&nbsp;&nbsp;
                        </td>
                        <td colspan=3 height="41" align="left" valign="middle">
                            <input name="vendorName" id="vendorName" type="text" maxlength="150" class="intext" style="width: 100%; height: 20px; overflow: auto; resize:none" value="' . $vendorName . '">
                        </td>
                    </tr>
                    <tr width=100%>
                        <td colspan=1 height="41" align="right" valign="middle">
                            <strong>Vendor E-Mail:</strong>&nbsp;&nbsp;
                        </td>
                        <td colspan=3 height="41" align="left" valign="middle">
                            <input name="vendorEMail" id="vendorEMail" type="text" maxlength="150" class="intext" style="width: 100%; height: 20px; overflow: auto; resize:none" value="' . $vendorEMail . '">
                        </td>
                    </tr>
                    <tr width=100%>
                        <td colspan=1 align="right" valign="middle">
                            <strong>Vendor Information:</strong>&nbsp;&nbsp;
                        </td>
                        <td colspan=3 align="left" valign="middle">
                            <textarea name="vendorInformation" id="vendorInformation" maxlength="1000" class="intext" style="width: 100%; height: 80px; overflow: auto; resize:none" >' .
                                $vendorInformation .
                            '</textarea>
                        </td>
                    </tr>
                    <tr width=100%>
                        <td colspan=1 height="41" align="right" valign="middle">
                            <strong>Vendor Row Color:</strong>&nbsp;&nbsp;
                        </td>
                        <td colspan=3 height="41" align="left" valign="middle">
                            <script type="text/javascript">        
                              $(document).ready(
                                function()
                                {
                                  $("#vendorRowColor").jPicker({window:{position:{x:"center",y:"center"},expandable: true,liveUpdate: true}});
                                });
                            </script>
                            <input id="vendorRowColor" name="vendorRowColor" type="text" maxlength="6" value="' . $vendorRowColor . '" style="width: 60px; height: 20px; overflow: auto; resize:none"/>
                        </td>
                    </tr>
                    <tr width=100%>
                        <td colspan=4 width=100%>
                            </table>' .
                            retrieveCurrentAddresses($db, $userRow, $vendorNumber, 'VendorID') .
                            '<strong>New Addresses: </strong>
                            <div id="newAddresses" style="margin: 5 auto; width: 100%; ">
                            </div>
                        </td>
                    </tr>
                </table>
                <p align="right">
                    <input type="hidden" id="formSubmitted" name="formSubmitted" value="TRUE">
                    <input type="hidden" id="newAddressNumbers" name="newAddressNumbers" value="0">
                    <button type="button" onClick="addNewAddress_NicelyFormedRow(\'VENDOR\')" align="right">Add New Address</button>
                    <input id="formSubmit" type="submit" style="cursor: hand; cursor: pointer;" value="' . $modifyType . ' vendor" />
                </p>
            </form>
            <script language="JavaScript">
                // Code for validating the form
                // Visit http://www.javascript-coder.com/html-form/javascript-form-validation.phtml
                // for details
                var frmvalidator = new Validator("' . $modifyType . 'Vendor", "formSubmit");
                frmvalidator.addValidation("vendorName",
                                           "required",
                                           "There must be a value for the vendor name.");
                frmvalidator.addValidation("vendorEMail",
                                           "required",
                                           "There must be a value for the vendor e-mail.");
                frmvalidator.addValidation("vendorEMail",
                                           "email",
                                           "The e-mail must be in the structure of email@server.com.");
            </script>';
    }
?>

