1
hipoonios
Php block: Let users change group
  • 2010/1/19 7:56

  • hipoonios

  • Friend of XOOPS

  • Posts: 298

  • Since: 2005/9/24


Another request

I want a block with a button. When a user click on it he/she will be moved to another group.

like: #CLICK HERE# to be a member of this group.

Anyone know how to do this?

2
sailjapan
Re: Php block: Let users change group

when you say 'group' are you talking about XOOPS groups... where permissions are allocated?

3
hipoonios
Re: Php block: Let users change group
  • 2010/1/19 19:42

  • hipoonios

  • Friend of XOOPS

  • Posts: 298

  • Since: 2005/9/24


Yes.

I want users to move their self from group 2 (registered users) to group 5 (another group i've created).

4
ghia
Re: Php block: Let users change group
  • 2010/1/20 2:26

  • ghia

  • Community Support Member

  • Posts: 4953

  • Since: 2008/7/3 1


Try with following addtogroup.php
<?php include "/mainfile.php"; global $xoopsDB; $numgroup = '5'; // choose Group number if (is_object($xoopsUser)) { $groups = $xoopsUser->getGroups(); $uid = $xoopsUser->getVar('uid'); } else { $groups = array(XOOPS_GROUP_ANONYMOUS); $uid = 0; } if (($uid > 0) && (!in_array($numgroup, $groups))) { $query = "insert into ".$xoopsDB->prefix('groups_users_link')." (groupid, uid) VALUES('".$numgroup."', '".$uid."')"; $result= $xoopsDB->query($query); if (mysql_error()) { echo "Error in database : ".mysql_error(); exit(); } } redirect_header(XOOPS_URL.'/',0); ?>


In your bloc you make a php program
le="color: #000000"><?php global $xoopsUser; $numgroup = '5'; // choose Group number if (is_object($xoopsUser)) { $groups = $xoopsUser->getGroups(); if (!in_array($numgroup, $groups)) { echo '<form action="'.XOOPS_URL.'/addtogroup.php" method="post"><input value="Add me as member" type="submit" /></form>'; } else { echo "Welcome member"; } } else { echo "please register"; }
Not tested. Make a database backup first.

5
hipoonios
Re: Php block: Let users change group
  • 2010/1/20 20:34

  • hipoonios

  • Friend of XOOPS

  • Posts: 298

  • Since: 2005/9/24


Just tested it and it doesn't work. First I've got a parse error on line 5. So I removed a ')'. After that it shows no errors. But the block show only "please register" even if i'm a registered user and logged in.

Thank you for helping!

6
ghia
Re: Php block: Let users change group
  • 2010/1/21 8:49

  • ghia

  • Community Support Member

  • Posts: 4953

  • Since: 2008/7/3 1


Add a
le="color: #000000"><?php global $xoopsUser;
as first line.
(Corrected on original post)

7
hipoonios
Re: Php block: Let users change group
  • 2010/1/21 18:51

  • hipoonios

  • Friend of XOOPS

  • Posts: 298

  • Since: 2005/9/24


Now it almost works.

After clicking on the button nothing happens. The Redirect Header is supposed to show up? But I see in the user profile that the user have been added to the the group.

And after member in the group the user still see "add my as a member" and not "welcome member".

Is this maybe because the user is member of both registered users and my new group after clicking?

8
ghia
Re: Php block: Let users change group
  • 2010/1/21 20:59

  • ghia

  • Community Support Member

  • Posts: 4953

  • Since: 2008/7/3 1


Try by in addtogroup.php to add
le="color: #000000"><?php global $xoopsUser;

and at the end, modify the redirect to
le="color: #000000"><?php redirect_header(XOOPS_URL.'/user.php?op=logout',0);

9
hipoonios
Re: Php block: Let users change group
  • 2010/1/22 4:55

  • hipoonios

  • Friend of XOOPS

  • Posts: 298

  • Since: 2005/9/24


That made it!!

But I don't like that the user have to login again after group change. But maybe there is no solution for that?

Login

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