Milonic provide full featured pull down web menus for some of the worlds largest companies
click here to see what it can do for you

Download Milonic DHTML Menu
Buy Milonic DHTML Menu

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:19

PHP Guru Needed - Milonic menu code using PHP 99% working!!


Poster: fiscus
Dated: Thursday July 15 2004 - 12:07:20 BST

Ok this is going to be a bit of a mouthful but here goes:

First up the basis behind this post stems from this thread http://www.milonic.com/forum/viewtopic.php?t=4570

My site has a fully working (and licensed) version of the milonic menu (5.33) which is menu driven. I am using a CMS system that allows me to formulate php codes into snippets which I can just call apon in pages & templates (by simplying using [[snippetname]]

Anyway....the reason for these posts is that my menu has issues with MAC I.E. The submenu offset is way off so I needed to fix this. I have read the info on this page and also the MAC specific stuff on this page

Ok so i know that I now have to render the sub menus first and then have the menu code in the table where I want it displayed.

As I mentioned above I am using some php code to generate the equivelent of my menu_data.js The code (which is my snippet) is currently this:


Code:
$MilonicMenu = "
<script>
_menuCloseDelay=500           // The time delay for menus to remain visible on mouse out
_menuOpenDelay=100            // The time delay before menus open on mouse over
_subOffsetTop=5
_subOffsetLeft=1

with(menuStyle=new mm_style()){
onbgcolor=\"#E78B00\";
oncolor=\"#6b6b74\";
offbgcolor=\"#e4e7eb\";
offcolor=\"#6b6b74\";
bordercolor=\"#e4e7eb\";
borderstyle=\"solid\";
borderwidth=1;
separatorcolor=\"#73726D\";
separatorsize=\"1\";
padding=5;
fontsize=\"11\";
fontstyle=\"normal\";
fontfamily=\"verdana\";
pagecolor=\"#F6F3F1\";
pagebgcolor=\"#A6A5AC\";
headercolor=\"#666666\";
headerbgcolor=\"#F6F3F1\";
overfilter=\"Fade(duration=0.2);Alpha(opacity=90);\";
outfilter=\"randomdissolve(duration=0.2)\";
}
with(milonic=new menuname(\"Main Menu\")){
position=\"relative\";
style=menuStyle;
alwaysvisible=1;
left=0;
itemwidth=120; ";


// OK, first we set the main menu up, by getting the documents in the root of the document tree.
$sql = "SELECT id, pagetitle, isfolder FROM $dbase.".$table_prefix."site_content WHERE $dbase.".$table_prefix."site_content.parent=0 AND $dbase.".$table_prefix."site_content.published=1 AND $dbase.".$table_prefix."site_content.deleted=0 ORDER BY $dbase.".$table_prefix."site_content.menuindex DESC;";
$rs = $db->Execute($sql);
$limit = $rs->RecordCount();
$menu1src=$rs->GetRows($limit);


for ($y = 0; $y < $limit; $y++) {
   if($menu1src[$y]['isfolder']==1) {
      $MilonicMenu.="aI(\"text=".$menu1src[$y]['pagetitle'].";showmenu=".$menu1src[$y]['pagetitle']."\");\n";
   } else {
      $MilonicMenu.="aI(\"text=".$menu1src[$y]['pagetitle'].";url=index.php?id=".$menu1src[$y]['id'].";status=".$menu1src[$y]['pagetitle']."\");\n";
   }       
}

$MilonicMenu.="
}
";

// now we loop throught he results again to get those document's children
for ($y = 0; $y < $limit; $y++) {
   $sql = "SELECT id, pagetitle FROM $dbase.".$table_prefix."site_content WHERE $dbase.".$table_prefix."site_content.parent=".$menu1src[$y]['id']." AND $dbase.".$table_prefix."site_content.published=1 AND $dbase.".$table_prefix."site_content.deleted=0 ORDER BY $dbase.".$table_prefix."site_content.menuindex DESC;";
   $rs2 = $db->Execute($sql);
   $limit2 = $rs2->RecordCount();
   if($limit2>0) {
      $MilonicMenu .= "with(milonic=new menuname(\"".$menu1src[$y]['pagetitle']."\")){
      style=menuStyle;
      overflow=\"scroll\";";
      for ($x = 0; $x < $limit2; $x++) {
         $menu2src=$rs2->FetchRow();
         $MilonicMenu.="aI(\"text=".$menu2src['pagetitle'].";url=index.php?id=".$menu2src['id'].";status=".$menu2src['pagetitle']."\");\n";   
      }
      $MilonicMenu.="
      }
      ";
   }
}

$MilonicMenu.="

drawMenus();

</script>
";



This is pretty much straight PHP code (apart from the $MilonicMenu.=" which are required for the snippet to work) and as I stated this code generated the fully working menu from the DB on my site.

The problem is that this ONE piece of code is gernerating all the config file...and now I have realised that I need to render the subs first and then the main meny in the table where I want it to be displayed.

So I need a PHP guru that can split this code into two sections. The first bit will be used to generate the subs code and the second part is to generate the main menu.

To distinguish between the two piece of code you will need to replace the $MilonicMenu for the new script name ie. $MilonicMenusubs and $MilonicMenuNoSubs (for this to work in the CMS I just have to call the snippet whatever the initial variable is).

Ruth was kind enough to post what I need to get as my output:
Code:
<BODY>
<SCRIPT language=JavaScript src="milonic_src.js"
type=text/javascript></SCRIPT>

<SCRIPT language=JavaScript>
if(ns4)_d.write("<scr"+"ipt language=JavaScript src=site/menu/mmenuns4.js><\/scr"+"ipt>");       
else _d.write("<scr"+"ipt language=JavaScript src=site/menu/mmenudom.js><\/scr"+"ipt>");
</SCRIPT>
<SCRIPT>
_menuCloseDelay=500           // The time delay for menus to remain visible on mouse out
_menuOpenDelay=100            // The time delay before menus open on mouse over
_subOffsetTop=5
_subOffsetLeft=1

with(menuStyle=new mm_style()){
onbgcolor="#E78B00";
oncolor="#6b6b74";
offbgcolor="#e4e7eb";
offcolor="#6b6b74";
bordercolor="#e4e7eb";
borderstyle="solid";
borderwidth=1;
separatorcolor="#73726D";
separatorsize="1";
padding=5;
fontsize="11";
fontstyle="normal";
fontfamily="verdana";
pagecolor="#F6F3F1";
pagebgcolor="#A6A5AC";
headercolor="#666666";
headerbgcolor="#F6F3F1";
overfilter="Fade(duration=0.2);Alpha(opacity=90);";
outfilter="randomdissolve(duration=0.2)";
}

with(milonic=new menuname("Courses & Classes")){
      style=menuStyle;
      overflow="scroll";aI("text=Current Classes;url=p42.html;status=Current Classes");
aI("text=Screenteens News;url=p54.html;status=Screenteens News");
aI("text=Workshop News;url=p55.html;status=Workshop News");
 
      }
      with(milonic=new menuname("Tutors")){
      style=menuStyle;
      overflow="scroll";aI("text=Denise Roberts;url=p21.html;status=Denise Roberts");
aI("text=Victoria Longley;url=p23.html;status=Victoria Longley");
aI("text=Tina Bursill;url=p27.html;status=Tina Bursill");
aI("text=Simon Burke;url=p28.html;status=Simon Burke");
aI("text=Lucy Bell;url=p29.html;status=Lucy Bell");
aI("text=Andrew McFarlane;url=p30.html;status=Andrew McFarlane");
aI("text=Nico Lathouris;url=p31.html;status=Nico Lathouris");
aI("text=Scott Hartford-Davis;url=p32.html;status=Scott Hartford-Davis");
aI("text=Stephen Wallace;url=p33.html;status=Stephen Wallace");
aI("text=Phillip Holder;url=p34.html;status=Phillip Holder");
aI("text=Tamblyn Lord;url=p35.html;status=Tamblyn Lord");
aI("text=Patrick Dickson;url=p36.html;status=Patrick Dickson");
aI("text=Roxane Wilson;url=p37.html;status=Roxane Wilson");
aI("text=Grant Bowler;url=p39.html;status=Grant Bowler");
aI("text=William Zappa;url=p40.html;status=William Zappa");
aI("text=Future Tutors;url=p41.html;status=Future Tutors");
 
      }
      with(milonic=new menuname("Links")){
      style=menuStyle;
      overflow="scroll";aI("text=studioCRE8;url=p44.html;status=studioCRE8");
aI("text=artConnect;url=p46.html;status=artConnect");
aI("text=Quiet on the Set;url=p47.html;status=Quiet on the Set");
aI("text=Australian Centre Of Performing Arts;url=p111.html;status=Australian Centre Of Performing Arts");
      }

drawMenus();
</SCRIPT>

<DIV align=center>
<TABLE cellSpacing=0 cellPadding=0 width=750 border=0><!--DWLayoutTable-->
  <TBODY>
  <TR>
    <TD vAlign=top colSpan=3 height=120>
      <TABLE cellSpacing=0 cellPadding=0 width="100%" border=0><!--DWLayoutTable-->
        <TBODY>
        <TR>
          <TD vAlign=top width=750 bgColor=#e6e7e2 height=100>
            <DIV align=left>
            <OBJECT title=screenwise
            codeBase=http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0
            classid=clsid:D27CDB6E-AE6D-11cf-96B8-444553540000 width=750
            height=100><PARAM NAME="movie" VALUE="site/header.swf"><PARAM NAME="quality" VALUE="high">
                                                            <embed
            src="site/header.swf" quality="high"
            pluginspage="http://www.macromedia.com/go/getflashplayer"
            type="application/x-shockwave-flash" width="750"
            height="100"></embed>              </OBJECT></DIV></TD></TR>
        <TR>
          <TD class=topspacer vAlign=top height=20><A
            href="http://screenwise.com.au/">Screenwise</A> ::
        <B>Home</B></TD></TR></TBODY></TABLE></TD></TR>
  <TR>
    <TD vAlign=top width=126 rowSpan=2>
      <TABLE cellSpacing=0 cellPadding=0 width="100%" bgColor=#e4e7eb border=0><!--DWLayoutTable-->
        <TBODY>
        <TR>
          <TD class=menu vAlign=top width=126 height=300>
            <SCRIPT> with(milonic=new menuname("Main Menu")){
position="relative";
style=menuStyle;
alwaysvisible=1;
left=0;
itemwidth=120; aI("text=Home;url=p1.html;status=Home");
aI("text=About Us;url=p7.html;status=About Us");
aI("text=Courses & Classes;showmenu=Courses & Classes");
aI("text=Tutors;showmenu=Tutors");
aI("text=Industry Heartbeat;url=p52.html;status=Industry Heartbeat");
aI("text=Studio Facilities;url=p9.html;status=Studio Facilities");
aI("text=Showreels;url=p10.html;status=Showreels");
aI("text=Testimonials;url=p51.html;status=Testimonials");
aI("text=Application Form;url=p105.html;status=Application Form");
aI("text=Search;url=p49.html;status=Search");
aI("text=Contact Us;url=p25.html;status=Contact Us");
aI("text=Links;showmenu=Links");
 
} drawMenus(); </script> </TD></TR></TBODY></TABLE></TD>
    <TD vAlign=top width=544 height=200>  and so on with the rest of the stuff on the page.


I hope I have explained everything correctly - if anyone can please help me it would be appreciated. I am very close to this but I just need this final step!!

Ultimately with these two bits of code (snippets) I can call on [[MilonicMenusubs]] directly under the body tag and then the [[MilonicMenuNosubs]] in the table where I want the menu to be displayed.

BTW the CMS is Phase if anyone is curious (probs the best CMS system there is!!)[/code]


Poster: Andy
Dated: Friday July 16 2004 - 11:05:29 BST

From what I can see, you are building the main menu and then the sub menus which is good.

I'm guessing that this code:

Code:
for ($y = 0; $y < $limit; $y++) {
   if($menu1src[$y]['isfolder']==1) {
      $MilonicMenu.="aI(\"text=".$menu1src[$y]['pagetitle'].";showmenu=".$menu1src[$y]['pagetitle']."\");\n";
   } else {
      $MilonicMenu.="aI(\"text=".$menu1src[$y]['pagetitle'].";url=index.php?id=".$menu1src[$y]['id'].";status=".$menu1src[$y]['pagetitle']."\");\n";
   }       
}


Can use a different variable name. Try changing it to $MilonicMainMenu so that you effectively have 2 php text strings. One containing the main menu, the other containing the subs. You can then echo these at the appropriate places within your HTML.

Hope this helps
Andy


Poster: fiscus
Dated: Sunday July 18 2004 - 11:10:57 BST

Thanks andy....I think I have got it sorted - just need someone with a MAC to test but after a couple of days of trial and error I have matched my output to the stuff Ruth gave me so I hope it is working.

Thanks