<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<?php
ob_start();
ini_set('session.bug_compat_warn', 0);
ini_set('session.bug_compat_42', 1);

 include("db.php");
 include("../pdate.php");
 
     $get_id=$_GET['editID'];
     $table=$_GET['table']; 
     $type=$_GET['type'];
  
    
   
     $customerRetriveSql="select * from exchangecurrency1396.crrencyrate where id='$get_id'  ";
	 $customerRetriveQuery=$db ->query($customerRetriveSql);
	 $customerRetriveRow=$customerRetriveQuery ->fetch_array();
	 
	 $id_retrive=$customerRetriveRow['id'];
	 $dateretrive=$customerRetriveRow['date'];
	 $unit=$customerRetriveRow['unit'];
	 $counterCurrency_retrive=$customerRetriveRow['counterCurrency'];
	 $baseCurrency_retrive=$customerRetriveRow['baseCurrency'];
	 $rate_retrive=$customerRetriveRow['rate'];
	//=================CURRENCY NAME========================
	 $currencyName_sql="select name from `currencies` where id='$counterCurrency_retrive'  ";
	 $currencyName_query=$db ->query($currencyName_sql);
	 $currencyName_row=$currencyName_query ->fetch_array();
	 
	 $currencyName=$currencyName_row['name'];
	//=================CURRENCY NAME========================
	//=================CURRENCY NAME========================
	 $baseName_sql="select name from `currencies` where id='$baseCurrency_retrive'  ";
	 $baseName_query=$db ->query($baseName_sql);
	 $baseName_row=$baseName_query ->fetch_array();
	 
	 $baseName=$baseName_row['name'];
	//=================CURRENCY NAME========================
	 
	 
?>  
<html>
<head>
	<title>ویــرایـش نرخ خرید</title>
	 
	<link rel="stylesheet" type="text/css" href="../css/style.css">
   <script src="dist/sweetalert-dev.js"></script>
  <link rel="stylesheet" href="dist/sweetalert.css"> 
  
<!---==========================================================================-->
 
 <script type="text/javascript" src="../js/decimal.js"></script>
 <script type="text/javascript" src="../js/NumberFormat.js"></script>
<!---==========================================================================-->
<link href="css/jquery.autocomplete.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="../js/jquery-1.5.2.min.js"></script>
<script type="text/javascript" src="../js/jquery.autocomplete.pack.js"></script>
<script type="text/javascript" src="../js/script.js"></script>
<!---==========================================================================-->
<!--========================================================================-->
 
</head>
<body> 

	<div id="wrap">
		 
		<div id="contentt">
			 
			<div id="menu">
				 
			</div>
		    <div id="matlab" >
			<div id="title"><p>ویــرایـش نــرخ خــــریداری</p> </div>
			<div id="picture">
					<table border="0" width="400px">
						<tr>
							<td style="width:180px;"><img src="../img/banktransaction.png" width="150px" height="120px">  </td>
							<td > </td>
						</tr>
					</table>
			   </div>
		    	<form method="post" action="" name="form">
               <table border="0"   id="rgistera_cart" width="800px" class="font">
					<tr>
						<td style="width:190px">&nbsp;</td>
		    			<th style="width:150px">مقـــدار</th>
						<td style="width:250px" >
							<input type='text' name="unit"  class="filed" value="<?php  echo $unit ?>"  > 							 
						</td>
						 
		    		</tr>
					<tr>
						<td style="width:190px">&nbsp;</td>
		    			<th style="width:150px">ارز مورد معاوضه</th>
						<td style="width:250px" >
							<input type="text"    value="<?php  echo $currencyName ?>"   class="filed" disabled  onChange="calculateDollar()"  onclick="calculateDollar()"/>
							<input type="hidden" autocomplete="off"   value="<?php  echo $currencyName ?>"   class="filed"  onChange="calculateDollar()"  onclick="calculateDollar()"/>
														
						</td>
						 
		    		</tr>
					<tr>
						<td style="width:190px">&nbsp;</td>
		    			<th style="width:150px">ارز پـایه</th>
						<td style="width:250px" >
							<input type="text"    value="<?php  echo $baseName ?>"   class="filed" disabled  onChange="calculateDollar()"  onclick="calculateDollar()"/>
							<input type="hidden" autocomplete="off"   value="<?php  echo $baseName ?>"   class="filed"  onChange="calculateDollar()"  onclick="calculateDollar()"/>
														
						</td>
						 
		    		</tr>
					<tr>
						<td style="width:190px">&nbsp;</td>
		    			<th style="width:150px">نرخ ارز پایه دربرابر ارز مورد معاوضه</th>
						<td style="width:250px" >
							<input type="text" required autocomplete="off" onkeyup="addSeparator(this)" value="<?php  echo $rate_retrive ?>" name="rate" id="rate"   class="filed"   />
														
						</td>
						 
		    		</tr>
					 
					 
					 
					 
					 
					 
					 
					 
					 
					 
					<tr>
						<td style="width:190px">&nbsp;</td>
		    			<th style="width:150px"> </th>
						<td style="width:230px"> 
						    <input type="submit" id="save"   name="save"  value="ذخیره">
							<input type="submit" id="back"   name="back"  value="انصراف">
							
						</td>
						<td style="width:300px;"> </td> 
		    		</tr>
                    
		    	</table>
		    	 
				</form>
		    </div>


		</div>
		 
	</div>
</body>
</html>
<?php
if($_POST['back']){
  header("location:../currencyRate.php");
}
if($_POST['save']){
    include("../message.php");
     
	$unit=$_POST['unit'];
	$rateP=$_POST['rate'];
	$rate = preg_replace('/[^\d\.-]/', '', $rateP);
   if(strlen(trim($rate))==0 or strlen(trim($unit))==0){
		echo' <script>
					sweetAlert("اخطار...", "لطفا جاهای خالی را پر کنید", "error");
			   </script>';

		die;
		}
	/*آپــدیـت کردن واحـــد پـــولی*/
		 $updateRate_Sql="update crrencyrate set rate='$rate',unit='$unit'  where id ='$get_id'";
		 $updateRate_Query=$db ->query($updateRate_Sql);
		
		echo' <script>
					 
					
				   swal("ذخیره موفق!", "اطلاعات وارده با موفقیت ثبت سیستم شد", "success")
				</script>';
	    echo '<meta http-equiv="refresh" content ="1; url=../currencyRate.php" >';
	
  }

?>