<%@ page language="C#" autoeventwireup="true" inherits="Pages_MobileView_NoOfStudentPresence, App_Web_ekfnmd41" masterpagefile="~/Pages/Common/MasterPages/MobileViewMasterPage.master" enableEventValidation="false" viewStateEncryptionMode="Never" %>

<asp:Content ID="Content1" ContentPlaceHolderID="CP" runat="Server">
    <script>
        var Id;
        var OrgId;
        var OrgGroupId;
        var Group;
        var BatchId;
        var statusId;
        var Day;
        var Header;
        var ReHeader;
        $(document).ready(function () {
            var myurl = window.location.href;
            var keyval = myurl.split('?')[1].split('&');
            OrgId = parseInt(keyval[0].split('=')[1].toString());
            Id = OrgId = parseInt(keyval[0].split('=')[1].toString());
            Group = keyval[1].split('=')[1].toString();
            BatchId = parseInt(keyval[2].split('=')[1].toString());
            Day = parseInt(keyval[3].split('=')[1].toString());
            $.ajax({
                type: "POST",
                url: "NoOfStudentPresence.aspx/GetOrgId",
                data: JSON.stringify({ "Id": Id, "Group": Group }),
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function (result) {
                    var obj = (result.d);
                    if (Group == "OrgId") {
                        Header = "<h5 class='page-title'><a href='#' onclick='dashboardpage()'>" + obj[0].Title + "</a></h5>"+
                        " <h5 class='page-title' ><a href='#' onclick='PageName()'>Student Presence</a></h5>";
                        $("#HeaderLabel").text("MIS DashBoard");
                    }
                    else {
                        Header = "<h5 class='page-title'><a href='#' onclick='dashboardpage()'>" + obj[0].Title + "</a></h5>"+
                        " <h5 class='page-title' ><a href='#' onclick='PageName()'>Student Presence</a></h5>";
                        $("#HeaderLabel").text("EIS DashBoard");
                    }

                    document.getElementById("HeaderTitle").innerHTML = Header;
                    ReHeader = document.getElementById("HeaderTitle").innerHTML;
                }
            });
            if (Group == "OrgId")
            { ClassDataBind(); }
            else { OrganizationGet(); }
            
        });
        function PageName() {
            if (Group == "OrgId") {
                window.location.href = "../MobileView/MobileDashBoard2.aspx?OrgId=" + Id;
            }
            else {
                window.location.href = "../MobileView/MobileDashBoard2.aspx?OrgGroupId=" + Id;
            }
        }
        function dashboardpage() {
            if (Group == "OrgId") {
                window.location.href = "../MobileView/MobileDashBoard2.aspx?OrgId=" + Id;
            }
            else {
                window.location.href = "../MobileView/MobileDashBoard2.aspx?OrgGroupId=" + Id;
            }
        }
        function OrganizationGet() {
            $.ajax({
                type: "POST",
                url: "NoOfStudentPresence.aspx/OrganizationGet",
                data: JSON.stringify({ "Day": parseInt(Day), "OrgId": OrgId, "BatchId": parseInt(BatchId) }),
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function (result) {
                    var obj = (result.d);
                    var tblOrg = "";
                   
                    if (obj != "") {
                        tblOrg += "<tr><th>Organization Name</th><th>Count</th></tr>";
                        $.each(obj, function (i, item) {
                            if (Day == -1)
                            { tblOrg += "<tr><td ><a onclick='ClassDataBind(" + item.OrgId + ")'>" + item.Organization + "</a></td><td>" + item.YesterdayCount + "</td></tr>"; }
                            else if (Day == 1)
                            { tblOrg += "<tr><td ><a onclick='ClassDataBind(" + item.OrgId + ")'>" + item.Organization + "</a></td><td>" + item.DailyAverage + "</td></tr>"; }
                            else if (Day == 7)
                            { tblOrg += "<tr><td><a onclick='ClassDataBind(" + item.OrgId + ")'>" + item.Organization + "</a></td><td>" + item.WeeklyAverage + "</td></tr>";  }
                            else
                            { tblOrg += "<tr><td ><a onclick='ClassDataBind(" + item.OrgId + ")'>" + item.Organization + "</a></td><td>" + item.MonthlyAverage + "</td></tr>"; }
                        });
                        //tblOrg += "<tr><td style='font-weight:bold'>Total</td><td style='font-weight:bold'>" + total + "</td></tr>";
                        // Header += " <h5 class='page-title' style='display:Block' id='ClassName'><a href='#' onclick='HeaderDisplay(1)'>" + ClassName + "</a></h5>";
                    }
                    else { tblOrg += "<tr><td colspan='8' class='record'>No records found..!!</td></tr>"; }
                    // alert(obj);
                    document.getElementById("tblOrg").innerHTML = tblOrg;
                    document.getElementById("ClassHead").style.display = "none";
                    document.getElementById("OrgHead").style.display = "block";
                    statusId = 0;
                    // document.getElementById("HeaderTitle").innerHTML = Header;
                }
            });
        }
        function ClassDataBind(Id) {
            if (Group == "OrgId")
            { OrgGroupId = 0; }
            else { OrgGroupId = OrgId; OrgId = Id; }
            $.ajax({
                type: "POST",
                url: "NoOfStudentPresence.aspx/ClassDataBind",
                data: JSON.stringify({ "OrgId": OrgId, "Group": Group, "BatchId": BatchId, "Day": Day, "OrgGroupId": OrgGroupId }),
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function (result) {
                    var obj = (result.d);
                    var tblClass = "";
                  //  var total = 0;
                    if (obj != "")
                    {
                        tblClass += "<tr><th>Class Name</th><th>Count</th><th> Student Presence Average</th></tr>";
                        $.each(obj, function (i, item) {
                            //if (item.YesterdayCount === null || item.YesterdayCount === undefined || item.DailyCount === null || item.DailyCount === undefined || item.WeeklyCount === null || item.WeeklyCount === undefined || item.MonthlyCount === null || item.MonthlyCount === undefined)
                            //{ item.YesterdayCount = 0; item.DailyCount = 0; item.WeeklyCount = 0; item.MonthlyCount = 0; }
                            // alert(item.DepartmentName);
                            // tblClass += "<tr><td><a onclick='StudentTransportDataBind()'>" + item.ClassName + "</a></td><td>" + item.TransportStudentCount + "</td></tr>";
                            if (Day == -1)
                            { tblClass += "<tr><td><a onclick='DivisionDataBind(" + item.ClassId + ",\"" + item.ClassName + " \")'>" + item.ClassName + "</a></td><td>" + item.YesterdayCount + "</td><td>" + item.YesterdayAverage + "</td></tr>"; }
                            else if (Day == 1)
                            { tblClass += "<tr><td><a onclick='DivisionDataBind(" + item.ClassId + ",\"" + item.ClassName + " \")'>" + item.ClassName + "</a></td><td>" + item.DailyCount + "</td><td>" + item.DailyAverage + "</td></tr>"; }
                            else if (Day == 7)
                            { tblClass += "<tr><td><a onclick='DivisionDataBind(" + item.ClassId + ",\"" + item.ClassName + " \")'>" + item.ClassName + "</a></td><td>" + item.WeeklyCount + "</td><td>" + item.WeeklyAverage + "</td></tr>"; }
                            else
                            { tblClass += "<tr><td><a onclick='DivisionDataBind(" + item.ClassId + ",\"" + item.ClassName + " \")'>" + item.ClassName + "</a></td><td>" + item.MonthlyCount + "</td><td>" + item.MonthlyAverage + "</td></tr>"; }
                        });
                        
                    }
                    else { tblClass += "<tr><td colspan='8' class='record'>No records found..!!</td></tr>"; }
                    // alert(obj);
                    document.getElementById("tblClass").innerHTML = tblClass;
                    document.getElementById("ClassHead").style.display = "block";
                    document.getElementById("OrgHead").style.display = "none";
                }

            });
        }

        function DivisionDataBind(ClassId, ClassName) {
            $.ajax({
                type: "POST",
                url: "NoOfStudentPresence.aspx/DivisionDataBind",
                data: JSON.stringify({ "OrgId": OrgId, "Group": Group, "BatchId": BatchId, "ClassId": ClassId, "Day": Day, "OrgGroupId": OrgGroupId }),
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function (result) {
                    var obj = (result.d);
                    var tblDivision = "";
                   
                    if (obj != "")
                    {
                        tblDivision += "<tr><th>Division Name</th><th>Count</th><th>Student Presence Average</th></tr>";
                        $.each(obj, function (i, item) {
                            // alert(item.DepartmentName);
                            //tblDivision += "<tr><td>" + item.DivisionName + "</td><td>" + item.Name + "</td></tr>";
                            if (Day == -1)
                            { tblDivision += "<tr><td>" + item.DivisionName + "</td><td>" + item.YesterdayCount + "</td><td>" + item.YesterdayAverage + "</td></tr>"; }
                            else if (Day == 1)
                            { tblDivision += "<tr><td>" + item.DivisionName + "</td><td>" + item.DailyCount + "</td><td>" + item.DailyAverage + "</td></tr>"; }
                            else if (Day == 7)
                            { tblDivision += "<tr><td>" + item.DivisionName + "</td><td>" + item.WeeklyCount + "</td><td>" + item.WeeklyAverage + "</td></tr>"; }
                            else
                            { tblDivision += "<tr><td>" + item.DivisionName + "</td><td>" + item.MonthlyCount + "</td><td>" + item.MonthlyAverage + "</td></tr>"; }
                        });
                       
                        Header += " <h5 class='page-title' style='display:Block' id='ClassName'><a href='#' onclick='HeaderDisplay(1)'>" + ClassName + "</a></h5>";
                    }
                    else { tblDivision += "<tr><td colspan='8' class='record'>No records found..!!</td></tr>"; }
                    // alert(obj);
                    document.getElementById("tblDivision").innerHTML = tblDivision;
                    document.getElementById("HeaderTitle").innerHTML = Header;
                    document.getElementById("ClassHead").style.display = "none";
                    document.getElementById("DivisionHead").style.display = "block";
                    statusId = 1;
                }

            });
        }

        function HeaderDisplay(id) {
            if (id == 1) {
                document.getElementById("ClassHead").style.display = "block";
                document.getElementById("DivisionHead").style.display = "none";
                $("#ClassName").hide();
                Header = '' + ReHeader;
            }
        }
        function BackOrgFunction() {
            if (statusId == 0) {
                document.getElementById("ClassHead").style.display = "none";
                document.getElementById("DivisionHead").style.display = "none";
                document.getElementById("OrgHead").style.display = "block";
                statusId--;
            }
            else if (statusId == 1) {
                document.getElementById("ClassHead").style.display = "block";
                document.getElementById("DivisionHead").style.display = "none";
                $("#ClassName").hide();
                Header = '' + ReHeader;
                statusId--;
            }
            else {
                if (Group == "OrgId")
                { window.location.href = "../MobileView/MobileDashBoard2.aspx?OrgId=" + OrgId; }
                else { window.location.href = "../MobileView/MobileDashBoard2.aspx?OrgGroupId=" + Id; }
            }

        }
        function DashBoard() { window.location.href = "../MobileView/DashBoard.aspx"; }
    </script>
    <asp:UpdatePanel ID="DoctorScheduleUpdatePanel" runat="server">
        <ContentTemplate>
          <div class="page-header row mb20">
                <div class="col-xl-12 col-sm-12 col-xs-12 border-bottom-inline padd-0">
                    <div class="col-md-12 ptb12 d-inline-flex">
                        <span class='btn btn-home btn-icon' onclick='DashBoard()' title='home'><span><i class='material-icons'>home</i></span></span>
                        <div class="d-inline-flex w-100">
                            <label class="header-topic justify-content-center" id="HeaderLabel"></label>
                        </div>
                        <input type="button" value="&#xf3e5;" id="bntBackOrg" onclick="BackOrgFunction()" skinid="0" class="float-right btn btn-back btn-icon fas" />
                    </div>
                    <div class="main-topic inner" id="HeaderTitle">
                    </div>
                </div>
            </div>

            <div class="bg-white row center-block">
                <div class="container-fluid">
                     <div class="gutters-tiny push js-appear-enabled animated fadeIn overflow-hidden" data-toggle="appear">
                        <div class="himssuHeader1WireBox col-md-12 pTop5" id="OrgHead" style="display:block">
                                        <h3 class="table-topic">Organization</h3>
                                       <%-- <asp:PlaceHolder ID="DepartMentPlaceHolder" runat="server" /> --%>
                                        <div class='himsBoxContent'><div class='table-responsive'>
                                             <table id='tblOrg' class='table table-striped table-bordered'>
                                            </table>
                                            </div></div>
                                    </div>
                           <div class="himssuHeader1WireBox col-md-12 pTop5" id="ClassHead" style="display:none">
                                        <h3 class="table-topic">Class List</h3>
                                       <%-- <asp:PlaceHolder ID="DepartMentPlaceHolder" runat="server" /> --%>
                                        <div class='himsBoxContent'><div class='table-responsive'>
                                             <table id='tblClass' class='table table-striped table-bordered'>
                                            </table>
                                            </div></div>
                                    </div>
                            
                          <div class="himssuHeader1WireBox col-md-12 pTop5" id="DivisionHead" style="display:none">
                                        <h3 class="table-topic">Division List</h3>
                                       <%-- <asp:PlaceHolder ID="DepartMentPlaceHolder" runat="server" /> --%>
                                        <div class='himsBoxContent'><div class='table-responsive'>
                                             <table id='tblDivision' class='table table-striped table-bordered'>
                                            </table>
                                            </div></div>
                                    </div>
                    </div>
                </div>
            </div>
            <script>
                function openNav() {
                    document.getElementById("mySidenav").style.width = "344px";
                }

                function closeNav() {
                    document.getElementById("mySidenav").style.width = "0";
                }
            </script>
           
        </ContentTemplate>
    </asp:UpdatePanel>
</asp:Content>
