Subject:*
<
Name/Email:*
<
Message Icon:*
<
Select*
<
Message:*
<



Click the Preview to see the content in action.
Options:*
<
Confirmation Code*
<
4 + 5 = ?  
Input the result from the expression
Maximum attempts you can try: 10
*
<
     

Re: Looking to get current user information and some fields from user profile.
by redheadedrod on 2011/2/1 17:52:51

Well I got it to work by accessing the database directly but I would rather NOT do it that way...

when I used queryf instead of query it worked in this code. Apparently the error was telling me it wasn't adding it but still would like to know what the error means any why I got it.

Here is the code that worked...


le="color: #000000"><?php function Groups_Add_n_Remove($id, $action = 0) { $action = (int)$action ? 1 : 0; // making sure it is an int. 1 = add user 0 = remove user global $xrosterList_users, $xoopsModuleConfig, $xrosterhMember; $groupid=$xoopsModuleConfig['ugroup']; $member=getMember($id, 1); // added the 1 to have getMember get a member no matter if activated or not and modified getMember accordingly $key = array_search($member['membername'], $xrosterList_users); // gets UID of user if user is a registered user on the site if ($key) { $db =& Database::getInstance(); $result = $db->query('SELECT linkid, groupid, uid FROM ' . $db->prefix('groups_users_link') . ' WHERE uid=' . $key . ' AND groupid=' . $groupid); $row = $db->fetchArray($result); $linkid=$row['linkid']; if (!(isset($linkid)) && $action) { $result = $db->queryF('INSERT INTO ' . $db->prefix('groups_users_link') . ' (groupid, uid) VALUES (' . $groupid . ', ' . $key .')'); } if (isset($linkid) && !($action)) { $result = $db->queryF('DELETE FROM ' . $db->prefix('groups_users_link') . ' WHERE linkid='. $linkid); } } }
Re: Looking to get current user information and some fields from user profile.
by redheadedrod on 2011/2/1 15:52:01

I don't get it.. Not only does the above code not work... But when I try this... In the code by its self not in a function or anything...
le="color: #000000"><?php $member_handler = &xoops_gethandler('member'); $member_handler->addUserToGroup(4, 1);


It doesn't work.

I have even put a debug line in the code to see what is getting sent and it is getting the right stuff. Just not completing for some reason?

I print what is going on with the functions themselves in kernel/member.php.

If I do it from the control panel It gets the same 4 and 1 but completes successfully. I do it manually like above and it gets the 4 and 1 but doesn't complete ?

Still getting the above error message which I wonder if it is interfering?

And yes when I do this I remove the user from the group in the admin then let my code try to add it back in... But it doesn't add.. GRRRR

Rodney

Re: Looking to get current user information and some fields from user profile.
by redheadedrod on 2011/2/1 14:40:50

Ok, this is getting frustrating and I am about to bypass this and go directly to the database.

I decided to make a new function as below and not use the function as above.

The following function works right up until the lines where it actually is supposed to add or subtract a user from the user group. I have heavily commented this function to show what I am trying to do. I would greatly appreciate someone looking at it and seeing what I am missing.

$result returns a null which I would expect is a failure?

le="color: #000000"><?php /** $id is the $id of the user from the roster database * $action true = add user to group false = remove user from group * $xrosterList_users is list of registered users with the key being the UID and value being the UNAME * $key = contains the UID of the user obtained from the list of registered users * $xoopsModuleConfig['ugroup'] is the groupid of the group I am trying to add/remove user from * $result should equal true if it worked */ $xrosterhMember =& xoops_gethandler('member'); // Getting a handle for xoops_gethandler (doesn't seem to work if I put it IN the function) function Groups_Add_n_Remove($id, $action = 0) { $action = (int)$action ? 1 : 0; // making sure it is an int. 1 = add user 0 = remove user global $xrosterList_users, $xoopsModuleConfig, $xrosterhMember; $member=getMember($id, 1); // added the 1 to have getMember get a member no matter if activated or not and modified getMember accordingly $key = array_search($member['membername'], $xrosterList_users); // gets UID of user if user is a registered user on the site if ($key){ // makes sure the roster memeber is a registered site member if ($action) $result =& $xrosterhMember->addUserToGroup($xoopsModuleConfig['ugroup'], $key); // addUserToGroup('groupid', 'uid') else $result =& $xrosterhMember->removeUsersFromGroup($xoopsModuleConfig['ugroup'], array($key)); // removeUsersFromGroup('groupid', array('uid')) } }
Re: Looking to get current user information and some fields from user profile.
by redheadedrod on 2011/1/31 19:59:47

Can someone tell me what is wrong with this code?

I am trying to use this to remove a user from a group. It is not working.

I will have a similar function to add a person to the group as well.

The $xoopsModuleConfig['ugroup'] line pulls up the right group and I am forcing the UID 1 which is a valid user number. I have some other code to add after I get this working but at the moment when I run this code it returns ok but no actual removal of the user.

If I am reading things right the right format for calling the method is...

removeUsersFromGroup(groupid, array(uid));

where array(uid) can be 1 user or many users.

This method is a little different than the similar method if I am understanding this which is called like this...

addUserToGroup(groupid, uid)

The snippet of code I am using...

le="color: #000000"><?php $xrosterhMember =& xoops_gethandler('member'); function Members_Delete($id){ global $xrosterhMember, $xoopsModuleConfig; $result =& $xrosterhMember->removeUsersFromGroup($xoopsModuleConfig['ugroup'], array(1)); }



Another note... I do get this following error...
Quote:

Warning: Database updates are not allowed during processing of a GET request in file /class/database/mysqldatabase.php line 397


This is the LAST thing I need to add to my roster program before I move onto the next thing so I would greatly appreciate any help someone can give me.

I want to thank ghia, iHackCode, zyspec, and tarik for helping me out so far. I didn't expect to do this much with this module because I want to totally rewrite it but the experience was useful.
Re: Looking to get current user information and some fields from user profile.
by xoobaru on 2011/1/30 19:54:06

Not in a template, just trying to use Javascript within a small php file to get uname and uid info into Javascript variables when the file is executed from a link in the logged on side. Tried the above variables anyways but no success. I wonder if XOOPS security features are interfering somehow. This should be simple.

Who's Online

512 user(s) are online (439 user(s) are browsing Support Forums)


Members: 0


Guests: 512


more...

Donat-O-Meter

Stats
Goal: $15.00
Due Date: Jul 31
Gross Amount: $0.00
Net Balance: $0.00
Left to go: $15.00
Make donations with PayPal!

Latest GitHub Commits