Code coverage for /20081101/modules/profile/profile.pages.inc

Line #Times calledCode
1
<?php
2
// $Id: profile.pages.inc,v 1.8 2008/10/13 00:33:04 webchick Exp $
3
4
/**
5
 * @file
6
 * User page callbacks for the profile module.
7
 */
8
9
/**
10
 * Menu callback; display a list of user information.
11
 */
122
function profile_browse() {
13
  // Ensure that the path is converted to 3 levels always.
140
  list(, $name, $value) = array_pad(explode('/', $_GET['q'], 3), 3, '');
15
160
  $field = db_fetch_object(db_query("SELECT DISTINCT(fid), type, title,
page, visibility FROM {profile_fields} WHERE name = '%s'", $name));
17
180
  if ($name && $field->fid) {
19
    // Only allow browsing of fields that have a page title set.
200
    if (empty($field->page)) {
210
      drupal_not_found();
220
      return;
230
    }
24
    // Do not allow browsing of private and hidden fields by non-admins.
250
    if (!user_access('administer users') && ($field->visibility ==
PROFILE_PRIVATE || $field->visibility == PROFILE_HIDDEN)) {
260
      drupal_access_denied();
270
      return;
280
    }
29
30
    // Compile a list of fields to show.
310
    $fields = array();
320
    $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);
330
    while ($record = db_fetch_object($result)) {
340
      $fields[] = $record;
350
    }
36
37
    // Determine what query to use:
380
    $arguments = array($field->fid);
390
    switch ($field->type) {
400
      case 'checkbox':
410
        $query = 'v.value = 1';
420
        break;
430
      case 'textfield':
440
      case 'selection':
450
        $query = "v.value = '%s'";
460
        $arguments[] = $value;
470
        break;
480
      case 'list':
490
        $query = "v.value LIKE '%%%s%%'";
500
        $arguments[] = $value;
510
        break;
520
      default:
530
        drupal_not_found();
540
        return;
550
    }
56
57
    // Extract the affected users:
580
    $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);
59
600
    $content = '';
610
    while ($account = db_fetch_object($result)) {
620
      $account = user_load(array('uid' => $account->uid));
630
      $profile = _profile_update_user_fields($fields, $account);
640
      $content .= theme('profile_listing', $account, $profile);
650
    }
660
    $output = theme('profile_wrapper', $content);
670
    $output .= theme('pager', NULL, 20);
68
690
    if ($field->type == 'selection' || $field->type == 'list' ||
$field->type == 'textfield') {
700
      $title = strtr(check_plain($field->page), array('%value' =>
theme('placeholder', $value)));
710
    }
72
    else {
730
      $title = check_plain($field->page);
74
    }
75
760
    drupal_set_title($title, PASS_THROUGH);
770
    return $output;
780
  }
790
  elseif ($name && !$field->fid) {
800
    drupal_not_found();
810
  }
82
  else {
83
    // Compile a list of fields to show.
840
    $fields = array();
850
    $result = db_query('SELECT name, title, type, weight, page FROM
{profile_fields} WHERE visibility = %d ORDER BY category, weight',
PROFILE_PUBLIC_LISTINGS);
860
    while ($record = db_fetch_object($result)) {
870
      $fields[] = $record;
880
    }
89
90
    // Extract the affected users:
910
    $result = pager_query('SELECT uid, access FROM {users} WHERE uid > 0
AND status != 0 AND access != 0 ORDER BY access DESC', 20, 0, NULL);
92
930
    $content = '';
940
    while ($account = db_fetch_object($result)) {
950
      $account = user_load(array('uid' => $account->uid));
960
      $profile = _profile_update_user_fields($fields, $account);
970
      $content .= theme('profile_listing', $account, $profile);
980
    }
990
    $output = theme('profile_wrapper', $content);
1000
    $output .= theme('pager', NULL, 20);
101
1020
    drupal_set_title(t('User list'), PASS_THROUGH);
1030
    return $output;
104
  }
1050
}
106
107
/**
108
 * Callback to allow autocomplete of profile text fields.
109
 */
1102
function profile_autocomplete($field, $string) {
1111
  $matches = array();
1121
  if (db_result(db_query("SELECT COUNT(*) FROM {profile_fields} WHERE fid =
%d AND autocomplete = 1", $field))) {
1131
    $result = db_query_range("SELECT value FROM {profile_values} WHERE fid
= :fid AND LOWER(value) LIKE LOWER(:value) GROUP BY value ORDER BY value
ASC", array(
1141
      ':fid' => $field,
1151
      ':value' => $string .'%',
1161
    ), 0, 10);
1171
    while ($data = db_fetch_object($result)) {
1181
      $matches[$data->value] = check_plain($data->value);
1191
    }
1201
  }
121
1221
  drupal_json($matches);
1231
}
1242