By polar-bear on
I would like to create pages containing lists of all the registered users.
These pages should be only viewable by authenicated users or users in a certain roles group.
How can I do this?
Thank you.
I would like to create pages containing lists of all the registered users.
These pages should be only viewable by authenicated users or users in a certain roles group.
How can I do this?
Thank you.
Comments
Just to get you started
Create a page using the "PHP code" input format. Then use something like this (it's just a sample to get you started)
Replace role name
In the above snippet, make sure to replace 'role name' with an array of user roles that are allowed to view the page. Also note that you should probably also restrict this item in a menu system from showing up to anonymous users. Otherwise they will get the access denied page from a menu item link, which is not the most elegant solution.
I am currently experimenting with a table based user list. This table assumes you have a real name and a country field added to the profiles. Also note that this code is not checking permissions, you can write it in from the above example. In my case everybody can look through the user list. However, depending on your access settings it determines whether or not a link to the user profiles is made, or if simply a plain text is shown with the username.
This code was altered from the last example on this page. I'm still trying to figure out how to replace the sortable headers with static headers (unsortable list) though.
A little more help
If you don't want any sortable headers just remove the $sql .= tablesort_sql($header); and don't include any 'field' definitions in the $header array. If you want to just sort by, say for example, "Real name" remove the 'field' definitions from the other array elements and leave array('data' => t('Real name'), 'field' => 'u.realname'), as is (and keep the $sql .= tablesort_sql($header); in).
Ah, splendid!
Works like a charm, thanks!
I am having problem with sorting with field in profile
Sorting with the u.name works fine but sorting with name in profile field does not work for me.
My code which is listed below generates an error.
Could someone offer me any advice on this, please?
Thank you.
Join
If you want to list/search by profile values you need to JOIN your {users} table......
Something like that. I suggest you look at the profile_fields and profile_values tables and see how they join with the users table (profile_values has a field called uid which joins that value to a user uid and fid that joins it to the profile_field table fid)
and I should point you to
and I should point you to the reason for your error also. You can't invent field names that don't exist.
'field' should hold the name of a field value that your SQL is going to return. What is u.name_us supposed to be? That isn't returned by your SQL. I'm guessing that you have a profile value called name_us. That being the case, you'll need to join as I explained and then use the correct col field name in your sort criteria (eg pf.name_us)
I just had a quick go at
I just had a quick go at doing this and realise it's more tricky than you think. The JOINed SQL I show above will return multiple rows per user (one row for each profile value). The code you show goes on to use user_load() to get the details. The problem is this, in order to use tablesort_sql() to produce a sortable table you need to make sure your SQL produces one row per table row (and not bother with the user_load() at all).
So, a straight table of users is fine but if you want a sortable list, you're going to have to sit down and design what you want rather than hacking away at a snippet. Tricky stuff ;) Possible but you need to think it through carefully. Sorry, I don't have the time to do it myself now, I have too many things on my plate ;)
What it boils down to is this. When using tablesort_sql() with theme('table') there should be a one to one relationship with SQL rows returned and table rows displayed. In order to get one row you can build the row with some array stuff. I just tried that and it "sort of" worked. The problem is you then need to make sure your profile values are always in the same order. But you can't do this as tablesort_sql() will alter them depending upon which col you are sorting on. Basically, I think you can create what you want but I don't think you'll be able to sort by profile value quite so easily (if at all).
Small addition
Please note where the sql statement says "WHERE uid != 0 AND uid != 6". This prevents user accounts 0 (anonymous) and 6 (in my case a special admin account) from showing up in the list. Omitting the "AND uid != 6" should be used if you only want to surpress the anonymous user.
how could i modify this code
how could i modify this code to just display the current users avatar?
addressbook
I picked up the code here some days ago and struggled with the sorting issue too. Then I saw that the views module can sort on profile.module fields, so I checked the code. And finally with some help from gnari at #mysql@irc.freenode.net I managed to get it to work!
Personally I needed an 'address book'. A list of users searchable on fields which were added by profile.module (then still sortable). So the code does just that :)
I didn't turn it into a module, because I don't have the time. Should someone be able to pick it up from here please do! I tried to make the code as flexible as I could, so I believe that turning it into a module shouldn't be that hard.
To 'configure' the script, just change the arrays $columns and $search_buttons at the top to specify what columns you want to show and be able to search on.
What's not (yet - hint hint ;)) configurable is the restriction to the search criteria I have added to force it to be no less than 2 character; and the WHERE clause that excludes the first 3 users + the blocked onces from the search.
Sorry about the inline javascript, but that's also because of the lack of time...
Several classnames and IDs are used, so the script is themeable. Some example CSS :
The icon used for the reset button can be found at http://www.saulmade.nl/forum/addressbook_reset.png or as a gif blended on a white bg http://www.saulmade.nl/forum/addressbook_reset.gif .
Paul
forgot t() with profile link and used account as object
I forgot to wrap the profile link in t() and I worked with account as it was fetched as an object (changed that later on to array). Also the unset need to come after using uid...
Change :
into
and of course the permisson
and of course the permisson check, if you want it, should go before the form:
should be moved to before
$addressbook_search = (!isset($_POST['addressbook_search']['reset']) ? $_REQUEST['addressbook_search'] : '');query
The query, by the way, will result in this code when using the setting (arrays) I posted above:
with the braked last line being added when you search on location (Dutch:'Plaatsnaam') 'Bruss' for 'Brussels' for example...