<?php include 'header1f.php';?>
<?php
	require_once("perpage.php");	
	require_once("dbcontroller.php");
	$db_handle = new DBController();
	
	$datepicker = "";
	$datepicker1 = "";
	$location = "";
	$billing_GST_no = "";
	$state = "";
	$city = "";
	$company_name="";
	
	$queryCondition = "";
	if(!empty($_POST["search"])) {
		foreach($_POST["search"] as $k=>$v){
			if(!empty($v)) {

$queryCases = array("datepicker","datepicker1","location","billing_GST_no","company_name");
				if(in_array($k,$queryCases)) {
					if(!empty($queryCondition)) {
						$queryCondition .= " AND ";
						
					} else {
						$queryCondition .= " WHERE ";
					}
				}
				switch($k) {
						case "datepicker":
						$datepicker = $v;
						$queryCondition .= "dpinv_date BETWEEN";
						case "datepicker1":
						$datepicker1 = $v;
						$queryCondition .= "'" . $v . "'";
						break;
						
						case "location":
						$location = $v;
						$queryCondition .= "location LIKE '%" . $v . "%'";
						break;
						case "company_name":
						$company_name = $v;
						$queryCondition .= "company_name LIKE '%" . $v . "%'";
						break;
						
						case "billing_GST_no":
						$billing_GST_no = $v;
						$queryCondition .= "billing_GST_no LIKE '%" . $v . "%'";
						break;
						
						
						
						
				}
			}
		}
	}
	if(!empty($queryCondition)) {
	
	$orderby = " ORDER BY eventID"; 
	$sql = "SELECT * FROM  event_master" . $queryCondition ." " ;
	}else{
	 $sql= "SELECT * FROM  event_master";
	}
	//echo $sql ;
	$href = 'view_all_event.php';					
	
	$perPage = 5000; 
	$page = 1;
	if(isset($_POST['page'])){
		$page = $_POST['page'];
	}
	$start = ($page-1)*$perPage;
	if($start < 0) $start = 0;
		
	$query =  $sql . $orderby .  " limit " . $start . "," . $perPage; 
	$result = $db_handle->runQuery($query);
	
	if(empty($result)) {
		
	$result["perpage"] = showperpage($sql, $perPage, $href);
	}
	else{ 
	$result["perpage"] = showperpage($sql, $perPage, $href); }
	
?>
  <div class="content-page">
    <div class="content">
      <div class="container">
        <div class="row">
          <div class="col-sm-12">
            <div class="page-header-title">
           <button type="button" class="btn btn-dark  waves-effect waves-light" onclick="location.href='index.php'">BACK </button>
			<button type="button" class="btn btn-primary  waves-effect waves-light" onclick="location.href='event_master.php'">ADD EVENT</button>
             
             
              <div class="clearfix"></div>
            </div>
          </div>
        </div>
      
        
        <div class="row">  
          <div class="col-md-12">
            <div class="panel panel-primary">
              <div class="panel-heading">
                <h3 class="panel-title">View all Event</h3>
              </div>
              <div class="panel-body">
                <table  id="datatable-buttons" class="table table-striped table-bordered">
                  <thead>
                    <tr>
                      				<th>Sr No.</th>
									<th>Event Name</th>
									<th>Date</th>
									<th>Place</th>
									<th>Coupon</th>
<th>Coupon Discount </th>
<th>URL QR Code </th>
<th>Status</th>
                    </tr>
                  </thead>
                  <tbody>
				  <?php
				 foreach($result as $k=>$v) {
						if(is_numeric($k)) {
						
					
		
$filename = $result[$k]["QR_code"];
						
												 					
													?>
                    <tr>
                      <td><?php echo $k+1?></a></td>
                      <td><?php echo $result[$k]["event_name"]?></a></td>
                      <td><?php  echo $result[$k]["Edate"]; ?></td>
                      <td><?php  echo $result[$k]["Eplace"]; ?></td>
					  <td><?php  echo $result[$k]["coupon_name"]; ?></td>
<td><?php  echo $result[$k]["coupon_discount"]; ?></td>
<td><img src="<?php echo $filename?>" width="150" /></td>
<td><?php if($result[$k]["status"]=='1'){?>
<button type="button" class="btn btn-success btn-xs waves-effect waves-light" onclick="location.href='status04.php?status=0&&eventID=<?php echo $result[$k]["eventID"]?>'" style="float:right; margin-right:10px;">Active</button>				
				
<?php } else { ?>
<button type="button" class="btn btn-danger btn-xs waves-effect waves-light" onclick="location.href='status04.php?status=1&&eventID=<?php echo $result[$k]["eventID"]?>'" style="float:right; margin-right:10px;">Inactive</button>	
<?php } ?></td>
                    </tr>
                    <?php }}?>
                  </tbody>
                </table>
              </div>
            </div>
          </div>
        </div>
        
      </div>
    </div>
	<?php include 'footer1a.php';?>