<br />
<br />
<section class="content-header">
            <h1>Total Applicants  </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> Applicants List
                            </h4>
                        </div>
                        <div class="card-body">
                            <div class="table-responsive table-responisve-lg table-responsive-xl">


									<?php




         $select="SELECT app.applicant_id, app.school_applied_for, app.department_applied_for, app.programme_applied_for, app.application_number,
              		 app.state_id, app.lga_id, app.first_name, app.middle_name, app.last_name, app.phone_no, app.gender,  app.email,
              		  DATE_FORMAT(app.date_added, '%M %d, %Y %l:%i:%p') as date_added,
              		  DATE_FORMAT(app.date_modified, '%M %d, %Y %l:%i:%p') as date_modified
              		  FROM  applicants app, applicants_fee_payments app_fees

              		  WHERE   app_fees.applicant_id = app.applicant_id

              		  ORDER BY app.application_number ASC";
                   $sql_select = mysqli_query($con,$select);
                   $num_rows=mysqli_num_rows($sql_select);
                   if($num_rows > 0){
                     $sn=1;

           echo '<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 > NMAE </th>

               <th >APPLICATION NUMBER </th>

               <th> PROGRAMME </th>

               <th > PHONE NUMBER </th>
               <th> GENDER </th>

               <th > EMAIL </th>

       <th>Created At</th>
                   <th>Status</th>
                   <th>Actions</th>
               </tr>
               </thead>
               <tbody>';
           while($row=mysqli_fetch_array($sql_select)){
             $f_name= $row['first_name'];
             $m_name= $row['middle_name'];
             $l_name= $row['last_name'];
             $name = $l_name.' '.$m_name.' '.$f_name;
             $student_id=$row['applicant_id'];
             $matric_number=$row['application_number'];
             $programme_id=$row['programme_applied_for'];
             $email=$row['email'];
             $gender=$row['gender'];
             $phone_contacts=$row['phone_no'];
             $date_added=$row['date_added'];
             $faculty_status=$row['department_applied_for'];
             $status='Paid';

             echo $tr = '<tr>
                   <td><center>'.$sn.'</center></td>
                   <td>'.$name.'</td>
                   <td>'.$matric_number.'</td>
                   <td>'.get_programmes_by_id($con,$programme_id).'</td>
                   <td>'.$phone_contacts.'</td>
                   <td>'.$gender.'</td>
                   <td>'.$email.'</td>
                   <td>'.$date_added.'</td>
                   <td>'.$status.'</td>



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

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

                 </tr>

                 </tbody>
             </table>';
                 $sn++;

           }
         }else{
           echo
                  '<div class="alert alert-danger alert-dismissable">
                 <button class="close" aria-hidden="true" data-dismiss="alert" type="button">x</button>
                 <img src="images/info.png" />&nbsp;&nbsp; No record found in the system.
                  </div>';
         }

									?>


                            </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 Students</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 Student?
                                </div>
                            </div>
                            <div class="modal-footer" id="delete_footer">

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

				<div class="modal fade" id="edit_faculty" 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 Students</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 Student ?
                                </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 STUDENTS </span></h2>
          <button type="button" class="close" data-dismiss="modal">&times;</button>
        </div>

        <!-- Modal body -->
        <div class="modal-body">

          <div class="alert alert-warning">
              <span class="fa fa-exclamation-triangle"></span> YOU CAN'T ADD STUDENT FROM HERE!
          </div>

        </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 Students </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_faculty.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("Faculty 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_faculty.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("Faculty 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_faculty',function(){
			var token=$(this).attr("id");
			$('#delete').modal('show');
			document.getElementById("delete_footer").innerHTML ='<a href="#" class="btn btn-danger" onclick="delete_faculty('+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_faculty',function(){
			var token=$(this).attr("id");
			$('#edit_faculty').modal('show');
			document.getElementById("edit_footer").innerHTML ='<a href="#" class="btn btn-danger" onclick="load_edit_faculty('+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_faculty(token){
			//alert(token);
		 	$.post("hub/php/delete_faculty.php",{token:token},
			function(response,status){

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

					  swal("Faculty Deleted");
					  links();


				}else{
					swal(response);
				}


			});
 }


 function load_edit_faculty(token){


			$('#edit_faculty').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_faculty.php',{token:token},
			function(response,status){

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

			});
}

</script>
