How to add one new link in the menu to a specific group?

Started by HecKel, May 27, 2008, 06:40:34 AM

Previous topic - Next topic

HecKel

Hi!

I want to create one new action in my community, one new menu (like admin panel) but to one or more specific groups. How can I do that?

tnks in advance ;)
Quote from: Eliana Tamerin on August 23, 2008, 04:10:10 PM
SMF 7 is where it gets good. That has time travel. You can go back and post before the guy who flamed you. :P

HecKel

Quote from: Eliana Tamerin on August 23, 2008, 04:10:10 PM
SMF 7 is where it gets good. That has time travel. You can go back and post before the guy who flamed you. :P

Nathaniel

Creating a new action can be done with either the Custom Action Mod or the Site Integration Mod, I would suggest the Custom Action Mod for your use.

In terms of adding a menu element to your menu, it depends on which version of SMF and which template, if you post that information then I may be able to help you better. I am actually developing a Mod called the Custom Menu Mod for this, but its on hold until after my exams. ;)
SMF Friend (Former Support Specialist) | SimplePortal Developer
My SMF Mods | SimplePortal

"Quis custodiet ipsos custodes?" - Who will Guard the Guards?

Please don't send me ANY support related PMs. I will just delete them.

Jennahan

And parts of page visible only for specified groups u can take into this:

    if (!$context['user']['is_guest'])
    if(in_array($YOUR_SPECIAL_GROUP, $user_info['groups'])){
HIDDEN PARTS
}

Nathaniel

Quote from: Jennahan on May 28, 2008, 07:46:49 AM
And parts of page visible only for specified groups u can take into this:

    if (!$context['user']['is_guest'])
    if(in_array($YOUR_SPECIAL_GROUP, $user_info['groups'])){
HIDDEN PARTS
}


You will actually find that for SMF 2 Beta, both of those mods will allow you to do your own permissions, but yeah, for SMF 1.1.5 you can use code like that.  :)
SMF Friend (Former Support Specialist) | SimplePortal Developer
My SMF Mods | SimplePortal

"Quis custodiet ipsos custodes?" - Who will Guard the Guards?

Please don't send me ANY support related PMs. I will just delete them.

HecKel

tnks for the quick answers ;)

I am using SMF 1.1.5 but now I am considering moving to SMF 2.0 Beta 3.1 :)
Quote from: Eliana Tamerin on August 23, 2008, 04:10:10 PM
SMF 7 is where it gets good. That has time travel. You can go back and post before the guy who flamed you. :P

Jennahan

How could u set permission to view page using Site Integration Mod? I have one but I can`t see any options to restrict access to pages different that this code...

HecKel

I want to avoid install more MODs, if I can set the action to redirect to some page that should be great!

For SMF 2.0 I have already one solution, Redirect Boards :P
Quote from: Eliana Tamerin on August 23, 2008, 04:10:10 PM
SMF 7 is where it gets good. That has time travel. You can go back and post before the guy who flamed you. :P

HecKel

Quote from: Jennahan on May 28, 2008, 07:46:49 AM
And parts of page visible only for specified groups u can take into this:

   if (!$context['user']['is_guest'])
   if(in_array($YOUR_SPECIAL_GROUP, $user_info['groups'])){
HIDDEN PARTS
}


What about to create one new menu? I am using SMF 1.1.5 :)
Quote from: Eliana Tamerin on August 23, 2008, 04:10:10 PM
SMF 7 is where it gets good. That has time travel. You can go back and post before the guy who flamed you. :P

Nathaniel

Which template are you using?

Have a look for the template_menu() function in the index.template.php filem, you might be able to work out which edits you have to do to that function, but if you can't then please post the code for that function for your template.
SMF Friend (Former Support Specialist) | SimplePortal Developer
My SMF Mods | SimplePortal

"Quis custodiet ipsos custodes?" - Who will Guard the Guards?

Please don't send me ANY support related PMs. I will just delete them.

HecKel

I didn't change anything yet, I just wanna know how to add one new tab to the main menu, but one tab with "limited" access ;)

I think that I only have to change in index.template.php, am I right?
Quote from: Eliana Tamerin on August 23, 2008, 04:10:10 PM
SMF 7 is where it gets good. That has time travel. You can go back and post before the guy who flamed you. :P

HecKel

This is my code, but is not working...

After this:

// Is the user allowed to administrate at all? ([admin])
    if ($context['allow_admin'])
        echo ($current_action == 'admin' || $context['browser']['is_ie4']) ? '<td class="maintab_active_' . $first . '">&nbsp;</td>' : '' , '
                <td valign="top" class="maintab_' , $current_action == 'admin' ? 'active_back' : 'back' , '">
                    <a href="', $scripturl, '?action=admin">' , $txt[2] , '</a>
                </td>' , $current_action == 'admin' ? '<td class="maintab_active_' . $last . '">&nbsp;</td>' : '';


I put this:

// Add new menu
    if (!$context['user']['is_guest']){
$mygroups= array(1,2,55);
         if(in_array($mygroups, $user_info['groups'])){
echo ($current_action=='smf_test' || $context['browser']['is_ie4']) ? '<td class="maintab_active_' . $first . '">&nbsp;</td>' : '' , '
<td valign="top" class="maintab_' , $current_action == 'smf_test ? 'active_back' : 'back' , '">
<a href="http://www.simplemachines.org">SMF</a>
</td>' , $current_action == 'smf_test' ? '<td class="maintab_active_' . $last . '">&nbsp;</td>' : '';
}
}


What is wrong? I am admin (group 1) and I don't see anything...

Now I followed this: http://docs.simplemachines.org/index.php?topic=564
Quote from: Eliana Tamerin on August 23, 2008, 04:10:10 PM
SMF 7 is where it gets good. That has time travel. You can go back and post before the guy who flamed you. :P

HecKel

Sorry to be so annoying...

So, I tried this in another folder:

<?php
// Get SSI into the mix.
include_once(dirname(dirname(__FILE__)) . '/forum/SSI.php');

echo var_dump($user_info['groups']) . '<br />';
$testteam = array("1","2","55");
echo var_dump($testteam) . '<br />';
if (in_array(1$user_info['groups']))
echo 'OK1';
else
echo 'NOK 1';
if (in_array('1'$user_info['groups']))
echo 'OK 2';
else
echo 'NOK 2';
if (in_array("1"$user_info['groups']))
echo 'OK 3';
else
echo 'NOK 3';
if (in_array(1$user_info['groups']) || in_array(2$user_info['groups'])  || in_array(55$user_info['groups']))
echo 'OK 4';
else
echo 'NOK 4';
if(in_array($testteam$user_info['groups']))
echo 'OK 5!!!!';
else
echo 'NOK 5';
?>


And I got the follow output:

array(3) { [0]=>  string(1) "1" [1]=>  string(2) "33" [2]=>  string(2) "55" }
array(3) { [0]=> string(1) "1" [1]=> string(1) "2" [2]=> string(2) "55" }
OK 1OK 2OK 3OK 4NOK 5


Now I tried this code in my index.template.php:
// Add new menu
    if (!$context['user']['is_guest']){
      // $mygroups= array(1,2,55);
         if (in_array(1, $user_info['groups']) || in_array(2, $user_info['groups'])  || in_array(55, $user_info['groups']))
         echo ($current_action=='smf_test' || $context['browser']['is_ie4']) ? '<td class="maintab_active_' . $first . '">&nbsp;</td>' : '' , '
            <td valign="top" class="maintab_' , $current_action == 'smf_test ? 'active_back' : 'back' , '">
               <a href="http://www.simplemachines.org">SMF</a>
            </td>' , $current_action == 'smf_test' ? '<td class="maintab_active_' . $last . '">&nbsp;</td>' : '';
   }


But..., doesn't work..., why? :| I don't understand why everything is ok in one folder and totally wrong in the production forum :|
Quote from: Eliana Tamerin on August 23, 2008, 04:10:10 PM
SMF 7 is where it gets good. That has time travel. You can go back and post before the guy who flamed you. :P

ccbtimewiz

Very funny reason why it doesn't work. I had the same problem, but what I was able to find out is:

Code (in_array) Select
$mygroups= array(1, 2, 55);
if (in_array($mygroups, $user_info['groups']))


Actually look at that code. "in_array" checks if a value exists in an array, however you used an array to describe $mygroups and not $user_info.

Now, I made a custom hack that takes away the "add_poll" to a topic in the recycle board, notice how I coded it:

Code (My Code) Select
if ($context['can_add_poll'] && !in_array($context['current_board'], $archive_boards))

This states that in the $context['current_board'] is currently loaded up with a single sanction, then the return value will be neglected if it's found in the array I defined in $archive_boards. This is obviously true because I am doing a false check using "!'.

So one way of getting this to work correctly would be to reverse it and manually type in what groups cannot access. The alternative would to use something similar to what you did, but you made a parse error on your code at this line:

Code (Parse Error) Select
<td valign="top" class="maintab_' , $current_action == 'smf_test ? 'active_back' : 'back' , '">

When it should be:

Code (Correct Version) Select
<td valign="top" class="maintab_' , $current_action == 'smf_test' ? 'active_back' : 'back' , '">

So, some variations of the following code might get you want you desire. I changed 'smf_test' to 'whatever'.

Code (Allowed) Select
# Let's try to get this working. A custom [button] for certain groups.
$x = array(1, 2, 55);
# Let's attempt to only show [button] for the groups defined above in $z.
if  (in_array($x, $user_info['groups'])) {
echo ($current_action == 'whatever' || $context['browser']['is_ie4']) ? '<td class="maintab_active_' . $first . '">&nbsp;</td>' : '' , '
<td valign="top" class="maintab_' , $current_action == 'whatever' ? 'active_back' : 'back' , '">
<a href="http://www.simplemachines.org" target="_blank">SMF</a>
</td>' , $current_action == 'whatever' ? '<td class="maintab_active_' . $last . '">&nbsp;</td>' : ''; }


Code (Disallowed) Select
# Let's try to get this working. A custom [button] for certain groups.
$z = array(3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34,
                35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 56);
# Let's attempt to only show [button] for the groups defined above in $z.
if (!in_array($user_info['groups'], $z)) {
echo ($current_action == 'whatever' || $context['browser']['is_ie4']) ? '<td class="maintab_active_' . $first . '">&nbsp;</td>' : '' , '
<td valign="top" class="maintab_' , $current_action == 'whatever' ? 'active_back' : 'back' , '">
<a href="http://www.simplemachines.org" target="_blank">SMF</a>
</td>' , $current_action == 'whatever' ? '<td class="maintab_active_' . $last . '">&nbsp;</td>' : ''; }


Code (Double) Select
# Let's try to get this working. A custom [button] for certain groups.
$x = array(1, 2, 55);
$z = array(3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 56);
# Let's attempt to only show [button] for the groups defined above in $z.
if (!in_array($user_info['groups'], $z)) || in_array($x, $user_info['groups']) {
echo ($current_action == 'whatever' || $context['browser']['is_ie4']) ? '<td class="maintab_active_' . $first . '">&nbsp;</td>' : '' , '
<td valign="top" class="maintab_' , $current_action == 'whatever' ? 'active_back' : 'back' , '">
<a href="http://www.simplemachines.org" target="_blank">SMF</a>
</td>' , $current_action == 'whatever' ? '<td class="maintab_active_' . $last . '">&nbsp;</td>' : ''; }

HecKel

Quote from: ccbtimewiz on May 29, 2008, 11:44:36 AM
So one way of getting this to work correctly would be to reverse it and manually type in what groups cannot access. The alternative would to use something similar to what you did, but you made a parse error on your code at this line:

Code (Parse Error) Select
<td valign="top" class="maintab_' , $current_action == 'smf_test ? 'active_back' : 'back' , '">

When it should be:

Code (Correct Version) Select
<td valign="top" class="maintab_' , $current_action == 'smf_test' ? 'active_back' : 'back' , '">

That was just a copy error :P I didn't put my original variables 'cause I though that this should be easier to explain ;) But in my index.template.php I have everything correct, or else I had one error :P

So, I have equal to your "Allowed" version :-[ I really don't understand...

Maybe is better that I put here my index.template.php ?
Quote from: Eliana Tamerin on August 23, 2008, 04:10:10 PM
SMF 7 is where it gets good. That has time travel. You can go back and post before the guy who flamed you. :P

ccbtimewiz

The above code should be used on the index.template.php file. Make no references to other files.

HecKel

And it is like that ;)

I only had change index.template.php and I didn't create any new file.
Quote from: Eliana Tamerin on August 23, 2008, 04:10:10 PM
SMF 7 is where it gets good. That has time travel. You can go back and post before the guy who flamed you. :P

ccbtimewiz

Oh duh. Remember to add $user_info into the globals of index.template.php too. ^^'


HecKel

Something like this?

function template_menu()
{
global $context, $settings, $options, $scripturl, $txt, $user_info;


blablabla

}


Didn't work :( And I tried to add in all the functions as well :x Just in case :X
Quote from: Eliana Tamerin on August 23, 2008, 04:10:10 PM
SMF 7 is where it gets good. That has time travel. You can go back and post before the guy who flamed you. :P

HecKel

Quote from: Eliana Tamerin on August 23, 2008, 04:10:10 PM
SMF 7 is where it gets good. That has time travel. You can go back and post before the guy who flamed you. :P

Advertisement: