Index: gmap_location.install
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/gmap/Attic/gmap_location.install,v
retrieving revision 1.1.2.2
diff -u -r1.1.2.2 gmap_location.install
--- gmap_location.install	28 Aug 2007 20:38:16 -0000	1.1.2.2
+++ gmap_location.install	7 Sep 2007 22:15:40 -0000
@@ -12,3 +12,62 @@
 function gmap_location_update_2() {
   drupal_set_message(t('WARNING! Obsolete gmap_location update #@num was triggered! Please verify the schema of your location table manually!', array('@num' => '2')));
 }
+
+// 5.x-0.8 first update
+function gmap_location_update_5080() {
+  // Convert role markers to single variable.
+  $result = db_query("SELECT name FROM {variable} WHERE name LIKE 'gmap_role_map_marker_%'");
+  $markers = array();
+  while ($row = db_fetch_object($result)) {
+    $num = (int)substr($row->name, 21);
+    $markers[$num] = variable_get($row->name, 'drupal');
+    variable_del($row->name);
+  }
+  variable_set('gmap_role_markers', $markers);
+  // It's pointless to have a default when the roles will take effect in all cases.
+  variable_del('gmap_user_map_marker');
+
+  // Convert node type markers to single variable.
+  $result = db_query("SELECT name FROM {variable} WHERE name LIKE 'gmap_node_marker_%'");
+  $markers = array();
+  while ($row = db_fetch_object($result)) {
+    $type = substr($row->name, 17);
+    $markers[$type] = variable_get($row->name, 'drupal');
+    variable_del($row->name);
+  }
+  variable_set('gmap_node_markers', $markers);
+
+  // User location setting functionality is moving to location.module.
+  variable_del('gmap_user');
+  variable_del('gmap_user_profile_category');
+
+  // gmap_user_map is a single variable now.
+  $temp = array(
+    'macro' => variable_get('gmap_user_map', '[gmap |id=usermap|center=40,0|zoom=3|width=100%|height=400px]'),
+    'header' => variable_get('gmap_user_map_header', 'This map illustrates the extent of users of this website. Each marker indicates a user that has entered their locations.'),
+    'footer' => '',
+  );
+  variable_set('gmap_user_map', $temp);
+  variable_del('gmap_user_map_header');
+
+  // gmap_node_map is a single variable now.
+  $temp = array(
+    'macro' => variable_get('gmap_node_map', '[gmap |id=nodemap|center=40,0|zoom=3|width=100%|height=400px]'),
+    'header' => variable_get('gmap_node_map_header', 'This map illustrates the locations of the nodes on this website. Each marker indicates a node associated with a specific location.'),
+    'footer' => '',
+  );
+  variable_set('gmap_node_map', $temp);
+  variable_del('gmap_node_map_header');
+
+  return array();
+}
+
+/**
+ * Implementation of hook_uninstall().
+ */
+function gmap_location_uninstall() {
+  variable_del('gmap_user_map');
+  variable_del('gmap_node_map');
+  variable_del('gmap_node_markers');
+  variable_del('gmap_role_markers');
+}
\ No newline at end of file
Index: gmap_location.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/gmap/Attic/gmap_location.module,v
retrieving revision 1.26.2.34
diff -u -r1.26.2.34 gmap_location.module
--- gmap_location.module	28 Aug 2007 20:59:22 -0000	1.26.2.34
+++ gmap_location.module	7 Sep 2007 23:49:44 -0000
@@ -13,7 +13,7 @@
  * Implementation of hook_perm().
  */
 function gmap_location_perm() {
-  return array('set user location', 'show user map', 'user locations', 'show node map');
+  return array('show user map', 'user locations', 'show node map');
 }
 
 /**
@@ -21,21 +21,32 @@
  */
 function gmap_location_menu($may_cache) {
   $items = array();
-
   if ($may_cache) {
     $items[] = array(
       'path' => 'map/user',
       'type' => MENU_NORMAL_ITEM,
       'title' => t('User locations'),
       'access' => user_access('show user map'),
-      'callback' => 'gmap_location_user_page'
+      'callback' => 'gmap_location_user_page',
+    );
+    $items[] = array(
+      'path' => 'map/user/load',
+      'type' => MENU_CALLBACK,
+      'access' => user_access('show user map'),
+      'callback' => 'gmap_location_user_point',
     );
     $items[] = array(
       'path' => 'map/node',
       'type' => MENU_NORMAL_ITEM,
       'title' => t('Node locations'),
       'access' => user_access('show node map'),
-      'callback' => 'gmap_location_node_page'
+      'callback' => 'gmap_location_node_page',
+    );
+    $items[] = array(
+      'path' => 'map/node/load',
+      'type' => MENU_CALLBACK,
+      'access' => user_access('show node map'),
+      'callback' => 'gmap_location_node_point',
     );
     $items[] = array(
       'path' => 'admin/settings/gmap_location',
@@ -54,62 +65,69 @@
  * Draws a page with a google map that has all of the site users.
  */
 function gmap_location_user_page() {
-  global $user;
-  $locationbyuser = array();
-
-  $output ='<p>'. t(variable_get('gmap_user_map_header', 'This map illustrates the extent of users of this website. Each marker indicates a user that has entered their locations.')) ."</p>\n";
 
-  // Find default marker
-  $default_marker = variable_get('gmap_user_map_marker', 'drupal');
+  $markertypes = variable_get('gmap_role_markers', array(DRUPAL_AUTHENTICATED_RID => 'drupal'));
 
-  // Determine if any roles override default setting
-  $roles = user_roles(TRUE);
-  $roles_override = array();
-  foreach ($roles as $rid => $role) {
-    if (variable_get("gmap_role_map_marker_$rid", $default_marker) != $default_marker) {
-      $roles_override[$rid] = $role;
-    }
-  }
+  $usermap = variable_get('gmap_user_map', array());
 
-  $thismap = array_merge(
+  $map = array_merge(
     gmap_defaults(),
-    gmap_parse_macro(variable_get('gmap_user_map', '[gmap|id=usermap|center=30,0|zoom=2|width=100%|height=400px]'))
+    gmap_parse_macro($usermap['macro'])
   );
-  $result=db_query("SELECT * FROM {location} WHERE (longitude !=0 OR latitude !=0) AND type='user'");
 
-  $mode = $thismap['markermode'];
+  $mode = $map['markermode'];
+  $map['rmtcallback'] = url('map/user/load');
 
-  while ($u=db_fetch_object($result)) {
-    $account = user_load(array('uid' => $u->eid));
-    $dupes = array_intersect($account->roles, $roles_override);
-    if (empty($dupes)) {
-      $marker = $default_marker;
-    }
-    else {
-      $key = key($dupes);
-      $marker = variable_get("gmap_role_map_marker_$key", $default_marker);
+  // Find the highest rid, if available, for each user with a location.
+  $result = db_query("
+    SELECT
+      u.name, MAX(r.rid) as role, l.eid as uid, l.latitude, l.longitude
+    FROM
+      {users} u
+    INNER JOIN
+      {location} l
+      ON
+        u.uid = l.eid
+    LEFT JOIN
+      {users_roles} r
+      ON
+        l.eid = r.uid
+    WHERE
+      l.type = '%s'
+      AND
+      (l.latitude != 0 OR l.longitude != 0)
+    GROUP BY
+      l.eid", 'user');
+
+  while ($row = db_fetch_object($result)) {
+    // Determine marker type to show.
+    $marker = $markertypes[DRUPAL_AUTHENTICATED_RID];
+    if ($row->role && isset($markertypes[$row->role])) {
+      $marker = $markertypes[$row->role];
     }
+
     if (user_access('user locations')) {
-      if ($mode==1) {
-        $newmarker['text'] = theme('gmap_location_user_html', $account);
+      if ($mode == 1) {
+        $newmarker['rmt'] = $row->uid;
       }
       else if ($mode == 2) {
-        $newmarker['link'] = url('user/'. $account->uid);
+        $newmarker['link'] = url('user/'. $row->uid);
       }
-      $newmarker['latitude'] = $u->latitude;
-      $newmarker['longitude'] = $u->longitude;
+      $newmarker['latitude'] = $row->latitude;
+      $newmarker['longitude'] = $row->longitude;
       $newmarker['markername'] = $marker;
-      $newmarker['opts']['title'] = check_plain($account->name);
-      $locationbyuser[$u->eid] = array('latitude' => $u->latitude, 'longitude' => $u->longitude);
+      $newmarker['opts']['title'] = check_plain($row->name);
     }
     else {
-      $newmarker['latitude']= $u->latitude;
-      $newmarker['longitude']= $u->longitude;
+      $newmarker['latitude']= $row->latitude;
+      $newmarker['longitude']= $row->longitude;
       $newmarker['markername'] = $marker;
     }
-    $thismap['markers'][]=$newmarker;
+    $map['markers'][]=$newmarker;
   }
 
+// @@@ Move to gmap_addons.
+/*
   if (user_access('user locations') && function_exists('buddylist_get_buddies') && count($locationbyuser)>0) {
     //create lines for buddies
     if (!isset($thismap['shapes'])) {
@@ -128,17 +146,31 @@
       }
     }
   }
+*/
 
-  $element = array(
-    '#type' => 'gmap',
-    '#map' => $thismap['id'],
-    '#settings' => $thismap,
+  return theme('gmap_location_user_page',
+    $usermap['header'],
+    theme('gmap', array('#settings' => $map)),
+    $usermap['footer']
   );
-  $output .= theme('gmap', $element);
+}
 
-  if ($user->uid > 0) {
-    $output .= '<p>'. t('To add/change your location to the user map, <a href="@url">edit your location</a>.', array('@url' => url('user/'. $user->uid .'/edit/gmap_user'))) .'</p>';
+/**
+ * AHAH callback for getting the contents of a user point popup.
+ */
+function gmap_location_user_point() {
+  $uid = arg(3);
+  if (is_numeric($uid) && $account = user_load(array('uid' => $uid))) {
+    echo theme('gmap_location_user_html', $account);
+    exit();
   }
+}
+
+/**
+ * Theme function for displaying the user page.
+ */
+function theme_gmap_location_user_page($header, $map, $footer) {
+  $output = "<p>$header</p>\n<p>$map</p>\n<p>$footer</p>";
   return $output;
 }
 
@@ -146,135 +178,163 @@
  * Draws a page with a google map with the node on it, or if no node is set all of the nodes on it.
  *
  * @param $nn
- * The node number to draw on the map.  If this is not set, or is null then all of the nodes will be drawn.
+ * The node nid to draw on the map.  If this is not set, or is null then all of the nodes will be drawn.
  */
 function gmap_location_node_page($nid = NULL) {
-  if ($nid && ($n = node_load($nid))) {
-    if (node_access('view', $n)) {
-      $output .='<p>'. t(variable_get('gmap_node_map_header', 'This map illustrates the extent of nodes of this website. ')) ."</p>\n";
-      $thismap = array_merge(gmap_defaults(), gmap_parse_macro(variable_get('gmap_node_map', '[gmap|id=nodemap|center=30,0|zoom=2|width=100%|height=400px]')));
-      $thismap = gmap_location_node_map($n, $thismap, TRUE);
-      $output .= '<p>'. theme('gmap', array('#settings' => $thismap));
-      // @@@ Hey! Wait a second -- Where's the closing </p> ?
-      return $output;
+
+  $nodemap = variable_get('gmap_node_map', array());
+  $markertypes = variable_get('gmap_node_markers', array());
+
+  $map = array_merge(
+    gmap_defaults(),
+    gmap_parse_macro($nodemap['macro']));
+
+  $mode = $map['markermode'];
+  $map['rmtcallback'] = url('map/node/load');
+  if (!is_array($map['markers'])) {
+    $map['markers'] = array();
+  }
+
+  $add_sql = (is_numeric($nid) && $nid > 0) ? ' AND n.nid = %d' : '';
+  $result = db_query(db_rewrite_sql("
+    SELECT n.nid, n.type, n.title, l.latitude, l.longitude
+    FROM {node} n
+    INNER JOIN {location} l
+      ON n.nid = l.eid
+    WHERE
+      l.type = '%s'
+    AND
+      (l.latitude != 0 OR l.longitude != 0)
+    ". $add_sql), 'node', $nid);
+
+  $count = 0;
+  while ($row = db_fetch_object($result)) {
+    $count++;
+    $newmarker = array();
+    if ($mode == 1) {
+      // Popup
+      $newmarker['rmt'] = $row->nid;
     }
-    else {   //access denied
-      return drupal_access_denied();
+    elseif ($mode == 2) {
+      // Link
+      $newmarker['link'] = url('node/'. $row->nid);
     }
+
+    $newmarker['latitude'] = $row->latitude;
+    $newmarker['longitude'] = $row->longitude;
+    $newmarker['markername'] = isset($markertypes[$row->type]) ? $markertypes[$row->type] : 'drupal';
+    $newmarker['opts']['title'] = $row->title;
+    $map['markers'][] = $newmarker;
   }
 
-  $output .='<p>'. t(variable_get('gmap_node_map_header', 'This map illustrates the extent of nodes of this website.')) ."</p>\n";
+  // Special stuff for single marker
+  if ($count == 1) {
+    // Center map on only marker.
+    $map['latitude'] = $map['markers'][0]['latitude'];
+    $map['longitude'] = $map['markers'][0]['longitude'];
 
-  $result = db_query(db_rewrite_sql("SELECT l.eid, l.longitude, l.latitude FROM {location} l INNER JOIN {node} n ON l.eid = n.vid WHERE (l.longitude!=0 OR l.latitude !=0) AND l.type='node' AND n.status = 1"));
-  $thismap = array_merge(gmap_defaults(), gmap_parse_macro(variable_get('gmap_node_map', '[gmap|id=usermap|center=30,0|zoom=2|width=100%|height=400px]')));
-  if (empty($thismap['markers'])) {
-    $thismap['markers']=array();
-  }
-  while ($locn=db_fetch_object($result)) {
-    $n = node_load(array('vid' => $locn->eid));
-    if ($n && node_access('view', $n)) {
-      $thismap = gmap_location_node_map($n, $thismap, FALSE);
+    // Autoclick in single marker case.
+    if ($mode == 1) {
+      $map['markers'][0]['autoclick'] = TRUE;
     }
   }
 
-  $output .= '<p>'. theme('gmap', array('#settings' => $thismap)) .'</p>';
+  // Special cases for single node view.
+  if (is_numeric($nid) && $node = node_load($nid)) {
+    if (user_access('user locations') && $node->type == 'og') {
+      // An OG is displayed as a map of the users who belong to the group.
+
+      $rolemarkers = variable_get('gmap_role_markers', array());
+
+      $map['markers'] = array(); // Reset markers.
+      $result = db_query("
+        SELECT
+          MAX(r.rid) as role, l.eid as uid, l.latitude, l.longitude
+        FROM
+          {og_uid} o
+        INNER JOIN {location} l
+          ON o.uid = l.eid
+        LEFT JOIN {users_roles} r
+          ON l.eid = r.uid
+        WHERE
+          o.nid = %d
+        AND
+          o.is_active >= 1
+        AND
+          l.type = '%s'
+        AND
+          (l.latitude != 0 OR l.longitude != 0)
+        GROUP BY
+          o.uid", $nid, 'user');
+
+      while ($row = db_fetch_object($result)) {
+        $newmarker = array();
+        $newmarker['rmt'] = $nid .'/'. $row->uid;
+
+        // Determine marker type to show.
+        $newmarker['markername'] = $markertypes[DRUPAL_AUTHENTICATED_RID];
+        if ($row->role && isset($rolemarkers[$row->role])) {
+          $newmarker['markername'] = $rolemarkers[$row->role];
+        }
+        $newmarker['latitude'] = $row->latitude;
+        $newmarker['longitude'] = $row->longitude;
+        $map['markers'][] = $newmarker;
+      }
+    }
+  }
+  elseif ($count == 0) {
+    // No results
+    return drupal_not_found();
+  }
 
-  return $output;
+  return theme('gmap_location_node_page',
+    $count,
+    $nodemap['header'],
+    theme('gmap', array('#settings' => $map)),
+    $nodemap['footer']
+  );
 }
 
 /**
- * Adds the location information from a node for a gmap.
- *
- * @param $n
- * The node object to add to the map.
- *
- * @param $thismap
- * A gmap var with the map that will be used as the basemap
- *
- * @param $single
- * true if this is the only node being looked at (will center the map and possible add
- * additional information.
- *
- * @return
- * A gmap centred on the
+ * AHAH callback for getting the contents of a node point popup.
  */
-function gmap_location_node_map($n, $thismap, $single = FALSE) {
-  if ((isset($n->gmap_location_latitude) && isset($n->gmap_location_longitude)) || (isset($n->location['latitude']) && isset($n->location['longitude']))) {
-    $latitude = isset($n->gmap_location_latitude) ? $n->gmap_location_latitude : $n->location['latitude'];
-    $longitude = isset($n->gmap_location_longitude) ? $n->gmap_location_longitude : $n->location['longitude'];
-
-    $mode = $thismap['markermode'];
-    $newmarker = array();
-    $width = 0;
-    if ($mode == 1) {
-      if (!($newmarker['text'] = theme(strtr($n->type, '-', '_') .'_gmapnodelabel', $n))) {
-        $newmarker['text'] = theme('gmapnodelabel', $n);
-        if ($single && $mode == 1) {
-          // Autoclick
-          $newmarker['autoclick'] = true;
-        }
-      }
-    }
-    else if ($mode == 2) {
-      $newmarker['link'] = url('node/'. $n->nid);
+function gmap_location_node_point() {
+  $nid = arg(3);
+  $opt = arg(4);
+  if (is_numeric($nid) && $node = node_load($nid)) {
+    $output = '';
+    $type = strtr($node->type, '-', '_');
+    $output = theme($type .'_gmapnodelabel', $node, $opt);
+    if (empty($output)) {
+      $output = theme('gmapnodelabel', $node, $opt);
     }
-
-    $newmarker['latitude'] = $latitude;
-    $newmarker['longitude'] = $longitude;
-    $newmarker['markername'] = variable_get('gmap_node_marker_'. $n->type, '');
-    $newmarker['opts']['title'] = $n->title;
-    switch ($n->type) {
-      case 'acidfree':
-        $newmarker['winwidth'] = (variable_get('acidfree_thumb_dim', IMAGE_THUMB_SIZE) + 40) .'px';
-        break;
-    }
-    $thismap['markers'][] = $newmarker;
-    if ($single) {
-      $thismap['latitude'] = $latitude;
-      $thismap['longitude'] = $longitude;
-    }
-
+    echo $output;
+    exit();
   }
-  if ($single) {
-    //do special things for certain nodes when it is the only node shown
-    switch ($n->type) {
-      case 'og':
-        $result = db_query(og_list_users_sql(), $n->nid);
-        while ($user = db_fetch_object($result)) {
-          if (isset($user->location['latitude']) && isset($user->location['longitude'])) {
-            if (user_access('user locations')) {
-              $newmarker = array(
-                'label' => theme('user_picture', $user) . theme('username', $user),
-                'latitude' => $latitude,
-                'longitude' => $longitude,
-                'markername' => variable_get('gmap_user_map_marker', 'drupal'),
-              );
-              if ($mode==1) {
-                // Autoclick
-                $newmarker['autoclick'] = true;
-              }
-              $thismap['markers'][] = $newmarker;
-            }
-          }
-          else {
-            $newmarker['latitude'] = $u->latitude;
-            $newmarker['longitude'] = $u->longitude;
-            if ($mode==1) {
-              // Autoclick
-              $newmarker['autoclick'] = true;
-            }
-            $thismap['markers'][] = $newmarker;
-          }
-        }
-        break;
-    }
+}
+
+/**
+ * For OG nodes, we are passing a nid/uid pair.
+ */
+function theme_og_gmapnodelabel($node, $opt) {
+  if (is_numeric($opt) && $account = user_load(array('uid' => $opt))) {
+    $output = theme('user_picture', $account);
+    $output .= theme('username', $account);
+    echo $output;
+    exit();
   }
-  return $thismap;
+}
+
+/**
+ * Theme function for displaying the node page.
+ */
+function theme_gmap_location_node_page($count, $header, $map, $footer) {
+  $output = "<p>$header</p>\n<p>$map</p>\n<p>$footer</p>";
+  return $output;
 }
 
 /**
  * Admin Settings Page
- *
  */
 function gmap_location_admin_settings() {
   $form['geocoding'] = array(
@@ -290,91 +350,131 @@
 
   $form['user'] = array(
     '#type' => 'fieldset',
-    '#title' => t('Location settings for users'),
-  );
-  $form['user']['gmap_user'] = array(
-    '#type' => 'checkbox',
-    '#title' => t('Profile map'),
-    '#default_value' => variable_get('gmap_user', TRUE),
-    '#description' => t('Let users set/edit their location in their profile.'),
-  );
-  $form['user']['gmap_user_profile_category'] = array(
-    '#type' => 'textfield',
-    '#title' => t('Profile category title'),
-    '#default_value' => variable_get('gmap_user_profile_category', "Location map"),
-    '#size' => 50,
-    '#maxlength' => 50,
-    '#description' => t('Let users set/edit their location in their profile.'),
+    '#title' => t('User settings'),
   );
+
+  // gmap_user_map defaults
+  $temp = variable_get('gmap_user_map', array(
+    'macro' => '[gmap |id=usermap|center=40,0|zoom=3|width=100%|height=400px]',
+    'header' => 'This map illustrates the extent of users of this website. Each marker indicates a user that has entered their locations.',
+    'footer' => '',
+  ));
+
   $form['user']['gmap_user_map'] = array(
+    '#type' => 'fieldset',
+    '#title' => t('User Map (<em>map/users</em>)'),
+    '#tree' => TRUE,
+  );
+  $form['user']['gmap_user_map']['macro'] = array(
     '#type' => 'textfield',
-    '#title' => t('Default user map'),
-    '#default_value' => variable_get('gmap_user_map', '[gmap |id=usermap|center=40,0|zoom=3|width=100%|height=400px]'),
+    '#title' => t('Macro'),
+    '#default_value' => $temp['macro'],
     '#size' => 50,
     '#maxlength' => 500,
     '#description' => t('The gmap macro where the user information will be diplayed on.'),
   );
-  $form['user']['gmap_user_map_header'] = array(
+  $form['user']['gmap_user_map']['header'] = array(
     '#type' => 'textarea',
-    '#title' => t('Text at the top of the map/users page'),
-    '#default_value' => variable_get('gmap_user_map_header', t('This map illustrates the extent of users of this website. Each marker indicates a user that has entered their locations.')),
+    '#title' => t('Page header'),
+    '#description' => t('Text at the top of the user map.', array('@url' => url('map/users'))),
+    '#default_value' => $temp['header'],
     '#cols' => 50,
     '#rows' => 6,
   );
-  $form['user']['gmap_user_map_marker'] = array(
-    '#type' => 'gmap_markerchooser',
-    '#title' => t('Marker for users'),
-    '#default_value' => variable_get('gmap_user_map_marker', 'drupal'),
+  $form['user']['gmap_user_map']['footer'] = array(
+    '#type' => 'textarea',
+    '#title' => t('Page footer'),
+    '#description' => t('Text at the bottom of the user map.'),
+    '#default_value' => $temp['footer'],
+    '#cols' => 50,
+    '#rows' => 6,
   );
 
   // Option to use a different marker for each role
-  $form['user']['roles'] = array(
+  $form['user']['gmap_role_markers'] = array(
     '#type' => 'fieldset',
     '#title' => t('Markers per role'),
-    '#description' => t('Use a different marker to denote users in the following roles.'),
+    '#description' => t('Choose a marker to represent each user role on the user map. If a user belongs to multiple roles, the marker for the highest Role ID will be used.'),
+    '#tree' => TRUE,
   );
 
   // Retrieve and sort list of roles, sans anonymous user
   $roles = user_roles(TRUE);
-  asort($roles);
+  //asort($roles);
+
+  $defaults = variable_get('gmap_role_markers', array());
 
   // Create a selection box per role
   foreach ($roles as $rid => $role) {
-    $form['user']['roles']["gmap_role_map_marker_$rid"] = array(
+    $form['user']['gmap_role_markers'][$rid] = array(
       '#type' => 'gmap_markerchooser',
-      '#title' => $role,
-      '#default_value' => variable_get("gmap_role_map_marker_$rid", variable_get('gmap_user_map_marker', 'drupal')),
+      '#title' => t('%role (Role ID: %rid)', array('%role' => $role, '%rid' => $rid)),
+      '#default_value' => isset($defaults[$rid]) ? $defaults[$rid] : 'drupal',
     );
   }
 
   $form['node'] = array(
     '#type' => 'fieldset',
-    '#title' => t('Location settings for nodes'),
+    '#title' => t('Node settings'),
   );
+
+  // gmap_node_map defaults
+  $temp = variable_get('gmap_node_map', array(
+    'macro' => '[gmap |id=nodemap|center=40,0|zoom=3|width=100%|height=400px]',
+    'header' => 'This map illustrates the locations of the nodes on this website. Each marker indicates a node associated with a specific location.',
+    'footer' => '',
+  ));
+
   $form['node']['gmap_node_map'] = array(
+    '#type' => 'fieldset',
+    '#title' => t('Node Map (<em>map/nodes</em>)'),
+    '#tree' => TRUE,
+  );
+  $form['node']['gmap_node_map']['macro'] = array(
     '#type' => 'textfield',
-    '#title' => t('Default node map'),
-    '#default_value' => variable_get('gmap_node_map', '[gmap |id=nodemap|center=40,0|zoom=3|width=100%|height=400px]'),
+    '#title' => t('Macro'),
+    '#default_value' => $temp['macro'],
     '#size' => 50,
     '#maxlength' => 500,
-    '#description' => t('The gmap macro where the user information will be diplayed on.'),
+    '#description' => t('The gmap macro where the node information will be diplayed on.'),
+  );
+  $form['node']['gmap_node_map']['header'] = array(
+    '#type' => 'textarea',
+    '#title' => t('Page header'),
+    '#description' => t('Text at the top of the node map.'),
+    '#default_value' => $temp['header'],
+    '#cols' => 50,
+    '#rows' => 6,
   );
-  $form['node']['gmap_node_map_header'] = array(
+  $form['node']['gmap_node_map']['footer'] = array(
     '#type' => 'textarea',
-    '#title' => t('Text at the top of the map/nodes page'),
-    '#default_value' => variable_get('gmap_node_map_header', t('This map illustrates the locations of the nodes on this website. Each marker indicates a node associated with a specific location.')),
+    '#title' => t('Page footer'),
+    '#description' => t('Text at the bottom of the node map.'),
+    '#default_value' => $temp['footer'],
     '#cols' => 50,
     '#rows' => 6,
   );
 
-  $ntypes=node_get_types();
+  // Option to use a different marker for each content type.
+  $form['node']['gmap_node_markers'] = array(
+    '#type' => 'fieldset',
+    '#title' => t('Markers per content type'),
+    '#description' => t('Choose a marker to represent each type of content on the node map.'),
+    '#tree' => TRUE,
+  );
+
+  $ntypes = node_get_types();
+
+  $defaults = variable_get('gmap_node_markers', array());
+
   foreach ($ntypes as $key => $value) {
-    if (intval(variable_get('location_maxnum_'. $key, 0)) !== 0) {
-      $form['node']['gmap_node_marker_'. $key] = array(
-        '#type' => 'gmap_markerchooser',
-        '#title' => t('Marker for '. $value->name),
-        '#default_value' => variable_get('gmap_node_marker_'. $key, ''),
-      );
+    $form['node']['gmap_node_markers'][$key] = array(
+      '#type' => 'gmap_markerchooser',
+      '#title' => t('Marker for '. $value->name),
+      '#default_value' => isset($defaults[$key]) ? $defaults[$key] : 'drupal',
+    );
+    if (intval(variable_get('location_maxnum_'. $key, 0)) === 0) {
+      $form['node']['gmap_node_markers'][$key]['#description'] = t('This content type is not currently Location enabled.');
     }
   }
   return system_settings_form($form);
@@ -578,170 +678,22 @@
   return $returntxt;
 }
 
-function gmap_location_user($op, &$edit, &$user, $category = NULL) {
-  if (variable_get('gmap_user', 0) && user_access('set user location')) {
-    switch ($op) {
-      case 'load':
-        $result = db_query("SELECT latitude,longitude FROM {location} WHERE eid = %d AND type='user'", $user->uid);
-        $u = db_fetch_object($result);
-        if ($u) {
-          $user->gmap_location_longitude = $u->longitude;
-          $user->gmap_location_latitude = $u->latitude;
-          $user->gmap_location_set = true;
-        }
-        break;
-      case 'categories':
-        return array(
-          array(
-            'name' => 'gmap_user',
-            'title' => variable_get('gmap_user_profile_category', t('location map')),
-            'weight' => 5,
-          ),
-        );
-
-      case 'insert':
-      case 'update':
-        if ($category == 'gmap_user') {
-          // source==1, location.module's LOCATION_LATLON_USER_SUBMITTED define.
-          // Insert or update based on the existance of $user->gmap_location_set.
-          if ($user->gmap_location_set) {
-            db_query("UPDATE {location} SET latitude = %s , longitude = %s , source = 1 WHERE eid = %d AND type = 'user'",
-              gmap_decimal($edit['gmap_location_latitude']),
-              gmap_decimal($edit['gmap_location_longitude']),
-              $user->uid);
-          }
-          else {
-            $lid = db_next_id('{location}_lid');
-            db_query("INSERT INTO {location} (eid, lid, type, latitude, longitude, source) VALUES (%d, %d, 'user', %s, %s, 1)",
-              $user->uid, $lid,
-              gmap_decimal($edit['gmap_location_latitude']),
-              gmap_decimal($edit['gmap_location_longitude']));
-          }
-          unset($edit['gmap_location_latitude']);
-          unset($edit['gmap_location_longitude']);
-        }
-        return;
-
-      case 'form':
-        if ($category == 'gmap_user' && user_access('set user location')) {
-          $form = array();
-
-          $form['coordinates'] = array(
-            '#type' => 'fieldset',
-            '#title' => t('Coordinates'),
-            '#weight' => 5,
-            '#collapsible' => $type!='user',
-            '#collapsed' => false,
-          );
-
-          // Reserve spot for map.
-          $form['coordinates']['gmap_node'] = array();
-
-          $form['coordinates']['gmap_location_latitude'] = array(
-            '#type' => 'textfield',
-            '#title' => t('Latitude'),
-            '#default_value' => $edit['gmap_location_latitude'],
-            '#size' => 30,
-            '#maxlength' => 120,
-          );
-
-          $form['coordinates']['gmap_location_longitude'] = array(
-            '#type' => 'textfield',
-            '#title' => t('Longitude'),
-            '#default_value' => $edit['gmap_location_longitude'],
-            '#size' => 30,
-            '#maxlength' => 120,
-            '#description' => t('The latitude and longitude will be entered here when you click on a location in the interactive map above. You can also fill in the values manually.'),
-          );
-
-          // @@@
-          $map_macro = variable_get('gmap_user_map', '[gmap |id=usermap |center=0,30 |zoom=16 |width=100% |height=400px]');
-
-          $form['coordinates']['gmap_node']['#value'] = gmap_set_location($map_macro, $form['coordinates'], array('latitude' => 'gmap_location_latitude', 'longitude' => 'gmap_location_longitude'));
-
-/*
-          if (variable_get('gmap_geocode', 1)) {
-            $form['coordinates']['gmap_location_address'] = array(
-              '#type' => 'textfield',
-              '#title' => t('Address'),
-              '#description' => t('The address to be found on the map.  Enter an address and then hit "TAB" and the current location will be updated.  Please note that this address is not saved for the node, it is only used for finding a location.'),
-            );
-          }
-*/
-        }
-        return $form;
-    }
-  }
-}
-
-/*
-function gmap_location_nodeapi(&$node, $op, $teaser = NULL, $page = NULL) {
-  if(variable_get('gmap_node_'. $node->type, 0)) {
-    $object->gmap_location_latitude = $node->gmap_location_latitude;
-    $object->gmap_location_longitude = $node->gmap_location_longitude;
-    $object->eid = $node->vid;
-
-    switch ($op) {
-    case 'load':
-      $res=db_query("SELECT * FROM {location} WHERE eid=%d AND type='node'",$node->vid);
-      if ($gmap_node=db_fetch_array($res)) {
-        if ($gmap_node['latitude'] !=0) $node->gmap_location_latitude= $gmap_node['latitude'];
-        if ($gmap_node['longitude']!=0) $node->gmap_location_longitude=$gmap_node['longitude'];
-        $node->gmap_location_set=true;
-      }
-      return;
-
-    case 'validate':
-      _gmap_location_validate_form($object);
-      return;
-
+/**
+ * Implementation of hook_node_type().
+ */
+function gmap_location_node_type($op, $info) {
+  $temp = variable_get('gmap_node_markers', array());
+  switch ($op) {
+    case 'delete':
+      unset($temp[$info->type]);
+      break;
     case 'insert':
-      _gmap_location_store_location($object, 'node', false);
-      return;
-
+      $temp[$info->type] = 'drupal';
+      break;
     case 'update':
-      _gmap_location_store_location($object, 'node', isset($node->gmap_location_set));
-      return;
-
-    case 'delete':
-      db_query ("DELETE from {location} WHERE eid=%d AND type='node'", $node->vid);
-      return;
-
-    }
-  }
-}
-*/
-
-/*
-function _gmap_location_validate_form(&$object) {
-  if (isset($object->latitude)){
-    if (!is_numeric($object->latitude) || abs($object->latitude)>90) {
-      form_set_error('gmap_location_latitude', t('Latitude must be between -90 and 90'));
-    }
+      $temp[$info->type] = $temp[$info->old_type];
+      unset ($temp[$info->old_type]);
+      break;
   }
-  if (isset($object->longitude)){
-    if (!is_numeric($object->longitude) || abs($object->longitude)>180) {
-      form_set_error('gmap_location_longitude', t('Longitude must be between -180 and 180'));
-    }
-  }
-}
-*/
-
-function _gmap_location_store_location($object, $type, $update = false) {
-  if (isset($object->gmap_location_latitude) && isset($object->gmap_location_longitude)) {
-    if ($update) {
-      db_query("UPDATE {location} SET latitude='%f', longitude='%f', source='%d' WHERE eid='%d' AND type='%s'",
-        $object->gmap_location_latitude, $object->gmap_location_longitude, 1, $object->eid, $type);
-
-    }
-    else {
-      $lid = db_next_id('{location}_lid');
-      // based on location.module LOCATION_LATLON_USER_SUBMITTED=1
-      db_query("INSERT INTO {location} (eid, lid, type, latitude, longitude, source) VALUES (%d, %d, '%s', '%f', '%f', '%d')",
-        $object->eid, $lid, $type, $object->gmap_location_latitude, $object->gmap_location_longitude, 1);
-    }
-    unset($object->gmap_location_latitude);
-    unset($object->gmap_location_longitude);
-    unset($object->gmap_location_set);
-  }
-}
+  variable_set('gmap_node_markers', $temp);
+}
\ No newline at end of file
Index: js/gmap_marker.js
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/gmap/js/Attic/gmap_marker.js,v
retrieving revision 1.1.2.21
diff -u -r1.1.2.21 gmap_marker.js
--- js/gmap_marker.js	3 Sep 2007 23:19:39 -0000	1.1.2.21
+++ js/gmap_marker.js	7 Sep 2007 19:04:42 -0000
@@ -66,6 +66,11 @@
     if (marker.text) {
       marker.marker.openInfoWindowHtml(marker.text);
     }
+    if (marker.rmt) {
+      $.get(obj.vars.rmtcallback + '/' + marker.rmt, {}, function(data){
+        marker.marker.openInfoWindowHtml(data);
+      });
+    }
     else if (marker.tabs) {
       var infoWinTabs = [];
       for (m in marker.tabs) {

