When an administrator clicks on a users points, an edit/add user points page comes up. The username does not auto populate. The attached patch adds the following lines to userpoints.module

+ if ($txn_id) {
+ $txn_user = user_load(array('uid' => $txn_id));
+ }

CommentFileSizeAuthor
#6 add_points_form.patch507 bytesbrownjed
#2 5.2.gif10.23 KBkmillecam
#2 5.3.gif9.71 KBkmillecam
form_fix.patch691 bytesbrownjed

Comments

jredding’s picture

I'm not exhibiting this behavior. In fact if a txn_id exists the point can ONLY go back to the same user according to the API moreover in this patch the following code exists

+  if ($txn_id) {
+    $txn_user = user_load(array('uid' => $txn_id));
+  }
   if ($mode == 'edit' && $txn_id) {
     $result = db_query('SELECT * FROM {userpoints_txn} WHERE txn_id = %d', $txn_id);
     $txn = db_fetch_object($result);
     $timestamp = format_date($txn->time_stamp, 'custom', 'Y-m-d H:i O');
-    $txn_user = user_load(array('uid' => $txn->uid));
   }

Which loads a user twice with editing points. If you're adding points the user is loaded but that's because you're adding point thus you do not have a txn_id.

maybe I'm confused.

kmillecam’s picture

StatusFileSize
new9.71 KB
new10.23 KB

I can reproduce this on my sites.

1) upgrade to userpoints 5.3
2) log in as admin
3) go to a user's profile page
4) click on their point total
5) the edit page that appears is not populated with their username

With v5.2 the username field was populated (see attached).

jredding’s picture

hhm.. something between 5.2 and 5.3, I'll have to check my dev environment its probably a version behind.

In either case the patch is wrong as it would potentially load the user twice.

jredding’s picture

Oh so this is from V2 to v3.. hmm. is userpoints_transactiontools enabled by chance? Its not compatible with version3 and could cause some odd errors.

kmillecam’s picture

I thought maybe you were on to something (with your transactiontools idea) jredding. I just checked the 5.3 site and we only have userpoints and userpoints_basic installed/activated.

brownjed’s picture

StatusFileSize
new507 bytes

The problem lies in the mode. If the mode is "add" then the user_id is passed in through arg(4) and thus $txn_id. If the mode is "edit" then the transaction id is passed in through arg(4) and we must grab the transaction in order to get the user_id.

I've fixed the patch to work properly for add and edit modes, using the different ways to load each depending on the mode.

jredding’s picture

I'm not saying that you're wrong but there is something else at play here

If the mode is add you should NOT have a txn_id because "add" means that you are granting points to a person, if you are granting points you do not have a txn_id (cart before the horse).

I'm curious as to why when the mode is edit (thus you have a txn_id) on your installs there is not txn_id. I really don't know.

And I don't want to be nitpicky here but for coding reasons if its the mode then it should be an if/else not if {} and a second if {} . They both do the same thing (as $mode can't be both add AND edit) but its easier to read and thus cleaner code to properly distinguish that it has to be add OR edit but never both. The code currently reads as though it could possibly be add and edit (which is impossible).

Thank you for all the work I really appreciate I just want to make sure you squash the correct bug, especially since I can't reproduce this on a fresh install.

brownjed’s picture

You are completely correct, when the mode is add we don't have a txn_id but since we clicked the users points in the users profile page we do have a user_id, that way we already know who we are adding points for and we don't have to re-select a user. These both get passed in as arg(3). I guess ideally, for readability, we should distinguish between the two before we load them into the variable $txn_id because its not a transaction id at all.

It's working fine when we click edit (ie we do have a txn_id)

jredding’s picture

wow.. so I'm really confused. The title reads

User name field fails to carry over to edit view

Edit view implies that you are editing existing points. In this bug really about "Adding Points"? and how are you adding these points?

kmillecam’s picture

I've observed (in my environments) that when you're on a user's profile page and click a user's point balance, you are taken to a userpoints transaction form. With 5.2 this form was pre-populated and knew who the user was. In 5.3, the form is not pre-populated.

I believe what brownjed is pointing out is that in 5.2 the uid was passed from the profile page and used to build the transaction form. In 5.3 it may be getting passed but it's not being used to build the form (populate the username field).

Just my observation.

Kevin

jredding’s picture

Title: User name field fails to carry over to edit view (attached fix) » Username does not prepopulate when adding points from user's profile page

changing the title to better reflect the error.

I think I finally got it now. I'll take a look at the patch again with this in mind and see if its fixes the right bug.

Thanks again!

jredding’s picture

Status: Active » Fixed

fixed and committed

Anonymous’s picture

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for two weeks with no activity.