'Store', 'description' => 'Administer orders, products, customers, store settings, etc.', 'page callback' => 'uc_store_admin', 'access arguments' => array('access administration pages'), 'weight' => -12, 'file' => 'uc_store.admin.inc', ); $items['admin/store/customers'] = array( 'title' => 'Customers', 'description' => 'View and modify customer information and orders.', 'page callback' => 'uc_store_customers', 'access arguments' => array('view customers'), 'weight' => -6, 'file' => 'uc_store.admin.inc', ); $items['admin/store/customers/view'] = array( 'title' => 'View customers', 'description' => 'View and modify customer information and orders.', 'page arguments' => array(NULL, NULL, '25'), 'access arguments' => array('view customers'), 'weight' => -10, 'file' => 'uc_store.admin.inc', ); $items['admin/store/customers/search'] = array( 'title' => 'Search customers', 'description' => 'Search through your customer list.', 'page callback' => 'uc_store_customer_search', 'access arguments' => array('view customers'), 'weight' => -5, 'file' => 'uc_store.admin.inc', ); $items['admin/store/reports'] = array( 'title' => 'Reports', 'description' => 'Browse various store reports.', 'page callback' => 'uc_store_reports', 'access arguments' => array('view store reports'), 'weight' => 2, 'file' => 'uc_store.admin.inc', ); $items['admin/store/settings'] = array( 'title' => 'Configuration', 'description' => 'Adjust configuration settings for Ubercart.', 'page callback' => 'uc_store_configuration_page', 'access arguments' => array('administer store'), 'weight' => 6, 'file' => 'uc_store.admin.inc', ); $items['admin/store/help'] = array( 'title' => 'Help', 'description' => 'Links to get help!', 'page callback' => 'uc_store_ubercart_help', 'access arguments' => array('administer store'), 'weight' => 10, 'file' => 'uc_store.admin.inc', ); $items['admin/store/help/tokens'] = array( 'title' => 'Using tokens', 'description' => 'Understand what tokens are and how to use them.', 'page callback' => 'uc_store_ubercart_help_tokens', 'access arguments' => array('administer store'), 'file' => 'uc_store.admin.inc', ); $items['admin/store/settings/countries'] = array( 'title' => 'Country settings', 'description' => 'Configure countries and address formats.', 'page callback' => 'drupal_get_form', 'page arguments' => array('uc_country_import_form'), 'access arguments' => array('administer store'), 'file' => 'uc_store.admin.inc', ); $items['admin/store/settings/countries/import'] = array( 'title' => 'Countries', 'description' => 'Import and manage countries.', 'access arguments' => array('administer store'), 'weight' => -10, 'type' => MENU_DEFAULT_LOCAL_TASK, 'file' => 'uc_store.admin.inc', ); $items['admin/store/settings/countries/formats'] = array( 'title' => 'Address formats', 'description' => 'Edit country specific address format settings.', 'page callback' => 'drupal_get_form', 'page arguments' => array('uc_country_formats_form'), 'access arguments' => array('administer store'), 'weight' => -5, 'type' => MENU_LOCAL_TASK, 'file' => 'uc_store.admin.inc', ); $items['admin/store/settings/store'] = array( 'title' => 'Store settings', 'description' => 'Configure the main store settings.', 'page callback' => 'drupal_get_form', 'page arguments' => array('uc_store_settings_form'), 'access arguments' => array('administer store'), 'file' => 'uc_store.admin.inc', ); $items['admin/store/settings/store/initials'] = array( 'title' => 'User initials', 'description' => 'Assign initials to user accounts.', 'page callback' => 'drupal_get_form', 'page arguments' => array('uc_store_initials'), 'access arguments' => array('administer store'), 'file' => 'uc_store.admin.inc', ); $items['uc_js_util/%'] = array( 'title' => 'JS utilities', 'page callback' => 'uc_store_js_util', 'page arguments' => array(1), 'access arguments' => array('access content'), 'type' => MENU_CALLBACK, ); $items['admin/store/customers/orders/%'] = array( 'title' => 'Customer orders', 'description' => 'View a list of orders placed by this customer.', 'page callback' => 'uc_store_customer_orders', 'page arguments' => array(4), 'access arguments' => array('view all orders'), 'weight' => -5, 'file' => 'uc_store.admin.inc', ); $items['admin/store/settings/countries/%/disable'] = array( 'title' => 'Disable a country', 'description' => 'Disable a country from use.', 'page callback' => 'uc_country_disable', 'page arguments' => array(4), 'access arguments' => array('administer store'), 'type' => MENU_CALLBACK, 'file' => 'uc_store.admin.inc', ); $items['admin/store/settings/countries/%/enable'] = array( 'title' => 'Enable a country', 'description' => 'Enable a disabled country.', 'page callback' => 'uc_country_enable', 'page arguments' => array(4), 'access arguments' => array('administer store'), 'type' => MENU_CALLBACK, 'file' => 'uc_store.admin.inc', ); $items['admin/store/settings/countries/%/remove'] = array( 'title' => 'Remove a country', 'description' => 'Remove an installed country.', 'page callback' => 'drupal_get_form', 'page arguments' => array('uc_country_remove_form', 4), 'access arguments' => array('administer store'), 'file' => 'uc_store.admin.inc', ); $items['admin/store/settings/countries/%/update/%'] = array( 'title' => 'Update a country', 'description' => 'Update an installed country.', 'page callback' => 'uc_country_update', 'page arguments' => array(4, 6), 'access arguments' => array('administer store'), 'type' => MENU_CALLBACK, 'file' => 'uc_store.admin.inc', ); return $items; } /** * Implements hook_init(). */ function uc_store_init() { module_load_include('inc', 'uc_store', 'includes/summaries'); module_load_include('inc', 'uc_store', 'includes/tapir'); drupal_add_css(drupal_get_path('module', 'uc_store') . '/uc_store.css', array('every_page' => TRUE)); global $conf; $conf['i18n_variables'][] = 'uc_store_name'; $conf['i18n_variables'][] = 'uc_field_first_name'; $conf['i18n_variables'][] = 'uc_field_last_name'; $conf['i18n_variables'][] = 'uc_field_email'; $conf['i18n_variables'][] = 'uc_field_phone'; $conf['i18n_variables'][] = 'uc_field_company'; $conf['i18n_variables'][] = 'uc_field_address'; $conf['i18n_variables'][] = 'uc_field_street'; $conf['i18n_variables'][] = 'uc_field_street1'; $conf['i18n_variables'][] = 'uc_field_street2'; $conf['i18n_variables'][] = 'uc_field_city'; $conf['i18n_variables'][] = 'uc_field_zone'; $conf['i18n_variables'][] = 'uc_field_postal_code'; $conf['i18n_variables'][] = 'uc_field_country'; } /** * Implements hook_element_info(). */ function uc_store_element_info() { $types = array(); $types['tapir_table'] = array( '#columns' => array(), '#rows' => array(), '#tree' => TRUE, '#value' => NULL, '#pre_render' => array('tapir_gather_rows'), '#theme' => 'tapir_table', '#process' => array('ajax_process_form'), ); return $types; } /** * Implements hook_theme(). */ function uc_store_theme() { return array( 'uc_store_footer' => array( 'variables' => array('message' => ''), ), 'uc_store_address_fields_form' => array( 'render element' => 'form', ), 'uc_pane_sort_table' => array( 'render element' => 'form', ), 'tapir_table' => array( 'render element' => 'element', ), 'uc_summary_overview' => array( 'variables' => array('summaries' => NULL, 'link' => TRUE), ), 'uc_price' => array( 'variables' => array('price' => 0), ), ); } /** * Implements hook_help(). */ function uc_store_help($path, $arg) { switch ($path) { case 'admin/store/customers': return t('This table lists out all users on your site who have placed orders.'); case 'admin/store/customers/search': return t('Use this page to search through users on your site who have placed orders.'); } } /** * Implements hook_permission(). */ function uc_store_permission() { return array( 'administer store' => array( 'title' => t('Administer store'), ), 'view customers' => array( 'title' => t('View customers'), ), 'view store reports' => array( 'title' => t('View store reports'), ), ); } /** * Implements hook_page_alter(). */ function uc_store_page_alter(&$page) { $id = variable_get('uc_footer_message', 0); // Exit if the store footer is turned off. if ($id === 'none') { return; } // Figure out what page is being viewed. $path = drupal_get_normal_path($_GET['q']); $parts = explode('/', $path); // Exit if the page isn't governed by Ubercart. switch ($parts[0]) { case 'admin': // No footer on /admin or /admin/*. // But add a footer on /admin/store and /admin/store/* if (!isset($parts[1]) || $parts[1] != 'store') { return; } break; case 'node': // No footer on /node or /node/[type]/add. // Only add a footer on /node/[nid] if that node is a product. if (count($parts) != 2 || intval($parts[1]) == 0) { return; } else { $node = node_load($parts[1]); if ($node == FALSE || !function_exists('uc_product_node_info') || !uc_product_is_product($node->type)) { return; } } break; case 'catalog': case 'cart': break; default: return; } $messages = _uc_store_footer_options(); if ($id == 0) { // Pseudorandom number based on the hash of the path and the site's private key, // so messages are consistent between pages on the same site, but different // on the same pages on different sites. $id = (hexdec(substr(md5($path . drupal_get_private_key()), 0, 2)) % count($messages)) + 1; } $page['page_bottom']['ubercart_footer'] = array( '#theme' => 'uc_store_footer', '#message' => $messages[$id], ); } /** * Implements hook_exit(). */ function uc_store_exit() { // Save the current request for tracking paths on subsequent page requests. // When HTTP_REFERER is set, the session version is not; and vice versa. if ($_SERVER['HTTP_REFERER'] == '') { $protocol = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off') ? 'https' : 'http'; $q = isset($_GET['q']) ? $_GET['q'] : ''; $_SESSION['uc_referer_uri'] = $protocol . '://' . $_SERVER['SERVER_NAME'] . $GLOBALS['base_path'] . $q; } else { if (isset($_SESSION['uc_referer_uri'])) { unset($_SESSION['uc_referer_uri']); } } // Save the timestamp of the last access. // $_SESSION['uc_last_access'] = REQUEST_TIME; } /** * Implements hook_reviews(). * * Provides code reviews for coder_review.module. */ function uc_store_reviews() { $coder_reviews = array(); $path = drupal_get_path('module', 'uc_store') . '/includes'; $files = drupal_system_listing('/coder_review_.*\.inc$/', $path, 'filepath', 0); foreach ($files as $file) { require_once DRUPAL_ROOT . '/' . $file->uri; $function = $file->name . '_reviews'; if (function_exists($function)) { if ($review = call_user_func($function)) { $coder_reviews = array_merge($coder_reviews, $review); } } } return $coder_reviews; } /****************************************************************************** * Callback Functions, Forms, and Tables ******************************************************************************/ /** * Displays a price in the standard format and with consistent markup. * * @ingroup themeable */ function theme_uc_price($variables) { return '' . uc_currency_format($variables['price']) . ''; } /** * Returns the default store footer options. */ function _uc_store_footer_options() { $url = array('!url' => 'http://www.ubercart.org/'); return array( 1 => t('Powered by Ubercart', $url), 2 => t('Drupal e-commerce provided by Ubercart.', $url), 3 => t('Supported by Ubercart, an open source e-commerce suite.', $url), 4 => t('Powered by Ubercart, the free shopping cart software.', $url), ); } /** * Wraps the footer in a div so it can be re-styled. * * @ingroup themeable */ function theme_uc_store_footer($variables) { return '
'; } /** * Helper function for hook_entity_property_info() and hook_rules_data_info(). * * Should be used by implementations of those hooks that wish to wrap address * selectors. */ function uc_address_property_info() { return array( 'first_name' => array( 'type' => 'text', 'label' => t('First name'), 'description' => t('First name of the addressee.'), ), 'last_name' => array( 'type' => 'text', 'label' => t('Last name'), 'description' => t('Last name of the addressee.'), ), 'company' => array( 'type' => 'text', 'label' => t('Company'), 'description' => t('Name of the company at the address.'), ), 'street1' => array( 'type' => 'text', 'label' => t('Street line 1'), 'description' => t('First line of the street address.'), ), 'street2' => array( 'type' => 'text', 'label' => t('Street line 2'), 'description' => t('Second line of the street address.'), ), 'city' => array( 'type' => 'text', 'label' => t('City'), 'description' => t('Address city.'), ), 'zone' => array( 'type' => 'integer', 'label' => t('Zone'), 'description' => t('Address state/province/zone.'), 'options list' => 'uc_zone_option_list', ), 'postal_code' => array( 'type' => 'text', 'label' => t('Postal code'), 'description' => t('Address post code.'), ), 'country' => array( 'type' => 'integer', 'label' => t('Country'), 'description' => t('Address country.'), 'options list' => 'uc_country_option_list', ), 'phone' => array( 'type' => 'text', 'label' => t('Phone'), 'description' => t('Contact phone number.'), ), 'email' => array( 'type' => 'text', 'label' => t('Email'), 'description' => t('Contact email address.'), ), ); } /** * Form to configure address fields. * * @ingroup forms * @see uc_store_address_fields_form_submit() * @see uc_store_address_fields_form_reset() * @see theme_uc_store_address_fields_form() */ function uc_store_address_fields_form($form, &$form_state) { $form['fields'] = array( '#tree' => TRUE, '#summary callback' => 'uc_summarize_form', ); $fields = array( 'first_name' => array(t('First name'), TRUE), 'last_name' => array(t('Last name'), TRUE), 'phone' => array(t('Phone number'), TRUE), 'company' => array(t('Company'), TRUE), 'street1' => array(t('Street address 1'), TRUE), 'street2' => array(t('Street address 2'), TRUE), 'city' => array(t('City'), TRUE), 'zone' => array(t('State/Province'), TRUE), 'country' => array(t('Country'), TRUE), 'postal_code' => array(t('Postal code'), TRUE), 'address' => array(t('Address'), FALSE), 'street' => array(t('Street address'), FALSE), ); $current = variable_get('uc_address_fields', drupal_map_assoc(array('first_name', 'last_name', 'phone', 'company', 'street1', 'street2', 'city', 'zone', 'postal_code', 'country'))); $required = variable_get('uc_address_fields_required', drupal_map_assoc(array('first_name', 'last_name', 'street1', 'city', 'zone', 'postal_code', 'country'))); foreach ($fields as $field => $data) { if ($data[1]) { $form['fields'][$field]['#summary callback'] = 'uc_summarize_form'; $form['fields'][$field]['enabled'] = array( '#type' => 'checkbox', '#summary callback' => 'uc_summarize_checkbox', '#summary arguments' => array( t('@field is enabled.', array('@field' => uc_get_field_name($field))), t('@field is disabled.', array('@field' => uc_get_field_name($field))), ), '#default_value' => isset($current[$field]) ? TRUE : FALSE, ); $form['fields'][$field]['required'] = array( '#type' => 'checkbox', '#summary callback' => 'uc_summarize_null', '#default_value' => isset($required[$field]) ? TRUE : FALSE, ); } else { $form['fields'][$field]['enabled'] = array( '#markup' => '-', ); } $form['fields'][$field]['default'] = array( '#markup' => $data[0], ); $form['fields'][$field]['title'] = array( '#type' => 'textfield', '#summary callback' => 'uc_summarize_null', '#default_value' => uc_get_field_name($field), '#size' => 32, ); } $form['actions'] = array('#type' => 'actions'); $form['actions']['save'] = array( '#type' => 'submit', '#value' => t('Save configuration'), ); $form['actions']['reset'] = array( '#type' => 'submit', '#value' => t('Reset to defaults'), '#submit' => array('uc_store_address_fields_form_reset'), ); return $form; } /** * Returns HTML for uc_store_address_fields_form(). * * @see uc_store_address_fields_form() * @ingroup themeable */ function theme_uc_store_address_fields_form($variables) { $form = $variables['form']; $header = array(t('Enabled'), t('Field'), t('Title'), t('Required')); foreach (element_children($form['fields']) as $field) { $rows[] = array( array('data' => drupal_render($form['fields'][$field]['enabled']), 'align' => 'center'), drupal_render($form['fields'][$field]['default']), drupal_render($form['fields'][$field]['title']), drupal_render($form['fields'][$field]['required']), ); } $output = theme('table', array('header' => $header, 'rows' => $rows)) . ' . drupal_get_path('module', 'uc_store')
           . '/images/' . $file . '.gif) ';
  return $output;
}
/**
 * Formats an amount for display with the store's currency settings.
 *
 * @param $value
 *   The numeric value of the currency amount.
 * @param $sign
 *   The currency symbol. If FALSE is given, no symbol is used. The default,
 *   NULL, causes the variable 'uc_currency_sign' to be used, which defaults to
 *   '$'.
 * @param $thou
 *   The thousands separator character. If FALSE is given, no separator is used.
 *   The default, NULL, causes the variable 'uc_currency_sign' to be used, which
 *   defaults to ','.
 * @param $dec
 *   The decimal separator character. If FALSE is given, confusion will abound,
 *   because it will look 100 times bigger. The default, NULL, causes the
 *   variable 'uc_currency_dec' to be used, which defaults to '.'.
 */
function uc_currency_format($value, $sign = NULL, $thou = NULL, $dec = NULL) {
  if ($value === NULL) {
    return NULL;
  }
  $output = '';
  $sign_after = variable_get('uc_sign_after_amount', FALSE);
  $prec = variable_get('uc_currency_prec', 2);
  if (is_null($sign)) {
    $sign = variable_get('uc_currency_sign', '$');
  }
  if (is_null($thou)) {
    $thou = variable_get('uc_currency_thou', ',');
  }
  if (is_null($dec)) {
    $dec = variable_get('uc_currency_dec', '.');
  }
  // If the value is significantly less than the minimum precision, zero it.
  if ($prec > 0 && round(abs($value), $prec + 1) < pow(10, -$prec)) {
    $value = 0;
  }
  // Force the price to a positive value and add a negative sign if necessary.
  if ($value < 0) {
    $value = abs($value);
    $output .= '-';
  }
  // Add the currency sign first if specified.
  if ($sign && !$sign_after) {
    $output .= $sign;
  }
  // Format the number, like 1234.567 => 1,234.57
  $output .= number_format($value, $prec, $dec, $thou);
  // Add the currency sign last if specified.
  if ($sign && $sign_after) {
    $output .= $sign;
  }
  return $output;
}
/**
 * Formats a weight value for display.
 */
function uc_weight_format($value, $unit = NULL) {
  $vars = array('!value' => $value);
  if (is_null($unit)) {
    $unit = variable_get('uc_weight_unit', 'lb');
  }
  $defaults = array(
    'lb' => '!value lb.',
    'oz' => '!value oz.',
    'kg' => '!valuekg',
    'g' => '!valueg',
  );
  $pattern = variable_get('uc_weight_format_' . $unit, $defaults[$unit]);
  if (strpos($pattern, '!value') === FALSE) {
    $pattern = $defaults[$unit];
  }
  $format = strtr($pattern, $vars);
  return $format;
}
/**
 * Gets the conversion ratio from one unit of weight to another.
 */
function uc_weight_conversion($from_units, $to_units = NULL) {
  if (is_null($to_units)) {
    $to_units = variable_get('uc_weight_unit', 'lb');
  }
  $constant = strtoupper($from_units) . '_TO_' . strtoupper($to_units);
  if (defined($constant) && ($conversion = constant($constant)) > 0) {
    return $conversion;
  }
  else {
    return 1;
  }
}
/**
 * Formats a length value for display.
 */
function uc_length_format($value, $unit = NULL) {
  $vars = array('!value' => $value);
  if (is_null($unit)) {
    $unit = variable_get('uc_length_unit', 'in');
  }
  $defaults = array(
    'in' => '!valuein.',
    'ft' => '!valueft.',
    'cm' => '!valuecm',
    'mm' => '!valuemm',
  );
  $pattern = variable_get('uc_length_format_' . $unit, $defaults[$unit]);
  if (strpos($pattern, '!value') === FALSE) {
    $pattern = $defaults[$unit];
  }
  $format = strtr($pattern, $vars);
  return $format;
}
/**
 * Gets the conversion ratio from one unit of length to another.
 */
function uc_length_conversion($from_units, $to_units = NULL) {
  if (is_null($to_units)) {
    $to_units = variable_get('uc_length_unit', 'in');
  }
  $constant = strtoupper($from_units) . '_TO_' . strtoupper($to_units);
  if (defined($constant) && ($conversion = constant($constant)) > 0) {
    return $conversion;
  }
  else {
    return 1;
  }
}
/**
 * Formats a date value for display.
 */
function uc_date_format($month, $day, $year, $class = 'default') {
  $time = strtotime($month . '/' . $day . '/' . $year);
  $pattern = variable_get('uc_date_format_' . $class, 'm/d/Y');
  if (strlen($pattern) < 3) {
    $pattern = 'm/d/Y';
  }
  return format_date($time, 'custom', $pattern);
}
/**
 * Saves the address format for a country.
 */
function uc_set_address_format($country_id, $format) {
  variable_set('uc_address_format_' . intval($country_id), $format);
}
/**
 * Formats an address for display based on a country's address format.
 */
function uc_address_format($first_name, $last_name, $company, $street1, $street2, $city, $zone, $postal_code, $country) {
  $result = db_query("SELECT * FROM {uc_zones} WHERE zone_id = :id", array(':id' => $zone));
  if (!($zone_data = $result->fetchAssoc())) {
    $zone_data = array('zone_code' => t('N/A'), 'zone_name' => t('Unknown'));
  }
  $result = db_query("SELECT * FROM {uc_countries} WHERE country_id = :id", array(':id' => $country));
  if (!($country_data = $result->fetchAssoc())) {
    $country_data = array(
      'country_name' => t('Unknown'),
      'country_iso_code_2' => t('N/A'),
      'country_iso_code_3' => t('N/A'),
    );
  }
  $variables = array(
    "\r\n" => '
';
  return $output;
}
/**
 * Formats an amount for display with the store's currency settings.
 *
 * @param $value
 *   The numeric value of the currency amount.
 * @param $sign
 *   The currency symbol. If FALSE is given, no symbol is used. The default,
 *   NULL, causes the variable 'uc_currency_sign' to be used, which defaults to
 *   '$'.
 * @param $thou
 *   The thousands separator character. If FALSE is given, no separator is used.
 *   The default, NULL, causes the variable 'uc_currency_sign' to be used, which
 *   defaults to ','.
 * @param $dec
 *   The decimal separator character. If FALSE is given, confusion will abound,
 *   because it will look 100 times bigger. The default, NULL, causes the
 *   variable 'uc_currency_dec' to be used, which defaults to '.'.
 */
function uc_currency_format($value, $sign = NULL, $thou = NULL, $dec = NULL) {
  if ($value === NULL) {
    return NULL;
  }
  $output = '';
  $sign_after = variable_get('uc_sign_after_amount', FALSE);
  $prec = variable_get('uc_currency_prec', 2);
  if (is_null($sign)) {
    $sign = variable_get('uc_currency_sign', '$');
  }
  if (is_null($thou)) {
    $thou = variable_get('uc_currency_thou', ',');
  }
  if (is_null($dec)) {
    $dec = variable_get('uc_currency_dec', '.');
  }
  // If the value is significantly less than the minimum precision, zero it.
  if ($prec > 0 && round(abs($value), $prec + 1) < pow(10, -$prec)) {
    $value = 0;
  }
  // Force the price to a positive value and add a negative sign if necessary.
  if ($value < 0) {
    $value = abs($value);
    $output .= '-';
  }
  // Add the currency sign first if specified.
  if ($sign && !$sign_after) {
    $output .= $sign;
  }
  // Format the number, like 1234.567 => 1,234.57
  $output .= number_format($value, $prec, $dec, $thou);
  // Add the currency sign last if specified.
  if ($sign && $sign_after) {
    $output .= $sign;
  }
  return $output;
}
/**
 * Formats a weight value for display.
 */
function uc_weight_format($value, $unit = NULL) {
  $vars = array('!value' => $value);
  if (is_null($unit)) {
    $unit = variable_get('uc_weight_unit', 'lb');
  }
  $defaults = array(
    'lb' => '!value lb.',
    'oz' => '!value oz.',
    'kg' => '!valuekg',
    'g' => '!valueg',
  );
  $pattern = variable_get('uc_weight_format_' . $unit, $defaults[$unit]);
  if (strpos($pattern, '!value') === FALSE) {
    $pattern = $defaults[$unit];
  }
  $format = strtr($pattern, $vars);
  return $format;
}
/**
 * Gets the conversion ratio from one unit of weight to another.
 */
function uc_weight_conversion($from_units, $to_units = NULL) {
  if (is_null($to_units)) {
    $to_units = variable_get('uc_weight_unit', 'lb');
  }
  $constant = strtoupper($from_units) . '_TO_' . strtoupper($to_units);
  if (defined($constant) && ($conversion = constant($constant)) > 0) {
    return $conversion;
  }
  else {
    return 1;
  }
}
/**
 * Formats a length value for display.
 */
function uc_length_format($value, $unit = NULL) {
  $vars = array('!value' => $value);
  if (is_null($unit)) {
    $unit = variable_get('uc_length_unit', 'in');
  }
  $defaults = array(
    'in' => '!valuein.',
    'ft' => '!valueft.',
    'cm' => '!valuecm',
    'mm' => '!valuemm',
  );
  $pattern = variable_get('uc_length_format_' . $unit, $defaults[$unit]);
  if (strpos($pattern, '!value') === FALSE) {
    $pattern = $defaults[$unit];
  }
  $format = strtr($pattern, $vars);
  return $format;
}
/**
 * Gets the conversion ratio from one unit of length to another.
 */
function uc_length_conversion($from_units, $to_units = NULL) {
  if (is_null($to_units)) {
    $to_units = variable_get('uc_length_unit', 'in');
  }
  $constant = strtoupper($from_units) . '_TO_' . strtoupper($to_units);
  if (defined($constant) && ($conversion = constant($constant)) > 0) {
    return $conversion;
  }
  else {
    return 1;
  }
}
/**
 * Formats a date value for display.
 */
function uc_date_format($month, $day, $year, $class = 'default') {
  $time = strtotime($month . '/' . $day . '/' . $year);
  $pattern = variable_get('uc_date_format_' . $class, 'm/d/Y');
  if (strlen($pattern) < 3) {
    $pattern = 'm/d/Y';
  }
  return format_date($time, 'custom', $pattern);
}
/**
 * Saves the address format for a country.
 */
function uc_set_address_format($country_id, $format) {
  variable_set('uc_address_format_' . intval($country_id), $format);
}
/**
 * Formats an address for display based on a country's address format.
 */
function uc_address_format($first_name, $last_name, $company, $street1, $street2, $city, $zone, $postal_code, $country) {
  $result = db_query("SELECT * FROM {uc_zones} WHERE zone_id = :id", array(':id' => $zone));
  if (!($zone_data = $result->fetchAssoc())) {
    $zone_data = array('zone_code' => t('N/A'), 'zone_name' => t('Unknown'));
  }
  $result = db_query("SELECT * FROM {uc_countries} WHERE country_id = :id", array(':id' => $country));
  if (!($country_data = $result->fetchAssoc())) {
    $country_data = array(
      'country_name' => t('Unknown'),
      'country_iso_code_2' => t('N/A'),
      'country_iso_code_3' => t('N/A'),
    );
  }
  $variables = array(
    "\r\n" => '