<?php
/**
 * OpenMage
 *
 * This source file is subject to the Academic Free License (AFL 3.0)
 * that is bundled with this package in the file LICENSE_AFL.txt.
 * It is also available at https://opensource.org/license/afl-3-0-php
 *
 * @category    design
 * @package     default_default
 * @copyright   Copyright (c) 2006-2020 Magento, Inc. (https://www.magento.com)
 * @copyright   Copyright (c) 2020-2022 The OpenMage Contributors (https://www.openmage.org)
 * @license     https://opensource.org/licenses/afl-3.0.php  Academic Free License (AFL 3.0)
 */

/** @var $this Mage_Adminhtml_Block_Page_Header */
?>
<div class="header-top">
    <a href="<?php echo $this->getHomeLink() ?>"><img src="<?php echo $this->getSkinUrl('images/logo.svg') ?>" alt="<?php echo Mage::helper('core')->quoteEscape($this->__('OpenMage Logo')) ?>" class="logo"/></a>
    <div class="header-right">
        <p class="super">
            <?php echo $this->__("Logged in as %s", $this->escapeHtml($this->getUser()->getUsername())) ?><span class="separator">|</span><a href="<?php echo $this->getLogoutLink() ?>" class="link-logout"><?php echo $this->__('Log Out') ?></a>
        </p>
        <?php if (Mage::getStoreConfigFlag('admin/global_search/enable') && Mage::getSingleton('admin/session')->isAllowed('admin/global_search')): ?>
        <fieldset>
            <legend>Search</legend>
            <span id="global_search_indicator" class="autocomplete-indicator" style="display: none">
                <img src="<?php echo $this->getSkinUrl('images/ajax-loader.gif') ?>" alt="<?php echo Mage::helper('core')->quoteEscape($this->__('Loading...')) ?>" class="v-middle"/>
            </span>
            <?php $defSearch = $this->__('Global Record Search') ?>
            <input id="global_search" name="query" type="text" class="input-text" value="<?php if(!empty($query)): ?><?php echo $query ?><?php else: ?><?php echo Mage::helper('core')->quoteEscape($defSearch) ?><?php endif ?>" onfocus="if(this.value=='<?php echo Mage::helper('core')->quoteEscape($defSearch, true) ?>')this.value=''; " onblur="if(this.value=='')this.value='<?php echo $defSearch ?>';" />
            <div id="global_search_autocomplete" class="autocomplete"></div>
            <script type="text/javascript">
                new Ajax.Autocompleter(
                    'global_search',
                    'global_search_autocomplete',
                    '<?php echo $this->getUrl('adminhtml/index/globalSearch') ?>',
                    {
                        paramName:"query",
                        minChars:2,
                        indicator:"global_search_indicator",
                        updateElement:getSelectionId,
                        evalJSON:'force'
                    }
                );
                function getSelectionId(li) {
                    location.href = li.getAttribute('url');
                }
            </script>
        </fieldset>
        <?php endif ?>
    </div>
</div>
