<%@ Page Title="" Language="vb" AutoEventWireup="false" MasterPageFile="~/Client/ClientMaster.master" CodeBehind="EditDriver.aspx.vb" Inherits="Web.EditDriver" %>
<%@ MasterType VirtualPath="ClientMaster.Master" %>
<%@ Register Src="~/_include/controls/StatePicker.ascx" TagPrefix="ctrl" TagName="StatePicker" %>
<%@ Register Src="~/_include/controls/SocialBox.ascx" TagPrefix="ctrl" TagName="SocialBox" %>
<%@ Register Src="~/_include/controls/YesNoPicker.ascx" TagPrefix="ctrl" TagName="YesNoPicker" %>
<asp:Content ID="Content1" ContentPlaceHolderID="phContent" runat="server">

    <div class="container">
        <h1>Driver Profile</h1>
        
        <ul id="tabList" class="nav nav-tabs">
            <li class="nav-item">
                <a class="nav-link active" href="#general" data-toggle="tab">General Information</a>
            </li>
            <li class="nav-item">
                <a class="nav-link" href="#contact" data-toggle="tab">Contact Information</a>
            </li>
            <!--<li class="nav-item">
                <a class="nav-link" href="#documents" data-toggle="tab">Documents</a>
            </li>-->
            <li class="nav-item">
                <a class="nav-link" href="#training" data-toggle="tab">Training</a>
            </li>
            <li class="nav-item">
                <a class="nav-link" href="#notes" data-toggle="tab">Notes</a>
            </li>
            <li class="nav-item">
                <a class="nav-link" href="#docs" data-toggle="tab">Documents</a>
            </li>
        </ul>

        <div class="tab-content bg-white border border-top-0 p-3 mb-3">

            <!-- General information tab -->
            <div id="general" class="tab-pane show active">
                <div class="row">
                    <div class="form-group col-4">
                        <asp:Label runat="server" AssociatedControlID="txtFirstName" Text="First Name" />
                        <asp:TextBox ID="txtFirstName" runat="server" MaxLength="50" ValidationGroup="AccountInfo" CssClass="form-control" />
                        <asp:RequiredFieldValidator runat="server" ValidationGroup="AccountInfo" ControlToValidate="txtFirstName"
                            Text="required" Display="Dynamic" CssClass="text-danger" />
                    </div>
                    <div class="form-group col-3">
                        <asp:Label runat="server" AssociatedControlID="txtMiddleName" Text="Middle Name" />
                        <asp:TextBox ID="txtMiddleName" runat="server" MaxLength="50" ValidationGroup="AccountInfo" CssClass="form-control" />
                    </div>
                    <div class="form-group col-4">
                        <asp:Label runat="server" AssociatedControlID="txtLastName" Text="Last Name" />
                        <asp:TextBox ID="txtLastName" runat="server" MaxLength="50" ValidationGroup="AccountInfo" CssClass="form-control" />
                        <asp:RequiredFieldValidator runat="server" ValidationGroup="AccountInfo" ControlToValidate="txtLastName"
                            Text="required" Display="Dynamic" CssClass="text-danger" />
                    </div>
                    <div class="form-group col-1">
                        <asp:Label runat="server" AssociatedControlID="txtNameSuffix" Text="Suffix" />
                        <asp:TextBox ID="txtNameSuffix" runat="server" MaxLength="50" ValidationGroup="AccountInfo" CssClass="form-control" />
                    </div>
                </div>
                <div class="form-group w-25">
                    <asp:Label runat="server" AssociatedControlID="txtSocial" Text="SSN" />
                    <ctrl:SocialBox ID="txtSocial" runat="server" />
                </div>
                <div class="form-group w-25">
                    <asp:Label runat="server" AssociatedControlID="dtBirth" Text="Date of Birth" />
                    <asp:TextBox ID="dtBirth" runat="server" MaxLength="50" TextMode="Date" CssClass="form-control" />
                </div>
                <div class="form-group w-25">
                    <asp:Label runat="server" AssociatedControlID="dtHireDate" Text="Hire Date" />
                    <asp:TextBox ID="dtHireDate" runat="server" MaxLength="50" TextMode="Date" CssClass="form-control"/>
                    <asp:RequiredFieldValidator runat="server" ControlToValidate="dtHireDate"
                        Text="required" Display="Dynamic" CssClass="text-danger" />
                </div>
                <div class="form-group w-25">
                    <asp:CheckBox ID="chkTerminated" runat="server" CssClass="mr-1" />
                    <asp:Label runat="server" AssociatedControlID="dtTermDate" Text="Terminated" />
                    <asp:TextBox ID="dtTermDate" runat="server" MaxLength="50" TextMode="Date" CssClass="form-control"/>
                    <asp:TextBox ID="txtTermReason" runat="server" CssClass="form-control" Text="" placeholder="Terminated Reason" />
                </div>
                <script>
                    $(document).ready(function () {
                        var chkTerminated = $('#<%= chkTerminated.ClientID %>');
                        var txtTermReason = $('#<%= txtTermReason.ClientID %>');
                        var dtTermDate = $('#<%= dtTermDate.ClientID %>');
                        var fixup = function () {
                            if (chkTerminated.prop('checked') == true) {
                                txtTermReason.prop('disabled', false);
                                dtTermDate.prop('disabled', false);
                            } else {
                                txtTermReason.prop('disabled', true);
                                dtTermDate.prop('disabled', true);
                            }
                        };
                        fixup();
                        chkTerminated.change(fixup);
                    });
                </script>
<asp:PlaceHolder ID="phTWIC" runat="server" Visible="false">
                <div class="form-group w-25">
                    <asp:CheckBox ID="chkTWIC" runat="server" CssClass="mr-1" />
                    <asp:Label runat="server" AssociatedControlID="chkTWIC" Text="TWIC Expiration" CssClass="mr-1" />
                    <asp:TextBox ID="dtTWIC" runat="server" MaxLength="50" TextMode="Date" CssClass="form-control" />
                </div>
</asp:PlaceHolder>

<asp:PlaceHolder ID="phOther" runat="server" Visible="false">
                <div class="form-group">
                    <asp:CheckBox ID="chkOtherDate" runat="server" CssClass="mr-1" />
                    <asp:Label runat="server" AssociatedControlID="chkOtherDate" Text="Other Date Enabled" CssClass="mr-1" />
                    <asp:TextBox ID="dtOtherDate" runat="server" MaxLength="50" TextMode="Date" CssClass="form-control w-25" />
                    <asp:TextBox ID="txtOtherDate" runat="server" CssClass="form-control" Text="Description" placeholder="Other date description" />
                </div>
                <script>
                    $(document).ready(function () {
                        var chkOtherDate = $('#<%= chkOtherDate.ClientID %>');
                        var txtOtherDate = $('#<%= txtOtherDate.ClientID %>');
                        var dtOtherDate = $('#<%= dtOtherDate.ClientID %>');
                        var fixup = function () {
                            if (chkOtherDate.prop('checked') == true) {
                                txtOtherDate.prop('disabled', false);
                                dtOtherDate.prop('disabled', false);
                            } else {
                                txtOtherDate.prop('disabled', true);
                                dtOtherDate.prop('disabled', true);
                            }
                        };
                        fixup();
                        chkOtherDate.change(fixup);
                    });
                </script>
                <div class="form-group w-25">
                    <asp:Label runat="server" AssociatedControlID="txtLocation" Text="Location" />
                    <asp:TextBox ID="txtLocation" runat="server" MaxLength="200" CssClass="form-control" />
                </div>
</asp:PlaceHolder>

                <section>
                    <h2>Driver's License</h2>
                    <div class="form-group w-25">
                        <asp:Label runat="server" AssociatedControlID="txtLicenseNumber" Text="Number" />
                        <asp:TextBox ID="txtLicenseNumber" runat="server" MaxLength="50" CssClass="form-control" />
                    </div>
                    <div class="form-group w-25">
                        <asp:Label runat="server" AssociatedControlID="ddlLicenseState" Text="State" />
                        <ctrl:StatePicker ID="ddlLicenseState" runat="server" />
                    </div>
                    <div class="form-group w-25">
                        <asp:Label runat="server" AssociatedControlID="txtLicenseClass" Text="Class" />
                        <asp:TextBox ID="txtLicenseClass" runat="server" MaxLength="50" CssClass="form-control" />
                    </div>
                    <div class="form-group">
                        <asp:Label runat="server" AssociatedControlID="ynCDL" Text="Commercial Driver's License (CDL)?" />
                        <div><input ID="ynCDL" runat="server" type="checkbox" class="form-control" data-toggle="toggle" data-on="yes" data-off="no" /></div>
                    </div>
                    <div class="form-group w-25">
                        <asp:Label runat="server" AssociatedControlID="dtLicenseExpires" Text="Expiration Date" />
                        <asp:TextBox ID="dtLicenseExpires" runat="server" MaxLength="50" TextMode="Date" CssClass="form-control" />
                    </div>
<asp:PlaceHolder ID="phDrugPool" runat="server">
                    <div class="form-group">
                        <asp:Label runat="server" AssociatedControlID="ynDrugPool" Text="Will this driver be operating a vehicle requiring a Commercial Drivers License (CDL) or would you like to enroll this driver in your default controlled substances and alcohol testing (CSAT) program?" />
                        <div><input ID="ynDrugPool" runat="server" type="checkbox" class="form-control" data-toggle="toggle" data-on="yes" data-off="no" /></div>
                    </div>
</asp:PlaceHolder>
                    <div class="form-group">
                        <asp:Label runat="server" AssociatedControlID="ynLogs" Text="Does this driver travel more than 100 air miles (150 air miles for non-CDL drivers) from their work reporting location?" />
                        <div><input ID="ynLogs" runat="server" type="checkbox" class="form-control" data-toggle="toggle" data-on="yes" data-off="no" /></div>
                    </div>
                    <div class="form-group">
                        <asp:Label runat="server" AssociatedControlID="ynInter" Text="Does this driver operate commercial motor vehicles across state lines or in interstate commerce?" />
                        <div><input ID="ynInter" runat="server" type="checkbox" class="form-control" data-toggle="toggle" data-on="yes" data-off="no" /></div>
                    </div>
                </section>

                <section>
                    <h2>Driver Qualification File (DQF) Documents</h2>
                    <div class="form-group">
                        <asp:Label runat="server" AssociatedControlID="txtMCExpires" Text="Medical Certificate (or Medical Card) Expiration Date" />
                        <asp:TextBox ID="txtMCExpires" runat="server" TextMode="Date" CssClass="form-control w-25" />
                    </div>
                    <div class="form-group">
                        <asp:Label runat="server" AssociatedControlID="txtMCMVRExpires" Text="Medical Certificate SDLA/MVR Verification Expiration Date" />
                        <asp:TextBox ID="txtMCMVRExpires" runat="server" TextMode="Date" CssClass="form-control w-25" />
                    </div>
                    <div class="form-group">
                        <asp:Label runat="server" AssociatedControlID="txtAnnualMVRExpire" Text="Annual Motor Vehicle Report (MVR) Expiration Date" />
                        <asp:TextBox ID="txtAnnualMVRExpire" runat="server" TextMode="Date" CssClass="form-control w-25" />
                    </div>
                    <div class="form-group">
                        <asp:Label runat="server" AssociatedControlID="txtAnnualCOVExpire" Text="Annual Certificate of Violations (COV) Form Expiration Date" />
                        <asp:TextBox ID="txtAnnualCOVExpire" runat="server" TextMode="Date" CssClass="form-control w-25" />
                    </div>
                    <div class="form-group">
                        <asp:Label runat="server" AssociatedControlID="txtAnnualDachExpire" Text="Annual Drug and Alcohol Clearinghouse (DACH) Expiration Date" />
                        <asp:TextBox ID="txtAnnualDachExpire" runat="server" TextMode="Date" CssClass="form-control w-25" />
                    </div>
                </section>
            </div>

            <!-- Contact information tab -->
            <div id="contact" class="tab-pane">
                <div class="form-group">
                    <asp:Label runat="server" AssociatedControlID="txtAddress1" Text="Address 1" />
                    <asp:TextBox ID="txtAddress1" runat="server" CssClass="form-control" MaxLength="100" />
                </div>
                <div class="form-group">
                    <asp:Label runat="server" AssociatedControlID="txtAddress2" Text="Address 2" />
                    <asp:TextBox ID="txtAddress2" runat="server" CssClass="form-control" MaxLength="50" />
                </div>
                <div class="row">
                    <div class="form-group col">
                        <asp:Label runat="server" AssociatedControlID="txtCity" Text="City" />
                        <asp:TextBox ID="txtCity" runat="server" CssClass="form-control" MaxLength="50" />
                    </div>
                    <div class="form-group col">
                        <asp:Label runat="server" AssociatedControlID="ddlState" Text="State" />
                        <ctrl:StatePicker ID="ddlState" runat="server" />
                    </div>
                    <div class="form-group col">
                        <asp:Label runat="server" AssociatedControlID="txtZip" Text="Zip" />
                        <asp:TextBox ID="txtZip" runat="server" CssClass="form-control" MaxLength="50" />
                    </div>
                </div>
                <div class="form-group w-25">
                    <asp:Label runat="server" AssociatedControlID="txtPhone1" Text="Phone 1" />
                    <asp:TextBox ID="txtPhone1" runat="server" CssClass="form-control" MaxLength="50" />
                </div>
                <div class="form-group w-25">
                    <asp:Label runat="server" AssociatedControlID="txtPhone2" Text="Phone 2" />
                    <asp:TextBox ID="txtPhone2" runat="server" CssClass="form-control" MaxLength="50" />
                </div>
                <div class="form-group w-25">
                    <asp:Label runat="server" AssociatedControlID="txtPhone3" Text="Phone 3" />
                    <asp:TextBox ID="txtPhone3" runat="server" CssClass="form-control" MaxLength="50" />
                </div>
                <div class="form-group">
                    <asp:Label runat="server" AssociatedControlID="txtEmail" Text="Email" />
                    <asp:TextBox ID="txtEmail" runat="server" CssClass="form-control" MaxLength="100" />
                </div>
            </div>

            <!-- Documents tab -->
            <!--<div id="documents" class="tab-pane">
            </div>-->

            <!-- Training tab -->
            <div id="training" class="tab-pane">
                <div class="table-responsive">
                    <asp:GridView ID="gvTraining" runat="server" DataSourceID="dsTraining" AutoGenerateColumns="false" AllowSorting="true"
                        CssClass="table clickable-rows table-hover floating-hscroll" CellSpacing="-1" GridLines="None" data-fixed-columns="true" data-fixed-number="2">
                        <HeaderStyle CssClass="thead-light" />
                        <Columns>
                            <asp:BoundField HeaderText="Topic" SortExpression="TopicName" DataField="TopicName" />
                            <asp:BoundField HeaderText="Specific" SortExpression="SpecificTopic" DataField="SpecificTopic" />
                            <asp:BoundField HeaderText="Training Date" SortExpression="TrainingDate" DataField="TrainingDate" DataFormatString="{0:d}" />
                            <asp:BoundField HeaderText="Training Expires" SortExpression="ExpireDate" DataField="ExpireDate" DataFormatString="{0:d}" />
                            <asp:BoundField HeaderText="Notes" SortExpression="Notes" DataField="Notes" />
                            <asp:TemplateField HeaderText="">
                                <ItemTemplate>
                                    <div class="text-right">
                                        <a href="RemoveTraining.aspx?id=<%# Eval("id") %>&cid=<%# Eval("ContractID") %>" class="btn btn-outline-danger">
                                            <i class="fa fa-trash-alt fa-fw" title="delete"></i>
                                        </a>
                                    </div>
                                </ItemTemplate>
                            </asp:TemplateField>
                        </Columns>
                        <EmptyDataTemplate>
                            <p>There are no training entries.</p>
                        </EmptyDataTemplate>
                    </asp:GridView>
                    <asp:SqlDataSource ID="dsTraining" runat="server"
                        SelectCommand ="
                            SELECT Training.ID, Training.ContractID, Training.TrainingDate, Training.ExpireDate, Training.Notes, Training.SpecificTopic, Topic.Name TopicName
                            FROM Training LEFT JOIN TrainingTopic Topic ON Topic.ID=Training.TopicID
                            WHERE Training.DriverID=@driverID
                            ORDER BY Topic.Name, Training.TrainingDate, Training.ID">
                        <SelectParameters>
                            <asp:Parameter Name="driverId" />
                        </SelectParameters>
                    </asp:SqlDataSource>
                </div>
            </div>

            <!-- Notes tab -->
            <div id="notes" class="tab-pane">
                <div class="table-responsive">
                    <asp:GridView ID="gvNotes" runat="server" DataSourceID="dsNotes" AutoGenerateColumns="false" AllowSorting="true"
                        CssClass="table clickable-rows table-hover floating-hscroll" CellSpacing="-1" GridLines="None" data-fixed-columns="true" data-fixed-number="2">
                        <HeaderStyle CssClass="thead-light" />
                        <Columns>
                            <asp:BoundField HeaderText="Note" SortExpression="Note" DataField="Note" />
                        </Columns>
                        <EmptyDataTemplate>
                            <p>There are no note entries.</p>
                        </EmptyDataTemplate>
                    </asp:GridView>
                    <asp:SqlDataSource ID="dsNotes" runat="server"
                        SelectCommand ="
                            SELECT Note.ID, Note.Note
                            FROM DriverNote Note
                            WHERE Note.DriverID=@driverId
                            ORDER BY Note.EnteredDate DESC">
                        <SelectParameters>
                            <asp:Parameter Name="driverId" />
                        </SelectParameters>
                    </asp:SqlDataSource>
                </div>
            </div>

            <!-- Documents tab -->
            <div id="docs" class="tab-pane">
                <div class="table-responsive">
                    <asp:GridView ID="gvDocs" runat="server" DataSourceID="dsDocs" AutoGenerateColumns="false" AllowSorting="true"
                        CssClass="table clickable-rows table-hover floating-hscroll" CellSpacing="-1" GridLines="None" data-fixed-columns="true" data-fixed-number="2">
                        <HeaderStyle CssClass="thead-light" />
                        <Columns>
                            <asp:BoundField HeaderText="Document Type" SortExpression="DocSubCategory" DataField="DocSubCategory" />
                            <asp:BoundField HeaderText="File name" SortExpression="DocName" DataField="DocName" />
                            <asp:BoundField HeaderText="Date" SortExpression="EnteredDate" DataField="EnteredDate" DataFormatString="{0:d}" />
                            <asp:TemplateField HeaderText="">
                                <ItemTemplate>
                                      <asp:HyperLink ID="lnkUpdate" NavigateUrl='<%#String.Format("DocumentEdit.aspx?cid={0}&docid={1}&ctx={2}&id={3}", Eval("ContractID"), Eval("ID"), Eval("Ctx"), Eval("ItemID"))%>'   runat="server" Text='<%#Eval("EditText") %>' />
                                </ItemTemplate>
                            </asp:TemplateField>
                            <asp:HyperLinkField DataNavigateUrlFields="Context,ID" DataNavigateUrlFormatString="/_assets/Document.aspx?context={0}&id={1}" Target="_blank" Text="view" />
                        </Columns>
                        <EmptyDataTemplate>
                            <p>There are no note entries.</p>
                        </EmptyDataTemplate>
                    </asp:GridView>
                    <asp:SqlDataSource ID="dsDocs" runat="server"
                        SelectCommand ="
                            SELECT DocumentsNew.ContractID,ISNULL(DocumentsNew.ItemID,0) AS ItemID,'DriverEdit' as Ctx,DocumentsNew.ID,DocumentsNew.DocName,DocumentsNew.EnteredDate,ISNULL(DocumentsSubCategory.Name,'') AS DocSubCategory,DocumentsNew.UploadNotes,0 AS OrderByField,'DocumentNew' AS Context,'Edit' AS EditText
                        
                            FROM DocumentsNew LEFT JOIN DocumentsSubCategory ON DocumentsNew.SubCategoryID=DocumentsSubCategory.Id
                            WHERE DocumentsNew.ItemID=@ItemId AND DocumentsNew.CategoryID=@CatID AND (ISNULL(DocumentsNew.Deleted,0) = 0) 
                            UNION ALL
                            SELECT ContractID,ID AS Itemid,'DriverEdit' AS Ctx,WebAppId AS ID, 'All application documents' DocName, EnteredDate, 'Web Application' AS DocSubCategory,'' AS UploadNotes,0 AS OrderByField,'FullApplication' AS Context,'' AS EditText FROM Driver WHERE ID=@ItemID AND ISNULL(webAppID,0)>0
                            UNION ALL
                            Select ContractID,Driver.ID AS ItemID,'DriverEdit' AS CTX,web_DriverApplicationPDF.ID AS ID,pageTitle AS DOcName,Driver.EnteredDate,'Web Application' AS DocSubCategory,'' AS UploadNotes,web_DriverApplicationPDF.ID AS OrderByField,'Application' AS Context,'' AS EditText
                            FROM Driver LEFT JOIN web_DriverApplicationPDF ON Driver.WebAppId=web_DriverApplicationPdf.appId
                            WHERE Driver.ID=@ItemID And Not web_DriverApplicationPdf.ID Is NULL
                            ORDER BY OrderByField,DocSubCategory,DocName,ID">
                        <SelectParameters>
                            <asp:Parameter Name="CatID" />
                            <asp:Parameter Name="ItemId" />

                        </SelectParameters>
                    </asp:SqlDataSource>
                </div>
            </div>

        </div>

        <div class="row">
            <div class="col">
                <asp:Button ID="btnCancel" runat="server" CssClass="btn btn-secondary" Text="Cancel" CausesValidation="false" />
            </div>
            <div class="col text-right">
                <asp:Button ID="btnDownloadAll" runat="server" CssClass="btn btn-primary" Text="Download All" CausesValidation="false" Width="150px" />
                <asp:Button ID="btnUploadDoc" runat="server" CssClass="btn btn-primary" Text="Upload Document" CausesValidation="false" Width="150px" />
                <asp:Button ID="btnSave" runat="server" CssClass="btn btn-primary" Text="Save" Width="150px" />
            </div>
        </div>

    </div>

</asp:Content>