<!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'];
   
    
   
     $money_RetriveSql="select * from `$table` where id='$get_id'  ";
	 $moeny_RetriveQuery=$db ->query($money_RetriveSql);
	 $money_RetriveRow=$moeny_RetriveQuery ->fetch_array();
	 
	 $id_retrive=$money_RetriveRow['id'];
	 $currencyId_retrive=$money_RetriveRow['currencyId'];
	 $amount_retrive=$money_RetriveRow['amount'];
	 $rate_retrive=$money_RetriveRow['rate'];
	 $dollarTotal_retrive=$money_RetriveRow['dollarTotal'];
	 $date_retrive=$money_RetriveRow['date'];
	 //======================================
	 
     $currencyName_Sql="select * from `currencies` where id='$currencyId_retrive'  ";
	 $currencyName_Query=$db ->query($currencyName_Sql);
	 $currencyName_Row=$currencyName_Query ->fetch_array();
	 
	 $currencyName=$currencyName_Row['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>
<!---==========================================================================-->
<!--========================================================================-->
<script>
  
//====================================================================================	
	
	function calculate(){
	     insertval=setInterval("multipal()",1);
	    }
		function multipal(){
		 rateOfCurrency=document.getElementById('rateOfCurrency').value;	 
		 amount=document.getElementById('amount').value;
		 
		  totalBuy=(rateOfCurrency*1)*(amount*1);
		  findTotalBuy=totalBuy.toFixed(2);	
		  document.getElementById('totalResutl').value=(findTotalBuy*1);
		
		}
	 
</script>	
 
   
</head>
<body onload="calculate()">

	<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="date" id="newdate" placeholder="" class="form-control" value="<?php echo $date_retrive;?>"/>
 
						</td>
						<td style="width:280px;">
							 
						 </td>
		    		</tr>
						 
					<tr>
						<td style="width:190px">&nbsp;</td>
		    			<th style="width:150px">نوع پول</th>
						<td style="width:250px" >
							<input type="text"    class='filed' disabled value="<?php echo $currencyName   ?>"> 
						</td>
						<td style="width:280px;">
							 
						 </td>
		    		</tr>
					<tr>
						<td style="width:190px">&nbsp;</td>
		    			<th style="width:150px">مقدار</th>
						<td style="width:250px" >
					    <input type="text"     class='filed' disabled value="<?php echo number_format($amount_retrive,2);   ?>" ></div>
					    <input type="hidden" name="amount" id='amount'  value="<?php echo $amount_retrive   ?>" ></div>
						
						</td>
														 
						<td style="width:280px;">
							 
						 </td>
		    		</tr>
					<tr>
						<td style="width:190px">&nbsp;</td>
		    			<th style="width:150px">نرخ</th>
						<td style="width:250px" >
					   <input type="text" name="rateOfCurrency" id='rateOfCurrency'  class='filed' value="<?php echo $rate_retrive ?>" onclick="calculate()" onchange="calculate()"> 
						</td>
														 
						<td style="width:280px;">
							 
						 </td>
		    		</tr>
					 <tr>
						<td style="width:190px">&nbsp;</td>
		    			<th style="width:150px">مجموع</th>
						<td style="width:250px" >
						 <input type="text" name="totalResutl" id='totalResutl' class='filed' > 
						</td>
														 
						<td style="width:280px;">
							 
						 </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:../moneyPrice.php");
}
if($_POST['save']){
     
	$rateOfCurrency=$_POST['rateOfCurrency'];
	$totalResutl=$_POST['totalResutl'];
		  
		  
		  
		  
		  if(strlen(trim($rateOfCurrency))==0  or strlen(trim($totalResutl))==0){
    
   echo' <script>
					sweetAlert("هـشــــــدار...", "لطـفــــا جـاهـای خـالـــی را پـــرکنیـــد!", "error");
		</script>'; 	  

		 echo '<meta http-equiv="refresh" content ="1; url=moneyPrice.php" >';
         die;


}


		  $backUpdateMoneySql="update dailyasset set rate='$rateOfCurrency',dollarTotal='$totalResutl' where id='$get_id'";
	      $backUpdateCustomerBaseMoneyQuery=$db ->query($backUpdateMoneySql);
          
          
 
		   echo' <script>
			 	 
					
				   swal("ذخیره موفق!", "اطلاعات وارده با موفقیت ثبت سیستم شد", "success")
				</script>';
	          echo '<meta http-equiv="refresh" content ="1; url=../moneyPrice.php" >';
                  
	 
   
  }

?>