11
Vargr
Re: Show main menus sub menus based on userlevel. Possible?
  • 2004/3/13 22:04

  • Vargr

  • Not too shy to talk

  • Posts: 130

  • Since: 2003/6/19


JackJ

Just tried your code again and now it worked. I guess this is a clear signal that I should go to bed now, as I obviously can't copy a few lines of code correctly...

Thank you for your help again.

12
JackJ
Re: Show main menus sub menus based on userlevel. Possible?
  • 2004/3/14 1:15

  • JackJ

  • Community Support Member

  • Posts: 747

  • Since: 2003/8/31


simonvl

Could you define what features you need in the menu/sub menu? Will the sub-menus appear for existing modules like news, or your own content pages module or whatever? Where will the sub-menus point to, pages wrapped in a module within xoops, or external links, or both

To achieve both requires different approaches. HTML is a better route for external links, or adding links to the smarty template in XOOPS etc

You could have a one page basic module (I have one for download at my site) and incorporate all the other links/sublinks from other modules into the xoops_version.php of this module as sublinks that appear when the destination page appears, and add some code to hide links from various groups like anon users.

Can't add external links doing it this way though, I dont think so anyway, unless anyone has some XOOPS variables that would add external sub links using the xoops_version.php

If you provide some specific specs, might be good project for the community to work on, as sub-menu questions arise quite often

For a trick of the eye HTML method seehttps://xoops.org/modules/newbb/viewtopic.php?topic_id=14712&forum=3#forumpost60550


13
simonvl
Error messages from hacking iMenu to get user levels and dynamic sub menus
  • 2004/3/22 21:32

  • simonvl

  • Just popping in

  • Posts: 44

  • Since: 2004/1/28


I use XOOPS 2.05

I have been adapting iMenu for my purposes, but have come across problems right near the end of my struggles which I cannot seem to fix. I have managed fine to adapt the admin section and the menu to display submenus as you can see at
www.chillout.org.uk.

However, I am having difficulties in making the sub menu items hide properly. I am going for a very simple approach, just basing it on the module rather than a full heirachical database-driven solution.

index.php
<?php

function b_imenu_show($options) {
        global 
$xoopsDB,$xoopsUser;
    
$myts =& MyTextSanitizer::getInstance();
        
$block = array();
    
$group is_object($xoopsUser) ? $xoopsUser->getGroups() : array(XOOPS_GROUP_ANONYMOUS);
        
$result $xoopsDB->query("SELECT groups, link, submenu, title, target FROM ".$xoopsDB->prefix("imenu")." WHERE hide=0 ORDER BY weight ASC");
    while ( 
$myrow $xoopsDB->fetchArray($result) ) {
        
$title $myts->makeTboxData4Show($myrow["title"]);
        if ( !
XOOPS_USE_MULTIBYTES ) {
            if (
strlen($myrow['title']) >= $options[0]) {
                
$title $myts->makeTboxData4Show(substr($myrow['title'],0,($options[0]-1)))."...";
            }
        }
        
$groups explode(" ",$myrow['groups']);
        if (
count(array_intersect($group,$groups)) > 0) {
            
$imenu['title'] = $title;
            
$imenu['target'] = $myrow['target'];
            
$imenu['link'] = $myrow['link'];
                                                    
$linkaddr explode("/"$imenu['link']);
                                                    
$linkmodule $linkaddr[2];
                                                    
$path getenv('REQUEST_URI');
                                                    
$var1 explode("."$path);
                                                    
$var2 explode("/"$var1[0]); 
                                                    
$presentmodule $var2[2];
                                                
$imenu['submenu'] = $myrow['submenu'];
                                                                       
            if (
eregi("^[([a-z0-9]+)]$"$myrow['link'], $moduledir)) {
                
$module_handler = & xoops_gethandler'module' );
                
$module =& $module_handler->getByDirname($moduledir[1]);
                if ( 
is_object$module ) && $module->getVar'isactive' ) ) {
                    
$imenu['link'] = XOOPS_URL."/modules/".$moduledir[1];
                }
            }
if (
$presentmodule == $linkmodule) {$submenushow "1";
$xoopsTpl->assign('submenushow'$submenushow);}

                    
$block['contents'][] = $imenu;
        }
        }
        return 
$block;
}

function 
b_imenu_edit($options) {
    
$form _IM_IMENU_CHARS."&nbsp;<input type='text' name='options[]' value='".$options[0]."' />&nbsp;"._IM_IMENU_LENGTH."";
    return 
$form;
}
?>


imenu_block.html
<table cellspacing="0">
  <
tr>
    <
td id="mainmenu">
<{
assign var="submenushow" value="0"}>
      <!-- 
start module menu loop -->
      <{foreach 
item=imenu from=$block.contents}>
        <{if ((
$imenu.link != "") AND ($imenu.submenu =="0"))}>
            <
class="menuMain" href="<{$imenu.link}>" target="<{$imenu.target}>"><{$imenu.title}></a>
        <{elseif ((
$imenu.link != "") AND ($imenu.submenu =="1") )}>
            <
class="menuSub" href="<{$imenu.link}>" target="<{$imenu.target}>"><{$imenu.title}></a>
        <{/if}>
      <{/foreach}>
      <!-- 
end module menu loop -->
    </
td>
  </
tr>
</
table>


Basically i picked out the /modulename/ part of the REQUEST_URI and then took the same bit out of the links. Then the idea is that if they are the same, I would make the variable $submenushow = 1 and in the smarty template, I would say <{if $submenushow == 1}> then display the sub menu item, else dont. Simple in concept, but I am not sure if I have done this bit correctly.

The problem arises when I try and use the code
if ($presentmodule == $linkmodule) {$submenushow "1";
$xoopsTpl->assign('submenushow'$submenushow);}


I get:
Quote:
Fatal error: Call to a member function on a non-object in /home/chillout/public_html/modules/iMenu/blocks/imenu.php on line 37


Furthermore, when I use
<{elseif (($imenu.link != "") AND ($imenu.submenu =="1") AND ($submenushow == 1))}>
            <
class="menuSub" href="<{$imenu.link}>" target="<{$imenu.target}>"><{$imenu.title}></a>
I get Quote:
Fatal error: Call to a member function on a non-object in /home/chillout/public_html/modules/iMenu/blocks/imenu.php on line 37


So I think there is an error in my coding in both of these files. Please can someone who is better at PHP help me. Thanks.
(my site may look fine because I have commented these tricky bits out to maintain functionality for now).

Simon

14
mrtwice
Re: Error messages from hacking iMenu to get user levels and dynamic sub menus
  • 2004/4/6 19:39

  • mrtwice

  • Just popping in

  • Posts: 9

  • Since: 2004/3/29


Have you packaged the module so that it can be installed? Have you posted the code in a place where I can access it?

Let me know and I will see if I can help you.

15
simonvl
Re: Error messages from hacking iMenu to get user levels and dynamic sub menus
  • 2004/4/7 14:32

  • simonvl

  • Just popping in

  • Posts: 44

  • Since: 2004/1/28


Thanks for replying. I have put a .zip package on my website. For some reason mydownloads won't show the file, so you have to use this link:
http://www.tallsimon.com/downloads/simons_iMenu_hack.zip

The bits I had difficulties with are commented out (perhaps not very helpfully documented, sorry its pre-alpha!!)

If you know of any, please suggest alternative ways to display submenu links when a visitor is viewing the main link. Should I use XOOPS [modulehandler]? Get the PATH_INFO or how?

Simon

16
mrtwice
Re: Error messages from hacking iMenu to get user levels and dynamic sub menus
  • 2004/5/20 12:23

  • mrtwice

  • Just popping in

  • Posts: 9

  • Since: 2004/3/29


Sorry about the delay, I have been "away" for a while :)

Are you still looking for help with this package?

mrtwice

Login

Who's Online

206 user(s) are online (122 user(s) are browsing Support Forums)


Members: 0


Guests: 206


more...

Donat-O-Meter

Stats
Goal: $100.00
Due Date: Mar 31
Gross Amount: $0.00
Net Balance: $0.00
Left to go: $100.00
Make donations with PayPal!

Latest GitHub Commits