<?php
require_once APPLICATION_PATH . '/modules/alw/views/helpers/Loadjs.php';
use Orchard\Service\SegmentAnalyticsTracking;
use Orchard\Feature\Feature;
use Orchard\FeatureFlags\FeatureService;
use Orchard\FeatureFlags\Context\AccountContext;

$translate = Zend_Registry::get("Zend_Translate");
$controller = Zend_Controller_Front::getInstance()->getRequest()->getControllerName();
$action = Zend_Controller_Front::getInstance()->getRequest()->getActionName();
$sessionData = new Zend_Session_Namespace('Alw');
$alwBannerDisplay = Feature::isEnabled('alw_banner_display', 'enabled');
$alwCxt = AccountContext::fromLegacy((string)$sessionData->S_VEND_CONTACT_ID, 'alw', $sessionData->S_VENDOR_ID);
$logger = Zend_Registry::get('applicationLoggerWS');
$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');
$loadjs = new Zend_View_Helper_loadjs();
?>
<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta charset="utf-8">
    <link rel="shortcut icon" href="<? echo $faviconImagePath ?>" type="image/x-icon">
<?php if (empty($this->removeGoogleAnalytics)) : ?>
<?php endif ?>
<?php
echo $this->headTitle() . "\n";
if ($sessionData->S_BROWSER_DETECT === true) {
    $this->headLink()->prependStylesheet('https://fonts.googleapis.com/css?family=Rubik:400,500');
}
echo $this->headLink() . "\n";
if ($sessionData->S_BROWSER_DETECT === true) { ?>
    <?php
        $jqueryPath = $loadjs->getCdnJsPath('jquery-1.8.2.min.js');
        $browserDetectPath = $loadjs->getCdnJsPath('browser-detect.js');
        $jqueryTablesorterPath = $loadjs->getCdnScriptPath('jquery/jquery.tablesorter.min.js');
        $tableRedesignPath = $loadjs->getCdnScriptPath('alw/table-redesign.js'); ?>
        <script type="text/javascript" src="<? echo $jqueryPath ?>"></script>
        <script type="text/javascript" src="<? echo $browserDetectPath ?>"></script>
        <script type="text/javascript" src="<? echo $jqueryTablesorterPath ?>"></script>
        <script type="text/javascript" src="<? echo $tableRedesignPath ?>"></script>
    <?php if ($alwBannerDisplay) {
            $topBannerPath = $loadjs->getCdnScriptPath('alw/top-banner.js'); ?>
            <script type="text/javascript" src="<? echo $topBannerPath ?>"></script>
    <?php }
}
echo $this->partial('partials/segment-analytics.phtml', array(
    'configs' => SegmentAnalyticsTracking::getTraitsFromSession($_SESSION, 'workstation')
));
?>
</head>
<body id="mainBody" class="<?php echo $controller . '-' . $action .($isBrandingEnabled ? ' branded' : '') .($isColorV2Enabled ? ' SuiteColorSchemeV2' : '') ?>">
<?php
    echo $this->partial('partials/subaccount_impersonation_banner.phtml', ['session', $_SESSION]);
?>
<noscript>Javascript appears to be turned off. In order to use this page, you must have it turned on.</noscript>
<?php if (isset($this->features)) { ?>
<script type="text/json" id="features">
    <?php echo json_encode($this->features); ?>
</script>
<?php } ?>
<?php if (isset($this->user)) { ?>
<script type="text/json" id="user_data">
    <?php echo json_encode($this->user); ?>
</script>
<?php } ?>

<?= $this->render('_header_redesign.phtml') ?>
    <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>
