<?php
ob_start();
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
// +----------------------------------------------------------------------+
// | PHP version 4/5                                                      |
// +----------------------------------------------------------------------+
// | This source file is a part of iScripts Multicart                     |
// +----------------------------------------------------------------------+
// | Authors: Programmer<programmer@armia.com>        		              |
// +----------------------------------------------------------------------+
// | Copyrights Armia Systems, Inc and iScripts.com © 2005                |
// | All rights reserved                                                  |
// +----------------------------------------------------------------------+
// | This script may not be distributed, sold, given away for free to     |
// | third party, or used as a part of any internet services such as      |
// | webdesign etc.                                                       |
// +----------------------------------------------------------------------+
?>
<?php

include "../includes/config.php";
include "../includes/session.php";
include "../includes/functions.php";


if (get_magic_quotes_gpc()) {
    $_POST = array_map('stripslashes_deep', $_POST);
    $_GET = array_map('stripslashes_deep', $_GET);
    $_COOKIE = array_map('stripslashes_deep', $_COOKIE); 
} 

if(isset( $_SESSION["sess_adminname"]) and $_SESSION["sess_adminname"]!= ""){
	$adminname = $_SESSION["sess_adminname"];
}else{
	header("Location:login.php");
	exit;
}


include "../includes/htmltop.php";

$currency_name_flag = 0;
$currency_code_flag = 0;

$adminCurrency	= GetAdminCurrency();

$select_currency_edit = "SELECT * FROM ".$tableprefix."currency_master WHERE  ncurrency_id = ".$_GET['edit_id'];
$result_currency_edit = mysql_query($select_currency_edit) or die(mysql_error());
$currency_row = mysql_fetch_assoc($result_currency_edit);
			
if(isset($_POST['update']))
{


	/*check whether currency name and currency code with the same name exists in the database*/
		
	$select_currency = "SELECT * FROM ".$tableprefix."currency_master 
						WHERE LOWER(vcurrency_name) = ".GetSQLValueString(strtolower($_POST['txtCurrencyName']),"text").
						" AND ncurrency_id != ".$_GET['edit_id'];
	$result_currency = mysql_query($select_currency) or die(mysql_error());
	
	$select_currency_code = "SELECT * FROM ".$tableprefix."currency_master 
							WHERE LOWER(vcurrency_code) = ".GetSQLValueString(strtolower($_POST['txtCurrencyCode']),"text").
							" AND ncurrency_id != ".$_GET['edit_id'];
	$result_currency_code = mysql_query($select_currency_code) or die(mysql_error());
			
	if(mysql_num_rows($result_currency)>0)
	{
	
		$message = CURR_NAME_EXIST."<br>";
		$currency_name_flag = 1;
		
	}
	if(mysql_num_rows($result_currency_code)>0)
	{
	
		$message .= CURR_CODE_EXIST;
		$currency_code_flag = 1;
	}
	if($currency_name_flag == 0 && $currency_code_flag == 0)
	{	
	
		 $update_currency = "UPDATE ".$tableprefix."currency_master
							SET vcurrency_name = ".GetSQLValueString($_POST['txtCurrencyName'],"text").",
							vcurrency_code = ".GetSQLValueString($_POST['txtCurrencyCode'],"text").",
							vcurrency_symbol=".GetSQLValueString($_POST['txtCurrencySymbol'],"text").",
							nexchange_price = ".GetSQLValueString($_POST['txtExchangePrice'],"text").",
							usdollar_rate = ".GetSQLValueString($_POST['txtUSDValue'],"text")."
							WHERE ncurrency_id = ".$_GET['edit_id'];
							
		mysql_query($update_currency) or die(mysql_error());			
		
		
								  
/*---------Patch-----------*/

	header("Location:currency.php?".$_GET['qstring']."&txtSearch=".$_GET['txtSearch']."&msg=update");
	
/*---------Patch-----------*/			
							  
	}						  

}
?>
<script>
function checkEditCurrencyForm()
{

  var form_name = new Array('txtCurrencyName','txtCurrencyCode','txtExchangePrice','txtUSDValue');		
  var display_name = new Array('<?php echo CURRENCY_NAME;?>','<?php echo CURRENCY_CODE;?>','<?php echo EXCHANGE_PRICE;?>','<?php echo EQUI_TO_TEXT;?>');
  var count = 4;	

  if(check_fields('frmEditCurrency',form_name,display_name,count))	
  {
  
  	
	if(!check_numeric(trimSpaces(document.frmEditCurrency.txtExchangePrice.value)))
	 {
	 
	 	return confirm("<?php echo PLS_NUMBER;?>")
		document.frmEditCurrency.txtExchangePrice.focus();
		return false;		 
	 
	 }
	 
	 if(trimSpaces(document.frmEditCurrency.txtExchangePrice.value)==0)
	 {
	 
		 return confirm("<?php echo PLS_NUMBER;?>")
		document.frmEditCurrency.txtExchangePrice.focus();
		return false;		 
	 
	 }
	 
	 if(!check_numeric(trimSpaces(document.frmEditCurrency.txtUSDValue.value)))
	 {
	 
		 return confirm("<?php echo PLS_NUMBER;?>")
		document.frmEditCurrency.txtUSDValue.focus();
		return false;		 
	 
	 }
	 
	  if(trimSpaces(document.frmEditCurrency.txtUSDValue.value)==0)
	 {
	 
		  return confirm("<?php echo PLS_NUMBER;?>")
		document.frmEditCurrency.txtUSDValue.focus();
		return false;		 
	 
	 }
  	
	   
  }
  else
  {
  
  		return false;
  
  }
   
}

</script>
<script type="text/javascript">
function changeExchangeCurrency(val)
{
  document.getElementById("exCurr").innerHTML = val;
  document.getElementById("exCurr2").innerHTML = val;
  document.getElementById("exCurr1").innerHTML = val;
  document.getElementById("exCurr3").innerHTML = val;
}
</script>

		
		<body>
		
		<center>
		
		<div align="left" id="layout">
		
		
				
				
				<!--header area start -->
<?php

	include_once("../includes/topheader_admin.php")

?>
				
				<!--header area end -->
				
				
				
				
				<div align="left" class="main_body">
				<!--main body start -->
				
				
				
<?php
		include_once("../includes/admintopmenu.php")
?>		
																					
								
					<div align="left" class="content_area">
					
					<!--content area start -->
				
					<table cellpadding="0" cellspacing="0" border="0" width="100%">
				<tr><td height="35"><?php include_once("../includes/currencymenu.php")?></td>
				</tr>
				<tr>
				<td>			
					<div align="left" class="page_title"><?php echo EDIT_CR;?></div>
					<div align="center" class="text_information grey_tr"><?php echo $message?></div>
            		<br>
											
					<div align="left">			

		
			<form name="frmEditCurrency" action="#" method="POST" enctype="" onSubmit="return checkEditCurrencyForm();">
		
			<table width="100%" border="0" cellpadding="2" cellspacing="2" class="manage_table">
				<tr><td colspan="3"><span class="required">*</span> <?php echo EXCHANGE_RATES;?>. </td></tr>
				<tr><td colspan="3" align="right"><span class="required">*</span>&nbsp;<?php echo FIELDS_ARE_MANDATORY;?></td></tr>
				<tr><td width="43%" align="left" valign=top><?php echo CURRENCY_NAME;?>&nbsp;<span class="required">*</span></td><td width="1%" >&nbsp;</td>
					<td width="56%" align="left" valign=top><input class="textbox" type="text" name="txtCurrencyName" value="<?php echo $currency_row['vcurrency_name']?>" size="25" maxlength="50" onChange="changeExchangeCurrency(this.value);"></td>
				</tr>
				<tr>
				  <td align="left" valign=top><?php echo CURRENCY_CODE;?>&nbsp;<span class="required">*</span></td>
				  <td>&nbsp;</td>
					<td valign=top align="left"><input class="textbox" type="text" name="txtCurrencyCode" value="<?php echo $currency_row['vcurrency_code']?>" size="25" maxlength="10"></td>
				</tr>
				<!--
				<tr>
				  <td align="left" valign=top>Currency Symbol&nbsp;<span class="required">*</span></td>
				  <td>&nbsp;</td>
					<td valign=top align="left"><input class="textbox" type="text" name="txtCurrencySymbol" value="<?php //echo $currency_row['vcurrency_symbol']?>" size="25" maxlength="10"></td>
				</tr>
				-->
				<tr>
				  <td align="left" valign=top><?php echo CURR_SYMBOL;?> &nbsp;<span class="required">*</span></td>
				  <td>&nbsp;</td>
				  <td valign=top align="left"><input class="textbox" type="text" name="txtCurrencySymbol" value="<?php echo $currency_row['vcurrency_symbol']?>" size="25" maxlength="10"></td>
			    </tr>
				
				<tr>
				  <td align="left" valign=top><?php echo EXC_RATE_ADMIN_CURR;?>(<?php echo $adminCurrency['currency_code'];?>) <?php echo AGAINST;?>  <span id="exCurr"><?php echo $currency_row['vcurrency_name']?><span class="required">*</span></span></td>
				  <td>&nbsp;</td>
				  <td valign=top align="left">&nbsp;</td>
			    </tr>
				
				<tr>
				  <td align="right" valign=top><strong>  ( 1 <?php echo $adminCurrency['currency_code']?> =   </strong></td>
				  <td>&nbsp;</td>
					<td valign=top align="left"><input class="textbox" type="text" name="txtExchangePrice" value="<?php echo $currency_row['nexchange_price']?>" size="25"> <b> <span id="exCurr1"><?php echo $currency_row['vcurrency_name']?></span> )</b></td>
				</tr>
				
				<tr>
				  <td align="left" valign=top><?php echo EXC_USD;?>    <span id="exCurr2"><?php echo $currency_row['vcurrency_name']?>  </span> (<?php echo HELP_MSG;?>)<span class="required">*</span></span></td>
				  <td>&nbsp;</td>
				  <td valign=top align="left">&nbsp;</td>
			    </tr>
				
						<tr>
						  <td align="right"> <b>( <?php echo USD_EQUALS;?> </b></td>
						  <td>&nbsp;</td>
						  <td><input class="textbox" type="text" name="txtUSDValue"  size="25" value="<?php echo $currency_row['usdollar_rate']?>"> 
						    <b> <span id="exCurr3"><?php echo $currency_row['vcurrency_name']?></span> )</b></td>
						</tr>
				<tr>
					<td colspan="3" align="center">
						<input type="button" name="back" class="button" value="<?php echo BACKBTN;?>" onClick="window.location='currency.php'">
						<input type="submit" value="<?php echo UPDATE;?>" name="update" class="button">
					</td>
				</tr>
				<tr><td colspan="3">&nbsp;</td></tr>
			</table>
			
		</form>
		
		</div>
						
	</td></tr></table>			
		<!--content area end-->
						
		</div>
		
						
			<div align="left" class="clear_float"><img src="<?php echo $imagefolder;?>/clear.gif" alt="" width="1" height="1" /></div>
		<!--main body end -->
		</div>
				
				
<?php
	include "../includes/footer.php";
	ob_end_flush();
?>
<script type="text/javascript">
function changeExchangeCurrency(val)
{
  document.getElementById("exCurr").innerHTML = val;
  document.getElementById("exCurr2").innerHTML = val;
}
</script>