|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
thenewhiking Smarty n00b
Joined: 26 Sep 2004 Posts: 1
|
Posted: Sun Sep 26, 2004 8:16 pm Post subject: New Function: currency Converter |
|
|
i just finished make currency converter for smarty i hope everyone here can review this function
thanks
Code: |
<?php
/*
* Smarty plugin
* -------------------------------------------------------------
* File: function.currency_converter.php
* Type: function
* Name: Currency Converter
* Purpose: Convert one currency to another currency
* example
* php 4
* for windows -> {currency_converter from=usa to=indonesia amount=1 nusoap_path='D:/Program Files/Apache Group/Apache/htdocs/smarty'}
* for linux ,freebsd, *nix -> {currency_converter from=usa to=indonesia amount=1 nusoap_path='/var/html/smarty'}
* php 5.0.2 or higher
* {currency_converter from=usa to=indonesia amount=1}
* @author dadan ramdan (thenewhiking@yahoo.com)
* Dependencies nusoap.php download from http://dietrich.ganx4.com/nusoap
* @version 1.0
*country
usa
euro
canada
uk
germany
france
japan
italy
switzerland
algeria
argentina
australia
austria
bermuda
brazil
chile
china
denmark
finland
greece
hong kong
india
indonesia
ireland
israel
jamaica
jordan
korea
mexico
pakistan
philippines
poland
portugal
russia
saudi arabia
slovakia
south africa
south korea
south africa
spain
sudan
sweden
* -------------------------------------------------------------
*/
function smarty_function_currency_converter($params, &$smarty) {
//path to nusoap
foreach ($params as $_key=>$_value) {
$__curconvamount=1;
switch ($_key) {
case 'from':
$__curconvfrom=$_value;
break;
case 'to':
$__curconvto=$_value;
break;
case 'amount':
$__curconvamount=$_value;
break;
case 'nusoap_path':
$_soappath=$_value;
break;
}
}
if ($_soappath =="") {
$smarty->trigger_error("assign: missing 'nusoap_path' parameter");
return;
}
$slorfive=0;
if ((version_compare(phpversion(), "5.0.2", "ge"))) {
////for php 5.0.2 or > 5.0.2
$ldext=get_loaded_extensions();
foreach( $ldext as $subElement ) {
if ($subElement =="soap") {
$slorfive=1;
}
}
if ($slorfive == 1) {
$_curnconvsslient = new SoapClient("http://www.xmethods.net/sd/CurrencyExchangeService.wsdl");
$_curconvresult=$_curnconvsslient->getRate($__curconvfrom,$__curconvto);
$hasil= ($__curconvamount * $_curconvresult);
} else {
echo "Soap Module Not Load<br>"; exit;
}
} else {
if ((version_compare(phpversion(), "5.0.2", "<"))) {
//for php < 5.0.2
//$curval1 = $from;
//$curval2 = $to;
//$amount = $amount;
$_nusoap=$_soappath."/nusoap.php";
require_once($_nusoap);
$_curconvparams1 = array(
'country1' => $__curconvfrom,
'country2' => $__curconvto
);
$_curnconvsslient = new soapclient('http://www.xmethods.net/sd/CurrencyExchangeService.wsdl','wsdl');
$_curconvresult = $_curnconvsslient->call('getRate',$_curconvparams1);
$hasil= ($__curconvamount * $_curconvresult );
}
}
return $hasil;
}
?>
|
|
|
Back to top |
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|