<div class="clearfix"></div>

	

  <div class="content-wrapper">

    <div class="container-fluid">

      <!-- Breadcrumb-->

     <div class="row pt-2 pb-2">

        <div class="col-sm-9">

		    <h4 class="page-title">Manage Cities</h4>

	   </div>

     

     </div>

    <!-- End Breadcrumb-->

      <div class="row">

			<div class="col-lg-4">

			   <?php if($this->session->flashdata("msg")){echo $this->session->flashdata("msg"); }?>

               <div class="card">

                    	  <div class="card-header">Add/Edit Cities</div>

                    <div class="card-body">

                          <?php if(isset($_GET['city_id'])){

						$edit=$this->db->get_where("cities",array("city_id"=>$_GET['city_id']))->row();?>

                        <form action="<?php echo base_url();?>admin/update_city" method="post" enctype="multipart/form-data">

                            <input type="hidden" name="city_id" value="<?php echo $edit->city_id;?>" />
							
                            <?php // $this->db->select("*");

									//$this->db->from("states");

									$this->db->order_by("state_name","asc");

									$branches=$this->db->get_where("states",array("country_id"=>101))->result();//print_r($branches);?>

                              <div class="form-group">

                                <label for="email">Select State</label>

                                <select class="form-control" name="state_id" required>

                                <option value="">Select State</option>

                                <?php foreach($branches as $st){?>

                                <option value="<?php echo $st->state_id;?>" <?php if($edit->city_state==$st->state_id){echo "selected";}?>><?php echo $st->state_name;?></option>

                                <?php }?>

                                </select>

                              </div>
                              <div class="form-group "> 

                              	<label>City Name</label>

                                <input type="text" required class="form-control" value="<?php echo $edit->city_name;?>"  name="city_name">

                              </div>

                              <button type="submit" class="btn btn-success">Update</button>

                            </form>

                        <?php }else{?>

                        <form action="<?php echo base_url();?>admin/add_city" method="post" enctype="multipart/form-data">
							 <?php // $this->db->select("*");

									//$this->db->from("states");

									$this->db->order_by("state_name","asc");

									$branches=$this->db->get_where("states",array("country_id"=>101))->result();//print_r($branches);?>

                              <div class="form-group">

                                <label for="email">Select State</label>

                                <select class="form-control" name="ag_state" required>

                                <option value="">Select State</option>

                                <?php foreach($branches as $st){?>

                                <option value="<?php echo $st->state_id;?>"><?php echo $st->state_name;?></option>

                                <?php }?>

                                </select>

                              </div>
                              <div class="form-group "> 

                              	<label>City Name</label>

                                <input type="text" required placeholder="City Name" class="form-control" name="city_name">

                              </div>

                              <button type="submit" class="btn btn-success">Add</button>

                            </form>

                        <?php }?>

                          

                    </div>

                    

               </div>                  

            </div>

            <div class="col-lg-8">

               <div class="card">

                    <div class="card-header">Listed Cities</div>

                    <div class="card-body">

                          <table class="table table-sm table-bordered">

                            <thead><tr><th>S.No.</th><th>City Name</th><th>State</th><th>Action</th></tr></thead>

                            <tbody>

                                <?php $i=1;foreach($cities as $dep){?>

                                <tr><td><?php echo $i;?></td>

                                    <td><?php echo $dep->city_name;?></td>
                                    <td><?php echo $dep->state_name;?></td>

                                    <td>

                                     
                                    <a href="<?php echo base_url().'admin/cities?city_id='.$dep->city_id;?>" class="btn btn-sm btn-warning"><i class="fa fa-edit"></i></a>

        <a href="#" id="<?php echo $dep->city_id;?>" class="btn btn-sm btn-danger city_delete"><i class="fa fa-trash-o"></i></a></td></tr><?php $i++;}?>

                            </tbody>

                        </table>

                    </div>

                    

               </div>                  

            </div>

            

        </div><!--End Row-->

	  

	  <!--End Row-->



    </div>

    <!-- End container-fluid-->

    

    </div><!--End content-wrapper-->

   <!--Start Back To Top Button-->

    <a href="javaScript:void();" class="back-to-top"><i class="fa fa-angle-double-up"></i> </a>

    <!--End Back To Top Button-->

	

	<!--Start footer-->

	<footer class="footer">

      <div class="container">

        <div class="text-center">

          Copyright © 2022
        </div>

      </div>

    </footer>

	<!--End footer-->

   

  </div><!--End wrapper-->





  <!-- Bootstrap core JavaScript-->

	<script>

	$(document).ready(function(){

		$(".city_delete").click(function(e){e.preventDefault();

				if(!confirm("Sure you want to delete?")){

					  return false;

				}

				var id=$(this).attr("id");$(this).closest("tr").remove();

				$.ajax({

					 type: "POST",

					 url: '<?php echo base_url();?>admin/ajax_city_delete',

					 data: {id:id},

					 success: function(response){

						 //alert(response);

					 }

				});

			});

		});

</script>

	<!-- simplebar js -->

  <script src="<?php echo base_url();?>adminassets/js/sidebar-menu.js"></script>

  <!-- Custom scripts -->

  <script src="<?php echo base_url();?>adminassets/js/app-script.js"></script>

  

  <!-- Vector map JavaScript -->

  <!-- Index js -->

  <script src="<?php echo base_url();?>adminassets/js/index.js"></script>



    

	

</body>

</html>

