[Pro] Programmatic Control of CSS Menu Buttons

I would like to use the CSS Menu action to create navigation buttons. Most buttons will be available to all users. But some buttons will only be available to those that have logons to the member-only areas based upon the group they belong to. (I am using sitelok to provide login security.)

I would like to prevent the restricted buttons from showing if a user is not authorized for that area. I can code it in PHP, but I haven’t the foggiest idea how to plug it in the the CSS Menus.

Is what I want to do possible, or am I heading down the wrong path?

Jim


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

On 9 Mar 2009, at 03:56, Starfish Jim wrote:

I would like to use the CSS Menu action to create navigation
buttons. Most buttons will be available to all users. But some
buttons will only be available to those that have logons to the
member-only areas based upon the group they belong to. (I am using
sitelok to provide login security.)

I would like to prevent the restricted buttons from showing if a
user is not authorized for that area.

How about a second CSS Menu on the restricted pages, containing the
buttons you want, along with the existing buttons?

best wishes,

Paul Bradforth

http://www.paulbradforth.com


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

How about a second CSS Menu on the restricted pages, containing the
buttons you want, along with the existing buttons?

I’d rather not have buttons to the other pages at all. One button leads to a members only page, the other leads to the admin page for sitelok. Both of those pages enforce security to prevent unauthorized users accessing them. But from a look and feel I’d rather not have the buttons leading to them showing at all. To me, when a site does this, it is like saying “Nya, nya, you can’t come here!”


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

But from a look and feel I’d rather not have the buttons leading to them showing at all. To me, when a site does this, it is like saying “Nya, nya, you can’t come here!”

You’ve got a chicken-and-egg problem here. You could use Cookies to identify the people who are allowed to see these menus, but how to get them in there the first time? Perhaps you could give each person an e-mail to the login page, then set the cookie that means “canSeeAdmin” to some known value, then test for that value when the page loads.

I would test for the Cookie value using PHP, then use PHP to rewrite the menu or to inject a bit of JavaScript that would rewrite it.

To figure out what to add, simply publish a scratch page containing all of the options, and another showing only the public options. If you have BBEdit, it can do a ‘diff’ between these files and show you just the parts you need to inject.

To get them in there, you could use Prototype.js and Element.insert(), or you could use Source Code Snooper to plop a bit of PHP into your menu code that would do the same thing.

<?php
if(isset($_COOKIE['rt'])){
	if($session = ActiveRecord::FindFirst('people','session = "' . $_COOKIE['rt'] . '"')){
		$script = ($session->can_edit(ActiveRecord::Create('meetings'))) ? '	<script type="text/javascript" charset="utf-8">
		Event.observe(window,"load",function(){$("member_bar").insert(" | <a href=\"meetings/create\">Add Meeting</a>")});
	</script>
' : '';
		$script .= ($session->can_admin(ActiveRecord::Create('people'))) ? '	<script type="text/javascript" charset="utf-8">
		Event.observe(window,"load",function(){$("member_bar").insert(" | <a href=\"people/create\">Add Moderator</a>")});
	</script>
' : '';
	}else{
		$session = ActiveRecord::Create('people');
	}
}else{
	$session = ActiveRecord::Create('people');
}
?>

That’s out of some running code here. (Requires Prototype.js) Note that Freeway won’t let you simply ID a P tag the way a hand-coded page will, so you’ll have to get creative in your JavaScript selector:

$$('#item4 p').first().insert(...);
//rather than
$('member_bar').insert(...);

Walter


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

Walter,

Source Code Snooper did the trick! Thank you so much. I swear there must be an action for everything. Although I must say I haven’t found yet to make me coffee. :slight_smile:

The part about validating the user is really simple using sitelok. All I had to do was modify the code as follows

<?php if (sl_ismemberof("ADMIN")) print '		chunk-of-code-for-button'; ?>

and the button shows or not depending upon the user’s access rights.

Jim


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options