We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 25308
    • 46 Posts
    version: Modx Revolution 2.07
    Searver: Godaddy w/ apache and php5 (install and operation works fine)
    me: Experienced web designer but new to Modx

    Hi all,

    I have the login package installed and upon registration new users are put into a user group called "customers". I’m trying to find a way to list and edit user’s information from the user group "customers" in the front end as an admin. Is this possible? Everything I’ve read/heard seems to indicate that I’d have to make a custom manager form. I would really prefer the ability to access this without logging into the back-end but will do what is necessary to have the functionality.

    Any thoughts?
      • 3749
      • 24,544 Posts
      Check out the UpdateProfile snippet in the Login package.
        Did I help you? Buy me a beer
        Get my Book: MODX:The Official Guide
        MODX info for everyone: http://bobsguides.com/modx.html
        My MODX Extras
        Bob's Guides is now hosted at A2 MODX Hosting
        • 25308
        • 46 Posts
        Quote from: BobRay at Mar 31, 2011, 01:44 PM

        Check out the UpdateProfile snippet in the Login package.

        Hi Bob! First off thanks for the reply and for your blog. I’ve been there several times to find answers to questions. I really have found it helpful and appreciate it!

        I have seen the update profile snippet in the login package. I understood it as a way to update your own profile. There is a way to update other people’s profiles? That would be the answer I’m looking for.

        As the admin I would like to list the members of a user group "customers". Once I select the name I would like the ability to view and update their information that I’ve collected in my registration form. This is possible with the updateprofile snippet? CAn you point me in a direction to utilize this? Custom hooks maybe?

        I’ve been going in some small circles with this. I’ve thought about using the profile snippet to show the current user info, but again wasn’t sure how to make is so I could edit the info. Also know that the Usergroup snippet will show all the users of the group. I really tried to research as much as possible before posting here. No need to clog up the forum if I can find it with a little leg work.

        Any info or direction you can point in would be greatly appreciated. Thanks in advance!
          • 22019
          • 390 Posts
          You will need to write some custom functionality if you want user A (admin) to be able to update user B (Joe Schmoe) profile in the front end. UpdateProfile, as you’ve discovered is designed to service the logged-in user in the front end. In your case, you want to edit a ’non-logged-in’ user. Manage Users in the backend manager is designed to do the job you want.

          You could create a restricted access policy that didn’t have edit content rights but did have edit user rights (I think!) - if you didn’t want to give them full backend access.

          From your other thread on the Register snippet, you are also going to run into issues with the non-standard fields (extended user profile fields) in any front-end editing scenario.

          As you’ve already suggested, if you have to have front-end user editing, it would probably be better/simpler to go down a custom table route.


            Writer > E-consultant > MODx developer || Salesforce || modx 2.x || PHP 5.2.13 || MySQL client 5.0.86
            • 3749
            • 24,544 Posts
            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.
              Did I help you? Buy me a beer
              Get my Book: MODX:The Official Guide
              MODX info for everyone: http://bobsguides.com/modx.html
              My MODX Extras
              Bob's Guides is now hosted at A2 MODX Hosting
              • 29019 ☆ A M B ☆
              • 104 Posts
              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.

                www.darkstardesign.com

                Are you in the Nashville area? Join us for our next MODX meetup!
                • 25308
                • 46 Posts
                Quote from: BobRay at Apr 01, 2011, 10:36 PM

                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.

                Thanks Bob, That’s the kind of solution i envisioned but didn’t have the technical skills to execute. I appreciate the input and will be doing some trials to see where this takes me. When I get it right I’ll definitely pass it back to share with others. grin
                  • 25308
                  • 46 Posts
                  Quote from: swespi at Apr 03, 2011, 12:09 PM

                  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.



                  Wow Swespi! That could be the solution I’m looking for. This has inspired me to brush up on my php. I’ll run some tests and let you know my findings. If all is well I’ll pass it back to share w/ credit to you (if that’s cool). Thanks for the reply,... Now I’m off to take this code for a spin. grin
                    • 25308
                    • 46 Posts
                    Quote from: Robot at Apr 05, 2011, 08:52 AM

                    Quote from: swespi at Apr 03, 2011, 12:09 PM


                    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.

                    I’ve made the changes you’ve described but have come to the last two steps and my own ignorance prevented me from continuing.

                    Can you explain these last two steps a little further? I’m still a newb when it comes to php. ;( That’ll be my next quest after I get this up and running.

                    To be more specific on my end:
                    1. Where would I put the
                    $userID = !empty($userID) ? (int) $userID : 1;
                    ?
                    2. I understand the "get" and "post" functions but I’m not sure how to implement your last step of sending the user ID to the editing page with a GET, and pass that argument on to the snippet.

                    any further explanation would be greatly appreciated. Thanks again for the post. grin
                      • 29019 ☆ A M B ☆
                      • 104 Posts
                      1.) You would put that line at the top of your new UpdateProfile snippet, just after the comments.
                      2.) On the page that has your UpdateProfile snippet, you’d need to get the user ID from the $_GET array (or $_POST or $_SESSION, if you prefer). You can do this with a simple snippet like this:

                      <?php
                      return $_GET[$q];


                      If you call that snippet "get", for example, you would then call UpdateProfile like so:

                      [[!UpdateProfile? &userID=`[[!get? &q=`userid`]]`]]


                      Then just have your user choosing page link to your profile page with a "?userid=[selected user id]" at the end of the link, or you can submit a form with something like this:

                      <form action="[[~[update profile page id]]]" method="get">
                      	<select name="userid">[[!getUsers]]</select>
                      	<input type="submit" value="Edit User" />
                      </form>


                      Let us know how it works out!
                        www.darkstardesign.com

                        Are you in the Nashville area? Join us for our next MODX meetup!