Login   Register  
PHP Classes
elePHPant
Icontem

File: select_convert.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Stephane Mouton  >  Currency Display & Convert  >  select_convert.php  >  Download  
File: select_convert.php
Role: ???
Content type: text/plain
Description: An example to help you interactively select parameters of the Currency Convert class
Class: Currency Display & Convert
Currency conversion and display with locale format
Author: By
Last change:
Date: 2001-03-25 15:33
Size: 4,852 bytes
 

Contents

Class file image Download
<html>
<head>
<title>Currency Convert class Selector</title>
</head>
<body>
<H1>Currency Convert class Selector</h1>
The goal of this tool is to help you use the CurrencyConvert class by selecting class parameters using a web form.<br>
Once you've selected your parameters, you obtain the PHP code to insert in your page as well as a sample of the conversion : how roundings and rates are handled.<br>
As you can see, rounding can be finely tuned using the kind of rounding.<br>
That way, you can define conversion rules like "convert $ price to DM using a 0.5 DM superior rounding", etc.<br>
<?
	if (isset($show)){
	include('class_currency_convert.php');
	$conversion=new CurrencyConvert($rate,$rounding,$roundType,$nbDecimal,$idFrom,$idTo);
	echo '<H2>Result :</h2>';
	echo "<ul><li>Conversion from $value in '$idFrom' to a value in '$idTo': ";
	echo $conversion->getValue($value)."<br>\n";
	echo " ( getStringValue($value) = ".$conversion->getStringValue($value)." )<br>\n";
	echo '</ul>';
	echo '<ul><li>PHP code : <pre>';
	echo "object = new CurrencyConvert('$rate','$rounding','$roundType','$nbDecimal','$idFrom','$idTo');";
	echo '</pre></ul>';
	} 
?>

<H2>Enter your choice :</h2>
<form action="<? echo $PHP_SELF; ?>" method="POST">
<table cellspacing="2" cellpadding="2" border="0">
<tr>
	<!-- ================================ -->
    <td align="right">Value : </td>
<?
	if (isset($show)):
?>
    <td><input type="Text" name="value" value="<? echo $value; ?>"></td>
<?
	else :
?>
    <td><input type="Text" name="value" ></td>
<?	
	endif; 
?>
    <td>Sample value to convert</td>
</tr>
<tr>
	<!-- ================================ -->
    <td align="right">ID of SOURCE currency : </td>
<?
	if (isset($show)):
?>
    <td><input type="Text" name="idFrom" value="<? echo $idFrom; ?>" size="10"></td>
<?
	else :
?>
    <td><input type="Text" name="idFrom" value="FF" size="10"></td>
<?	
	endif; 
?>
    <td>Name ot the currency to convert</td>
</tr>
<tr>
	<!-- ================================ -->
    <td align="right">ID of TARGET currency : </td>
<?
	if (isset($show)):
?>
    <td><input type="Text" name="idTo" value="<? echo $idTo; ?>" size="10"></td>
<?
	else :
?>
    <td><input type="Text" name="idTo" value="Euro" size="10"></td>
<?	
	endif; 
?>
    <td>Name of the currency to which the value is converted</td>
</tr>
<tr>
$roundType,$nbDecimal
	<!-- ================================ -->
    <td align="right">Exchange rate : </td>
<?
	if (isset($show)):
?>
    <td><input type="Text" name="rate" value="<? echo $rate; ?>" size="8"></td>
<?
	else :
?>
    <td><input type="Text" name="rate" value="6.55957" size="8"></td>
<?	
	endif; 
?>
    <td>= (SOURCE currency) / (TARGET currency)</td>
</tr>
<tr>
	<!-- ================================ -->
    <td align="right">Rounding : </td>
<?
	if (isset($show)):
?>
    <td><input type="Text" name="rounding" value="<? echo $rounding; ?>" size="6"></td>
<?
	else :
?>
    <td><input type="Text" name="rounding" size="6" value="0.01"></td>
<?	
	endif; 
?>
    <td>Factor used to get rounded values. When used with powers of 10, (0.1, 0.01, ...) it correspond to the number of decimal digits to display.
	</td>
</tr>
<tr>
	<!-- ================================ -->
    <td align="right">Kind of rounding : </td>
    <td>
<?
	if (isset($show)):
?>
	<select name="roundType">
			<option value="0"<? if ($roundType=='0') echo ' selected ';?>>Inferior rounding</option>
	   		<option value="1"<? if ($roundType=='1') echo ' selected ';?>>Normal rounding</option>
	   		<option value="2"<? if ($roundType=='2') echo ' selected ';?>>Superior rounding</option>
		   	<option value="3"<? if ($roundType=='3') echo ' selected ';?>>None</option>
	</select>
<?
	else :
?>
	<select name="roundType">
			<option value="0">Inferior rounding</option>
	   		<option value="1" selected>Normal rounding</option>
	   		<option value="2">Superior rounding</option>
		   	<option value="3">None</option>
	</select>
<?	
	endif; 
?>
	</td>
    <td>Allow to finely adjust the final conversion value.<br>For example you might want to get a rounded value to the 0.5 DM above the computed value.</td>
</tr>
<tr>
	<!-- ================================ -->
    <td align="right">Decimals : </td>
<?
	if (isset($show)):
?>
    <td><input type="Text" name="nbDecimal" value="<? echo $nbDecimal; ?>" size="1"></td>
<?
	else :
?>
    <td><input type="Text" name="nbDecimal" value="2" size="1"></td>
<?	
	endif; 
?>
    <td>Number of displayed decimals (can be 0)<br>Only used for getStringValue()</td>
</tr>
<tr>
    <td align="right"></td>
    <td align="right"><input type="Submit" name="show" value="Show"></td>
    <td></td>
</tr>
</table>
</form>
</body>
</html>