'Store administration',
'description' => 'Administer store settings, products, orders, and more.',
'page callback' => 'uc_store_admin',
'access arguments' => array('access administration pages'),
'type' => MENU_NORMAL_ITEM,
'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,
'type' => MENU_NORMAL_ITEM,
'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, NULL, '25'),
'access arguments' => array('view customers'),
'weight' => -10,
'type' => MENU_NORMAL_ITEM,
'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,
'type' => MENU_NORMAL_ITEM,
'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,
'type' => MENU_NORMAL_ITEM,
'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,
'type' => MENU_NORMAL_ITEM,
'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,
'type' => MENU_NORMAL_ITEM,
'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'),
'type' => MENU_NORMAL_ITEM,
'file' => 'uc_store.admin.inc',
);
$items['admin/store/settings/countries'] = array(
'title' => 'Country settings',
'description' => 'Configure country specific settings.',
'page callback' => 'uc_country_settings_overview',
'access arguments' => array('administer store'),
'type' => MENU_NORMAL_ITEM,
'file' => 'uc_store.admin.inc',
);
$items['admin/store/settings/countries/overview'] = array(
'title' => 'Overview',
'description' => 'View the country settings.',
'access arguments' => array('administer store'),
'weight' => -10,
'type' => MENU_DEFAULT_LOCAL_TASK,
'file' => 'uc_store.admin.inc',
);
$items['admin/store/settings/countries/edit'] = array(
'title' => 'Edit',
'description' => 'Edit the country settings.',
'page callback' => 'drupal_get_form',
'page arguments' => array('uc_country_import_form'),
'access arguments' => array('administer store'),
'weight' => -5,
'type' => MENU_LOCAL_TASK,
'file' => 'uc_store.admin.inc',
);
$items['admin/store/settings/countries/edit/import'] = array(
'title' => 'Import 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/edit/formats'] = array(
'title' => 'Country formats',
'description' => 'Edit the country specific 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' => 'uc_store_store_settings_overview',
'access arguments' => array('administer store'),
'type' => MENU_NORMAL_ITEM,
'file' => 'uc_store.admin.inc',
);
$items['admin/store/settings/store/overview'] = array(
'title' => 'Overview',
'description' => 'View the store settings.',
'access arguments' => array('administer store'),
'weight' => -10,
'type' => MENU_DEFAULT_LOCAL_TASK,
'file' => 'uc_store.admin.inc',
);
$items['admin/store/settings/store/edit'] = array(
'title' => 'Edit',
'description' => 'Edit the store settings.',
'page callback' => 'drupal_get_form',
'page arguments' => array('uc_store_store_settings_form'),
'access arguments' => array('administer store'),
'weight' => -5,
'type' => MENU_LOCAL_TASK,
'file' => 'uc_store.admin.inc',
);
$items['admin/store/settings/store/edit/contact'] = array(
'title' => 'Contact settings',
'description' => 'Edit the contact settings.',
'access arguments' => array('administer store'),
'weight' => -10,
'type' => MENU_DEFAULT_LOCAL_TASK,
'file' => 'uc_store.admin.inc',
);
$items['admin/store/settings/store/edit/display'] = array(
'title' => 'Display settings',
'description' => 'Edit the display settings.',
'page callback' => 'drupal_get_form',
'page arguments' => array('uc_store_display_settings_form'),
'access arguments' => array('administer store'),
'weight' => -5,
'type' => MENU_LOCAL_TASK,
'file' => 'uc_store.admin.inc',
);
$items['admin/store/settings/store/edit/format'] = array(
'title' => 'Format settings',
'description' => 'Edit the format settings.',
'page callback' => 'drupal_get_form',
'page arguments' => array('uc_store_format_settings_form'),
'access arguments' => array('administer store'),
'weight' => 0,
'type' => MENU_LOCAL_TASK,
'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'),
'type' => MENU_NORMAL_ITEM,
'file' => 'uc_store.admin.inc',
);
/*$items['admin/store/settings/tables'] = array(
'title' => 'Table display settings',
'description' => 'Configure the display of tables in your store.',
'page callback' => 'uc_store_tables',
'access arguments' => array('administer store'),
'type' => MENU_NORMAL_ITEM,
);*/
$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,
'type' => MENU_CALLBACK,
'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'),
'type' => MENU_CALLBACK,
'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',
);
$items['admin/store/settings/price-handlers'] = array(
'title' => 'Price handler settings',
'description' => 'Select which price handlers to use for your store.',
'page callback' => 'drupal_get_form',
'page arguments' => array('uc_price_settings_form'),
'access arguments' => array('administer store'),
'type' => MENU_NORMAL_ITEM,
'file' => 'uc_store.admin.inc',
);
return $items;
}
/**
* Implementation of 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');
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';
}
/**
* Implementation of hook_elements().
*/
function uc_store_elements() {
$types = array();
$types['tapir_table'] = array(
'#columns' => array(),
'#rows' => array(),
'#tree' => TRUE,
'#value' => NULL,
'#pre_render' => array('tapir_gather_rows'),
'#process' => 'form_expand_ahah',
);
return $types;
}
/**
* Implementation of hook_flush_caches().
*/
function uc_store_flush_caches() {
return array('cache_uc_price');
}
/**
* Implementation of hook_theme().
*/
function uc_store_theme() {
return array(
'uc_admin_dashboard' => array(
'arguments' => array('type' => NULL, 'menus' => NULL),
),
'uc_store_footer' => array(
'arguments' => array('message' => ''),
),
'uc_store_address_fields_form' => array(
'arguments' => array('form' => NULL),
),
'uc_pane_sort_table' => array(
'arguments' => array('form' => NULL),
),
'tapir_table' => array(
'arguments' => array('form' => NULL),
),
'uc_price_settings_form' => array(
'arguments' => array('form' => NULL),
),
'summary_overview' => array(
'arguments' => array(),
),
'uc_price' => array(
'arguments' => array('value' => 0, 'context' => array(), 'options' => array()),
),
);
}
/**
* Implementation of hook_token_values(). (token.module)
*/
function uc_store_token_values($type, $object = NULL) {
global $base_url;
$values = array();
switch ($type) {
case 'global':
$login_link = url('user', array('absolute' => 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'];
}
}
// Use a logo; but only if we have one to use.
if (isset($settings['logo']) && $settings['logo']) {
$values['site-logo'] = '';
}
else {
$values['site-logo'] = '';
}
$values['store-name'] = variable_get('uc_store_name', t('Our store'));
$values['store-url'] = $base_url;
$values['store-link'] = l(variable_get('uc_store_name', t('Our store')), $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-fax'] = variable_get('uc_store_fax', '');
$values['store-address'] = uc_store_address();
$values['store-help-url'] = url(variable_get('uc_store_help_page', ''), array('absolute' => TRUE));
break;
}
return $values;
}
/**
* Implementation of hook_token_list(). (token.module)
*/
function uc_store_token_list($type = 'all') {
$tokens = array();
if ($type == 'global' || $type == 'ubercart' || $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-fax'] = t('The Ubercart store fax 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;
}
/**
* Implementation of hook_help().
*/
function uc_store_help($path, $arg) {
switch ($path) {
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.");
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.');
}
}
/**
* Implementation of hook_perm().
*/
function uc_store_perm() {
return array('administer store', 'view customers', 'view store reports');
}
/**
* Implementation of hook_footer().
*/
function uc_store_footer() {
// Exit if the store footer is turned off.
if (variable_get('uc_footer_message', 0) === 'none') {
return;
}
// Figure out what page is being viewed.
$path = drupal_get_normal_path($_GET['q']);
$parts = explode('/', $path);
// Break out of the switch 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') {
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) {
break;
}
else {
$node = node_load($parts[1]);
if ($node == FALSE || !function_exists('uc_product_node_info') || !uc_product_is_product($node->type)) {
break;
}
}
// Add a footer to the following pages.
case 'catalog':
case 'cart':
case 'manufacturer':
$messages = _store_footer_options();
if (($message = variable_get('uc_footer_message', 0)) > 0) {
$message = $messages[$message];
}
else {
$message = db_result(db_query("SELECT message FROM {uc_store_footers} WHERE path_hash = '%s'", md5($path)));
if (!$message) {
unset($messages['none']);
$message = $messages[array_rand($messages)];
db_query("INSERT INTO {uc_store_footers} (path_hash, message) VALUES ('%s', '%s')", md5($path), $message);
}
}
return theme('uc_store_footer', $message);
}
}
/**
* Implementation of 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 (referer_uri() == '') {
$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'] = time();
}
/**
* Implementation of hook_form_alter().
*/
function uc_store_form_alter(&$form, $form_state, $form_id) {
if ($form_id == 'uc_product_table') {
unset($form['table']['#value']['columns']['list_price']);
}
}
/******************************************************************************
* Callback Functions, Forms, and Tables
******************************************************************************/
/**
* Theme a formatted price for display.
*
* @ingroup themeable
*/
function theme_uc_price($value, $context, $options) {
// Fixup class names.
if (!is_array($context['class'])) {
$context['class'] = array();
}
foreach ($context['class'] as $key => $class) {
$context['class'][$key] = 'uc-price-'. $class;
}
$context['class'][] = 'uc-price';
// Class the element.
$output = '';
// Prefix(es).
if ($options['label'] && isset($options['prefixes'])) {
$output .= ''. implode('', $options['prefixes']) .'';
}
// Value.
$output .= $value;
// Suffix(es).
if ($options['label'] && isset($options['suffixes'])) {
$output .= ''. implode('', $options['suffixes']) .'';
}
$output .= '';
return $output;
}
/**
* Theme the dashboard on the admin/store page.
*
* @ingroup themeable
*/
function theme_uc_admin_dashboard($type, $menus) {
if ($type == 1) {
drupal_add_js(drupal_get_path('module', 'uc_store') .'/uc_store.js', 'module');
drupal_add_js(array('ucTextShow' => t('- Show links -'), 'ucTextHide' => t('- Hide links -')), 'setting');
}
$output = '
| '. l(uc_store_get_icon($menu['href']), $menu['href'], array('html' => TRUE)) .' | ' .''. l($menu['title'], $menu['href']) .' |
| '. $panel_links .' | |
| '. t('- Show links -') .' | |
';
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;
}
$context = array(
'revision' => 'formatted',
'type' => 'amount',
);
$options = array();
if (!$sign) {
$options['sign'] = '';
}
if (!$thou) {
$options['thou'] = '';
}
if (!is_null($dec)) {
$options['dec'] = $dec;
}
return uc_price($value, $context, $options);
}
/**
* 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;
}
/**
* Get 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;
}
}
/**
* 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;
}
/**
* Get 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;
}
}
/**
* 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" => '