home *** CD-ROM | disk | FTP | other *** search
/ Cricao de Sites - 650 Layouts Prontos / WebMasters.iso / CMS / drupal-6.0.exe / drupal-6.0 / modules / profile / profile.pages.inc < prev   
Encoding:
Text File  |  2007-12-08  |  4.1 KB  |  121 lines

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