<?php
//v1.0.4 www.bcoos.net 2006/10 GPL
//v1.5 www.exoops.info 2006/03 
// $Id: system_menu.php,v 1.4 2003/03/19 07:04:15 half-dead Exp $
// ------------------------------------------------------------------------- //
//               E-Xoops: Content Management for the Masses                  //
//                       < http://www.e-xoops.com >                          //
// ------------------------------------------------------------------------- //
// Original Author: Kazumi Ono
// Author Website : http://www.mywebaddons.com/ , http://www.myweb.ne.jp
// License Type   : GPL: See /manual/LICENSES/GPL.txt
// ------------------------------------------------------------------------- //
//---------------------------------------------------------------------------------------//
/**
* Description
*
* @param type $var description
* @return type description
*/
function b_system_main_dynshow() {
global $db, $xoopsUser, $xoopsModule,$bcoosConfig;
$groups   = array();
$block    = array();
$sublinks = array();
$subcont  = array();
$groups   = $xoopsUser ? $xoopsUser->groups() : XoopsGroup::getByType('Anonymous');
$block['title']   = _MB_SYSTEM_MMENU;
$block['content'] = "
<script type='text/javascript'>
function toggle_dynmenu(id)  {
	if (xoopsGetElementById(id + '_sub')) {
		var dom = xoopsGetElementById(id + '_sub').style.display;
		if (dom == 'none') {
			xoopsGetElementById(id + '_sub').style.display = 'inline';
			xoopsGetElementById(id + '_sign').src   = '".XOOPS_URL."/images/icons/".$bcoosConfig['iconset']."menu_minus.gif';
			xoopsGetElementById(id + '_folder').src = '".XOOPS_URL."/images/icons/".$bcoosConfig['iconset']."menu_tree_open.gif';
			} else if (dom == 'inline') {
				xoopsGetElementById(id + '_sub').style.display = 'none';
				xoopsGetElementById(id + '_sign').src   = '".XOOPS_URL."/images/icons/".$bcoosConfig['iconset']."menu_plus.gif';
				xoopsGetElementById(id + '_folder').src = '".XOOPS_URL."/images/icons/".$bcoosConfig['iconset']."menu_tree_close.gif';
			}
	}
}
</script>";
$block['content'] .= "<img src='".XOOPS_URL."/images/icons/".$bcoosConfig['iconset']."menu_d_tree_home.gif' alt='' /> <a href='".XOOPS_URL."/'>"._MB_SYSTEM_HOME."</a>";
$sql    = '
		SELECT
		M.mid,
		M.dirname
		FROM
		'.$db->prefix('modules').' M,
		'.$db->prefix('groups_modules_link').' L
		WHERE M.hasmain=1
		AND M.isactive=1
		AND M.weight>0
		AND M.mid = L.mid
		AND L.groupid IN('.join(',', $groups).')
		GROUP BY M.dirname
		ORDER BY M.weight ASC';
$result = $db->query($sql);
while ($myrow = $db->fetchArray($result)) {
	if ( @file_exists(XOOPS_ROOT_PATH.'/modules/'.$myrow['dirname'].'/include/bcoos_module.php') ) {
		$module = new XoopsModule($myrow);
		if ($sublinks = $module->subLink()) {
			$subcont[] = $myrow['dirname'];
			$block['content'] .= "<br /><a href='javascript:toggle_dynmenu(\"".$myrow['dirname']."\");'><img id='".$myrow['dirname']."_sign' name='".$myrow['dirname']."_sign' src='".XOOPS_URL."/images/icons/".$bcoosConfig['iconset']."menu_minus.gif' align='absmiddle' border='0' /></a> ";
			$block['content'] .= $module->mainLink();
			$block['content'] .= "<span id='".$myrow['dirname']."_sub' name='".$myrow['dirname']."_sub' style='display:inline;'>";
			foreach($sublinks as $sublink) {
				$block['content'] .= "<br /> <img src='".XOOPS_URL."/images/icons/".$bcoosConfig['iconset']."menu_d_tree_content.gif' alt='' /> ".$sublink;
			}
			$block['content'] .= "</span>";
			} else {
				$block['content'] .= "<br /><img src='".XOOPS_URL."/images/icons/".$bcoosConfig['iconset']."menu_d_tree_close.gif' alt='' /> ".$module->mainLink()."\n";
			}
	}
}
if ( !empty($subcont) ) {
	$block['content'] .= "<script type='text/javascript'>\n";
	foreach($subcont as $value) {
		if (!$xoopsModule || ($xoopsModule->dirname() != $value)) {
			$block['content'] .= "toggle_dynmenu('$value');\n";
		}
	}
	$block['content'] .= "</script>";
}
return $block;
}
//---------------------------------------------------------------------------------------//
?>
