2007-11-13 12:28:36 +00:00
< ? php
// $Id$
/**
* @ file
* User page callbacks for the profile module .
*/
/**
* Menu callback ; display a list of user information .
*/
function profile_browse () {
// Ensure that the path is converted to 3 levels always.
list (, $name , $value ) = array_pad ( explode ( '/' , $_GET [ 'q' ], 3 ), 3 , '' );
2008-12-05 12:50:28 +00:00
$field = db_fetch_object ( db_query ( " SELECT DISTINCT(fid), type, title, page, visibility FROM { profile_field} WHERE name = '%s' " , $name ));
2007-11-13 12:28:36 +00:00
if ( $name && $field -> fid ) {
// Only allow browsing of fields that have a page title set.
if ( empty ( $field -> page )) {
drupal_not_found ();
return ;
}
// Do not allow browsing of private and hidden fields by non-admins.
if ( ! user_access ( 'administer users' ) && ( $field -> visibility == PROFILE_PRIVATE || $field -> visibility == PROFILE_HIDDEN )) {
2007-12-08 14:06:23 +00:00
drupal_access_denied ();
return ;
2007-11-13 12:28:36 +00:00
}
// Compile a list of fields to show.
$fields = array ();
2008-12-05 12:50:28 +00:00
$result = db_query ( 'SELECT name, title, type, weight, page FROM {profile_field} WHERE fid != %d AND visibility = %d ORDER BY weight' , $field -> fid , PROFILE_PUBLIC_LISTINGS );
2007-11-13 12:28:36 +00:00
while ( $record = db_fetch_object ( $result )) {
$fields [] = $record ;
}
// Determine what query to use:
$arguments = array ( $field -> fid );
switch ( $field -> type ) {
case 'checkbox' :
$query = 'v.value = 1' ;
break ;
case 'textfield' :
case 'selection' :
$query = " v.value = '%s' " ;
$arguments [] = $value ;
break ;
case 'list' :
$query = " v.value LIKE '%%%s%%' " ;
$arguments [] = $value ;
break ;
default :
drupal_not_found ();
return ;
}
// Extract the affected users:
2009-03-14 23:01:38 +00:00
$result = pager_query ( " SELECT u.uid, u.access FROM { users} u INNER JOIN { profile_value} 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 ) -> fetchAllAssoc ( 'uid' );
// Load the users.
$users = user_load_multiple ( array_keys ( $result ));
2007-11-13 12:28:36 +00:00
$content = '' ;
2009-03-14 23:01:38 +00:00
foreach ( $users as $account ) {
2007-11-13 12:28:36 +00:00
$profile = _profile_update_user_fields ( $fields , $account );
$content .= theme ( 'profile_listing' , $account , $profile );
}
$output = theme ( 'profile_wrapper' , $content );
2009-04-26 19:44:40 +00:00
$output .= theme ( 'pager' , NULL );
2007-11-13 12:28:36 +00:00
if ( $field -> type == 'selection' || $field -> type == 'list' || $field -> type == 'textfield' ) {
$title = strtr ( check_plain ( $field -> page ), array ( '%value' => theme ( 'placeholder' , $value )));
}
else {
$title = check_plain ( $field -> page );
}
2008-10-13 00:33:05 +00:00
drupal_set_title ( $title , PASS_THROUGH );
2007-11-13 12:28:36 +00:00
return $output ;
}
2008-10-12 04:30:09 +00:00
elseif ( $name && ! $field -> fid ) {
2007-11-13 12:28:36 +00:00
drupal_not_found ();
}
else {
// Compile a list of fields to show.
$fields = array ();
2008-12-05 12:50:28 +00:00
$result = db_query ( 'SELECT name, title, type, weight, page, visibility FROM {profile_field} WHERE visibility = %d ORDER BY category, weight' , PROFILE_PUBLIC_LISTINGS );
2007-11-13 12:28:36 +00:00
while ( $record = db_fetch_object ( $result )) {
$fields [] = $record ;
}
// Extract the affected users:
2009-03-14 23:01:38 +00:00
$result = pager_query ( 'SELECT uid, access FROM {users} WHERE uid > 0 AND status != 0 AND access != 0 ORDER BY access DESC' , 20 , 0 , NULL ) -> fetchAllAssoc ( 'uid' );
$users = user_load_multiple ( array_keys ( $result ));
2007-11-13 12:28:36 +00:00
$content = '' ;
2009-03-14 23:01:38 +00:00
foreach ( $users as $account ) {
2007-11-13 12:28:36 +00:00
$profile = _profile_update_user_fields ( $fields , $account );
$content .= theme ( 'profile_listing' , $account , $profile );
}
$output = theme ( 'profile_wrapper' , $content );
2009-04-26 19:44:40 +00:00
$output .= theme ( 'pager' , NULL );
2007-11-13 12:28:36 +00:00
2008-10-13 00:33:05 +00:00
drupal_set_title ( t ( 'User list' ), PASS_THROUGH );
2007-11-13 12:28:36 +00:00
return $output ;
}
}
/**
* Callback to allow autocomplete of profile text fields .
*/
function profile_autocomplete ( $field , $string ) {
$matches = array ();
2008-12-05 12:50:28 +00:00
if ( db_result ( db_query ( " SELECT COUNT(*) FROM { profile_field} WHERE fid = %d AND autocomplete = 1 " , $field ))) {
$result = db_query_range ( " SELECT value FROM { profile_value} WHERE fid = :fid AND LOWER(value) LIKE LOWER(:value) GROUP BY value ORDER BY value ASC " , array (
2008-09-15 20:48:10 +00:00
':fid' => $field ,
2008-08-21 19:36:39 +00:00
':value' => $string . '%' ,
), 0 , 10 );
2007-11-13 12:28:36 +00:00
while ( $data = db_fetch_object ( $result )) {
$matches [ $data -> value ] = check_plain ( $data -> value );
}
}
drupal_json ( $matches );
}