-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconvert.php
69 lines (55 loc) · 1.74 KB
/
convert.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<?php
include_once('allFunctions.php');
session_start();
$_SESSION['currencyRates'] = getRates();
$_SESSION['currencyVariations'] = getVariations();
$fromCurrencyIndex = (int) $_GET['ffv'];
$toCurrencyName = $_GET['tfv'];
$fromCurrencyName = $_SESSION['currencies1'][$fromCurrencyIndex];
$amount = (double) $_GET['sv'];
$ca = $_SESSION['amountsExpected'];
$finalAmount = 0;
if($toCurrencyValue == 'JPY')
$finalAmount = $ca['JPY'];
$index = 0;
switch($toCurrencyName)
{
case 'USD': $finalAmount = $ca['USD']; $index = 0;
break;
case 'INR': $finalAmount = $ca['INR']; $index = 1;
break;
case 'JPY': $finalAmount = $ca['JPY']; $index = 2;
break;
case 'EUR': $finalAmount = $ca['EUR']; $index = 3;
break;
case 'HKD': $finalAmount = $ca['HKD']; $index = 4;
break;
case 'SLR': $finalAmount = $ca['SLR']; $index = 5;
break;
case 'COP': $finalAmount = $ca['COP']; $index = 6;
break;
case 'CNY': $finalAmount = $ca['CNY']; $index = 7;
break;
case 'DKK': $finalAmount = $ca['DKK']; $index = 8;
break;
}
if($_SESSION['currentAmounts'][$fromCurrencyName]<$amount)
$amount = $_SESSION['currentAmounts'][$fromCurrencyName];
echo 'Last transaction was from '.$fromCurrencyName.' '.$amount.' to '.$toCurrencyName.' '.$finalAmount;
$sa = $_SESSION['currentAmounts'][$fromCurrencyName]-$amount;
if($sa<1)
$sa=0;
$_SESSION['currentAmounts'][$fromCurrencyName] = round($sa,4);
$da = $_SESSION['currentAmounts'][$toCurrencyName]+$finalAmount;
if($da<1)
$da=0;
$_SESSION['currentAmounts'][$toCurrencyName] = round($da,4);
$finalValues = getRates();
$usd = 0.0;
$count = 0;
foreach($_SESSION['currentAmounts'] as $currencyName => $currencyAmount)
{
$usd = $usd + $currencyAmount * 1.0/(doubleval($finalValues[$count++]));
}
$_SESSION['currentAmount'] = $usd;
?>