Index: modules/location/location.module
===================================================================
RCS file: /cvs/drupal/contributions/modules/location/location.module,v
retrieving revision 1.62
diff -u -r1.62 location.module
--- modules/location/location.module	19 Apr 2006 00:08:32 -0000	1.62
+++ modules/location/location.module	20 May 2006 16:23:40 -0000
@@ -468,6 +468,89 @@
       $form['location'] = array_merge($form['location'], location_latlon_form(t('If you wish to supply your own latitude/longitude, you may do so here.  Leaving these fields blank means that the system will determine a latitude/longitude for you, if possible.'), $node->location ? location_api2form($node->location) : array()));
     }
   }
+  else if ($form_id == 'user_configure_settings' && variable_get('location_user', 0)) {
+    // If locations are enabled for users, show location options on the 
+    // user settings configure form.
+    $form['location'] = array(
+      '#type' => 'fieldset',
+      '#title' => t('Locative information'),
+      '#collapsible' => TRUE,
+      '#collapsed' => TRUE,
+      '#weight' => 0
+    );
+    for ($i=-10; $i<11; $i++) {
+      $options[$i] = $i;
+    }
+    $form['location']['location_weight_user'] = array(
+      '#type' => 'select',
+      '#title' => t('Location weight'),
+      '#options' => $options,
+      '#default_value' => variable_get('location_weight_user', 9),
+      '#description' => t('Weight of the location box in the input form. Lowest values will be displayed higher in the form.')
+    );
+    $form['location']['location_collapsible_user'] = array(
+      '#type' => 'checkbox',
+      '#title' => t('Collapsible'),
+      '#return_value' => 1,
+      '#default_value' => variable_get('location_collapsible_user', 1),
+      '#description' => t('Make the location box collapsible.')
+    );
+    $form['location']['location_collapsed_user'] = array(
+      '#type' => 'checkbox',
+      '#title' => t('Collapsed'),
+      '#return_value' => 1,
+      '#default_value' => variable_get('location_collapsed_user', 1),
+      '#description' => t('Display the location box collapsed.')
+    );
+    $form['location']['location_name_user'] = array(
+      '#type' => 'radios',
+      '#title' => t('Location names'),
+      '#default_value' => variable_get('location_name_user', $default),
+      '#options' => array(t('Do not collect location names (e.g. place of business) for users.'), t('Allow location names for users.'), t('Require location names for users.'))
+    );
+    $form['location']['location_street_user'] = array(
+      '#type' => 'radios',
+      '#title' => t('Street locations'),
+      '#default_value' => variable_get('location_street_user', $default),
+      '#options' => array(t('Do not collect a street location for users.'), t('Allow street locations to be submitted for users.'), t('Require street locations to be submitted for users.'))
+    );
+    $form['location']['location_city_user'] = array(
+      '#type' => 'radios',
+      '#title' => t('City names'),
+      '#default_value' => variable_get('location_city_user', 0),
+      '#options' => array(t('Do not collect city names for users.'), t('Allow city names to be submitted for users.'), t('Require city names to be submitted for users.'))
+    );
+    $form['location']['location_province_user'] = array(
+      '#type' => 'radios',
+      '#title' => 'State/Province names',
+      '#default_value' => variable_get('location_province_user', 0),
+      '#options' => array(t('Do not collect state/province names for users.'), t('Allow state/province names to be submitted for users.'), t('Require state/province names to be submitted for users.'))
+    );
+    $form['location']['location_postal_code_user'] = array(
+      '#type' => 'radios',
+      '#title' => 'Postal codes',
+      '#default_value' => variable_get('location_postal_code_user', 0),
+      '#options' => array(t('Do not collect postal codes for users.'), t('Allow postal codes to be submitted for users.'), t('Require postal codes to be submitted for users.'))
+    );
+    $form['location']['location_country_user'] = array(
+      '#type' => 'radios',
+      '#title' => 'Country names',
+      '#default_value' => variable_get('location_country_user', 1),
+      '#options' => array(1 => t('Allow country names to be submitted for users.'), 2 => t('Require country names to be submitted for users.')),
+      '#description' => t('The selection of a country can be hidden and/or forced to a default country selection by going to the %location_settings and checking the box marked "Hide country selection" and selecting a country from the drop down select labelled "Default country selection".', array('%location_settings' => l(t('location settings page'), 'admin/settings/location'))),
+    );
+    $form['location']['location_user_register'] = array(
+      '#type' => 'checkbox',
+      '#title' => t('Collect location information on registration form'),
+      '#return_value' => 1,
+      '#default_value' => variable_get('location_user_register', 0),
+      '#description' => t('Enable the submission of a location on user registration form.')
+    );
+    // clear the views cache in case anything was changed
+    if (function_exists('views_invalidate_cache')) {
+      views_invalidate_cache();
+    }
+  }
 }
 
 /**
@@ -757,7 +840,7 @@
         '#title' => 'User locations',
         '#default_value' => variable_get('location_user', 0),
         '#options' => array('Disable', 'Enable'),
-        '#description' => t('Collect user addresses (partial or full) if users wish to submit them for their user accounts.')
+        '#description' => t('Collect user addresses (partial or full) if users wish to submit them for their user accounts. If you enable this option, please go to the <a href="%user-settings">user configuration</a> page to set additional options.', array('%user-settings' => url('admin/settings/user')))
         );
   }
   else {
@@ -803,18 +886,12 @@
   if ($user_setting == LOCATION_USER_DONT_COLLECT) {
     return;
   }
-  
-  if ($op == 'form' && $category == 'account' && $user_setting == LOCATION_USER_COLLECT) {
-    $form = array(1 => array());
-    $form[0]['location'] = location_form(array('street', 'city', 'province', 'postal_code', 'country'), (isset($user->location) && !_location_is_empty($user->location)) ? location_api2form($user->location) : array('country' => variable_get('location_default_country', 'us')));
-    $form[0]['location']['#type'] = 'fieldset';
-    $form[0]['location']['#title'] = t('Location');
-    $form[0]['location']['#tree'] = TRUE;
-    $form[0]['location']['#description'] = t('Enter as much of your address as you are comfortable with. Your address will only be viewable by those who have the appropriate permissions. The site will be able to automatically link you to driving directions and other features if it already knows your address.');
-    return $form;
+
+  if (($op == 'register' && variable_get('location_user_register', 0)) || ($op == 'form' && $category == 'account' && $user_setting == LOCATION_USER_COLLECT)) {
+    return location_user_form($user);
   }
   
-  if ($op == 'load' && $user_setting != LOCATION_USER_DONT_COLLECT) {
+  if ($op == 'load') {
     $res = db_query("SELECT * FROM {location} WHERE type = 'user' AND oid = %d", $user->uid);
     if ($location = db_fetch_object($res)) {
       $user->location = (array)$location;
@@ -885,6 +962,65 @@
   
 }
 
+function location_user_form($user) {
+  $location_fields = array();
+  $required_fields = array();
+  foreach (array_keys(location_field_names()) as $field_name) {
+    $workflow_setting = variable_get('location_'. $field_name .'_user', $field_name == 'country' ? 1 : 0);
+    if ($workflow_setting) {
+      $location_fields[] = $field_name;
+      if ($workflow_setting == 2) {
+        $required_fields[] = $field_name;
+      }
+    }
+  }
+
+  if (!isset($user->location['country']) || $user->location['country'] == '') {
+    $user->location['country'] = variable_get('location_default_country', 'us');
+  }
+
+  $suppressed_values = variable_get('location_suppress_country', 0) ? array('country' => variable_get('location_default_country', 'us')) : array();
+
+  if ($_POST['op'] == t('Preview') || ($_POST['op'] == t('Submit') && form_get_errors())) {
+    $form['location'] = location_form($location_fields, $user->location ? $user->location : array(), $required_fields, $suppressed_values);
+  }
+  else {
+    $form['location'] = location_form($location_fields, $user->location ? location_api2form($user->location) : array(), $required_fields, $suppressed_values);
+  }
+  $form['location']['#type'] = 'fieldset';
+  $form['location']['#title'] = t('Location');
+  $form['location']['#tree'] = TRUE;
+  $form['location']['#attributes'] = array('class' => 'location');
+  $form['location']['#weight'] = variable_get('location_weight_user', 9);
+  $form['location']['#collapsible'] = variable_get('location_collapsible_user', 0) == 0 ? FALSE : TRUE;
+  $form['location']['#collapsed'] = variable_get('location_collapsed_user', 0) == 0 ? FALSE : TRUE;
+
+  if (user_access('submit latitude/longitude')) {
+    $form['location'][] = array(
+    '#type' => 'markup',
+    '#value' => "<br/>\n"
+    );
+    if ($user->uid || isset($user->location['previous_source'])) {
+      $form['location']['previous_source'] = array(
+      '#type' => 'hidden',
+      '#value' => $user->location['source']
+      );
+      $form['location']['previous_latitude'] = array(
+      '#type' => 'hidden',
+      '#value' => $user->location['latitude']
+      );
+      $form['location']['previous_longitude'] = array(
+      '#type' => 'hidden',
+      '#value' => $user->location['longitude']
+      );
+    }
+
+    $form['location'] = array_merge($form['location'], location_latlon_form(t('If you wish to supply your own latitude/longitude, you may do so here.  Leaving these fields blank means that the system will determine a latitude/longitude for you, if possible.'), $user->location ? location_api2form($user->location) : array()));
+  }
+
+  return $form;
+}
+
 /**
  * Saves a location.  Needs a $user or $node object.
  * 
