<?php
    $menu_search_url = Horde::applicationUrl('search.php');
    $menu_mailbox_url = Horde::applicationUrl('mailbox.php');
    $menu_allow_folders = ($conf['user']['allow_folders'] && isset($menu_folders));
?>
<link rel="search" href="<?php echo $menu_search_url ?>" />

<?php if ($menu_allow_folders): ?>
<form action="<?php echo $menu_mailbox_url ?>" method="get" name="menu">
<input type="hidden" name="no_newmail_popup" value="1" />
<?php endif; ?>
<table border="0" cellpadding="2" cellspacing="0" width="100%">
<tr>
  <td class="menu">

    <table border="0" width="100%">
      <tr>
<?php

/* IMP menu items */
Menu::printItem(Horde::addParameter($menu_mailbox_url, 'mailbox', 'INBOX'), _("INBOX"), 'folders/inbox.gif');
if (($imp['base_protocol'] != 'pop3') && $prefs->getValue('use_trash') && ($prefs->getValue('trash_folder') !== null) && $prefs->getValue('empty_trash_menu')) {
    $menu_trash_url = Horde::addParameter($menu_mailbox_url, 'thismailbox', IMP::preambleString() . $prefs->getValue('trash_folder'));
    $menu_trash_url = Horde::addParameter($menu_trash_url, 'actionID', 'empty_mailbox');
    $menu_trash_url = Horde::addParameter($menu_trash_url, 'return_url', IMP::getInitialUrl());
    Menu::printItem($menu_trash_url, _("Empty Trash"), 'empty_trash.gif', null, null, "return window.confirm('" . addslashes(_("Are you sure you wish to empty your trash folder?")) . "');", '__noselection');
}
Menu::printItem(IMP::composeLink(), _("Compose"), 'compose.gif');
if ($conf['user']['allow_folders']) {
    Menu::printItem(Horde::nocacheUrl(Horde::applicationUrl('folders.php')), _("Folders"), 'folders.gif');
}
Menu::printItem($menu_search_url, _("Search"), 'search.gif');
//if ($prefs->getValue('fetchmail_menu')) {
//    if ($prefs->getValue('fetchmail_popup')) {
//        Menu::printItem(Horde::applicationUrl('fetchmail.php'), _("Accounts"), 'fetchmail.gif', NULL, 'fetchmail', 'window.open(\'' . Horde::applicationUrl('fetchmail.php'). '\', \'fetchmail\', \'toolbar=no,location=no,status=yes,scrollbars=yes,resizable=yes,width=300,height=450,left=100,top=100\'); return false;');
//    } else {
//        Menu::printItem(Horde::applicationUrl('fetchmail.php'), _("Accounts"), 'fetchmail.gif');
//    }
//}
if ($prefs->getValue('filter_menuitem')) {
    Menu::printItem(Horde::applicationUrl('filterprefs.php'), _("Filters"), 'filters.gif');
}

/* Additional site-specific menu items */
Menu::siteLinks();

/* Preferences */
if (($conf['prefs']['driver'] != '') && ($conf['prefs']['driver'] != 'none')) {
    Menu::printItem(Horde::applicationUrl('prefs.php'), _("Options"), 'prefs.gif', $registry->getParam('graphics', 'horde'));
}

/* Online Help */
if (($help_link = Help::listLink('imp'))) {
    Menu::printItem($help_link, _("Help"), 'manual.gif', $registry->getParam('graphics', 'horde'));
}

/* Links to other Horde applications. */
Menu::appLinks();

/* Logout */
if ((Auth::getProvider() == 'imp') && $conf['menu']['display']) {
    $menu_logout_url = $registry->getParam('webroot', 'horde') . '/login.php';
    Menu::printItem(Horde::addParameter($menu_logout_url, 'reason', 'logout'), _("Logout"), 'logout.gif', $registry->getParam('graphics', 'horde'), '_parent');
} else {
    $menu_logout_url = Horde::applicationUrl('login.php');
    Menu::printItem(Horde::addParameter($menu_logout_url, 'reason', 'logout'), _("Logout"), 'logout.gif', $registry->getParam('graphics', 'horde'));
}

?>

        <td width="100%">&nbsp;</td>

<?php if ($menu_allow_folders): ?>
<?php $menu_view = $prefs->getValue('menu_view'); ?>
        <td class="light" align="center" nowrap="nowrap" valign="<?php echo ($menu_view == 'icon') ? 'middle' : 'bottom' ?>">
          <a class="menuitem" href="" onclick="folderSubmit(true); return false;" onmouseover="window.status='<?php echo _("Open Folder") ?>'; return true;" onmouseout="window.status=''; return true;">
<?php
if (($menu_view == 'icon') || ($menu_view == 'both')) {
    echo Horde::img('folders/folder_open.gif', _("Open Folder"));
    if ($menu_view == 'both') {
        echo '<br />';
    }
}
if ($menu_view != 'icon') {
    $accesskey = $prefs->getValue('widget_accesskey') ? Horde::getAccessKey(_("Open Folder")) : '';
    echo Horde::highlightAccessKey(_("Open Folder"), $accesskey);
}
?>
          </a>
        </td>
        <td class="light" align="right" nowrap="nowrap">
          <?php echo Horde::formInput() ?>
<?php if (isset($accesskey)): ?>
          <label for="mailbox" accesskey="<?php echo $accesskey ?>"></label>
<?php endif; ?>
          <select id="mailbox" name="mailbox" onchange="folderSubmit()"><?php echo $menu_folders ?></select>
        </td>
<?php endif; ?>

      </tr>
    </table>

  </td>
</tr>
</table>

<?php if ($menu_allow_folders): ?>
</form>
<script language="JavaScript" type="text/javascript">
<!--
var loading;
function folderSubmit(clear)
{
    if (document.menu.mailbox[document.menu.mailbox.selectedIndex].value != '') {
        if ((loading == null) || (clear != null)) {
            loading = true;
            document.menu.submit();
        }
    }
}
// -->
</script>
<?php endif; ?>
<br />
