'admin/store',
'title' => t('Store administration'),
'description' => t('Administer store settings, products, orders, and more.'),
'callback' => 'uc_store_admin',
'access' => user_access('administer store'),
'type' => MENU_NORMAL_ITEM,
);
$items[] = array(
'path' => 'admin/store/customers',
'title' => t('Customers'),
'description' => t('View and modify customer information and orders.'),
'callback' => 'uc_store_customers',
'callback arguments' => array(NULL, NULL, NULL, 25),
'access' => user_access('view customers'),
'weight' => -6,
'type' => MENU_NORMAL_ITEM,
);
$items[] = array(
'path' => 'admin/store/customers/view',
'title' => t('View customers'),
'description' => t('View and modify customer information and orders.'),
'callback arguments' => array(NULL, NULL, NULL, 25),
'access' => user_access('view customers'),
'weight' => -10,
'type' => MENU_NORMAL_ITEM,
);
$items[] = array(
'path' => 'admin/store/customers/search',
'title' => t('Search customers'),
'description' => t('Search through your customer list.'),
'callback' => 'uc_store_customer_search',
'access' => user_access('view customers'),
'weight' => -5,
'type' => MENU_NORMAL_ITEM,
);
$items[] = array(
'path' => 'admin/store/reports',
'title' => t('Reports'),
'description' => t('Browse various store reports.'),
'callback' => 'uc_store_reports',
'access' => user_access('view store reports'),
'weight' => 2,
'type' => MENU_NORMAL_ITEM,
);
$items[] = array(
'path' => 'admin/store/settings',
'title' => t('Configuration'),
'description' => t('Adjust configuration settings for Ubercart.'),
'callback' => 'uc_store_configuration_page',
'access' => user_access('administer store'),
'weight' => 6,
'type' => MENU_NORMAL_ITEM,
);
$items[] = array(
'path' => 'admin/store/help',
'title' => t('Help'),
'description' => t('Links to get help!'),
'callback' => 'uc_store_ubercart_help',
'access' => user_access('administer store'),
'weight' => 10,
'type' => MENU_NORMAL_ITEM,
);
$items[] = array(
'path' => 'admin/store/help/tokens',
'title' => t('Using tokens'),
'description' => t('Understand what tokens are and how to use them.'),
'callback' => 'uc_store_ubercart_help_tokens',
'access' => user_access('administer store'),
'type' => MENU_NORMAL_ITEM,
);
$items[] = array(
'path' => 'admin/store/settings/countries',
'title' => t('Country settings'),
'callback' => 'uc_country_settings_overview',
'access' => user_access('administer store'),
'description' => t('Configure country specific settings.'),
'type' => MENU_NORMAL_ITEM,
);
$items[] = array(
'path' => 'admin/store/settings/countries/overview',
'title' => t('Overview'),
'access' => user_access('administer store'),
'description' => t('View the country settings.'),
'type' => MENU_DEFAULT_LOCAL_TASK,
'weight' => -10,
);
$items[] = array(
'path' => 'admin/store/settings/countries/edit',
'title' => t('Edit'),
'callback' => 'drupal_get_form',
'callback arguments' => array('uc_country_import_form'),
'access' => user_access('administer store'),
'description' => t('Edit the country settings.'),
'type' => MENU_LOCAL_TASK,
'weight' => -5,
);
$items[] = array(
'path' => 'admin/store/settings/countries/edit/import',
'title' => t('Import countries'),
'access' => user_access('administer store'),
'description' => t('Import and manage countries.'),
'type' => MENU_DEFAULT_LOCAL_TASK,
'weight' => -10,
);
$items[] = array(
'path' => 'admin/store/settings/countries/edit/formats',
'title' => t('Country formats'),
'access' => user_access('administer store'),
'callback' => 'drupal_get_form',
'callback arguments' => array('uc_country_formats_form'),
'description' => t('Edit the country specific format settings.'),
'type' => MENU_LOCAL_TASK,
'weight' => -5,
);
$items[] = array(
'path' => 'admin/store/settings/store',
'title' => t('Store settings'),
'callback' => 'uc_store_store_settings_overview',
'access' => user_access('administer store'),
'description' => t('Configure the main store settings.'),
'type' => MENU_NORMAL_ITEM,
);
$items[] = array(
'path' => 'admin/store/settings/store/overview',
'title' => t('Overview'),
'access' => user_access('administer store'),
'description' => t('View the store settings.'),
'type' => MENU_DEFAULT_LOCAL_TASK,
'weight' => -10,
);
$items[] = array(
'path' => 'admin/store/settings/store/edit',
'title' => t('Edit'),
'callback' => 'drupal_get_form',
'callback arguments' => array('uc_store_store_settings_form'),
'access' => user_access('administer store'),
'description' => t('Edit the store settings.'),
'type' => MENU_LOCAL_TASK,
'weight' => -5,
);
$items[] = array(
'path' => 'admin/store/settings/store/edit/contact',
'title' => t('Contact settings'),
'access' => user_access('administer store'),
'description' => t('Edit the contact settings.'),
'type' => MENU_DEFAULT_LOCAL_TASK,
'weight' => -10,
);
$items[] = array(
'path' => 'admin/store/settings/store/edit/display',
'title' => t('Display settings'),
'access' => user_access('administer store'),
'callback' => 'drupal_get_form',
'callback arguments' => array('uc_store_display_settings_form'),
'description' => t('Edit the display settings.'),
'type' => MENU_LOCAL_TASK,
'weight' => -5,
);
$items[] = array(
'path' => 'admin/store/settings/store/edit/format',
'title' => t('Format settings'),
'access' => user_access('administer store'),
'callback' => 'drupal_get_form',
'callback arguments' => array('uc_store_format_settings_form'),
'description' => t('Edit the format settings.'),
'type' => MENU_LOCAL_TASK,
'weight' => 0,
);
$items[] = array(
'path' => 'admin/store/settings/store/edit/report',
'title' => t('Reporting settings'),
'callback' => 'drupal_get_form',
'callback arguments' => array('uc_store_report_settings'),
'access' => user_access('administer store'),
'description' => t('Report version information to Ubercart.org.'),
'type' => MENU_LOCAL_TASK,
'weight' => 10,
);
$items[] = array(
'path' => 'admin/store/settings/store/initials',
'title' => t('User initials'),
'callback' => 'drupal_get_form',
'callback arguments' => array('uc_store_initials'),
'access' => user_access('administer store'),
'description' => t('Assign initials to user accounts.'),
'type' => MENU_NORMAL_ITEM,
);
$items[] = array(
'path' => 'admin/store/settings/tables',
'title' => t('Table display settings'),
'callback' => 'uc_store_tables',
'access' => user_access('administer store'),
'description' => t('Configure the display of tables in your store.'),
'type' => MENU_NORMAL_ITEM,
);
}
else {
uc_add_js(array('base_path' => base_path()), 'setting');
$items[] = array(
'path' => 'uc_js_util/'. arg(1),
'title' => t('JS utilities'),
'callback' => 'uc_store_js_util',
'callback arguments' => array(arg(1)),
'access' => user_access('access content'),
'type' => MENU_CALLBACK,
);
if (arg(2) == 'customers') {
$items[] = array(
'path' => 'admin/store/customers/orders/'. arg(4),
'title' => t('Customer orders'),
'callback' => 'uc_store_customer_orders',
'callback arguments' => array(intval(arg(4))),
'description' => t('View a list of orders placed by this customer.'),
'access' => user_access('view all orders'),
'weight' => -5,
'type' => MENU_CALLBACK,
);
}
if (is_numeric(arg(4))) {
$items[] = array(
'path' => 'admin/store/settings/countries/'. arg(4) .'/disable',
'title' => t('Disable a country'),
'description' => t('Disable a country from use.'),
'callback' => 'uc_country_disable',
'callback arguments' => array(arg(4)),
'access' => user_access('administer store'),
'type' => MENU_CALLBACK,
);
$items[] = array(
'path' => 'admin/store/settings/countries/'. arg(4) .'/enable',
'title' => t('Enable a country'),
'description' => t('Enable a disabled country.'),
'callback' => 'uc_country_enable',
'callback arguments' => array(arg(4)),
'access' => user_access('administer store'),
'type' => MENU_CALLBACK,
);
$items[] = array(
'path' => 'admin/store/settings/countries/'. arg(4) .'/remove',
'title' => t('Remove a country'),
'description' => t('Remove an installed country.'),
'callback' => 'drupal_get_form',
'callback arguments' => array('uc_country_remove_form', arg(4)),
'access' => user_access('administer store'),
'type' => MENU_CALLBACK,
);
$items[] = array(
'path' => 'admin/store/settings/countries/'. arg(4) .'/update/'. arg(6),
'title' => t('Update a country'),
'description' => t('Update an installed country.'),
'callback' => 'uc_country_update',
'callback arguments' => array(arg(4), arg(6)),
'access' => user_access('administer store'),
'type' => MENU_CALLBACK,
);
}
}
return $items;
}
/**
* Implementation of hook_init().
*/
function uc_store_init() {
// Add base_path to the Drupal object for use in Ubercart .js files.
// uc_add_js(array('base_path' => base_path()), 'setting');
}
/**
* Implementation of hook_token_values(). (token.module)
*/
function uc_store_token_values($type, $object = NULL) {
global $base_url;
switch ($type) {
case 'global':
$login_link = url('user', NULL, NULL, TRUE);
$values['site-login'] = l($login_link, $login_link);
$theme_key = variable_get('theme_default', 'garland');
$settings = theme_get_settings($theme_key);
$themes = list_themes();
$theme_object = $themes[$theme_key];
if ($settings['toggle_logo']) {
if ($settings['default_logo']) {
$settings['logo'] = dirname($theme_object->filename) .'/logo.png';
}
elseif ($settings['logo_path']) {
$settings['logo'] = $settings['logo_path'];
}
}
$values['site-logo'] = '';
$values['store-name'] = variable_get('uc_store_name', t('Our store'));
$values['store-url'] = variable_get('uc_store_url', $base_url);
$values['store-link'] = l(variable_get('uc_store_name', t('Our store')), variable_get('uc_store_url', $base_url));
$values['store-owner'] = variable_get('uc_store_owner', '');
$values['store-email'] = variable_get('uc_store_email', '');
$values['store-phone'] = variable_get('uc_store_phone', '');
$values['store-address'] = uc_store_address();
$values['store-help-url'] = url(variable_get('uc_notify_store_help_page', ''), NULL, NULL, TRUE);
break;
}
return $values;
}
/**
* Implementation of hook_token_list(). (token.module)
*/
function uc_store_token_list($type = 'all') {
$tokens['global']['site-login'] = t('A link to the site login page.');
$tokens['global']['site-logo'] = t('The URL for the site logo.');
$tokens['global']['store-name'] = t('The Ubercart store name.');
$tokens['global']['store-url'] = t('The Ubercart store URL.');
$tokens['global']['store-link'] = t('A link to the Ubercart store using the store name.');
$tokens['global']['store-owner'] = t('The Ubercart store owner.');
$tokens['global']['store-email'] = t('The Ubercart store e-mail address.');
$tokens['global']['store-phone'] = t('The Ubercart store phone number.');
$tokens['global']['store-address'] = t('The Ubercart store mailing address.');
$tokens['global']['store-help-url'] = t('The URL to the store help page.');
return $tokens;
}
function uc_store_help($section) {
switch ($section) {
case 'admin/store/settings/store/edit/report':
return t("Reporting to Ubercart.org happens once a week during a normal cron run and is logged in your site's watchdog. Reporting lets Ubercart.org calculate the total number of Ubercart installations and aggregate version information for use in development. Your site's data is never shared with anyone, and aggregate statistics displayed through Ubercart.org will be in the form of anonymous group statistics. Reporting will also allow Ubercart.org to report security notices back to your site if needed.");
}
}
/**
* Implementation of hook_cron().
*/
function uc_store_cron() {
// Report version information into Ubercart.org once a week if enabled.
if (variable_get('uc_store_report', TRUE) && variable_get('uc_store_last_report', 0) <= time() - 604800) {
uc_store_send_report();
}
}
/**
* Implementation of hook_block().
*/
function uc_store_block($op = 'list', $delta = 0, $edit = array()) {
if ($op == 'list') {
$blocks[0]['info'] = t('Store links');
return $blocks;
}
else if ($op == 'view') {
switch ($delta) {
case 0:
if (!user_access('administer store')) {
break;
}
uc_add_js(drupal_get_path('module', 'uc_store') .'/uc_store.js');
$menu = menu_get_item(null, 'admin/store');
$output = '
| '. l(uc_store_get_icon($menu['path']), $menu['path'], array(), NULL, NULL, FALSE, TRUE) .' | ' .''. l($menu['title'], $menu['path']) .' |
| '. $panel_links .' | |
| '. t('- Show links -') .' | |
'. $message .'
' . theme('table', $header, $rows, array('width' => '100%', 'class' => 'uc-customer-table')) .''. l(t('Create an order for this customer.'), 'admin/store/orders/create/'. $uid) .'
'; $output .= ''. t('!totals_orders orders shown match that account with !totals_items items purchased and !totals_total spent:', array('!totals_orders' => $totals['orders'], '!totals_items' => $totals['items'], '!totals_total' => uc_currency_format($totals['total']))) .'
' . theme('table', $header, $rows, array('width' => '100%', 'class' => 'uc-cust-orders-table')) .'| ');
$form['search']['desc'] = array(
'#value' => ' '. t("Search for customers based on any of the following fields. Use * as a wildcard to match any character. ',
);
$form['search']['table2'] = array('#value' => 'For example, searching by last name for 's*' will return all customers whose last name starts with an s. (Leave a field empty to ignore it in the search.)"). ' | |||
| '); $form['search']['first_name'] = array( '#type' => 'textfield', '#title' => t('First name'), '#default_value' => arg(5) != '0' ? arg(5) : '', '#size' => 24, '#maxlength' => 32, ); $form['search']['table3'] = array('#value' => ' | '); $form['search']['last_name'] = array( '#type' => 'textfield', '#title' => t('Last name'), '#default_value' => arg(6) != '0' ? arg(6) : '', '#size' => 24, '#maxlength' => 32, ); $form['search']['table4'] = array('#value' => ' | '); $form['search']['email'] = array( '#type' => 'textfield', '#title' => t('E-mail'), '#default_value' => arg(7) != '0' ? arg(7) : '', '#size' => 24, '#maxlength' => 96, ); $form['search']['table5'] = array('#value' => ' | '); $form['search']['submit'] = array( '#type' => 'submit', '#value' => t('Search'), ); $form['search']['table6'] = array('#value' => ' |
'. t('Use the following links to find documentation and support:') .'
'; $items[] = l(t("Ubercart User's Guide"), 'http://www.ubercart.org/docs/user'); $items[] = l(t('Support Forums'), 'http://www.ubercart.org/forum'); $items[] = l(t('Drupal Handbook'), 'http://drupal.org/node/258'); $output .= theme_item_list($items); return $output; } /** * Display the tokens help page. */ function uc_store_ubercart_help_tokens() { $output = ''. t('Tokens are bracketed phrases you can use in certain text fields and boxes as placeholders for some other text. Tokens represent things like store variables, links to certain pages, order information, etc. Tokens are used by including the token listed below in a text field that uses them. The description for the textfields will alert you to which groups of tokens listed below may be used.') .'
'; $output .= theme('token_help', 'ubercart'); return $output; } /** * Display the country settings overview. */ function uc_country_settings_overview() { $result = db_query("SELECT * FROM {uc_countries} ORDER BY country_name ASC"); while ($country = db_fetch_object($result)) { $items[] = t('!country version !version is !status.', array('!country' => $country->country_name, '!version' => abs($country->version), '!status' => $country->version > 0 ? t('enabled') : t('disabled'))); } $sections[] = array( 'edit' => 'admin/store/settings/countries/edit', 'title' => t('Imported countries'), 'items' => $items, ); $sections[] = array( 'edit' => 'admin/store/settings/countries/edit/formats', 'title' => t('Country specific formats'), 'items' => array( t('Tweak the address formatting for a specific country.'), ), ); $output = theme('uc_settings_overview', $sections); return $output; } function uc_country_import_form() { $result = db_query("SELECT * FROM {uc_countries} ORDER BY country_name ASC"); while ($country = db_fetch_object($result)) { $countries[] = $country; } $files = _country_import_list(); $header = array(t('Country'), t('Code'), t('Version'), t('Operations')); if (is_array($countries)) { foreach ($countries as $country) { $row = array( $country->country_name, $country->country_iso_code_3, array('data' => abs($country->version), 'align' => 'center') ); $ops = array(); if ($country->version < 0) { $ops[] = l(t('enable'), 'admin/store/settings/countries/'. $country->country_id .'/enable'); } else { $ops[] = l(t('disable'), 'admin/store/settings/countries/'. $country->country_id .'/disable'); } if ($country->version < $files[$country->country_id]['version'] && $country->version > 0) { $ops[] = l(t('update'), 'admin/store/settings/countries/'. $country->country_id .'/update/'. $files[$country->country_id]['version']); } $ops[] = l(t('remove'), 'admin/store/settings/countries/'. $country->country_id .'/remove'); $row[] = implode(' ', $ops); $rows[] = $row; unset($files[$country->country_id]); } } foreach ($files as $file) { $import_list[$file['file']] = $file['file']; } if (is_array($import_list)) { ksort($import_list); } $form['text'] = array( '#value' => t('To import new country data, select it in the list and click the import button. If you are using a custom or contributed import file, it must be placed in the Ubercart folder uc_store/countries.'), ); if (is_array($import_list)) { $options = $import_list; } else { $options = array(t('-None available-')); } $form['import_file'] = array( '#type' => 'select', '#title' => t('Country'), '#options' => $options, '#disabled' => !is_array($import_list), '#multiple' => is_array($import_list), '#size' => min(10, count($options)), ); $form['import_button'] = array( '#type' => 'submit', '#value' => t('Import'), '#disabled' => !is_array($import_list), ); $form['country_table'] = array( '#value' => theme('table', $header, $rows), ); return $form; } function uc_country_import_form_submit($form_id, $form_values) { $files = $form_values['import_file']; foreach ($files as $file) { $pieces = explode('_', substr($file, 0, strlen($file) - 4)); $country_id = $pieces[count($pieces) - 2]; $version = $pieces[count($pieces) - 1]; $country = substr($file, 0, strlen($file) - strlen($country_id) - strlen($version) - 6); require_once(drupal_get_path('module', 'uc_store') .'/countries/'. $file); $func = $country .'_install'; if (function_exists($func)) { $func(); drupal_set_message(t('Country file @file imported.', array('@file' => $file))); } else { drupal_set_message(t('Country file @file had no install function.', array('@file' => $file)), 'error'); } } } /** * Disable a country so it remains installed but is no longer selectable. */ function uc_country_disable($country_id) { $result = db_query("SELECT * FROM {uc_countries} WHERE country_id = %d", $country_id); if (($country = db_fetch_object($result))) { if ($country->version > 0) { db_query("UPDATE {uc_countries} SET version = %d WHERE country_id = %d", 0 - $country->version, $country_id); drupal_set_message(t('!country disabled.', array('!country' => $country->country_name))); } else { drupal_set_message(t('!country is already disabled.', array('!country' => $country->country_name)), 'error'); } } else { drupal_set_message(t('Attempted to disable an invalid country.'), 'error'); } drupal_goto('admin/store/settings/countries/edit'); } /** * Enable a disabled country. */ function uc_country_enable($country_id) { $result = db_query("SELECT * FROM {uc_countries} WHERE country_id = %d", $country_id); if (($country = db_fetch_object($result))) { if ($country->version < 0) { db_query("UPDATE {uc_countries} SET version = %d WHERE country_id = %d", abs($country->version), $country_id); drupal_set_message(t('@country enabled.', array('@country' => $country->country_name))); } else { drupal_set_message(t('@country is already enabled.', array('@country' => $country->country_name)), 'error'); } } else { drupal_set_message(t('Attempted to enable an invalid country.'), 'error'); } drupal_goto('admin/store/settings/countries/edit'); } // Form to completely remove a country. function uc_country_remove_form($country_id) { // Fetch the country name from the database. $country = db_result(db_query("SELECT country_name FROM {uc_countries} WHERE country_id = %d", $country_id)); // If orders exist for this country, show a warning message prior to removal. if ($_POST['op'] != t('Remove') && module_exists('uc_order')) { $count = db_result(db_query("SELECT COUNT(order_id) FROM {uc_orders} WHERE delivery_country = %d OR billing_country = %d", $country_id, $country_id)); if ($count > 0) { drupal_set_message(t('Warning: @count orders were found with addresses in @country. Removing it now will cause errors to show on those order pages. You might consider simply disabling @country instead.', array('@count' => $count, '@country' => $country)), 'error'); } } // Store the country ID in the form array for processing. $form['country_id'] = array( '#type' => 'value', '#value' => $country_id, ); return confirm_form($form, t('Are you sure you want to remove @country from the system?', array('@country' => $country)), 'admin/store/settings/countries/edit', NULL, t('Remove')); } function uc_country_remove_form_submit($form_id, $form_values) { $country_id = $form_values['country_id']; $result = db_query("SELECT * FROM {uc_countries} WHERE country_id = %d", $country_id); if (!($country = db_fetch_object($result))) { drupal_set_message(t('Attempted to remove an invalid country.'), 'error'); drupal_goto('admin/store/settings/countries'); } db_query("DELETE FROM {uc_countries} WHERE country_id = %d", $country_id); db_query("DELETE FROM {uc_zones} WHERE zone_country_id = %d", $country_id); variable_del('uc_address_format_'. $country_id); $func_base = _country_import_include($country_id, $country->version); if ($func_base !== FALSE) { $func = $func_base .'_uninstall'; if (function_exists($func)) { $func(); } } drupal_set_message(t('!country removed.', array('!country' => $country->country_name))); drupal_goto('admin/store/settings/countries/edit'); } /** * Update a country to its latest version. */ function uc_country_update($country_id, $version) { $result = db_query("SELECT * FROM {uc_countries} WHERE country_id = %d", $country_id); if (!($country = db_fetch_object($result))) { drupal_set_message(t('Attempted to update an invalid country.')); drupal_goto('admin/store/settings/countries'); } if ($version < $country->version) { drupal_set_message(t('You cannot update to a previous version.')); drupal_goto('admin/store/settings/countries'); } $func_base = _country_import_include($country_id, $version); if ($func_base !== FALSE) { $func = $func_base .'_update'; if (function_exists($func)) { for ($i = $country->version; $i <= $version; $i++) { $func($i); } } db_query("UPDATE {uc_countries} SET version = %d WHERE country_id = %d", $version, $country_id); drupal_set_message(t('Country update complete.')); } else { drupal_set_message(t('Attempted to update an invalid country.')); } drupal_goto('admin/store/settings/countries'); } function uc_country_formats_form() { $form['instructions'] = array( '#type' => 'fieldset', '#title' => t('Address variables instructions'), '#collapsible' => TRUE, '#collapsed' => TRUE, ); $header = array(t('Variable'), t('Description')); $rows = array( array('!first_name', t("Customer's first name")), array('!last_name', t("Customer's last name")), array('!company', t('Company name')), array('!street1', t('First street address field')), array('!street2', t('Second street address field')), array('!city', t('City name')), array('!zone_name', t('Full name of the zone')), array('!zone_code', t('Abbreviation of the zone')), array('!postal_code', t('Postal code')), array('!country_name', t('Name of the country')), array('!country_code2', t('2 digit country abbreviation')), array('!country_code3', t('3 digit country abbreviation')), ); $form['instructions']['text'] = array( '#value' => '' . theme('table', $header, $rows) .'
'. t('*Adding _if to any country variable will make it only display for addresses
whose country is different than the default store country.') .'
!address', array('!address' => uc_store_address())),
),
);
switch (variable_get('uc_store_admin_page_display', 1)) {
case 1:
$type = t('Dashboard with collapsed submenu links');
break;
case 2:
$type = t('Dashboard with expanded submenu links');
break;
case 3:
$type = t('Dashboard with no submenu links');
break;
case 4:
$type = t('Normal Drupal submenu listing');
break;
}
$sections[] = array(
'edit' => 'admin/store/settings/store/edit/display',
'title' => t('Display settings'),
'items' => array(
t('Store admin page display type:
!type', array('!type' => $type)),
t('Customer !type address used in lists.', array('!type' => variable_get('uc_customer_list_address', 'billing') == 'billing' ? t('billing') : t('shipping'))),
t('Footer using !type message.', array('!type' => variable_get('uc_footer_message', 0) == 0 ? t('random') : t('specified'))),
),
);
$sections[] = array(
'edit' => 'admin/store/settings/store/edit/format',
'title' => t('Format settings'),
'items' => array(
t('Default currency: !code', array('!code' => variable_get('uc_currency_code', 'USD'))),
t('Currency format: !value', array('!value' => uc_currency_format(1234.56))),
t('Weight format: !value', array('!value' => uc_weight_format(36))),
t('Date format: !value', array('!value' => uc_date_format(8, 18, 2007))),
),
);
$items = array();
if (variable_get('uc_store_report', TRUE)) {
$items[] = t('Version information is being reported to Ubercart.org.');
}
else {
$items[] = t('Your site is not reporting to Ubercart.org.');
}
$sections[] = array(
'edit' => 'admin/store/settings/store/edit/report',
'title' => t('Reporting settings'),
'items' => $items,
);
$output = theme('uc_settings_overview', $sections);
return $output;
}
// Displays the form for store settings.
function uc_store_store_settings_form() {
$form['uc_store_name'] = uc_textfield(t('Store name'), variable_get('uc_store_name', NULL), FALSE, NULL, 64);
$form['uc_store_owner'] = uc_textfield(t('Store owner'), variable_get('uc_store_owner', NULL), FALSE, NULL, 64);
$form['uc_store_email'] = uc_textfield(t('E-mail address'), variable_get('uc_store_email', NULL), FALSE, NULL, 128);
$form['uc_store_email_include_name'] = array(
'#type' => 'checkbox',
'#title' => t('Include the store name in the from line of store e-mails.'),
'#description' => t('May not be available on all server configurations. Turn off if this causes problems.'),
'#default_value' => variable_get('uc_store_email_include_name', TRUE),
);
$form['uc_store_phone'] = uc_textfield(t('Phone number'), variable_get('uc_store_phone', NULL), FALSE);
$form['uc_store_fax'] = uc_textfield(t('Fax number'), variable_get('uc_store_fax', NULL), FALSE);
$form['uc_store_street1'] = uc_textfield(uc_get_field_name('street1'), variable_get('uc_store_street1', NULL), FALSE, NULL, 128);
$form['uc_store_street2'] = uc_textfield(uc_get_field_name('street2'), variable_get('uc_store_street2', NULL), FALSE, NULL, 128);
$form['uc_store_city'] = uc_textfield(uc_get_field_name('city'), variable_get('uc_store_city', NULL), FALSE);
$form['uc_store_country'] = uc_country_select(uc_get_field_name('country'), uc_store_default_country());
if (isset($_POST['uc_store_country'])) {
$country_id = intval($_POST['uc_store_country']);
}
else {
$country_id = uc_store_default_country();
}
$form['uc_store_zone'] = uc_zone_select(uc_get_field_name('zone'), variable_get('uc_store_zone', NULL), NULL, $country_id);
$form['uc_store_postal_code'] = uc_textfield(uc_get_field_name('postal_code'), variable_get('uc_store_postal_code', NULL), FALSE, NULL, 10);
return system_settings_form($form);
}
function uc_store_display_settings_form() {
$form['uc_store_admin_page_display'] = array(
'#type' => 'radios',
'#title' => t('Display type for the main store admininstration page'),
'#description' => t('Some options are better suited for different themes, so feel free to try them all out!'),
'#options' => array(
1 => t('Dashboard with collapsed submenu links'),
2 => t('Dashboard with expanded submenu links'),
3 => t('Dashboard with no submenu links'),
4 => t('Normal Drupal submenu listing'),
),
'#default_value' => variable_get('uc_store_admin_page_display', 1),
);
$desc = t('Select the address to be used on customer lists and summaries.');
if (module_exists('uc_notify')) {
$desc .= ' '. t('Also applies to notification e-mails.');
}
$form['uc_customer_list_address'] = array(
'#type' => 'radios',
'#title' => t('Primary customer address'),
'#description' => $desc,
'#options' => array(
'billing' => t('Billing address'),
'shipping' => t('Shipping address'),
),
'#default_value' => variable_get('uc_customer_list_address', 'billing'),
);
$options = array(t('Randomly select a message from the list below.'));
$form['uc_footer_message'] = array(
'#type' => 'radios',
'#title' => t('Footer message for store pages'),
'#options' => array_merge($options, _store_footer_options()),
'#default_value' => variable_get('uc_footer_message', 0),
);
return system_settings_form($form);
}
// Return the default store footer options.
function _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),
'none' => t('(Do not display a message in the footer.)'),
);
}
// Wrap the footer in a div so it can be re-styled.
function theme_uc_store_footer($message) {
return '
'. print_r(uc_store_report_data(), TRUE) .'', ); return system_settings_form($form); } /** * List of extensible TAPIr tables used by Ubercart. */ function uc_store_tables() { $output = '
'. t('The following tables are used to display various parts of your store to your administrators and customers. Click on a table id to configure the display of that table.'); $output .= '
'. tapir_table_list('admin/store/settings/tables') .'
'; return $output; } /** * A handler for Javascript helper functions... */ function uc_store_js_util($func) { switch ($func) { case 'currency_format': $amount = is_numeric($_POST['amount']) ? $_POST['amount'] : 0; $output = uc_currency_format($amount); break; case 'zone_select': $country_id = intval($_POST['country_id']) > 0 ? intval($_POST['country_id']) : uc_store_default_country(); $title = isset($_POST['title']) ? check_plain($_POST['title']) : NULL; $display = isset($_POST['display']) ? check_plain($_POST['display']) : 'name'; $select = uc_zone_select($title, NULL, NULL, $country_id, $display); $select['#parents'] = array(); $match = array('`<[/]*div[^>]*>`', '`<[/]*select[^>]*>`', '`\n|\r`'); $replace = array('', '', ''); $output = preg_replace($match, $replace, theme('select', $select)); } print $output; exit(); } /******************************************************************************* * Module and Helper Functions ******************************************************************************/ function theme_uc_store_block_links($menu) { if (!($menu['type'] & MENU_VISIBLE_IN_TREE)) { return ''; } $depth = count(explode('/', $menu['path'])); $link_title = uc_store_get_icon($menu['path'], TRUE) .' '. $menu['title']; $output = str_repeat(" ", $depth) .'
';
return $output;
}
/**
* Format an amount for display with the store's currency settings.
*/
function uc_currency_format($value, $sign = TRUE, $thou = TRUE, $dec = NULL) {
if ($value === NULL) {
return NULL;
}
if (variable_get('uc_currency_prec', 2) > 0) {
if (abs($value) < '.'. str_repeat('0', variable_get('uc_currency_prec', 2) - 1) .'1') {
$value = 0;
}
}
$format = '';
if ($value < 0) {
$value = abs($value);
$format = '-';
}
if ($sign && !variable_get('uc_sign_after_amount', FALSE)) {
$format .= variable_get('uc_currency_sign', '$');
}
$format .= number_format($value, variable_get('uc_currency_prec', 2), !is_null($dec) ? $dec : variable_get('uc_currency_dec', '.'), $thou ? variable_get('uc_currency_thou', ',') : '');
if ($sign && variable_get('uc_sign_after_amount', FALSE)) {
$format .= variable_get('uc_currency_sign', '$');
}
return $format;
}
/**
* Format 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;
}
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;
}
}
/**
* Format 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;
}
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;
}
}
/**
* Format 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);
}
/**
* Save the address format for a country.
*/
function uc_set_address_format($country_id, $format) {
variable_set('uc_address_format_'. intval($country_id), $format);
}
/**
* Format 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 = %d", $zone);
if (!($zone_data = db_fetch_array($result))) {
$zone_data = array('zone_code' => t('N/A'), 'zone_name' => t('Unknown'));
}
$result = db_query("SELECT * FROM {uc_countries} WHERE country_id = %d", $country);
if (!($country_data = db_fetch_array($result))) {
$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" => '