| 1 |
<?php
|
| 2 |
// $Id: location.admin.inc,v 1.20 2009/04/17 19:09:53 bdragon Exp $
|
| 3 |
|
| 4 |
/**
|
| 5 |
* @file
|
| 6 |
* Admin forms for Location.
|
| 7 |
*/
|
| 8 |
|
| 9 |
/**
|
| 10 |
* Admin settings form.
|
| 11 |
*
|
| 12 |
* @ingroup form
|
| 13 |
*/
|
| 14 |
function location_admin_settings() {
|
| 15 |
// Recalculate the supported countries.
|
| 16 |
cache_clear_all('location:supported-countries', 'cache');
|
| 17 |
_location_supported_countries();
|
| 18 |
|
| 19 |
$iso_list_sorted = location_get_iso3166_list();
|
| 20 |
array_multisort($iso_list_sorted);
|
| 21 |
$iso_list_sorted = array_merge(array('' => ''), $iso_list_sorted);
|
| 22 |
|
| 23 |
$form = array();
|
| 24 |
|
| 25 |
// @@@TODO 7.x -- Verify integrity of site_default_country and direct user
|
| 26 |
// to the appropriate place to change it if necessary.
|
| 27 |
|
| 28 |
$form['location_display_location'] = array(
|
| 29 |
'#type' => 'radios',
|
| 30 |
'#title' => t('Toggle location display'),
|
| 31 |
'#default_value' => variable_get('location_display_location', 1),
|
| 32 |
'#options' => array(
|
| 33 |
0 => t('Disable the display of locations.'),
|
| 34 |
1 => t('Enable the display of locations.')
|
| 35 |
),
|
| 36 |
'#description' => t('If you are interested in turning off locations and having a custom theme control their display, you may want to disable the display of locations so your theme can take that function.')
|
| 37 |
);
|
| 38 |
|
| 39 |
$form['location_usegmap'] = array(
|
| 40 |
'#type' => 'checkbox',
|
| 41 |
'#title' => t('Use a Google Map to set latitude and longitude '),
|
| 42 |
'#default_value' => variable_get('location_usegmap', FALSE),
|
| 43 |
'#description' => t('If the gmap.module is installed and <a href="@enabled">enabled</a>, and this setting is also turned on, users that are allowed to manually enter latitude/longitude coordinates will be able to do so with an interactive Google Map. You should also make sure you have entered a <a href="@google_maps_api_key">Google Maps API key</a> into your <a href="@gmap_module_settings">gmap module settings</a>.', array('@enabled' => url('admin/build/modules'), '@google_maps_api_key' => 'http://www.google.com/apis/maps', '@gmap_module_settings' => url('admin/settings/gmap'))),
|
| 44 |
// @@@ megapatch This is an idea, but I'd opt more for a warning here...
|
| 45 |
// '#disabled' => !module_exists('gmap'),
|
| 46 |
);
|
| 47 |
|
| 48 |
$form['location_locpick_macro'] = array(
|
| 49 |
'#type' => 'textfield',
|
| 50 |
'#title' => t('Location chooser macro'),
|
| 51 |
'#size' => 50,
|
| 52 |
'#maxlength' => 500,
|
| 53 |
'#default_value' => variable_get('location_locpick_macro', '[gmap]'),
|
| 54 |
'#description' => t('If you would like to change the macro used to generate the location chooser map, you can do so here. Note: Behaviors <em>locpick</em> and <em>collapsehack</em> are forced to be enabled and cannot be changed.'),
|
| 55 |
);
|
| 56 |
|
| 57 |
$form['location_jit_geocoding'] = array(
|
| 58 |
'#type' => 'checkbox',
|
| 59 |
'#title' => t('Enable JIT geocoding'),
|
| 60 |
'#default_value' => variable_get('location_jit_geocoding', FALSE),
|
| 61 |
'#description' => t('If you are going to be importing locations in bulk directly into the database, you may wish to enable JIT geocoding and load the locations with source set to 4 (LOCATION_LATLON_JIT_GEOCODING). The system will automatically geocode locations as they are loaded.'),
|
| 62 |
);
|
| 63 |
|
| 64 |
return system_settings_form($form);
|
| 65 |
}
|
| 66 |
|
| 67 |
/**
|
| 68 |
* Settings page for map links.
|
| 69 |
*/
|
| 70 |
function location_map_link_options_form() {
|
| 71 |
$form = array();
|
| 72 |
|
| 73 |
$form['countries'] = array(
|
| 74 |
'#type' => 'markup',
|
| 75 |
'#markup' => ''
|
| 76 |
);
|
| 77 |
|
| 78 |
foreach (_location_supported_countries() as $country_iso => $country_name) {
|
| 79 |
location_load_country($country_iso);
|
| 80 |
|
| 81 |
$form['countries'][$country_iso] = array(
|
| 82 |
'#type' => 'markup',
|
| 83 |
'#markup' => ''
|
| 84 |
);
|
| 85 |
|
| 86 |
$form['countries'][$country_iso]['label_'. $country_iso] = array(
|
| 87 |
'#type' => 'markup',
|
| 88 |
'#markup' => $country_name
|
| 89 |
);
|
| 90 |
|
| 91 |
// Set up '#options' array for mapping providers for the current country
|
| 92 |
$mapping_options = array();
|
| 93 |
$provider_function = 'location_map_link_'. $country_iso .'_providers';
|
| 94 |
$default_provider_function = 'location_map_link_'. $country_iso .'_default_providers';
|
| 95 |
$checked = variable_get('location_map_link_'. $country_iso, function_exists($default_provider_function) ? $default_provider_function() : array());
|
| 96 |
//print "Calling provider function $provider_function";
|
| 97 |
if (function_exists($provider_function)) {
|
| 98 |
foreach ($provider_function() as $name => $details) {
|
| 99 |
$mapping_options[$name] = '<a href="'. $details['url'] .'">'. $details['name'] .'</a> (<a href="'. $details['tos'] .'">Terms of Use</a>)';
|
| 100 |
}
|
| 101 |
}
|
| 102 |
|
| 103 |
if (count($mapping_options)) {
|
| 104 |
$form['countries'][$country_iso]['location_map_link_'. $country_iso] = array(
|
| 105 |
'#title' => '',
|
| 106 |
'#type' => 'checkboxes',
|
| 107 |
'#default_value' => $checked,
|
| 108 |
'#options' => $mapping_options
|
| 109 |
);
|
| 110 |
}
|
| 111 |
else {
|
| 112 |
$form['countries'][$country_iso]['location_map_link_'. $country_iso] = array(
|
| 113 |
'#type' => 'markup',
|
| 114 |
'#markup' => t('None supported.')
|
| 115 |
);
|
| 116 |
}
|
| 117 |
}
|
| 118 |
|
| 119 |
$form = system_settings_form($form);
|
| 120 |
$form['#theme'] = 'location_map_link_options';
|
| 121 |
return $form;
|
| 122 |
}
|
| 123 |
|
| 124 |
function location_geocoding_options_form() {
|
| 125 |
$form = array();
|
| 126 |
|
| 127 |
$form['countries'] = array();
|
| 128 |
|
| 129 |
// First, we build two arrays to help us figure out on the fly whether a specific country is covered by a multi-country geocoder,
|
| 130 |
// and what the details of the multi-country geocoder are
|
| 131 |
// (1) Get list of geocoders
|
| 132 |
$general_geocoders_list = location_get_general_geocoder_list();
|
| 133 |
|
| 134 |
// (2) get data about each geocoder and the list of coutnries covered by each geocoder
|
| 135 |
$general_geocoders_data = array();
|
| 136 |
$general_geocoders_countries = array();
|
| 137 |
foreach ($general_geocoders_list as $geocoder_name) {
|
| 138 |
location_load_geocoder($geocoder_name);
|
| 139 |
$info_function = $geocoder_name .'_geocode_info';
|
| 140 |
if (function_exists($info_function)) {
|
| 141 |
$general_geocoders_data[$geocoder_name] = $info_function();
|
| 142 |
}
|
| 143 |
|
| 144 |
$countries_function = $geocoder_name .'_geocode_country_list';
|
| 145 |
if (function_exists($countries_function)) {
|
| 146 |
$general_geocoders_countries[$geocoder_name] = $countries_function();
|
| 147 |
}
|
| 148 |
}
|
| 149 |
|
| 150 |
foreach (_location_supported_countries() as $country_iso => $country_name) {
|
| 151 |
location_load_country($country_iso);
|
| 152 |
|
| 153 |
$geocoding_options = array();
|
| 154 |
|
| 155 |
$form['countries'][$country_iso] = array(
|
| 156 |
'#type' => 'markup',
|
| 157 |
'#value' => ''
|
| 158 |
);
|
| 159 |
|
| 160 |
$form['countries'][$country_iso]['label_'. $country_iso] = array(
|
| 161 |
'#type' => 'markup',
|
| 162 |
'#value' => '<div id="'. $country_iso .'">'. $country_name .'</div>'
|
| 163 |
);
|
| 164 |
|
| 165 |
// Next, we look for options presented by country specific providers
|
| 166 |
$country_specific_provider_function = 'location_geocode_'. $country_iso .'_providers';
|
| 167 |
if (function_exists($country_specific_provider_function)) {
|
| 168 |
foreach ($country_specific_provider_function() as $name => $details) {
|
| 169 |
$geocoding_options[$name .'|'. $country_iso] = '<a href="'. $details['url'] .'">'. $details['name'] .'</a> (<a href="'. $details['tos'] .'">Terms of Use</a>)';
|
| 170 |
}
|
| 171 |
}
|
| 172 |
|
| 173 |
foreach ($general_geocoders_list as $geocoder_name) {
|
| 174 |
if (in_array($country_iso, $general_geocoders_countries[$geocoder_name])) {
|
| 175 |
$geocoding_options[$geocoder_name] = '<a href="'. $general_geocoders_data[$geocoder_name]['url'] .'">'. $general_geocoders_data[$geocoder_name]['name'] .'</a> (<a href="'. $general_geocoders_data[$geocoder_name]['tos'] .'">Terms of Use</a>)';
|
| 176 |
}
|
| 177 |
}
|
| 178 |
|
| 179 |
if (count($geocoding_options)) {
|
| 180 |
$geocoding_options = array_merge(array('none' => t('None')), $geocoding_options);
|
| 181 |
|
| 182 |
$form['countries'][$country_iso]['location_geocode_'. $country_iso] = array(
|
| 183 |
'#type' => 'radios',
|
| 184 |
'#default_value' => variable_get('location_geocode_'. $country_iso, 'none'),
|
| 185 |
'#options' => $geocoding_options
|
| 186 |
);
|
| 187 |
}
|
| 188 |
else {
|
| 189 |
$form['countries'][$country_iso]['location_geocode_'. $country_iso] = array(
|
| 190 |
'#type' => 'markup',
|
| 191 |
'#markup' => t('None supported.')
|
| 192 |
);
|
| 193 |
}
|
| 194 |
|
| 195 |
$current_value = variable_get('location_geocode_'. $country_iso, 'none');
|
| 196 |
if ($current_value == 'none') {
|
| 197 |
$form['countries'][$country_iso]['location_geocode_config_link_'. $country_iso] = array(
|
| 198 |
'#type' => 'markup',
|
| 199 |
'#markup' => t('No service selected for country.')
|
| 200 |
);
|
| 201 |
}
|
| 202 |
else {
|
| 203 |
$current_val_chopped = substr($current_value, 0, strpos($current_value, '|'));
|
| 204 |
$geocode_settings_form_function_specific = 'location_geocode_'. $country_iso .'_'. $current_val_chopped .'_settings';
|
| 205 |
$geocode_settings_form_function_general = $current_value .'_geocode_settings';
|
| 206 |
|
| 207 |
if (function_exists($geocode_settings_form_function_specific)) {
|
| 208 |
$form['countries'][$country_iso]['location_geocode_config_link_'. $country_iso] = array(
|
| 209 |
'#type' => 'markup',
|
| 210 |
'#markup' => l(t('Configure parameters'), 'admin/settings/location/geocoding/'. $country_iso .'/'. $current_val_chopped)
|
| 211 |
);
|
| 212 |
}
|
| 213 |
elseif (function_exists($geocode_settings_form_function_general)) {
|
| 214 |
$form['countries'][$country_iso]['location_geocode_config_link_'. $country_iso] = array(
|
| 215 |
'#type' => 'markup',
|
| 216 |
'#markup' => l(t('Configure parameters'), 'admin/settings/location/geocoding/'. $country_iso .'/'. $current_value)
|
| 217 |
);
|
| 218 |
}
|
| 219 |
else {
|
| 220 |
$form['countries'][$country_iso]['location_geocode_config_link_'. $country_iso] = array(
|
| 221 |
'#type' => 'markup',
|
| 222 |
'#markup' => t('No configuration necessary for selected service.')
|
| 223 |
);
|
| 224 |
}
|
| 225 |
}
|
| 226 |
}
|
| 227 |
$form = system_settings_form($form);
|
| 228 |
$form['#theme'] = 'location_geocoding_options';
|
| 229 |
array_unshift($form['#submit'], 'location_geocoding_options_form_submit');
|
| 230 |
|
| 231 |
return $form;
|
| 232 |
}
|
| 233 |
|
| 234 |
function location_geocoding_options_form_submit($form, &$form_state) {
|
| 235 |
$general_geocoders = location_get_general_geocoder_list();
|
| 236 |
$general_geocoders_in_use = array();
|
| 237 |
|
| 238 |
foreach ($form_state['values'] as $key => $value) {
|
| 239 |
if (substr($key, 0, 17) == 'location_geocode_') {
|
| 240 |
if (in_array($value, $general_geocoders)) {
|
| 241 |
$general_geocoders_in_use[$value] = $value;
|
| 242 |
variable_set($key, $value);
|
| 243 |
}
|
| 244 |
}
|
| 245 |
}
|
| 246 |
|
| 247 |
variable_set('location_general_geocoders_in_use', $general_geocoders_in_use);
|
| 248 |
}
|
| 249 |
|
| 250 |
function theme_location_map_link_options(&$form) {
|
| 251 |
$header = array(array('align' => 'center', 'data' => '<center>'. t('Country') .'</center>'), array('align' => 'center', 'data' => '<center>'. t('Options') .'</center>'));
|
| 252 |
$rows = array();
|
| 253 |
foreach (element_children($form['countries']) as $country_iso) {
|
| 254 |
$row = array();
|
| 255 |
$row[] = array(
|
| 256 |
'data' => drupal_render($form['countries'][$country_iso]['label_'. $country_iso])
|
| 257 |
);
|
| 258 |
$row[] = array(
|
| 259 |
'data' => drupal_render($form['countries'][$country_iso]['location_map_link_'. $country_iso])
|
| 260 |
);
|
| 261 |
$rows[] = $row;
|
| 262 |
}
|
| 263 |
$output = theme('table', $header, $rows);
|
| 264 |
$output .= drupal_render_children($form);
|
| 265 |
return $output;
|
| 266 |
}
|
| 267 |
|
| 268 |
function theme_location_geocoding_options(&$form) {
|
| 269 |
$header = array(
|
| 270 |
array('align' => 'center', 'data' => '<center>'. t('Country') .'</center>'),
|
| 271 |
array('align' => 'center', 'data' => '<center>'. t('Options') .'</center>'),
|
| 272 |
array('align' => 'center', 'data' => '<center>'. t('Configure') .'</center>')
|
| 273 |
);
|
| 274 |
$rows = array();
|
| 275 |
foreach (element_children($form['countries']) as $country_iso) {
|
| 276 |
$row = array();
|
| 277 |
$row[] = array(
|
| 278 |
'data' => drupal_render($form['countries'][$country_iso]['label_'. $country_iso])
|
| 279 |
);
|
| 280 |
$row[] = array(
|
| 281 |
'data' => drupal_render($form['countries'][$country_iso]['location_geocode_'. $country_iso])
|
| 282 |
);
|
| 283 |
$row[] = array(
|
| 284 |
'data' => drupal_render($form['countries'][$country_iso]['location_geocode_config_link_'. $country_iso])
|
| 285 |
);
|
| 286 |
$rows[] = $row;
|
| 287 |
}
|
| 288 |
$output = theme('table', $header, $rows);
|
| 289 |
$output .= drupal_render_children($form);
|
| 290 |
return $output;
|
| 291 |
}
|
| 292 |
|
| 293 |
/**
|
| 294 |
* Location Utilities form.
|
| 295 |
*/
|
| 296 |
function location_util_form() {
|
| 297 |
$form['province_clear'] = array(
|
| 298 |
'#type' => 'fieldset',
|
| 299 |
'#title' => t('Clear province cache'),
|
| 300 |
'#description' => t('If you have modified location.xx.inc files, you will need to clear the province cache to get Location to recognize the modifications.'),
|
| 301 |
);
|
| 302 |
$form['province_clear']['province_clear_submit'] = array(
|
| 303 |
'#type' => 'submit',
|
| 304 |
'#value' => t('Clear province cache'),
|
| 305 |
'#submit' => array('location_util_form_clear_province_cache_submit'),
|
| 306 |
);
|
| 307 |
|
| 308 |
$form['supported_countries_clear'] = array(
|
| 309 |
'#type' => 'fieldset',
|
| 310 |
'#title' => t('Clear supported country list'),
|
| 311 |
'#description' => t('If you have added support for a new country, you will need to clear the supported country list to get Location to recognize the modifications.'),
|
| 312 |
);
|
| 313 |
$form['supported_countries_clear']['supported_countries_clear_submit'] = array(
|
| 314 |
'#type' => 'submit',
|
| 315 |
'#value' => t('Clear supported country list'),
|
| 316 |
'#submit' => array('location_util_form_clear_supported_countries_submit'),
|
| 317 |
);
|
| 318 |
return $form;
|
| 319 |
}
|
| 320 |
|
| 321 |
/**
|
| 322 |
* Location utilities form: Clear province cache.
|
| 323 |
*/
|
| 324 |
function location_util_form_clear_province_cache_submit() {
|
| 325 |
drupal_set_message(t('Location province cache cleared.'));
|
| 326 |
cache_clear_all('provinces:', 'cache_location', TRUE);
|
| 327 |
}
|
| 328 |
|
| 329 |
/**
|
| 330 |
* Location utilities form: Clear supported countries cache.
|
| 331 |
*/
|
| 332 |
function location_util_form_clear_supported_countries_submit() {
|
| 333 |
drupal_set_message(t('Location supported country list cleared.'));
|
| 334 |
cache_clear_all('location:supported-countries', 'cache_location');
|
| 335 |
}
|