Check out the UpdateProfile snippet in the Login package.
$if ($_SESSION['password']=='something' {
$modx->setPlaceholder('session_user_id', $_SESSION['user_id'];
return "";
}
[[UpdateProfile? &user=`[[+session_user_id]]`]]
<?php
/**********************************************************************************************
* getUsers - gets MODx users
*
* tpl - chunk for output
* group - (optional) a group name
* limit - (optional) used by get page - defaults to 0
* offset - (optional) used by get page - defaults to 0
* totalVar - (optional) used by get page - defaults to 'total'
**********************************************************************************************/
$group = !empty($group) ? $group : '';
$tpl = !empty($tpl) ? $tpl : '';
$limit = !empty($limit) ? (int) $limit : 0;
$offset = !empty($offset) ? (int) $offset : 0;
$totalVar = !empty($totalVar) ? $totalVar : 'total';
$criteria = $modx->newQuery('modUser', array());
if (!empty($limit)) $criteria->limit($limit, $offset);
$users = $modx->getCollection('modUser', $criteria);
$output = '';
$i = 1;
foreach($users as $user) {
if (empty($group) || $user->isMember($group)) {
$p = $user->getOne('Profile');
$tpl_args = array();
$tpl_args['id'] = $user->get('id');
$tpl_args['username'] = $user->get('username');
if ($p) {
// this is all i needed - if you want more attributes check out the bottom of bob's objects page: http://www.bobsguides.com/revolution-objects.html
$tpl_args['fullname'] = $p->get('fullname');
$tpl_args['email'] = $p->get('email');
$tpl_args['logincount'] = $p->get('logincount');
}
// (optional) i like to do this in case my users show up in a drop down list, so i can pass on a selected value to the chunk
$tpl_args['selected'] = $selected;
// (optional) i use this in chunks for odd, last, etc
$tpl_args['idx'] = $i;
$output .= $modx->getChunk($tpl, $tpl_args);
++$i;
}
}
$modx->setPlaceholder($totalVar, $i);
return $output;
if (!$modx->user->hasSessionContext($modx->context->get('key'))) {if (!$modx->user->hasSessionContext($modx->context->get('key')) && $modx->user->isMember('Administrator')) {$profile = $modx->user->getOne('Profile');$user = $modx->getOne('modUser', $userID));
if(empty($user)) return '';
$profile = $user->getOne('Profile');$userID = !empty($userID) ? (int) $userID : 1;
The Profile snippet will take any user with the &user parameter. Unfortunately, UpdateProfile won’t (though it would be a good feature request).
Just thinking out loud, you could modify the UpdateProfile snippet to accept a &user parameter (and then submit that as an improvement). You could create a page with a form to select the user. On repost, if the user was found, you could set a $_SESSION variable with the user ID and forward to the page with UpdateProfile on it. On that page, you could have a snippet at the top that set a placeholder from the $_SESSION variable for use in the &user parameter. You’d probably also want to set another $_SESSION variable with a password for security to be checked in the snippet.
$if ($_SESSION['password']=='something' { $modx->setPlaceholder('session_user_id', $_SESSION['user_id']; return ""; }
[[UpdateProfile? &user=`[[+session_user_id]]`]]
Mind you, I haven’t looked at the UpdateProfile snippet to see how easy it would be to add the &user parameter, but in theory, it shouldn’t be too hard to see if $scriptProperties[’user’] is not empty, and if so, use it instead of $modx->user.
Just to elaborate on Bob’s idea a bit, to list members I use the following really simple snippet that works with getPage, if you have lots of users:
<?php /********************************************************************************************** * getUsers - gets MODx users * * tpl - chunk for output * group - (optional) a group name * limit - (optional) used by get page - defaults to 0 * offset - (optional) used by get page - defaults to 0 * totalVar - (optional) used by get page - defaults to 'total' **********************************************************************************************/ $group = !empty($group) ? $group : ''; $tpl = !empty($tpl) ? $tpl : ''; $limit = !empty($limit) ? (int) $limit : 0; $offset = !empty($offset) ? (int) $offset : 0; $totalVar = !empty($totalVar) ? $totalVar : 'total'; $criteria = $modx->newQuery('modUser', array()); if (!empty($limit)) $criteria->limit($limit, $offset); $users = $modx->getCollection('modUser', $criteria); $output = ''; $i = 1; foreach($users as $user) { if (empty($group) || $user->isMember($group)) { $p = $user->getOne('Profile'); $tpl_args = array(); $tpl_args['id'] = $user->get('id'); $tpl_args['username'] = $user->get('username'); if ($p) { // this is all i needed - if you want more attributes check out the bottom of bob's objects page: http://www.bobsguides.com/revolution-objects.html $tpl_args['fullname'] = $p->get('fullname'); $tpl_args['email'] = $p->get('email'); $tpl_args['logincount'] = $p->get('logincount'); } // (optional) i like to do this in case my users show up in a drop down list, so i can pass on a selected value to the chunk $tpl_args['selected'] = $selected; // (optional) i use this in chunks for odd, last, etc $tpl_args['idx'] = $i; $output .= $modx->getChunk($tpl, $tpl_args); ++$i; } } $modx->setPlaceholder($totalVar, $i); return $output;
Then to update users, you can modify the UpdateProfile snippet that comes with login really easily. I’d make a copy of it with a new name, just so you can still update the Login package.
Change line 43 from this:
if (!$modx->user->hasSessionContext($modx->context->get('key'))) {
To this:
if (!$modx->user->hasSessionContext($modx->context->get('key')) && $modx->user->isMember('Administrator')) {
Just to make sure you aren’t letting anybody update your users, only administrators.
Next change line 52 from this:
$profile = $modx->user->getOne('Profile');
To this:
$user = $modx->getOne('modUser', $userID)); if(empty($user)) return ''; $profile = $user->getOne('Profile');
The $userID will have to be passed to the UpdateProfile snippet, so you may want to throw a line at the top validating it a bit:
$userID = !empty($userID) ? (int) $userID : 1;
Then I’d just send the user ID to the editing page with a GET, and pass that argument on to the snippet. I can’t honestly say I’ve tried the update profile changes before, but it looks pretty straightforward.
Quote from: swespi at Apr 03, 2011, 12:09 PMThe $userID will have to be passed to the UpdateProfile snippet, so you may want to throw a line at the top validating it a bit:
$userID = !empty($userID) ? (int) $userID : 1;
Then I’d just send the user ID to the editing page with a GET, and pass that argument on to the snippet. I can’t honestly say I’ve tried the update profile changes before, but it looks pretty straightforward.
$userID = !empty($userID) ? (int) $userID : 1;

<?php return $_GET[$q];
[[!UpdateProfile? &userID=`[[!get? &q=`userid`]]`]]
<form action="[[~[update profile page id]]]" method="get"> <select name="userid">[[!getUsers]]</select> <input type="submit" value="Edit User" /> </form>