<%@ Page Title="" Language="C#" MasterPageFile="~/module/dashboardPage.master" AutoEventWireup="true" CodeFile="weeklyoff.aspx.cs" Inherits="module_weeklyoff" %>

<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">

     <script src="../assets/js/jquery.min.js"></script>
    <script type="text/javascript">  

        var pid = null; var id1 = "";
        $(document).ready(function () {

            $("#btncreate").show();
            $("#A1").hide();

            $("#btnok").click(function () {
                Saveall();
            });

            datatable();
            aid = GetParameterValues('ID');
            function GetParameterValues(param) {
                var url = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
                for (var i = 0; i < url.length; i++) {
                    var urlparam = url[i].split('=');
                    if (urlparam[0] == param) {
                        return urlparam[1];
                    }
                }
            }

                   
        });

        function SaveCheck() {
            var chkval = [];
            $("input:checkbox[name=vehicle1]:checked").each(function () {
                chkval.push($(this).val());
            });
           
                $.ajax({
                    url: 'weeklyoff.aspx/savecheck',
                    type: 'post',
                    dataType: 'json',
                    contentType: 'application/json;charset=utf-8',
                    //data: JSON.stringify(obj),
                    data: "{ week:'" + chkval + "'}",
                    success: function (er) {
                        datatable();

                        noty({ text: 'Added Successfully', layout: 'topRight', type: 'information' });
                        setTimeout(function () { $.noty.closeAll(); }, 3000);
                        clear();
                    },
                    error: function (error) {
                        console.log(JSON.stringify(error));
                    }
                });
                      
        }

        function updatedays() {
            if ($("#btncreate").val() == "update") {
                var chkval = [];
                $("input:checkbox[name=vehicle1]:checked").each(function () {
                    chkval.push($(this).val());
                });
                $.ajax({
                    url: 'weeklyoff.aspx/UpdateDays',
                    type: 'post',
                    dataType: 'json',
                    contentType: 'application/json;charset=utf-8',
                    // data: "{Id: '" + pid + "',firstweek:'" + $("#chk1").val() + "',secondweek:'" + $("#chk2").val() + "',thirdweek:'" + $("#chk3").val() + "',fourthweek:'" + $("#chk4").val() + "',fifthweek:'" + $("#chk5").val() + "',temptenme:'" + $("#txtemp").val() + "'}",
                    data: "{Id: '" + pid + "', week:'" + chkval + "'}",
                    success: function (er) {
                        datatable();
                        noty({ text: 'Updated Successfully', layout: 'topRight', type: 'information' });
                        setTimeout(function () { $.noty.closeAll(); }, 3000);
                        clear();
                        pid = null;
                    },
                    error: function (error) {
                        console.log(JSON.stringify(error));
                    }
                });
            }
        }

        function editdata(pid1) {
            $("#btncreate").hide();
            $("#A1").show();
           
            $.ajax({
                url: "weeklyoff.aspx/EditData",
                contentType: "application/JSON; charset=utf-8",
                method: "post",
                datatype: "JSON",
                data: "{Id:'" + pid1 + "'}",
                success: function (data) {
                    data = JSON.parse(data.d);
                    console.log(data);
                    // $("#txtemp").val(data[0].temptenme);
                    alert(data[0].week);
                    chkval = data[0].week;


                    //if (data[0].week != 0) {
                    //    $("#chk1").prop('checked', true);
                    //}
                    //else {
                    //    $("#chk1").prop('checked', false);
                    //}
                    //if (data[0].week != 0) {
                    //    $("#chk2").prop('checked', true);
                    //}
                    //else {
                    //    $("#chk2").prop('checked', false);
                    //}
                   
                    datatable();
                    pid = pid1; 
                    $("#btncreate").val("update")                  
                    //$("#A1").val('Update');
                }
            });
        }

        function Saveall() {
            var chkval = [];
            $("input:checkbox[name=vehicle1]:checked").each(function () {
                chkval.push($(this).val());
            });
                     
                    if (pid == null) {

                        $.ajax({
                            url: 'weeklyoff.aspx/savedata',
                            type: 'post',
                            dataType: 'json',
                            contentType: 'application/json;charset=utf-8',
                            //data: JSON.stringify(obj),
                            //data: "{ firstweek:'" + $("#chk1").val() + "',secondweek:'" + $("#chk2").val() + "',thirdweek:'" + $("#chk3").val() + "',fourthweek:'" + $("#chk4").val() + "',fifthweek:'" + $("#chk5").val() + "',temptenme:'" + $("#txtemp").val() + "'}",
                            data: "{ week:'" + chkval + "',temptenme:'" + $("#txtemp").val() + "'}",
                            success: function (er) {                               
                                    noty({ text: 'Added Successfully', layout: 'topRight', type: 'information' });
                                    setTimeout(function () { $.noty.closeAll(); }, 3000);
                                    clear();
                                   // btnclose
                            },
                            error: function (error) {
                                console.log(JSON.stringify(error));
                            }
                        });
                    }
                    else {
                        $.ajax({
                            url: 'weeklyoff.aspx/UpdateData',
                            type: 'post',
                            dataType: 'json',
                            contentType: 'application/json;charset=utf-8',
                           // data: "{Id: '" + pid + "',firstweek:'" + $("#chk1").val() + "',secondweek:'" + $("#chk2").val() + "',thirdweek:'" + $("#chk3").val() + "',fourthweek:'" + $("#chk4").val() + "',fifthweek:'" + $("#chk5").val() + "',temptenme:'" + $("#txtemp").val() + "'}",
                            data: "{Id: '" + pid + "', week:'" + chkval + "',temptenme:'" + $("#txtemp").val() + "'}",
                            success: function (er) {
                              
                                    noty({ text: 'Updated Successfully', layout: 'topRight', type: 'information' });
                                    setTimeout(function () { $.noty.closeAll(); }, 3000);
                                    clear(); 

                                    pid = null;
                            },
                            error: function (error) {
                                console.log(JSON.stringify(error));
                            }
                        });
                    }
                        
        }

        function datatable() {
            $.ajax({
                type: "POST",
                url: "weeklyoff.aspx/GetData",
                contentType: "application/JSON; charset=utf-8",

                datatype: "JSON",
                success: function (data) {
                    var table = $('#dataemp').DataTable();
                    data = JSON.parse(data.d);
                    table.clear();
                    for (var i = 0; i < data.length; i++) {
                        table.row.add([
                             data[i].id, data[i].temptenme,  "<i class='fadeIn animated bx bx-user-check' style='font-size:28px;' data-bs-toggle='modal' data-bs-target='#exampleLargeModal' onclick=getTemplate('" + data[i].id + "')></i><button  style='height:35px; width: 35px; padding-left:7px;' type='button' onclick=editdata('" + data[i].id + "') id='btnedit' class='btn btn-success'  ><i class='bx bx-message-square-edit'></i></button>"

                        ]).draw(true);

                    }
                }
            });
        }
        
        function getTemplate(id) {
            $.ajax({
                type: "POST",
                url: "weeklyoff.aspx/gettemplate", //It calls our web method.
                contentType: "application/json; charset=utf-8",
                data: "{id: '" + id + "' }",
                dataType: "json",
                success: function (data) {
                    console.log(JSON.stringify(data));
                    data = JSON.parse(data.d);

                    $("#txttempstu").val(data[0].temptenme);
                   
                    
                },
                
                error: function (error) {
                    console.log(JSON.stringify(error));
                }
            });
        }

        function deletedata(id1) {
            //alert(id1);
            $.ajax({
                url: "weeklyoff.aspx/DeleteData",
                contentType: "application/JSON; charset=utf-8",
                method: "post",
                datatype: "JSON",
                data: "{id:'" + id1 + "'}",
                success: function (data) {
                    $(".vehicle1").prop("checked", false);
                    datatable();
                    noty({ text: 'Delete Successfully', layout: 'topRight', type: 'information' });
                    setTimeout(function () { $.noty.closeAll(); }, 3000);
                }
            });
        }


        function getdata12() {
           
            $.ajax({
                url: "weeklyoff.aspx/Getdata12",
                method: "post",
                contentType: "application/json; charset=utf-8",
                data: "{clasr:'" + $("select[id$=clasrch]").val() + "', division:'" + $("select[id$=divisrch]").val() + "'}",
                dataType: "json",
                success: function (data) {
                console.log(JSON.stringify(data));
                data = JSON.parse(data.d);

                $("#datatables").show();
               $("#itembody1").empty();
                         
               for (var i = 0; i < data.length ; i++, count++) {
                {
                    var fullname = data[i].fname + " " + data[i].mname + " " + data[i].lname; 
                    var markup = '<tr ><td >' + data[i].id + '</td><td >' + fullname +  '</td><td >' + data[i].classd + '</td><td>' + data[i].temptenme +  '</td><td> '

                    $("#itembody1").append(markup);
                  }
                }
             },           
                error: function () {
                    //alert("Error in display");
                    noty({ text: 'Get Error', layout: 'topRight', type: 'error' });
                    setTimeout(function () { $.noty.closeAll(); }, 3000);
                }

            });
        }

        function clear() {
            $(".vehicle1").prop("checked", false);
            $("#txtemp").val('');
            $("#txttempstu").val('');
            $('select[id$=clasrch]').val("");
            $('select[id$=divisrch]').val("");
        }

    </script>

    	<!--start page wrapper -->
			<!--start page wrapper -->
		<div class="page-wrapper">
			<div class="page-content">


				<div class="overlay toggle-icon"></div>
				<h6>Weekly Off</h6>
				<hr />
				<div class="col-md-12 mx-auto">
					<div class="card">
						<div class="card-body">
							<div class="table-responsive">
								<table id="" class="table table-striped table-bordered">
									<thead>
										<tr>
											<th >Day</th>
											<th>1st</th>
											<th>2nd</th>
											<th>3rd</th>
											<th>4th</th>
											<th>5th</th>
											<!-- <th>Action</th> -->
										</tr>
									</thead>
									<tbody>
										<tr>
											<td id="txtday">Sunday</td>
											<td><input type="checkbox" id="chk1" name="vehicle1" class="vehicle1" value="1st"></td>
											<td><input type="checkbox" id="chk2" name="vehicle1" class="vehicle1" value="2nd"></td>
											<td><input type="checkbox" id="chk3" name="vehicle1" class="vehicle1" value="3rd"></td>
											<td><input type="checkbox" id="chk4" name="vehicle1" class="vehicle1" value="4th"></td>
											<td><input type="checkbox" id="chk5" name="vehicle1" class="vehicle1" value="5th"></td>

											<!-- <td>
																	 
										 <button  style="height:35px; width: 35px; padding-left:7px;" type="button" class="btn btn-success"  ><i class='bx bx-message-square-edit'></i>
										 </button>&nbsp;<button  style="height:35px; width: 35px; padding-left:7px;" type="button" class="btn btn-danger"><i class="fadeIn animated bx bx-trash-alt"></i>
										 </button>
										 
										 </td> -->
							</div>
						</div>
					</div>
					</tr>
					<tr>
						<td>Monday</td>
						<td><input type="checkbox" id="chk6" name="vehicle1" class="vehicle1" value="1st"></td>
						<td><input type="checkbox" id="chk7" name="vehicle1" class="vehicle1" value="2nd"></td>
						<td><input type="checkbox" id="chk8" name="vehicle1" class="vehicle1" value="3rd"></td>
						<td><input type="checkbox" id="chk9" name="vehicle1" class="vehicle1" value="4th"></td>
						<td><input type="checkbox" id="chk10" name="vehicle1" class="vehicle1" value="5th"></td>
                        <
						<!-- <td>
																		 
											 <button  style="height:35px; width: 35px; padding-left:7px;" type="button" class="btn btn-success"  ><i class='bx bx-message-square-edit'></i>
											 </button>&nbsp;<button  style="height:35px; width: 35px; padding-left:7px;" type="button" class="btn btn-danger"><i class="fadeIn animated bx bx-trash-alt"></i>
											 </button>
											 
											 </td> -->
				</div>
			</div>
		</div>
		</tr>
		<tr>
			<td>Tuesaday</td>
            <td><input type="checkbox" id="chk11" name="vehicle1" class="vehicle1" value="1st"></td>
			<td><input type="checkbox" id="chk12" name="vehicle1" class="vehicle1" value="2nd"></td>
			<td><input type="checkbox" id="chk13" name="vehicle1" class="vehicle1" value="3rd"></td>
			<td><input type="checkbox" id="chk14" name="vehicle1" class="vehicle1" value="4th"></td>
			<td><input type="checkbox" id="chk15" name="vehicle1" class="vehicle1" value="5th"></td>

			<!-- <td>
																			 
												 <button  style="height:35px; width: 35px; padding-left:7px;" type="button" class="btn btn-success"  ><i class='bx bx-message-square-edit'></i>
												 </button>&nbsp;<button  style="height:35px; width: 35px; padding-left:7px;" type="button" class="btn btn-danger"><i class="fadeIn animated bx bx-trash-alt"></i>
												 </button>
												 
												 </td> -->
	</div>
	</div>
	</div>
	</tr>
	<tr>
		<td>Wednesday</td>
       	<td><input type="checkbox" id="chk16" name="vehicle1" class="vehicle1" value="1st"></td>
		<td><input type="checkbox" id="chk17" name="vehicle1" class="vehicle1" value="2nd"></td>
		<td><input type="checkbox" id="chk18" name="vehicle1" class="vehicle1" value="3rd"></td>
		<td><input type="checkbox" id="chk19" name="vehicle1" class="vehicle1" value="4th"></td>
		<td><input type="checkbox" id="chk20" name="vehicle1" class="vehicle1" value="5th"></td>

		<!-- <td>
																				 
													 <button  style="height:35px; width: 35px; padding-left:7px;" type="button" class="btn btn-success"  ><i class='bx bx-message-square-edit'></i>
													 </button>&nbsp;<button  style="height:35px; width: 35px; padding-left:7px;" type="button" class="btn btn-danger"><i class="fadeIn animated bx bx-trash-alt"></i>
													 </button>
													 
													 </td> -->
		</div>
		</div>
		</div>
	</tr>
	<tr>
		<td>Thursday</td>
      	<td><input type="checkbox" id="chk21" name="vehicle1" class="vehicle1" value="1st"></td>
		<td><input type="checkbox" id="chk22" name="vehicle1" class="vehicle1" value="2nd"></td>
		<td><input type="checkbox" id="chk23" name="vehicle1" class="vehicle1" value="3rd"></td>
		<td><input type="checkbox" id="chk24" name="vehicle1" class="vehicle1" value="4th"></td>
		<td><input type="checkbox" id="chk25" name="vehicle1" class="vehicle1" value="5th"></td>

		<!-- <td>
																					 
														 <button  style="height:35px; width: 35px; padding-left:7px;" type="button" class="btn btn-success"  ><i class='bx bx-message-square-edit'></i>
														 </button>&nbsp;<button  style="height:35px; width: 35px; padding-left:7px;" type="button" class="btn btn-danger"><i class="fadeIn animated bx bx-trash-alt"></i>
														 </button>
														 
														 </td> -->
		</div>
		</div>
		</div>
	</tr>
	<tr>
		<td>Friday</td>
		<td><input type="checkbox" id="chk26" name="vehicle1" class="vehicle1" value="1st"></td>
		<td><input type="checkbox" id="chk27" name="vehicle1" class="vehicle1" value="2nd"></td>
		<td><input type="checkbox" id="chk28" name="vehicle1" class="vehicle1" value="3rd"></td>
		<td><input type="checkbox" id="chk29" name="vehicle1" class="vehicle1" value="4th"></td>
		<td><input type="checkbox" id="chk30" name="vehicle1" class="vehicle1" value="5th"></td>
       <!-- <td>
																						 
															 <button  style="height:35px; width: 35px; padding-left:7px;" type="button" class="btn btn-success"  ><i class='bx bx-message-square-edit'></i>
															 </button>&nbsp;<button  style="height:35px; width: 35px; padding-left:7px;" type="button" class="btn btn-danger"><i class="fadeIn animated bx bx-trash-alt"></i>
															 </button>
															 
															 </td> -->
		</div>
		</div>
		</div>
	</tr>
	<tr>
		<td>Saturday</td>
       	<td><input type="checkbox" id="chk31" name="vehicle1" class="vehicle1" value="1st"></td>
		<td><input type="checkbox" id="chk32" name="vehicle1" class="vehicle1" value="2nd"></td>
		<td><input type="checkbox" id="chk33" name="vehicle1" class="vehicle1" value="3rd"></td>
		<td><input type="checkbox" id="chk34" name="vehicle1" class="vehicle1" value="4th"></td>
		<td><input type="checkbox" id="chk35" name="vehicle1" class="vehicle1" value="5th"> </td>

		<!-- <td>
																							 
																 <button  style="height:35px; width: 35px; padding-left:7px;" type="button" class="btn btn-success"><i class='bx bx-message-square-edit'></i>
																 </button>&nbsp;<button  style="height:35px; width: 35px; padding-left:7px;" type="button" class="btn btn-danger"><i class="fadeIn animated bx bx-trash-alt"></i>
																 </button>
																 
																 </td> -->
		</div>
		</div>
		</div>
	</tr>
	</tbody>
	</table>
	</div>
	</div>
	</div>
	</div>

<div>
	<form class="row g-2">
	<div class="col-md-3">
			<button type="button" class="btn btn-primary">Default Apply to All Student</button>
	</div>

	<div class="col-md-2">
		<button type="button" class="btn btn-primary" id="btncreate" onclick="SaveCheck();" data-bs-toggle="modal" data-bs-target="#exampleLargeModal1">Create Temp</button>
        <button type="button" class="btn btn-primary" id="A1" onclick="updatedays();" >Update Temp</button>

</div>

<div class="col-md-2">
	<button type="button" onclick="deletedata();" class="btn btn-primary">Delete Temp</button>
</div>
</form>
</div>

	<div class="overlay toggle-icon"></div>

	<hr />
	<div class="col-md-12 mx-auto">
		<div class="card">
			<div class="card-body">
				<table class="table mb-0" id="dataemp">
					<thead>
						<tr>
							<th scope="col">Sr.No</th>
							<th scope="col">Template</th>
                            <%--<th scope="col">Week</th>--%>
							<th scope="col">Student</th>
							
						</tr>
					</thead>
					<%--<tbody>
						<tr>
							<th scope="row">1</th>
							<td>Student</td>
							<td>	<i class="fadeIn animated bx bx-user-check" style="font-size:28px;" data-bs-toggle="modal" data-bs-target="#exampleLargeModal"></i></td>
							
						</tr>
						
					</tbody>--%>
				</table>
			</div>
		</div>
		
	
	</div>
	

	</div>

    <div class="col">
		<!-- Button trigger modal -->
		
		<!-- Modal -->
		<div class="modal fade" id="exampleLargeModal1" tabindex="-1" aria-hidden="true">
			<div class="modal-dialog modal-lg">
				<div class="modal-content">
					<div class="modal-header">
						<h5 class="modal-title">Modal title</h5>
						<button type="button" id="btnclose" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
					</div>
					<div class="modal-body">
                        <form class="row g-2">
					
						<div class="row">
					   <div class="col-md-4">
						 <label>Enter Name Of Template</label>
						<input class="form-control mb-3" type="text" id="txtemp" placeholder="Template Name"
							aria-label="default input example">
					</div>

					
					<div class="col-md-1" style="margin-top: 1vh;padding-top: 15px">
						<button type="button" id="btnok" value="Submit" class="btn btn-primary">Ok</button>
						
										
					   </div>
                        <div class="col-md-1" style="padding-top: 15px; margin-top: 1vh;">
						<button type="button" class="btn btn-primary">Cancel</button>
						
										
					   </div>

					   
					   </form>


					</div>
                    </div>
				
				</div>
			</div>
		</div>
	

	<div class="col">
		<!-- Button trigger modal -->
		
		<!-- Modal -->
		<div class="modal fade" id="exampleLargeModal" tabindex="-1" aria-hidden="true">
			<div class="modal-dialog modal-lg">
				<div class="modal-content">
					<div class="modal-header">
						<h5 class="modal-title">Modal title</h5>
						<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
					</div>
					<div class="modal-body"><form class="row g-2">
					
						<div class="col-md-3">
						
							<select class="form-select mb-3" id="clasrch" aria-label="Default select example">
								<option selected>Select</option>
								<option >B.Pharm</option>
								<option >M. Pharm</option>
								<option >MSC</option>
								<option>Bsc</option>
								<option >D. Pharm</option>
							</select>
						</div>
						
						
						<div class="col-md-3">
						
								<select class="form-select mb-3" id="divisrch" aria-label="Default select example">
								<option selected>Select Class</option>
								<option>1st Year</option>
								<option>2nd Year</option>
								<option>3rd Year</option>
                                <option>4th Year</option>
						
							</select>
						</div>
						
					   <div class="col-md-2" style="margin-top: 1vh;">
						<button type="button" onclick="getdata12();" class="btn btn-primary"><i class='bx bx-search'></i>Search</button>
						
										
					   </div>

					   <div class="col-md-2">
						<!-- <label>Student</label> -->
						<input class="form-control mb-3" id="txttempstu" type="text"  
							aria-label="default input example">
					</div>

					
					<div class="col-md-1" style="margin-top: 1vh;">
						<button type="button" class="btn btn-primary">Assign</button>
						
										
					   </div>

					   
					   </form>

					   <div class="col-md-12 mx-auto">
						<div class="card">
							<div class="card-body">
								<table class="table mb-0" id="datatables">
									<thead class="table-dark">
										<tr>
											<%--<th scope="col"><input type="checkbox" id="vehicle1" name="vehicle1" value="Bike">--%>
												
											<th scope="col">Sr. No</th>
											<th scope="col">Student Name</th>
											<th scope="col">Class</th>
											<th scope="col">Template</th>
										</tr>
									</thead>
									<tbody id="itembody1">
										<tr>
										
										</tr>
									
									</tbody>
								</table>
							</div>
						</div>
					
					</div>
					</div>
				
				</div>
			</div>
		</div>
	</div>
</asp:Content>

