Change menu at login

Having problems with DHTML Menu? There is usually somebody here who knows the answer.
Post Reply
User avatar
Maz
Milonic God
Milonic God
Posts: 1717
Joined: Fri Jun 06, 2003 11:39 pm
Location: San Francisco
Contact:

Change menu at login

Post by Maz »

Hi all,

I now have the login set up on the menu, if I'm doing this right:

Code: Select all


-snipet-

aI("text=Membership;showmenu=membership;pointer=arrow;status=submenu membership info;image=/template/main/images/xsitemember.gif;imagealt=membership;");
if( userIsGuest )
{
aI("text=Members Login;showmenu=memberlogin;pointer=arrow;status=submenu member login;image=/template/main/images/xmemberarea.gif;imagealt=member login;");
}
if( userIsMember )
{
aI("text=Members Area;showmenu=memberarea;pointer=arrow;status=submenu member area;image=/template/main/images/xmemberarea.gif;imagealt=member area;");
}
aI("text=Print;url=javascript:self.print('');status=link print;image=/template/main/images/xprint.gif;imagealt=print;");

-sniped-
Do I have to use more javascript to define the user php login?
Or can I change how it says userIsmember?

Sorry I don't know this stuff.

Thanks,
maz
User avatar
Hergio
Milonic God
Milonic God
Posts: 1123
Joined: Wed Jun 12, 2002 7:46 pm
Location: Rochester, NY

Post by Hergio »

That all looks fine, you just need to put in code that determines whether the user is a member or not (maybe by querying a database) and then you set the userIsMember variable to true or false based on that.
Dave Hergert
Software Engineer
"Helping to make the menu better, one :?: at a time."
User avatar
Maz
Milonic God
Milonic God
Posts: 1717
Joined: Fri Jun 06, 2003 11:39 pm
Location: San Francisco
Contact:

Post by Maz »

Dave,

Right now the menu fails because it doesn't know what it means, and I'm thinking it would be better if it never failed for the guest menu.

Can I change to IsMember first, or use this... without further requests. Or will that change the way it works when it IS set up?

If I leave Guest () empty will it fail to start the menu item?

Thank you,
maz
User avatar
kevin3442
Milonic God
Milonic God
Posts: 2460
Joined: Sat Sep 07, 2002 12:09 am
Location: Lincoln, NE
Contact:

Post by kevin3442 »

Hi Maz,

Two things: (1) I'm not sure where userIsMember is getting set. Are you in fact setting that based on previous conditionals that we don't see? (2) There are two conditionals in your code snippet. One would make more sense, and would also more easily allow you to define a default state. For example, let's just use userIsMember as a flag, and forget about userIsGuest. We'll set userIsMember to 0 (false = off = no), or simply not set it (but that's sloppy), so that the default state of the system is to assume that the user is NOT a member. Hence, the Login menu item will show by default, until the user logs in, at which time we will set userIsMember to 1 (true = on = yes). Like so:

Code: Select all

var userIsMember = false; // set toward top of menu_data.js
.
.
.
// typical start to menu definition
with(milonic=new menuname("menuname")){
style=menuStyle;
.
.
.
aI("text=Membership;showmenu=membership;pointer=arrow;status=submenu membership info;image=/template/main/images/xsitemember.gif;imagealt=membership;");
if (userIsMember) {
  aI("text=Members Area;showmenu=memberarea;pointer=arrow;status=submenu member area;image=/template/main/images/xmemberarea.gif;imagealt=member area;");
}
else {
  aI("text=Members Login;showmenu=memberlogin;pointer=arrow;status=submenu member login;image=/template/main/images/xmemberarea.gif;imagealt=member login;");
}
aI("text=Print;url=javascript:self.print('');status=link print;image=/template/main/images/xprint.gif;imagealt=print;");
.
.
.
}
The login script would have to set userIsMember to true. The other thing to consider... if you are using a js variable to keep track of the user's status (i.e., userIsMember), that variable, even if global, goes out of scope when the user leaves the current page, unless you do something to preserve it. In other words, you will want to preserve the user's status -- the value of userIsMember -- across pages, so that the user does not have to log into each page. I don't know how you are doing that, or if you have yet planned on doing that. There are several ways you can do that, including storing the value in a hidden frame, using a cookie (which will require that the user has cookies on, but also makes automatic login on future visits easy), or passing it from page to page in the url.

Hope that helps,

Kevin
User avatar
Maz
Milonic God
Milonic God
Posts: 1717
Joined: Fri Jun 06, 2003 11:39 pm
Location: San Francisco
Contact:

Post by Maz »

Thank you Kevin! :D

That did it, now the menu works, just have to figure out the rest.

maz
User avatar
Maz
Milonic God
Milonic God
Posts: 1717
Joined: Fri Jun 06, 2003 11:39 pm
Location: San Francisco
Contact:

Post by Maz »

Kevin, I sent you an email, my volunteer doesn't know how the script sends the command to javascript :oops:

Thanks,
maz
User avatar
kevin3442
Milonic God
Milonic God
Posts: 2460
Joined: Sat Sep 07, 2002 12:09 am
Location: Lincoln, NE
Contact:

Post by kevin3442 »

Hi Maz, Justin,

Don't know if you want to do this here, or email, so I posted this to both:

Unfortunately, I am not a php user. I have dabbled, but have yet to really do anything substantial with it. So this might be the blind leading the blind.

It seems that what is needed is a way to set the userIsMember js variable from the php script. Can you create a global variable in php? If so, suppose you call it $userStatus. $userStatus would be set to true or false (1 or 0 will do) in the php login script... 1 if logged in, 0 if not. You could probably then use a php echo to get the value of $userStatus into the js userIsMember variable. Maybe something like this:

Code: Select all

<script language=javascript>
var userIsMember = <?php echo $userStatus ?>;
<script>
-or-

Code: Select all

<script language="javascript">
<?
  echo("var userIsMember = ".$userStatus.";");
?>
</script> 
If you're generating the entire page with php, I suppose you'd have to echo the <script> tag lines as well. These script lines could be included in the main page or, probably, into the top of the menu_data.js file (without the <script> tags, of course).

Another possibility might be to have the php script store the value of $userStatus in a hidden form field, then set the value of the js variable userIsMember from the contents of that hidden field; using the hidden field as a temporary holding place to pass the data between php and js. I have no idea how to set a hidden field's value from php, but if you can do that, then I can tell you how to read the value out of the field using js. I might try the more direct methods above first.

Kevin

P.S. It occurs to me that you could also generate the entire menu_data script from php, which might be the easier way to go if you're going to be doing much more dynamic menu generating.
Post Reply