<link rel="stylesheet" href="https://cdn.datatables.net/1.10.16/css/dataTables.bootstrap.min.css" />
<script src="https://cdn.datatables.net/1.10.16/js/jquery.dataTables.min.js"></script>
<section role="main" class="content-body">
					<header class="page-header">
						<h2>Manage Stores</h2>
						<div class="right-wrapper pull-right">
							<ol class="breadcrumbs">
								<li>
									<a href="<?php echo base_url();?>admin">
										<i class="fa fa-home"></i>
									</a>
								</li>
								<li><span>Manage Stores</span></li>
							</ol>
						</div>
					</header>

					<div class="row">
						<div class="col-md-4"> <?php if($this->session->flashdata("msg")){echo $this->session->flashdata("msg"); }?>
							<section class="panel panel-featured">
								<div class="panel-heading">Add/Edit Events</div>
								<div class="panel-body">
      
      <?php if($this->uri->segment(3)){?>
      	<form  action="<?php echo base_url();?>admin/update_event" method="post" enctype="multipart/form-data">
          <input type="hidden" name="id_event" value="<?php echo $edit->id_event;?>" />
          <div class="form-group ">
            <label for="email">Event Title</label>
            <input type="text" required class="form-control" name="name"  value="<?php echo $edit->name;?>">
          </div>
           <?php if($this->session->userdata("type")=="vendor"){?>
            <input type="hidden" name="user_id" value="<?php echo $this->session->userdata("userid");?>" />
            <?php }else{?>
            <div class="form-group">
            	<label>Select Vendor</label>
                <select class="form-control" name="user_id">
				<option value="">Select Vendor</option>
				<?php $v=$this->db->get_where("vendors")->result();
				foreach($v as $v){?>
                <option value="<?php echo $v->vid;?>" <?php if($edit->vid==$v->vid){echo "selected";}?>><?php echo $v->vb_name.' - '.$v->v_name;?></option>
                <?php }?>
                </select>
            </div>
            <?php }?>
            <div class="form-group">
            <label for="email">Contact Phone</label>
            <input type="text" required value="<?php echo $edit->tel;?>" class="form-control" name="tel">
          </div>
          <div class="form-group">
            <label for="email">Short Description</label>
            <textarea class="form-control" rows="3" name="description"><?php echo $edit->description;?></textarea>
          </div>
          <div class="form-group">
            <label for="email">Address</label>
            <textarea class="form-control" rows="3" name="address"><?php echo $edit->address;?></textarea>
          </div>
          <div class="row">
          <div class="form-group col-md-6">
            <label for="email">Latitude</label>
            <input type="text" required class="form-control" name="lat" value="<?php echo $edit->lat;?>">
          </div>
          <div class="form-group col-md-6">
            <label for="email">Longitude</label>
            <input type="text" required class="form-control" name="lng" value="<?php echo $edit->lng;?>">
          </div>
          <div class="form-group col-md-12">
            <label>Store Image</label>
            <input type="file"  class="form-control" name="img"/>
            <input type="hidden" name="oldimg"  value="<?php echo $edit->images;?>" />
            <img class="img img-responsive" src="<?php echo base_url();?>assets/images/<?php echo $edit->images;?>" />
          </div>
          </div><br/>
          <button type="submit" class="btn btn-success" name="submit">Update Event</button>
        </form>
      <?php }else{?>
      	<form action="<?php echo base_url();?>admin/add_event" method="post" enctype="multipart/form-data">
          <div class="form-group ">
            <label for="email">Event Title</label>
            <input type="text" required class="form-control" name="name">
          </div>
           <?php if($this->session->userdata("type")=="vendor"){?>
            <input type="hidden" name="user_id" value="<?php echo $this->session->userdata("userid");?>" />
            <?php }else{?>
            <div class="form-group">
            	<label>Select Vendor</label>
                <select class="form-control" name="user_id">
				<option value="">Select Vendor</option>
				<?php $v=$this->db->get_where("vendors")->result();
				foreach($v as $v){?>
                <option value="<?php echo $v->vid;?>"><?php echo $v->vb_name.' - '.$v->v_name;?></option>
                <?php }?>
                </select>
            </div>
            <?php }?>
            
          <div class="form-group">
            <label for="email">Contact Phone</label>
            <input type="text" required class="form-control" name="tel">
          </div>
          <div class="form-group">
            <label for="email">Short Description</label>
            <textarea class="form-control" rows="3" name="description"></textarea>
          </div>
          <div class="form-group">
            <label for="email">Address</label>
            <textarea class="form-control" rows="3" name="address"></textarea>
          </div>
          <div class="row">
          <div class="form-group col-md-6">
            <label for="email">Latitude</label>
            <input type="text" required class="form-control" name="lat">
          </div>
          <div class="form-group col-md-6">
            <label for="email">Longitude</label>
            <input type="text" required class="form-control" name="lng">
          </div>
          <div class="form-group col-md-12">
            <label>Event Image</label>
            <input type="file"  class="form-control" name="img"/>
          </div>
          </div><br/>
          <button type="submit" class="btn btn-success" name="submit">Create Event</button>
        </form>
        <?php }?>
      </div>
							</section>
						</div>
                        <div class="col-md-8">
							<div class="panel panel-featured">	
								<div class="panel-heading">Listing All Events</div>
								
     							<div class="panel-body">
                     <table class="table table-striped table-responsive table-bordered dataTable" id="example">
        	<thead><tr><th>S.No.</th><th>Image</th><th>EventName</th><th>Contacts/Address</th><th>Action</th></tr></thead>
            <tbody>
            	<?php $i=1;foreach($events as $cat){?>
                <tr><td><?php echo $i;?></td>
                <td width="100px"><img src="<?php echo base_url();?>assets/images/<?php echo $cat->images;?>" class="img img-responsive"></td>
                <td><h5 class="text-success"><b><?php echo $cat->name;?></b></h5>
				<label class="label label-info"><?php echo $cat->vb_name;?></label></td>
                 <td>
         <i class="fa fa-phone"></i> <?php echo $cat->tel;?><br/><i class="fa fa-map-marker"></i> <?php echo $cat->address;?></td>
                <td>
   <a href="<?php echo base_url();?>admin/events/<?php echo $cat->id_event;?>" class="btn btn-xs btn-warning"><i class="fa fa-edit"></i></a>
   <a href="<?php echo $cat->id_event;?>" class="btn btn-xs btn-danger catdelete"><i class="fa fa-trash-o"></i></a></td>
                <?php $i++;}?></tr>
            </tbody>
        </table>
        </div>
        						</div>
							</div>
						</div>
						
				</section>
			</div>

			
		</section>

		<!-- Vendor -->
        <script>
	$(document).ready(function(){ 
	$("#state").change(function(){
			var state=$(this).val();
			$.ajax({
				 type: "POST",
				 url: '<?php echo base_url();?>admin/ajax_city',
				 data: {state:state},
				 success: function(response){
					 //alert(response);
					 $("#city").html(response);
				 }
				 });
		});
	$('#example').DataTable({ "lengthChange": false,"dom": '<"pull-left"f><"pull-right"l>tip'});
		$(".enable").click(function(e){e.preventDefault();
			var st=$(this).text();
			var id=$(this).attr("href");
			if(st=="Enable"){
			$(this).text("Disable");
			}else{
			$(this).text("Enable");	
			}
			$.ajax({
							 type: "POST",
							 url: '<?php echo base_url();?>admin/store_enable',
							 data: {id:id,st:st},
							 success: function(response){
								 //alert(response);
							 }
							 });
		});
		$(".catdelete").click(function(e){e.preventDefault();
		if (!confirm("Sure you want to delete?")){
				  return false;
				}
			var id=$(this).attr("href");$(this).closest("tr").remove();
			$.ajax({
							 type: "POST",
							 url: '<?php echo base_url();?>admin/vendordelete',
							 data: {id:id},
							 success: function(response){
								 //alert(response);
							 }
							 });
		});
	});
</script>
		<script src="<?php echo base_url();?>admin_assets/vendor/jquery-browser-mobile/jquery.browser.mobile.js"></script>
		<script src="<?php echo base_url();?>admin_assets/vendor/bootstrap/js/bootstrap.js"></script>
		<script src="<?php echo base_url();?>admin_assets/vendor/nanoscroller/nanoscroller.js"></script>
		<script src="<?php echo base_url();?>admin_assets/vendor/jquery-placeholder/jquery.placeholder.js"></script>
		
		<!-- Theme Base, Components and Settings -->
		<script src="<?php echo base_url();?>admin_assets/javascripts/theme.js"></script>
		
		<!-- Theme Custom -->
		<script src="<?php echo base_url();?>admin_assets/javascripts/theme.custom.js"></script>
		
		<!-- Theme Initialization Files -->
		<script src="<?php echo base_url();?>admin_assets/javascripts/theme.init.js"></script>

	</body>
</html>