<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 New Store</div>
								<div class="panel-body">
      
      <?php if($this->uri->segment(3)){?>
      	<form  action="<?php echo base_url();?>admin/update_store" method="post" enctype="multipart/form-data">
          <input type="hidden" name="store_id" value="<?php echo $edit->store_id;?>" />
          <div class="form-group ">
            <label for="email">Store Title</label>
            <input type="text" required class="form-control" name="store_name"  value="<?php echo $edit->store_name;?>">
          </div>
           <?php if($this->session->userdata("type")=="vendor"){?>
            <input type="hidden" name="vid" value="<?php echo $this->session->userdata("userid");?>" />
            <?php }else{?>
            <div class="form-group">
            	<label>Select Vendor</label>
                <select class="form-control" name="vid">
				<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>Select Store Category</label>
                <select class="form-control" name="store_cat">
				<option value="">Store Category</option>
				<?php $v=$this->db->get_where("store_category")->result();
				foreach($v as $v){?>
                <option value="<?php echo $v->st_catid;?>" <?php if($edit->store_cat==$v->st_catid){echo "selected";}?>><?php echo $v->st_cat_name;?></option>
                <?php }?>
                </select>
            </div>
          <div class="form-group">
            <label for="email">Store Phone</label>
            <input type="text" required class="form-control"  value="<?php echo $edit->st_phone;?>" name="st_phone">
          </div>
          <div class="form-group">
            <label for="email">Address</label>
            <textarea class="form-control" rows="2" name="st_address"><?php echo $edit->st_address;?></textarea>
          </div>
          <div class="form-group">
            <label for="email">State</label>
            <select class="form-control" name="st_state" id="state">
                <option value="">Select State</option>
                <?php $st=$this->db->get_where("states",array("country_id"=>101))->result();
                foreach($st as $st){?>
                <option value="<?php echo $st->state_id;?>" <?php if($st->state_id==$edit->st_state){echo "selected";}?>><?php echo $st->state_name;?></option>
                <?php }?>
            </select>
          </div>
          <div class="row">
          <div class="form-group  col-md-7">
            <label for="email">City</label>
            <select class="form-control" name="st_city" id="city">
             <?php $st=$this->db->get_where("cities",array("state_id"=>$edit->st_state))->result();
                foreach($st as $st){?>
                <option value="<?php echo $st->city_id;?>" <?php if($st->city_id==$edit->st_city){echo "selected";}?>><?php echo $st->city_name;?></option><?php }?>
            </select>
          </div>
          <div class="form-group col-md-5">
            <label for="email">Pincode</label>
            <input type="text"  class="form-control" name="st_pincode"  value="<?php echo $edit->st_pincode;?>">
          </div>
          </div>
          <div class="row">
          <div class="form-group col-md-6">
            <label for="email">GPS Co-Ordinates</label>
            <input type="text" required class="form-control" name="co_ord"  value="<?php echo $edit->co_ord;?>">
          </div>
          <div class="form-group col-md-6">
            <label>Store Image</label>
            <input type="file"  class="form-control" name="img"/>
            <input type="hidden" name="oldimg"  value="<?php echo $edit->st_image;?>" />
            <img class="img img-responsive" src="<?php echo base_url();?>assets/images/<?php echo $edit->st_image;?>" />
          </div>
          </div><br/>
          <button type="submit" class="btn btn-success" name="submit">Update Store</button>
        </form>
      <?php }else{?>
      	<form  action="<?php echo base_url();?>admin/add_store" method="post" enctype="multipart/form-data">
          <div class="form-group ">
            <label for="email">Store Title</label>
            <input type="text" required class="form-control" name="store_name">
          </div>
           <?php if($this->session->userdata("type")=="vendor"){?>
            <input type="hidden" name="vid" value="<?php echo $this->session->userdata("userid");?>" />
            <?php }else{?>
            <div class="form-group">
            	<label>Select Vendor</label>
                <select class="form-control" name="vid">
				<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>Select Store Category</label>
                <select class="form-control" name="store_cat">
				<option value="">Store Category</option>
				<?php $v=$this->db->get_where("store_category")->result();
				foreach($v as $v){?>
                <option value="<?php echo $v->st_catid;?>"><?php echo $v->st_cat_name;?></option>
                <?php }?>
                </select>
            </div>
          <div class="form-group">
            <label for="email">Store Phone</label>
            <input type="text" required class="form-control" name="st_phone">
          </div>
          <div class="form-group">
            <label for="email">Address</label>
            <textarea class="form-control" rows="2" name="st_address"></textarea>
          </div>
          <div class="form-group">
            <label for="email">State</label>
            <select class="form-control" name="st_state" id="state">
                                    	<option value="">Select State</option>
                                        <?php $st=$this->db->get_where("states",array("country_id"=>101))->result();
										foreach($st as $st){?>
                                        <option value="<?php echo $st->state_id;?>"><?php echo $st->state_name;?></option>
                                        <?php }?>
                                    </select>
          </div>
          <div class="row">
          <div class="form-group  col-md-7">
            <label for="email">City</label>
            <select class="form-control" name="st_city" id="city">
                                    	<option value="">Select City</option>
                                    </select>
          </div>
          <div class="form-group col-md-5">
            <label for="email">Pincode</label>
            <input type="text"  class="form-control" name="st_pincode">
          </div>
          </div>
          <div class="row">
          <div class="form-group col-md-6">
            <label for="email">GPS Co-Ordinates</label>
            <input type="text" required class="form-control" name="co_ord">
          </div>
          <div class="form-group col-md-6">
            <label>Store Image</label>
            <input type="file"  class="form-control" name="img"/>
          </div>
          </div><br/>
          <button type="submit" class="btn btn-success" name="submit">Add Store</button>
        </form>
        <?php }?>
      </div>
							</section>
						</div>
                        <div class="col-md-8">
							<div class="panel panel-featured">	
								<div class="panel-heading">Listing All Stores</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>StoreName</th><th>Contacts</th><th>Action</th></tr></thead>
            <tbody>
            	<?php $i=1;foreach($stores as $cat){?>
                <tr><td><?php echo $i;?></td>
                <td width="100px"><img src="<?php echo base_url();?>assets/images/<?php echo $cat->st_image;?>" class="img img-responsive"></td>
                <td><h5 class="text-success"><b><?php echo $cat->store_name;?></b></h5>
				<label class="label label-primary"><?php echo $cat->st_cat_name;?></label><br/>
				<label class="label label-info"><?php echo $cat->vb_name;?></label></td>
                 <td>
         <i class="fa fa-phone"></i> <?php echo $cat->st_phone;?><br/><i class="fa fa-map-marker"></i> <?php echo $cat->st_address.' '.$cat->city_name.' '.$cat->state_name.' '.$cat->st_pincode;?></td>
                <td>
                <?php if($cat->st_status==""){$st="Disable";}else{$st="Enable";}?>
   <a href="<?php echo $cat->store_id;?>" class="btn btn-xs btn-default enable"><?php echo $st;?></a>
   <a href="<?php echo base_url();?>admin/my_store/<?php echo $cat->store_id;?>" class="btn btn-xs btn-warning"><i class="fa fa-edit"></i></a>
   <a href="<?php echo $cat->store_id;?>" 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>