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
Hi there,
Is PHP supported in Simple Portal pages?
Yes. You can add a PHP block of code anywhere.
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.
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>';
}
?>
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>';
}
?>
Same issue.
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>';
}
?>
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.
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 :)
It's on an internal Dev server which can't be accessed externally.
Sorry.
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>.
Hi,
Just spoken with colleagues, we do have jquery available on the dev site - version 1.3.
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.
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
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.
That's fantastic.
Thankyou so much for your help.
W.
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 :)
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.
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>';
}
Spectacular :)
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.