<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 Vendors</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 Vendors</span></li>
							</ol>
						</div>
					</header>

					<div class="row">
						<div class="col-md-4" style="display:none;"> <?php if($this->session->flashdata("msg")){echo $this->session->flashdata("msg"); }?>
							<section class="panel panel-featured">
								<div class="panel-heading">Add New Vendors</div>
								<div class="panel-body">
      
      <?php if($this->uri->segment(3)){?>
      	<form  action="<?php echo base_url();?>admin/add_vendor/<?php echo $this->uri->segment(3);?>" method="post" enctype="multipart/form-data">
       	  <div class="form-group ">
            <label for="email">Business Name/Title</label>
            <input type="text" required class="form-control" name="bname"  value="<?php echo $vendor->vb_name;?>">
          </div>
          <div class="form-group ">
            <label for="email">Vendor Name</label>
            <input type="text" required class="form-control" value="<?php echo $vendor->v_name;?>" name="name">
          </div>
         
          <div class="form-group ">
            <label for="email">Email</label>
            <input type="text"  class="form-control" name="email" value="<?php echo $vendor->v_email;?>">
          </div>
          <div class="form-group ">
            <label for="email">Phone</label>
            <input type="text"  class="form-control" name="phone" value="<?php echo $vendor->v_phone;?>">
          </div>
          <div class="form-group ">
            <label for="email">Address</label>
            <textarea class="form-control" rows="3" name="address"><?php echo $vendor->v_address;?></textarea>
          </div>
          <div class="row">
          <div class="form-group  col-md-6">
            <label for="email">City</label>
            <input type="text"  class="form-control" name="city"  value="<?php echo $vendor->vcity;?>">
          </div>
          <div class="form-group col-md-6">
            <label for="email">State</label>
            <input type="text"  class="form-control" name="state"  value="<?php echo $vendor->vstate;?>">
          </div>
          <div class="form-group col-md-6">
            <label for="email">Pincode</label>
            <input type="text"  class="form-control" name="pincode"  value="<?php echo $vendor->vpincode;?>">
          </div>
          </div>
          <div class="form-group ">
            <label for="email">Vendor Logo</label>
          	<input type="hidden" value="<?php echo $vendor->v_logo;?>" name="oldimg">
            <input type="file"  class="form-control" name="img"/>
            <img width="200px" src="<?php echo base_url();?>assets/images/<?php echo $vendor->v_logo;?>" class="img img-responsive">
          </div><br/>
          <button type="submit" class="btn btn-success" name="submit">Update</button>
        </form>
      <?php }else{?>
      	<form  action="<?php echo base_url();?>admin/add_vendor" method="post" enctype="multipart/form-data">
          <div class="form-group ">
            <label for="email">Business Name/Title</label>
            <input type="text" required class="form-control" name="bname">
          </div>
          <div class="form-group ">
            <label for="email">Vendor Name</label>
            <input type="text" required class="form-control" name="name">
          </div>
          <div class="form-group ">
            <label for="email">Email</label>
            <input type="text"  class="form-control" name="email">
          </div>
          <div class="form-group ">
            <label for="email">Password</label>
            <input type="password"  class="form-control" name="password">
          </div>
          <div class="form-group ">
            <label for="email">Phone</label>
            <input type="text"  class="form-control" name="phone">
          </div>
          <div class="form-group">
            <label for="email">Address</label>
            <textarea class="form-control" rows="2" name="address"></textarea>
          </div>
          <div class="row">
          <div class="form-group  col-md-6">
            <label for="email">City</label>
            <input type="text"  class="form-control" name="city">
          </div>
          <div class="form-group col-md-6">
            <label for="email">State</label>
            <input type="text"  class="form-control" name="state">
          </div>
          <div class="form-group col-md-5">
            <label for="email">Pincode</label>
            <input type="text"  class="form-control" name="pincode">
          </div>
          <div class="form-group col-md-7">
            <label for="email">Vendor Logo</label>
          	<input type="file" name="img" class="form-control"/>
          </div>
          </div><br/>
          <button type="submit" class="btn btn-success" name="submit">Add Vendor</button>
        </form>
        <?php }?>
      </div>
							</section>
						</div>
                        <div class="col-md-12">
							<div class="panel panel-featured">	
								<div class="panel-heading">Listing All Vendors</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>BusinessName</th><th>Contact Person</th><th>Contact Details</th><th>Action</th></tr></thead>
            <tbody>
            	<?php $i=1;foreach($vendors as $cat){
					$state_name="";
					$city_name="";
					if($cat->vstate!=0){
					$st=$this->db->get_where("states",array("state_id"=>$cat->vstate))->row();$state_name=$st->state_name;
					}if($cat->vcity!=0){
					$st=$this->db->get_where("cities",array("city_id"=>$cat->vcity))->row();$city_name=$st->city_name;
					}
					?>
                <tr><td><?php echo $i;?></td>
                <td width="100px"><img src="<?php echo base_url();?>assets/images/<?php echo $cat->v_logo;?>" class="img img-responsive"></td>
                <td><h5 class="text-success"><b><?php echo $cat->vb_name;?></b></h5></td><td><?php echo $cat->v_name;?></td>
                 <td><i class="fa fa-envelope"></i> <?php echo $cat->v_email;?><br/>
                 	 <i class="fa fa-phone"></i> <?php echo $cat->v_phone;?><br/>
                     <i class="fa fa-map-marker"></i> <?php echo $cat->v_address.' '.$city_name.' '.$state_name.' '.$cat->vpincode;?></td>
                <td>
                <?php if($cat->v_status==""){$st="Disable";$btn="success";}else{$st="Enable";$btn="warning";}?>
   <a href="<?php echo $cat->vid;?>" title="<?php echo $cat->v_phone;?>" class="btn btn-xs btn-<?php echo $btn;?> enable"><?php echo $st;?></a>
   <!--<a href="<?php echo base_url();?>admin/vendors/<?php echo $cat->vid;?>" class="btn btn-xs btn-warning"><i class="fa fa-edit"></i></a>-->
   <a href="<?php echo $cat->vid;?>" id="<?php echo $cat->v_logo;?>" 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(){ $('#example').DataTable({ "lengthChange": false,"dom": '<"pull-left"f><"pull-right"l>tip'});
		$(".enable").click(function(e){e.preventDefault();
			var st=$(this).text();
			var ph=$(this).attr("title");
			var id=$(this).attr("href");
			if(st=="Enable"){
			$(this).text("Disable");
			}else{
			$(this).text("Enable");	
			}
			$.ajax({
				 type: "POST",
				 url: '<?php echo base_url();?>admin/vendorenable',
				 data: {id:id,st:st,ph:ph},
				 success: function(response){
					 //alert(response);
				 }
				 });
			//$.ajax({
//				 type: "GET",
//				 url: 'http://offera.in/frontent/home/vendorenable',
//				 data: {ph:ph,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>