<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="PracownicyAgencyjniSzczegoly.aspx.cs" Inherits="KOLKaP_WEB.KOLKaP.PracownicyAgencyjniSzczegoly" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Pracownik agencyjny</title>
    <link href="../Web.css?2" type="text/css" rel="stylesheet" />
    <link rel="stylesheet" href="../jquery/themes/ui-lightness/jquery-ui-1.9.2.custom.min.css" />
    <script src="../jquery/jquery-1.8.3.min.js" type="text/javascript"></script>
    <script src="../jquery/ui/jquery-ui-1.9.2.custom.min.js" type="text/javascript"></script>
    <script src="../jquery/jquery.blockUI.js" type="text/javascript"></script>
    <script src="../jquery/jquery.corner.js" type="text/javascript"></script>
    <script src="../Skrypty.js" type="text/javascript"></script>
    <script type="text/javascript">
        $(function () {
            $("#btnOdswiez").button({ icons: { primary: 'ui-icon-refresh' } });
            $(".btnOtworzGrid").button({ icons: { primary: 'ui-icon-folder-open' } });
            $("#btnPowrot").button({ icons: { primary: 'ui-icon-arrowreturnthick-1-w' } });
            $("#btnZapisz").button({ icons: { primary: 'ui-icon-disk' } });
            //$("#btnDodaj").button({ icons: { primary: 'ui-icon-plusthick' } });

            $("#divWniosek").corner("10px");
        });
    </script>
    <style type="text/css">
        .auto-style1 {
            height: 13px;
        }
    </style>
</head>
<body class="body"  onload="PokazOpisSchematu();">

        <script type="text/javascript">


        function LoginEmail() {
            var imie = document.getElementById("tbImie").value;
            var nazwisko = document.getElementById("tbNazwisko").value;

            if (nazwisko != '')
                document.getElementById("tbNazwisko").value = PierwszaDuza(nazwisko);
            if (imie != '')
                document.getElementById("tbImie").value = PierwszaDuza(imie);

            //tymczasowo odblokowane do drożenia ldap
            if (nazwisko != '' && imie != '') {
                __doPostBack('tbNazwisko', '');
            }
        }

        function UsunPolskieSpacje(text) {
            text = replace(text, 'Ą', 'A');
            text = replace(text, 'Á', 'A');
            text = replace(text, 'À', 'A');
            text = replace(text, 'Â', 'A');
            text = replace(text, 'Ä', 'A');
            text = replace(text, 'Ã', 'A');
            text = replace(text, 'Å', 'A');
            text = replace(text, 'ą', 'a');
            text = replace(text, 'á', 'a');
            text = replace(text, 'à', 'a');
            text = replace(text, 'â', 'a');
            text = replace(text, 'ä', 'a');
            text = replace(text, 'ã', 'a');
            text = replace(text, 'å', 'a');
            text = replace(text, 'Ć', 'C');
            text = replace(text, 'Ç', 'C');
            text = replace(text, 'ć', 'c');
            text = replace(text, 'ç', 'c');
            text = replace(text, 'Ę', 'E');
            text = replace(text, 'É', 'E');
            text = replace(text, 'Ê', 'E');
            text = replace(text, 'È', 'E');
            text = replace(text, 'Ë', 'E');
            text = replace(text, 'ę', 'e');
            text = replace(text, 'é', 'e');
            text = replace(text, 'ê', 'e');
            text = replace(text, 'è', 'e');
            text = replace(text, 'ë', 'e');
            text = replace(text, 'Í', 'I');
            text = replace(text, 'Î', 'I');
            text = replace(text, 'Ì', 'I');
            text = replace(text, 'Ï', 'I');
            text = replace(text, 'í', 'i');
            text = replace(text, 'î', 'i');
            text = replace(text, 'ì', 'i');
            text = replace(text, 'ï', 'i');
            text = replace(text, 'Ł', 'L');
            text = replace(text, 'ł', 'l');
            text = replace(text, 'Ń', 'N');
            text = replace(text, 'Ñ', 'N');
            text = replace(text, 'ń', 'n');
            text = replace(text, 'ñ', 'n');
            text = replace(text, 'Ó', 'O');
            text = replace(text, 'Ö', 'O');
            text = replace(text, 'Ô', 'O');
            text = replace(text, 'Ø', 'O');
            text = replace(text, 'Õ', 'O');
            text = replace(text, 'ó', 'o');
            text = replace(text, 'ö', 'o');
            text = replace(text, 'ô', 'o');
            text = replace(text, 'ø', 'o');
            text = replace(text, 'õ', 'o');
            text = replace(text, 'Ś', 'S');
            text = replace(text, 'ś', 's');
            text = replace(text, 'ß', 's');
            text = replace(text, 'Ú', 'U');
            text = replace(text, 'Ù', 'U');
            text = replace(text, 'Û', 'U');
            text = replace(text, 'Ü', 'U');
            text = replace(text, 'ú', 'u');
            text = replace(text, 'ù', 'u');
            text = replace(text, 'û', 'u');
            text = replace(text, 'ü', 'u');
            text = replace(text, 'Ý', 'Y');
            text = replace(text, 'ý', 'y');
            text = replace(text, 'ÿ', 'y');
            text = replace(text, 'Ż', 'Z');
            text = replace(text, 'ż', 'z');
            text = replace(text, 'Ź', 'Z');
            text = replace(text, 'ź', 'z');
            text = replace(text, ' ', '')
            return text;
        }

        function replace(string, text, by) {
            // Replaces text with by in string
            var strLength = string.length, txtLength = text.length;
            if ((strLength == 0) || (txtLength == 0)) return string;

            var i = string.indexOf(text);
            if ((!i) && (text != string.substring(0, txtLength))) return string;
            if (i == -1) return string;

            var newstr = string.substring(0, i) + by;

            if (i + txtLength < strLength)
                newstr += replace(string.substring(i + txtLength, strLength), text, by);
            return newstr;
            //return string;
        }

        function PierwszaDuza(text) {
            var pattern = /(\s)/;
            var a = text.split('-');

            for (i = 0 ; i < a.length ; i++) {
                var parts = a[i];

                if (parts.length == 1)
                    parts = parts.substr(0, 1).toUpperCase();
                if (parts.length >= 2)
                    parts = parts.substr(0, 1).toUpperCase() + parts.substr(1, text.length - 1);
                a[i] = parts;
            }

            text = a.join('-'); // join it back together
            return text;
        }

        //function sprawdzNIP(inputVal) {
        //    if (!inputVal.match(/^((\d{3}[- ]\d{3}[- ]\d{2}[- ]\d{2})|(\d{3}[- ]\d{2}[- ]\d{2}[- ]\d{3})|(\d{10}))$/)) {
        //        return false;
        //    }
        //    return true;
        //}

        function isDate(dateStr) {
            var datePat = /^(\d{4})(\/|-)(\d{1,2})(\/|-)(\d{1,2})$/;
            var matchArray = dateStr.match(datePat);

            if (matchArray == null) {
                alert("Właściwy format daty to rrrr-mm-dd.");
                return false;
            }

            year = matchArray[1];
            month = matchArray[3];
            day = matchArray[5];

            if (month < 1 || month > 12) {
                alert("Miesiąc musi być w zakresie 1 - 12.");
                return false;
            }

            if (day < 1 || day > 31) {
                alert("Dzień musi być w zakresie 1 - 31.");
                return false;
            }

            if ((month == 4 || month == 6 || month == 9 || month == 11) && day == 31) {
                alert("Miesiąc " + month + " nie ma 31 dni!")
                return false;
            }

            if (month == 2) {
                var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
                if (day > 29 || (day == 29 && !isleap)) {
                    alert("luty " + year + " nie ma " + day + " dni!");
                    return false;
                }
            }
            return true;
        }

        function DlugoscNip() {
            var nip = document.getElementById("tbNip").value;
            if (nip != '') {
                if ((nip.indexOf("-") > 0 && nip.length != 13) || (nip.indexOf("-") <= 0 && nip.length != 10)) {
                    alert('Nr NIP ma nieprawidłową długość!');
                    return false;
                }
                if (!sprawdzNIP(nip)) {
                    alert('Nr NIP ma nieprawidłowy format (xxx-xxx-xx-xx/xxx-xx-xx-xxx/xxxxxxxxxx)');
                    return false;
                }
            }
        }

        function DlugoscPesel() {
            var pesel = document.getElementById("tbPesel").value;
            if (pesel != '') {
                if (pesel.length != 11) {
                    alert('Nr PESEL ma nieprawidłową długość!');
                    return false;
                }
            }
        }

    </script>
    <form id="form1" runat="server">
        <div id="spanWniosekTitle" style="width:200px;">Pracownik agencyjny</div>
        <div id="divWniosek">
            <table border="0" cellspacing="0" cellpadding="0" width="100%">
                <tr>
                    <td colspan="4" class="auto-style1">
                        <asp:Label ID="lblError" runat="server"></asp:Label></td>
                </tr>
                <tr>
                    <td colspan="4" style="height: 20px" align="right">
                        <asp:LinkButton ID="btnPowrot" runat="server" Text="Powrót" CssClass="aspButton" Width="90px" OnClick="btnPowrot_Click"></asp:LinkButton>
                        <asp:LinkButton ID="btnZapisz" runat="server" Text="Zapisz" CssClass="aspButton" Width="90px" OnClick="btnZapisz_Click"></asp:LinkButton>
                        <%--                        <asp:LinkButton ID="btnDodaj" runat="server" Text="Dodaj" CssClass="aspButton" Width="90px" OnClick="btnDodaj_Click"></asp:LinkButton>--%>
                    </td>
                </tr>
                <tr>
                    <td colspan="2">
                        <small>Imię</small><br />
                        <asp:TextBox ID="tbImie" runat="server" Width="95%"  OnChange="LoginEmail()" OnTextChanged="tbImieNazwisko_TextChanged"></asp:TextBox>
                    </td>
                    <td colspan="2">
                        <small>Nazwisko</small><br />
                        <asp:TextBox ID="tbNazwisko" runat="server" Width="100%"  OnChange="LoginEmail()" OnTextChanged="tbImieNazwisko_TextChanged"></asp:TextBox>
                    </td>
                </tr>
                <tr>
                    <td colspan="2">
                        <small>Rodzaj numeru identyfikacyjnego</small><br />
                        <asp:DropDownList ID="ddlRodzajIdentyfikatora" runat="server" Width="95%"></asp:DropDownList>
                    </td>
                    <td colspan="2">
                        <small>Numer identyfikacyjny</small><br />
                        <asp:TextBox ID="tbNumerIdentyfikacyjny" runat="server" Width="100%" AutoPostBack="True" OnTextChanged="tbNumerIdentyfikacyjny_TextChanged"></asp:TextBox>
                    </td>
                </tr>
                <tr>
                    <td colspan="2">
                        <small>Login</small><br />
                        <asp:TextBox ID="tbLogin" runat="server" Enabled="False" Width="95%" ReadOnly="True"></asp:TextBox>
                    </td>
                    <td colspan="2">
                        <small>e-mail</small><br />
                        <asp:TextBox ID="tbEmail" runat="server" Enabled="False" Width="100%" ReadOnly="True"></asp:TextBox>
                    </td>
                </tr>
                <tr>
                    <td colspan="2">
                        <small>Agencja pracy</small><br />
                        <asp:DropDownList ID="ddlAgencjePracy" runat="server" Width="95%"></asp:DropDownList>
                    </td>
                    <td colspan="2">
                    </td>
                </tr>
                <tr>
                    <td colspan="2">
                        <small>Schemat uprawnień</small><br />
                        <asp:DropDownList ID="ddlSchematUprawnien" runat="server" Width="95%" OnChange="PokazOpisSchematu();" AutoPostBack="True" OnSelectedIndexChanged="ddlSchematUprawnien_SelectedIndexChanged"></asp:DropDownList>
                    </td>
                    <td colspan="2">
                        <div id="lblSchematOpis"></div>
                    </td>
                </tr>
                <tr>
                    <td colspan="2">
                        <asp:CheckBox ID="cbAktywny" runat="server" Text="Aktywny (LDAP)" Checked="True" AutoPostBack="True" OnCheckedChanged="cbAktywny_CheckedChanged" />
                    </td>
                    <td colspan="2">
                        &nbsp;
                    </td>
                </tr>
                <tr style="height:20px;">
                    <td colspan="2">
                        &nbsp;
                    </td>
                    <td colspan="2">
                        &nbsp;
                    </td>
                </tr>
                <tr>
                    <td colspan="4">
                        <asp:Label ID="lblAplikacje" runat="server" Font-Bold="True" Font-Size="9pt" Font-Names="Tahoma">Prawa do aplikacji</asp:Label>
                    </td>
                </tr>
                <tr>
                    <td colspan="4" valign="top">
                        <asp:DataGrid ID="dgAplikacje" runat="server" CssClass="aspGrid" Width="100%" DataSource="<%# dvAplikacje %>"
                            AutoGenerateColumns="False" PageSize="12">
                            <AlternatingItemStyle CssClass="TableItemAlt"></AlternatingItemStyle>
                            <ItemStyle CssClass="TableItem"></ItemStyle>
                            <HeaderStyle HorizontalAlign="Center" ForeColor="White" CssClass="TableHeader" VerticalAlign="Top"></HeaderStyle>
                            <Columns>
                                <asp:TemplateColumn HeaderText="Obecne">
                                    <HeaderStyle Width="10px"></HeaderStyle>
                                    <ItemStyle HorizontalAlign="Center"></ItemStyle>
                                    <ItemTemplate>
                                        <asp:CheckBox ID="cbObecne" runat="server" Enabled="False" Checked='<%# DataBinder.Eval(Container, "DataItem.PRAWO_STARE") %>'></asp:CheckBox>
                                    </ItemTemplate>
                                </asp:TemplateColumn>
                                <asp:TemplateColumn HeaderText="Nowe">
                                    <HeaderStyle Width="10px"></HeaderStyle>
                                    <ItemStyle HorizontalAlign="Center"></ItemStyle>
                                    <ItemTemplate>
                                        <asp:CheckBox ID="cbNowe" runat="server" AutoPostBack="False" 
                                            Checked='<%# DataBinder.Eval(Container, "DataItem.PRAWO_NOWE") %>' Enabled='<%# DataBinder.Eval(Container, "DataItem.PRAWO_NOWE_ENABLED") %>'></asp:CheckBox>
                                    </ItemTemplate>
                                </asp:TemplateColumn>
                                <asp:BoundColumn Visible="False" DataField="ID_APLIKACJI" SortExpression="ID_APLIKACJI"
                                    HeaderText="ID_APLIKACJI"></asp:BoundColumn>
                                <asp:BoundColumn DataField="NAZWA" SortExpression="NAZWA" HeaderText="Nazwa">
                                    <HeaderStyle Width="100%"></HeaderStyle>
                                </asp:BoundColumn>
                            </Columns>
                            <PagerStyle Position="Top" BackColor="LightGray" CssClass="Pager" Mode="NumericPages"></PagerStyle>
                        </asp:DataGrid>
                    </td>
                </tr>
                <tr>
                    <td colspan="4">&nbsp;</td>
                </tr>
                <tr>
                    <td colspan="4">
                        <asp:Label ID="lblJednostki" runat="server" Font-Bold="True" Font-Size="9pt" Font-Names="Tahoma">Prawa do jednostek</asp:Label>
                    </td>
                </tr>
                <tr>
                    <td colspan="4" style="width: 50%" valign="top">
                        <asp:DataGrid ID="dgJednostki" runat="server" CssClass="aspGrid" Width="100%" DataSource="<%# dvJednostki %>"
                            AutoGenerateColumns="False" PageSize="12">
                            <AlternatingItemStyle CssClass="TableItemAlt"></AlternatingItemStyle>
                            <ItemStyle CssClass="TableItem"></ItemStyle>
                            <HeaderStyle HorizontalAlign="Center" ForeColor="White" CssClass="TableHeader" VerticalAlign="Top"></HeaderStyle>
                            <Columns>
                                <asp:TemplateColumn HeaderText="Obecne">
                                    <HeaderStyle Width="10px"></HeaderStyle>
                                    <ItemStyle HorizontalAlign="Center"></ItemStyle>
                                    <ItemTemplate>
                                        <asp:CheckBox ID="cbObecneJednostki" runat="server" Enabled="False" Checked='<%# DataBinder.Eval(Container, "DataItem.PRAWO_STARE") %>'></asp:CheckBox>
                                    </ItemTemplate>
                                </asp:TemplateColumn>
                                <asp:TemplateColumn HeaderText="Nowe">
                                    <HeaderStyle Width="10px"></HeaderStyle>
                                    <ItemStyle HorizontalAlign="Center"></ItemStyle>
                                    <ItemTemplate>
                                        <asp:CheckBox ID="cbNoweJednostki" runat="server" Checked='<%# DataBinder.Eval(Container, "DataItem.PRAWO_NOWE") %>' Enabled='<%# DataBinder.Eval(Container, "DataItem.PRAWO_NOWE_ENABLED") %>'></asp:CheckBox>
                                    </ItemTemplate>
                                </asp:TemplateColumn>
                                <asp:BoundColumn Visible="False" DataField="ID_MPZ" SortExpression="ID_MPZ" HeaderText="ID_MPZ"></asp:BoundColumn>
                                <asp:BoundColumn Visible="False" DataField="ID_MPZ_PRZODKA" SortExpression="ID_MPZ_PRZODKA"
                                    HeaderText="ID_MPZ_PRZODKA"></asp:BoundColumn>
                                <asp:BoundColumn DataField="KOD_UZYJ" SortExpression="KOD_UZYJ" HeaderText="Kod"></asp:BoundColumn>
                                <asp:BoundColumn DataField="NAZWA" SortExpression="NAZWA" HeaderText="Nazwa"></asp:BoundColumn>
                                <asp:BoundColumn Visible="False" DataField="MPZ" SortExpression="MPZ" HeaderText="MPZ"></asp:BoundColumn>
                            </Columns>
                            <PagerStyle Position="Top" BackColor="LightGray" CssClass="Pager" Mode="NumericPages"></PagerStyle>
                        </asp:DataGrid>
                    </td>
                </tr>
            </table>
        </div>
    </form>
</body>
</html>
