TP-Docs
HTML5 Icon HTML5 Icon HTML5 Icon
TP on Social Media

Recent

Welcome to TinyPortal. Please login or sign up.

Members
Stats
  • Total Posts: 196,004
  • Total Topics: 21,330
  • Online today: 103
  • Online ever: 8,223 (February 19, 2025, 04:35:35 AM)
Users Online
  • Users: 0
  • Guests: 84
  • Total: 84

Cluttered Admin Screen

Started by daemonist, January 04, 2007, 05:47:24 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

daemonist

I know that there is no built-in way to "hide" a block/article from the administrator account, however, I'm wondering if anyone has a "sneaky" way to accomplish this (without using a second "non-admin" account). :)

I'm using SMF 1.1.1 and TP 0.9.7 with a few simple mods.

I'm trying to create special blocks on the frontpage that provide new members with instructions, and that change based on group membership.  It works great, except that the administrators get to see all the blocks without regard for their other membership groups.

What I'd love to be able to do is ignore the administrator group for specific blocks, so that they just appear to members that are in the appropriate group.

I've hunted for mods, but have not yet found anything.

Ideas? 

Any suggestions would be greatly appreciated!

JPDeni

Quoteprovide new members with instructions, and that change based on group membership.  It works great, except that the administrators get to see all the blocks without regard for their other membership groups.
You have different ones for different groups? You could have them all in one php block. That way, you could have one blank block for admins.

daemonist

Quote from: JPDeni on January 04, 2007, 06:01:14 PM
You have different ones for different groups? You could have them all in one php block. That way, you could have one blank block for admins.

Right now, the blocks are simple HTML as I'm not the most proficient with PHP-- although, I am familiar with programming concepts and application design.  I wouldn't know the code required in order to display different contents to different people based on membergroup status...   

I suppose, if you could point me at a PHP resource that has TP specific functions, I could try and muddle my way through it.   Or better, if you can direct me to some code examples that do similar membergroup manipulation and display...

(embarrassed that I've not taken the time to brush up on my PHP/SMF/TP programming, but...time is my enemy)

JPDeni

That's okay. I'm willing to help. It's really not too hard to do, especially if you already have the html worked out.

The first thing is that you need to know what group or groups the person is in. That information is held in an array called $user_info['groups']. In order to make it accessible, you have to tell the script to make it a global variable. So you start with


global $user_info;


From here, it's just a matter of a bunch of "if" statements, based on the number of the group.


if (in_array(0,$user_info['groups']))
{
  echo 'All sorts of cool html that you want to print out for regular members';
}
if (in_array(-1,$user_info['groups']))
{
  echo 'Anything you want to print for guests';
}


Just substitute the numbers above for the number of the group you're dealing with -- one "if" statement per group. And you can just skip group 1, for admins, because you don't want to show anything for them.

A few things to remember. Watch your brackets and parentheses. Make sure you have closing ones for all opening ones. Start and end with single quotes. Watch for single quotes within your html. (Also apostrophes.) If you have them, stick a \ in front of each one and you should be fine. Be sure you end your echo statement with a ;.

We'll make you into a php programmer yet! ;)

daemonist

#4
Fabulous!  This works great, thank you so much!   However, I'd like to try and take this to the next level.  Currently, I have to find the ID of each group and create a separate entry for them...but...

Is there another variable that contains information about the PHP-block that we are programming within?  I'd like to create a loop structure that would parse through the security groups that are "enabled" for the block, and have it automatically add the HTML code based on those "checkmarked" groups.

for example:

"#5 (Regular Members)" and "#9 (Advanced Members)" are both checked, so they should see the block based on the default security structure.  I change the block to a PHP block, but instead of using:

(in_array(5,$user_info['groups']))

for my if condition, I would like to replace the "5" with a list of the checked security groups (in this example, 5 and 9).  So, the condition above becomes:

(in_array($active_group,$user_info['groups']))

with the values of the $active_group variable filled based on the "checked" security groups that can view the block.

There is probably a far easier way to do this...  I'm open to your experience!

Again, thank you for taking time to help!


EDIT:   I suppose an additional question would be:  'where would I look to find a complete listing of PHP available variables?'  :)

JPDeni

Last question first :)

Quote'where would I look to find a complete listing of PHP available variables?'
I've not found one. They change depending on the context. The $user_info array is mostly built within the Load.php file, so that's a place to start.

As for the rest, I'm not sure what you're working to accomplish. If you want to print something out for everyone who is allowed to see the block, dispense with the "if" statement altogether and just use


echo 'Everyone will see this';


Or am I misunderstanding what you're wanting?

Glad to help. :)

daemonist

Well, the purpose of this exercise is to "remove" the display of items in Administrator view.  I'd still like the block to appear to all those listed in the block's security list, just that I want to exclude it from the Administrators.

To explain further, this is one reason...

The site I host is for an online game and has three separate groups that "share" the services it offers.  We are an alliance of three guilds (more directly).  One of the reasons for this is to allow customizations of the look to include things like a "guild logo".   But, any administrators see all three logos and also see any custom blocks that the guild leaders of the guild can edit for their own guild.

I'd like to be able to set some blocks to "exclude" the administrators so that the site doesn't end up cluttered from an Admin point of view.

If it is just a matter of wrapping the HTML code in PHP code that limits the view to only those "checked" groups and displays a small "blank" space for administrators....  that would be excellent.   (ideal would be a "no admin" check box in the security structure that would exclude admin from seeing the block altogether).

That's mainly the plan.  :)

JPDeni

I see. Yes. I had forgotten. :smile:

You can start your whole thing with:


global $user_info;
if (in_array(1,$user_info['groups']))
{
  echo ' '; // This is just a space that all admins will see. Or you can post a message to admins.
}
else
{
  echo 'This everyone who can view the block can see.';
  if (in_array(0,$user_info['groups']))
  {
    echo 'All sorts of cool html that you want to print out for regular members';
  }
  if (in_array(-1,$user_info['groups']))
  {
    echo 'Anything you want to print for guests';
  }
}


Notice the nested brackets. Indenting makes it easier to keep track of them. (You probably already know that, but I thought I'd mention it anyway. :) )

daemonist

So simple, I'm ashamed that I didn't come up with that myself.

Thank you for your help here!

JPDeni

Sometimes you just need another set of brain cells to think in a different way.

Really glad to help. If you run into any problems, just holler.

This website is proudly hosted on Crocweb Cloud Website Hosting.