source: sipes/cord/modules/profile/profile.pages.inc @ 8a8efa8

stableversion-3.0
Last change on this file since 8a8efa8 was b354002, checked in by José Gregorio Puentes <jpuentes@…>, 8 años ago

se agrego el directorio del cord

  • Propiedad mode establecida a 100755
File size: 4.0 KB
Línea 
1<?php
2
3/**
4 * @file
5 * User page callbacks for the profile module.
6 */
7
8/**
9 * Menu callback; display a list of user information.
10 */
11function profile_browse() {
12  // Ensure that the path is converted to 3 levels always.
13  list(, $name, $value) = array_pad(explode('/', $_GET['q'], 3), 3, '');
14
15  $field = db_fetch_object(db_query("SELECT DISTINCT(fid), type, title, page, visibility FROM {profile_fields} WHERE name = '%s'", $name));
16
17  if ($name && $field->fid) {
18    // Only allow browsing of fields that have a page title set.
19    if (empty($field->page)) {
20      drupal_not_found();
21      return;
22    }
23    // Do not allow browsing of private and hidden fields by non-admins.
24    if (!user_access('administer users') && ($field->visibility == PROFILE_PRIVATE || $field->visibility == PROFILE_HIDDEN)) {
25      drupal_access_denied();
26      return;
27    }
28
29    // Compile a list of fields to show.
30    $fields = array();
31    $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);
32    while ($record = db_fetch_object($result)) {
33      $fields[] = $record;
34    }
35
36    // Determine what query to use:
37    $arguments = array($field->fid);
38    switch ($field->type) {
39      case 'checkbox':
40        $query = 'v.value = 1';
41        break;
42      case 'textfield':
43      case 'selection':
44        $query = "v.value = '%s'";
45        $arguments[] = $value;
46        break;
47      case 'list':
48        $query = "v.value LIKE '%%%s%%'";
49        $arguments[] = $value;
50        break;
51      default:
52        drupal_not_found();
53        return;
54    }
55
56    // Extract the affected users:
57    $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);
58
59    $content = '';
60    while ($account = db_fetch_object($result)) {
61      $account = user_load(array('uid' => $account->uid));
62      $profile = _profile_update_user_fields($fields, $account);
63      $content .= theme('profile_listing', $account, $profile);
64    }
65    $output = theme('profile_wrapper', $content);
66    $output .= theme('pager', NULL, 20);
67
68    if ($field->type == 'selection' || $field->type == 'list' || $field->type == 'textfield') {
69      $title = strtr(check_plain($field->page), array('%value' => theme('placeholder', $value)));
70    }
71    else {
72      $title = check_plain($field->page);
73    }
74
75    drupal_set_title($title);
76    return $output;
77  }
78  else if ($name && !$field->fid) {
79    drupal_not_found();
80  }
81  else {
82    // Compile a list of fields to show.
83    $fields = array();
84    $result = db_query('SELECT name, title, type, weight, page FROM {profile_fields} WHERE visibility = %d ORDER BY category, weight', PROFILE_PUBLIC_LISTINGS);
85    while ($record = db_fetch_object($result)) {
86      $fields[] = $record;
87    }
88
89    // Extract the affected users:
90    $result = pager_query('SELECT uid, access FROM {users} WHERE uid > 0 AND status != 0 AND access != 0 ORDER BY access DESC', 20, 0, NULL);
91
92    $content = '';
93    while ($account = db_fetch_object($result)) {
94      $account = user_load(array('uid' => $account->uid));
95      $profile = _profile_update_user_fields($fields, $account);
96      $content .= theme('profile_listing', $account, $profile);
97    }
98    $output = theme('profile_wrapper', $content);
99    $output .= theme('pager', NULL, 20);
100
101    drupal_set_title(t('User list'));
102    return $output;
103  }
104}
105
106/**
107 * Callback to allow autocomplete of profile text fields.
108 */
109function profile_autocomplete($field, $string) {
110  $matches = array();
111  if (db_result(db_query("SELECT COUNT(*) FROM {profile_fields} WHERE fid = %d AND autocomplete = 1", $field))) {
112    $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);
113    while ($data = db_fetch_object($result)) {
114      $matches[$data->value] = check_plain($data->value);
115    }
116  }
117
118  drupal_json($matches);
119}
Nota: Vea TracBrowser para ayuda de uso del navegador del repositorio.