<?
include_once("../include/main.inc.php");
check_session('MyCpanel','index.php');

################ Paging Starts From Here ##################
@extract($_REQUEST);
$start = (intval($start)==0 or $start=="")?$start=0:$start;
$pagesize = intval($pagesize)==0?$pagesize=20:$pagesize;

$record_type="Banner Price";
$script_name="manage_banner_prices.php";
$table_name="banner_price_tbl";
####################################################
if($action=="add_record") {
	if ($price!="") {
		$sql=db_query("insert into $table_name set pageName='$pageName', bannerPosition='$bannerPosition', price='$price', bannerSize='$bannerSize'");
		$_SESSION[session_message]='New '.$record_type.' has been added successfully';
	}
	else {
		$_SESSION[session_message]='Banner price is required.';
	}
	header("Location: ".SITE_ADMIN_URL."/".$script_name."?start=".$start."&pagesize=".$pagesize."&id=".$id);
	exit;	
}

if($action=="update_record") {
	if ($price!="") {
		updateTable($table_name," pageName='$pageName', bannerPosition='$bannerPosition', price='$price', bannerSize='$bannerSize' where slno='$recordID'");
		$_SESSION[session_message]=$record_type.' has been updated successfully';
	}
	else {
		$_SESSION[session_message]='Banner price is required.';
	}
	header("Location: ".SITE_ADMIN_URL."/".$script_name."?start=".$start."&pagesize=".$pagesize);
	exit;
}

admin_header("Manage $record_type");
?>
<table width="99%" border="0" align="center" cellpadding="0" cellspacing="0" valign="top">
 <tr>
	<td align="left" width="50%" class="myTitle"><?=$heading;?></td>
	<td align="right">
	 <form name="pgcolor_form" action="<?=$PHP_SELF?>" method="post" style="margin:0px;padding:0px;">
	 <table width="98%" border="0" align="center" cellpadding="0" cellspacing="0" valign="top">
	  <tr>
	   <td align="right">Records Per Page:
	    <select name="pagesize" onchange="this.form.submit();">
	     <option value="0">Select</option>
	     <?php
	     foreach($_GLOBALS[pgsize_arr] as $val) {
		     if(trim($pagesize)==trim($val)) {
			     echo '<option value="'.$val.'" selected>'.$val.'</option>';
		     }
		     else{
			     echo '<option value="'.$val.'">'.$val.'</option>';
		     }
	     }
	     ?>
	    </select>	    
		 </td>
		</tr>
	 </table>
	 </form>
	</td>
 </tr>
</table>
<hr size="2" width="99%" color="#DA251C">
<!--
<table width="99%" border="0" align="center" cellpadding="0" cellspacing="0" valign="top">
 <tr><td align="right"><input type="button" onclick='window.location.href="<?=SITE_ADMIN_URL;?>/<?=$script_name;?>?start=<?$start;?>&pagesize=<?=$pagesize;?>&id=add_new"' class="button" value="Add New <?=$record_type;?>" /></td></tr>
</table>
!-->

<?php
$qry1= db_query("select * from $table_name where 1");
$reccnt = NumRows($qry1);
$qry= db_query("select * from $table_name where 1 order by slno desc limit $start, $pagesize");
echo pageNavigation($reccnt,$pagesize,$start);
print_message();

if($reccnt>0){
	?>
	<form name="formn" method="post" action="" enctype="multipart/form-data" onsubmit="return validate(this);">
	<table width="99%" border="0" cellpadding="2" cellspacing="2" class="lightBorder">
	 <tr height="25" bgcolor="#EAEAEA">
	  <td width="5%"><b>S.No.</b> <!-- <input type="checkbox" name="chk" onclick="CheckAll()" class="NoStyle"> 1--> </td>
	  <td width="25%"><b>Page Name</b></td>
	  <td width="20%"><b>Banner Position</td>
	  <td width="20%"><b>Banner Size</b></td>
	  <td width="20%"><b>Price Per Week</b></td>
	  <td width="10%" align="center"><b>Options </td>
	 </tr>
	 <?php
	 $sl=$start+1;
	 while ($res=mysql_fetch_array($qry)) {
		 $res=ms_htmlentities_decode($res);
		 if($sl%2==0){
			 $color="f0f0f0";
		 }
		 else{
			 $color="f9f9f9";
		 }
		 ?>
		 <tr bgcolor="<?=$color;?>">
		  <td valign="top"> <?=$sl;?>. <!-- <input type=checkbox name="cid[]" value="<?=$res[slno]?>" class="NoStyle"> 1--> </td>
		  <td valign="top"><?=$res[pageName];?></td>
		  <td valign='top'><?=$res[bannerPosition];?></td>
		  <td valign='top'><?=$res[bannerSize];?></td>
		  <td valign='top'><?=$res[price];?> <?=CURRENCY;?></td>
		  <td valign='top' align="center">
		   <a href="<?=$script_name;?>?id=edit_record&start=<?=$start;?>&id=edit_record&recordID=<?=$res[slno];?>#bot"><img src="<?=SITE_ADMIN_URL?>/images/edit.gif" alt="Edit This <?=$record_type;?>" title="Edit This <?=$record_type;?>" border="0"></a>
		  </td>
		 </tr>
		 <?php
		 $sl++;
	 }
	 ?>	 
	</table><br>
	<?php	
}
else {
	?>
	<table width="100%"  border="0" cellpadding="6" cellspacing="2" class="lightBorder">
	 <tr><td><b>No Record Found.............</b></td></tr>
	</table>
	<?
}

if ($id=="add_new" || $id=="edit_record") {
	?>
	<br/>
	<form name="formn1" method="post" action="" enctype="multipart/form-data" onsubmit="return validate(this);">
	<table width="99%"  border="0" cellpadding="0" cellspacing="2" class="lightBorder">
	 <?
	 if($recordID=="" || $id!="edit_record") {
		 ?>
		 <tr><td colspan="3" align="left" class="lightBlueBg PadFive" height="20"><b><a name="bot">Add New <?=$record_type;?></a></b></td></tr>
		 <?
	 }
	 else {
		 //$read_only="readonly";
		 ?>
		 <tr>
		  <td align="left" class="lightBlueBg PadFive" height="20"><a name="bot"></a><b>Edit <?=$record_type;?></b></td>
		  <td align="right" class="lightBlueBg  PadFive" height="20"></td>
		 </tr>
		 <?
	 }
	 $result=getResult($table_name," where slno='$recordID'");
	 ?>
	 <tr>
	  <td class="brdrbtm" width="17%"><b>Page Name <font color="red">*</font></b></td>
	  <td class="brdrbtm"><input size="50" type="text" name="pageName" value="<?=$result[pageName]; ?>" class="txtfieldadmin" id="NOBLANK~Please enter page name~DM~" <?=$read_only;?> /></td>
	 </tr>
	 <tr>
	  <td class="brdrbtm"><b>Banner Position <font color="red">*</font></b></td>
	  <td class="brdrbtm"><input size="50" type="text" name="bannerPosition" value="<?=$result[bannerPosition]; ?>" class="txtfieldadmin" id="NOBLANK~Please enter banner position~DM~" <?=$read_only;?> /></td>
	 </tr>
	 <tr>
	  <td class="brdrbtm"><b>Banner Size <font color="red">*</font></b></td>
	  <td class="brdrbtm"><input size="50" type="text" name="bannerSize" value="<?=$result[bannerSize]; ?>" class="txtfieldadmin" id="NOBLANK~Please enter banner size~DM~" <?=$read_only;?> /></td>
	 </tr>
	 <tr>
	  <td class="brdrbtm"><b>Price Per Week <font color="red">*</font></b></td>
	  <td class="brdrbtm"><input size="50" type="text" name="price" value="<?=$result[price]; ?>" class="txtfieldadmin" id="NOBLANK~Please enter price per week~DM~NUM~Please enter numbers only" /></td>
	 </tr>
	 <tr>
	  <td class="brdrbtm"></td>
	  <td class="brdrbtm">
	   <?
	   if($recordID!="") {
		   ?>
		   <input type="submit" name="submit" value="Update <?=$record_type;?>" class="button">
		   <input type="hidden" name="recordID" value="<? echo $result[slno]; ?>">
		   <input type="hidden" name="action" value="update_record">
		   <?
	   }
	   else{
		   ?>
		   <input type="submit" name="submit" value="Add New <?=$record_type;?>" class="button">
		   <input type="hidden" name="action" value="add_record">
		   <?
	   }
	   ?>
	   <input type="hidden" name="id" value="edit_record">	   
	   <input type="hidden" name="start" value="<? echo $start; ?>">
	   <input type="hidden" name="pagesize" value="<? echo $pagesize; ?>">
	  </td>
	 </tr>
	</table>
	</form>
	<?
}

admin_footer();
exit;
?>