<?php
$where 					= " WHERE 1=1 ";
$next_page_condition 	= "";
$paging ="";
if($_REQUEST['start']){
	$paging .="&start=".$_REQUEST['start'];
}
###########################################  STRAT FILTER CONITIONS    #####################################
$site_name 	= isset($_REQUEST['site_name']) ? $_REQUEST['site_name'] : "";
if($site_name) {
    $where	.= " AND site_name LIKE '%$site_name%' ";
    $next_page_condition.="&site_name=$site_name";
}
###########################################  	END  FILTER CONITIONS 	#####################################
###########################################  PAGING WITH PER PAGE  #####################################
$file_name		= "index"; // this is file name which is used during paging  , included at the bottom of the page
$table_name		= "sites";
$paging_table_name	= $table_name;
$paging_query		= $where;
$join_query_for_paging = "SELECT * FROM $table_name  $where ";
$page_header = "Sites";
include("paging/paging_query.inc.php");
############################################ END PAGING WITH PER PAGE  #######################################
$query = "SELECT * FROM $table_name $where ORDER BY site_name ASC LIMIT $eu, $limit";
$sql=mysqli_query($conn,$query);
$result=mysqli_num_rows($sql);

#################################   DELETE    #########################################
// when we click on delete this area of php code will execute
if(isset($_REQUEST['action']) && $_REQUEST['action']=='delete')
{
	$sql=mysqli_query($conn,"DELETE FROM $table_name WHERE id = '".$_REQUEST['id']."' ");
	$_SESSION['info_message'] = "Category deleted sucessfully";
	header("location: $file_name?page=view&message=sites deleted sucessfully".$next_page_condition.$paging);
}
#################################  END DELETE    #########################################
?>
<section class="content-header">
  <h1>
	<?=$page_header;?>
  </h1>
</section>
<section class="content">
	<div class="row">
		<div class="col-xs-12">
			<div class="box">
			<!----------------------- Message ------------------------------->
			<? if(isset($_SESSION['info_message'])){ ?>
			  <div class="alert alert-primary alert-dismissable">
				<button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>
				<? echo $_SESSION['info_message']; unset($_SESSION['info_message']);?>
			  </div>
			  <? } ?>
			<!----------------------- End Message ------------------------------->
				<div class="box-body">
				<!-- search form -->
				<?php include_once('sites_search_options.inc.php');?>
				<!-- /.search form -->
					<form action="index?page=add" method="post" name="form1" id="form1">
					<div class="box-footer">
					   <button type="submit" name="add" class="btn btn-primary">Add Site</button>
					</div>
					<? if($result>0){?>
					 <table id="example1" class="table table-bordered table-striped">
						<thead>
						  <tr>
							<th>Site Name</th>
							<th>Site Email</th>
							<th>Site Phone</th>
							<th>Site Alias Name</th>
							<!--<th>Info Email</th>-->
							<th>Edit</th>
							<th>Delete</th>
						  </tr>
						</thead>
						<tbody>
							<?
								$question_no = $eu +1;
								while($row =mysqli_fetch_array($sql)){ 
							?>
						  <tr>
							<td><?php echo ucfirst($row['site_name']); ?></td>
							<td><?php echo $row['sales_email']; ?></td>
							<td><?php echo $row['company_phone']; ?></td>
							<td><?php echo ucfirst($row['site_alias_name']) ?></td>
							<!--<td><?php echo $row['info_email']; ?></td>-->
							<td><a href="index?page=add&action=edit&id=<?=$row['id'].$next_page_condition.$paging;?>"> <i class="fa fa-fw fa-edit"></i> </a></td>
							<td><a href="index?page=view&action=delete&id=<?=$row['id'].$next_page_condition.$paging; ?>" onclick=" javascript:return confirm('Are you sure! You want to delete');"><i class="fa fa-fw fa-trash-o"></i> </a></td>
						  </tr>
							<? } ?>
							<!-- Paging starts here  -->
							<? 
								$next_page_condition .="&page=view";
								include("paging/paging_row.inc.php") ?>
							<!-- Paging ends starts here  -->
						</tbody>
					 </table>
					 <? }else{ ?>
						No	sites found...
					 <? } ?>
				</div>
				<div class="box-footer">
                   <button type="submit" name="add" class="btn btn-primary">Add Site</button>
                </div>
				</form>
			</div>
		</div>
	</div>
</section>