### Eclipse Workspace Patch 1.0 #P location Index: location.module =================================================================== RCS file: /cvs/drupal/contributions/modules/location/location.module,v retrieving revision 1.80 diff -u -r1.80 location.module --- location.module 19 Feb 2007 11:30:22 -0000 1.80 +++ location.module 5 Apr 2007 17:05:22 -0000 @@ -12,6 +12,9 @@ define('LOCATION_USER_COLLECT', 1); define('LOCATION_USER_CIVICRM_ONLY', 2); +define('LOCATION_USER_FIELDSET_TITLE', 'Location'); +define('LOCATION_USER_FIELDSET_DESC', '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.'); + include_once LOCATION_PATH.'/location.inc'; /** @@ -23,6 +26,14 @@ if ($may_cache) { $items[] = array('path' => 'search/location', 'title' => t('By location'), 'callback' => 'drupal_get_form', 'callback arguments' => array('location_search_view'), 'access' => user_access('search content'), 'type' => MENU_LOCAL_TASK, 'weight' => 9,); $items[] = array('path' => 'admin/settings/location/main', 'title' => t('Main settings'), 'type' => MENU_DEFAULT_LOCAL_TASK,); + $items[] = array( + 'path' => 'admin/settings/location/user', + 'title' => t('User Locations'), + 'callback' => 'drupal_get_form', + 'callback arguments' => array('location_admin_settings_user'), + 'access' => user_access('administer site configuration'), + 'type' => MENU_LOCAL_TASK, + ); $items[] = array('path' => 'admin/settings/location/maplinking', 'title' => t('Map links'), 'callback' => 'location_map_link_options_page', 'access' => user_access('administer site configuration'), 'type' => MENU_LOCAL_TASK, 'weight' => 1,); $items[] = array('path' => 'admin/settings/location/geocoding', 'title' => t('Geocoding options'), 'callback' => 'location_geocoding_options_page', 'access' => user_access('administer site configuration'), 'type' => MENU_LOCAL_TASK, 'weight' => 2,); $items[] = array('path' => 'admin/settings/location', 'title' => t('Location'), 'description' => t('Settings for Location module'), 'callback' => 'drupal_get_form', 'callback arguments' => array('location_admin_settings'), 'access' => user_access('administer site configuration'), 'type' => MENU_NORMAL_ITEM, ); @@ -1311,22 +1322,27 @@ '#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.') ); - if (!module_exists('civicrm')) { - $form['location_user'] = array( - '#type' => 'radios', - '#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.') - ); - } - else { - $form['location_user'] = array( - '#type' => 'item', - '#title' => t('User locations'), - '#description' => t("You have enabled the CiviCRM module. This means that CiviCRM will collect user locations for you. To make sure you will be able to use location module features with these user addresses, you should make sure the CiviCRM 'address' profile is marked as active. If you installed CiviCRM on a seperate Drupal installation, please consult the documentation in the README.txt file for the Location module.") - ); - } + /* + * commented out in favor of new user options page from location_admin_settings_user() + * + * if (!module_exists('civicrm')) { + * $form['location_user'] = array( + * '#type' => 'radios', + * '#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.') + * ); + * } + * else { + * $form['location_user'] = array( + * '#type' => 'item', + * '#title' => t('User locations'), + * '#description' => t("You have enabled the CiviCRM module. This means that CiviCRM will collect user locations for you. To make sure you will be able to use location module features with these user addresses, you should make sure the CiviCRM 'address' profile is marked as active. If you installed CiviCRM on a seperate Drupal installation, please consult the documentation in the README.txt file for the Location module.") + * ); + * } + * + */ $form['location_usegmap'] = array( '#type' => 'checkbox', @@ -1357,24 +1373,66 @@ } } +function _location_effective_user_registration_setting() { + if (module_exists('civicrm')) { + return LOCATION_USER_CIVICRM_ONLY; + } + else { + return variable_get('location_user_reg', LOCATION_USER_DONT_COLLECT); + } +} + function location_user($op, &$edit, &$user, $category = NULL) { $user_setting = _location_effective_user_setting(); + $reg_setting = _location_effective_user_registration_setting(); 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')), array(), variable_get('location_suppress_country', 0) ? array('country' => variable_get('location_default_country', 'us')) : array()); - $form[0]['location']['#type'] = 'fieldset'; - $form[0]['location']['#title'] = t('Location'); - $form[0]['location']['#tree'] = TRUE; - $form[0]['location']['#collapsible'] = 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.'); + /* + * commented out in favor of new implementation below + * + * 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')), array(), variable_get('location_suppress_country', 0) ? array('country' => variable_get('location_default_country', 'us')) : array()); + * $form[0]['location']['#type'] = 'fieldset'; + * $form[0]['location']['#title'] = t('Location'); + * $form[0]['location']['#tree'] = TRUE; + * $form[0]['location']['#collapsible'] = 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.'); + * + * if ($user->location['lid']) { + * $form[0]['location']['lid'] = array( + * '#type' => 'hidden', + * '#value' => $user->location['lid'] + * ); + * } + * + * return $form; + * } + * + */ + + // expanded and cleaned up slightly + if (($op == 'form' && $category == 'account' && $user_setting == LOCATION_USER_COLLECT) || ($op == 'register' && $user_setting == LOCATION_USER_COLLECT && $reg_setting == LOCATION_USER_COLLECT)) { + $form['location'] = location_form( + variable_get('location_user_fields', array_keys(_location_user_field_names())), + (isset($user->location) && !_location_is_empty($user->location)) ? location_api2form($user->location) : array('country' => variable_get('location_default_country', 'us')), + variable_get('location_user_fields_required', array()), + variable_get('location_suppress_country', 0) ? array('country' => variable_get('location_default_country', 'us')) : array() + ); + $form['location']['#type'] = 'fieldset'; + $form['location']['#title'] = t(variable_get('location_user_fieldset_title', LOCATION_USER_FIELDSET_TITLE)); + $form['location']['#tree'] = TRUE; + $form['location']['#collapsible'] = variable_get('location_user_fieldset_collapse', TRUE); + $form['location']['#description'] = t(variable_get('location_user_fieldset_desc', LOCATION_USER_FIELDSET_DESC)); + if (variable_get('location_user_fieldset_weight', 0)) { + $form['location']['#weight'] = variable_get('location_user_fieldset_weight', 0); + } if ($user->location['lid']) { - $form[0]['location']['lid'] = array( + $form['location']['lid'] = array( '#type' => 'hidden', '#value' => $user->location['lid'] ); @@ -1538,3 +1596,112 @@ } return $return; } + +/** + * Callback function for user options page /admin/settings/location/user + */ +function location_admin_settings_user() { + if (module_exists('civicrm')) { + $form['location_user'] = array( + '#type' => 'item', + '#title' => t('User locations'), + '#description' => t("You have enabled the CiviCRM module. This means that CiviCRM will collect user locations for you. To make sure you will be able to use location module features with these user addresses, you should make sure the CiviCRM 'address' profile is marked as active. If you installed CiviCRM on a seperate Drupal installation, please consult the documentation in the README.txt file for the Location module.") + ); + } + else { + // fields to collect + $form['collection'] = array( + '#type' => 'fieldset', + '#title' => t('Collection'), + '#description' => t('Select which location data we will collect for users.'), + ); + + $form['collection']['location_user'] = array( + '#type' => 'radios', + '#title' => 'On profile edit', + '#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.') + ); + + $form['collection']['location_user_reg'] = array( + '#type' => 'radios', + '#title' => 'For new account creation', + '#default_value' => variable_get('location_user_reg', 0), + '#options' => array('Disable', 'Enable'), + '#description' => t('Collect user addresses (partial or full) if users wish to submit them when creating their user accounts.') + ); + + $form['collection']['location_user_fields'] = array( + '#type' => 'checkboxes', + '#title' => 'Shown fields', + '#default_value' => variable_get('location_user_fields', array_keys(_location_user_field_names())), + '#options' => _location_user_field_names(), + '#description' => t('Which fields will be presented to the user to complete.') + ); + + $form['collection']['location_user_fields_required'] = array( + '#type' => 'checkboxes', + '#title' => 'Required fields', + '#default_value' => variable_get('location_user_fields_required', array()), + '#options' => _location_user_field_names(), + '#description' => t('Which fields will be required for the user. If the fields are not enable above, they will not be required, however.') + ); + + // presentation options + $form['presentation'] = array( + '#type' => 'fieldset', + '#title' => t('Presentation'), + '#description' => t('Presentation options for the user location fieldset.'), + ); + + $form['presentation']['location_user_fieldset_title'] = array( + '#type' => 'textfield', + '#title' => t('Title'), + '#default_value' => variable_get('location_user_fieldset_title', LOCATION_USER_FIELDSET_TITLE), + '#description' => t('The title for the user location fieldset.'), + ); + + $form['presentation']['location_user_fieldset_desc'] = array( + '#type' => 'textarea', + '#title' => 'Description', + '#default_value' => variable_get('location_user_fieldset_desc', LOCATION_USER_FIELDSET_DESC), + '#description' => t('The descriptive copy for the user location fieldset.'), + ); + + $form['presentation']['location_user_fieldset_collapse'] = array( + '#type' => 'radios', + '#title' => 'Collapsible?', + '#default_value' => variable_get('location_user_fieldset_collapse', TRUE), + '#options' => array(1 => 'Yes', 0 => No), + '#description' => t('Controls if the user is allowed to collapse the location fieldset.'), + ); + + $form['presentation']['location_user_fieldset_weight'] = array( + '#type' => 'textfield', + '#title' => 'Weight', + '#default_value' => variable_get('location_user_fieldset_weight', 0), + '#size' => 4, + '#maxlength' => 4, + '#description' => t('Weight of the location fieldset.'), + ); + + } + + return system_settings_form($form); + +} + +/** + * Returns an array of fields to use for user locations. + */ +function _location_user_field_names() { + return array( + 'street' => t('Street location'), + 'city' => t('City'), + 'province' => t('State/Province'), + 'postal_code' => t('Postal code'), + 'country' => t('Country') + ); +} +