Changing menu item according to login state

Having problems with DHTML Menu? There is usually somebody here who knows the answer.
Post Reply
chet
Beginner
Beginner
Posts: 2
Joined: Sat May 21, 2005 9:38 am

Changing menu item according to login state

Post by chet »

Hi I am integrating milonic menu (follow scroll type menu) with my oscommerce shop.

The thing I would like to do is have a menu item which if a customer wishes to log in, the menu item reads "log in" (default) and if logged in, this then changes to "log out" and links to a file called logoff.php

Is this possible? - there are two associated php files for each function but how to add the logic or where to find it and implement it, i don't know.

Maybe someone familiar with oscommerce can help here.

Thanks
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 Chet,

I'm not too familiar with php or oscommerce, but I imagine the process would be similar to how you might do it with asp.

Most people's menu_data file is normally a static .js file. But you can use php commands in it by sending it through the php parser when the page is served; just name the file menu_data.php instead of menu_data.js. Now you can include php conditionals in with the menu's javascript. Like I said, I'm not too familiar with php, but I imagine that there must be a php session variable that you can test, like a UserName, to see if the user is logged in or not. If the user is not logged in, then generate the aI() menu item for logging in. If the user is logged in, generate the aI() item for logging out instead. In asp, I do something similar like so in menu_data.asp:

Code: Select all

with(milonic=new menuname("main")){
  style=styleMain;
  <%if session("UserName") & "" = "" then%>
    aI("text=Log In;url=login.asp;");
  <%else%>
    aI("text=Log out;url=logout.asp");
  <%end if%>
  aI("text=About Us;url=aboutus.asp");
  aI("text=Contact Us;url=contactus.asp");
}
The <%if...%> tests to see if the UserName session variable is blank. If it is blank, then the user is not logged in, and so the aI() item for logging in is generated. The <%else%> is true only if UserName isn't blank, which must mean that the user is logged in, so generate the aI() menu item for logging out.

This is in asp, by maybe that'll help you come up with similar php code.

Hope that helps,

Kevin
chet
Beginner
Beginner
Posts: 2
Joined: Sat May 21, 2005 9:38 am

Post by chet »

Thanks Kevin,

I think I have found the detect part by looking at a login box module.

Code: Select all

(!tep_session_is_registered('customer_id')) { 
but I dont think Ive the knowledge to implement the php within javascript.

could I just edit the menu_data.js javascript to include a php code i.e. put it inbetween <?php & ?> to mark the start and end of the php.
I've tried something like this but failed!
Post Reply