<?php
// $Id: menubar.php,v 1.74 2004/01/13 00:57:16 eddieajau Exp $
/**
* Administrator menubar definition file
* @package Mambo Open Source
* @Copyright (C) 2000 - 2003 Miro International Pty Ltd
* @ All rights reserved
* @ Mambo Open Source is Free Software
* @ Released under GNU/GPL License: http://www.gnu.org/copyleft/gpl.html
* @version $Revision: 1.74 $
**/

// ensure this file is being included by a parent file
defined( '_VALID_MOS' ) or die( 'Direct Access to this location is not allowed.' );
require_once( "menubar/html/HTML_menubar.php" );

// cache some acl checks
$canConfig = $acl->acl_check( 'administration', 'config', 'users', $my->usertype );

$manageDB = $acl->acl_check( 'administration', 'manage', 'users', $my->usertype, 'components', 'com_dbadmin' );
$manageTemplates = $acl->acl_check( 'administration', 'manage', 'users', $my->usertype, 'components', 'com_templates' );
$manageLanguages = $acl->acl_check( 'administration', 'manage', 'users', $my->usertype, 'components', 'com_languages' );
$installModules = $acl->acl_check( 'administration', 'install', 'users', $my->usertype, 'modules', 'all' );
$editAllModules = $acl->acl_check( 'administration', 'edit', 'users', $my->usertype, 'modules', 'all' );
$installComponents = $acl->acl_check( 'administration', 'install', 'users', $my->usertype, 'components', 'all' );
$editAllComponents = $acl->acl_check( 'administration', 'edit', 'users', $my->usertype, 'components', 'all' );

$canMassMail = $acl->acl_check( 'administration', 'manage', 'users', $my->usertype, 'components', 'com_massmail' );
$canManageUsers = $acl->acl_check( 'administration', 'manage', 'users', $my->usertype, 'components', 'com_users' );

$database->setQuery( "SELECT COUNT(*) FROM #__messages WHERE state='0' AND user_id_to='$my->id'" );
$unread = $database->loadResult();
?>
<script language="JavaScript" type="text/javascript">
var myMenu =
[
	[null,'Site',null,null,'Site Menu',
<?php if ($canConfig) { ?>
		['<img src="../includes/js/ThemeOffice/config.png" />','Global Configuration','index2.php?option=com_config',null,'Configuration'],
<?php } ?>
		['<img src="../includes/js/ThemeOffice/mainmenu.png" />','Menu Manager',null,null,'Menu Manager',
			['<img src="../includes/js/ThemeOffice/mainmenu.png" />','Main Menu','index2.php?option=com_menus&menutype=mainmenu',null,'Main Levels'],
			['<img src="../includes/js/ThemeOffice/users.png" />','User Menu','index2.php?option=com_menus&menutype=usermenu',null,'Manage user menu'],
		],
		['<img src="../includes/js/ThemeOffice/preview.png" />','Preview','<?php echo $mosConfig_live_site; ?>','_blank','<?php echo $mosConfig_live_site; ?>'],
		['<img src="../includes/js/ThemeOffice/sysinfo.png" />', 'Statistics', null, null, 'Site Statistics',
			['<img src="../includes/js/ThemeOffice/sysinfo.png" />', 'Browser, OS, Domain', 'index2.php?option=com_statistics', null, 'Browser, OS, Domain'],
			['<img src="../includes/js/ThemeOffice/sysinfo.png" />', 'Page Impressions', 'index2.php?option=com_statistics&task=pageimp', null, 'Page Impressions'],
			['<img src="../includes/js/ThemeOffice/sysinfo.png" />', 'Search Text', 'index2.php?option=com_statistics&task=searches', null, 'Search Text']
		],
<?php if ($manageTemplates) { ?>
		['<img src="../includes/js/ThemeOffice/template.png" />','Template Manager','index2.php?option=com_templates',null,'Change site template'],
<?php } ?>
<?php if ($manageLanguages) { ?>
		['<img src="../includes/js/ThemeOffice/component.png" />','Language Manager','index2.php?option=com_languages',null,'Manage languages'],
<?php } ?>
<?php if ($canManageUsers || $canMassMail) { ?>
		['<img src="../includes/js/ThemeOffice/users.png" />','User Manager',null,null,'Manage users',
<?php	if ($canManageUsers) { ?>
			['<img src="../includes/js/ThemeOffice/edit.png" />','Add/Edit Users','index2.php?option=com_users&task=view',null,'Add/Edit Users'],
<?php	} ?>
<?php	if ($canMassMail) { ?>
			['<img src="../includes/js/ThemeOffice/mail.png" />','Mass Mail','index2.php?option=com_massmail',null,'Send an e-mail to a register user group']
<?php	} ?>
		],
<?php } ?>
	],
	_cmSplit,
	[null,'Content',null,null,'Content Management',
		['<img src="../includes/js/ThemeOffice/sections.png" />','Add/Edit Sections','index2.php?option=com_sections&scope=content',null,'Manage Sections'],
		_cmSplit,
		<?php $database->setQuery( "SELECT a.id, a.title, a.name,"
			. "\n	COUNT(DISTINCT c.id) AS numcat, COUNT(DISTINCT b.id) AS numarc"
			. "\nFROM #__sections AS a"
			. "\nLEFT JOIN #__categories AS c ON c.section=a.id"
			. "\nLEFT JOIN #__content AS b ON b.sectionid=a.id AND b.state<0"
			. "\nWHERE a.scope='content'"
			. "\nGROUP BY a.id"
			. "\nORDER BY a.ordering"
		);
		$types = $database->loadObjectList();
		foreach ($types as $type) {
			$txt = addslashes( $type->title ? $type->title : $type->name );
			?>
		['<img src="../includes/js/ThemeOffice/content.png" />','<?php echo $txt;?>', null, null,'<?php echo $txt;?>',
		<?php if ($type->numcat) { ?>
			['<img src="../includes/js/ThemeOffice/edit.png" />', '<?php echo $txt;?> Items', 'index2.php?option=content&sectionid=<?php echo $type->id;?>',null,null],
		<?php } ?>
			['<img src="../includes/js/ThemeOffice/categories.png" />', '<?php echo $txt;?> Categories', 'index2.php?option=categories&section=<?php echo $type->id;?>',null, null],
		<?php if ($type->numarc) { ?>
			['<img src="../includes/js/ThemeOffice/db.png" />', '<?php echo $txt;?> Archive', 'index2.php?option=content&task=showarchive&sectionid=<?php echo $type->id;?>',null,null],
		<?php } ?>
		],
		<?php
		} ?>
	],
	_cmSplit,
	[null,'Components',null,null,'Install/Uninstall',
<?php if ($installComponents) { ?>
		['<img src="../includes/js/ThemeOffice/install.png" />','Install/Uninstall','index2.php?option=component_installer',null,'Install/Uninstall components'],
		_cmSplit,
<?php } ?>
		<?php $database->setQuery( "SELECT * FROM #__components ORDER BY ordering,name" );
		$comps = $database->loadObjectList();	// component list
		$subs = array();	// sub menus
		// first pass to collect sub-menu items
		foreach ($comps as $row) {
			if ($row->parent) {
				if (!array_key_exists( $row->parent, $subs )) {
					$subs[$row->parent] = array();
				}
				$subs[$row->parent][] = $row;
			}
		}
		$topLevelLimit = 19; //You can get 19 top levels on a 800x600 Resolution
		$topLevelCount = 0;
		foreach ($comps as $row) {
			if ($editAllComponents | $acl->acl_check( 'administration', 'edit', 'users', $my->usertype, 
					'components', $row->option )) {
				if ($row->parent == 0 && (trim( $row->admin_menu_link ) || array_key_exists( $row->id, $subs ))) {
					$topLevelCount++;
					if ($topLevelCount > $topLevelLimit) {
						continue;
					}
					$name = addslashes( $row->name );
					$alt = addslashes( $row->admin_menu_alt );
					$link = $row->admin_menu_link ? "'index2.php?$row->admin_menu_link'" : "null";
					echo "\n	['<img src=\"../includes/$row->admin_menu_img\" />','$name',$link,null,'$alt'";
					if (array_key_exists( $row->id, $subs )) {
						echo ',';
						foreach ($subs[$row->id] as $sub) {//print_r($row);
							$name = addslashes( $sub->name );
							$alt = addslashes( $sub->admin_menu_alt );
							$link = $sub->admin_menu_link ? "'index2.php?$sub->admin_menu_link'" : "null";
							echo "\n		['<img src=\"../includes/$sub->admin_menu_img\" />','$name',$link,null,'$alt'],";
						}
					}
					
					echo "\n	],";
				}
			}
		}
		if ($topLevelLimit < $topLevelCount) {
			echo "\n		['<img src=\"../includes/js/ThemeOffice/sections.png\" />','More Components...','index2.php?option=com_admisc&task=listcomponents',null,'More Components'],\n";
		}
?>
	],
<?php if ($installModules | $editAllModules) { ?>
	_cmSplit,
	[null,'Modules',null,null,null,
<?php if ($installModules) { ?>
		['<img src="../includes/js/ThemeOffice/install.png" />', 'Install/Uninstall', 'index2.php?option=module_installer', null, 'Install custom modules'],
<?php } ?>
<?php if ($editAllModules) { ?>
		['<img src="../includes/js/ThemeOffice/edit.png" />', 'Manage Modules', "index2.php?option=Modules", null, 'Manage installed modules'],
<?php } ?>
	],
<?php } ?>
<?php if ($manageDB || $canConfig) { ?>
	_cmSplit,
	[null,'System',null,null,null,
	<?php if ($manageDB) { ?>
		['<img src="../includes/js/ThemeOffice/db.png" />','Database', null, null, 'Backup and restore your MOS site',
			['<img src="../includes/js/ThemeOffice/backup.png" />','Backup', 'index2.php?option=com_dbadmin&task=dbBackup', null, 'Backup'],
			['<img src="../includes/js/ThemeOffice/restore.png" />','Restore', 'index2.php?option=com_dbadmin&task=dbRestore', null, 'Restore'],
			['<img src="../includes/js/ThemeOffice/db.png" />','Query', 'index2.php?option=com_dbadmin&task=xquery', null, 'Exectue Query'],
		],
	<?php } ?>
	<?php if ($canConfig) { ?>
		['<img src="../includes/js/ThemeOffice/checkin.png" />', 'Global Checkin', 'index2.php?option=com_checkin', null,'Check-in all checked-out items'],
		['<img src="../includes/js/ThemeOffice/sysinfo.png" />', 'System Info', 'index2.php?option=com_admisc', null, 'System Info'],
	],
	<?php } ?>
<?php } ?>
	_cmSplit,
	[null,'Logout','index2.php?option=logout',null,'Logout'],
	_cmSplit,
	[null,'Help',null,null,null,
		['<img src="../includes/js/ThemeOffice/credits.png" />','Credits','index2.php?option=com_admisc&task=credits',null,'A big thanks to those involved'],
		['<img src="../includes/js/ThemeOffice/help.png" />', 'Help index', null, null, ' Mambo Open Source Help Index',
	<?php
		$database->setQuery( "SELECT a.id,a.title,COUNT(h.id) AS numcat"
			. "\nFROM #__categories AS a"
			. "\nLEFT JOIN #__help AS h ON h.catid = a.id"
			. "\nWHERE section='help'"
			. "\nGROUP BY a.id"
			. "\nORDER BY a.ordering"
		);
		$cats = $database->loadObjectList();	// component list
		foreach ($cats as $cat) {
			if ($cat->numcat) {
	?>
			['<img src="../includes/js/ThemeOffice/help.png" />','<?php echo $cat->title;?>','index2.php?option=com_help&file=index&catid=<?php echo $cat->id;?>',null,''],
	<?php
			}
		}
	?>
			['<img src="../includes/js/ThemeOffice/categories.png" />','Help Categories','index2.php?option=categories&section=help',null,'Manage Help Categories']
		],
		['<img src="../includes/js/ThemeOffice/tux.png" />','License','index2.php?option=com_admisc&task=license',null,'GNU/GPL License'],
		['<img src="../includes/js/ThemeOffice/help.png" />', 'Support', 'index2.php?option=com_admisc&task=support', null, 'Mambo Open Source Support']
	],
	_cmSplit,
	[null,'My Admin',null,null,'My Stuff',
		['<img src="../includes/js/ThemeOffice/content.png" />','Messaging',null,null,'Workflow',
			['<img src="../includes/js/ThemeOffice/config.png" />','Configuration','index2.php?option=com_messages&task=config',null,'Configuration'],
			['<img src="../includes/js/ThemeOffice/content.png" />','Inbox','index2.php?option=com_messages',null,'Private Messages']
		],
	]

];

</script>
<table width="100%" class="menudottedline" cellpadding="0" cellspacing="0" border="0">
  <tr>
    <td class="menubackgr"><div id="myMenuID"></div>
      <script language="JavaScript" type="text/javascript">
	cmDraw ('myMenuID', myMenu, 'hbr', cmThemeOffice, 'ThemeOffice');
	</script>
    </td>
    <?php
// Get no. of users online not including current session
$query = "SELECT count(session_id) FROM #__session"
."\n WHERE '$session_id' <> session_id";
$database->setQuery($query);
$online_num=$database->loadResult();
?>

  </tr>
</table>
<table width="100%" class="menubar" cellpadding="0" cellspacing="0" border="0">
  <tr>
    <td width="45%" class="menudottedline" height="37">&nbsp;
    </td>
    <td class="menudottedline">
      <?php
		if ($path = $mainframe->getPath( "toolbar" )) {
			include_once( $path );
		}
?>
    </td>
  </tr>
</table>
<table width="100%" class="menudottedline" cellpadding="0" cellspacing="0" border="0">
  <tr class="menubackgr">
    <td class="smallgrey" width="50%">&nbsp;&nbsp;<strong><?php echo $mosConfig_sitename;?></strong>
    <span class="small">
    <?php
    if ($option!='') {
		    echo " / ".$option;
    }

    if ($task!='') {
    echo " / ".$task;
    }
    ?>
    </span></td>

    <td align="right" class="smallgrey">&nbsp;Logged in as <strong><?php echo $my->username;?></td>
    <td align="right" class="smallgrey">&nbsp;<?php if ($unread) { ?><a href="index2.php?option=com_messages"> <?php } ?><?php echo $unread; ?> unread messages<?php if ($unread) { ?></a> <?php } ?>&nbsp;&nbsp;</td>
    <td align="right" class="smallgrey">&nbsp;<?php echo $online_num; ?> users online&nbsp;&nbsp;</td>
  </tr>
</table>
<br />
