Currency Conversion
Categories
Component ID
Component name
Component type
Maintenance status
Development status
Component security advisory coverage
Component created
Component changed
Component body
Currency change without using any Drupal commerce module
<?php
error_reporting(E_ALL ^ E_NOTICE);
/**
** Implementation of hook_permission().
**/
function currencycode_permission() {
// Restrict access to either of your new URLs.
return array(
'access currencycode' => array(
'title' => t('access currencycode'),
'description' => t('Allow users to access currencycode'),
),
);
}
/****
** hook_block_info()
****/
function currencycode_block_info() {
$blocks['executive_sidebar'] = array(
'info' => t('curr del'),
);
return $blocks;
}
/****
** hook_block_view()
****/
function currencycode_block_view($delta) {
$blocks = array();
//delta is your block name. then just set it equal to your return functions.
switch ($delta) {
case 'executive_sidebar':
$blocks['subject'] = '';
$blocks['content'] = drupal_get_form('currency_form');
break;
}
return $blocks;
}
function currency($from_Currency,$to_Currency,$amount) {
$amount = urlencode($amount);
$from_Currency = urlencode($from_Currency);
$to_Currency = urlencode($to_Currency);
$url = "http://www.google.com/ig/calculator?hl=en&q=$amount$from_Currency=?$to_Currency";
$ch = curl_init();
$timeout = 0;
curl_setopt ($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_USERAGENT , "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1)");
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
$rawdata = curl_exec($ch);
curl_close($ch);
$data = explode('"', $rawdata);
$data = explode(' ', $data['3']);
$var = $data['0'];
return round($var,3);
}
/***this.form.submit();'#default_value' => '4',
* function to
***/
function currency_form() {
$geoPlugin_array = unserialize( file_get_contents('http://www.geoplugin.net/php.gp?ip=' . $_SERVER['REMOTE_ADDR']) );
$curr=$geoPlugin_array['geoplugin_currencyCode'];
//echo "
";
//print_r(currency_optionsto());
//$form = array();
$form['category1'] = array(
'#type' => 'select',
'#title' => t(''),
'#options' => currency_optionsto(),
'#attributes' => array('onchange' => 'this.form.submit();'),
'#id' => 'jay'
);
$form['location'] = array(
'#type' => 'hidden',
'#size' => 40,
'#value' =>$_SESSION['loc'],
);
$form['#action'] ='';
$TO=$_POST['category1'];
//echo currency("USD",$TO,1);
return $form;
}
/*function currency_form_submit($form, &$form_state) {
echo "dsdfg";
print_r($form_state);
exit;
}*/
function currency_optionsto(){
$options = array();
$options =Array
(
'ARS' => t('ARS'),
'AUD' => t('AUD'),
'BRL' => t('BRL'),
'CHF' => t('CAD'),
'CNY' => t('CNY'),
'CZK' => t('CZK'),
'DKK' => t('DKK'),
'EUR' => t('EUR'),
'GBP' => t('GBP'),
'HKD' => t('HKD'),
'HUF' => t('HUF'),
'IDR' => t('IDR'),
'ILS' => t('ILS'),
'INR' => t('INR'),
'JPY' => t('JPY'),
'KRW' => t('KRW'),
'MYR' => t('MYR'),
'MXN' => t('MXN'),
'NOK' => t('NOK'),
'NZD' => t('NZD'),
'PHP' => t('PHP'),
'PLN' => t('PLN'),
'RUB' => t('RUB'),
'SEK' => t('SEK'),
'SGD' => t('SGD'),
'THB' => t('THB'),
'TRY' => t('TRY'),
'TWD' => t('TWD'),
'AUD' => t('AUD'),
'BRL' => t('BRL'),
'USD' => t('USD'),
'VND' => t('VND'),
'ZAR' => t('ZAR'),
);
return $options;
}