web/drupal/modules/profile/profile.pages.inc
author cavaliet@caf4f556-3d62-0410-8435-a86758001935
Fri, 21 Aug 2009 16:26:26 +0000
branchdrupal
changeset 74 0ff3ba646492
permissions -rw-r--r--
Create branch for drupal with first commit from local working copy
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
74
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
     1
<?php
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
     2
// $Id: profile.pages.inc,v 1.2 2007/12/08 14:06:22 goba Exp $
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
     3
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
     4
/**
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
     5
 * @file
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
     6
 * User page callbacks for the profile module.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
     7
 */
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
     8
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
     9
/**
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    10
 * Menu callback; display a list of user information.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    11
 */
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    12
function profile_browse() {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    13
  // Ensure that the path is converted to 3 levels always.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    14
  list(, $name, $value) = array_pad(explode('/', $_GET['q'], 3), 3, '');
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    15
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    16
  $field = db_fetch_object(db_query("SELECT DISTINCT(fid), type, title, page, visibility FROM {profile_fields} WHERE name = '%s'", $name));
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    17
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    18
  if ($name && $field->fid) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    19
    // Only allow browsing of fields that have a page title set.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    20
    if (empty($field->page)) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    21
      drupal_not_found();
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    22
      return;
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    23
    }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    24
    // Do not allow browsing of private and hidden fields by non-admins.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    25
    if (!user_access('administer users') && ($field->visibility == PROFILE_PRIVATE || $field->visibility == PROFILE_HIDDEN)) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    26
      drupal_access_denied();
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    27
      return;
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    28
    }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    29
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    30
    // Compile a list of fields to show.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    31
    $fields = array();
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    32
    $result = db_query('SELECT name, title, type, weight, page FROM {profile_fields} WHERE fid != %d AND visibility = %d ORDER BY weight', $field->fid, PROFILE_PUBLIC_LISTINGS);
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    33
    while ($record = db_fetch_object($result)) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    34
      $fields[] = $record;
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    35
    }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    36
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    37
    // Determine what query to use:
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    38
    $arguments = array($field->fid);
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    39
    switch ($field->type) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    40
      case 'checkbox':
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    41
        $query = 'v.value = 1';
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    42
        break;
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    43
      case 'textfield':
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    44
      case 'selection':
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    45
        $query = "v.value = '%s'";
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    46
        $arguments[] = $value;
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    47
        break;
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    48
      case 'list':
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    49
        $query = "v.value LIKE '%%%s%%'";
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    50
        $arguments[] = $value;
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    51
        break;
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    52
      default:
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    53
        drupal_not_found();
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    54
        return;
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    55
    }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    56
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    57
    // Extract the affected users:
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    58
    $result = pager_query("SELECT u.uid, u.access FROM {users} u INNER JOIN {profile_values} v ON u.uid = v.uid WHERE v.fid = %d AND $query AND u.access != 0 AND u.status != 0 ORDER BY u.access DESC", 20, 0, NULL, $arguments);
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    59
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    60
    $content = '';
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    61
    while ($account = db_fetch_object($result)) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    62
      $account = user_load(array('uid' => $account->uid));
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    63
      $profile = _profile_update_user_fields($fields, $account);
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    64
      $content .= theme('profile_listing', $account, $profile);
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    65
    }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    66
    $output = theme('profile_wrapper', $content);
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    67
    $output .= theme('pager', NULL, 20);
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    68
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    69
    if ($field->type == 'selection' || $field->type == 'list' || $field->type == 'textfield') {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    70
      $title = strtr(check_plain($field->page), array('%value' => theme('placeholder', $value)));
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    71
    }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    72
    else {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    73
      $title = check_plain($field->page);
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    74
    }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    75
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    76
    drupal_set_title($title);
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    77
    return $output;
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    78
  }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    79
  else if ($name && !$field->fid) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    80
    drupal_not_found();
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    81
  }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    82
  else {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    83
    // Compile a list of fields to show.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    84
    $fields = array();
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    85
    $result = db_query('SELECT name, title, type, weight, page FROM {profile_fields} WHERE visibility = %d ORDER BY category, weight', PROFILE_PUBLIC_LISTINGS);
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    86
    while ($record = db_fetch_object($result)) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    87
      $fields[] = $record;
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    88
    }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    89
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    90
    // Extract the affected users:
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    91
    $result = pager_query('SELECT uid, access FROM {users} WHERE uid > 0 AND status != 0 AND access != 0 ORDER BY access DESC', 20, 0, NULL);
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    92
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    93
    $content = '';
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    94
    while ($account = db_fetch_object($result)) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    95
      $account = user_load(array('uid' => $account->uid));
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    96
      $profile = _profile_update_user_fields($fields, $account);
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    97
      $content .= theme('profile_listing', $account, $profile);
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    98
    }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    99
    $output = theme('profile_wrapper', $content);
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   100
    $output .= theme('pager', NULL, 20);
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   101
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   102
    drupal_set_title(t('User list'));
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   103
    return $output;
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   104
  }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   105
}
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   106
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   107
/**
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   108
 * Callback to allow autocomplete of profile text fields.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   109
 */
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   110
function profile_autocomplete($field, $string) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   111
  $matches = array();
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   112
  if (db_result(db_query("SELECT COUNT(*) FROM {profile_fields} WHERE fid = %d AND autocomplete = 1", $field))) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   113
    $result = db_query_range("SELECT value FROM {profile_values} WHERE fid = %d AND LOWER(value) LIKE LOWER('%s%%') GROUP BY value ORDER BY value ASC", $field, $string, 0, 10);
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   114
    while ($data = db_fetch_object($result)) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   115
      $matches[$data->value] = check_plain($data->value);
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   116
    }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   117
  }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   118
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   119
  drupal_json($matches);
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   120
}