<br />
<br />
<section class="content-header">
            <h1>Manage Programmes Course</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> Programmes Course 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 > SCHOOL </th>

                                    <th > DEPARTMENT </th>

                                    <th> PROGRAMME </th>

                                    <th > COURSE </th>

                                    <th > SEEN</th>

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

									<?php




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

											$programme_course_id=$row['programme_course_id'];
											$school_id=$row['school_id'];
											$department_id=$row['department_id'];
											$programme_id=$row['programme_id'];
											$course_id=$row['course_id'];
											$seen_as_elective=$row['seen_as_elective'];
											$date_added=$row['date_added'];
											$programme_course_status=$row['programme_course_status'];
											if($programme_course_status=='0'){
														$status='Delete';
													}else if($programme_course_status=="1"){
														$status='Active';
													}else{
														$status='Suspend';
													}if($seen_as_elective=='0'){
														$seen='Core';
													}else if($seen_as_elective=="1"){
														$seen='Elective';
													}

											echo $tr = '<tr>
														<td><center>'.$sn.'</center></td>
														<td>'.get_school_by_id($con, $school_id).'</td>
														<td>'.get_department_by_id($con,$department_id).'</td>
														<td>'.get_programmes_by_id($con,$programme_id).'</td>
														<td>'.get_course_id($con,$course_id).'</td>
														<td>'.$seen.'</td>
														<td>'.$date_added.'</td>
														<td>'.$status.'</td>



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

																class="delete_programme_course"
																><i
																class="fa fa-fw fa-times text-danger actions_icon" title="Delete Programme Course"></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 Programme Course</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 Programme Course?
                                </div>
                            </div>
                            <div class="modal-footer" id="delete_footer">

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

				<div class="modal fade" id="edit_programme_course" 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 Programme Course</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 Programme Course?
                                </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 PROGRAMME COURSE</span></h2>
          <button type="button" class="close" data-dismiss="modal">&times;</button>
        </div>

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

		  <div class="form-group row">
				<label for="category" class="col-sm-3 col-form-label text-right">School *</label>
                                                <div class="col-sm-9">
                                                    <select class="form-control select21" id="school"
                                                            title="Select School..." name="school_id">
                                                        <option disabled selected>Select School</option>
														<?php
														echo get_all_schools($con);
														?>

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

			 <div class="form-group row">
				<label for="category" class="col-sm-3 col-form-label text-right">Department *</label>
                                                <div class="col-sm-9">
                                                    <select class="form-control select21" id="department"
                                                            title="Select Department..." name="department_id">
                                                        <option disabled selected>Select Department</option>
														<?php
														echo get_all_department($con);
														?>

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

          <div class="form-group row">
				<label for="category" class="col-sm-3 col-form-label text-right">Programme *</label>
                                                <div class="col-sm-9">
                                                    <select class="form-control select21" id="programme"
                                                            title="Select Programme..." name="programme_id">
                                                        <option disabled selected>Select Programme</option>
														<?php
														echo get_all_programmes($con);
														?>

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

			 <div class="form-group row">
				<label for="category" class="col-sm-3 col-form-label text-right">Course *</label>
                                                <div class="col-sm-9">
                                                    <select class="form-control select21" id="course"
                                                            title="Select Course..." name="course_id">
                                                        <option disabled selected>Select Course</option>
														<?php
														echo get_all_course($con);
														?>

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

			<div class="form-group row">
				<label for="category" class="col-sm-3 col-form-label text-right">Seen As *</label>
                                                <div class="col-sm-9">
                                                    <select class="form-control select21" id="seen_as_elective"
                                                            title="Seen As..." name="seen_as_elective">
                                                        <option disabled selected>Seen As</option>
                                                        <option value="0">Core</option>
                                                        <option value="1">Elective</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 Programme Course</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_programme_course" >

							</form>

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

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

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



		$("#form_programme_course").submit(function(event){
			event.preventDefault(); //prevent default action
			var post_url = "hub/php/add_prog_course.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_programme_course')[0].reset();
						swal("Programme Course 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_programme_course").submit(function(event){

			event.preventDefault(); //prevent default action
			var post_url = "hub/php/update_prog_course.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_programme_course')[0].reset();
						swal("Programme Course 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 programme modal
		$(document).on('click','.delete_programme_course',function(){
			var token=$(this).attr("id");
			$('#delete').modal('show');
			document.getElementById("delete_footer").innerHTML ='<a href="#" class="btn btn-danger" onclick="delete_programme_course('+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 programme end

		// load edit programme start modal
		$(document).on('click','.edit_programme_course',function(){
			var token=$(this).attr("id");
			$('#edit_programme_course').modal('show');
			document.getElementById("edit_footer").innerHTML ='<a href="#" class="btn btn-danger" onclick="load_edit_programme_course('+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 programme end




});

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


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

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

					  swal("Programme Course Deleted");
					  links();


				}else{
					swal(response);
				}


			});
 }


 function load_edit_programme_course(token){


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

			document.getElementById("edit_form_programme_course").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_prog_course.php',{token:token},
			function(response,status){

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

			});
}

</script>
