00001 <?php
00002
00003
00012 function profile_browse() {
00013
00014 list(, $name, $value) = array_pad(explode('/', $_GET['q'], 3), 3, '');
00015
00016 $field = db_fetch_object(db_query("SELECT DISTINCT(fid), type, title, page, visibility FROM {profile_fields} WHERE name = '%s'", $name));
00017
00018 if ($name && $field->fid) {
00019
00020 if (empty($field->page)) {
00021 drupal_not_found();
00022 return;
00023 }
00024
00025 if (!user_access('administer users') && ($field->visibility == PROFILE_PRIVATE || $field->visibility == PROFILE_HIDDEN)) {
00026 drupal_access_denied();
00027 return;
00028 }
00029
00030
00031 $fields = array();
00032 $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);
00033 while ($record = db_fetch_object($result)) {
00034 $fields[] = $record;
00035 }
00036
00037
00038 $arguments = array($field->fid);
00039 switch ($field->type) {
00040 case 'checkbox':
00041 $query = 'v.value = 1';
00042 break;
00043 case 'textfield':
00044 case 'selection':
00045 $query = "v.value = '%s'";
00046 $arguments[] = $value;
00047 break;
00048 case 'list':
00049 $query = "v.value LIKE '%%%s%%'";
00050 $arguments[] = $value;
00051 break;
00052 default:
00053 drupal_not_found();
00054 return;
00055 }
00056
00057
00058 $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);
00059
00060 $content = '';
00061 while ($account = db_fetch_object($result)) {
00062 $account = user_load(array('uid' => $account->uid));
00063 $profile = _profile_update_user_fields($fields, $account);
00064 $content .= theme('profile_listing', $account, $profile);
00065 }
00066 $output = theme('profile_wrapper', $content);
00067 $output .= theme('pager', NULL, 20);
00068
00069 if ($field->type == 'selection' || $field->type == 'list' || $field->type == 'textfield') {
00070 $title = strtr(check_plain($field->page), array('%value' => theme('placeholder', $value)));
00071 }
00072 else {
00073 $title = check_plain($field->page);
00074 }
00075
00076 drupal_set_title($title);
00077 return $output;
00078 }
00079 else if ($name && !$field->fid) {
00080 drupal_not_found();
00081 }
00082 else {
00083
00084 $fields = array();
00085 $result = db_query('SELECT name, title, type, weight, page FROM {profile_fields} WHERE visibility = %d ORDER BY category, weight', PROFILE_PUBLIC_LISTINGS);
00086 while ($record = db_fetch_object($result)) {
00087 $fields[] = $record;
00088 }
00089
00090
00091 $result = pager_query('SELECT uid, access FROM {users} WHERE uid > 0 AND status != 0 AND access != 0 ORDER BY access DESC', 20, 0, NULL);
00092
00093 $content = '';
00094 while ($account = db_fetch_object($result)) {
00095 $account = user_load(array('uid' => $account->uid));
00096 $profile = _profile_update_user_fields($fields, $account);
00097 $content .= theme('profile_listing', $account, $profile);
00098 }
00099 $output = theme('profile_wrapper', $content);
00100 $output .= theme('pager', NULL, 20);
00101
00102 drupal_set_title(t('User list'));
00103 return $output;
00104 }
00105 }
00106
00110 function profile_autocomplete($field, $string) {
00111 $matches = array();
00112 if (db_result(db_query("SELECT COUNT(*) FROM {profile_fields} WHERE fid = %d AND autocomplete = 1", $field))) {
00113 $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);
00114 while ($data = db_fetch_object($result)) {
00115 $matches[$data->value] = check_plain($data->value);
00116 }
00117 }
00118
00119 drupal_json($matches);
00120 }