Index: domain_geolocalization.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/domain_geolocalization/domain_geolocalization.inc,v
retrieving revision 1.1.2.6
diff -u -r1.1.2.6 domain_geolocalization.inc
--- domain_geolocalization.inc	4 Dec 2009 23:07:49 -0000	1.1.2.6
+++ domain_geolocalization.inc	4 Feb 2010 18:44:25 -0000
@@ -13,6 +13,7 @@
  */
 function _domain_geolocalization_update_user(&$edit, &$account) {
   $edit['domain_geolocalization'] = $account->domain_geolocalization = domain_geolocalization_set_user_location($edit['domain_geolocalization']);
+  unset($_SESSION['domain_user_default_location_set']);
 }
 
 /**
@@ -23,11 +24,10 @@
     $field = 'uid';
     $value = $account->uid;
   }
-  elseif (module_exists('domain_session_default') && session_api_available()) {
+  elseif (module_exists('session_api') && session_api_available()) {
     $field = 'sid';
     $value = session_api_get_sid();
   }
-
   if ($field) {
     $result = db_query("SELECT * FROM {domain_geolocalization_location_instance} LEFT JOIN {domain_geolocalization_location} USING (dglid) WHERE " . $field . " = %d", $value);
     $location = db_fetch_array($result);
@@ -35,7 +35,6 @@
     unset($location['domain_id'], $location['uid'], $location['sid']);
     return $location;
   }
-
   return FALSE;
 }
 
@@ -252,9 +251,11 @@
  * through to the user domain switcher.
  */
 function domain_geolocalization_international_domain_selector_form_submit($form, &$form_state) {
+  if (module_exists('domain_user_default')) {
   module_load_include('inc', 'domain_user_default');
   domain_user_default_domain_switcher_form_submit($form, $form_state);
 }
+}
 
 /**
  * Provides and options list for use in a form of all international (Country other than US).
Index: domain_geolocalization.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/domain_geolocalization/domain_geolocalization.module,v
retrieving revision 1.1.2.16
diff -u -r1.1.2.16 domain_geolocalization.module
--- domain_geolocalization.module	4 Dec 2009 23:07:49 -0000	1.1.2.16
+++ domain_geolocalization.module	4 Feb 2010 19:10:42 -0000
@@ -231,7 +231,6 @@
     // primary domain gmap key
     $domain['gmap_key'] = variable_get('domain_geolocalization_primary_gmap_key', FALSE);
   }
-
   $geo = db_fetch_object(db_query("SELECT * FROM {domain_geolocalization} LEFT JOIN {domain_geolocalization_location_instance} USING (domain_id) LEFT JOIN {domain_geolocalization_location} USING (dglid) WHERE {domain_geolocalization}.domain_id = %d", $domain['domain_id']));
   if ($geo) {
     foreach ($geo as $key => $value) {
@@ -347,6 +346,12 @@
     '#description' => t('If selected, one and only one domain will be defined as a default for a given state. If left unselected, default states will be presented to the user as a proximity ordered list if no domains are found.'),
     '#default_value' => variable_get('domain_geolocalization_use_state_defaults', FALSE),
   );
+  $form['domain_geolocalization']['domain_geolocalization_store_user_locative_information'] = array(
+    '#type' => 'checkbox',
+    '#title' => t('Store user locative information in the database and in $user object'),
+    '#description' => t('If selected, user locative information will be stored in the database and available in the $user object.'),
+    '#default_value' => variable_get('domain_geolocalization_store_user_locative_information', TRUE),
+  );
 
   // Display/theme settings
   if (module_exists('domain_user_default')) {
@@ -435,6 +440,7 @@
   // Domain User Default module when picking a domain off a list.
   $record = (object) $address;
   $set = _domain_geolocalization_set_user_location($record);
+  unset($_SESSION['domain_user_default_location_set']);
   if ($set && ($record->radius || $record->latitude || $record->longitude)) {
     // only attempt writes if domain is geolocalized
     if ($user->uid > 0) {
@@ -445,7 +451,7 @@
       }
       $record->uid = $user->uid;
     }
-    elseif (module_exists('domain_session_default') && domain_user_default_is_switchable()) {
+    elseif ((module_exists('domain_session_default') && domain_user_default_is_switchable()) || module_exists('session_api')) {
       $sid = session_api_get_sid();
       // save locative information to the session
       if ($existing = db_fetch_object(db_query("SELECT * FROM {domain_geolocalization_location_instance} LEFT JOIN {domain_geolocalization_location} USING (dglid) WHERE sid = %d", $sid))) {
@@ -482,6 +488,8 @@
  * for Drupal 6. At that point it will either go away or be modified.
  */
 function domain_geolocalization_user($op, &$edit, &$account, $category = NULL) {
+  // User data is only stored if so defined in domain settings
+  if (variable_get('domain_geolocalization_store_user_locative_information',TRUE)) {
   switch ($op) {
     case 'insert':
     case 'update':
@@ -492,11 +500,32 @@
       break;
     case 'load':
       // load locative information
+        global $_domain;
       module_load_include('inc', 'domain_geolocalization');
       $account->domain_geolocalization = _domain_geolocalization_load_user_location($account);
+        if ($account->domain_geolocalization == FALSE || $account->domain_geolocalization['domain_id'] != $_domain['domain_id']) {
+          $account->domain_geolocalization = array(
+            'domain_id' => $_domain['domain_id'],
+            'state_default' => '',
+            'latitude' => '',
+            'longitude' => '',
+            'city' => '',
+            'state' => '',
+            'country' => '',
+            'radius' => '',
+            'zipcode' => '',
+          );
+          _domain_geolocalization_map_domain_to_user($account, $_domain);
+          // Make changes to $user object permanent
+          $edit = array(
+            'domain_geolocalization' => $account->domain_geolocalization,
+          );
+          _domain_geolocalization_update_user($edit, $account);
+        }
       break;
   }
 }
+}
 
 /**
  * Remove records from db.
@@ -549,4 +578,4 @@
       $user->domain_geolocalization[$key] = $domain[$key];
     }
   }
-}
+}
\ No newline at end of file

