Back To Start Of Archive
Taken From The Forum: Help & Support for DHTML Menu Version 5+
Forum Topic: Click to view post
Last Updated: Saturday July 14 2012 - 06:07:52
Change menu at login
Poster: Maz
Dated: Tuesday December 16 2003 - 19:23:58 GMT
Hi all,
I now have the login set up on the menu, if I'm doing this right:
Code:
-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
Poster: Hergio
Dated: Wednesday December 17 2003 - 3:02:18 GMT
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.
Poster: Maz
Dated: Wednesday December 17 2003 - 4:14:48 GMT
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
Poster: kevin3442
Dated: Wednesday December 17 2003 - 19:09:58 GMT
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:
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;");
.
.
.
}
.
.
.
// 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
Poster: Maz
Dated: Wednesday December 17 2003 - 20:12:31 GMT
Thank you Kevin!
That did it, now the menu works, just have to figure out the rest.
maz
Poster: Maz
Dated: Wednesday December 17 2003 - 22:43:03 GMT
Kevin, I sent you an email, my volunteer doesn't know how the script sends the command to javascript
Thanks,
maz
Poster: kevin3442
Dated: Wednesday December 17 2003 - 23:45:50 GMT
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:
<script language=javascript>
var userIsMember = <?php echo $userStatus ?>;
<script>
var userIsMember = <?php echo $userStatus ?>;
<script>
-or-
Code:
<script language="javascript">
<?
echo("var userIsMember = ".$userStatus.";");
?>
</script>
<?
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.