Index: contrib/ecurrency/README.txt
===================================================================
RCS file: contrib/ecurrency/README.txt
diff -N contrib/ecurrency/README.txt
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ contrib/ecurrency/README.txt	1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,13 @@
+Required Module : currency
+Original Author : Edison Wong
+Settings        : > administer > store > settings > ecurrency
+
+********************************************************************
+DESCRIPTION:
+
+Adds multiple currency configuration and API to E-Commerce.
+
+********************************************************************
+
+See MAINTAINERS.txt for more maintenance info.
+See README.txt (in E-Commerce root) for other info.
Index: contrib/ecurrency/ecurrency.css
===================================================================
RCS file: contrib/ecurrency/ecurrency.css
diff -N contrib/ecurrency/ecurrency.css
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ contrib/ecurrency/ecurrency.css	1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,12 @@
+.price {
+  display: inline;
+}
+.price-base {
+  font-style: normal;
+}
+.price-display {
+  font-style: italic;
+}
+.block-ecurrency select {
+  width: 100%;
+}
Index: contrib/ecurrency/ecurrency.install
===================================================================
RCS file: contrib/ecurrency/ecurrency.install
diff -N contrib/ecurrency/ecurrency.install
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ contrib/ecurrency/ecurrency.install	1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,62 @@
+<?php
+// $Id: ecurrency.install,v 1.3 2006/07/27 03:42:29 hswong3i Exp $
+
+function ecurrency_install() {
+  switch ($GLOBALS['db_type']) {
+    case 'mysql':
+    case 'mysqli':
+      db_query("CREATE TABLE {ec_ecurrency} (
+        currencies_id int(10) NOT NULL default '0',
+        title varchar(32) NOT NULL,
+        code char(3) NOT NULL,
+        symbol_left varchar(12) NOT NULL,
+        symbol_right varchar(12) NOT NULL,
+        decimal_point char(1) NOT NULL,
+        thousands_point char(1) NOT NULL,
+        decimal_places char(1) NOT NULL default '0',
+        value float(13,8) NOT NULL default '0.00000000',
+        last_updated int(11) NOT NULL default '0',
+        KEY currencies_id (currencies_id)
+      ) TYPE=MyISAM /*!40100 DEFAULT CHARACTER SET utf8 */;");
+      db_query("CREATE TABLE {ec_ecurrency_cache} (
+        cookie_id varchar(32) NOT NULL default '0',
+        currencies_id int(10) NOT NULL default '0',
+        last_updated int(11) NOT NULL default '0',
+        KEY cookie_id (cookie_id)
+      ) TYPE=MyISAM /*!40100 DEFAULT CHARACTER SET utf8 */;");
+      break;
+    case 'pgsql':
+      db_query("CREATE TABLE {ec_ecurrency} (
+        currencies_id integer NOT NULL default '0',
+        title varchar(32) NOT NULL,
+        code char(3) NOT NULL,
+        symbol_left varchar(12) NOT NULL,
+        symbol_right varchar(12) NOT NULL,
+        decimal_point char(1) NOT NULL,
+        thousands_point char(1) NOT NULL,
+        decimal_places char(1) NOT NULL default '0',
+        value float(13,8) NOT NULL default '0.00000000',
+        last_updated integer NOT NULL default '0',
+        KEY currencies_id (currencies_id)
+      );");
+      db_query("CREATE TABLE {ec_ecurrency_cache} (
+        cookie_id varchar(32) NOT NULL default '0',
+        currencies_id integer NOT NULL default '0',
+        last_updated integer NOT NULL default '0',
+        KEY cookie_id (cookie_id)
+      );");
+      break;
+  }
+
+  $USD = db_next_id('{ec_ecurrency}_currencies_id');
+  $EUR = db_next_id('{ec_ecurrency}_currencies_id');
+  db_query("INSERT INTO {ec_ecurrency} VALUES (%d, 'US Dollar', 'USD', '$', '', '.', ',', '2', 1.00000000, 1153934739);", $USD);
+  db_query("INSERT INTO {ec_ecurrency} VALUES (%d, 'Euro', 'EUR', 'EUR', '', '.', ',', '2', 0.79040003, 1153934738);", $EUR);
+
+  variable_set('ecurrency_default_base', $USD);
+  variable_set('ecurrency_default_display', $USD);
+  variable_set('ecurrency_update_manual', array());
+  variable_set('ecurrency_update_auto', array());
+}
+
+?>
Index: contrib/ecurrency/ecurrency.module
===================================================================
RCS file: contrib/ecurrency/ecurrency.module
diff -N contrib/ecurrency/ecurrency.module
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ contrib/ecurrency/ecurrency.module	1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,545 @@
+<?php
+// $Id: ecurrency.module,v 1.2 2006/07/26 18:15:04 hswong3i Exp $
+
+/********************************************************************
+ * Drupal Hooks
+ ********************************************************************/
+
+/**
+ * Implementation of hook_help()
+ */
+function ecurrency_help($section = 'admin/help#ecurrency') {
+  $output = '';
+  switch ($section) {
+    case 'admin/modules#description':
+      return t('Add additional currency features to E-Commerce. Dependency: currency_api.module');
+    case 'admin/store/settings/ecurrency/list':
+      $output .= t('To configure specific currency settings, click the "configure" link for the corresponding currency. Click "update" link for update corresponding currency foreign exchange rates. Require currency_api.module for currency update.</p>');
+      $output .= t('<p>Default currency is not allow to delete, and value is always equal to 1.</p>');
+      return $output;
+  }
+}
+
+/**
+ * Implementation of hook_menu()
+ */
+function ecurrency_menu($may_cache) {
+  $items = array();
+
+  $access = user_access('administer store');
+
+  if ($may_cache) {
+    $items[] = array(
+      'path' => 'admin/store/settings/ecurrency/configure',
+      'title' => t('configure'),
+      'type' => MENU_DEFAULT_LOCAL_TASK,
+      'access' => $access,
+    );
+    $items[] = array(
+      'path' => 'admin/store/settings/ecurrency/list',
+      'title' => t('list'),
+      'callback' => 'ecurrency_admin_currency_list',
+      'type' => MENU_LOCAL_TASK,
+      'access' => $access,
+    );
+    $items[] = array(
+      'path' => 'admin/store/settings/ecurrency/add/currency',
+      'title' => t('add currency'),
+      'callback' => 'ecurrency_admin_currency_edit',
+      'type' => MENU_LOCAL_TASK,
+      'weight' => 1,
+      'access' => $access,
+    );
+    $items[] = array(
+      'path' => 'admin/store/settings/ecurrency/edit/currency',
+      'title' => t('edit currency'),
+      'callback' => 'ecurrency_admin_currency_edit',
+      'type' => MENU_CALLBACK,
+      'access' => $access,
+    );
+    $items[] = array(
+      'path' => 'admin/store/settings/ecurrency/update/currency',
+      'title' => t('edit currency'),
+      'callback' => 'ecurrency_admin_currency_update',
+      'type' => MENU_CALLBACK,
+      'access' => $access,
+    );
+  }
+  else {
+    // Add css for price formatting
+    theme_add_style(drupal_get_path('module', 'ecurrency') .'/ecurrency.css');
+
+    // Alway reset base currency value to 1
+    $base = ecurrency_get_currency(variable_get('ecurrency_default_base', 1));
+    if ($base['value'] != 1) {
+      $base['value'] = 1;
+      ecurrency_save_currency($base);
+
+      $currencies = ecurrency_get_currencies_list();
+      foreach ($currencies as $currencies_id => $currency) {
+        ecurrency_admin_currency_update($currencies_id, TRUE);
+      }
+    }
+
+    // We change the selected currency by drop down select, save it, and back to currenct page
+    if ($_POST['edit']['ecurrency_custom_display']) {
+      db_query("UPDATE {ec_ecurrency_cache} SET currencies_id = %d, last_updated = %d WHERE cookie_id = '%s'", $_POST['edit']['ecurrency_custom_display'], time(), ecurrency_get_id());
+      drupal_goto();
+    }
+  }
+
+  return $items;
+}
+
+/**
+ * Implementation of hook_block()
+ */
+function ecurrency_block($op = "list", $delta = 0, $edit = array()) {
+  if ($op == 'list') {
+    $blocks[0]['info'] = t('Currencies');
+    return $blocks;
+  }
+  else if ($op == 'view') {
+    /**
+     * Until Drupal can handle partial page caching, We should not display this
+     * block for anonymous users. This is due to all anonymous user will share
+     * the same session_id(), and so we can't handle it.
+     */
+    global $user;
+    if ($user->uid == 0 && variable_get('cache', 0)) {
+      return FALSE;
+    }
+
+    $list = ecurrency_get_currencies_list();
+    $display = ecurrency_get_display();
+    $form['ecurrency_custom_display'] = array(
+      '#type' => 'select',
+      '#default_value' => $display,
+      '#options' => $list,
+      '#attributes' => array('onChange' => 'this.form.submit()'),
+    );
+
+    $block['subject'] = t('Currencies');
+    $block['content'] = drupal_get_form('ecurrency_block_form', $form);
+    return $block;
+  }
+}
+
+/**
+ * implementation of hook_ec_settings()
+ */
+function ecurrency_ec_settings() {
+  $form['default'] = array(
+    '#type' => 'fieldset',
+    '#title' => t('Default Settings'),
+    '#collapsible' => TRUE,
+    '#collapsed' => FALSE,
+  );
+  $form['default']['intro'] = array(
+    '#type' => 'item',
+    '#value' => t('Specify the base currency. All foregin exchange rate of other currencies will base on base currency. Note that change of default currency requires a manual update of database currency values.'),
+  );
+  $form['default']['ecurrency_default_base'] = array(
+    '#type' => 'select',
+    '#title' => t('Default base currency'),
+    '#default_value' => variable_get('ecurrency_default_base', 1),
+    '#options' => ecurrency_get_currencies_list(),
+  );
+  $form['default']['ecurrency_default_display'] = array(
+    '#type' => 'select',
+    '#title' => t('Default display currency'),
+    '#default_value' => variable_get('ecurrency_default_display', 1),
+    '#options' => ecurrency_get_currencies_list(),
+    '#description' => t('Default display currency. Anonymous user will use this as currency display format.'),
+  );
+  $form['update'] = array(
+    '#type' => 'fieldset',
+    '#title' => t('Update Settings'),
+    '#collapsible' => TRUE,
+    '#collapsed' => FALSE,
+  );
+  $form['update']['ecurrency_update_manual'] = array(
+    '#type' => 'select',
+    '#title' => t('Manual update foregin exchange rate'),
+    '#default_value' => variable_get('ecurrency_update_manual', array()),
+    '#options' => ecurrency_get_currencies_list(),
+    '#multiple' => TRUE,
+    '#description' => t("Admin can change the foregin exchange rate manually, by manual input or currency_api. Value of default base currency is always equal to 1, and can't be changed."),
+  );
+  $form['update']['ecurrency_update_auto'] = array(
+    '#type' => 'select',
+    '#title' => t('Automatic update foregin exchange rate'),
+    '#default_value' => variable_get('ecurrency_update_auto', array()),
+    '#options' => ecurrency_get_currencies_list(),
+    '#multiple' => TRUE,
+    '#description' => t('Chose currencies that hope to handle update forgine exchange rate automatically by cron. Dependency: currency_api.module'),
+  );
+
+  if (!module_exist('currency_api')) {
+    $form['update']['ecurrency_update_auto']['#attributes'] = array('disabled' => 'disabled');
+  }
+
+  return $form;
+}
+
+/**
+ * Implementation of hook_user().
+ */
+function ecurrency_user($op, &$edit, &$user, $category = NULL) {
+  switch ($op) {
+    case 'login':
+      // Convert their cookie_id from session id to user id at login.
+      db_query("DELETE FROM {ec_ecurrency_cache} WHERE cookie_id = %d", $user->uid);
+      db_query("UPDATE {ec_ecurrency_cache} SET cookie_id = %d WHERE cookie_id = '%s'", $user->uid, session_id());
+      break;
+  }
+}
+
+/**
+ * Implementation of hook_cron()
+ */
+function ecurrency_cron() {
+  // Auto update foregin exchange rate
+  $currencies = ecurrency_get_currencies_list();
+  $auto = variable_get('ecurrency_update_auto', array());
+  foreach ($currencies as $currencies_id => $currency) {
+    if (array_key_exists($currencies_id, $auto)) {
+      ecurrency_admin_currency_update($currencies_id, TRUE);
+    }
+  }
+
+  // Clean cache that month before
+  db_query('DELETE FROM {ec_ecurrency_cache} WHERE last_updated < %d', strtotime('last month'));
+}
+
+/********************************************************************
+ * API Functions
+ ********************************************************************/
+
+/**
+ * Format the price according to input currency format.
+ */
+function ecurrency_format($from, $to, $price) {
+  static $formats = array();
+  $formats = !empty($formats) ? $formats : ecurrency_get_currencies();
+
+  $price = (float) $price / (float) $formats[$from]['value'] * (float) $formats[$to]['value'];
+  $price = number_format((float) $price,
+    $formats[$to]['decimal_places'],
+    $formats[$to]['decimal_point'],
+    $formats[$to]['thousands_point']);
+  $price = $formats[$to]['symbol_left'] . $price . $formats[$to]['symbol_right'];
+
+  ($from == $to) ?
+    $price = '<div class="price price-base">' . $price . '</div>' :
+    $price = '<div class="price price-display">' . $price . '</div>';
+
+  return $price;
+}
+
+/**
+ * Return an array of all currency objects.
+ */
+function ecurrency_get_currencies() {
+  static $currencies = array();
+  if (empty($currencies)) {
+    $result = db_query("SELECT * FROM {ec_ecurrency} ORDER BY title");
+    while ($currency = db_fetch_object($result)) {
+      $currency = (array) $currency;
+      $currencies[$currency['currencies_id']] = $currency;
+    }
+  }
+  return $currencies;
+}
+
+/**
+ * Return an list of all currency objects.
+ */
+function ecurrency_get_currencies_list() {
+  static $list = array();
+  if (empty($list)) {
+    $currencies = ecurrency_get_currencies();
+    foreach ($currencies as $currency) {
+      $list[$currency['currencies_id']] = $currency['title'];
+    }
+  }
+  return $list;
+}
+
+/**
+ * Return the currency object matching a currency ID.
+ */
+function ecurrency_get_currency($currencies_id) {
+  $currencies = ecurrency_get_currencies();
+  return $currencies[$currencies_id];
+}
+
+/********************************************************************
+ * Module Functions
+ ********************************************************************/
+
+/**
+ * List and manage currencies.
+ */
+function ecurrency_admin_currency_list() {
+  $currencies = ecurrency_get_currencies();
+  foreach($currencies as $currency) {
+    $rows[] = array(
+      'title' =>  ($currency['currencies_id'] == variable_get('ecurrency_default_base', 1)) ?
+        t('<b>%title (default)</b>', array('%title' => $currency['title'])) :
+        $currency['title'],
+      'code' => $currency['code'],
+      'example' => ecurrency_format(variable_get('ecurrency_default_base', 1), $currency['currencies_id'], 30),
+      'value' => $currency['value'],
+      'last_updated' => format_date($currency['last_updated'], 'small'),
+      'configure' => l(t('configure'), 'admin/store/settings/ecurrency/edit/currency/'. $currency['currencies_id']),
+      'update' => (module_exist('currency_api') && $currency['currencies_id'] != variable_get('ecurrency_default_base', 1) && array_key_exists($currency['currencies_id'], variable_get('ecurrency_update_manual', array()))) ?
+        l(t('update'), 'admin/store/settings/ecurrency/update/currency/'. $currency['currencies_id']) :
+        '',
+    );
+  }
+  $header = array(t('Currency'), t('Code'), t('Example Output'), t('Value'), t('Last Updated'), array('data' => t('Operations'), 'colspan' => 2));
+
+  return theme('table', $header, $rows, array('id' => 'ecurrency'));
+}
+
+function ecurrency_admin_currency_edit($currencies_id = NULL) {
+  if ($_POST['op'] == t('Delete') || $_POST['edit']['confirm']) {
+    return _ecurrency_confirm_del_currency($currencies_id);
+  }
+  elseif ($currencies_id) {
+    $currency = ecurrency_get_currency($currencies_id);
+  }
+  return ecurrency_form_currency($currency);
+}
+
+function ecurrency_admin_currency_update($currencies_id = NULL, $cron = FALSE) {
+  if (!module_exist('currency_api')) {
+    return;
+  }
+
+  $from = ecurrency_get_currency(variable_get('ecurrency_default_base', 1));
+  if ($currencies_id != variable_get('ecurrency_default_base', 1)) {
+    $to = ecurrency_get_currency($currencies_id);
+    $ret = currency_api_convert($from['code'], $to['code'], 1);
+    if ($ret['status'] == FALSE) {
+      watchdog('ecurrency', t('%message', array('%message' => $ret['message'])));
+    }
+    else {
+      $to['value'] = $ret['value'];
+      ecurrency_save_currency($to);
+    }
+  }
+  else {
+    $from['value'] = 1;
+    ecurrency_save_currency($from);
+  }
+
+  if (!$cron) {
+    drupal_goto('admin/store/settings/ecurrency/list');
+  }
+}
+
+/**
+ * Display form for adding and editing currencies.
+ */
+function ecurrency_form_currency($edit = array()) {
+  $form['intro'] = array(
+    '#type' => 'item',
+    '#value' => t('<p>For more information about ISO 4217 three-character currency code, please read <a href="%wiki">Wiki page</a>.</p>', array('%wiki' => 'http://en.wikipedia.org/wiki/ISO_4217#Active_codes_.28sorted_by_code.29')),
+  );
+  $form['title'] = array(
+    '#type' => 'textfield',
+    '#title' => t('Title'),
+    '#default_value' => $edit['title'],
+    '#size' => 32,
+    '#maxlength' => 32,
+    '#description' => t('Enter the title of this currency.'),
+    '#required' => TRUE,
+  );
+  $form['code'] = array(
+    '#type' => 'textfield',
+    '#title' => t('Code'),
+    '#default_value' => $edit['code'],
+    '#size' => 32,
+    '#maxlength' => 3,
+    '#description' => t('Enter the ISO 4217 three-character currency code.'),
+    '#required' => TRUE,
+  );
+  $form['symbol_left'] = array(
+    '#type' => 'textfield',
+    '#title' => t('Symbol Left'),
+    '#default_value' => $edit['symbol_left'],
+    '#size' => 32,
+    '#maxlength' => 12,
+    '#description' => t('Enter the left currency symbol. This will be displayed in front of the price.'),
+  );
+  $form['symbol_right'] = array(
+    '#type' => 'textfield',
+    '#title' => t('Symbol Right'),
+    '#default_value' => $edit['symbol_right'],
+    '#size' => 32,
+    '#maxlength' => 12,
+    '#description' => t('Enter the right currency symbol. This will be displayed after the price.'),
+  );
+  $form['decimal_point'] = array(
+    '#type' => 'textfield',
+    '#title' => t('Decimal Point'),
+    '#default_value' => $edit['decimal_point'],
+    '#size' => 32,
+    '#maxlength' => 1,
+    '#description' => t('Enter the sign to seperate real numbers from floating numbers.')
+   );
+  $form['thousands_point'] = array(
+    '#type' => 'textfield',
+    '#title' => t('Thousands Point'),
+    '#default_value' => $edit['thousands_point'],
+    '#size' => 32,
+    '#maxlength' => 1,
+    '#description' => t('Enter the sign for the thousands separator.')
+  );
+  $form['decimal_places'] = array(
+    '#type' => 'textfield',
+    '#title' => t('Decimal Places'),
+    '#default_value' => $edit['decimal_places'],
+    '#size' => 32,
+    '#maxlength' => 1,
+    '#description' => t('How many slots are needed after the decimal?')
+  );
+  $form['value'] = array(
+    '#type' => 'textfield',
+    '#title' => t('Foreign Exchange Rate'),
+    '#default_value' => $edit['value'],
+    '#size' => 32,
+    '#maxlength' => 21,
+    '#description' => t('Current foreign exchange rate with default currency.'),
+  );
+  if ($edit['currencies_id'] == variable_get('ecurrency_default_base', 1) ||
+    ($edit['currencies_id'] && !array_key_exists($edit['currencies_id'], variable_get('ecurrency_update_manual', array())))) {
+    $form['value']['#attributes'] = array('disabled' => 'disabled');
+  }
+
+  $form['submit'] = array('#type' => 'submit', '#value' => t('Submit'));
+  if ($edit['currencies_id']) {
+    if ($edit['currencies_id'] != variable_get('ecurrency_default_base', 1)) {
+      $form['delete'] = array('#type' => 'submit', '#value' => t('Delete'));
+    }
+    $form['currencies_id'] = array('#type' => 'value', '#value' => $edit['currencies_id']);
+  }
+  return drupal_get_form('ecurrency_form_currency', $form);
+}
+
+function ecurrency_form_currency_submit($form_id, $form_values) {
+  $form_values = array_filter($form_values);
+  switch (ecurrency_save_currency($form_values)) {
+  case SAVED_NEW:
+    drupal_set_message(t('Created new currency %title.', array('%title' => theme('placeholder', $form_values['title']))));
+    break;
+  case SAVED_UPDATED:
+    drupal_set_message(t('Updated currency %title.', array('%title' => theme('placeholder', $form_values['title']))));
+    break;
+  }
+  return 'admin/store/settings/ecurrency/list';
+}
+
+function _ecurrency_confirm_del_currency($currencies_id) {
+  $currency = ecurrency_get_currency($currencies_id);
+
+  $form['type'] = array('#type' => 'value', '#value' => 'ecurrency');
+  $form['currencies_id'] = array('#type' => 'value', '#value' => $currencies_id);
+  $form['title'] = array('#type' => 'value', '#value' => $currency['title']);
+  return confirm_form('ecurrency_currency_confirm_delete', $form,
+                  t('Are you sure you want to delete the currency %title?',
+                  array('%title' => theme('placeholder', $currency['title']))),
+                  'admin/store/settings/ecurrency', t('This action cannot be undone.'),
+                  t('Delete'),
+                  t('Cancel'));
+}
+
+function ecurrency_currency_confirm_delete_submit($form_id, $form_values) {
+  $status = ecurrency_del_currency($form_values['currencies_id']);
+  drupal_set_message(t('Deleted currency %title.', array('%title' => theme('placeholder', $form_values['title']))));
+  return 'admin/store/settings/ecurrency/list';
+}
+
+
+/********************************************************************
+ * Helper Functions
+ ********************************************************************/
+
+/**
+ * Return the unique id (and hence the cookie_id) of the user.
+ */
+function ecurrency_get_id() {
+  global $user;
+  static $id = NULL;
+
+  if (!$id) {
+    if ($user->uid) {
+      $id = $user->uid;
+    }
+    else if ($sid = session_id()) {
+      $id = $sid;
+    }
+  }
+
+  return $id;
+}
+
+/**
+ * Return current display currency format
+ */
+function ecurrency_get_display() {
+  global $user;
+  static $cookie = NULL;
+
+  if ($user->uid == 0 && variable_get('cache', 0)) {
+    if (!$cookie) {
+      $cookie = variable_get('ecurrency_default_display', 1);
+    }
+  }
+  else {
+    $id = ecurrency_get_id();
+    if (!$cookie) {
+      $cookie = db_result(db_query("SELECT currencies_id FROM {ec_ecurrency_cache} WHERE cookie_id = '%s'", $id));
+      if (!$cookie) {
+        $cookie = variable_get('ecurrency_default_display', 1);
+        db_query("INSERT INTO {ec_ecurrency_cache} (cookie_id, currencies_id, last_updated) VALUES ('%s', %d, %d)", $id, $cookie, time());
+      }
+    }
+  }
+
+  return $cookie;
+}
+
+/**
+ * Save change of currency format, due to update/delete/add
+ */
+function ecurrency_save_currency(&$edit) {
+  //Update currency
+  if ($edit['currencies_id'] && $edit['title'] && $edit['code']) {
+    db_query("UPDATE {ec_ecurrency} SET title = '%s', code = '%s', symbol_left = '%s', symbol_right = '%s', decimal_point = '%s', thousands_point = '%s', decimal_places = '%s', value = '%s', last_updated = %d where currencies_id = %d", $edit['title'], $edit['code'], $edit['symbol_left'], $edit['symbol_right'], $edit['decimal_point'], $edit['thousands_point'], $edit['decimal_places'], $edit['value'], time(), $edit['currencies_id']);
+    $status = SAVE_UPDATED;
+  }
+  //Delete currency
+  else if ($edit['currencies_id']) {
+    $status = ecurrency_del_currency($edit['currencies_id']);
+  }
+  //Add new currency
+  else {
+    $edit['currencies_id'] = db_next_id('{ec_ecurrency}_currencies_id');
+    db_query("INSERT INTO {ec_ecurrency} (currencies_id, title, code, symbol_left, symbol_right, decimal_point, thousands_point, decimal_places, value, last_updated) VALUES (%d, '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', %d)", $edit['currencies_id'], $edit['title'], $edit['code'], $edit['symbol_left'], $edit['symbol_right'], $edit['decimal_point'], $edit['thousands_point'], $edit['decimal_places'], $edit['value'], time());
+    $status = SAVED_NEW;
+  }
+  return $status;
+}
+
+/**
+ * Delete currency from DB
+ */
+function ecurrency_del_currency($currencies_id) {
+  db_query("DELETE FROM {ec_ecurrency} WHERE currencies_id = %d", $currencies_id);
+  return SAVED_DELETED;
+}
+
+?>
