<br />
<br />
<section class="content-header">
            <h1>Manage Hostel Campus </h1>
            <ol class="breadcrumb">
                <li class="breadcrumb-item pt-1"><a href="dashboard"><i class="fa fa-fw fa-home"></i> Dashboard</a>
                </li>

            </ol>
        </section>
        <!-- Main content -->
        <section class="content p-l-r-15">
            <div class="row">
                <div class="col-12">
                    <div class="card border-primary ">
                        <div class="card-header text-white  bg-primary">
                            <h4 class="card-title d-inline">
                                <i class="fa fa-fw fa-News"></i> Campus List
                            </h4>
                        </div>
                        <div class="card-body">
                            <div class="table-responsive table-responisve-lg table-responsive-xl">
                                <table class="table table-bordered" id="table">
                                    <thead>
                                    <tr class="filters">
                                        <th width="5%"><a href="#" class="button button-3d button-primary button-rounded btn_3d" data-toggle="modal" data-target="#myModal">+
											</a></th>


                                    <th > TITTLE </th>

                                    <th > DESCRIPTION </th>

                                    <th> DATE ADDED </th>

                                    <th > ADDED BY </th>

										                <th>DATE MODIFIED</th>
                                        <th>Status</th>
                                        <th>Actions</th>
                                    </tr>
                                    </thead>
                                    <tbody>

									<?php




									$select="SELECT * FROM hostel_campuses WHERE status ='1' ";
									$sql_select = mysqli_query($conn_1,$select);
									$num_rows=mysqli_num_rows($sql_select);
									if($num_rows > 0){
										$sn=1;
										while($row=mysqli_fetch_array($sql_select)){

											$id=$row['id'];
											$title=$row['title'];
											$description=$row['description'];
											$date_added=$row['date_added'];
											$added_by=$row['added_by'];
											$modified_by=$row['modified_by'];
											$campus_status=$row['status'];
                      $date_modified = $row['date_modified'];
											if($campus_status=='0'){
														$status='Deleted';
													}else if($campus_status=="1"){
														$status='Active';
													}else{
														$status='Suspend';
													}

											echo $tr = '<tr>
														<td><center>'.$sn.'</center></td>
														<td>'.$title.'</td>
														<td>'.$description.'</td>
														<td>'.$date_added.'</td>
														<td>'.$added_by.'</td>
														<td>'.$date_modified.'</td>
														<td>'.$status.'</td>



														<td><a href="#" class="edit_campus" id="'.$id.'"><i
																class="fa fa-fw fa-pencil text-primary actions_icon " title="Edit Campus"></i></a>
																<a
																href="#"
																id="'.$id.'"
																data-toggle="modal"

																class="delete_campus"
																><i
																class="fa fa-fw fa-times text-danger actions_icon" title="Delete Campus"></i>
														</a></td>

													</tr>';
													$sn++;

										}
									}

									?>
                                    </tbody>
                                </table>

                            </div>
                        </div>
                    </div>
                </div>
                <div class="modal fade" id="delete" tabindex="-1" role="dialog" aria-labelledby="Heading"
                     aria-hidden="true">
                    <div class="modal-dialog">
                        <div class="modal-content">
                            <div class="modal-header">
                                <h4 class="modal-title custom_align" id="Heading">Delete Capus</h4>
                                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                            </div>
                            <div class="modal-body">
                                <div class="alert alert-warning">
                                    <span class="fa fa-exclamation-triangle"></span> Are you sure you want to
                                    delete this Campus?
                                </div>
                            </div>
                            <div class="modal-footer" id="delete_footer">

                            </div>
                        </div>
                        <!-- /.modal-content -->
                    </div>
                </div>

				<div class="modal fade" id="edit_campus" tabindex="-1" role="dialog" aria-labelledby="Heading"
                     aria-hidden="true">
                    <div class="modal-dialog">
                        <div class="modal-content">
                            <div class="modal-header">
                                <h4 class="modal-title custom_align" id="Heading">Edit Campus</h4>
                                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                            </div>
                            <div class="modal-body">
                                <div class="alert alert-warning">
                                    <span class="fa fa-exclamation-triangle"></span> Are you sure you want to
                                    edit this Campus ?
                                </div>
                            </div>
                            <div class="modal-footer" id="edit_footer">

                            </div>
                        </div>
                        <!-- /.modal-content -->
                    </div>
                </div>


            </div>
            <!-- row-->

        </section>

 <!-- The Modal -->
  <div class="modal fade" id="myModal">
    <div class="modal-dialog modal-lg">
      <div class="modal-content">

        <!-- Modal Header -->
        <div class="modal-header">
          <h2 class="modal-title"><span class="badge badge-pill badge-danger"> ADD CAMPUS </span></h2>
          <button type="button" class="close" data-dismiss="modal">&times;</button>
        </div>

        <!-- Modal body -->
        <div class="modal-body">
		<form method="POST" id="form_faculty" >


			 <div class="form-group row">
				<label for="title" class="col-sm-3 col-form-label text-right">Title : (*)
				</label>
					<div class="col-sm-9">
						<input id="title" name="title" type="text"
						placeholder="Title " class="form-control required" required />
					</div>
             </div>

			 <div class="form-group row">
				<label for="code" class="col-sm-3 col-form-label text-right">Description : (*)
				</label>
					<div class="col-sm-9">
						<input id="description" name="description" type="text"
						placeholder="description " class="form-control required" required />
					</div>
             </div>




			 <div class="form-group row">
				<label for="location" class="col-sm-3 col-form-label text-right">Added By
				</label>
					<div class="col-sm-9">
						<input id="added_by" name="added_by" type="added_by"
						placeholder="Added By " class="form-control required"  />
					</div>
             </div>

			 <div class="form-group row">
				<label for="Phone Number" class="col-sm-3 col-form-label text-right">Status
				</label>
					<div class="col-sm-9">
						<select class="form-control select21" name="status" id="status">
              <option value="">----- Select ----</option>
              <option value="0">Block</option>
              <option value="1">Unblock</option>
            </select>
					</div>
             </div>




						<div id="button">
							<center>
														<button class="button button-3d button-primary button-rounded btn_3d" onclick="add_sub_cat()">Save
												</button>
						</div>
             </form>


        </div>

        <!-- Modal footer -->
        <div class="modal-footer">
			<center>
				<div id="output_error">

				</div>
			</center>

        </div>

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



<div class="modal fade" id="edit_loading" tabindex="-1" role="dialog" aria-labelledby="Heading"
                     aria-hidden="true">
                    <div class="modal-dialog">
                        <div class="modal-content">
                            <div class="modal-header">
                                <h2 class="modal-title custom_align" id="Heading"> <span class="badge badge-pill badge-danger"> Editing Campus </span> </h2>
                                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                            </div>
                            <div class="modal-body" id="edit_modal_body">
							<form method="POST" id="edit_form_faculty" >

							</form>

                            </div>
                            <div class="modal-footer" id="edit_footer">

                            </div>
                        </div>
                        <!-- /.modal-content -->
                    </div>
                </div>

<script type="text/javascript">
$(document).ready(function(e){



		$("#form_faculty").submit(function(event){
			event.preventDefault(); //prevent default action
			var post_url = "hub/php/add_campus.php"; //get form action url
			var request_method = $(this).attr("method"); //get form GET/POST method

			$("#output_error").html('<div style="margin-top:10px"><center>login, please wait...<br/><img src="images/ajax-loader1.gif" width="20%"/></center></div>');
			document.getElementById("button").style.display = "none";
			var form_data = new FormData(this); //Creates new FormData object


				$.ajax({
					url : post_url,
					type: request_method,
					data : form_data,
					contentType: false,
					cache: false,
					processData:false
				}).done(function(response){ //

					if(response==1){

						$('#form_faculty')[0].reset();
						swal("Campus saved successfully");
						document.getElementById("button").style.display = "block";
						$("#output_error").html("");
						links();

					}else{

					$("#output_error").html(response);
					document.getElementById("button").style.display = "block";

					}
				});

		});




		$("#edit_form_faculty").submit(function(event){

			event.preventDefault(); //prevent default action
			var post_url = "hub/php/update_campus.php"; //get form action url
			var request_method = $(this).attr("method"); //get form GET/POST method

			$("#output_error_edit").html('<div style="margin-top:10px"><center>login, please wait...<br/><img src="images/ajax-loader1.gif" width="20%"/></center></div>');
			document.getElementById("button_edit").style.display = "none";
			var form_data = new FormData(this); //Creates new FormData object


				$.ajax({
					url : post_url,
					type: request_method,
					data : form_data,
					contentType: false,
					cache: false,
					processData:false
				}).done(function(response){ //

					if(response==1){

						$('#edit_form_faculty')[0].reset();
						swal("Campus Updated successfully");
						document.getElementById("button_edit").style.display = "block";
						$("#output_error_edit").html("");
						links();

					}else{

					$("#output_error_edit").html(response);
					document.getElementById("button_edit").style.display = "block";

					}
				});

		});







		// load delete faculty modal
		$(document).on('click','.delete_campus',function(){
			var token=$(this).attr("id");
			$('#delete').modal('show');
			document.getElementById("delete_footer").innerHTML ='<a href="#" class="btn btn-danger" onclick="delete_campus('+token+')"><span class="fa fa-check"></span> Yes</a><button type="button" class="btn btn-success" data-dismiss="modal"><span class="fa fa-close"></span> No</button>';


		});
		// delete faculty end

		// load edit faculty start modal
		$(document).on('click','.edit_campus',function(){
			var token=$(this).attr("id");
			$('#edit_campus').modal('show');
			document.getElementById("edit_footer").innerHTML ='<a href="#" class="btn btn-danger" onclick="load_edit_campus('+token+')"><span class="fa fa-check"></span> Yes</a><button type="button" class="btn btn-success" data-dismiss="modal"><span class="fa fa-close"></span> No</button>';


		});
		// edit faculty end




});

function links(){
	location.reload();
 }


  function delete_campus(token){
			//alert(token);
		 	$.post("hub/php/delete_campus.php",{token:token},
			function(response,status){

				if(response == 1 ){
					$('#delete').modal('hide');

					  swal("Campus Deleted");
					  links();


				}else{
					swal(response);
				}


			});
 }


 function load_edit_campus(token){


			$('#edit_campus').modal('hide');
			$('#edit_loading').modal('show');

			document.getElementById("edit_form_faculty").innerHTML ='<div style="margin-top:10px"><center>loading Data, please wait...<br/><img src="images/ajax-loader1.gif" width="10%"/></center></div>';

			$.post('hub/php/load_edit_campus.php',{token:token},
			function(response,status){

			document.getElementById("edit_form_faculty").innerHTML =response;

			});
}

</script>
