Same name and namespace in other branches
  1. 4.7.x modules/profile.module \profile_browse()
  2. 5.x modules/profile/profile.module \profile_browse()
  3. 6.x modules/profile/profile.pages.inc \profile_browse()
  4. 7.x modules/profile/profile.pages.inc \profile_browse()

Menu callback; display a list of user information.

1 string reference to 'profile_browse'
profile_menu in modules/profile.module
Implementation of hook_menu().

File

modules/profile.module, line 62
Support for configurable user profiles.

Code

function profile_browse() {
  $name = arg(1);
  $value = arg(2);
  $field = db_fetch_object(db_query("SELECT DISTINCT(fid), type, title, page, visibility FROM {profile_fields} WHERE name = '%s'", $name));
  if ($name && $field->fid) {

    // Do not allow browsing of private fields by non-admins
    if (!user_access('administer users') && $field->visibility == PROFILE_PRIVATE) {
      drupal_access_denied();
      return;
    }

    // Compile a list of fields to show
    $fields = array();
    $result = db_query('SELECT name, title, type, weight FROM {profile_fields} WHERE fid != %d AND visibility = %d ORDER BY weight', $field->fid, PROFILE_PUBLIC_LISTINGS);
    while ($record = db_fetch_object($result)) {
      $fields[] = $record;
    }

    // Determine what query to use:
    $arguments = array(
      $field->fid,
    );
    switch ($field->type) {
      case 'checkbox':
        $query = 'v.value = 1';
        break;
      case 'selection':
        $query = "v.value = '%s'";
        $arguments[] = $value;
        break;
      case 'list':
        $query = "v.value LIKE '%%%s%%'";
        $arguments[] = $value;
        break;
      default:
        drupal_not_found();
        return;
    }

    // Extract the affected users:
    $result = pager_query("SELECT u.uid, u.changed FROM {users} u INNER JOIN {profile_values} v ON u.uid = v.uid WHERE v.fid = %d AND {$query} ORDER BY u.changed DESC", 20, 0, NULL, $arguments);
    $output = '<div id="profile">';
    while ($account = db_fetch_object($result)) {
      $output .= theme('profile_profile', user_load(array(
        'uid' => $account->uid,
      )), $fields);
    }
    $output .= theme('pager', NULL, 20);
    if ($field->type == 'selection' || $field->type == 'list') {
      $title = strtr($field->page, array(
        '%value' => theme('placeholder', $value),
      ));
    }
    else {
      $title = $field->page;
    }
    $output .= '</div>';
    drupal_set_title(check_plain($title));
    print theme('page', $output);
  }
  else {
    if ($name && !$field->id) {
      drupal_not_found();
    }
    else {

      // Compile a list of fields to show
      $fields = array();
      $result = db_query('SELECT name, title, type, weight FROM {profile_fields} WHERE visibility = %d ORDER BY weight', PROFILE_PUBLIC_LISTINGS);
      while ($record = db_fetch_object($result)) {
        $fields[] = $record;
      }

      // Extract the affected users:
      $result = pager_query("SELECT uid, changed FROM {users} WHERE uid > 0 ORDER BY changed DESC", 20, 0, NULL);
      $output = '<div id="profile">';
      while ($account = db_fetch_object($result)) {
        $output .= theme('profile_profile', user_load(array(
          'uid' => $account->uid,
        )), $fields);
      }
      $output .= '</div>';
      $output .= theme('pager', NULL, 20);
      drupal_set_title(t('user list'));
      print theme('page', $output);
    }
  }
}