<?php
$message = (isset($_REQUEST['message'])) ? $_REQUEST['message'] :"";

$where 	= " WHERE 1=1 ";
$next_page_condition 	= "";
$paging ="";
if($_REQUEST['start']){
	$paging .="&start=".$_REQUEST['start'];
}
###########################################  STRAT FILTER CONITIONS    #####################################
$keycode 	= isset($_REQUEST['keycode']) ? $_REQUEST['keycode'] : "";
if($keycode) {
    $where	.= " AND name LIKE '%$keycode%' ";
    $next_page_condition.="&keycode=$keycode";
}

$code 	= isset($_REQUEST['code']) ? $_REQUEST['code'] : "";
if($code) {
    $where	.= " AND code LIKE '%$code%' ";
    $next_page_condition.="&code=$code";
}


$description 	= isset($_REQUEST['description']) ? $_REQUEST['description'] : "";
if($description) {
    $where	.= " AND description LIKE '%$description%' ";
    $next_page_condition.="&description=$description";
}

###########################################  	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		= "keycode";
$paging_table_name	= $table_name;
$paging_query		= $where;
$join_query_for_paging = "SELECT * FROM $table_name  $where ";
$page_header = "Keycode";
include("paging/paging_query.inc.php");
############################################ END PAGING WITH PER PAGE  #######################################

$query = "SELECT * FROM $table_name $where ORDER BY ord 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'){
	$id	= $_REQUEST['id'];
	$sql=mysqli_query($conn,"DELETE FROM $table_name WHERE id = $id ");
	
	header("location: $file_name?page=view_keycode&message=keycode deleted sucessfully".$next_page_condition.$paging);
}
#################################  END DELETE    #########################################
?>
<td width="100%" align="center" valign="top" bgcolor="" class="red">
<table width="100%" border="0" align="center" cellpadding="0" cellspacing="0" bordercolor="#000000">
	<tr>
		<td valign="middle" height="10" align="center">
		<table width="100%" border="0" cellspacing="0" cellpadding="0">
			<tr>
				<td height="10" align="center" class="head_ing"><? echo $page_header; ?></td>
				<!--<td width="368"  align="right" class="red">&nbsp;<? include("paging/no_of_records.inc.php"); ?></td>-->
			</tr>
		</table>
		</td>
	</tr>
	<tr>
		<td bordercolor="#FFFFFF" valign="top" align="center">
		<table width="100%" border="0" cellspacing="4" cellpadding="0">		
			<?php include_once('keycode_search_options.inc.php');?>		
			<? if($message){ ?>
			<tr>
				<td align="center" class="red"><?=$message;?></td>
			</tr>
			<? }?>			
			<tr>
				<td align="center" valign="top">
				
				<table width="100%" border="0" align="center" cellpadding="3" cellspacing="1" bgcolor="#CCCCCC">					
					<form action="index?page=add_keycode" method="post" name="form1" id="form1">
					<? if($result>0){?>
					<!-- Start  records header -->
					
					<input name="add"  type="submit" id="add_invoice" value="Add New keycode" />						
						<tr align="center" bgcolor="#000000">
						<td width="10%" class="white">Name</td>
						<td width="10%" class="white">Code</td>
						<td width="10%" class="white">Description</td>
						<td width="5%" class="white">Edit</td>						
						<td width="5%" class="white">Delete</td>
					</tr>
					<!-- End records header -->
					<?
					while($row = mysqli_fetch_array($sql)){
					?>
					<!-- Start data -->
					<tr align="center" bgcolor="#000000">
						<td align="left" bgcolor="#FFFFFF"><?php echo ucfirst($row['name']); ?></td>
						<td align="left" bgcolor="#FFFFFF"><?php echo ucfirst($row['code']); ?></td>
						<td align="left" bgcolor="#FFFFFF"><?php echo ucfirst($row['description']); ?></td>					
						
						<td align="center" bgcolor="#FFFFFF"><a href="index?page=add_keycode&action=edit&id=<?=$row['id'].$next_page_condition.$paging;?>"> <img src="../images/edit.gif" border="0" /> </a></td>
						<td width="17%" align="center" bgcolor="#FFFFFF"><a
							href="index?page=view_keycode&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>
					<!-- End data -->
					<? 
					}?>
					
					<?}else{?>
					<tr bgcolor="#000000">
						<td height="33" colspan="7" align="center" bgcolor="#000000"></td>
					</tr>
					<tr bgcolor="#ffffff">
						<td height="33" colspan="7" align="center" bgcolor="#ffffff">No	keycode found...</td>
					</tr>
					<?php }?>
					<tr bgcolor="#000000">
						<!--  <td height="25%" align="right" valign="top"  >&nbsp;</td> -->
						<td colspan="20" height="33"  align="center" bgcolor="#000000">												
						<input name="add"  type="submit" id="add_invoice" value="Add New keycode" />						
					</td>
					</tr>	
					<input type="hidden" id="keycode_value" name="keycode_value" value="<?=$_REQUEST['keycode']?>" />
					<!-- Paging starts here  -->
					<? 
					$next_page_condition .="&page=view_keycode";
					include("paging/paging_row.inc.php") ?>
					<!-- Paging ends starts here  -->
					</form>	
				</table>
				
				</td>
			</tr>
		</table>
		</td>
	</tr>
</table>
</td>