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