TinyPortal

Development => Block Codes => Topic started by: penfield on August 26, 2006, 02:38:30 PM

Title: Need Block that provides link to Pre-defined Member group page
Post by: penfield on August 26, 2006, 02:38:30 PM
I'm looking for a block that would give a logged-on user the ability to click thru to a pre-defined page that is available only to a given Member group. If that user is a member of several Member groups, he could choose among links to each Group's page...I have created separate javascript blocks for each Member group and made them available only to such Member Group, and that is working perfectly; however, I am concerned that if I need to have 100 separate pages for 100 separate Member groups, there will not be enough real estate (blocks) available to accomodate. Thanks to anybody who can help!
Title: Re: Need Block that provides link to Pre-defined Member group page
Post by: JPDeni on August 26, 2006, 03:09:37 PM
If I understand correctly, you can do something like

$perms = $GLOBALS['user_info']['groups'];

if (in_array('1',$perms))
{
  echo 'The stuff you want group 1 to see';
}
if (in_array('2',$perms))
{
  echo 'The stuff you want group 2 to see';
}


and so on. If you have stuff for more than one group you can use

if (in_array('1',$perms) || (in_array('2',$perms))

The || means "or". You can have several of them in a line, but if you get too many it can get confusing for you to edit.

Just be sure that you have matching braces -- { and } for each one that that you end every "echo" statement with a ;
Title: Re: Need Block that provides link to Pre-defined Member group page
Post by: Jpg on August 26, 2006, 03:23:15 PM
That could be helpful for a news page. Where you can set up different news for each group based on their ranking. Would be great for a roleplaying forum too.
Title: Re: Need Block that provides link to Pre-defined Member group page
Post by: akulion on August 26, 2006, 03:59:12 PM
For Membergroup based Links



global $user_info;

    if ($user_info['is_guest']) echo '<a href="...Guest link target here...">Link Text</a>';
    elseif (in_array(#, $user_info['groups'])) echo '<a href="...Group# link target here...">Link Text</a>';
    else echo '<a href="...Default link target here...">Link Text</a>';



the code above modify following:
Replace the '#' in the 'in_array(#, $user_info['groups'])' with the number of the membergroup you want to supply with the particular link or content (you could actually have mulitple 'elseif' lines before the 'else' for default).

And put all the correct links in the 'a href="', of course.

Using the same Link Text, the link would appear the same to all, but clicking would take user to the appropriate place.

=======================================
For membergroup based content

alternatively u could also specify different content using the same code as follows:



global $user_info;

    if ($user_info['is_guest']) echo 'Your content goes here....';
    elseif (in_array(#, $user_info['groups'])) echo 'Your content goes here....';
    else echo 'Your content goes here....';



please note that for EACH member group that u add, IF you want them to have a special content then u have to add one more line for each group as such specifying the membergroup number


elseif (in_array(#, $user_info['groups'])) echo 'Your content goes here....';



Explanation of code

    if ($user_info['is_guest']) echo 'Your content goes here....';

This basically says that if the user is a guest display this

    elseif (in_array(#, $user_info['groups'])) echo 'Your content goes here....';

This says but if the member belongs to this membergroup then display this

    else echo 'Your content goes here....';

Other wise if the member is not a guest or belong to any of the specified membergroups then display this
Title: Re: Need Block that provides link to Pre-defined Member group page
Post by: jacortina on August 26, 2006, 04:01:37 PM
For a block with "Link-per-group" (for all groups user is in), this might be easier to maintain (since you're only going to show the block to groups who have links anyway):


global $user_info, $boardurl, $db_prefix;

//  Assumes group pages ar somwhere under board directory ($boardurl)
//     $boardurl . page_url
//
$group_pages[] = array('group_num' => '4', 'page_url' => '/pagedir/pagea.html');
$group_pages[] = array('group_num' => '5', 'page_url' => '/pagedir/pageb.html');
$group_pages[] = array('group_num' => '6', 'page_url' => '/pagedir/pagec.html');
$group_pages[] = array('group_num' => '7', 'page_url' => '/pagedir/paged.html');
$group_pages[] = array('group_num' => '8', 'page_url' => '/pagedir/pagee.html');
$group_pages[] = array('group_num' => '9', 'page_url' => '/pagedir/pagef.html');
$group_pages[] = array('group_num' => '10', 'page_url' => '/pagedir/pageg.html');
$group_pages[] = array('group_num' => '11', 'page_url' => '/pagedir/pageh.html');
$group_pages[] = array('group_num' => '12', 'page_url' => '/pagedir/pagei.html');
$group_pages[] = array('group_num' => '13', 'page_url' => '/pagedir/pagej.html');
$group_pages[] = array('group_num' => '14', 'page_url' => '/pagedir/pagek.html');
$group_pages[] = array('group_num' => '15', 'page_url' => '/pagedir/pagel.html');
$group_pages[] = array('group_num' => '16', 'page_url' => '/pagedir/pagem.html');
$group_pages[] = array('group_num' => '17', 'page_url' => '/pagedir/pagen.html');

foreach ($group_pages as $group_page)
{
if ( in_array($group_page['group_num'], $user_info['groups']) )
{
$request = db_query("
SELECT groupName
FROM {$db_prefix}membergroups
WHERE ID_GROUP = " . $group_page['group_num'] . "
LIMIT 1", __FILE__, __LINE__);
$row = mysql_fetch_assoc($request);
mysql_free_result($request);
echo '<a href="' . $boardurl . $group_page['page_url'] . '">' . $row['groupName'] . '</a><br \>';
}
}

Title: Re: Need Block that provides link to Pre-defined Member group page
Post by: penfield on August 26, 2006, 10:56:21 PM
Thanks to everyone for great thoughts! I'd especially like to thank jacortina who generously helped outside the forum.
Title: Re: Need Block that provides link to Pre-defined Member group page
Post by: akulion on August 26, 2006, 11:02:39 PM
yes Jacortina is cool

even the code i gave u is adapted from a code she gave me to a similar question i had long time ago about conditional links
Title: "Link-per-Group" code question
Post by: penfield on April 22, 2007, 10:01:48 PM
Does anyone know how I could modify J.A.Cortina's "Link-per-Group" to open target url in an iframe? I need to mask the url of the link opened and am thinking that opening it in an iframe is the way to go..?..thanks!
Title: Re: Need Block that provides link to Pre-defined Member group page
Post by: jacortina on April 24, 2007, 03:23:25 PM
I don't think an IFrame will really keep the URL info secret (right-clicking on it will allow the properties to be displayed), though it should keep it not obviously visible.

But you could try to put this in an article (yeah, that's all):
if( isset($_GET['link']) )
echo '<iframe id="myframe" src="', $_GET['link'], '" marginwidth="0" marginheight="0" style="width: 100%;height: 500px;" frameborder="0" scrolling="yes"></iframe>';


Then, based off code above (plus the tweaks we talked about via PM), change the code (well, make a new block with this version of code):
global $user_info, $boardurl, $db_prefix;

$use_iframe = true;

//  Assumes group pages are anywhere
//  Can use  $boardurl . page_url  for pages at/under the forum root
//
$group_pages[] = array('group_num' => '3',   'page_url' => $boardurl . '/filetransfer/xxxxxxxxxxxx/sftpapplet/index.html');
$group_pages[] = array('group_num' => '6',   'page_url' => $boardurl . '/pagedir/pagec.html');
$group_pages[] = array('group_num' => '7',   'page_url' => $boardurl . '/pagedir/paged.html');
$group_pages[] = array('group_num' => '8',   'page_url' => $boardurl . '/pagedir/pagee.html');
$group_pages[] = array('group_num' => '10',   'page_url' => $boardurl . '/filetransfer/xxxxxxxxxxxx/sftpapplet/index.html');
$group_pages[] = array('group_num' => '4',   'page_url' => $boardurl . '/pagedir/pageg.html');
$group_pages[] = array('group_num' => '11',   'page_url' => $boardurl . '/pagedir/pageh.html');
$group_pages[] = array('group_num' => '12',   'page_url' => $boardurl . '/pagedir/pagei.html');
$group_pages[] = array('group_num' => '13',   'page_url' => $boardurl . '/pagedir/pagej.html');
$group_pages[] = array('group_num' => '14',   'page_url' => $boardurl . '/pagedir/pagek.html');
$group_pages[] = array('group_num' => '15',   'page_url' => $boardurl . '/pagedir/pagel.html');
$group_pages[] = array('group_num' => '16',   'page_url' => $boardurl . '/pagedir/pagem.html');
$group_pages[] = array('group_num' => '17',   'page_url' => $boardurl . '/pagedir/pagen.html');

// $group_pages[] = array('group_num' => '99',   'page_url' => 'http://www.google.com');

foreach ($group_pages as $group_page)
{
   if ( in_array($group_page['group_num'], $user_info['groups']) )
   {
      $request = db_query("
         SELECT groupName
         FROM {$db_prefix}membergroups
         WHERE ID_GROUP = " . $group_page['group_num'] . "
         LIMIT 1", __FILE__, __LINE__);
      $row = mysql_fetch_assoc($request);
      mysql_free_result($request);
      if (!$use_iframe)
        echo '<a href="' , $group_page['page_url'] , '">' , $row['groupName'] , '</a><br \>';
      else
        echo '<a href="' , $boardurl, 'index.php?page=##;link=', $group_page['page_url'] , '">' , $row['groupName'] , '</a><br \>';
   }
}


Make sure to change the '##' in that last line to the number of the article you made above.
Title: Re: Need Block that provides link to Pre-defined Member group page
Post by: penfield on April 24, 2007, 07:03:05 PM
Thanks! Works great! You're the best!...now if I can find a way to mask the urls... ;)