You are here

function gmap_location_user in GMap Module 5

File

./gmap_location.module, line 878
GMap Location module is a module to add some gmap funcationality based on location.modules information.

Code

function gmap_location_user($op, &$edit, &$user, $category = NULL) {
  if (function_exists('location_newapi')) {

    // Location 3.x handles the whole process.
    return;
  }
  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.'),
          );

          // @@@ Why is this based off the user map?
          $tmp = variable_get('gmap_user_map', _gmap_location_user_map_defaults());
          $form['coordinates']['gmap_node']['#value'] = gmap_set_location($tmp['macro'], $form['coordinates'], array(
            'latitude' => 'gmap_location_latitude',
            'longitude' => 'gmap_location_longitude',
          ));
        }
        return $form;
    }
  }
}