<?php
use Orchard\Service\SegmentAnalyticsTracking;
use Orchard\FeatureFlags\FeatureService;
use Orchard\FeatureFlags\Context\AccountContext;

$sessionData = new Zend_Session_Namespace('Alw');

$logger = Zend_Registry::get('applicationLoggerWS');
$alwCxt = AccountContext::fromLegacy((string)$sessionData->S_VEND_CONTACT_ID, 'alw', $sessionData->S_VENDOR_ID);
$owsFeatureClient = new FeatureService($logger);
$isBrandingEnabled = $owsFeatureClient->isFeatureVariantActive('orchard_suite_use_branding', 'enabled', $alwCxt);
$isColorV2Enabled = $owsFeatureClient->isFeatureVariantActive('workstation_solfege_color_scheme_v2', 'enabled', $alwCxt);
$loadImage = new Alw_View_Helper_Loadingimage();
$faviconImagePath = $loadImage->getCdnImagePath('images/icons/favicon.ico');

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="shortcut icon" href="<? echo $faviconImagePath ?>" type="image/x-icon" />

<?php
echo $this->headMeta();
$this->loadcss();
$this->loadjs();
$script = '
     DD_roundies.addRule("#modalTrackDetails #content", "20px", true);
     DD_roundies.addRule("#modalWindow", "20px", true);
     DD_roundies.addRule(".ui-widget-content", "20px", true);
     startList = function() {
        if (document.all&&document.getElementById) {
            navRoot = document.getElementById("nav");
            for (i=0; i<navRoot.childNodes.length; i++) {
                node = navRoot.childNodes[i];
                if (node.nodeName=="LI") {
                    node.onmouseover=function() {
                        this.className+=" over";
                    }
                    node.onmouseout=function() {
                        this.className=this.className.replace(" over", "");
                    }
                }
            }
        }
    }

    if ((BrowserDetect.browser == "Explorer" && BrowserDetect.version >= 8)
        || (BrowserDetect.browser == "Mozilla" && BrowserDetect.version >= 1)
        || (BrowserDetect.browser == "Firefox" && BrowserDetect.version >= 3)
        || (BrowserDetect.browser == "Safari" && BrowserDetect.version >= 3)
        || (BrowserDetect.browser == "Chrome")
        ) {
        //do nothing
    } else {';
$sessionData = new Zend_Session_Namespace('Alw');
if ($sessionData->S_BROWSER_DETECT) {
    $script .= '
        var refUrl = encodeURIComponent($(document).context.location.pathname+$(document).context.location.search);
        window.location = "/index/browserdetect?ref="+refUrl;';
}
$script .= '
    } ';
?>
<?php
$this->inlineScript()->appendScript($script);

echo $this->headTitle(),
    $this->headLink(),
    $this->headStyle(),
    $this->headScript(),
    $this->inlineScript();

$useragent = $_SERVER['HTTP_USER_AGENT'];
if (preg_match('|MSIE ([0-9].[0-9]{1,2})|', $useragent, $matched)) {
    $browser_version = $matched[1];
    $browser = 'IE';
} elseif (preg_match('|Opera ([0-9].[0-9]{1,2})|', $useragent, $matched)) {
    $browser_version = $matched[1];
    $browser = 'Opera';
} elseif (preg_match('|Firefox/([0-9\.]+)|', $useragent, $matched)) {
    $browser_version = $matched[1];
    $browser = 'Firefox';
} elseif (preg_match('|Safari/([0-9\.]+)|', $useragent, $matched)) {
    $browser_version = $matched[1];
    $browser = 'Safari';
} else {
    // browser not recognized!
    $browser_version = 0;
    $browser = 'other';
}
$this->browser = $browser;
$translate = Zend_Registry::get("Zend_Translate");
?>

<!--[if lte IE 9]>
    <link href="/alw/styles/ie.css" media="screen" rel="stylesheet" type="text/css" >
    <script>
        (function ($) {
        var a = $.ui.mouse.prototype._mouseMove;
        $.ui.mouse.prototype._mouseMove = function (b) {
            if ($.browser.msie && document.documentMode >= 9) {
                b.button = 1
            };
            a.apply(this, [b]);
        }
        }(jQuery));
    </script>
<![endif]-->

<!--[if IE 9]>
    <link href="/alw/styles/ie9.css" media="screen" rel="stylesheet" type="text/css" >
<![endif]-->
<?php
if (!empty($_SESSION['S_VEND_CONTACT_ID'])) {
    echo $this->partial('partials/segment-analytics.phtml', array(
        'configs' => SegmentAnalyticsTracking::getTraitsFromSession($_SESSION, 'workstation')
    ));
}
?>
</head>
<!-- end head -->

<body id="mainBody" class="<?php echo ($isBrandingEnabled ? 'branded' : '') .($isColorV2Enabled ? ' SuiteColorSchemeV2' : '') ?>">

    <?php
        echo $this->partial('partials/subaccount_impersonation_banner.phtml', ['session', $_SESSION]);
    ?>
    <?= $this->render('_header_redesign.phtml', $this->featureVendorContext) ?>
    <div class="container fix-width-grid">
        <div class="row text-center">
            <div class="main-content">
                <?= $this->layout()->content ?>
                <div class="clear"></div>
            </div>
        </div>
    </div>
    <?= $this->render('_footer_redesign.phtml') ?>
    <?php
        // javascript apps
        echo $this->bottomScripts();
    ?>
</body>
</html>
