<?php
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;

$heading="Manage Currencies";
$record_type="Currency";
$script_name="manage_currencies.php";
$table_name="currency_tbl";
######################################################
if($_POST['action']=="saveCurrency") {
	if(strlen(trim($cTitle))) {
		if(strlen(trim($itemID))) {
			updateTable($table_name, "cTitle='$cTitle', cSymbol='$cSymbol',cvalue='$cvalue' where cID='$itemID' ");
			$_SESSION[session_message]=$record_type.' has been updated successfully';
		}
		else {
			db_query("insert into $table_name set cTitle='$cTitle', cSymbol='$cSymbol',cvalue='$cvalue'");
			$_SESSION[session_message]=$record_type.' has been added successfully';
		}
	}
	header("Location: ".SITE_ADMIN_URL."/".$script_name."?start=".$start."&pagesize=".$pagesize);
	exit;
}

if($action=="crDel" and strlen(trim($cID))) {
	db_query("delete from $table_name where cID='$cID' ");
	$_SESSION[session_message]=$record_type.' has been deleted successfully';
	header("Location: ".SITE_ADMIN_URL."/".$script_name."?start=".$start."&pagesize=".$pagesize);
	exit;
}


admin_header();
?>
<table width="99%" border="0" align="center" cellpadding="0" cellspacing="0" valign="top">
 <tr><td align="left" width="50%" class="myTitle"><?=$heading;?></td></tr>
</table>
<hr size="2" width="99%" color="#92B2D6">

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


<form name="formn" method="post" action="" enctype="multipart/form-data">
<table width="100%"  border="0" cellpadding="2" cellspacing="2" class="lightBorder">
 <tr height="25" bgcolor="#EAEAEA">
  <td width="5%"><strong>S.No.</strong></td>
  <td width="35%" align="left"><strong> Currency Title</strong></td>
  <td width="20%" align="left"><strong>Currency Symbol</strong></td>
  <td width="20%" align="center"><strong>Currency Value</strong></td>
  <td width="20%" align="center"><strong>Options</strong></td>
 </tr>
 <?php
 $vNum=$start+1;
 if($reccnt>0){
	 while($arr=mysql_fetch_array($qry)) {
		 $arr=ms_htmlentities_decode($arr);
		 if($vNum%2!=0) {
			 $color="#f9f9f9";
		 }
		 else{
			 $color="#f0f0f0";
		 }
		 ?>
		 <tr bgcolor="<?=$color;?>">
		  <td align="center"><?=$vNum;?></td>
		  <td align="left"><?=ucwords($arr[cTitle]);?></td>
		  <td align="left"><?=$arr[cSymbol];?></td>
		  <td align="center"><?=$arr[cvalue];?></td>
		  <td align="center">
		   <?php
		   if (strtolower($arr['cID']) != 1) {
			   ?>
			   <a href="<?=$PHP_SELF;?>?cID=<?=$arr[cID];?>&action=fqEdit&start=<?=$start;?>&pagesize=<?=$pagesize;?>#bot"><img src="<?=SITE_ADMIN_URL?>/images/edit.gif" alt="Edit This Currency" title="Edit This <?=$record_type;?>" border="0"></a>
			   <!-- &nbsp;<a href="<?=$PHP_SELF;?>?cID=<?=$arr[cID];?>&action=crDel&start=<?=$start;?>&pagesize=<?=$pagesize;?>" onClick="return confirm('Are you sure to delete the record...');"><img src="<?=SITE_ADMIN_URL?>/images/cancel.gif" alt="Delete This <?=$record_type;?>" border="0"></a> !-->
			   <?php
		   }
		   else {
			   ?>
			   <strong>Base Currency</strong>
			   <?php
		   }
		   ?>
		  </td>
		 </tr>
		 <?php
		 $vNum++;
	 }
 }
 else{
	 ?>
	 <tr><td colspan="3"><strong>No Record Found..........</strong></td></tr>
	 <?php
 }
 ?>
</table>
</form><br />	

<?php
if(strlen(trim($cID))) {
	$readonly="";
	if(strlen(trim($cID))) {
		$sectionTitle="Edit & Update Currency";
		$currencyRes=getResult("currency_tbl"," where cID='$cID'");
		if (strtolower($currencyRes['cTitle']) == "us dollars") {
			$readonly="readonly";
		}
	}
	else {
		$sectionTitle="Add New Currency";
	}
	?>
	<script type="text/javascript" src="<?=SITE_ADMIN_URL?>/fckeditor/fckeditor.js"></script>
	<form name="frmFaq" action="" method="post" onsubmit="return validate(this);">
	<table width="100%"  border="0" cellpadding="2" cellspacing="2" class="lightBorder">
	 <tr height=20>
	  <td colspan=2 align="left"><a name="bot"><strong><?=$sectionTitle;?></strong></td>
	 </tr>
	 <tr height=30 align="left">
	  <td class="lightGrayBg">Currency Title: </td><td class="lightGrayBg">
	   <input type=text name="cTitle" value="<?=$currencyRes[cTitle];?>" <?=$readonly;?> size="40" class="txtfieldadmin" id="NOBLANK~Please enter currency title~DM~">
	  </td>
	 </tr>
	 <tr height=30 align="left">
	  <td class="lightGrayBg">Currency Symbol : </td>
	  <td class="lightGrayBg"><input type=text name="cSymbol" value="<?=$currencyRes[cSymbol];?>" size="5" class="txtfieldadmin" id="NOBLANK~Please enter currency symbol~DM~"> &nbsp; Please enter html code of the symbol, every time you update the currency value.</td>
	 </tr>
	 <tr height=30 align="left">
	  <td class="lightGrayBg">Currency Value : </td>
	  <td class="lightGrayBg"><input type=text name="cvalue" value="<?=$currencyRes[cvalue];?>" size="5" class="txtfieldadmin" id="NOBLANK~Please enter currency value~DM~">&nbsp;= 1 <?=CURRENCY?></td>
	 </tr>
	 <tr class="lightGrayBg">
	  <td></td>
	  <td align=left>
	   <input type="hidden" name="itemID" value="<?=$currencyRes[cID];?>">
	   <input type="hidden" name="action" value="saveCurrency">
	   <input type="submit" class="button" name="submitProd" value="Save">
	  </td>
	 </tr>
	</table>
	</form>
	<?php
}
admin_footer();
exit;
?>