<?php
session_start();
$where 					= " WHERE 1=1 ";
$next_page_condition 	= "";
$paging ="";
if($_REQUEST['start']){
	$paging .="&start=".$_REQUEST['start'];
}
###########################################  STRAT FILTER CONITIONS    #####################################
$country 	= isset($_REQUEST['country']) ? $_REQUEST['country'] : "";
if($country) {
    $where	.= " AND country LIKE '%$country%' ";
    $next_page_condition.="&country=$country";
}
###########################################  	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		= "country";
$paging_table_name	= $table_name;
$paging_query		= $where;
$join_query_for_paging = "SELECT * FROM $table_name  $where ";
$page_header = "Country Management";
include("paging/paging_query.inc.php");
############################################ END PAGING WITH PER PAGE  #######################################
$query = "SELECT * FROM $table_name $where ORDER BY country ASC LIMIT $eu, $limit";
$sql=mysql_query($query);
$result=mysql_num_rows($sql);

#################################   DELETE    #########################################
// when we click on delete this area of php code will execute
if(isset($_REQUEST['action']) && $_REQUEST['action']=='delete')
{
	$sql=mysql_query("DELETE FROM $table_name WHERE id = '".$_REQUEST['id']."' ");
	$_SESSION['info_message'] = "Country deleted sucessfully";
	header("location: $file_name?page=view_country".$next_page_condition.$paging);
	exit;
}
#################################  END DELETE    #########################################
?>
<section class="content-header">
  <h1>
	<?=$page_header;?>
  </h1>
</section>
<section class="content">
	<div class="row">
		<div class="col-xs-12">
			<!----------------------- Message ------------------------------->
			<? if(isset($_SESSION['info_message'])){ ?>
			  <div class="alert alert-success 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">
				<div class="box-body">
				<!-- search form -->
				<?php include_once('country_search_options.inc.php');?>
				<!-- /.search form -->
					<form action="index?page=add_country" method="post" name="form1" id="form1">
					<div class="box-footer">
					   <button type="submit" name="add" class="btn btn-success">Add Country</button>
					</div>
					<? if($result>0){?>
					 <table id="example1" class="table table-bordered table-striped">
						<thead>
						  <tr>
							<th>Country</th>
							<th>Edit</th>
							<th>Delete</th>
						  </tr>
						</thead>
						<tbody>
							<?
								while($row =mysql_fetch_array($sql)){ 
							?>
						  <tr>
							<td><?php echo ucfirst($row['country']); ?></td>
							<td><a href="index?page=add_country&action=edit&id=<?=$row['id'].$next_page_condition.$paging;?>"> <img src="../images/edit.gif" border="0" /> </a></td>
							<td><a href="index?page=view_country&action=delete&id=<?=$row['id'].$next_page_condition.$paging; ?>" 
							onclick=" javascript:return confirm('Are you sure! You want to delete');"><img
							src="../images/del.gif" border="0" /> </a></td>
						  </tr>
							<? } ?>
							<!-- Paging starts here  -->
							<? 
								$next_page_condition .="&page=view_country";
								include("paging/paging_row.inc.php") ?>
							<!-- Paging ends starts here  -->
						</tbody>
					 </table>
					 <? }else{ ?>
						No country found...
					 <? } ?>
				</div>
				<div class="box-footer">
                   <button type="submit" name="add" class="btn btn-success">Add Country</button>
                </div>
				</form>
			</div>
		</div>
	</div>
</section>