Simple Machines Community Forum

Customizing SMF => Modifications and Packages => Mod Requests => Aiheen aloitti: Wilo - maaliskuu 27, 2012, 09:48:09 AP

Otsikko: URL to join a Membergroup from anywhere in the forum.
Kirjoitti: Wilo - maaliskuu 27, 2012, 09:48:09 AP
Hi,

SMF 2.0.2
Simple Portal

Is there, or can a Mod be developed whereby a specific membergroup can be joined or left from a link.  So the member could click Join Group to join a membergroup with out having to goto their profile/group membership page.

For Example, I have a page (using Simple Portal) containing information about a group (membergroup).  On that page a button would exist called join group.  The member presses Join Group and the member now can access boards and permissions managed by that particular membergroup.  The button would then change to Leave group to leave the membergroup.

Many thanks,

W
Otsikko: Re: URL to join a Membergroup from anywhere in teh forum.
Kirjoitti: NanoSector - maaliskuu 27, 2012, 10:01:50 AP
Hi there,

Is PHP supported in Simple Portal pages?
Otsikko: Re: URL to join a Membergroup from anywhere in teh forum.
Kirjoitti: Wilo - maaliskuu 27, 2012, 10:04:14 AP
Yes.  You can add a PHP block of code anywhere.
Otsikko: Re: URL to join a Membergroup from anywhere in teh forum.
Kirjoitti: NanoSector - maaliskuu 27, 2012, 10:12:42 AP
Lainaus käyttäjältä: Wilo - maaliskuu 27, 2012, 10:04:14 AP
Yes.  You can add a PHP block of code anywhere.
Then that's great :)

Add this as PHP block:


<?php

global $user_info;

if (!
in_array(number_of_your_membergroup$user_info['groups']))
{
echo 
'<a href="http://url.to.your/forum/index.php?action=profile;save;u=' $user_info['id'] . ';area=groupmembership;gid=number_of_your_membergroup">Join this group!</a>';
}
else
{
echo 
'<a href="http://url.to.your/forum/index.php?action=profile;save;u=' $user_info['id'] . ';area=groupmembership;gid=number_of_your_membergroup">Leave this group!</a>';
}

?>


Replace "number_of_your_membergroup" with the ID of the membergroup in question.
Otsikko: Re: URL to join a Membergroup from anywhere in the forum.
Kirjoitti: Wilo - maaliskuu 27, 2012, 10:43:47 AP
Hi,  Thankyou very much for your time.

I've added the code however I get the following

Whoops!
Session verification failed. Please try logging out and back in again, and then try again.

Here's the code i'm entering.

<?php

global $user_info;

if (!in_array(20, $user_info['groups']))
{
echo '<a href="//test_server/index.php?action=profile;save;u=' . $user_info['id'] . ';area=groupmembership;gid=20">Join this group!</a>';
}
else
{
echo '<a href="//test_server/index.php?action=profile;save;u=' . $user_info['id'] . ';area=groupmembership;gid=20">Leave this group!</a>';
}

?>
Otsikko: Re: URL to join a Membergroup from anywhere in the forum.
Kirjoitti: NanoSector - maaliskuu 27, 2012, 10:46:29 AP
Lainaus käyttäjältä: Wilo - maaliskuu 27, 2012, 10:43:47 AP
Hi,  Thankyou very much for your time.

I've added the code however I get the following

Whoops!
Session verification failed. Please try logging out and back in again, and then try again.

Here's the code i'm entering.

<?php

global $user_info;

if (!in_array(20, $user_info['groups']))
{
echo '<a href="//test_server/index.php?action=profile;save;u=' . $user_info['id'] . ';area=groupmembership;gid=20">Join this group!</a>';
}
else
{
echo '<a href="//test_server/index.php?action=profile;save;u=' . $user_info['id'] . ';area=groupmembership;gid=20">Leave this group!</a>';
}

?>

Oh, meh, seems like it doesn't like me removing the phpSessID stuff. Let me test something.

EDIT: Try this:
<?php

global $user_info;

if (!
in_array(20$user_info['groups']))
{
echo 
'<a href="//test_server/index.php?action=profile;save;u=' $user_info['id'] . ';area=groupmembership;' $_SESSION['session_value'] . ';gid=20">Join this group!</a>';
}
else
{
echo 
'<a href="//test_server/index.php?action=profile;save;u=' $user_info['id'] . ';area=groupmembership;' $_SESSION['session_value'] . ';gid=20">Leave this group!</a>';
}

?>
Otsikko: Re: URL to join a Membergroup from anywhere in the forum.
Kirjoitti: Wilo - maaliskuu 27, 2012, 11:01:34 AP
Same issue.
Otsikko: Re: URL to join a Membergroup from anywhere in the forum.
Kirjoitti: NanoSector - maaliskuu 27, 2012, 11:18:49 AP
Last try then:

<?php

global $user_info;

if (!
in_array(20$user_info['groups']))
{
echo 
'<a href="//test_server/index.php?action=profile;save;u='$user_info['id'], ';area=groupmembership;'$_SESSION['session_var'], '='$_SESSION['session_value'], ';gid=20">Join this group!</a>';
}
else
{
echo 
'<a href="//test_server/index.php?action=profile;save;u='$user_info['id'], ';area=groupmembership;'$_SESSION['session_var'], '='$_SESSION['session_value'], ';gid=20">Leave this group!</a>';
}

?>
Otsikko: Re: URL to join a Membergroup from anywhere in the forum.
Kirjoitti: Wilo - maaliskuu 27, 2012, 11:35:19 AP
That's it!

That is absolutely amazing, I have been searching for a work around for months.  While your brain is on fire can your script return to it's origin.  When the link is pressed it goes to the membergroup page and joins, or leaves the group.  Can the script run in the background so the member remains on the page containing the link?

Thanks again for your help.

W.
Otsikko: Re: URL to join a Membergroup from anywhere in the forum.
Kirjoitti: NanoSector - maaliskuu 27, 2012, 11:49:18 AP
Lainaus käyttäjältä: Wilo - maaliskuu 27, 2012, 11:35:19 AP
That's it!

That is absolutely amazing, I have been searching for a work around for months.  While your brain is on fire can your script return to it's origin.  When the link is pressed it goes to the membergroup page and joins, or leaves the group.  Can the script run in the background so the member remains on the page containing the link?

Thanks again for your help.

W.
Sure, that's not so hard to do.

Can I have a link to your site, so I can check if jQuery is available?
Because if it is, it would be a lot easier to code for me :)
Otsikko: Re: URL to join a Membergroup from anywhere in the forum.
Kirjoitti: Wilo - maaliskuu 27, 2012, 11:55:05 AP
It's on an internal Dev server which can't be accessed externally.

Sorry.
Otsikko: Re: URL to join a Membergroup from anywhere in the forum.
Kirjoitti: NanoSector - maaliskuu 27, 2012, 11:56:12 AP
Lainaus käyttäjältä: Wilo - maaliskuu 27, 2012, 11:55:05 AP
It's on an internal Dev server which can't be accessed externally.

Sorry.
That's fine, no worries.

Can you check the source code of your Index page (Right click -> View source) for something with "jquery.js"?
It's usually somewhere between <head> and </head>.
Otsikko: Re: URL to join a Membergroup from anywhere in the forum.
Kirjoitti: Wilo - maaliskuu 27, 2012, 12:15:53 IP
Hi,

Just spoken with colleagues, we do have jquery available on the dev site - version 1.3.
Otsikko: Re: URL to join a Membergroup from anywhere in the forum.
Kirjoitti: NanoSector - maaliskuu 27, 2012, 01:07:07 IP
Lainaus käyttäjältä: Wilo - maaliskuu 27, 2012, 12:15:53 IP
Hi,

Just spoken with colleagues, we do have jquery available on the dev site - version 1.3.
Okay, assuming it also is available in SMF then, change the code into this:

<?php

// For the JS code...
echo '<div id="membergroupupdatejunk" style="width:1px;height:1px"></div>
<script type="text/javascript">
function updateMembergroup(id)
{
        $(\'#membergroupupdatejunk\').load("http://test_server/index.php?action=profile;save;u='
$user_info['id'], ';area=groupmembership;'$_SESSION['session_var'], '='$_SESSION['session_value'], ';gid=" + id + ")", function()
        {
                if (document.getElementByID(\'membergroupupdate\').innerHTML == "Leave this group!")
                        document.getElementByID(\'membergroupupdate\').innerHTML = "Join this group!";
                else
                        document.getElementByID(\'membergroupupdate\').innerHTML = "Leave this group!";
        });
}
</script>'
;

global 
$user_info;

if (!
in_array(20$user_info['groups']))
{
echo 
'<a onclick="updateMembergroup(20)"><div id="membergroupupdate">Join this group!</div></a>';
}
else
{
echo 
'<a onclick="updateMembergroup(20)"><div id="membergroupupdate">Leave this group!</div></a>';
}

?>


No idea if that'll work (I suck in JavaScript, heh) but give it a try.
Otsikko: Re: URL to join a Membergroup from anywhere in the forum.
Kirjoitti: Wilo - maaliskuu 28, 2012, 05:47:15 AP
Morning Yoshi2889,

It's sooo close but it's not reloading the screen.  In firefox and Chrome when clicking the link it loads a blank screen and hangs there.  I can reload the screen and the action has worked, i.e the link changes between join group and leave group and the membergroups are updated.

It doesn't work in IE, but then again, not much seems to.

Thanks again
Otsikko: Re: URL to join a Membergroup from anywhere in the forum.
Kirjoitti: NanoSector - maaliskuu 28, 2012, 07:20:23 AP
Okay then, try this:

<?php

// For the JS code...
echo '<div id="membergroupupdatejunk" style="width:1px;height:1px"></div>
<script type="text/javascript">
function updateMembergroup(id)
{
        $(\'#membergroupupdatejunk\').load("http://test_server/index.php?action=profile;save;u='
$user_info['id'], ';area=groupmembership;'$_SESSION['session_var'], '='$_SESSION['session_value'], ';gid=" + id + ")", function()
        {
                window.location.reload();
        });
}
</script>'
;

global 
$user_info;

if (!
in_array(20$user_info['groups']))
{
echo 
'<a onclick="updateMembergroup(20)" href="#">Join this group!</a>';
}
else
{
echo 
'<a onclick="updateMembergroup(20)" href="#">Leave this group!</a>';
}

?>


This will reload the page.
Otsikko: Re: URL to join a Membergroup from anywhere in the forum.
Kirjoitti: Wilo - maaliskuu 28, 2012, 07:52:16 AP
That's fantastic.

Thankyou so much for your help.

W.
Otsikko: Re: URL to join a Membergroup from anywhere in the forum.
Kirjoitti: NanoSector - maaliskuu 28, 2012, 07:56:29 AP
No problem :)

Just in case you want to update another membergroup, you can use the JavaScript function "updateMembergroup" with the ID of the group, like so:


updateMembergroup(4);


Anyways, what's important is that it works :)
Otsikko: Re: URL to join a Membergroup from anywhere in the forum.
Kirjoitti: Wilo - maaliskuu 30, 2012, 08:06:57 AP
Hi,

The code's working brilliantly, thanks.

Is it possible to assign the code to a button, or a graphic?  Could it be embedded into an HTML page?

Thanks again for your help,

W.

Otsikko: Re: URL to join a Membergroup from anywhere in the forum.
Kirjoitti: NanoSector - maaliskuu 30, 2012, 08:42:00 AP
Sure, a button or a graphic is possible. In a HTML page isn't though, unless it's coded with PHP.

Try this with a button/graphic:

if (!in_array(20, $user_info['groups']))
{
echo '<input type="button" onclick="updateMembergroup(20)">Join this group!</input>';
}
else
{
echo '<input type="button" onclick="updateMembergroup(20)">Leave this group!</input>';
}


Guess that's the correct way.

And for a graphic:

if (!in_array(20, $user_info['groups']))
{
echo '<a onclick="updateMembergroup(20)" href="#"><img src="http://url.to.my/image.png" alt="Join this group!" /></a>';
}
else
{
echo '<a onclick="updateMembergroup(20)" href="#"><img src="http://url.to.my/other/image.png" alt="Leave this group!" /></a>';
}
Otsikko: Re: URL to join a Membergroup from anywhere in the forum.
Kirjoitti: Wilo - maaliskuu 30, 2012, 11:35:51 AP
Spectacular   :)
Otsikko: Re: URL to join a Membergroup from anywhere in the forum.
Kirjoitti: Wilo - toukokuu 10, 2012, 10:57:13 AP
Hi,

A while ago you magicked up some PHP code which enabled members to join and leave member groups at the touch of a button.

Is it possible to edit this code so it works for member groups where members Request Membership as well?

You've done so much already it's fine if you say no.

Thanks again for all your help.

W.