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

                                    <th> SCHOOL </th>

                                    <th > FACULTY </th>

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

									<?php




									$select="SELECT * FROM programmes WHERE programme_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_id=$row['programme_id'];
											$title=$row['title'];
											$code=$row['code'];
											$school_id=$row['school_id'];
											$faculty_id=$row['faculty_id'];
											$date_added=$row['date_added'];
											$programme_status=$row['programme_status'];
											if($programme_status=='0'){
														$status='Delete';
													}else if($programme_status=="1"){
														$status='Active';
													}else{
														$status='Suspend';
													}

											echo $tr = '<tr>
														<td><center>'.$sn.'</center></td>
														<td>'.$title.'</td>
														<td>'.$code.'</td>
														<td>'.get_school_by_id($con, $school_id).'</td>
														<td>'.get_faculty_by_id($con, $faculty_id).'</td>
														<td>'.$date_added.'</td>
														<td>'.$status.'</td>



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

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

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

				<div class="modal fade" id="edit_programme" 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</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 ?
                                </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 </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" >

		  <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">Code : (*)
				</label>
					<div class="col-sm-9">
						<input id="Code" name="code" type="text"
						placeholder="Code " class="form-control required" required />
					</div>
             </div>

          <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">Faculty *</label>
                                                <div class="col-sm-9">
                                                    <select class="form-control select21" id="school"
                                                            title="Select Faculty..." name="faculty_id">
                                                        <option disabled selected>Select Faculty</option>
														<?php
														echo get_all_faculty($con);
														?>

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

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

			 <div class="form-group row">
									<label class="col-sm-3 col-form-label text-right"> Required Subjects</label>
									<div class="col-sm-9">
									<textarea class="form-control" rows="2" name="required_subjects" id="optional_subjects"></textarea>
									</div>
							</div>

			 <div class="form-group row">
									<label class="col-sm-3 col-form-label text-right"> Optional Subjects</label>
									<div class="col-sm-9">
									<textarea class="form-control" rows="2" name="optional_subjects" id="optional_subjects"></textarea>
									</div>
							</div>

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

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

							<div class="form-group row">
				<label for="minimum_credit_load" class="col-sm-3 col-form-label text-right">Minimum Credit Load : (*)
				</label>
					<div class="col-sm-9">
						<input id="minimum_credit_load" name="minimum_credit_load" type="text"
						placeholder="Minimum Credit Load " class="form-control required" />
					</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 </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" >

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

			event.preventDefault(); //prevent default action
			var post_url = "hub/php/update_programme.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')[0].reset();
						swal("Programme 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',function(){
			var token=$(this).attr("id");
			$('#delete').modal('show');
			document.getElementById("delete_footer").innerHTML ='<a href="#" class="btn btn-danger" onclick="delete_programme('+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',function(){
			var token=$(this).attr("id");
			$('#edit_programme').modal('show');
			document.getElementById("edit_footer").innerHTML ='<a href="#" class="btn btn-danger" onclick="load_edit_programme('+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(token){
			//alert(token);
		 	$.post("hub/php/delete_programme.php",{token:token},
			function(response,status){

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

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


				}else{
					swal(response);
				}


			});
 }


 function load_edit_programme(token){


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

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

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

			});
}

</script>
