<?php
// $Id: system_menu.php,v 1.1 2004/07/11 10:29:03 Farsus Exp $
// -------------------------------------------------------------------------//
//			       RUNCMS                                                   //
//                                                                          //
//	 reliable - Unique - Nocost &  Simplicity & ease off use                //
//                       < http://www.runcms.org >                          //
// -------------------------------------------------------------------------//
//               System menu v1.22                                          //
// -------------------------------------------------------------------------//
// Original Author: Farsus
// Author Website : http://www.runcms.org/ , http://www.farsus.dk
// License Type   : LGPL: See /manual/LICENSES/LGPL.txt
// -------------------------------------------------------------------------//
// all color and optinal graphic exchange from  yourtheme/menu/menu_stylecss.//
/**
* Description
*
* @param type $var description
* @return type description
*/

function b_system_main_dynshow() {
global $db, $xoopsUser, $xoopsModule;

$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 expand_menu(id)  {
	if (xoopsGetElementById(id + '_submenu')) {
		xoopsGetElementById(id + '_submenu').style.display = 'inline';
	}
}

function collapse_menu(id)  {
	if (id != '".$dirname."') {
		if (xoopsGetElementById(id + '_submenu')) {
			xoopsGetElementById(id + '_submenu').style.display = 'none';
		}
	}
}
</script>";

$block['content'] .= "<span id='hmenu' class='top'><a href='".XOOPS_URL."/'>"._MB_SYSTEM_HOME."</a></span>";


$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->fetch_array($result)) {
	if ( @file_exists(XOOPS_ROOT_PATH.'/modules/'.$myrow['dirname'].'/xoops_version.php') ) {

		$module = new XoopsModule($myrow);
		$block['content'] .= "<span onmouseover,Duration=0.63='expand_menu(\"".$myrow['dirname']."\")' onmouseout,Duration=0.63='collapse_menu(\"".$myrow['dirname']."\")'>";

		if ($sublinks = $module->subLink()) {
			$subcont[] = $myrow['dirname'];
			// Main menu entry
			$block['content'] .= "<span id='hmenu' class='hmenu'>".$module->mainLink()."</span>";

			// Submenu entry, if any..
			$block['content'] .= "<span id='".$myrow['dirname']."_submenu' name='".$myrow['dirname']."_submenu' style='display:none;'>";
			foreach($sublinks as $sublink) {
				$block['content'] .= "<span id='hmenu2' class='sub'>$sublink</span>";
			}
			$block['content'] .= "</span>";
			} else {
				$block['content'] .= "<span id='hmenu' class='hmenu'>".$module->mainLink()."</span>";
			}
	$block['content'] .= "</span>";
	}
}

if ( !empty($subcont) ) {
	$block['content'] .= "<script type='text/javascript'>\n";
	foreach($subcont as $value) {
		if ($xoopsModule && ($xoopsModule->dirname() == $value)) {
			$block['content'] .= "expand_menu('$value');\n";
		}
	}
	$block['content'] .= "</script>";
}

unset($groups);
return $block;
}
?>
