<br />
<br />
<?php
  $sn=1;
?>
<section class="content-header">
            <h1>Manage All Paid Students </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> Students 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 > NMAE </th>

                      <th >MATRIC NUMBER </th>

                      <th> PROGRAMME </th>

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

                      <th > EMAIL </th>


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

									<?php

                  $session = 6;
                  //collect the passed
                  if(isset($_GET['pt']))
                  {
                   echo $pt =  $_GET['pt'];
                  }

                           //fetch record by their programme types
                           if($pt=='1')
                           {
                             //fetch all records from hostel_fee_payments mysql_list_tables
                             $get_record = mysqli_query($conn_1, "SELECT *FROM hostel_fee_payments WHERE programme_type_id='$pt'");
                             $record_rows=mysqli_num_rows($get_record);
                             if($record_rows > 0)
                             {
                               while($row=mysqli_fetch_array($get_record)){
                                  $student_id = $row['student_id'];

                                  //get students details
                                  $allocate = mysqli_query($conn_1, "SELECT CONCAT_WS(' ', first_name, middle_name, other_names) as name,
                                  gender, id, programme_type_applied_for, department_applied_for,
                                  number, programme_applied_for, application_number,
                                    state_id, lga_id,  phone_no, gender,  email,
                                     DATE_FORMAT(date_added, '%M %d, %Y %l:%i:%p') as date_added
                                     FROM  students_nce WHERE
                                      id = '$student_id'
                                     ORDER BY students_nce.application_number ASC ") or die(mysqli_error($conn_1));
                                  $row = mysqli_fetch_assoc($allocate);


                                  $student_id=$row['id'];
                                  $name=$row['name'];
                                  $matric_number=$row['number'];
                                  $email=$row['email'];
                                   $programme_id=$row['programme_applied_for'];
                                  $gender=$row['gender'];
                                  $phone_contacts=$row['phone_no'];
                                  $date_added=$row['date_added'];
                                  $faculty_status=$row['department_applied_for'];

                                  $status='Active';


                                  echo $tr = '<tr>
                                   <td><center>'.$sn.'</center></td>
                                   <td>'.$name.'</td>
                                   <td>'.$matric_number.'</td>
                                   <td>'.get_programmes_by_id($conn_1,$programme_id).'</td>
                                   <td>'.$phone_contacts.'</td>
                                   <td>'.$gender.'</td>
                                   <td>'.$email.'</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>';
                                      $sn++;
                               }
                             }

                           }else if($pt=='2')
                           {
                             //fetch all records from hostel_fee_payments mysql_list_tables
                             $get_record = mysqli_query($conn_1, "SELECT *FROM hostel_fee_payments WHERE programme_type_id='$pt' ");
                             $record_rows=mysqli_num_rows($get_record);
                             if($record_rows > 0)
                             {
                               while($row=mysqli_fetch_array($get_record)){
                                  $student_id = $row['student_id'];

                                  //get students details
                                  $allocate = mysqli_query($conn_1, "SELECT CONCAT_WS(' ', first_name, middle_name, other_names) as name,
                                  gender, id, programme_type_applied_for, department_applied_for,
                                  number, programme_applied_for, application_number,
                                    state_id, lga_id,  phone_no, gender,  email,
                                     DATE_FORMAT(date_added, '%M %d, %Y %l:%i:%p') as date_added
                                     FROM  students_nce WHERE
                                      id = '$student_id'
                                     ORDER BY students_nce.application_number ASC ") or die(mysqli_error($conn_1));
                                  $row = mysqli_fetch_assoc($allocate);


                                  $student_id=$row['id'];
                                  $name=$row['name'];
                                  $matric_number=$row['number'];
                                  $email=$row['email'];
                                   $programme_id=$row['programme_applied_for'];
                                  $gender=$row['gender'];
                                  $phone_contacts=$row['phone_no'];
                                  $date_added=$row['date_added'];
                                  $faculty_status=$row['department_applied_for'];

                                  $status='Active';


                                  echo $tr = '<tr>
                                   <td><center>'.$sn.'</center></td>
                                   <td>'.$name.'</td>
                                   <td>'.$matric_number.'</td>
                                   <td>'.get_programmes_by_id($conn_1,$programme_id).'</td>
                                   <td>'.$phone_contacts.'</td>
                                   <td>'.$gender.'</td>
                                   <td>'.$email.'</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>';
                                      $sn++;
                               }
                             }
                           }else if($pt=='3')
                           {
                             //fetch all records from hostel_fee_payments mysql_list_tables
                             $get_record = mysqli_query($conn_1, "SELECT *FROM hostel_fee_payments WHERE programme_type_id='$pt'");
                             $record_rows=mysqli_num_rows($get_record);
                             if($record_rows > 0)
                             {
                               while($row=mysqli_fetch_array($get_record)){
                                  $student_id = $row['student_id'];

                                  //get students details
                                  $allocate = mysqli_query($conn_2, "SELECT CONCAT_WS(' ', first_name, middle_name, other_names) as name,
                                  gender, id, programme_type_applied_for, department_applied_for,
                                  number, programme_applied_for, application_number,
                                    state_id, lga_id,  phone_no, gender,  email,
                                     DATE_FORMAT(date_added, '%M %d, %Y %l:%i:%p') as date_added
                                     FROM  students_nce WHERE
                                      id = '$student_id'
                                     ORDER BY students_nce.application_number ASC ") or die(mysqli_error($conn_2));
                                  $row = mysqli_fetch_assoc($allocate);


                                  $student_id=$row['id'];
                                  $name=$row['name'];
                                  $matric_number=$row['number'];
                                  $email=$row['email'];
                                   $programme_id=$row['programme_applied_for'];
                                  $gender=$row['gender'];
                                  $phone_contacts=$row['phone_no'];
                                  $date_added=$row['date_added'];
                                  $faculty_status=$row['department_applied_for'];

                                  $status='Active';


                                  echo $tr = '<tr>
                                   <td><center>'.$sn.'</center></td>
                                   <td>'.$name.'</td>
                                   <td>'.$matric_number.'</td>
                                   <td>'.get_programmes_by_id_duap($conn_2,$programme_id).'</td>
                                   <td>'.$phone_contacts.'</td>
                                   <td>'.$gender.'</td>
                                   <td>'.$email.'</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>';
                                      $sn++;
                               }
                             }
                           }else if($pt=='4')
                           {
                             //fetch all records from hostel_fee_payments mysql_list_tables
                             $get_record = mysqli_query($conn_1, "SELECT *FROM hostel_fee_payments WHERE programme_type_id='$pt'");
                             $record_rows=mysqli_num_rows($get_record);
                             if($record_rows > 0)
                             {
                               while($row=mysqli_fetch_array($get_record)){
                                  $student_id = $row['student_id'];

                                  //get students details
                                  $allocate = mysqli_query($conn_2, "SELECT CONCAT_WS(' ', first_name, middle_name, other_names) as name,
                                  gender, id, programme_type_applied_for, department_applied_for,
                                  number, programme_applied_for, application_number,
                                    state_id, lga_id,  phone_no, gender,  email,
                                     DATE_FORMAT(date_added, '%M %d, %Y %l:%i:%p') as date_added
                                     FROM  students_udus WHERE
                                      id = '$student_id'
                                     ORDER BY students_udus.number ASC ") or die(mysqli_error($conn_2));
                                  $row = mysqli_fetch_assoc($allocate);


                                  $student_id=$row['id'];
                                  $name=$row['name'];
                                  $matric_number=$row['number'];
                                  $email=$row['email'];
                                   $programme_id=$row['programme_applied_for'];
                                  $gender=$row['gender'];
                                  $phone_contacts=$row['phone_no'];
                                  $date_added=$row['date_added'];
                                  $faculty_status=$row['department_applied_for'];

                                  $status='Active';


                                  echo $tr = '<tr>
                                   <td><center>'.$sn.'</center></td>
                                   <td>'.$name.'</td>
                                   <td>'.$matric_number.'</td>
                                   <td>'.get_programmes_by_id_duap($conn_2,$programme_id).'</td>
                                   <td>'.$phone_contacts.'</td>
                                   <td>'.$gender.'</td>
                                   <td>'.$email.'</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>';
                                      $sn++;

                               }
                             }
                           }else if($pt=='5')
                           {
                             //fetch all records from hostel_fee_payments mysql_list_tables
                             $get_record = mysqli_query($conn_1, "SELECT *FROM hostel_fee_payments WHERE programme_type_id='$pt' ");
                             $record_rows=mysqli_num_rows($get_record);
                             if($record_rows > 0)
                             {
                               while($row=mysqli_fetch_array($get_record)){
                                  $student_id = $row['student_id'];

                                  //get students details
                                  $allocate = mysqli_query($conn_1, "SELECT CONCAT_WS(' ', first_name, middle_name, other_names) as name,
                                  gender, id, programme_type_applied_for, department_applied_for,
                                  number, programme_applied_for, application_number,
                                    state_id, lga_id,  phone_no, gender,  email,
                                     DATE_FORMAT(date_added, '%M %d, %Y %l:%i:%p') as date_added
                                     FROM  summer_students WHERE
                                      id = '$student_id'
                                     ORDER BY summer_students.application_number ASC ") or die(mysqli_error($conn_1));
                                  $row = mysqli_fetch_assoc($allocate);


                                  $student_id=$row['id'];
                                  $name=$row['name'];
                                  $matric_number=$row['number'];
                                  $email=$row['email'];
                                   $programme_id=$row['programme_applied_for'];
                                  $gender=$row['gender'];
                                  $phone_contacts=$row['phone_no'];
                                  $date_added=$row['date_added'];
                                  $faculty_status=$row['department_applied_for'];

                                  $status='Active';


                                  echo $tr = '<tr>
                                   <td><center>'.$sn.'</center></td>
                                   <td>'.$name.'</td>
                                   <td>'.$matric_number.'</td>
                                   <td>'.get_programmes_by_id($conn_1,$programme_id).'</td>
                                   <td>'.$phone_contacts.'</td>
                                   <td>'.$gender.'</td>
                                   <td>'.$email.'</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>';
                                      $sn++;
                               }
                             }
                           }else if($pt=='6')
                           {
                             //fetch all records from hostel_fee_payments mysql_list_tables
                             $get_record = mysqli_query($conn_1, "SELECT *FROM hostel_fee_payments WHERE programme_type_id='$pt' ");
                             $record_rows=mysqli_num_rows($get_record);
                             if($record_rows > 0)
                             {
                               while($row=mysqli_fetch_array($get_record)){
                                 $student_id = $row['student_id'];

                                 //get students details
                                 $allocate = mysqli_query($conn_1, "SELECT CONCAT_WS(' ', first_name, middle_name, other_names) as name,
                                 gender, id, programme_type_applied_for, department_applied_for,
                                 number, programme_applied_for, application_number,
                                   state_id, lga_id,  phone_no, gender,  email,
                                    DATE_FORMAT(date_added, '%M %d, %Y %l:%i:%p') as date_added
                                    FROM  summer_students WHERE
                                     id = '$student_id'
                                    ORDER BY summer_students.application_number ASC ") or die(mysqli_error($conn_1));
                                 $row = mysqli_fetch_assoc($allocate);


                                 $student_id=$row['id'];
                                 $name=$row['name'];
                                 $matric_number=$row['number'];
                                 $email=$row['email'];
                                  $programme_id=$row['programme_applied_for'];
                                 $gender=$row['gender'];
                                 $phone_contacts=$row['phone_no'];
                                 $date_added=$row['date_added'];
                                 $faculty_status=$row['department_applied_for'];

                                 $status='Active';


                                 echo $tr = '<tr>
                                  <td><center>'.$sn.'</center></td>
                                  <td>'.$name.'</td>
                                  <td>'.$matric_number.'</td>
                                  <td>'.get_programmes_by_id($conn_1,$programme_id).'</td>
                                  <td>'.$phone_contacts.'</td>
                                  <td>'.$gender.'</td>
                                  <td>'.$email.'</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>';
                                     $sn++;
                               }
                             }
                           }


									?>
                                    </tbody>
                                </table>
<input type="hidden" name="id" id="type_id" value="<?=$pt?>">
                            </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">

                        <!-- 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 DELETE STUDENT FROM HERE!
                          </div>

                        </div>

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

                        </div>
                      </center>

                        </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_student.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("Student 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){
var type_id = document.getElementById("type_id").value;

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

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

			});
}

</script>
