Index: currency/INSTALL.txt
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/currency/INSTALL.txt,v
retrieving revision 1.2
diff -u -r1.2 INSTALL.txt
--- currency/INSTALL.txt	24 Sep 2005 17:30:53 -0000	1.2
+++ currency/INSTALL.txt	28 Jun 2006 01:51:08 -0000
@@ -1,34 +1,33 @@
-Description:
-------------
-	
-This module provides visitors to your web site with currency conversion rates.
-
-It also provides an API for currency conversion that other modules can use.
-
-Requirements:
--------------
-	
-This module requires drupal 4.5.x or greater.
-
-Installation:
--------------
-
-1. Copy the entire currency directory under the Drupal modules/ directory.
-
-2. Go to admin/modules and enable 'currency_api' and 'currency'.
-
-3. Allow access to the module under admin/user/configure/permission (4.5) or
-   admin/access (4.6).
-   You can enable it for authenticated and/or anonymous users, depending on
-   your web site needs.
-
-4. Configure the module under admin/settings/currency
-   - Specify the default From Currency and the To Currency. You must enter the 
-     three letter code for each. What you enter depends on your country and/or
-     audience.
-
-   - Provide a description. It can be any text you want. You can enter a disclaimer,
-     instructions, ...etc.
-
-   - You can change the navigation link text if you want. Normally leave that as
-     it is.
+Description:
+------------
+	
+This module provides visitors to your web site with currency conversion rates.
+
+It also provides an API for currency conversion that other modules can use.
+
+Requirements:
+-------------
+	
+This module requires drupal 4.7.x or greater.
+
+Installation:
+-------------
+
+1. Copy the entire currency directory under the Drupal modules/ directory.
+
+2. Go to admin/modules and enable 'currency_api' and 'currency'.
+
+3. Allow access to the module under admin/access.
+   You can enable it for authenticated and/or anonymous users, depending on
+   your web site needs.
+
+4. Configure the module under admin/settings/currency
+   - Specify the default From Currency and the To Currency. You must enter the 
+     three letter code for each. What you enter depends on your country and/or
+     audience.
+
+   - Provide a description. It can be any text you want. You can enter a disclaimer,
+     instructions, ...etc.
+
+   - You can change the navigation link text if you want. Normally leave that as
+     it is.
Index: currency/README.txt
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/currency/README.txt,v
retrieving revision 1.6
diff -u -r1.6 README.txt
--- currency/README.txt	24 Sep 2005 17:30:53 -0000	1.6
+++ currency/README.txt	28 Jun 2006 01:51:08 -0000
@@ -1,50 +1,50 @@
-$Id: README.txt,v 1.6 2005/09/24 17:30:53 kbahey Exp $
-
-Copyright 2005 http://2bits.com
-
-Description:
-------------
-
-This module provides visitors to your web site with currency conversion rates.
-
-It also provides a callable API for currency conversion that other modules can
-use.
-
-It relies on Yahoo! Finance for getting the currency exchange data.
-
-Features:
----------
-
-This module provides several options that customize its look and feel:
-
-* An overview section on the top of the page can contain any text you want
-* Users can enter an amount, and that amount will calculated in the target
-  currency.
-* Provides a link to a detailed history and chart page on Yahoo Finance.
-* All currency conversion operations are logged to the watchdog (optional).
-* Provides a callable API for other modules to do currency exchange calculations.
-  See currency_api/API.txt for details.
-
-Database:
----------
-No database changes are required for this module.
-
-Installation:
--------------
-Please see the INSTALL.txt document for details.
-
-Bugs/Features/Patches:
-----------------------
-If you want to report bugs, feature requests, or submit a patch, please do so
-at the project page on the Drupal web site.
-http://drupal.org/project/currency
-
-Author
-------
-Khalid Baheyeldin (http://baheyeldin.com/khalid and http://2bits.com)
-
-If you use this module, find it useful, and want to send the author
-a thank you note, then use the Feedback/Contact page at the URL above.
-
-The author can also be contacted for paid customizations of this
-and other modules.
+$Id: README.txt,v 1.6 2005/09/24 17:30:53 kbahey Exp $
+
+Copyright 2005 http://2bits.com
+
+Description:
+------------
+
+This module provides visitors to your web site with currency conversion rates.
+
+It also provides a callable API for currency conversion that other modules can
+use.
+
+It relies on Yahoo! Finance for getting the currency exchange data.
+
+Features:
+---------
+
+This module provides several options that customize its look and feel:
+
+* An overview section on the top of the page can contain any text you want
+* Users can enter an amount, and that amount will calculated in the target
+  currency.
+* Provides a link to a detailed history and chart page on Yahoo Finance.
+* All currency conversion operations are logged to the watchdog (optional).
+* Provides a callable API for other modules to do currency exchange calculations.
+  See currency_api/API.txt for details.
+
+Database:
+---------
+No database changes are required for this module.
+
+Installation:
+-------------
+Please see the INSTALL.txt document for details.
+
+Bugs/Features/Patches:
+----------------------
+If you want to report bugs, feature requests, or submit a patch, please do so
+at the project page on the Drupal web site.
+http://drupal.org/project/currency
+
+Author
+------
+Khalid Baheyeldin (http://baheyeldin.com/khalid and http://2bits.com)
+
+If you use this module, find it useful, and want to send the author
+a thank you note, then use the Feedback/Contact page at the URL above.
+
+The author can also be contacted for paid customizations of this
+and other modules.
Index: currency/currency.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/currency/currency.module,v
retrieving revision 1.6
diff -u -r1.6 currency.module
--- currency/currency.module	24 Sep 2005 17:30:53 -0000	1.6
+++ currency/currency.module	28 Jun 2006 01:51:09 -0000
@@ -5,43 +5,65 @@
 // Copyright 2005 Khalid Baheyeldin http://2bits.com
 
 function currency_help($section) {
-  $output ="";
+  $output = '';
 
   switch ($section) {
     case 'admin/modules#description':
-      $output = t("Currency conversion page. Requires currency_api.");
+      $output = t('Currency conversion page. Requires currency_api.');
       break;
+      
     case 'admin/help#currency':
     case 'admin/settings/currency':
-      $output = t("This module provides currency conversion rates.");
+      $output = t('This module provides currency conversion rates.');
       break;
   }
 
   return $output;
 }
   
-function currency_settings() {
-  $output .= form_textfield(t("Default Currency From"), "currency_default_from",
-    variable_get("currency_default_from", 'CAD'), 3, 3,
-    t('Three letter symbol for default currency to convert from.'));
-
-  $output .= form_textfield(t("Default Currency To"), "currency_default_to",
-    variable_get("currency_default_to",   'USD'), 3, 3,
-    t('Three letter symbol for default currency to convert to.'));
-
-  $output .= form_textarea(t("Description"), "currency_description",
-    variable_get("currency_description", t("This is the currency conversion page.")), 70, 7,
-    t('This text will be displayed at the top of the currency conversion page'));
-
-  $output .= form_textfield(t("Navigation link text"), "currency_overview_title",
-    variable_get("currency_overview_title", t("currency conversion")), 35, 255,
-    t("The text in the navigation link which points to the currency conversion page."));  
+function currency_settings() {  
+  
+  $form['currency_default_from'] = array(
+    '#type' => 'textfield',
+    '#title' => t('Default Currency From'),
+    '#default_value' => variable_get('currency_default_from', 'CAD'),
+    '#size' => 3,
+    '#maxlength' => 3,
+    '#description' => t('Three letter symbol for default currency to convert from.'),
+  );
+  
+  $form['currency_default_to'] = array(
+    '#type' => 'textfield',
+    '#title' => t('Default Currency To'),
+    '#default_value' => variable_get('currency_default_to', 'USD'),
+    '#size' => 3,
+    '#maxlength' => 3,
+    '#description' => t('Three letter symbol for default currency to convert to.'),
+  );
+  
+  $form['currency_description'] = array(
+    '#type' => 'textarea',
+    '#title' => t('Description'),
+    '#default_value' =>  variable_get('currency_description', t('This is the currency conversion page.')),
+    '#cols' => 70,
+    '#rows' => 7,
+    '#description' => t('This text will be displayed at the top of the currency conversion page'),
+  );
+  
+  $form['currency_overview_title'] = array(
+    '#type' => 'textfield',
+    '#title' => t('Navigation link text'),
+    '#default_value' => variable_get('currency_overview_title', t('currency conversion')),
+    '#size' => 35,
+    '#maxlength' => 255,
+    '#description' => t('The text in the navigation link which points to the currency conversion page.'),
+  ); 
 
-  return $output;
+  return $form;
 }  
 
 function currency_perm() {
-  return array ("use currency");
+  return array ('use currency');
 }
 
 function currency_link($type, $node = 0, $main = 0) {
@@ -50,7 +72,7 @@
   $links = array();
 
   if ($type == 'page' && user_access('use currency')) {
-          $links[] = l(t('currency'), 'currency');
+    $links[] = l(t('currency'), 'currency');
   }
 
   return $links;
@@ -60,110 +82,130 @@
   $items = array();
 
   $access = user_access('use currency');
-  $title  = t(variable_get("currency_overview_title", "currency conversion"));
+  $title  = t(variable_get('currency_overview_title', 'currency conversion'));
   $path   = 'currency';
 
   $items[] = array(
-	 'path'     => $path,
-	 'title'    => $title,
-	 'access'   => $access,
-   'callback' => 'currency_page',
-   'weight'   => 0 );
+    'path'     => $path,
+    'title'    => $title,
+    'access'   => $access,
+    'callback' => 'currency_page',
+    'weight'   => 0,
+  );
 
   return $items;
 }
 
 // Display the currency page
 function currency_page() {
-  $output = currency_contents ();
+  $output = currency_contents();
 
-  print theme("page", $output );
+  return $output;
 }
 
 // Display the form
 function currency_form() {
- 
- $edit = $_POST['edit'];
-
- $from   = $edit['currency_from'];
- $to     = $edit['currency_to'];
- $amount = $edit['currency_amount'];
-
- if (!isset($from)) {
-   $from = variable_get('currency_default_from', 'CAD');
- }
+  $edit   = isset($_POST['edit']) ? $_POST['edit'] : '';
+  $from   = $edit['currency_from'];
+  $to     = $edit['currency_to'];
+  $amount = $edit['currency_amount'];
 
- if (!isset($to)) {
-   $to = variable_get('currency_default_to', 'USD');
- }
-
- if (!isset($amount)) {
-   $amount = 1;
- }
-
- if (!is_numeric($amount)) {
-   $amount = 1;
- }
+  if (empty($from)) {
+    $from = variable_get('currency_default_from', 'CAD');
+  }
 
- $output .= form_textfield(t('Amount'), 'currency_amount', $amount, 9, 9, t('Amount to convert'));
- $output .= form_select   (t('From'),   'currency_from', $from, currency_api_get_list());
- $output .= form_select   (t('To'),     'currency_to',   $to,   currency_api_get_list());
- $output .= form_submit   (t('Convert'),'button_convert');
+  if (empty($to)) {
+    $to = variable_get('currency_default_to', 'USD');
+  }
 
- $form = form($output);
+  if (!isset($amount)) {
+    $amount = 1;
+  }
 
- return $form;
+  if (!is_numeric($amount)) {
+    $amount = 1;
+  }
+ 
+  $form['currency_amount'] = array(
+    '#type' => 'textfield',
+    '#title' => t('Amount'),
+    '#default_value' => $amount,
+    '#size' => 9,
+    '#maxlength' => 9, 
+    '#description' => t('Amount to convert'), 
+  );
+  
+  $form['currency_from'] = array(
+    '#type' => 'select',
+    '#title' => t('From'),
+    '#default_value' => $from,
+    '#options' => currency_api_get_list(),    
+  );
+  
+  $form['currency_to'] = array(
+    '#type' => 'select',
+    '#title' => t('To'),
+    '#default_value' => $to,
+    '#options' => currency_api_get_list(),    
+  );
+       
+  $form['button_convert'] = array(
+    '#type' => 'button',
+    '#input' => TRUE,
+    '#name' => 'op',
+    '#button_type' => 'submit',
+    '#value' => t('Convert'),
+    '#execute' => TRUE,
+  ); 
+    
+  $form['#method'] = 'post';
+  
+  return drupal_get_form('stock_form', $form);
 }
 
 
 function currency_contents() {
+  $op = isset($_POST['op']) ? $_POST['op'] : '';
+  $edit   = isset($_POST['edit']) ? $_POST['edit'] : '';
+  $amount = $edit['currency_amount'];
+  $from   = strtoupper($edit['currency_from']);
+  $to     = strtoupper($edit['currency_to']);
 
- $edit = $_POST['edit'];
-
- $amount = $edit['currency_amount'];
- $from   = strtoupper($edit['currency_from']);
- $to     = strtoupper($edit['currency_to']);
-
- if (($amount != "") AND (!is_numeric($amount))) {
-   drupal_set_message(t('Invalid Amount. Please enter a number'), 'error');
- }
- else {
-   $output .= variable_get("currency_description", "This is the currency conversion page.");
-   if (isset($_POST['button_convert'])) {
- 	   $output .= currency_do_quote($from, $to, $amount);
-   }
- }
+  if (($amount != "") AND (!is_numeric($amount))) {
+    drupal_set_message(t('Invalid Amount. Please enter a number'), 'error');
+  }
+  else {
+    $output .= variable_get('currency_description', 'This is the currency conversion page.');
+    if ($op == t('Convert')) {
+      $output .= currency_do_quote($from, $to, $amount);
+    }
+  }
 
- $output .= currency_form();
+  $output .= currency_form();
 
- return $output ;
+  return $output;
 }
 
-function currency_detailed_quote ( $currency_from, $currency_to ) {
- 
- $full_quote_url = 'http://finance.yahoo.com/q?s=';
- 
- 
- $url = $full_quote_url . $currency_from . $currency_to . '=X';
+function currency_detailed_quote($currency_from, $currency_to) { 
+  $full_quote_url = 'http://finance.yahoo.com/q?s=';
+  
+  $url = $full_quote_url . $currency_from . $currency_to . '=X';
 
- return '<a target="_blank" title="'.
-   t('History and Chart').'" href="'.$url.'">'.t('Detailed history and chart').'</a>';
+  return l(t('Detailed history and chart'), $url, array('title' => t('History and Chart'), 'target' => '_blank'), NULL, NULL, TRUE);  
 }
 
-function currency_do_quote( $currency_from, $currency_to, $amount = 1 ) {
+function currency_do_quote($currency_from, $currency_to, $amount = 1) {
   $ret = currency_api_convert($currency_from, $currency_to, $amount);
+  
   if ($ret['status'] == FALSE) { 
     drupal_set_message(t('currency conversion error: ') . $ret['message']);
- 	}
- 	else {
-    $result .= '<p>'. $amount .' '.
-      currency_api_get_desc($currency_from) .' = '. $ret['value'] .' '.
-      currency_api_get_desc($currency_to) . '</p>';
-
-    $result .= '<p>'. currency_detailed_quote($currency_from, $currency_to).'</p>';
- 	}
-
- return $result;
+  }
+  else {
+    $result .= '<p>'. $amount .' '. currency_api_get_desc($currency_from) .' = '. $ret['value'] .' '. currency_api_get_desc($currency_to) .'</p>';
+    $result .= '<p>'. currency_detailed_quote($currency_from, $currency_to) .'</p>';
+  }
+  
+  return $result;
 }
 
 ?>
Index: currency/currency_api/API.txt
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/currency/currency_api/API.txt,v
retrieving revision 1.1
diff -u -r1.1 API.txt
--- currency/currency_api/API.txt	24 Sep 2005 17:30:53 -0000	1.1
+++ currency/currency_api/API.txt	28 Jun 2006 01:51:09 -0000
@@ -1,75 +1,75 @@
-The currency module provides two callable API functions that allow other
-modules to do real time currency exchange.
-
-The functions are:
-
-function currency_api_exchange($currency_from, $currency_to, $amount = 1)
-
- * This function converts two currencies using exchange rates from Yahoo Finance.
- * The currency codes are standard ISO 3-letter codes, and you can find the details
- * here:
- *  http://www.oanda.com/site/help/iso_code.shtml
- *
- * Here is an example on how to use it:
- *
- *   $from = 'CAD';
- *   $to   = 'USD';
- *   $amt  = 20;
- *   $ret = currency_exchange($from, $to, $amt);
- *   if ($ret['status'] == FALSE)
- *   {
- *     drupal_set_message(t('An error occured: '). $ret['message']);
- *   }
- *   else
- *   {
- *     print $amt .' '. $from .' = '. $ret['value'];
- *   }
- *
- * @param $currency_from
- *   Currency to convert from
- *
- * @param $currency_to
- *   Currency to convert to
- *
- * @param $amount
- *   Option amount to convert. If not supplied, 1 is assumed.
- *
- * @return $result
- *   An associative array that contains the following:
- *    $result['status'] TRUE or FALSE
- *    $result['message']'success' when status is TRUE, otherwise, contains a 
- *                      descriptive error text
- *   The following items are only returned when status is TRUE
- *    $result['value']  $amount * exchange rate of $currency_from into $currency_to
- *    $result['date']   Date of the last update to the rates (Format is "m/d/yyyy")
- *    $result['time']   Time of the last update to the rates (Format is "h:mmpm")
-
-function currency_api_get_desc($currency)
-
- * This function gets the currency name for a standard ISO 3-letter codes,
- * You can find the details here:
- *  http://www.oanda.com/site/help/iso_code.shtml
- *
- * Here is an example on how to use it:
- *
- *   $ccode = 'CAD';
- *   $ret = currency_get_description($ccode);
- *   if ($ret == FALSE)
- *   {
- *     drupal_set_message(t('Could not get description'));
- *   }
- *   else
- *   {
- *     print $ccode .' => '. $ret;
- *   }
- *
- * @param $currency
- *   Currency code (3-letter ISO)
- *
- * @return $result
- *   Contains FALSE if the currency cannot be found, otherwise, it
- *   has the description.
-
-function currency_api_get_list()
-
- * Returns a list of supported currencies
+The currency module provides two callable API functions that allow other
+modules to do real time currency exchange.
+
+The functions are:
+
+function currency_api_exchange($currency_from, $currency_to, $amount = 1)
+
+ * This function converts two currencies using exchange rates from Yahoo Finance.
+ * The currency codes are standard ISO 3-letter codes, and you can find the details
+ * here:
+ *  http://www.oanda.com/site/help/iso_code.shtml
+ *
+ * Here is an example on how to use it:
+ *
+ *   $from = 'CAD';
+ *   $to   = 'USD';
+ *   $amt  = 20;
+ *   $ret = currency_exchange($from, $to, $amt);
+ *   if ($ret['status'] == FALSE)
+ *   {
+ *     drupal_set_message(t('An error occured: '). $ret['message']);
+ *   }
+ *   else
+ *   {
+ *     print $amt .' '. $from .' = '. $ret['value'];
+ *   }
+ *
+ * @param $currency_from
+ *   Currency to convert from
+ *
+ * @param $currency_to
+ *   Currency to convert to
+ *
+ * @param $amount
+ *   Option amount to convert. If not supplied, 1 is assumed.
+ *
+ * @return $result
+ *   An associative array that contains the following:
+ *    $result['status'] TRUE or FALSE
+ *    $result['message']'success' when status is TRUE, otherwise, contains a 
+ *                      descriptive error text
+ *   The following items are only returned when status is TRUE
+ *    $result['value']  $amount * exchange rate of $currency_from into $currency_to
+ *    $result['date']   Date of the last update to the rates (Format is "m/d/yyyy")
+ *    $result['time']   Time of the last update to the rates (Format is "h:mmpm")
+
+function currency_api_get_desc($currency)
+
+ * This function gets the currency name for a standard ISO 3-letter codes,
+ * You can find the details here:
+ *  http://www.oanda.com/site/help/iso_code.shtml
+ *
+ * Here is an example on how to use it:
+ *
+ *   $ccode = 'CAD';
+ *   $ret = currency_get_description($ccode);
+ *   if ($ret == FALSE)
+ *   {
+ *     drupal_set_message(t('Could not get description'));
+ *   }
+ *   else
+ *   {
+ *     print $ccode .' => '. $ret;
+ *   }
+ *
+ * @param $currency
+ *   Currency code (3-letter ISO)
+ *
+ * @return $result
+ *   Contains FALSE if the currency cannot be found, otherwise, it
+ *   has the description.
+
+function currency_api_get_list()
+
+ * Returns a list of supported currencies
Index: currency/currency_api/currency_api.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/currency/currency_api/currency_api.module,v
retrieving revision 1.1
diff -u -r1.1 currency_api.module
--- currency/currency_api/currency_api.module	24 Sep 2005 17:30:53 -0000	1.1
+++ currency/currency_api/currency_api.module	28 Jun 2006 01:51:09 -0000
@@ -9,22 +9,25 @@
 
   switch ($section) {
     case 'admin/modules#description':
-      $output = t("Currency Conversion API");
+      $output = t('Currency Conversion API');
       break;
     case 'admin/help#currency_api':
     case 'admin/settings/currency_api':
-      $output = t("This module provides an API for currency conversion.");
+      $output = t('This module provides an API for currency conversion.');
       break;
   }
 
   return $output;
 }
   
-function currency_api_settings() {
-  $output .= form_checkbox (t("Log all currency conversions and errors to watchdog"),
-    "currency_watchdog", 1, variable_get("currency_api_watchdog", "1"));
+function currency_api_settings() {    
+  $form['currency_api_watchdog'] = array(
+    '#type' => 'checkbox',
+    '#title' => t('Log all currency conversions and errors to watchdog'),    
+    '#default_value' => variable_get('currency_api_watchdog'),    
+  );
 
-  return $output;
+  return $form;
 }  
 
 /**
@@ -69,57 +72,54 @@
  *    $result['date']   Date of the last update to the rates (Format is "m/d/yyyy")
  *    $result['time']   Time of the last update to the rates (Format is "h:mmpm")
  */
-function currency_api_convert($currency_from, $currency_to, $amount = 1)
-{
- $currency_array = array
-	(
-	's'  => 'Currencies',
-	'l1' => 'Last',
-	'd1' => 'Date',
-	't1' => 'Time'
-	);
-
- $result = array();
- $result['status']  = FALSE;
- $result['message'] = '';
- $result['value']   = '';
- $result['date']    = '';
- $result['time']    = '';
-
- $from = strtoupper($currency_from);
- $to   = strtoupper($currency_to);
-
- $url = "http://finance.yahoo.com/d/quotes.csv?e=.csv&f=" .
-   currency_api_get_fields($currency_array) . "&s=". $from . $to ."=X";
-
- // Validate the passed currency codes, to make sure they are valid
- if (FALSE == currency_api_get_desc($from)) {
-   $msg = "currency: Invalid currency_from=$from";
-   _log_to_watchdog($msg, WATCHDOG_ERROR);
-   $result['message'] = $msg;
-   $result['status'] = FALSE;
- }
-
- if (FALSE == currency_api_get_desc($currency_to)) {
-   $msg = "currency: Invalid currency_to=$to";
-   _log_to_watchdog($msg, WATCHDOG_ERROR);
-   return FALSE;
-   $result['message'] = $msg;
-   $result['status'] = FALSE;
- }
-
- if (!is_numeric($amount)) {
-   $msg = "currency: Invalid amount=$amount";
-   _log_to_watchdog($msg, WATCHDOG_ERROR);
-   $result['message'] = $msg;
-   $result['status'] = FALSE;
- }
-
- $handle = @fopen($url, 'r');
- if ($handle) {
-	  if ($record = fgets($handle, 4096)) {
-		  fclose($handle);
-		  $currency_data = explode(',', $record);
+function currency_api_convert($currency_from, $currency_to, $amount = 1) {
+  $currency_array = array(
+    's'  => 'Currencies',
+    'l1' => 'Last',
+    'd1' => 'Date',
+    't1' => 'Time'
+  );
+
+  $result = array();
+  $result['status']  = FALSE;
+  $result['message'] = '';
+  $result['value']   = '';
+  $result['date']    = '';
+  $result['time']    = '';
+
+  $from = strtoupper($currency_from);
+  $to   = strtoupper($currency_to);
+
+  $url = 'http://finance.yahoo.com/d/quotes.csv?e=.csv&f='. currency_api_get_fields($currency_array) .'&s='. $from . $to .'=X';
+
+  // Validate the passed currency codes, to make sure they are valid
+  if (FALSE == currency_api_get_desc($from)) {
+    $msg = "currency: Invalid currency_from=$from";
+    _log_to_watchdog($msg, WATCHDOG_ERROR);
+    $result['message'] = $msg;
+    $result['status'] = FALSE;
+  }
+
+  if (FALSE == currency_api_get_desc($currency_to)) {
+    $msg = "currency: Invalid currency_to=$to";
+    _log_to_watchdog($msg, WATCHDOG_ERROR);
+    return FALSE;
+    $result['message'] = $msg;
+    $result['status'] = FALSE;
+  }
+
+  if (!is_numeric($amount)) {
+    $msg = "currency: Invalid amount=$amount";
+    _log_to_watchdog($msg, WATCHDOG_ERROR);
+    $result['message'] = $msg;
+    $result['status'] = FALSE;
+  }
+
+  $handle = @fopen($url, 'r');
+  if ($handle) {
+    if ($record = fgets($handle, 4096)) {
+      fclose($handle);
+      $currency_data = explode(',', $record);
       $rate = $currency_data[1];
       $date = $currency_data[2];
       $time = $currency_data[3];
@@ -138,20 +138,20 @@
       $result['message']= 'success';
     }
     else {
-      $msg = "currency: fgets failed";
+      $msg = 'currency: fgets failed';
       _log_to_watchdog($msg, WATCHDOG_ERROR);
       $result['status'] = FALSE;
       $result['message'] = $msg;
     }
- }
- else {
-   $msg = "currency: cannot contact Yahoo Finance host";
-   _log_to_watchdog($msg, WATCHDOG_ERROR);
-   $result['status'] = FALSE;
-   $result['message'] = $msg;
- }
+  }
+  else {
+    $msg = 'currency: cannot contact Yahoo Finance host';
+    _log_to_watchdog($msg, WATCHDOG_ERROR);
+    $result['status'] = FALSE;
+    $result['message'] = $msg;
+  }
 
- return $result;
+  return $result;
 }
 
 
@@ -183,194 +183,189 @@
  *   has the description.
  */
 function currency_api_get_desc($currency) {
-  foreach ( currency_api_get_list() as $key => $description) {
+  foreach (currency_api_get_list() as $key => $description) {
     if ($key == $currency) {
       return $description;
     }
   }
+  
   return FALSE;
 }
 
 function currency_api_get_list() {
-
-$currency = array (
-  'AFA' => t('Afghanistan Afghani (AFA)'),
-  'ALL' => t('Albanian Lek (ALL)'),
-  'DZD' => t('Algerian Dinar (DZD)'),
-  'ARS' => t('Argentine Peso (ARS)'),
-  'AWG' => t('Aruba Florin (AWG)'),
-  'AUD' => t('Australian Dollar (AUD)'),
-  'BSD' => t('Bahamian Dollar (BSD)'),
-  'BHD' => t('Bahraini Dinar (BHD)'),
-  'BDT' => t('Bangladesh Taka (BDT)'),
-  'BBD' => t('Barbados Dollar (BBD)'),
-  'BYR' => t('Belarus Ruble (BYR)'),
-  'BZD' => t('Belize Dollar (BZD)'),
-  'BMD' => t('Bermuda Dollar (BMD)'),
-  'BTN' => t('Bhutan Ngultrum (BTN)'),
-  'BOB' => t('Bolivian Boliviano (BOB)'),
-  'BWP' => t('Botswana Pula (BWP)'),
-  'BRL' => t('Brazilian Real (BRL)'),
-  'GBP' => t('British Pound (GBP)'),
-  'BND' => t('Brunei Dollar (BND)'),
-  'BGN' => t('Bulgarian Lev (BGN)'),
-  'BIF' => t('Burundi Franc (BIF)'),
-  'KHR' => t('Cambodia Riel (KHR)'),
-  'CAD' => t('Canadian Dollar (CAD)'),
-  'CVE' => t('Cape Verde Escudo (CVE)'),
-  'KYD' => t('Cayman Islands Dollar (KYD)'),
-  'XOF' => t('CFA Franc (BCEAO) (XOF)'),
-  'XAF' => t('CFA Franc (BEAC) (XAF)'),
-  'CLP' => t('Chilean Peso (CLP)'),
-  'CNY' => t('Chinese Yuan (CNY)'),
-  'COP' => t('Colombian Peso (COP)'),
-  'KMF' => t('Comoros Franc (KMF)'),
-  'CRC' => t('Costa Rica Colon (CRC)'),
-  'HRK' => t('Croatian Kuna (HRK)'),
-  'CUP' => t('Cuban Peso (CUP)'),
-  'CYP' => t('Cyprus Pound (CYP)'),
-  'CZK' => t('Czech Koruna (CZK)'),
-  'DKK' => t('Danish Krone (DKK)'),
-  'DJF' => t('Dijibouti Franc (DJF)'),
-  'DOP' => t('Dominican Peso (DOP)'),
-  'XCD' => t('East Caribbean Dollar (XCD)'),
-  'ECS' => t('Ecuador Sucre (ECS)'),
-  'EGP' => t('Egyptian Pound (EGP)'),
-  'SVC' => t('El Salvador Colon (SVC)'),
-  'ERN' => t('Eritrea Nakfa (ERN)'),
-  'EEK' => t('Estonian Kroon (EEK)'),
-  'ETB' => t('Ethiopian Birr (ETB)'),
-  'EUR' => t('Euro (EUR)'),
-  'FKP' => t('Falkland Islands Pound (FKP)'),
-  'FJD' => t('Fiji Dollar (FJD)'),
-  'GMD' => t('Gambian Dalasi (GMD)'),
-  'GHC' => t('Ghanian Cedi (GHC)'),
-  'GIP' => t('Gibraltar Pound (GIP)'),
-  'XAU' => t('Gold Ounces (XAU)'),
-  'GTQ' => t('Guatemala Quetzal (GTQ)'),
-  'GNF' => t('Guinea Franc (GNF)'),
-  'GYD' => t('Guyana Dollar (GYD)'),
-  'HTG' => t('Haiti Gourde (HTG)'),
-  'HNL' => t('Honduras Lempira (HNL)'),
-  'HKD' => t('Hong Kong Dollar (HKD)'),
-  'HUF' => t('Hungarian Forint (HUF)'),
-  'ISK' => t('Iceland Krona (ISK)'),
-  'INR' => t('Indian Rupee (INR)'),
-  'IDR' => t('Indonesian Rupiah (IDR)'),
-  'IRR' => t('Iran Rial (IRR)'),
-  'IQD' => t('Iraqi Dinar (IQD)'),
-  'ILS' => t('Israeli Shekel (ILS)'),
-  'JMD' => t('Jamaican Dollar (JMD)'),
-  'JPY' => t('Japanese Yen (JPY)'),
-  'JOD' => t('Jordanian Dinar (JOD)'),
-  'KZT' => t('Kazakhstan Tenge (KZT)'),
-  'KES' => t('Kenyan Shilling (KES)'),
-  'KRW' => t('Korean Won (KRW)'),
-  'KWD' => t('Kuwaiti Dinar (KWD)'),
-  'LAK' => t('Lao Kip (LAK)'),
-  'LVL' => t('Latvian Lat (LVL)'),
-  'LBP' => t('Lebanese Pound (LBP)'),
-  'LSL' => t('Lesotho Loti (LSL)'),
-  'LRD' => t('Liberian Dollar (LRD)'),
-  'LYD' => t('Libyan Dinar (LYD)'),
-  'LTL' => t('Lithuanian Lita (LTL)'),
-  'MOP' => t('Macau Pataca (MOP)'),
-  'MKD' => t('Macedonian Denar (MKD)'),
-  'MGF' => t('Malagasy Franc (MGF)'),
-  'MWK' => t('Malawi Kwacha (MWK)'),
-  'MYR' => t('Malaysian Ringgit (MYR)'),
-  'MVR' => t('Maldives Rufiyaa (MVR)'),
-  'MTL' => t('Maltese Lira (MTL)'),
-  'MRO' => t('Mauritania Ougulya (MRO)'),
-  'MUR' => t('Mauritius Rupee (MUR)'),
-  'MXN' => t('Mexican Peso (MXN)'),
-  'MDL' => t('Moldovan Leu (MDL)'),
-  'MNT' => t('Mongolian Tugrik (MNT)'),
-  'MAD' => t('Moroccan Dirham (MAD)'),
-  'MZM' => t('Mozambique Metical (MZM)'),
-  'MMK' => t('Myanmar Kyat (MMK)'),
-  'NAD' => t('Namibian Dollar (NAD)'),
-  'NPR' => t('Nepalese Rupee (NPR)'),
-  'ANG' => t('Neth Antilles Guilder (ANG)'),
-  'NZD' => t('New Zealand Dollar (NZD)'),
-  'NIO' => t('Nicaragua Cordoba (NIO)'),
-  'NGN' => t('Nigerian Naira (NGN)'),
-  'KPW' => t('North Korean Won (KPW)'),
-  'NOK' => t('Norwegian Krone (NOK)'),
-  'OMR' => t('Omani Rial (OMR)'),
-  'XPF' => t('Pacific Franc (XPF)'),
-  'PKR' => t('Pakistani Rupee (PKR)'),
-  'XPD' => t('Palladium Ounces (XPD)'),
-  'PAB' => t('Panama Balboa (PAB)'),
-  'PGK' => t('Papua New Guinea Kina (PGK)'),
-  'PYG' => t('Paraguayan Guarani (PYG)'),
-  'PEN' => t('Peruvian Nuevo Sol (PEN)'),
-  'PHP' => t('Philippine Peso (PHP)'),
-  'XPT' => t('Platinum Ounces (XPT)'),
-  'PLN' => t('Polish Zloty (PLN)'),
-  'QAR' => t('Qatar Rial (QAR)'),
-  'ROL' => t('Romanian Leu (ROL)'),
-  'RUB' => t('Russian Rouble (RUB)'),
-  'RWF' => t('Rwanda Franc (RWF)'),
-  'WST' => t('Samoa Tala (WST)'),
-  'STD' => t('Sao Tome Dobra (STD)'),
-  'SAR' => t('Saudi Arabian Riyal (SAR)'),
-  'SCR' => t('Seychelles Rupee (SCR)'),
-  'SLL' => t('Sierra Leone Leone (SLL)'),
-  'XAG' => t('Silver Ounces (XAG)'),
-  'SGD' => t('Singapore Dollar (SGD)'),
-  'SKK' => t('Slovak Koruna (SKK)'),
-  'SIT' => t('Slovenian Tolar (SIT)'),
-  'SBD' => t('Solomon Islands Dollar (SBD)'),
-  'SOS' => t('Somali Shilling (SOS)'),
-  'ZAR' => t('South African Rand (ZAR)'),
-  'LKR' => t('Sri Lanka Rupee (LKR)'),
-  'SHP' => t('St Helena Pound (SHP)'),
-  'SDD' => t('Sudanese Dinar (SDD)'),
-  'SRG' => t('Surinam Guilder (SRG)'),
-  'SZL' => t('Swaziland Lilageni (SZL)'),
-  'SEK' => t('Swedish Krona (SEK)'),
-  'CHF' => t('Swiss Franc (CHF)'),
-  'SYP' => t('Syrian Pound (SYP)'),
-  'TWD' => t('Taiwan Dollar (TWD)'),
-  'TZS' => t('Tanzanian Shilling (TZS)'),
-  'THB' => t('Thai Baht (THB)'),
-  'TOP' => t('Tonga Pa\'anga (TOP)'),
-  'TTD' => t('Trinidad & Tobago Dollar (TTD)'),
-  'TND' => t('Tunisian Dinar (TND)'),
-  'TRL' => t('Turkish Lira (TRL)'),
-  'USD' => t('U.S. Dollar (USD)'),
-  'AED' => t('UAE Dirham (AED)'),
-  'UGX' => t('Ugandan Shilling (UGX)'),
-  'UAH' => t('Ukraine Hryvnia (UAH)'),
-  'UYU' => t('Uruguayan New Peso (UYU)'),
-  'VUV' => t('Vanuatu Vatu (VUV)'),
-  'VEB' => t('Venezuelan Bolivar (VEB)'),
-  'VND' => t('Vietnam Dong (VND)'),
-  'YER' => t('Yemen Riyal (YER)'),
-  'YUM' => t('Yugoslav Dinar (YUM)'),
-  'ZMK' => t('Zambian Kwacha (ZMK)'),
-  'ZWD' => t('Zimbabwe Dollar (ZWD)')
+  $currency = array(
+    'AFA' => t('Afghanistan Afghani (AFA)'),
+    'ALL' => t('Albanian Lek (ALL)'),
+    'DZD' => t('Algerian Dinar (DZD)'),
+    'ARS' => t('Argentine Peso (ARS)'),
+    'AWG' => t('Aruba Florin (AWG)'),
+    'AUD' => t('Australian Dollar (AUD)'),
+    'BSD' => t('Bahamian Dollar (BSD)'),
+    'BHD' => t('Bahraini Dinar (BHD)'),
+    'BDT' => t('Bangladesh Taka (BDT)'),
+    'BBD' => t('Barbados Dollar (BBD)'),
+    'BYR' => t('Belarus Ruble (BYR)'),
+    'BZD' => t('Belize Dollar (BZD)'),
+    'BMD' => t('Bermuda Dollar (BMD)'),
+    'BTN' => t('Bhutan Ngultrum (BTN)'),
+    'BOB' => t('Bolivian Boliviano (BOB)'),
+    'BWP' => t('Botswana Pula (BWP)'),
+    'BRL' => t('Brazilian Real (BRL)'),
+    'GBP' => t('British Pound (GBP)'),
+    'BND' => t('Brunei Dollar (BND)'),
+    'BGN' => t('Bulgarian Lev (BGN)'),
+    'BIF' => t('Burundi Franc (BIF)'),
+    'KHR' => t('Cambodia Riel (KHR)'),
+    'CAD' => t('Canadian Dollar (CAD)'),
+    'CVE' => t('Cape Verde Escudo (CVE)'),
+    'KYD' => t('Cayman Islands Dollar (KYD)'),
+    'XOF' => t('CFA Franc (BCEAO) (XOF)'),
+    'XAF' => t('CFA Franc (BEAC) (XAF)'),
+    'CLP' => t('Chilean Peso (CLP)'),
+    'CNY' => t('Chinese Yuan (CNY)'),
+    'COP' => t('Colombian Peso (COP)'),
+    'KMF' => t('Comoros Franc (KMF)'),
+    'CRC' => t('Costa Rica Colon (CRC)'),
+    'HRK' => t('Croatian Kuna (HRK)'),
+    'CUP' => t('Cuban Peso (CUP)'),
+    'CYP' => t('Cyprus Pound (CYP)'),
+    'CZK' => t('Czech Koruna (CZK)'),
+    'DKK' => t('Danish Krone (DKK)'),
+    'DJF' => t('Dijibouti Franc (DJF)'),
+    'DOP' => t('Dominican Peso (DOP)'),
+    'XCD' => t('East Caribbean Dollar (XCD)'),
+    'ECS' => t('Ecuador Sucre (ECS)'),
+    'EGP' => t('Egyptian Pound (EGP)'),
+    'SVC' => t('El Salvador Colon (SVC)'),
+    'ERN' => t('Eritrea Nakfa (ERN)'),
+    'EEK' => t('Estonian Kroon (EEK)'),
+    'ETB' => t('Ethiopian Birr (ETB)'),
+    'EUR' => t('Euro (EUR)'),
+    'FKP' => t('Falkland Islands Pound (FKP)'),
+    'FJD' => t('Fiji Dollar (FJD)'),
+    'GMD' => t('Gambian Dalasi (GMD)'),
+    'GHC' => t('Ghanian Cedi (GHC)'),
+    'GIP' => t('Gibraltar Pound (GIP)'),
+    'XAU' => t('Gold Ounces (XAU)'),
+    'GTQ' => t('Guatemala Quetzal (GTQ)'),
+    'GNF' => t('Guinea Franc (GNF)'),
+    'GYD' => t('Guyana Dollar (GYD)'),
+    'HTG' => t('Haiti Gourde (HTG)'),
+    'HNL' => t('Honduras Lempira (HNL)'),
+    'HKD' => t('Hong Kong Dollar (HKD)'),
+    'HUF' => t('Hungarian Forint (HUF)'),
+    'ISK' => t('Iceland Krona (ISK)'),
+    'INR' => t('Indian Rupee (INR)'),
+    'IDR' => t('Indonesian Rupiah (IDR)'),
+    'IRR' => t('Iran Rial (IRR)'),
+    'IQD' => t('Iraqi Dinar (IQD)'),
+    'ILS' => t('Israeli Shekel (ILS)'),
+    'JMD' => t('Jamaican Dollar (JMD)'),
+    'JPY' => t('Japanese Yen (JPY)'),
+    'JOD' => t('Jordanian Dinar (JOD)'),
+    'KZT' => t('Kazakhstan Tenge (KZT)'),
+    'KES' => t('Kenyan Shilling (KES)'),
+    'KRW' => t('Korean Won (KRW)'),
+    'KWD' => t('Kuwaiti Dinar (KWD)'),
+    'LAK' => t('Lao Kip (LAK)'),
+    'LVL' => t('Latvian Lat (LVL)'),
+    'LBP' => t('Lebanese Pound (LBP)'),
+    'LSL' => t('Lesotho Loti (LSL)'),
+    'LRD' => t('Liberian Dollar (LRD)'),
+    'LYD' => t('Libyan Dinar (LYD)'),
+    'LTL' => t('Lithuanian Lita (LTL)'),
+    'MOP' => t('Macau Pataca (MOP)'),
+    'MKD' => t('Macedonian Denar (MKD)'),
+    'MGF' => t('Malagasy Franc (MGF)'),
+    'MWK' => t('Malawi Kwacha (MWK)'),
+    'MYR' => t('Malaysian Ringgit (MYR)'),
+    'MVR' => t('Maldives Rufiyaa (MVR)'),
+    'MTL' => t('Maltese Lira (MTL)'),
+    'MRO' => t('Mauritania Ougulya (MRO)'),
+    'MUR' => t('Mauritius Rupee (MUR)'),
+    'MXN' => t('Mexican Peso (MXN)'),
+    'MDL' => t('Moldovan Leu (MDL)'),
+    'MNT' => t('Mongolian Tugrik (MNT)'),
+    'MAD' => t('Moroccan Dirham (MAD)'),
+    'MZM' => t('Mozambique Metical (MZM)'),
+    'MMK' => t('Myanmar Kyat (MMK)'),
+    'NAD' => t('Namibian Dollar (NAD)'),
+    'NPR' => t('Nepalese Rupee (NPR)'),
+    'ANG' => t('Neth Antilles Guilder (ANG)'),
+    'NZD' => t('New Zealand Dollar (NZD)'),
+    'NIO' => t('Nicaragua Cordoba (NIO)'),
+    'NGN' => t('Nigerian Naira (NGN)'),
+    'KPW' => t('North Korean Won (KPW)'),
+    'NOK' => t('Norwegian Krone (NOK)'),
+    'OMR' => t('Omani Rial (OMR)'),
+    'XPF' => t('Pacific Franc (XPF)'),
+    'PKR' => t('Pakistani Rupee (PKR)'),
+    'XPD' => t('Palladium Ounces (XPD)'),
+    'PAB' => t('Panama Balboa (PAB)'),
+    'PGK' => t('Papua New Guinea Kina (PGK)'),
+    'PYG' => t('Paraguayan Guarani (PYG)'),
+    'PEN' => t('Peruvian Nuevo Sol (PEN)'),
+    'PHP' => t('Philippine Peso (PHP)'),
+    'XPT' => t('Platinum Ounces (XPT)'),
+    'PLN' => t('Polish Zloty (PLN)'),
+    'QAR' => t('Qatar Rial (QAR)'),
+    'ROL' => t('Romanian Leu (ROL)'),
+    'RUB' => t('Russian Rouble (RUB)'),
+    'RWF' => t('Rwanda Franc (RWF)'),
+    'WST' => t('Samoa Tala (WST)'),
+    'STD' => t('Sao Tome Dobra (STD)'),
+    'SAR' => t('Saudi Arabian Riyal (SAR)'),
+    'SCR' => t('Seychelles Rupee (SCR)'),
+    'SLL' => t('Sierra Leone Leone (SLL)'),
+    'XAG' => t('Silver Ounces (XAG)'),
+    'SGD' => t('Singapore Dollar (SGD)'),
+    'SKK' => t('Slovak Koruna (SKK)'),
+    'SIT' => t('Slovenian Tolar (SIT)'),
+    'SBD' => t('Solomon Islands Dollar (SBD)'),
+    'SOS' => t('Somali Shilling (SOS)'),
+    'ZAR' => t('South African Rand (ZAR)'),
+    'LKR' => t('Sri Lanka Rupee (LKR)'),
+    'SHP' => t('St Helena Pound (SHP)'),
+    'SDD' => t('Sudanese Dinar (SDD)'),
+    'SRG' => t('Surinam Guilder (SRG)'),
+    'SZL' => t('Swaziland Lilageni (SZL)'),
+    'SEK' => t('Swedish Krona (SEK)'),
+    'CHF' => t('Swiss Franc (CHF)'),
+    'SYP' => t('Syrian Pound (SYP)'),
+    'TWD' => t('Taiwan Dollar (TWD)'),
+    'TZS' => t('Tanzanian Shilling (TZS)'),
+    'THB' => t('Thai Baht (THB)'),
+    'TOP' => t('Tonga Pa\'anga (TOP)'),
+    'TTD' => t('Trinidad & Tobago Dollar (TTD)'),
+    'TND' => t('Tunisian Dinar (TND)'),
+    'TRL' => t('Turkish Lira (TRL)'),
+    'USD' => t('U.S. Dollar (USD)'),
+    'AED' => t('UAE Dirham (AED)'),
+    'UGX' => t('Ugandan Shilling (UGX)'),
+    'UAH' => t('Ukraine Hryvnia (UAH)'),
+    'UYU' => t('Uruguayan New Peso (UYU)'),
+    'VUV' => t('Vanuatu Vatu (VUV)'),
+    'VEB' => t('Venezuelan Bolivar (VEB)'),
+    'VND' => t('Vietnam Dong (VND)'),
+    'YER' => t('Yemen Riyal (YER)'),
+    'YUM' => t('Yugoslav Dinar (YUM)'),
+    'ZMK' => t('Zambian Kwacha (ZMK)'),
+    'ZWD' => t('Zimbabwe Dollar (ZWD)'),
   );
 
-  return ($currency);
+  return $currency;
 }
 
-function currency_api_get_fields ( $array )
-{
- while ( list($field, $header) = each($array) )
-	{
-	$field_string = $field_string . $field;
-	}
-
- return ( $field_string );
+function currency_api_get_fields($array) {
+  while (list($field, $header) = each($array)) {
+    $field_string = $field_string . $field;
+  }
+  
+  return $field_string;
 }
 
-function _log_to_watchdog($msg = '', $severity = WATCHDOG_NOTICE, $type = 'user') 
-{
+function _log_to_watchdog($msg = '', $severity = WATCHDOG_NOTICE, $type = 'user') {
   if (variable_get('currency_api_watchdog', 1)) {
     watchdog($type, $msg, $severity);
   }
-}
-
-?>
+}
\ No newline at end of file
