<!--<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.8.0/css/bootstrap-datepicker.css" />	
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.8.0/js/bootstrap-datepicker.js"></script>-->
<section role="main" class="content-body">
					<header class="page-header">
						<h2>Manage Auctions</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 Auctions</span></li>
							</ol>
					
						</div>
					</header>
						<section class="panel">
							<header class="panel-heading">
				<h2 class="panel-title">List of <b class="text-danger"><?php echo strtoupper($this->uri->segment(3));?></b> Auctions</h2>
							</header>
							<div class="panel-body">
                            <form class="form-inline" action="" method="get">
                              <div class="form-group">
                                <label for="email">Date : </label>
                <input type="text" name="date" value="" required class="form-control date" placeholder="Select A Date">
                              </div>
                              <button type="submit" class="btn btn-primary">Filter</button>
                            </form>
								<table class="table table-bordered table-striped mb-none" data-swf-path="assets/vendor/jquery-datatables/extras/TableTools/swf/copy_csv_xls_pdf.swf">
        									<thead>
												<tr>
													<th>S.No.</th>
													<th>Title</th>
													<th>Total Bids Placed</th>
													<th>Action</th>
												</tr>
											</thead>
											<tbody>
                                            <?php  $i=1;foreach($auctions as $myad){?>
                                            <tr data-category="active">
												<td data-title=""><?php echo $i;?></td>
      
                                                <td data-title="Title"><h4><?php echo $myad->title;?></h4>
                                                <h5>Max Auction Price : <?php echo $myad->max_price.'<br/>Min Auction Price : '.$myad->min_price;?></h5></td>
                                                <?php if($this->uri->segment(3)=="live"){?>
               <td>Total Bids <b id="prebid<?php echo $myad->apid;?>"><?php echo $this->db->get_where("auctions",array("auc_dayid"=>$myad->apid))->num_rows();?></b></td>
              <script>
				  $(document).ready(function(){
					setInterval(function(){
						 var prebid=parseInt($("#prebid<?php echo $myad->apid;?>").text());
						 var sec=parseInt($("#time<?php echo $myad->apid;?>").text());
						 sec--;
						 $("#time<?php echo $myad->apid;?>").text(sec); 
						 if(sec==20){
							 //alert(sec);
							$.ajax({
							 type: "POST",
							 url: '<?php echo base_url();?>admin/robot_bid',
							  data: {apid:"<?php echo $myad->apid;?>",pid:"<?php echo $myad->pid;?>"},
							 success: function(res){
								$("#prebid<?php echo $myad->apid;?>").text(prebid+1);
								$("#time<?php echo $myad->apid;?>").text("<?php echo $myad->duration;?>"); 
								 }
							 });
						 }
						 if(sec>20){
						 $.ajax({
						 type: "POST",
						 url: '<?php echo base_url();?>admin/check_bids',
						 data: {apid:"<?php echo $myad->apid;?>",prebid:prebid,sec:sec},
						 success: function(res){$("#prebid<?php echo $myad->apid;?>").text(res);
								 if(parseInt(res)>prebid){
								 $("#time<?php echo $myad->apid;?>").text("<?php echo $myad->duration;?>"); 
								 }
							 }
						 });}
					 }, 1000);
				   });
			</script>
                                                <?php }if($this->uri->segment(3)=="closed"){?>
                                                <td><?php echo $myad->username;?></td>
                                                <?php }?>
                                                <td>
                     <h3><b id="time<?php echo $myad->apid;?>"><?php echo $myad->duration;?></b> <small>Seconds</small></h3>
                                                <a href="#" title="<?php echo $myad->title;?>" id="<?php echo $myad->apid;?>" class="btn btn-success btn-xs viewlive" data-toggle="modal" data-target="#myModal">View All Bids</a></td>
                            				</tr>
                  
                                            <?php $i++;}?>
                                            </tbody>
        						</table>
							</div>
						</section>
				</section>
                <div id="myModal" class="modal fade" role="dialog">
                  <div class="modal-dialog modal-sm">
                    <!-- Modal content-->
                    <div class="modal-content">
                      <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal">&times;</button>
                        <h4 class="modal-title">Auction Fields</h4>
                      </div>
                      <div class="modal-body">
                        
                      </div>
                    </div>
                  </div>
                </div>
			  </div>

			
		</section>

		<!-- Vendor -->
        <script>
	$(document).ready(function(){
		$('.date').datepicker({ format: 'yyyy-mm-dd', autoclose: true,});
		$(".viewlive").click(function(){
			var apid=$(this).attr("id");
			$.ajax({
				 type: "POST",
				 url: '<?php echo base_url();?>admin/view_live_bid',
				 data: {apid:apid},
				 success: function(response){
					 //alert(response);
					 $(".modal-body").html(response);
				 }
				 });
		});
		
		$(".auction").click(function(){
			var pid=$(this).attr("id");
			var title=$(this).attr("title");
			$(".modal-title").text(title);
			$.ajax({
							 type: "POST",
							 url: '<?php echo base_url();?>admin/set_auction',
							 data: {pid:pid},
							 success: function(response){
								 //alert(response);
								 $(".modal-body").html(response);
							 }
							 });
		});
		$(".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/proenable',
							 data: {id:id,st:st},
							 success: function(response){
								 //alert(response);
							 }
							 });
		});
		
		$(".in_feat").click(function(){
							var id=$(this).val();
							var v="";
							if ($(this).is(':checked')) {
								var v='yes';
							}
							//alert(v);
							$.ajax({
							 type: "POST",
							 url: '<?php echo base_url();?>admin/in_feat',
							 data: {v:v,id:id},
							 success: function(response){
								// alert(response);
							 }
							 });
						});
						$(".buy_now").click(function(){
							var id=$(this).val();
							var v="";
							if ($(this).is(':checked')) {
								var v='yes';
							}
							//alert(v);
							$.ajax({
							 type: "POST",
							 url: '<?php echo base_url();?>admin/buy_now',
							 data: {v:v,id:id},
							 success: function(response){
								// alert(response);
							 }
							 });
						});
		$(".pro_delete").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/pro_delete',
							 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/bootstrap-datepicker/js/bootstrap-datepicker.js"></script>
		<script src="<?php echo base_url();?>admin_assets/vendor/magnific-popup/magnific-popup.js"></script>
		<script src="<?php echo base_url();?>admin_assets/vendor/jquery-placeholder/jquery.placeholder.js"></script>
		
		<!-- Specific Page Vendor -->
		<script src="<?php echo base_url();?>admin_assets/vendor/select2/select2.js"></script>
		<script src="<?php echo base_url();?>admin_assets/vendor/jquery-datatables/media/js/jquery.dataTables.js"></script>
		<script src="<?php echo base_url();?>admin_assets/vendor/jquery-datatables/extras/TableTools/js/dataTables.tableTools.min.js"></script>
		<script src="<?php echo base_url();?>admin_assets/vendor/jquery-datatables-bs3/assets/js/datatables.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>


		<!-- Examples -->
		<script src="<?php echo base_url();?>admin_assets/javascripts/tables/examples.datatables.default.js"></script>
		<script src="<?php echo base_url();?>admin_assets/javascripts/tables/examples.datatables.row.with.details.js"></script>
		<script src="<?php echo base_url();?>admin_assets/javascripts/tables/examples.datatables.tabletools.js"></script>
</body>
</html>