<?php 
		include("connection/conn.php");
		if($_SESSION['adminuser']==''){
			header("location:index.php");
			exit();
		}
		
		
		  if(isset($_POST['searchenq'])){
		    $centername=$_POST['centername'];
			$dating=$_POST['startdate'];
			$explode=explode("-",$dating);
			$month=$explode[0];
			$day=$explode[1];
			$year=$explode[2];
			$dat=$year.'-'.$month.'-'.$day;
			if($dat=="YYYY-MM-DD"){
				$dat="";
			}
			$dating1=$_POST['enddate'];
			$explode1=explode("-",$dating1);
			$month1=$explode1[0];
			$day1=$explode1[1];
			$year1=$explode1[2];
			$dat1=$year1.'-'.$month1.'-'.$day1;
			if($dat1=="YYYY-MM-DD"){
				$dat1="";
			}
		}
		if($_GET['dat']!="" || $_GET['dat1']!=""){ 
		      $centername=$_GET['centername'];
			  $dat=$_GET['dat'];
			  $dat1=$_GET['dat1'];
		}
		$adjacents = 3;
		$select_1="select * from online_center_apply where ";
		if($centername!=""){
		$select_1.="institute_name like '%".$centername."%' AND ";
		}
		if($dat!="" && $dat1!=""){
		$select_1.="date BETWEEN '".$dat."%' AND '".$dat1."%' AND ";
		}
		$select_1.="apply_id!=''  order by apply_id desc";
		$query_1=mysqli_query($link,$select_1);
		$total_pages=mysqli_num_rows($query_1);
		$path="dat=$dat&dat1=$dat1&centername=$centername";
		$targetpage="manage-franchise.php"; 	   
		$limit=300; 								
		$page=$_GET['page'];
		if($page){
			$start=($page - 1) * $limit; 
		}		
		else{
			$start=0;		
		}
		$sql="select * from online_center_apply where ";
		if($centername!=""){
		$sql.="institute_name like '%".$centername."%' AND ";
		}
		if($dat!="" && $dat1!=""){
		$sql.="date BETWEEN '".$dat."%' AND '".$dat1."%' AND ";
		}
		$sql.="apply_id!='' order by apply_id desc LIMIT $start, $limit";
		$result=mysqli_query($link,$sql);
		$count=mysqli_num_rows($result);
		if($page==0) 
		$page=1;					              
		$prev=$page-1;							
		$next=$page+1;							
		$lastpage=ceil($total_pages/$limit);		
		$lpm1=$lastpage-1;		
	// Export Data In CSV Format	
	if(isset($_POST['export'])){
		$startdates=$_POST['startdates'];
		$enddates=$_POST['enddates'];
		if($startdates!="" && $enddates!=""){
			$select_res="select * from online_center_apply where date BETWEEN '".$startdates."%' AND '".$enddates."%' order by apply_id desc";
			$rsSearchResults=mysqli_query($link,$select_res);
		}
		else{
			$select_res_def="select * from online_center_apply order by apply_id desc";
			$rsSearchResults=mysqli_query($link,$select_res_def);
		}
		$out = '';
		//$fields =mysqli_list_fields('skilledu_skillseducationdblist','online_center_apply');
		//$columns = mysqli_num_fields($fields);
		// Put the name of all fields
		
		for ($i = 0; $i < 1; $i++){
		//$l=mysqli_field_name($fields, $i);
		$out .= '"Institute Name","Director Name","Email","Phone","Mobile","City","Enquiry Date",';
		}
		$out .="\n";
		// Add all values in the table
		while ($l = mysqli_fetch_array($rsSearchResults)){
		for ($i = 0; $i < 1; $i++){
		$out .='","'.$l['institute_name'].'","'.$l['director'].'","'.$l['email'].'","'.$l['phone'].'","'.$l['mobile'].'","'.$l['state'].'","'.$l['date'].'",';
		}
		$out .="\n";
		}
		// Output to browser with appropriate mime type, you choose
		header("Content-type: text/x-csv");
		header("Content-Disposition: attachment; filename=CenterReportList.csv");
		echo $out;
		exit;
	}
		
		
	
?>
<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8" />
		<meta name="viewport" content="width=device-width, initial-scale=1.0" />
		<title>Administrator | Manage Franchise</title>
		<link href="css/bootstrap.css" rel="stylesheet" />
		<link href="css/style.css" rel="stylesheet" />
		<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
		<link href='http://fonts.googleapis.com/css?family=Open+Sans' rel='stylesheet' type='text/css' />
	</head>
	
	<body>
		<div id="wrapper">
			<?php
				include("top-header.php");
				include("right-sec.php");
			?>
			<div id="page-wrapper" >
				<div id="page-inner">
					<div class="row">
						<div class="col-md-12">
							<h3 class="page-header">
								Manage Franchise Section<small></small>
							</h3>
							
							<div class="table-sec">
					<form name="frm" action="" method="post">
								<table>
								 <tr>
		<td colspan="7" width="800">
			<table width="800" >
                <tr>
                  <td class="tabular h2" align="center" style="color:#000000; font-size:14px;">Center Name</td>
                  <td><input name="centername" type="text" style="width:150px;" id="centername" /></td>
                  <td class="tabular h2" align="center" style="color:#000000; font-size:14px;">From Date</td>
                  <td><input name="startdate" type="text" class="dropdownin" style="width:70%;" id="startdate" onfocus="showCalendarControl(this);" readonly="readonly" value="<?php if($dating!=""){echo $dating;}else {echo "MM-DD-YYYY";}?>"/></td>
                  <td class="tabular h2" align="center" style="color:#000000; font-size:14px;">To Date</td>
                  <td> <input name="enddate" type="text" class="dropdownin" style="width:70%;" id="enddate" onfocus="showCalendarControl(this);" readonly="readonly" value="<?php echo date('m-d-Y');?>"/></td>
                  <td class="tabular h2" align="center">
                      <input name="searchenq" type="submit" class="submit" id="searchenq" value="Search" style="font-size:14px;" />
                      <input type="submit" name="export" value="+ Generate Report" class="submit" style="width:170px; font-size:14px;" />
                      
                      </td>
                </tr>
			</table>
		</td>
	</tr>
									<tr>
										<th>Id</th>
										<th>Center Name</th>
										<th>Director</th>
										<th>Mobile</th>
										<th>Email ID</th>
										<th>City</th>
										<th>State</th>
										<th>Date</th>			
										<th>Status</a></th>
									</tr>
									<?php
									  $i=1;
									  while($find=mysqli_fetch_array($result)){
										$color = (($i%2) == 0)?"#e7f3ff":"#FFFFFF";
										
								?>
									<tr>
										<td><?php echo $i;?></td>
										
										<td><?php echo $find['institute_name'];?></td>
											<td> <?php echo $find['institute_name'];?></td>
										<td><?php echo $find['mobile'];?></td>
										<td><?php echo $find['email'];?></td>
									
										<td> <?php echo $find['city'];?></td>
										<td> <?php echo $find['state'];?></td>
										
										<td> <?php echo $find['date'];?></td>
										<td>
											<ul class="table-ul">
												
												
												
												<li><a href="delete-franchise.php?id=<?php echo $find['cid'];?>" onclick="return confirm('are you sure delete this?');"><i class="delete fa fa-trash"></i></a></li>
											</ul>
										</td>
									</tr>
									  <?php $i++; } ?>
									
								</table>
							</div>
						</div>
					</div> 
				</div>
			</div>
			<footer class="footer-sec">
				<div class="container">
					<div class="row">
						<div class="col-md-12">
							<p class="text-center">All right reserved. Template Design by: <a href="">Anshul Chittouria</a></p>
						</div>
					</div>
				</div>
			</footer>
		</div>
		
		
		<!-- jQuery Js -->
		<script src="js/jquery-1.10.2.js"></script>
		<script src="js/bootstrap.min.js"></script>
		<script src="js/jquery.metisMenu.js"></script>
		<script src="js/custom-scripts.js"></script>
	</body>
</html>
