--- location.inc	Fri Nov 27 08:07:42 2009 +1100
+++ location.inc	Fri Nov 27 08:16:18 2009 +1100
@@ -1,5 +1,5 @@
 <?php
-// $Id: location.inc,v 1.95.2.3 2009/07/08 20:53:22 bdragon Exp $
+// $Id: location.inc,v 1.95.2.1 2009/01/09 17:34:39 bdragon Exp $
 
 /**
  * @defgroup Location Location: An API for working with locations.
@@ -37,7 +37,7 @@
  * @ingroup Location
  */
 function location_map_link($location = array(), $link_text = 'See map: ') {
-  if (!isset($location['country']) || $location['country'] == 'xx') {
+  if (!isset($location['country']) && $location['country'] != 'xx') {
     return '';
   }
 
@@ -88,20 +88,40 @@
  *
  * @ingroup Location
  */
+ // emfluence
 function location_get_postalcode_data($location = array()) {
-  $location['country'] = isset($location['country']) ? trim($location['country']) : NULL;
-  $location['postal_code'] = isset($location['postal_code']) ? trim($location['postal_code']) : NULL;
-  if (is_null($location['postal_code']) || is_null($location['country']) || empty($location['country']) || empty($location['postal_code']) || $location['postal_code'] == 'xx') {
-    return NULL;
-  }
-  location_load_country($location['country']);
-  $country_specific_function = 'location_get_postalcode_data_'. $location['country'];
-  if (function_exists($country_specific_function)) {
-    return $country_specific_function($location);
-  }
-  else {
-    return NULL;
-  }
+	$location['country'] = isset($location['country']) ? trim($location['country']) : NULL;
+	$location['postal_code'] = isset($location['postal_code']) ? trim($location['postal_code']) : NULL;
+	if (is_null($location['postal_code']) || is_null($location['country']) || empty($location['country']) || empty($location['postal_code']) || $location['postal_code'] == 'xx') {
+			return NULL;
+	}
+	$country_specific_function = 'location_get_postalcode_data_'. $location['country'];
+	if (function_exists($country_specific_function)) {
+			return $country_specific_function($location);
+	}
+	else {
+		if ($cache = cache_get('location:supported-countries', 'cache_location')) {
+			$country = $location['country'];
+			if ($cache->data[$country]) {
+				$include = drupal_get_path('module', 'location') .'/supported/location.'. $location['country'] .'.inc';
+				if (file_exists($include)){
+					include_once($include);
+					if (function_exists($country_specific_function)) {
+						return $country_specific_function($location);
+					} else {
+						drupal_set_message(t('The support file for: ' . $location['country']. ' found at <i>' . $include .'</i>. does not have a function to support zip code look ups. Missing funtion: <i>' . $country_specific_function . '</i>'), 'error');
+					}
+				} else {
+					drupal_set_message(t('The support file for: ' . $location['country']. ' could not be found at <i>' . $include .'</i>.'), 'error');
+				}
+			} else {
+				drupal_set_message(t('The country code requested: ' . $location['country']. ' is not supported by this site.'), 'warning');
+			}
+		} else {
+			drupal_set_message(t('There are no supported countries in the site cache.'), 'warning');
+		}
+		return NULL;
+	}
 }
 
 /**
--- location.module	Fri Nov 27 08:07:42 2009 +1100
+++ location.module	Fri Nov 27 08:16:18 2009 +1100
@@ -1,5 +1,5 @@
 <?php
-// $Id: location.module,v 1.222.2.25 2009/07/30 20:58:43 bdragon Exp $
+// $Id: location.module,v 1.222.2.20 2009/03/03 20:07:19 bdragon Exp $
 
 /**
  * @file
@@ -70,15 +70,6 @@
     'access arguments' => array('administer site configuration'),
     'type' => MENU_CALLBACK,
   );
-  $items['admin/settings/location/util'] = array(
-    'title' => 'Location utilities',
-    'page callback' => 'drupal_get_form',
-    'page arguments' => array('location_util_form'),
-    'access arguments' => array('administer site configuration'),
-    'file' => 'location.admin.inc',
-    'type' => MENU_LOCAL_TASK,
-    'weight' => 3,
-  );
 
   return $items;
 }
@@ -654,7 +645,7 @@
             );
           }
           else {
-            $options = array_merge(array('' => t('Please select'), 'xx' => t('NOT LISTED')), location_get_iso3166_list());
+            $options = array_merge(array('' => t('Please select'), 'xx' => 'NOT LISTED'), location_get_iso3166_list());
             return array(
               '#type'           => 'select',
               '#title'          => t('Country'),
@@ -714,6 +705,21 @@
       }
       break;
 
+    case 'instance_links':
+      foreach ($obj as $k => $v) {
+        if ($v['nid'] != 0) {
+          $node = node_load($v['nid']);
+          $obj[$k]['href'] = 'node/'. $v['nid'];
+          $obj[$k]['title'] = $node->title;
+        }
+        else if ($v['uid'] != 0) {
+          $account = user_load(array('uid' => $v['uid']));
+          $obj[$k]['href'] = 'user/'. $v['uid'];
+          $obj[$k]['title'] = $account->name;
+        }
+      }
+      break;
+
   }
 }
 
@@ -827,7 +833,8 @@
       if ($location['lid'] !== FALSE) {
         $args[] = $location['lid'];
         $newlids[] = $location['lid'];
-        db_query('INSERT INTO {location_instance} ('. implode(', ', $columns) .') VALUES ('. implode(', ', $placeholders) .')', $args);
+								db_query('INSERT INTO {location_instance} ('. implode(', ', $columns) .') VALUES ('. implode(', ', $placeholders) .')', $args);
+        //db_query('INSERT INTO {location_instance} ('. implode(', ', $columns) .') VALUES ('. implode(', ', $placeholders) .')', $args);
         array_pop($args);
       }
     }
@@ -1000,26 +1007,6 @@
 }
 
 /**
- * Apply locpick twiddling to a location.
- * This is needed before saving and comparison.
- */
-function _location_patch_locpick(&$location) {
-  $inhibit_geocode = FALSE;
-  if (!empty($location['locpick'])) {
-    $location['locpick']['user_latitude'] = trim($location['locpick']['user_latitude']);
-    $location['locpick']['user_longitude'] = trim($location['locpick']['user_longitude']);
-  }
-  // If the user location was set, convert it into lat / lon.
-  if (!empty($location['locpick']['user_latitude']) && !empty($location['locpick']['user_longitude'])) {
-    $location['source'] = LOCATION_LATLON_USER_SUBMITTED;
-    $location['latitude'] = $location['locpick']['user_latitude'];
-    $location['longitude'] = $location['locpick']['user_longitude'];
-    $inhibit_geocode = TRUE;
-  }
-  return $inhibit_geocode;
-}
-
-/**
  * Save a location.
  *
  * This is the central function for saving a location.
@@ -1058,7 +1045,18 @@
   if (isset($location['lid']) && !empty($location['lid'])) {
     $oldloc = (array)location_load_location($location['lid']);
   }
-  if (_location_patch_locpick($location)) {
+
+  // @@@ This isn't the best place to do this...
+  // But if the user only changes user lat/lon, we need to be able to detect it!
+  if (!empty($location['locpick'])) {
+    $location['locpick']['user_latitude'] = trim($location['locpick']['user_latitude']);
+    $location['locpick']['user_longitude'] = trim($location['locpick']['user_longitude']);
+  }
+  // If the user location was set, convert it into lat / lon.
+  if (!empty($location['locpick']['user_latitude']) && !empty($location['locpick']['user_longitude'])) {
+    $location['source'] = LOCATION_LATLON_USER_SUBMITTED;
+    $location['latitude'] = $location['locpick']['user_latitude'];
+    $location['longitude'] = $location['locpick']['user_longitude'];
     $inhibit_geocode = TRUE;
   }
 
@@ -1197,16 +1195,6 @@
     return TRUE;
   }
 
-  // Special case: Consider a location with the "delete" checkbox checked to
-  // be empty.
-  if (isset($location['delete_location']) && $location['delete_location']) {
-    return TRUE;
-  }
-
-  // Patch locpick at this point.
-  // Otherwise, changing locpick only will not show a difference.
-  _location_patch_locpick($location);
-
   $settings = isset($location['location_settings']) ? $location['location_settings'] : array();
   $emptyloc = location_empty_location($settings);
 
@@ -1251,7 +1239,10 @@
   }
   foreach ($location as $k => $v) {
     if (!isset($tmp[$k])) {
-      unset($location[$k]);
+				// emfluence
+			if(!($location[$k] == "locpick" || $location[$k] == "user_latitude" || $location[$k] == "user_longitude")) {
+	      unset($location[$k]);
+			}
     }
   }
 }
@@ -1301,7 +1292,8 @@
   if (!$inhibit_geocode) {
     // Have any of the fields possibly affecting geocoding changed?
     // Or, was the location previously user submitted but is no longer?
-    if ($changed['street'] || $changed['additional'] || $changed['city'] || $changed['province'] || $changed['country'] || $changed['postal_code'] || $location['source'] == LOCATION_LATLON_USER_SUBMITTED) {
+		// emfluence
+    if ($changed['street'] || $changed['additional'] || $changed['city'] || $changed['province'] || $changed['country'] || $changed['postal_code'] || $location['source'] == LOCATION_LATLON_USER_SUBMITTED || $location['source'] == LOCATION_LATLON_UNDEFINED) {
 
       // Attempt exact geocoding.
       if ($data = location_latlon_exact($location)) {
@@ -1321,6 +1313,10 @@
         $location['source'] = LOCATION_LATLON_UNDEFINED;
         $location['latitude'] = 0;
         $location['longitude'] = 0;
+								//emfluence
+								if (! ( empty($location['street']) || empty($location['postal_code']) ) ){
+									drupal_set_message(t('The location could not be identified based on the address, or zip code provided.'), 'warning');
+								}
       }
     }
   }
