Parent Directory
|
Revision Log
|
Revision Graph
Begin the Ubercart 6.x-2.x branch.
| 1 | <?php |
| 2 | // $Id$ |
| 3 | |
| 4 | /** |
| 5 | * @file |
| 6 | * Contains global Ubercart functions and store administration functionality. |
| 7 | * |
| 8 | * The store module is a container of sorts for various helper functions used |
| 9 | * in different parts of the Ubercart core. It also provides screens and |
| 10 | * settings pages for use in store administration. |
| 11 | */ |
| 12 | |
| 13 | /** |
| 14 | * Unit conversion ratios. |
| 15 | * |
| 16 | * Used by the unit conversion functions uc_weight_convesion() and |
| 17 | * uc_length_conversion(). |
| 18 | */ |
| 19 | define('KG_TO_KG', 1); |
| 20 | define('KG_TO_G', 1000); |
| 21 | define('KG_TO_LB', 2.204622621849); |
| 22 | define('KG_TO_OZ', 35.27396194958); |
| 23 | |
| 24 | define('G_TO_G', 1); |
| 25 | define('G_TO_KG', 0.001); |
| 26 | define('G_TO_LB', 0.002204622622); |
| 27 | define('G_TO_OZ', 0.03527396195); |
| 28 | |
| 29 | define('LB_TO_LB', 1); |
| 30 | define('LB_TO_OZ', 16); |
| 31 | define('LB_TO_KG', 0.45359237); |
| 32 | define('LB_TO_G', 453.59237); |
| 33 | |
| 34 | define('OZ_TO_OZ', 1); |
| 35 | define('OZ_TO_LB', 0.0625); |
| 36 | define('OZ_TO_G', 28.349523125); |
| 37 | define('OZ_TO_KG', 0.028349523); |
| 38 | |
| 39 | define('IN_TO_IN', 1); |
| 40 | define('IN_TO_FT', 0.083333333333); |
| 41 | define('IN_TO_CM', 2.54); |
| 42 | define('IN_TO_MM', 25.4); |
| 43 | |
| 44 | define('FT_TO_FT', 1); |
| 45 | define('FT_TO_IN', 12); |
| 46 | define('FT_TO_CM', 30.48); |
| 47 | define('FT_TO_MM', 304.8); |
| 48 | |
| 49 | define('CM_TO_CM', 1); |
| 50 | define('CM_TO_IN', 0.393700787402); |
| 51 | define('CM_TO_FT', 0.03280839895); |
| 52 | define('CM_TO_MM', 10); |
| 53 | |
| 54 | define('MM_TO_MM', 1); |
| 55 | define('MM_TO_IN', 0.03937007874); |
| 56 | define('MM_TO_FT', 0.003280839895); |
| 57 | define('MM_TO_CM', 0.1); |
| 58 | |
| 59 | /******************************************************************************* |
| 60 | * Hook Functions (Drupal) |
| 61 | ******************************************************************************/ |
| 62 | |
| 63 | /** |
| 64 | * Implementation of hook_menu(). |
| 65 | */ |
| 66 | function uc_store_menu() { |
| 67 | $items = array(); |
| 68 | $items['admin/store'] = array( |
| 69 | 'title' => 'Store administration', |
| 70 | 'description' => 'Administer store settings, products, orders, and more.', |
| 71 | 'page callback' => 'uc_store_admin', |
| 72 | 'access arguments' => array('administer store'), |
| 73 | 'type' => MENU_NORMAL_ITEM, |
| 74 | ); |
| 75 | $items['admin/store/customers'] = array( |
| 76 | 'title' => 'Customers', |
| 77 | 'description' => 'View and modify customer information and orders.', |
| 78 | 'page callback' => 'uc_store_customers', |
| 79 | 'page arguments' => array(NULL, NULL, NULL, '25'), |
| 80 | 'access arguments' => array('view customers'), |
| 81 | 'weight' => -6, |
| 82 | 'type' => MENU_NORMAL_ITEM, |
| 83 | ); |
| 84 | $items['admin/store/customers/view'] = array( |
| 85 | 'title' => 'View customers', |
| 86 | 'description' => 'View and modify customer information and orders.', |
| 87 | 'page arguments' => array(NULL, NULL, NULL, '25'), |
| 88 | 'access arguments' => array('view customers'), |
| 89 | 'weight' => -10, |
| 90 | 'type' => MENU_NORMAL_ITEM, |
| 91 | ); |
| 92 | $items['admin/store/customers/search'] = array( |
| 93 | 'title' => 'Search customers', |
| 94 | 'description' => 'Search through your customer list.', |
| 95 | 'page callback' => 'uc_store_customer_search', |
| 96 | 'access arguments' => array('view customers'), |
| 97 | 'weight' => -5, |
| 98 | 'type' => MENU_NORMAL_ITEM, |
| 99 | ); |
| 100 | $items['admin/store/reports'] = array( |
| 101 | 'title' => 'Reports', |
| 102 | 'description' => 'Browse various store reports.', |
| 103 | 'page callback' => 'uc_store_reports', |
| 104 | 'access arguments' => array('view store reports'), |
| 105 | 'weight' => 2, |
| 106 | 'type' => MENU_NORMAL_ITEM, |
| 107 | ); |
| 108 | $items['admin/store/settings'] = array( |
| 109 | 'title' => 'Configuration', |
| 110 | 'description' => 'Adjust configuration settings for Ubercart.', |
| 111 | 'page callback' => 'uc_store_configuration_page', |
| 112 | 'access arguments' => array('administer store'), |
| 113 | 'weight' => 6, |
| 114 | 'type' => MENU_NORMAL_ITEM, |
| 115 | ); |
| 116 | $items['admin/store/help'] = array( |
| 117 | 'title' => 'Help', |
| 118 | 'description' => 'Links to get help!', |
| 119 | 'page callback' => 'uc_store_ubercart_help', |
| 120 | 'access arguments' => array('administer store'), |
| 121 | 'weight' => 10, |
| 122 | 'type' => MENU_NORMAL_ITEM, |
| 123 | ); |
| 124 | $items['admin/store/help/tokens'] = array( |
| 125 | 'title' => 'Using tokens', |
| 126 | 'description' => 'Understand what tokens are and how to use them.', |
| 127 | 'page callback' => 'uc_store_ubercart_help_tokens', |
| 128 | 'access arguments' => array('administer store'), |
| 129 | 'type' => MENU_NORMAL_ITEM, |
| 130 | ); |
| 131 | $items['admin/store/settings/countries'] = array( |
| 132 | 'title' => 'Country settings', |
| 133 | 'description' => 'Configure country specific settings.', |
| 134 | 'page callback' => 'uc_country_settings_overview', |
| 135 | 'access arguments' => array('administer store'), |
| 136 | 'type' => MENU_NORMAL_ITEM, |
| 137 | ); |
| 138 | $items['admin/store/settings/countries/overview'] = array( |
| 139 | 'title' => 'Overview', |
| 140 | 'description' => 'View the country settings.', |
| 141 | 'access arguments' => array('administer store'), |
| 142 | 'weight' => -10, |
| 143 | 'type' => MENU_DEFAULT_LOCAL_TASK, |
| 144 | ); |
| 145 | $items['admin/store/settings/countries/edit'] = array( |
| 146 | 'title' => 'Edit', |
| 147 | 'description' => 'Edit the country settings.', |
| 148 | 'page callback' => 'drupal_get_form', |
| 149 | 'page arguments' => array('uc_country_import_form'), |
| 150 | 'access arguments' => array('administer store'), |
| 151 | 'weight' => -5, |
| 152 | 'type' => MENU_LOCAL_TASK, |
| 153 | ); |
| 154 | $items['admin/store/settings/countries/edit/import'] = array( |
| 155 | 'title' => 'Import countries', |
| 156 | 'description' => 'Import and manage countries.', |
| 157 | 'access arguments' => array('administer store'), |
| 158 | 'weight' => -10, |
| 159 | 'type' => MENU_DEFAULT_LOCAL_TASK, |
| 160 | ); |
| 161 | $items['admin/store/settings/countries/edit/formats'] = array( |
| 162 | 'title' => 'Country formats', |
| 163 | 'description' => t('Edit the country specific format settings.'), |
| 164 | 'page callback' => 'drupal_get_form', |
| 165 | 'page arguments' => array('uc_country_formats_form'), |
| 166 | 'access arguments' => array('administer store'), |
| 167 | 'weight' => -5, |
| 168 | 'type' => MENU_LOCAL_TASK, |
| 169 | ); |
| 170 | |
| 171 | $items['admin/store/settings/store'] = array( |
| 172 | 'title' => 'Store settings', |
| 173 | 'description' => 'Configure the main store settings.', |
| 174 | 'page callback' => 'uc_store_store_settings_overview', |
| 175 | 'access arguments' => array('administer store'), |
| 176 | 'type' => MENU_NORMAL_ITEM, |
| 177 | ); |
| 178 | $items['admin/store/settings/store/overview'] = array( |
| 179 | 'title' => 'Overview', |
| 180 | 'description' => 'View the store settings.', |
| 181 | 'access arguments' => array('administer store'), |
| 182 | 'weight' => -10, |
| 183 | 'type' => MENU_DEFAULT_LOCAL_TASK, |
| 184 | ); |
| 185 | $items['admin/store/settings/store/edit'] = array( |
| 186 | 'title' => 'Edit', |
| 187 | 'description' => t('Edit the store settings.'), |
| 188 | 'page callback' => 'drupal_get_form', |
| 189 | 'page arguments' => array('uc_store_store_settings_form'), |
| 190 | 'access arguments' => array('administer store'), |
| 191 | 'weight' => -5, |
| 192 | 'type' => MENU_LOCAL_TASK, |
| 193 | ); |
| 194 | $items['admin/store/settings/store/edit/contact'] = array( |
| 195 | 'title' => 'Contact settings', |
| 196 | 'description' => 'Edit the contact settings.', |
| 197 | 'access arguments' => array('administer store'), |
| 198 | 'weight' => -10, |
| 199 | 'type' => MENU_DEFAULT_LOCAL_TASK, |
| 200 | ); |
| 201 | $items['admin/store/settings/store/edit/display'] = array( |
| 202 | 'title' => 'Display settings', |
| 203 | 'description' => 'Edit the display settings.', |
| 204 | 'page callback' => 'drupal_get_form', |
| 205 | 'page arguments' => array('uc_store_display_settings_form'), |
| 206 | 'access arguments' => array('administer store'), |
| 207 | 'weight' => -5, |
| 208 | 'type' => MENU_LOCAL_TASK, |
| 209 | ); |
| 210 | $items['admin/store/settings/store/edit/format'] = array( |
| 211 | 'title' => 'Format settings', |
| 212 | 'description' => 'Edit the format settings.', |
| 213 | 'page callback' => 'drupal_get_form', |
| 214 | 'page arguments' => array('uc_store_format_settings_form'), |
| 215 | 'access arguments' => array('administer store'), |
| 216 | 'weight' => 0, |
| 217 | 'type' => MENU_LOCAL_TASK, |
| 218 | ); |
| 219 | $items['admin/store/settings/store/edit/report'] = array( |
| 220 | 'title' => 'Reporting settings', |
| 221 | 'description' => 'Report version information to Ubercart.org.', |
| 222 | 'page callback' => 'drupal_get_form', |
| 223 | 'page arguments' => array('uc_store_report_settings'), |
| 224 | 'access arguments' => array('administer store'), |
| 225 | 'weight' => 10, |
| 226 | 'type' => MENU_LOCAL_TASK, |
| 227 | ); |
| 228 | |
| 229 | $items['admin/store/settings/store/initials'] = array( |
| 230 | 'title' => 'User initials', |
| 231 | 'description' => 'Assign initials to user accounts.', |
| 232 | 'page callback' => 'drupal_get_form', |
| 233 | 'page arguments' => array('uc_store_initials'), |
| 234 | 'access arguments' => array('administer store'), |
| 235 | 'type' => MENU_NORMAL_ITEM, |
| 236 | ); |
| 237 | /*$items['admin/store/settings/tables'] = array( |
| 238 | 'title' => 'Table display settings', |
| 239 | 'description' => 'Configure the display of tables in your store.', |
| 240 | 'page callback' => 'uc_store_tables', |
| 241 | 'access arguments' => array('administer store'), |
| 242 | 'type' => MENU_NORMAL_ITEM, |
| 243 | );*/ |
| 244 | |
| 245 | $items['uc_js_util/%'] = array( |
| 246 | 'title' => 'JS utilities', |
| 247 | 'page callback' => 'uc_store_js_util', |
| 248 | 'page arguments' => array(1), |
| 249 | 'access arguments' => array('access content'), |
| 250 | 'type' => MENU_CALLBACK, |
| 251 | ); |
| 252 | $items['admin/store/customers/orders/%'] = array( |
| 253 | 'title' => 'Customer orders', |
| 254 | 'description' => 'View a list of orders placed by this customer.', |
| 255 | 'page callback' => 'uc_store_customer_orders', |
| 256 | 'page arguments' => array(4), |
| 257 | 'access arguments' => array('view all orders'), |
| 258 | 'weight' => -5, |
| 259 | 'type' => MENU_CALLBACK, |
| 260 | ); |
| 261 | |
| 262 | $items['admin/store/settings/countries/%/disable'] = array( |
| 263 | 'title' => 'Disable a country', |
| 264 | 'description' => 'Disable a country from use.', |
| 265 | 'page callback' => 'uc_country_disable', |
| 266 | 'page arguments' => array(4), |
| 267 | 'access arguments' => array('administer store'), |
| 268 | 'type' => MENU_CALLBACK, |
| 269 | ); |
| 270 | $items['admin/store/settings/countries/%/enable'] = array( |
| 271 | 'title' => 'Enable a country', |
| 272 | 'description' => 'Enable a disabled country.', |
| 273 | 'page callback' => 'uc_country_enable', |
| 274 | 'page arguments' => array(4), |
| 275 | 'access arguments' => array('administer store'), |
| 276 | 'type' => MENU_CALLBACK, |
| 277 | ); |
| 278 | $items['admin/store/settings/countries/%/remove'] = array( |
| 279 | 'title' => 'Remove a country', |
| 280 | 'description' => 'Remove an installed country.', |
| 281 | 'page callback' => 'drupal_get_form', |
| 282 | 'page arguments' => array('uc_country_remove_form', 4), |
| 283 | 'access arguments' => array('administer store'), |
| 284 | 'type' => MENU_CALLBACK, |
| 285 | ); |
| 286 | $items['admin/store/settings/countries/%/update/%'] = array( |
| 287 | 'title' => 'Update a country', |
| 288 | 'description' => 'Update an installed country.', |
| 289 | 'page callback' => 'uc_country_update', |
| 290 | 'page arguments' => array(4, 6), |
| 291 | 'access arguments' => array('administer store'), |
| 292 | 'type' => MENU_CALLBACK, |
| 293 | ); |
| 294 | |
| 295 | return $items; |
| 296 | } |
| 297 | |
| 298 | /** |
| 299 | * Implementation of hook_init(). |
| 300 | */ |
| 301 | function uc_store_init() { |
| 302 | $dir = drupal_get_path('module', 'uc_store'); |
| 303 | |
| 304 | require_once($dir .'/includes/summaries.inc'); |
| 305 | drupal_add_css($dir .'/uc_store.css'); |
| 306 | } |
| 307 | |
| 308 | function uc_store_theme() { |
| 309 | return array( |
| 310 | 'uc_admin_dashboard' => array( |
| 311 | 'arguments' => array('type' => NULL, 'menus' => NULL), |
| 312 | ), |
| 313 | 'uc_store_footer' => array( |
| 314 | 'arguments' => array('message' => ''), |
| 315 | ), |
| 316 | 'uc_store_address_fields_form' => array( |
| 317 | 'arguments' => array('form' => NULL), |
| 318 | ), |
| 319 | 'uc_settings_overview' => array( |
| 320 | 'arguments' => array('sections' => array()), |
| 321 | ), |
| 322 | 'uc_pane_sort_table' => array( |
| 323 | 'arguments' => array('form' => NULL), |
| 324 | ), |
| 325 | 'tapir_table' => array( |
| 326 | 'arguments' => array('form' => NULL), |
| 327 | ), |
| 328 | 'summary_overview' => array( |
| 329 | 'arguments' => array(), |
| 330 | ), |
| 331 | ); |
| 332 | } |
| 333 | |
| 334 | /** |
| 335 | * Implementation of hook_token_values(). (token.module) |
| 336 | */ |
| 337 | function uc_store_token_values($type, $object = NULL) { |
| 338 | global $base_url; |
| 339 | |
| 340 | switch ($type) { |
| 341 | case 'global': |
| 342 | $login_link = url('user', array('absolute' => TRUE)); |
| 343 | $values['site-login'] = l($login_link, $login_link); |
| 344 | |
| 345 | $theme_key = variable_get('theme_default', 'garland'); |
| 346 | $settings = theme_get_settings($theme_key); |
| 347 | $themes = list_themes(); |
| 348 | $theme_object = $themes[$theme_key]; |
| 349 | if ($settings['toggle_logo']) { |
| 350 | if ($settings['default_logo']) { |
| 351 | $settings['logo'] = dirname($theme_object->filename) .'/logo.png'; |
| 352 | } |
| 353 | elseif ($settings['logo_path']) { |
| 354 | $settings['logo'] = $settings['logo_path']; |
| 355 | } |
| 356 | } |
| 357 | $values['site-logo'] = '<img src="'. url($settings['logo'], array('absolute' => TRUE)) .'" />'; |
| 358 | |
| 359 | $values['store-name'] = variable_get('uc_store_name', t('Our store')); |
| 360 | $values['store-url'] = variable_get('uc_store_url', $base_url); |
| 361 | $values['store-link'] = l(variable_get('uc_store_name', t('Our store')), variable_get('uc_store_url', $base_url)); |
| 362 | $values['store-owner'] = variable_get('uc_store_owner', ''); |
| 363 | $values['store-email'] = variable_get('uc_store_email', ''); |
| 364 | $values['store-phone'] = variable_get('uc_store_phone', ''); |
| 365 | $values['store-address'] = uc_store_address(); |
| 366 | $values['store-help-url'] = url(variable_get('uc_notify_store_help_page', ''), array('absolute' => TRUE)); |
| 367 | break; |
| 368 | } |
| 369 | |
| 370 | return $values; |
| 371 | } |
| 372 | |
| 373 | /** |
| 374 | * Implementation of hook_token_list(). (token.module) |
| 375 | */ |
| 376 | function uc_store_token_list($type = 'all') { |
| 377 | $tokens['global']['site-login'] = t('A link to the site login page.'); |
| 378 | $tokens['global']['site-logo'] = t('The URL for the site logo.'); |
| 379 | $tokens['global']['store-name'] = t('The Ubercart store name.'); |
| 380 | $tokens['global']['store-url'] = t('The Ubercart store URL.'); |
| 381 | $tokens['global']['store-link'] = t('A link to the Ubercart store using the store name.'); |
| 382 | $tokens['global']['store-owner'] = t('The Ubercart store owner.'); |
| 383 | $tokens['global']['store-email'] = t('The Ubercart store e-mail address.'); |
| 384 | $tokens['global']['store-phone'] = t('The Ubercart store phone number.'); |
| 385 | $tokens['global']['store-address'] = t('The Ubercart store mailing address.'); |
| 386 | $tokens['global']['store-help-url'] = t('The URL to the store help page.'); |
| 387 | |
| 388 | return $tokens; |
| 389 | } |
| 390 | |
| 391 | function uc_store_help($path, $arg) { |
| 392 | switch ($path) { |
| 393 | case 'admin/store/settings/store/edit/report': |
| 394 | 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."); |
| 395 | } |
| 396 | } |
| 397 | |
| 398 | /** |
| 399 | * Implementation of hook_cron(). |
| 400 | */ |
| 401 | function uc_store_cron() { |
| 402 | // Report version information into Ubercart.org once a week if enabled. |
| 403 | if (variable_get('uc_store_report', TRUE) && variable_get('uc_store_last_report', 0) <= time() - 604800) { |
| 404 | uc_store_send_report(); |
| 405 | } |
| 406 | } |
| 407 | |
| 408 | /** |
| 409 | * Implementation of hook_perm(). |
| 410 | */ |
| 411 | function uc_store_perm() { |
| 412 | return array('administer store', 'view customers', 'view store reports'); |
| 413 | } |
| 414 | |
| 415 | /** |
| 416 | * Implementation of hook_footer(). |
| 417 | */ |
| 418 | function uc_store_footer() { |
| 419 | // Figure out what page is being viewed. |
| 420 | $path = drupal_get_normal_path($_GET['q']); |
| 421 | $parts = explode('/', $path); |
| 422 | |
| 423 | switch ($parts[0]) { |
| 424 | case 'admin': |
| 425 | if ($parts[1] != 'store') { |
| 426 | break; |
| 427 | } |
| 428 | case 'node': |
| 429 | if (intval($parts[1]) > 0) { |
| 430 | if ($node = node_load($parts[1])) { |
| 431 | if (function_exists('uc_product_node_info') && !in_array($node->type, module_invoke_all('product_types'))) { |
| 432 | break; |
| 433 | } |
| 434 | } |
| 435 | } |
| 436 | case 'catalog': |
| 437 | case 'cart': |
| 438 | case 'manufacturer': |
| 439 | $messages = _store_footer_options(); |
| 440 | if (($message = variable_get('uc_footer_message', 0)) > 0) { |
| 441 | $message = $messages[$message]; |
| 442 | } |
| 443 | else { |
| 444 | $message = db_result(db_query("SELECT message FROM {uc_store_footers} WHERE path_hash = '%s'", md5($path))); |
| 445 | if (!$message) { |
| 446 | $message = $messages[array_rand($messages)]; |
| 447 | db_query("INSERT INTO {uc_store_footers} (path_hash, message) VALUES ('%s', '%s')", md5($path), $message); |
| 448 | } |
| 449 | } |
| 450 | |
| 451 | return theme('uc_store_footer', $message); |
| 452 | } |
| 453 | } |
| 454 | |
| 455 | /** |
| 456 | * Implementation of hook_exit(). |
| 457 | */ |
| 458 | function uc_store_exit() { |
| 459 | // Save the current request for tracking paths on subsequent page requests. |
| 460 | // $_SESSION['uc_referer_uri'] = $_GET['q']; |
| 461 | |
| 462 | // Save the timestamp of the last access. |
| 463 | // $_SESSION['uc_last_access'] = time(); |
| 464 | } |
| 465 | |
| 466 | /****************************************************************************** |
| 467 | * Callback Functions, Forms, and Tables |
| 468 | ******************************************************************************/ |
| 469 | |
| 470 | function uc_store_admin() { |
| 471 | $tree = menu_navigation_links('navigation', 2); |
| 472 | |
| 473 | if (($type = variable_get('uc_store_admin_page_display', 1)) == 4) { |
| 474 | $main_menu = menu_get_item('admin/store'); |
| 475 | $content = system_admin_menu_block((array)$main_menu); |
| 476 | |
| 477 | $output = theme('admin_block_content', $content); |
| 478 | } |
| 479 | else { |
| 480 | $output = theme('uc_admin_dashboard', $type, $tree); |
| 481 | } |
| 482 | |
| 483 | $results = module_invoke_all('store_status'); |
| 484 | |
| 485 | foreach ($results as $message) { |
| 486 | switch ($message['status']) { |
| 487 | case 'warning': |
| 488 | $icon = base_path() . drupal_get_path('module', 'uc_store') .'/images/alert.gif'; |
| 489 | break; |
| 490 | case 'error': |
| 491 | $icon = base_path() . drupal_get_path('module', 'uc_store') .'/images/error.gif'; |
| 492 | break; |
| 493 | case 'ok': |
| 494 | default: |
| 495 | $icon = base_path() . drupal_get_path('module', 'uc_store') .'/images/info.gif'; |
| 496 | } |
| 497 | |
| 498 | $rows[] = array('data' => array( |
| 499 | array('data' => '<img src="'. $icon .'" />'), |
| 500 | array('data' => '<strong>'. $message['title'] .'</strong>', 'nowrap' => 'nowrap'), |
| 501 | array('data' => $message['desc'], 'width' => '100%')), 'valign' => 'top'); |
| 502 | } |
| 503 | |
| 504 | $header = array(' ', t('Title'), t('Description')); |
| 505 | |
| 506 | $output .= '<div style="clear: both;"><h2>'. t('Status messages:') .'</h2>' |
| 507 | . theme('table', $header, $rows) .'</div>'; |
| 508 | |
| 509 | return $output; |
| 510 | } |
| 511 | |
| 512 | // Themes the dashboard on the admin/store page. |
| 513 | function theme_uc_admin_dashboard($type, $menus) { |
| 514 | if ($type == 1) { |
| 515 | uc_add_js(drupal_get_path('module', 'uc_store') .'/uc_store.js', 'module'); |
| 516 | uc_add_js("var text_show = '". t('- Show links -') ."';\nvar text_hide = '". t('- Hide links -') ."';\n", 'inline'); |
| 517 | } |
| 518 | |
| 519 | $output = '<table class="uc-store-admin-table" align="center"><tr valign="top">'; |
| 520 | |
| 521 | $panels = 0; |
| 522 | if (is_array($menus)) { |
| 523 | foreach ($menus as $menu) { |
| 524 | $panel++; |
| 525 | if ($panel % 4 == 0) { |
| 526 | $output .= '</tr><tr valign="top">'; |
| 527 | } |
| 528 | $panel_title = $menu['title']; |
| 529 | if ($type == 3) { |
| 530 | $panel_links = ''; |
| 531 | } |
| 532 | else { |
| 533 | $panel_links = theme('admin_block_content', system_admin_menu_block(menu_get_item($menu['href']))); |
| 534 | } |
| 535 | $panel_table = '<table width="100%"><tr>' |
| 536 | .'<td>'. l(uc_store_get_icon($menu['href']), $menu['href'], |
| 537 | array('html' => TRUE)) .'</td>' |
| 538 | .'<td class="panel-title">'. l($menu['title'], $menu['href']) |
| 539 | .'</td></tr>'; |
| 540 | if (strlen($panel_links) > 0) { |
| 541 | if ($type == 1) { |
| 542 | $disp = 'display: none;'; |
| 543 | } |
| 544 | $panel_table .= '<tr><td nowrap colspan="2" class="panel-links" ' |
| 545 | .'style="'. $disp .'">'. $panel_links .'</td></tr>'; |
| 546 | if ($type == 1) { |
| 547 | $panel_table .= '<tr><td align="center" colspan="2" ' |
| 548 | .'class="panel-show-link" id="show-links-'. $panel |
| 549 | .'"><a>'. t('- Show links -') .'</a></td></tr>'; |
| 550 | } |
| 551 | } |
| 552 | $panel_table .= '</table>'; |
| 553 | $output .= '<td class="uc-store-admin-panel" id="panel-'. $panel .'">' |
| 554 | . $panel_table .'</td>'; |
| 555 | } |
| 556 | } |
| 557 | |
| 558 | $output .= '</tr></table>'; |
| 559 | |
| 560 | return $output; |
| 561 | } |
| 562 | |
| 563 | /** |
| 564 | * Display customer administration page. |
| 565 | */ |
| 566 | function uc_store_customers($message = NULL, $query = NULL, $count_query = NULL, $page_length = 25) { |
| 567 | if (!module_exists('uc_order')) { |
| 568 | return t('You must enable the order module to track customers.'); |
| 569 | } |
| 570 | |
| 571 | if (is_null($query)) { |
| 572 | $query = "SELECT DISTINCT o.uid, u.mail, o.billing_first_name, " |
| 573 | ."o.billing_last_name, o.billing_city, o.billing_zone, " |
| 574 | ."o.billing_country FROM {uc_orders} AS o LEFT JOIN " |
| 575 | ."{users} AS u ON o.uid = u.uid WHERE o.uid > 0 AND " |
| 576 | ."o.order_status IN ". uc_order_status_list('general', TRUE); |
| 577 | |
| 578 | $count_query = ""; |
| 579 | switch ($GLOBALS['db_type']) { |
| 580 | case 'mysql': |
| 581 | case 'mysqli': |
| 582 | $count_query = "SELECT COUNT(DISTINCT o.uid, o.billing_first_name, " |
| 583 | ."o.billing_last_name, u.mail) FROM {uc_orders} AS o " |
| 584 | ."LEFT JOIN {users} AS u ON o.uid = u.uid WHERE o.uid > 0 " |
| 585 | ."AND o.order_status IN ". uc_order_status_list('general', TRUE); |
| 586 | break; |
| 587 | case 'pgsql': |
| 588 | $count_query = "SELECT DISTINCT o.uid, o.billing_last_name, o.billing_first_name, " |
| 589 | ."COUNT(*) " |
| 590 | ."FROM {uc_orders} AS o " |
| 591 | ."LEFT JOIN {users} AS u ON o.uid = u.uid WHERE o.uid > 0 " |
| 592 | ."AND o.order_status IN ". uc_order_status_list('general', TRUE) |
| 593 | ." GROUP BY o.uid, o.billing_last_name, o.billing_first_name "; |
| 594 | break; |
| 595 | } |
| 596 | |
| 597 | $message = t('The following users on your site have placed orders:'); |
| 598 | } |
| 599 | |
| 600 | $header = array( |
| 601 | t('View'), |
| 602 | array('data' => t('Name'), 'field' => 'o.billing_last_name', 'sort' => 'asc'), |
| 603 | array('data' => t('E-mail'), 'field' => 'u.mail'), |
| 604 | array('data' => t('City'), 'field' => 'o.billing_city'), |
| 605 | array('data' => t('ID'), 'field' => 'o.uid'), |
| 606 | ); |
| 607 | |
| 608 | $query .= tablesort_sql($header); |
| 609 | $count_query .= tablesort_sql($header); |
| 610 | |
| 611 | $address = variable_get('uc_customer_list_address', 'billing'); |
| 612 | if ($address == 'shipping') { |
| 613 | $query = str_replace('billing', 'delivery', $query); |
| 614 | $count_query = str_replace('billing', 'delivery', $count_query); |
| 615 | } |
| 616 | else { |
| 617 | $address = 'billing'; |
| 618 | } |
| 619 | |
| 620 | $result = pager_query($query, $page_length, 0, $count_query); |
| 621 | |
| 622 | while ($customer = db_fetch_object($result)) { |
| 623 | $icons = l(uc_store_get_icon('admin/store/customers', TRUE), |
| 624 | 'user/'. $customer->uid, array('title' => t('View user details.')), |
| 625 | NULL, NULL, FALSE, TRUE) |
| 626 | . l(uc_store_get_icon('admin/store/orders', TRUE), |
| 627 | 'admin/store/customers/orders/'. $customer->uid, |
| 628 | array('title' => t("View customer's order.")), NULL, NULL, FALSE, TRUE); |
| 629 | if ($address == 'shipping') { |
| 630 | $name = ucfirst($customer->delivery_last_name) .', ' |
| 631 | . ucfirst($customer->delivery_first_name); |
| 632 | $city = ucfirst($customer->delivery_city) .', ' |
| 633 | . uc_get_zone_code($customer->delivery_zone); |
| 634 | } |
| 635 | else { |
| 636 | $name = ucfirst($customer->billing_last_name) .', ' |
| 637 | . ucfirst($customer->billing_first_name); |
| 638 | $city = ucfirst($customer->billing_city) .', ' |
| 639 | . uc_get_zone_code($customer->billing_zone); |
| 640 | } |
| 641 | if ($name == ', ') { |
| 642 | $name = db_result(db_query("SELECT name FROM {users} WHERE uid = %d", $customer->uid)); |
| 643 | $name = t('User: !name', array('!name' => $name)); |
| 644 | } |
| 645 | $rows[] = array( |
| 646 | 'data' => array( |
| 647 | array('data' => $icons), |
| 648 | array('data' => check_plain($name)), |
| 649 | array('data' => check_plain($customer->mail)), |
| 650 | array('data' => check_plain($city)), |
| 651 | array('data' => $customer->uid)), |
| 652 | 'id' => 'customer-'. $customer->uid, |
| 653 | ); |
| 654 | } |
| 655 | |
| 656 | uc_add_js(drupal_get_path('module', 'uc_store') .'/uc_store.js'); |
| 657 | |
| 658 | $output = '<p>'. $message .'</p>' |
| 659 | . theme('table', $header, $rows, array('width' => '100%', 'class' => 'uc-customer-table')) |
| 660 | .'<br />'. theme_pager(NULL, $page_length); |
| 661 | |
| 662 | return $output; |
| 663 | } |
| 664 | |
| 665 | function uc_store_customer_orders($uid) { |
| 666 | $result = pager_query("SELECT * FROM {uc_orders} WHERE uid = %d AND " |
| 667 | ."order_status IN ". uc_order_status_list('general', TRUE) |
| 668 | ." ORDER BY created DESC", 50, 0, |
| 669 | NULL, $uid); |
| 670 | |
| 671 | $header = array(t('View'), t('Order ID'), t('Date'), t('Billing name'), |
| 672 | t('Shipping name'), t('Items'), t('Total')); |
| 673 | |
| 674 | $totals = array('orders' => 0, 'items' => 0, 'total' => 0); |
| 675 | while ($order = db_fetch_object($result)) { |
| 676 | $icons = l(uc_store_get_icon('file:order_view'), |
| 677 | 'admin/store/orders/'. $order->order_id, |
| 678 | array('title' => t("View order !order_id.", |
| 679 | array('!order_id' => $order->order_id))), |
| 680 | NULL, NULL, FALSE, TRUE) |
| 681 | . l(uc_store_get_icon('file:order_edit'), |
| 682 | 'admin/store/orders/'. $order->order_id .'/edit', |
| 683 | array('title' => t("Edit order !order_id.", |
| 684 | array('!order_id' => $order->order_id))), |
| 685 | NULL, NULL, FALSE, TRUE); |
| 686 | $bname = ucfirst($order->billing_first_name) .' ' |
| 687 | . ucfirst($order->billing_last_name); |
| 688 | $sname = ucfirst($order->delivery_first_name) .' ' |
| 689 | . ucfirst($order->delivery_last_name); |
| 690 | $result2 = db_query("SELECT COUNT(*) FROM {uc_order_products} WHERE " |
| 691 | ."order_id = %d", $order->order_id); |
| 692 | $item_count = db_fetch_array($result2); |
| 693 | |
| 694 | $totals['orders'] += 1; |
| 695 | $totals['items'] += $item_count['COUNT(*)']; |
| 696 | $totals['total'] += $order->order_total; |
| 697 | |
| 698 | $rows[] = array( |
| 699 | 'data' => array( |
| 700 | array('data' => $icons), |
| 701 | array('data' => $order->order_id), |
| 702 | array('data' => format_date($order->created, 'custom', variable_get('uc_date_format_default', 'm/d/Y'))), |
| 703 | array('data' => check_plain($bname)), |
| 704 | array('data' => check_plain($sname)), |
| 705 | array('data' => $item_count['COUNT(*)']), |
| 706 | array('data' => uc_currency_format($order->order_total), 'nowrap' => 'nowrap')), |
| 707 | 'id' => 'order-'. $order->order_id, |
| 708 | ); |
| 709 | } |
| 710 | if (empty($rows)) { |
| 711 | $rows[] = array( |
| 712 | array('data' => t('No orders found.'), 'colspan' => 7) |
| 713 | ); |
| 714 | } |
| 715 | |
| 716 | uc_add_js(drupal_get_path('module', 'uc_store') .'/uc_store.js'); |
| 717 | |
| 718 | $output = '<p>'. l(t('Create an order for this customer.'), |
| 719 | 'admin/store/orders/create/'. $uid) .'</p>'; |
| 720 | $output .= '<p>'. t('!totals_orders orders shown match that account with !totals_items items purchased and !totals_total spent:', |
| 721 | array('!totals_orders' => $totals['orders'], |
| 722 | '!totals_items' => $totals['items'], |
| 723 | '!totals_total' => uc_currency_format($totals['total']))) .'</p>' |
| 724 | . theme('table', $header, $rows, array('width' => '100%', 'class' => 'uc-cust-orders-table')) |
| 725 | .'<br />'. theme_pager(NULL, 50); |
| 726 | |
| 727 | return $output; |
| 728 | } |
| 729 | |
| 730 | /** |
| 731 | * Display the customer search page. |
| 732 | */ |
| 733 | function uc_store_customer_search() { |
| 734 | $output = drupal_get_form('uc_store_customer_search_form'); |
| 735 | |
| 736 | if (arg(4) == 'results') { |
| 737 | $first_name = strtolower(str_replace('*', '%', check_plain(arg(5)))); |
| 738 | $last_name = strtolower(str_replace('*', '%', check_plain(arg(6)))); |
| 739 | $email = strtolower(str_replace('*', '%', check_plain(arg(7)))); |
| 740 | |
| 741 | if ($first_name !== '0' && $first_name !== '%') { |
| 742 | $where .= " AND LOWER(o.billing_first_name) LIKE '". $first_name ."'"; |
| 743 | } |
| 744 | if ($last_name !== '0' && $last_name !== '%') { |
| 745 | $where .= " AND LOWER(o.billing_last_name) LIKE '". $last_name ."'"; |
| 746 | } |
| 747 | if ($email !== '0' && $email !== '%') { |
| 748 | $where .= " AND LOWER(o.primary_email) LIKE '". $email ."'"; |
| 749 | } |
| 750 | |
| 751 | $query = "SELECT DISTINCT o.uid, u.mail, o.billing_first_name," |
| 752 | ."o.billing_last_name, o.billing_city, o.billing_zone, " |
| 753 | ."o.billing_country FROM {uc_orders} AS o LEFT JOIN " |
| 754 | ."{users} AS u ON o.uid = u.uid WHERE o.uid > 0 AND " |
| 755 | ."o.order_status IN ". uc_order_status_list('general', TRUE) |
| 756 | . $where;// ." ORDER BY o.billing_last_name ASC"; |
| 757 | |
| 758 | |
| 759 | $count_query = ''; |
| 760 | switch ($GLOBALS['db_type']) { |
| 761 | case 'mysql': |
| 762 | case 'mysqli': |
| 763 | $count_query = "SELECT COUNT(DISTINCT o.uid, o.billing_first_name, " |
| 764 | ."o.billing_last_name, u.mail) FROM {uc_orders} AS o " |
| 765 | ."LEFT JOIN {users} AS u ON o.uid = u.uid WHERE o.uid > 0 AND " |
| 766 | ."o.order_status IN ". uc_order_status_list('general', TRUE) |
| 767 | . $where;// ." ORDER BY o.billing_last_name ASC"; |
| 768 | break; |
| 769 | case 'pgsql': |
| 770 | $count_query = "SELECT DISTINCT o.uid, o.billing_first_name, " |
| 771 | ."o.billing_last_name, u.mail, COUNT(*) " |
| 772 | ."FROM {uc_orders} AS o " |
| 773 | ."LEFT JOIN {users} AS u ON o.uid = u.uid WHERE o.uid > 0 AND " |
| 774 | ."o.order_status IN ". uc_order_status_list('general', TRUE) |
| 775 | . $where |
| 776 | ."GROUP BY o.uid, o.billing_first_name, o.billing_last_name, u.mail "; |
| 777 | //."ORDER BY o.billing_last_name ASC"; |
| 778 | break; |
| 779 | } |
| 780 | |
| 781 | $message = t('Search returned the following results:'); |
| 782 | |
| 783 | $output .= uc_store_customers($message, $query, $count_query, 100); |
| 784 | } |
| 785 | |
| 786 | return $output; |
| 787 | } |
| 788 | |
| 789 | function uc_store_customer_search_form() { |
| 790 | $form['search'] = array( |
| 791 | '#type' => 'fieldset', |
| 792 | '#title' => t('Search options'), |
| 793 | '#collapsible' => TRUE, |
| 794 | '#collapsed' => arg(4) == 'results' ? TRUE : FALSE, |
| 795 | ); |
| 796 | |
| 797 | $form['search']['table1'] = array('#value' => '<table><tbody style="border: 0px;"><tr><td colspan="4">'); |
| 798 | |
| 799 | $form['search']['desc'] = array( |
| 800 | '#value' => '<div>'. t("Search for customers based on any of the following fields. Use * as a wildcard to match any character.<br/>For example, searching by last name for 's*' will return all customers whose last name starts with an s.<br/>(<em>Leave a field empty to ignore it in the search.</em>)") .'</div>', |
| 801 | ); |
| 802 | |
| 803 | $form['search']['table2'] = array('#value' => '</td></tr><tr><td>'); |
| 804 | |
| 805 | $form['search']['first_name'] = array( |
| 806 | '#type' => 'textfield', |
| 807 | '#title' => t('First name'), |
| 808 | '#default_value' => arg(5) != '0' ? arg(5) : '', |
| 809 | '#size' => 24, |
| 810 | '#maxlength' => 32, |
| 811 | ); |
| 812 | |
| 813 | $form['search']['table3'] = array('#value' => '</td><td>'); |
| 814 | |
| 815 | $form['search']['last_name'] = array( |
| 816 | '#type' => 'textfield', |
| 817 | '#title' => t('Last name'), |
| 818 | '#default_value' => arg(6) != '0' ? arg(6) : '', |
| 819 | '#size' => 24, |
| 820 | '#maxlength' => 32, |
| 821 | ); |
| 822 | |
| 823 | $form['search']['table4'] = array('#value' => '</td><td>'); |
| 824 | |
| 825 | $form['search']['email'] = array( |
| 826 | '#type' => 'textfield', |
| 827 | '#title' => t('E-mail'), |
| 828 | '#default_value' => arg(7) != '0' ? arg(7) : '', |
| 829 | '#size' => 24, |
| 830 | '#maxlength' => 96, |
| 831 | ); |
| 832 | |
| 833 | $form['search']['table5'] = array('#value' => '</td><td>'); |
| 834 | |
| 835 | $form['search']['submit'] = array( |
| 836 | '#type' => 'submit', |
| 837 | '#value' => t('Search'), |
| 838 | ); |
| 839 | |
| 840 | $form['search']['table6'] = array('#value' => '</td></tr></tbody></table>'); |
| 841 | |
| 842 | return $form; |
| 843 | } |
| 844 | |
| 845 | function uc_store_customer_search_form_submit($form_id, &$form_state) { |
| 846 | if (strlen(trim($form_state['values']['first_name'])) == 0) { |
| 847 | $first_name = '0'; |
| 848 | } |
| 849 | else { |
| 850 | $first_name = strtolower(trim($form_state['values']['first_name'])); |
| 851 | } |
| 852 | |
| 853 | if (strlen(trim($form_state['values']['last_name'])) == 0) { |
| 854 | $last_name = '0'; |
| 855 | } |
| 856 | else { |
| 857 | $last_name = strtolower(trim($form_state['values']['last_name'])); |
| 858 | } |
| 859 | |
| 860 | if (strlen(trim($form_state['values']['email'])) == 0) { |
| 861 | $email = '0'; |
| 862 | } |
| 863 | else { |
| 864 | $email = strtolower(trim($form_state['values']['email'])); |
| 865 | } |
| 866 | |
| 867 | drupal_goto('admin/store/customers/search/results/'. $first_name .'/' |
| 868 | . $last_name .'/'. $email); |
| 869 | } |
| 870 | |
| 871 | /** |
| 872 | * Display main reports page. |
| 873 | */ |
| 874 | function uc_store_reports() { |
| 875 | $menu = menu_get_item('admin/store/reports'); |
| 876 | $content = system_admin_menu_block($menu); |
| 877 | |
| 878 | $message = (module_exists('uc_reports')) ? t('Various reports generated by Ubercart modules can be found here. Click the links below to view the reports.') : t('Various reports generated by Ubercart modules can be found here. Click the links below to view the reports. To view core Ubercart statistics enable the <strong>Reports</strong> module on the <a href="!url">module administration page</a>', array('!url' => url('admin/build/modules'))); |
| 879 | $output = $message . theme('admin_block_content', $content); |
| 880 | |
| 881 | return $output; |
| 882 | } |
| 883 | |
| 884 | /** |
| 885 | * Display store configuration page. |
| 886 | */ |
| 887 | function uc_store_configuration_page() { |
| 888 | $menu = menu_get_item('admin/store/settings'); |
| 889 | $content = system_admin_menu_block($menu); |
| 890 | |
| 891 | $output = theme('admin_block_content', $content); |
| 892 | |
| 893 | return $output; |
| 894 | } |
| 895 | |
| 896 | /** |
| 897 | * Display store help page. |
| 898 | */ |
| 899 | function uc_store_ubercart_help() { |
| 900 | $output = '<p>'. t('Use the following links to find documentation and support:') .'</p>'; |
| 901 | |
| 902 | $items[] = l(t("Ubercart User's Guide"), 'http://www.ubercart.org/docs/user'); |
| 903 | $items[] = l(t('Support Forums'), 'http://www.ubercart.org/forum'); |
| 904 | $items[] = l(t('Drupal Handbook'), 'http://drupal.org/node/258'); |
| 905 | $output .= theme_item_list($items); |
| 906 | |
| 907 | return $output; |
| 908 | } |
| 909 | |
| 910 | /** |
| 911 | * Display the tokens help page. |
| 912 | */ |
| 913 | function uc_store_ubercart_help_tokens() { |
| 914 | $output = '<p>'. 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.') .'</p>'; |
| 915 | |
| 916 | $output .= theme('token_help', 'ubercart'); |
| 917 | |
| 918 | return $output; |
| 919 | } |
| 920 | |
| 921 | /** |
| 922 | * Display the country settings overview. |
| 923 | */ |
| 924 | function uc_country_settings_overview() { |
| 925 | $result = db_query("SELECT * FROM {uc_countries} ORDER BY country_name ASC"); |
| 926 | while ($country = db_fetch_object($result)) { |
| 927 | $items[] = t('!country version !version is !status.', array('!country' => $country->country_name, '!version' => abs($country->version), '!status' => $country->version > 0 ? t('enabled') : t('disabled'))); |
| 928 | } |
| 929 | $sections[] = array( |
| 930 | 'edit' => 'admin/store/settings/countries/edit', |
| 931 | 'title' => t('Imported countries'), |
| 932 | 'items' => $items, |
| 933 | ); |
| 934 | |
| 935 | $sections[] = array( |
| 936 | 'edit' => 'admin/store/settings/countries/edit/formats', |
| 937 | 'title' => t('Country specific formats'), |
| 938 | 'items' => array( |
| 939 | t('Tweak the address formatting for a specific country.'), |
| 940 | ), |
| 941 | ); |
| 942 | |
| 943 | $output = theme('uc_settings_overview', $sections); |
| 944 | |
| 945 | return $output; |
| 946 | } |
| 947 | |
| 948 | function uc_country_import_form() { |
| 949 | $result = db_query("SELECT * FROM {uc_countries} ORDER BY country_name ASC"); |
| 950 | while ($country = db_fetch_object($result)) { |
| 951 | $countries[] = $country; |
| 952 | } |
| 953 | $files = _country_import_list(); |
| 954 | |
| 955 | $header = array(t('Country'), t('Code'), t('Version'), t('Operations')); |
| 956 | if (is_array($countries)) { |
| 957 | foreach ($countries as $country) { |
| 958 | $row = array( |
| 959 | $country->country_name, |
| 960 | $country->country_iso_code_3, |
| 961 | array('data' => abs($country->version), 'align' => 'center') |
| 962 | ); |
| 963 | |
| 964 | $ops = array(); |
| 965 | if ($country->version < 0) { |
| 966 | $ops[] = l(t('enable'), 'admin/store/settings/countries/'. $country->country_id .'/enable'); |
| 967 | } |
| 968 | else { |
| 969 | $ops[] = l(t('disable'), 'admin/store/settings/countries/'. $country->country_id .'/disable'); |
| 970 | } |
| 971 | if ($country->version < $files[$country->country_id]['version'] && $country->version > 0) { |
| 972 | $ops[] = l(t('update'), 'admin/store/settings/countries/'. $country->country_id .'/update/'. $files[$country->country_id]['version']); |
| 973 | } |
| 974 | $ops[] = l(t('remove'), 'admin/store/settings/countries/'. $country->country_id .'/remove'); |
| 975 | $row[] = implode(' ', $ops); |
| 976 | |
| 977 | $rows[] = $row; |
| 978 | unset($files[$country->country_id]); |
| 979 | } |
| 980 | } |
| 981 | |
| 982 | foreach ($files as $file) { |
| 983 | $import_list[$file['file']] = $file['file']; |
| 984 | } |
| 985 | if (is_array($import_list)) { |
| 986 | ksort($import_list); |
| 987 | } |
| 988 | |
| 989 | $form['text'] = array( |
| 990 | '#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.'), |
| 991 | ); |
| 992 | $form['import_file'] = array( |
| 993 | '#type' => 'select', |
| 994 | '#title' => t('Country'), |
| 995 | '#options' => is_array($import_list) ? $import_list : array(t('-None available-')), |
| 996 | '#disabled' => is_array($import_list) ? FALSE : TRUE, |
| 997 | ); |
| 998 | $form['import_button'] = array( |
| 999 | '#type' => 'submit', |
| 1000 | '#value' => t('Import'), |
| 1001 | '#disabled' => is_array($import_list) ? FALSE : TRUE, |
| 1002 | ); |
| 1003 | $form['country_table'] = array( |
| 1004 | '#value' => theme('table', $header, $rows), |
| 1005 | ); |
| 1006 | |
| 1007 | return $form; |
| 1008 | } |
| 1009 | |
| 1010 | function uc_country_import_form_submit($form_id, &$form_state) { |
| 1011 | $file = $form_state['values']['import_file']; |
| 1012 | |
| 1013 | $pieces = explode('_', substr($file, 0, strlen($file) - 4)); |
| 1014 | $country_id = $pieces[count($pieces) - 2]; |
| 1015 | $version = $pieces[count($pieces) - 1]; |
| 1016 | $country = substr($file, 0, strlen($file) - strlen($country_id) - strlen($version) - 6); |
| 1017 | |
| 1018 | require_once(drupal_get_path('module', 'uc_store') .'/countries/'. $file); |
| 1019 | $func = $country .'_install'; |
| 1020 | if (function_exists($func)) { |
| 1021 | $func(); |
| 1022 | drupal_set_message(t('Country file !file imported.', array('!file' => $file))); |
| 1023 | } |
| 1024 | else { |
| 1025 | drupal_set_message(t('Country file had no install function.')); |
| 1026 | } |
| 1027 | } |
| 1028 | |
| 1029 | /** |
| 1030 | * Disable a country so it remains installed but is no longer selectable. |
| 1031 | */ |
| 1032 | function uc_country_disable($country_id) { |
| 1033 | $result = db_query("SELECT * FROM {uc_countries} WHERE country_id = %d", $country_id); |
| 1034 | if (($country = db_fetch_object($result))) { |
| 1035 | if ($country->version > 0) { |
| 1036 | db_query("UPDATE {uc_countries} SET version = %d WHERE country_id = %d", |
| 1037 | 0 - $country->version, $country_id); |
| 1038 | drupal_set_message(t('!country disabled.', array('!country' => $country->country_name))); |
| 1039 | } |
| 1040 | else { |
| 1041 | drupal_set_message(t('!country is already disabled.', array('!country' => $country->country_name)), 'error'); |
| 1042 | } |
| 1043 | } |
| 1044 | else { |
| 1045 | drupal_set_message(t('Attempted to disable an invalid country.'), 'error'); |
| 1046 | } |
| 1047 | drupal_goto('admin/store/settings/countries/edit'); |
| 1048 | } |
| 1049 | |
| 1050 | /** |
| 1051 | * Enable a disabled country. |
| 1052 | */ |
| 1053 | function uc_country_enable($country_id) { |
| 1054 | $result = db_query("SELECT * FROM {uc_countries} WHERE country_id = %d", $country_id); |
| 1055 | if (($country = db_fetch_object($result))) { |
| 1056 | if ($country->version < 0) { |
| 1057 | db_query("UPDATE {uc_countries} SET version = %d WHERE country_id = %d", |
| 1058 | abs($country->version), $country_id); |
| 1059 | drupal_set_message(t('!country enabled.', array('!country' => $country->country_name))); |
| 1060 | } |
| 1061 | else { |
| 1062 | drupal_set_message(t('!country is already enabled.', array('!country' => $country->country_name)), 'error' |