<?php
use Orchard\Feature\Feature;
use Orchard\FeatureFlags\FeatureService;
use Orchard\FeatureFlags\Context\AccountContext;

$logger = Zend_Registry::get('applicationLoggerWS');
$owsFeaturesServiceClient = new FeatureService($logger);

$isSupportContactEmailEnabled = Feature::isEnabled('support_contact_email', 'enabled');
$helpcenterUrl = Zend_Registry::get('configuration')->helpcenterUrl;
$sessionData = new Zend_Session_Namespace('Alw');
$this->userVendorContext = AccountContext::fromLegacy(
    (string)$sessionData->S_VEND_CONTACT_ID,
    'alw',
    $sessionData->S_VENDOR_ID
);

$isHelpcenterAutoLoginEnabled =  $owsFeaturesServiceClient->isFeatureVariantActive('helpcenter_auto_login', 'enabled', $this->userVendorContext);
$isBrandingEnabled = $owsFeaturesServiceClient->isFeatureVariantActive('orchard_suite_use_branding', 'enabled', $this->userVendorContext);
$isFullReactFooterEnabled = $owsFeaturesServiceClient->isFeatureVariantActive('workstation_use_full_react_footer', 'enabled', $this->userVendorContext);

if ($isHelpcenterAutoLoginEnabled) {
    $helpcenterUrl = '/helpcenter/';
} else if (!empty($_SESSION['S_LANGUAGE'])) {
    $workstationLanguage = $_SESSION['S_LANGUAGE'];
    $helpcenterUrl = $helpcenterUrl . '?lang=' . $workstationLanguage;
}
?>

<?php if ($isFullReactFooterEnabled) { ?>
	<div id="react_footer_app"></div>
<?php } else { ?>
<footer id="footer" class="footer-main fix-width-grid">
	<div class="hidden-print">
		<?php
		/** get users OA contact Info */
		$sessionData = new Zend_Session_Namespace('Alw');
		$model_vendor = NULL;
		$contactText = "Support contact:";
		$assignedToEmail = '';
		if (Zend_Registry::get('UserObj')->isAllowed ("","","footercontactemail")) {// Shows subaccount Contact Info
			if (!empty($sessionData->subaccount_contact_email)) {
				$assignedToEmail = $sessionData->subaccount_contact_email;
			} else {
				$contactText = "If you need assistance, please contact your distributor.";
			}
		} else {// Shows DA and Non-DA Conatct Info
			$vendor_id = $sessionData->S_VENDOR_ID;
			$model_vendor = Model_Vendor::getVendorWithAssignedToByVendorID($vendor_id);
                       if ($isSupportContactEmailEnabled && isset($model_vendor->support_contact_email) && $model_vendor->support_contact_email) {
                               $assignedToEmail = $model_vendor->support_contact_email;
                       } elseif (isset($model_vendor->AssignedTo->email) && $model_vendor->AssignedTo->email) {
				$assignedToEmail = $model_vendor->AssignedTo->email;
			} else {
				$assignedToEmail = 'clientservices@theorchard.com';
			}
		}
		?>
		<?php if (!$isBrandingEnabled) { ?>
			<?php if (isset($sessionData->vendor_icon_path)) {?>
				<img src="/images/redesign/powered-by.svg">
			<?php } else {?>
				<img src="/images/redesign/logo-footer.svg">
			<?php }
		} ?>
		<p>
			<?=$this->translate->_($contactText)?>
			<a onClick="event.stopPropagation();" href="mailto:<?=$assignedToEmail?>"><?=$assignedToEmail?></a>
			<?php if (isset($model_vendor->AssignedTo)) { ?> | <?=$model_vendor->AssignedTo->office_phone?> <?php } ?>
				<a href="<?php echo $helpcenterUrl; ?>"><?=$this->translate('workstation help')?></a> |
				<a href="/legal/privacy"><?=$this->translate('privacy policy')?></a> |
				<a href="/legal/terms"><?=$this->translate('terms and conditions')?></a>
		</p>
		<p><?=$this->translate->_("Copyright")?> &copy; <?=date("Y")?> <?=$this->translate->_("Orchard Enterprises NY, Inc.")?></p>
		<?php if (!$isBrandingEnabled) { ?>
		<p><?=$this->translate->_("The Orchard is a registered trademark and The Orchard logo is a service mark of Orchard Enterprises NY, Inc. All Rights Reserved.")?></p>
		<?php }?>
    </div>
</footer>
<?php } ?>
