<?php
require_once APPLICATION_PATH . '/modules/alw/views/helpers/Loadingimage.php';
require_once APPLICATION_PATH . '/modules/alw/views/helpers/Loadjs.php';

use Orchard\Feature\Feature;
use Orchard\FeatureFlags\FeatureService;
use Orchard\FeatureFlags\Context\AccountContext;

$loadCdnImage = new Alw_View_Helper_Loadingimage();
$loadJs = new Zend_View_Helper_loadjs();

$jQueryCdnScript = $loadJs->getCdnAlwScriptPath('jquery.autocomplete.js');
$loadingGif = $loadCdnImage->getCdnAlwImagePath('/images/loading.gif');
$noArtworkPng = $loadCdnImage->getCdnAlwImagePath('/images/noArtwork.png');
$statusCheckPng = $loadCdnImage->getCdnAlwImagePath('/images/icons/statusCheck-homepage.png');
$statusXPng = $loadCdnImage->getCdnAlwImagePath('/images/icons/statusX-homepage.png');
$marketingPng = $loadCdnImage->getCdnAlwImagePath('/images/icons/marketing.png');
$deliveryPng = $loadCdnImage->getCdnAlwImagePath('/images/icons/delivery.png');
$analyticsPng = $loadCdnImage->getCdnAlwImagePath('/images/icons/analytics.png');
$accountingPng = $loadCdnImage->getCdnAlwImagePath('/images/icons/accounting.png');

$logger = Zend_Registry::get('applicationLoggerWS');
$alwSalesStartDateEnabled = Feature::isEnabled('alw_sales_start_date', 'enabled', $this->featureVendorContext);
$workstationAccountingPeriodEnabled = Feature::isEnabled('workstation_accounting_period', 'enabled', $this->featureVendorContext);

$userContext = AccountContext::fromLegacy((string)$_SESSION['S_VEND_CONTACT_ID'], 'alw');
$owsFeaturesServiceClient = new FeatureService($logger);
$isDeprecateDeleteFromLegacyCatalogPageEnabled = $owsFeaturesServiceClient->isFeatureVariantActive(
    'deprecate_delete_from_legacy_catalog_page',
    'enabled',
    $userContext
);

//Get userObj from registry for application user
$userObj = $this->userObj;
$validator = $this->validator;
if ($userObj->isWorkstationExperienceFilm()) {
    $searchPlaceholder = $this->translate('i.e. Release, Collection, or UPC');
} elseif ($userObj->isWorkstationExperienceTV()) {
    $searchPlaceholder = $this->translate('i.e. Release, Volume, or UPC');
} else {
    $searchPlaceholder = $this->translate('i.e. Album, Artist, UPC or CAT#');
}
$conflictManagerFeatureFlagEnabled = Feature::isEnabled('alw_conflict_manager', 'enabled', $this->featureVendorContext);
$catalogToConflictManagerUrlUpdateFeatureEnabled = Feature::isEnabled('catalog_to_conflict_manager_url_update', 'enabled', $this->featureVendorContext);
$projectManagerFeatureEnabled = Feature::isEnabled('project_manager', 'enabled', $this->featureVendorContext);
$projectManagerUIEnabled = $userObj->isAllowed('', '', 'uiproject');
$projectManagerEnabled = $projectManagerFeatureEnabled && $projectManagerUIEnabled;
$workstationCatalogPageDelete = Feature::isEnabled('workstation_catalog_page_delete', 'enabled', $this->featureVendorContext);
$panelDefault = 'panel-default';
$panelTitle = 'panel-title';
$isAccountingNavigationEnabled = $userObj->isAllowed('', '', 'navaccounting');
$loadingBtnLoader = $this->loader('loadingbtn');
?>
<div id="loading_image" class="notDisplay">
    <div class="modalLoading">
        <center>
            <b><?=$this->translate('LOADING...')?></b><br />
            <img src="<?= $loadingGif ?>"/>
        </center>
    </div>
</div>
<script src="<?= $jQueryCdnScript ?>"></script>
<script type="text/javascript">
    var releaseData = '';
    var artistData = '';
    var subgenreRows = 0;
    var genre_id = '';
    var error_releases = new Object();
    var correction = 'false';
    var numberOfCheckbox = 0; // INIT FOR SELECT ALL/NONE CHECKBOX FN, TO WORK WITH FILTERS
    var filterType = '<?php echo implode(',', $this->filterType); ?>';
    var subaccountId = '<?=((isset($this->subacc_id) && $this->subacc_id > 0) ? $this->subacc_id : '0')?>';
    var subAccParam = '';
    if (subaccountId > 0) {
        subAccParam = '&subacc_id=' + subaccountId;
    }
    var artistId = '<?=((isset($this->artist_id) && $this->artist_id > 0) ? $this->artist_id : '0')?>';
    var artistParam = '';
    if (artistId > 0) {
        artistParam = '&artist_id=' + artistId;
    }
    $(document).ready(function () {
        $('#apply_filters').click(filterReleaseResult);
        $('#search_release_inputbox').keydown(function (e) {
            //Execute filter if user presses enter in filter box
            if (e.which == 13) {
                e.preventDefault();
                filterReleaseResult();
            }
        });

        //Toggle display of filter checkboxes
        function closeStatusFilter(e) {
            var container = $('.dropdown__list:visible');
            if (!container.is(e.target) && container.has(e.target).length === 0) {
                container.hide();
            }
            //Prevent from firing unless status box is being displayed
            $(document).unbind('mouseup', closeStatusFilter);
        }

        //Toggle Display of filter checkboxes change event
        function getcheckvalue(e) {
            var container = $('.dropdown__list:visible');
            var filterCheckboxes = $(e).find('input[type=checkbox]');
            var filterDisplayNames = [];
            var dropdown = $(e).prev();
            if (!container.is(e.target) && container.has(e.target).length === 0) {
                container.find('input:checkbox:checked').each(function (i, selected) {
                    var checkboxId = $(selected).attr('id');
                    var label = $('label[for="' + checkboxId + '"]').text();
                    filterDisplayNames[i] = label;
                });
                dropdown.html(filterDisplayNames.join(', '));
                if (filterCheckboxes.length === filterCheckboxes.filter(':checked').length) {
                    dropdown.html('All Selected');
                } else if (filterCheckboxes.filter(':checked').length == 0) {
                    dropdown.html('None Selected');
                }
            }
        }

        $('#status-checkbox-filters input[type=checkbox]').change(function () {
            getcheckvalue('#status-checkbox-filters');
        });
        $('#product-checkbox-filters input[type=checkbox]').change(function () {
            getcheckvalue('#product-checkbox-filters');
        });
        $('#filterBox').click(function () {
            $('#status-checkbox-filters').show();
            $(document).mouseup(closeStatusFilter);
        });
        $('#productFilterBox').click(function () {
            $('#product-checkbox-filters').show();
            $(document).mouseup(closeStatusFilter);
        });
    });
</script>

<!-- Start Left Side Content -->

<div id="content" onload="loadDashboard()">
    <div id="submmary">
        <a href="/catalog" class="albumName">← CATALOG OVERVIEW</a>
        <p style="font-size: 20px; margin-top: 20px;">
            Bulk Product Actions
        </p>
        <p style="background-color: #fefbea; padding: 10px; margin-top: 15px;">
            <span style="font-weight: bold;">Please note you are viewing a legacy version of the Catalog Page</span>
            <br>
            This page is solely intended for submitting and deleting products in bulk.
        </p>
    </div>
    <?php
    $items = array();
    if ($validator->isValid(array('resource' => 'index', 'privilege' => 'viewexareleases'))) {
        if ($projectManagerEnabled) {
            array_push($items, array($this->translate('Projects'), '/projects'));
        }
        if ($projectManagerEnabled) {
            array_push(
                $items,
                array(
                    $this->translate('Products'),
                    '/index/viewexareleases?filterType=delivered,submitted,in_progress,error_correction,rejected&productType=1,2,3,5&release_date=desc',
                    true
                )
            );
        } else {
            array_push(
                $items,
                array(
                    $this->translate('Releases'),
                    '/index/viewexareleases?filterType=delivered,submitted,in_progress,error_correction,rejected&productType=1,2,3,5&release_date=desc',
                    true
                )
            );
        }
    }
    if ($userObj->isAllowed('', '', 'navartistbuilder')
        && $validator->isValid(array('resource' => 'artistinfo', 'privilege' => 'index'))) {
        array_push($items, array($this->translate('Artists'), '/artist/index'));
    }
    if ($userObj->isAllowed('', '', 'uiproject') && $conflictManagerFeatureFlagEnabled) {
        $conflictsUrl = '/conflicts';
        if ($catalogToConflictManagerUrlUpdateFeatureEnabled) {
            $conflictsUrl .= '/new';
        }
        array_push($items, array('Conflicts', $conflictsUrl));
    }
    echo $this->partial('partials/sub-nav.phtml', array('items' => $items));
    ?>

    <!-- Your Recent Releases Module -->
    <div class="modContainerReleases">
        <!-- Start Module Body -->
        <div class="modBodyReleases">
            <div  id="view_exarelease_listing">
                <form id="view_exarelease_form">
                    <div class="filter-bottom-space">
                    <div id="view-releases-filters" class="float-left">
                        <div id="filter-term" class="float-left">
                            <label><?=$this->translate('Filter By Term')?>:</label>
                            <div id="filterTerm" action="" class="filter-dropdown">
                                <input id="search_release_inputbox" class="form-control" placeholder="<?=$searchPlaceholder?>" value="<?=$this->search_term?>">
                            </div>
                        </div>
                        <div id="filter-status" class="float-left">
                            <label><?=$this->translate('Filter By Status')?>:</label>
                            <div id="filterBox" action="" class="filter-dropdown">
                                <button type="button" class="btn btn-mini dropdown__toggle button-arrow" id="status-filters">
                                <?php
                                $filterContent = '';
                                $allTypes = array('delivered', 'submitted', 'in_progress', 'error_correction', 'rejected');
                                $allDisplayTypes = array(
                                    'delivered' => 'Delivered',
                                    'submitted' => 'Submitted',
                                    'in_progress' => 'In Progress',
                                    'error_correction' => 'In Correction',
                                    'rejected' => 'Action Required');
                                if (count($this->filterType) == 0) {
                                    $filterContent = 'Select a status';
                                } elseif (count(array_diff($allTypes, $this->filterType)) == 0) {
                                    $filterContent = $this->translate('All Selected');
                                } else {
                                    $displayArr = array();
                                    foreach ($this->filterType as $filter) {
                                        if (isset($allDisplayTypes[$filter])) {
                                            $displayArr[$filter] = $allDisplayTypes[$filter];
                                        }
                                    }
                                    $filterContent = implode(', ', $displayArr);
                                }
                                echo $filterContent; ?>
                                </button>
                                <ul id="status-checkbox-filters" class="dropdown__list list-unstyled" style="display:none;">
                                    <li class="checkbox">
                                        <input type="checkbox" name="filterType" id="delivered_check" value="delivered"
                                        <?=in_array('delivered', $this->filterType) ? 'checked="checked"' : ''?>/>
                                        <label for="delivered_check"><?=$this->translate('Delivered')?></label>
                                    </li>
                                    <li class="checkbox">
                                        <input type="checkbox" name="filterType" id="submitted_check" value="submitted"
                                        <?=in_array('submitted', $this->filterType) ? 'checked="checked"' : ''?> />
                                        <label for="submitted_check"><?=$this->translate('Submitted')?></label>
                                    </li>
                                    <li class="checkbox">
                                        <input type="checkbox" name="filterType" id="progress_check" value="in_progress"
                                        <?=in_array('in_progress', $this->filterType) ? 'checked="checked"' : ''?> />
                                        <label for="progress_check"><?=$this->translate('In Progress')?></label>
                                    </li>
                                    <li class="checkbox">
                                        <input type="checkbox" name="filterType" id="in_correction" value="error_correction"
                                        <?=in_array('error_correction', $this->filterType) ? 'checked="checked"' : ''?> />
                                        <label for="in_correction"><?=$this->translate('In Correction')?></label>
                                    </li>
                                    <li class="checkbox">
                                        <input type="checkbox" name="filterType" id="action_required" value="rejected"
                                        <?=in_array('rejected', $this->filterType) ? 'checked="checked"' : ''?> />
                                        <label for="action_required"><?=$this->translate('Action Required')?></label>
                                    </li>
                                </ul>
                            </div>
                        </div>
                        <div id="filter-product" class="float-left">
                            <label><?=$this->translate('Filter By Product Type')?>:</label>
                            <div id="productFilterBox" action="" class="filter-dropdown">
                                <button type="button" class="btn btn-mini dropdown__toggle button-arrow" id="product-filters">
                                <?php
                                $filterContent = '';
                                if (count($this->selectedProductTypes) == 0) {
                                    $filterContent = 'Select a product type';
                                } elseif ($this->isAllProductsSelected) {
                                    $filterContent = $this->translate('All Selected');
                                } else {
                                    $displayProductTypes = array();
                                    foreach ($this->selectedProductTypes as $filter) {
                                        if (isset($this->textForProductTypes[$filter])) {
                                            $displayProductTypes[$filter] = $this->textForProductTypes[$filter];
                                        }
                                    }
                                    $filterContent = implode(', ', $displayProductTypes);
                                }
                                echo $filterContent; ?>
                                </button>
                                <ul id="product-checkbox-filters" class="dropdown__list list-unstyled" style="display:none;">
                                <?php
                                foreach ($this->textForProductTypes as $key => $value) {
                                    echo '<li class="checkbox"><input type="checkbox" id="ProductType'.$key.'" name="productType" value="' . $key . '"';
                                    if (in_array($key, $this->selectedProductTypes)) {
                                        echo 'checked="checked"';
                                    }
                                    echo '/> <label for="ProductType'.$key.'">' . $this->translate($value) . '</label></li>';
                                }
                                ?>
                                </ul>
                            </div>
                        </div>

                        <?php if (Zend_Registry::get('UserObj')->isAllowed('', '', 'viewexareleases') && isset($this->vendSubaccounts)) { ?>
                                <div class="modFilter">
                                    <select id="subaccountUser" name="subaccountUser" onchange="releaseFilterBySubaccount();" class="searchbox trackSearchBox searchboxLarge ac_input form-control">
                                        <option value=""><?php echo $this->translate('Select A Subaccount'); ?></option>
                                            <?php foreach ($this->vendSubaccounts as $eachSubaccount) {
                                                $selected = '';
                                                if (isset($this->subacc_id) && $this->subacc_id == $eachSubaccount->subaccount_id) {
                                                    $selected = 'selected';
                                                } ?>
                                                <option value="<?=$eachSubaccount->subaccount_id?>" <?=$selected?>><?=$eachSubaccount->subaccount_name?></option>
                                            <?php } ?>
                                    </select>
                               </div>
                        <?php } ?>

                    </div>
                    <div class="float-right">
                        <button type="button" class="btn btn-default" id="apply_filters"><?=$this->translate('Filter')?></button>
                    </div>
                    <div class="clear"></div>
                    </div>
                    <thead class="table_header">
                        <?php if (isset($this->search_term) && $this->search_term !='') { ?>
                            <div><i><?=$this->translate('Displaying results for')?>: <span>"<?=$this->search_term?>"</span></i></div>
                        <?php } ?>
                    </thead>
                    <table id="view-ex-a" width="100%" border="0" cellspacing="0" cellpadding="0" class="table">
                        <thead class="table_header">
                            <tr>
                                <?php
                                $release_title_url = '';
                                $release_date_url = '';
                                $release_artist_url = '';
                                $release_preorder_date_url = '';
                                $sortUpArrowClass = 'catalogSortArrowUp';
                                $sortDownArrowClass = 'catalogSortArrowDown';
                                if ($alwSalesStartDateEnabled) {
                                    $sale_start_date_url = '';
                                }
                                $filterType = implode(',', $this->filterType);
                                $selectedProductTypes = implode(',', $this->selectedProductTypes);
                                $searchParam = isset($this->search_term) ? '&name=' . $this->search_term : '';
                                $page = isset($this->current_page) ? $this->current_page : '1';
                                $release_date_order = isset($this->release_date_order) ? $this->release_date_order : '';
                                $release_artist_order = isset($this->release_artist_order) ? $this->release_artist_order : '';
                                if ($alwSalesStartDateEnabled) {
                                    $sale_start_date_order = isset($this->sale_start_date_order) ? $this->sale_start_date_order : '';
                                }
                                $release_preorder_date_order = isset($this->release_preorder_date_order) ? $this->release_preorder_date_order : '';
                                $release_title_order = isset($this->release_title_order) ? $this->release_title_order : '';

                                // @todo: extract all of this conditional logic into a view-model class
                                if ($release_title_order == '' || $release_title_order == 'asc') {
                                    $release_title_changed = 'desc';
                                    $release_title_order = 'asc';
                                    $arrowClassTitle = ($this->sortBy == 'title') ? $sortDownArrowClass : 'no_sort';
                                } elseif ($release_title_order == 'desc') {
                                    $release_title_changed = 'asc';
                                    $release_title_order = 'desc';
                                    $arrowClassTitle = ($this->sortBy == 'title') ? $sortUpArrowClass : 'no_sort';
                                }

                                if ($release_artist_order == '' || $release_artist_order == 'asc') {
                                    $release_artist_changed = 'desc';
                                    $release_artist_order = 'asc';
                                    $arrowClassArtist = ($this->sortBy == 'release_artist') ? $sortDownArrowClass : 'no_sort';
                                } elseif ($release_artist_order == 'desc') {
                                    $release_artist_changed = 'asc';
                                    $arrowClassArtist = ($this->sortBy == 'release_artist') ? $sortUpArrowClass : 'no_sort';
                                }

                                if ($release_date_order == '' || $release_date_order == 'asc') {
                                    $release_date_changed = 'desc';
                                    $arrowClassReleaseDate = ($this->sortBy == 'date') ? $sortDownArrowClass : 'no_sort';
                                    if (in_array('delivered', $this->filterType) && $release_date_order == '') {
                                        $release_date_changed = 'asc';
                                        $release_date_order = 'desc';
                                    } else {
                                        $release_date_order = 'asc';
                                    }
                                } elseif ($release_date_order == 'desc') {
                                    $release_date_changed = 'asc';
                                    $release_date_order = 'desc';
                                    $arrowClassReleaseDate = ($this->sortBy == 'date') ? $sortUpArrowClass : 'no_sort';
                                }
                                if ($alwSalesStartDateEnabled) {
                                    if ($sale_start_date_order == '' || $sale_start_date_order == 'asc') {
                                        $sale_start_date_changed = 'desc';
                                        $sale_start_date_order = 'asc';
                                        $arrowClassSalesDate = ($this->sortBy == 'sale_start_date') ? $sortDownArrowClass : 'no_sort';
                                    } elseif ($sale_start_date_order == 'desc') {
                                        $sale_start_date_changed = 'asc';
                                        $sale_start_date_order = 'desc';
                                        $arrowClassSalesDate = ($this->sortBy == 'sale_start_date') ? $sortUpArrowClass : 'no_sort';
                                    }
                                }
                                if ($release_preorder_date_order == '' || $release_preorder_date_order == 'asc') {
                                    $release_preorder_date_changed = 'desc';
                                    $release_preorder_date_order = 'asc';
                                    $arrowClaspreOrderDate = ($this->sortBy == 'preorder_date') ? $sortDownArrowClass : 'no_sort';
                                } elseif ($release_preorder_date_order == 'desc') {
                                    $release_preorder_date_changed = 'asc';
                                    $arrowClaspreOrderDate = ($this->sortBy == 'preorder_date') ? $sortUpArrowClass : 'no_sort';
                                }
                                $subAccParam = '';
                                if (isset($this->subacc_id) && $this->subacc_id > 0) {
                                    $subAccParam = '&subacc_id=' . $this->subacc_id;
                                }
                                $artistParam = '';
                                if (isset($this->artist_id) && $this->artist_id > 0) {
                                    $artistParam = '&artist_id=' . $this->artist_id;
                                }
                                if ($alwSalesStartDateEnabled) {
                                    $release_title_url = '/index/viewexareleases?filterType=' . $filterType . '&productType=' . $selectedProductTypes . $searchParam . $artistParam . $subAccParam . '&page=' . $page . '&release_title=' . $release_title_changed . '&release_date=' . $release_date_order . '&sale_start_date=' . $sale_start_date_order . '&sortby=title';
                                    $release_date_url = '/index/viewexareleases?filterType=' . $filterType . '&productType=' . $selectedProductTypes . $searchParam . $artistParam . $subAccParam . '&page=' . $page . '&release_title=' . $release_title_order . '&release_date=' . $release_date_changed .'&sale_start_date=' . $sale_start_date_order . '&sortby=date';
                                    $sale_start_date_url = '/index/viewexareleases?filterType=' . $filterType . '&productType=' . $selectedProductTypes . $searchParam . $artistParam . $subAccParam . '&page=' . $page . '&release_title=' . $release_title_order . '&release_date=' . $release_date_order . '&sale_start_date=' . $sale_start_date_changed . '&sortby=sale_start_date';
                                } else {
                                    $release_title_url = '/index/viewexareleases?filterType=' . $filterType . '&productType=' . $selectedProductTypes . $searchParam . $artistParam . $subAccParam . '&page=' . $page . '&release_title=' . $release_title_changed . '&release_date=' . $release_date_order . '&sortby=title';
                                    $release_date_url = '/index/viewexareleases?filterType=' . $filterType . '&productType=' . $selectedProductTypes . $searchParam . $artistParam . $subAccParam . '&page=' . $page . '&release_title=' . $release_title_order . '&release_date=' . $release_date_changed . '&sortby=date';
                                }
                                $release_artist_url = '/index/viewexareleases?filterType=' . $filterType . '&productType=' . $selectedProductTypes . $searchParam . $artistParam . $subAccParam . '&page=' . $page . '&release_title=' . $release_title_order . '&release_date=' . $release_date_order . '&sale_start_date=' . $sale_start_date_order . '&release_artist=' . $release_artist_changed . '&preorder_date=' . $release_preorder_date_order . '&sortby=release_artist';
                                $release_title_url = '/index/viewexareleases?filterType=' . $filterType . '&productType=' . $selectedProductTypes . $searchParam . $artistParam . $subAccParam . '&page=' . $page . '&release_title=' . $release_title_changed . '&release_date=' . $release_date_order . '&sale_start_date=' . $sale_start_date_order . '&release_artist=' . $release_artist_order . '&preorder_date=' . $release_preorder_date_order . '&sortby=title';
                                $release_date_url = '/index/viewexareleases?filterType=' . $filterType . '&productType=' . $selectedProductTypes . $searchParam . $artistParam . $subAccParam . '&page=' . $page . '&release_title=' . $release_title_order . '&release_date=' . $release_date_changed .'&sale_start_date=' . $sale_start_date_order . '&release_artist=' . $release_artist_order . '&preorder_date=' . $release_preorder_date_order . '&sortby=date';
                                $sale_start_date_url = '/index/viewexareleases?filterType=' . $filterType . '&productType=' . $selectedProductTypes . $searchParam . $artistParam . $subAccParam . '&page=' . $page . '&release_title=' . $release_title_order . '&release_date=' . $release_date_order . '&sale_start_date=' . $sale_start_date_changed . '&release_artist=' . $release_artist_order . '&preorder_date=' . $release_preorder_date_order . '&sortby=sale_start_date';
                                $release_preorder_date_url = '/index/viewexareleases?filterType=' . $filterType . '&productType=' . $selectedProductTypes . $searchParam . $artistParam . $subAccParam . '&page=' . $page . '&release_title=' . $release_title_order . '&release_date=' . $release_date_order . '&sale_start_date=' . $sale_start_date_order . '&release_artist=' . $release_artist_order . '&preorder_date=' . $release_preorder_date_changed . '&sortby=preorder_date';
                                ?>
                                <th class="ri <?=$alwSalesStartDateEnabled ? 'col1' : ''?>"><?=$userObj->isAllowed(null, null, 'uiproject') ? $this->translate->_('Product') : $this->translate->_('Release')?></th>
                                    <th class="text-left"><a href="<?php echo $release_title_url; ?>" class="<?php echo $arrowClassTitle;?>"><?=$this->translate('Name')?></a></th>
                                <th><a href="<?php echo $release_artist_url; ?>" class="<?php echo $arrowClassArtist;?>"><?=$this->translate('Artist Name')?></a></th>
                                <th <?=$alwSalesStartDateEnabled ? 'class="col1"' : ''?>><?=$this->translate('Product Type')?></th>
                                <th class="rd <?=$alwSalesStartDateEnabled ? 'col1' : ''?> productDateCol"><a href="<?php echo $release_date_url; ?>" class="<?php echo $arrowClassReleaseDate;?>"><?=$this->translate('Release Date')?></a></th>
                                <?php if ($alwSalesStartDateEnabled) { ?>
                                    <th class="col2 productDateCol"><a href="<?php echo $sale_start_date_url; ?>" class="<?php echo $arrowClassSalesDate;?>"><?=$this->translate('Sales Date')?></a></th>
                                <?php } ?>
                                <th class="productDateCol">
                                    <a href="<?php echo $release_preorder_date_url; ?>" class="<?php echo $arrowClaspreOrderDate;?>"><?=$this->translate('Preorder Date')?></a>
                                </th>
                                <th class="bi <?=$alwSalesStartDateEnabled ? 'col3' : ''?> productStatusCol"><?=$userObj->isAllowed(null, null, 'uiproject') ? $this->translate->_('Product Status') : $this->translate->_('Release Status')?></th>
                                <th class="chk <?=$alwSalesStartDateEnabled ? 'col4' : ''?>"><a id="viewexareleases_selectall_link" class="no_sort" onclick="toggleSelectAll()"><?=$this->translate('Select all')?></a></th>
                            </tr>
                        </thead>
                        <tbody>
                        <?php
                        if (count($this->releases_in_progress)) {
                            $content_releases = array();
                            $submitted_releases = array();
                            foreach ($this->releases_in_progress as $values) {
                                $upc = $values['upc'];
                                $status = $values['release_status'];
                                $correction_status = isset($values['correction_status']) ? $values['correction_status'] : '';
                                $approval_queue_status = isset($values['approval_queue_status']) ? $values['approval_queue_status'] : '';
                                $showStepsStatus = false;
                                $release_name = $values['release_name'];
                                $artist_name = $values['artist_name'];
                                $release_date = $values['release_date'];
                                if ($alwSalesStartDateEnabled) {
                                    $sale_start_date = $values['sale_start_date'];
                                }
                                $release_id = $values['release_id'];
                                $release_type = $values['release_type'];
                                $product_type = $this->translate($values['product_type']);
                                $version = $values['version'];
                                $subaccount_name = (isset($values['subaccount_name']) && Zend_Registry::get('UserObj')->isAllowed('', '', 'viewsubaccountinviewexareleases')) ? $values['subaccount_name'] : '';
                                $isChangedCoverart = $values['isChangedCoverart'];
                                if (in_array($values['product_type'], array('Digital Audio', 'Physical Audio'))) {
                                    $image_info = array();
                                    $response = $this->owsAssetsServiceClient->getCoverImagePath($release_id, 'cover', $isChangedCoverart);
                                    if ($response->getStatusCode() !== 200) {
                                        $image_info['path'] = $noArtworkPng;
                                    } else {
                                        $image_info['path'] = $response->getBody()->getContents();
                                    }
                                    //Original Image size 110x110 for thumbnail size should be 40x40
                                    $image_info['width'] = 40;
                                    $image_info['height'] = 40;
                                } else {
                                    $image_info = Web_Controller_Plugin_ImagePathLookup::getImage($upc, true, 40, null, $release_id, $isChangedCoverart, null, 'posterart');
                                }
                                $href = '/releasebuilder/view?release_id=' . $release_id;
                                if ($status == 'in_content' && ($correction_status == 'active' || $correction_status == 'submitted')) {
                                    $href .= '&correction=true'; // show edited page with corrections
                                }
                                $isDigitalProductBuilder = ($this->isProjectMode
                                    && $values['product_type'] == 'Digital Audio'
                                );
                                if ($isDigitalProductBuilder) {
                                    $href = '/project/' . $values['project_id'] . '/product/' . $release_id . '/overview';
                                }
                                if ($values['product_type'] == 'Music Video') {
                                    $href = '/project/' . $values['project_id'] . '/product/' . $release_id . '/video';
                                }
                                $physical_releases = [];
                                if ($projectManagerEnabled && $product_type === "Physical Audio") {
                                    $physical_releases[] = $release_id;
                                }
                                if ($approval_queue_status == 'rejected') {
                                    $status_class = 'rejected';
                                    $status_text = $this->translate('Action Required');
                                } elseif ($status == 'transfer_to_content' || $correction_status == 'submitted') {
                                    $status_class = 'submitted';
                                    $status_text = $this->translate('Submitted');
                                    $submitted_releases[] = $release_id;
                                } elseif ($status == 'label_processing' || $status == 'orchard_processing') {
                                    if ($product_type === "Physical Audio") {
                                        $status_class = 'in-progress';
                                        $status_text = $this->translate('In Progress');
                                    } else {
                                        $status_images = array('check' => $statusCheckPng, 'cross' => $statusXPng);
                                        $rb_index = ($values['release_basics']) ? 'check' : 'cross';
                                        $art_index = ($values['art_uploaded']) ? 'check' : 'cross';
                                        $t_index = ($values['tracks_completed']) ? 'check' : 'cross';
                                        $showStepsStatus = true;
                                    }
                                } elseif ($status == 'in_content' && $correction_status == 'active') {
                                    $status_class = 'in-correction';
                                    $status_text = $this->translate('In Correction');
                                } elseif ($status == 'in_content' && ($correction_status == '' || $correction_status == 'applied')) {
                                    //$status_image = '/images/icons/delivered.png';
                                    $content_releases[] = $release_id;
                                }
                                $randomValue = mt_rand();
                                $image_info['path'] .= '?' . $randomValue;
                                /**  ------ BEGIN DISPLAY  LSIT SECTION  ------- */
                                if ($showStepsStatus == true) { ?>
                                    <tr id="release<?=$release_id?>_tr">
                                        <td align="center">
                                            <div class="release-image">
                                                <a class="viewReleasesPhoto" href="<?=$href?>">
                                                    <img src="<?=$image_info['path']?>" width="<?=$image_info['width']?>" height="<?=$image_info['height']?>" />
                                                </a>
                                            </div>
                                        </td>
                                        <td class="ri">
                                            <div class="releaseInfo <?=$alwSalesStartDateEnabled ? 'release-info-width' : ''?>">
                                                <!--<?=(($release_type == 'music_video') ? '<img src="/images/icons/videoicon.gif"/>' : '')?>-->
                                                <a href="<?=$href?>" class="albumName"><?=$release_name?></a>
                                                <span class="viewexareleases_artist_name">
                                                    <?= ($version ? '<br>(' . $version . ')' : '') ?>
                                                    <?= ((trim($subaccount_name) != '') ? '<br>(' . $subaccount_name . ')' : '') ?>
                                                </span>
                                            </div>
                                        </td>
                                        <td class="viewexareleases_catalog_artist_name"><div class="releaseInfo"><?=$this->translate($artist_name)?></div></td>
                                        <td class="product-type"><?=$this->translate($product_type)?></td>
                                            <td class="release-date productDateCol">
                                                <div class="release-date-container">
                                                    <?=$release_date?>
                                                </div>
                                            </td>
                                            <?php if ($alwSalesStartDateEnabled) { ?>
                                                <td class="sale-start-date productDateCol">
                                                    <?=$sale_start_date?>
                                                </td>
                                            <?php } ?>
                                            <td class="productDateCol">
                                                <?=isset($values['preorder_date']) && $product_type !== 'Physical Audio' ? $values['preorder_date'] : ''?>
                                            </td>
                                            <td class="status">
                                                <p class="status_icon_inline"><img title="<?=($rb_index=='check')?'last updated: '.date('Y-m-d', strtotime($values['last_updated'])):''?>" src="<?=$status_images[$rb_index]?>" /><span><?php echo $this->translate('Info'); ?></span></p>
                                                <p class="status_icon_inline"><img title="<?=($art_index=='check')?'last updated: '.date('Y-m-d', strtotime($values['last_updated'])):''?>" src="<?=$status_images[$art_index]?>" /><span><?php echo $this->translate('Art'); ?></span></p>
                                                <p class="status_icon_inline"><img title="<?=(!is_null($values['last_track_update'])&&$t_index=='check')?'last updated: '.date('Y-m-d', strtotime($values['last_track_update'])):'' ?>" src="<?=$status_images[$t_index]?>" /><span><?php echo $this->translate('Assets'); ?></span></p>
                                            </td>
                                        <?php if (in_array($release_id, $physical_releases) && $workstationCatalogPageDelete!==true) { ?>
                                            <td align="center" class="chk chkOff"></td>
                                        <?php } else { ?>
                                        <td align="center" id="release<?=$release_id?>_td" class="chk" onclick="toggleReleaseCheckbox($('#release<?=$release_id?>_checkbox'), 'release<?=$release_id?>_tr'); return true;">
                                                <div class="checkbox">
                                                    <input onclick="toggleReleaseCheckbox(this, 'release<?=$release_id?>_tr'); return true;"
                                                    id="release<?=$release_id?>_checkbox" name="release_checkboxes[]" type="checkbox"
                                                    value="<?=$release_id?>">
                                                    <label for="release<?=$release_id?>"></label>
                                                </div>
                                        </td>
                                        <?php } ?>
                                    </tr>
                                    <?php
                                } else { ?>
                                    <tr id="release<?=$release_id?>_tr" class="submitted">
                                        <td align="center">
                                            <div class="release-image">
                                                <a class="viewReleasesPhoto" href="<?=$href?>">
                                                    <img src="<?=$image_info['path']?>" width="<?=$image_info['width']?>" height="<?=$image_info['height']?>" />
                                                </a>
                                            </div>
                                        </td>
                                        <td class="ri">
                                            <div class="releaseInfo <?=$alwSalesStartDateEnabled ? 'release-info-width' : ''?>">
                                                <a href="<?=$href?>" class="albumName">
                                                    <?=$release_name?>
                                                </a>
                                                <span class="viewexareleases_artist_name">
                                                    <?= ((trim($subaccount_name) != '') ? '(' . $subaccount_name . ')' : '') ?>
                                                </span>
                                            </div>
                                        </td>
                                        <td class="viewexareleases_catalog_artist_name"><div class="releaseInfo"><?=$artist_name?></div></td>
                                            <td class="product-type"><?=$product_type?></td>
                                            <td class="release-date productDateCol">
                                                <div class="release-date-container">
                                                    <?=$release_date?>
                                                </div>
                                            </td>
                                            <?php if ($alwSalesStartDateEnabled) { ?>
                                                <td class="sale-start-date productDateCol">
                                                    <?=$sale_start_date?>
                                                </td>
                                            <?php } ?>
                                            <td class="productDateCol">
                                                <?=isset($values['preorder_date']) && $product_type !== 'Physical Audio' ? $values['preorder_date'] : ''?>
                                            </td>
                                            <td class="status">
                                                <div class="release-status">
                                                    <?php
                                                    if ($status == 'in_content' && ($correction_status == '' || $correction_status == 'applied')) {
                                                        if ($product_type === "Physical Audio") { ?>
                                                            <div class="status-label physical-delivered">
                                                                <?=$this->translate('Delivered');?>
                                                            </div>
                                                            <?php
                                                        } else {
                                                            if ($userObj->isAllowed('', '', 'icon_marketplace_release_catalogue') && $this->has_marketing_resource) {
                                                            ?>
                                                                <a href="/marketing/allapplications/"><img title="Market this release" src="<?= $marketingPng ?>" /></a>
                                                            <?php
                                                            }
                                                            if (!$projectManagerEnabled || !in_array($release_id, $physical_releases)) { ?>
                                                                <a href="/releasebuilder/deliveryreport/upc/<?=$upc?>"><img title="View delivery report" src="<?= $deliveryPng ?>" /></a>
                                                            <?php
                                                            }
                                                            //isAllowed method checks if user has access to Analytics Section
                                                            if ($userObj->isAllowed('', '', 'releasecataloganalytic') && $this->has_analytics_resource) { ?>
                                                                    <a href="/analytics/overview?product_ids=<?=$upc?>">
                                                                    <img title="<?=$this->translate('Analyze sales activity')?>" src="<?= $analyticsPng ?>"/>
                                                                    </a>
                                                                <?php
                                                            }
                                                            if ($workstationAccountingPeriodEnabled && $this->has_accounting_resource && $isAccountingNavigationEnabled) {
                                                                $fromPeriod = (!empty($this->periods->periods[0]->min)) ? $this->periods->periods[0]->min : null;
                                                                $toPeriod = (!empty($this->periods->periods[0]->max)) ? $this->periods->periods[0]->max : null;
                                                            ?>
                                                                <a href="/accounting/?accounting_start=<?=$fromPeriod?>&accounting_end=<?=$toPeriod?>&view_by=release_id&release_ids=<?=$upc?>"><img title="View accounting data " src="<?= $accountingPng ?>" /></a>
                                                                <?php
                                                            } else if ($this->has_accounting_resource && $isAccountingNavigationEnabled) { ?>
                                                                <a href="/accounting/?accounting_start=166&accounting_end=168&view_by=trackId&releaseIds=<?=$upc?>"><img title="View accounting data " src="<?= $accountingPng ?>" /></a>
                                                                <?php
                                                            }
                                                        }
                                                    } else { ?>
                                                        <div class="status-label <?=$status_class?>"><?=$status_text?></div>
                                                    <?php
                                                    } ?>
                                                </div>
                                            </td>
                                        <?php if (in_array($release_id, $content_releases) || (in_array($release_id, $submitted_releases)) || ($projectManagerEnabled && in_array($release_id, $physical_releases) && $workstationCatalogPageDelete !== true)) { ?>
                                            <td align="center" class="chk chkOff"></td>
                                        <?php } else { ?>
                                            <td align="center" id="release<?=$release_id?>_td" class="chk" onclick="toggleReleaseCheckbox($('#release<?=$release_id?>_checkbox'), 'release<?=$release_id?>_tr'); return true;">
                                                <div class="checkbox">
                                                    <input onclick="toggleReleaseCheckbox(this, 'release<?=$release_id?>_tr'); return true;"
                                                    id="release<?=$release_id?>_checkbox" name="release_checkboxes[]" type="checkbox"
                                                    value="<?=$release_id?>">
                                                    <label for="release<?=$release_id?>"></label>
                                                </div>
                                            </td>
                                        <?php } ?>
                                    </tr>
                                <?php
                                } /**  ------ ENDS DISPLAY  LSIT SECTION  ------- */
                            }
                            echo '<script type="text/javascript"> numberOfCheckbox= '.(count($this->releases_in_progress) - count($submitted_releases) - count($content_releases)).'; </script>';
                        } else { ?>
                            <tr>
                                <td colspan="5" align="center" style="height: 40px;">
                                    <?=$this->translate('No Releases Found')?>
                                </td>
                            </tr>
                            <?php
                        } ?>
                        </tbody>
                    </table>

                    <div class="selectedReleasesBtns">
                        <?php
                        if (!$this->payment_required) { ?>
                        <button type="button" onclick="if ($('form tbody input:checkbox:checked').length > 0) { validateReleases(); }" class="btn btn-default disabled"><?=$userObj->isAllowed(null, null, 'uiproject') ? $this->translate->_('Submit Selected Products') : $this->translate->_('Submit Selected Releases')?></button>
                        <?php
                        }
                        ?>
                        <?php if (!$isDeprecateDeleteFromLegacyCatalogPageEnabled) { ?>
                            <button type="button" onclick="if ($('form tbody input:checkbox:checked').length > 0) { deleteReleases(); }" class="btn btn-danger disabled"><?=$this->translate('delete selected releases')?></button>
                        <?php } ?>
                    </div>
                </form>
                <?php
                $query_string = '';
                $url = parse_url($this->serverUrl(true));
                if (key_exists('query', $url)) {
                    $query_string = $url['query'];
                }
                echo $this->paginationpanel(
                    '/index/viewexareleases',
                    $this->current_page,
                    10,
                    $this->total_num_of_releases,
                    'page',
                    $query_string,
                    $this->featureVendorContext
                ); ?>
                <div class="clear"></div>
            </div> <!-- ENDS view_exarelease_listing  -->
            <!-- End Module Body -->
        </div>
    </div>
    <!-- End Release Schedule Module -->
    <div id="modal_overlay" class="modal fade in"><div id="modal_container"></div></div>
    <div id="new_artist_overlay" class="modal fade in"><div id="new_artist_container"></div></div>
</div>
<!-- End Left Side Content -->
<script type="text/javascript">
    function filterReleaseResult() {
        var searchTerm = $('#search_release_inputbox').val();
        var statusButtons = $('#filterBox input:checkbox:checked').serializeArray();
        var productButtons = $('#productFilterBox input:checkbox:checked').serializeArray();
        var subaccountId = '<?=((isset($this->subacc_id) && $this->subacc_id > 0) ? $this->subacc_id : '0')?>';
        var filterType = [<?php echo(count($this->filterType) > 1 ? ("'".implode("','", $this->filterType)."'") : "" ); ?>];
        //THIS IS TO CHECK IF PAGE NO IS FOR CORRECT FILTER TYPE. ELSE IT SELECTES WRONG PAGE FOR CHANGED FILTER TYPE
        var pageForSameFilter = true;
        var queryString = '';
        for (i = 0; i < statusButtons.length; i++) { //Make an array of only selected values
            queryString = (queryString == '') ? queryString : (queryString + ',');
            queryString += statusButtons[i].value;
        }
        var productParam = [];
        var productQuery = '';
        for (i = 0; i < productButtons.length; i++) {
            productParam.push(productButtons[i].value);
        }
        if (productParam.length > 0) {
            productQuery = productParam.join();
        }
        var subAccParam = '';
        if (subaccountId > 0) {
            subAccParam = '&subacc_id=' + subaccountId;
        }
        var termParam = '';
        if (searchTerm != '') {
            termParam = '&name=' + encodeURIComponent(searchTerm);
            //Always returning search results ordered by release date when search term present
            <?php $release_date_order = 'desc'; ?>
        }
        var artistId = '<?=((isset($this->artist_id) && $this->artist_id > 0) ? $this->artist_id : '0')?>';
        var artistParam = '';
        if (artistId > 0) {
            artistParam = '&artist_id=' + artistId;
        }
        $('#loading_image').addClass('catalog_loading_overlay');
        $('html, #mainBody').addClass('hide-overflow');
        $('#loading_image').show();
        window.location.href = '/index/viewexareleases?bulk=1&filterType=' + queryString + artistParam + subAccParam + '&productType=' + productQuery + termParam + '&release_title=<?php echo $release_title_order; ?>&release_date=<?php echo $release_date_order; ?>&sale_start_date=<?php echo $sale_start_date_order; ?>&release_artist=<?php echo $release_artist_order;?>&preorder_date=<?php echo $release_preorder_date_order;?>';
    }

    function releaseFilterBySubaccount() {
        var subaccount = document.getElementById('subaccountUser');
        var subaccountId = subaccount.options[subaccount.selectedIndex].value;
        var filterType = '<?php echo implode(',', $this->filterType); ?>';
        var selectedProductTypes = '<?php echo implode(',', $this->selectedProductTypes); ?>';
        var subAccParam = '';
        if (subaccountId > 0) {
            subAccParam = '&subacc_id=' + subaccountId;
        }
        var artistId = '<?=((isset($this->artist_id) && $this->artist_id > 0) ? $this->artist_id : '0')?>';
        var artistParam = '';
        if (artistId > 0) {
            artistParam = '&artist_id=' + artistId;
        }

        $('#loading_image').addClass('catalog_loading_overlay');
            $('html, #mainBody').addClass('hide-overflow');
        $('#loading_image').show();
        window.location.href = '/index/viewexareleases?bulk=1&filterType=' + filterType + artistParam + subAccParam + '&productType=' + selectedProductTypes + '&release_title=<?php echo $release_title_order; ?>&release_date=<?php echo $release_date_order; ?>&sale_start_date=<?php echo $sale_start_date_order; ?>&release_artist=<?php echo $release_artist_order; ?>&preorder_date=<?php echo $release_preorder_date_order;?>';
    }

    var new_artist_overlay = $('#new_artist_overlay').overlay({
        closeOnEsc: false,
        closeOnClick: false,
        oneInstance: false,
        // custom top position
        top: '5%',
        left: 'center',
        speed: 700,
        // some expose tweaks suitable for facebox-looking dialogs
        expose: {
            // you might also consider a 'transparent' color for the mask
            color: '#333',
            // load mask a little faster
            loadSpeed: 700,
            // highly transparent
            opacity: 0.9,
            zIndex: 9999
        },
        // we want to use the programming API
        api: true
    });

    new_artist_overlay.onStart(function () {
        $('#new_artist_overlay').css({top: $('#modal_overlay').position().top + 'px'});
    });

    var tooltipClassName = '';
    <?php if ($this->userObj->isAllowed(null, null, 'labelsdropdown')) { ?>
        tooltipClassName = 'createReleaseSubAccount_li';
    <?php } else { ?>
        tooltipClassName = 'createReleaseMetaLanguage_li';
    <?php } ?>

    function createFilmReleaseOnBeforeLoad() {
        modal_overlay.oneInstance = false;
        $('#tooltipForRelease').hide();
        showModalTooltip('tooltipForRelease', tooltipClassName);
    }
    function createFilmReleaseOnBeforeClose() {
        modal_overlay.oneInstance = true;
        $('#ui-datepicker-div').hide();
    }
    function createFilmReleaseOnLoad() {
        $('#tooltipForRelease').css('top', 38);
        $('#tooltipForRelease').show();
        showModalTooltip('tooltipForRelease', tooltipClassName);
    }
    function createReleaseOnBeforeLoad() {
        modal_overlay.oneInstance = false;
        $('#tooltipForRelease').hide();
        showModalTooltip('tooltipForRelease', tooltipClassName);
    }
    function createReleaseOnBeforeClose() {
        modal_overlay.oneInstance = true;
        $('#ui-datepicker-div').hide();
    }
    function createReleaseOnLoad() {
        $('#tooltipForRelease').css('top', 50);
        $('#tooltipForRelease').show();
        showModalTooltip('tooltipForRelease', tooltipClassName);
    }
    function validateReleaseOnLoad() {
        $('#error_releases').html('');
        $('#multiple_error_releases_table').find("th:eq(0)").after('<th class="text-nowrap">Artist Name</th>');
        var selected_releases = $('#view_exarelease_form').serializeArray();
        var tmp_error_release_ids = new Array();
        for (var i in error_releases) {
            tmp_error_release_ids.push(i);
        }
        for (var i in selected_releases) {
            if (jQuery.inArray(selected_releases[i].value, tmp_error_release_ids) > -1) {
                var release_name = $('tr#release' + selected_releases[i].value + '_tr div.releaseInfo a').html();
                var artist_name = $('tr#release' + selected_releases[i].value + '_tr .viewexareleases_catalog_artist_name').html();
                var isProjectMode = <?=json_encode($this->isProjectMode)?>;
                if (isProjectMode) {
                    var href = $('tr#release' + selected_releases[i].value + '_tr div.releaseInfo a').attr('href');
                        var releaseInfo = '<div class="releaseInfo">\
                            <a class="albumName" href="' + href + '">'
                            + release_name + '</a>';
                } else {
                        var releaseInfo = '<div class="releaseInfo">\
                            <a class="albumName" href="/releasebuilder/view?release_id=' + selected_releases[i].value + '">'
                            + release_name + '</a>';
                }
                var errorMessage = '<div class="error">';
                for (var msg in error_releases[selected_releases[i].value].errors) {
                    var error_value = error_releases[selected_releases[i].value].errors[msg];
                    errorMessage += error_value + ' , ';
                }
                errorMessage += '</div>';
                releaseInfo += errorMessage + '</div>';

                var release_date = $('tr#release' + selected_releases[i].value + '_tr td.release-date').html();
                $('#error_releases').append('<tr><td>' + releaseInfo + '</td><td>'+ artist_name +'</td><td>'+ release_date + '</td></tr>');
            }
        }
        $('.table-sorter').tablesorter();
    }
    function validateReleases() {
        error_releases = new Object();
        var selected_releases = $('#view_exarelease_form').serialize();
        $.ajax({
            type: 'POST',
            url: '/multiplereleases/validatemultiplereleases',
            data: selected_releases + '&format=json',
            dataType: 'json',
            success: function (objResponse, textStatus, XMLHttpRequest) {
                $('#error_releases').html('');
                var num_of_errors = 0;
                var num_of_error_releases = 0;
                if (!objResponse.payment_required) {
                    for (var release_id in objResponse.error_releases) {
                        num_of_errors = 0;
                        error_releases[release_id] = new Object();
                        error_releases[release_id]['data'] = new Object();
                        error_releases[release_id]['errors'] = new Object();
                        for (var error_key in objResponse.error_releases[release_id].errors) {
                            var error_value = objResponse.error_releases[release_id].errors[error_key];
                            error_releases[release_id]['errors'][error_key] = error_value;
                            num_of_errors++;
                        }
                        error_releases[release_id]['data']['release_name'] = objResponse.error_releases[release_id].release_name;
                        error_releases[release_id]['data']['artist_name'] = objResponse.error_releases[release_id].artist_name;
                        error_releases[release_id]['data']['num_of_errors'] = num_of_errors;
                        num_of_error_releases++;
                    }
                    if (num_of_error_releases <= 0) {
                        modalWindow3();
                        $('#submit_selected_releases_button').html('Submit Selected Releases');
                    } else {
                        modalWindow2();
                        $('#submit_selected_releases_button').html('Submit Selected Releases');
                    }
                } else {
                    modalWindow4();
                }
            },
            error: function (xhr, textStatus, errorThrown) {
                var err_obj = eval('(' + xhr.responseText + ')');
                alert('Update error: ' + err_obj.additional_info);
            }
        });
    }
    function submitSelectedReleases() {
        $('#multiple_releases_confirm_submit_button').attr('onclick', '').unbind('click');
        var loadingBtnLoader = '<?php echo $loadingBtnLoader; ?>';
        $('#multiple_releases_confirm_submit_button').addClass('loader-active').append(loadingBtnLoader);
        var selected_releases = $('#view_exarelease_form').serialize();
        $.ajax({
            type: 'POST',
            url: '/multiplereleases/submitmultiplereleases',
            data: selected_releases + '&format=json',
            dataType: 'json',
            success: function (objResponse, textStatus, XMLHttpRequest) {
                $('#submit_release_success_msg').removeClass('notDisplay');
                $('.submit-releases-text, .submit-releases-correct-text').hide();
                $('#multiple_releases_confirm_submit_button').hide();
                window.location.reload();
                hideRefinedMask();
            },
            error: function (xhr, textStatus, errorThrown) {
                var err_obj = eval('(' + xhr.responseText + ')');
                alert('Update error: ' + err_obj.additional_info);
                hideRefinedMask();
            }
        });
    }
    function toggleReleaseCheckbox(obj, row_id) {
        if ($(obj).attr('checked')) {
            $(obj).attr('checked', false);
            $('#' + row_id + ' td.chk').removeClass('selected');
        } else {
            $(obj).attr('checked', true);
            $('#' + row_id + ' td.chk').addClass('selected');
        }
        changeSubmitClassName();
    }
    function toggleSelectAll() {
        var selected_releases = $('form tbody input:checkbox:checked');
        //If not all checkboxes are checked, check all, otherwise, uncheck all
        if (selected_releases.length == numberOfCheckbox) {
            $('input[name="release_checkboxes\[\]"]').attr('checked', false);
            $('.homepageTable td.chk').removeClass('selected');
            $('#viewexareleases_selectall_link').html('<?=$this->escapejs($this->translate('Select all'))?>');
        } else {
            $('input[name="release_checkboxes\[\]"]').attr('checked', true);
            $('.homepageTable td.chk').addClass('selected');
            $('tr.submitted td').removeClass('selected');
            $('#viewexareleases_selectall_link').html('<?=$this->escapejs($this->translate('Select none'))?>');
        }
        changeSubmitClassName();
    }

    function changeSubmitClassName() {
        var selected_releases = $('form tbody input:checkbox:checked');
        if (selected_releases.length > 0) {
            $('.selectedReleasesBtns button.btn-default').removeClass('disabled');
            $('.selectedReleasesBtns button.btn-danger').removeClass('disabled');
        } else {
            $('.selectedReleasesBtns button.btn-default').addClass('disabled');
            $('.selectedReleasesBtns button.btn-danger').addClass('disabled');
        }
    }

    $('.homepageTable tbody tr td').click(function () {
        if (this.className != 'chk' && this.className != 'chk selected') {
            document.location.href = $('#' + $(this).parent().attr('id') + ' a').attr('href');
        }
    });

    function deleteReleasesModalWindowOnLoad() {
        $('#releases_to_be_deleted').html('');
        $('#confirm_delete_releases_table').find("th:eq(0)").after('<th class="ri text-left">Artist Name</th>');
        var selected_releases = $('form tbody input:checkbox:checked').serializeArray();
        for (var i in selected_releases) {
            var release_name = $('tr#release' + selected_releases[i].value + '_tr div.releaseInfo a').html();
            var artist_name = $('tr#release' + selected_releases[i].value + '_tr .viewexareleases_catalog_artist_name').html();
            var isProjectMode = <?=json_encode($this->isProjectMode)?>;
            if (isProjectMode) {
                var url = $('tr#release' + selected_releases[i].value + '_tr div.releaseInfo a').attr('href');
                var releaseInfo = '<div class="releaseInfo">\
                   <a class="albumName" href="' + url + '">'
                    + release_name + '</a></div>';
            } else {
                    var releaseInfo = '<div class="releaseInfo">\
                        <a class="albumName" href="/releasebuilder/view?release_id=' + selected_releases[i].value + '">'
                        + release_name + '</a>\
                        <span class="viewexareleases_artist_name">' + artist_name + '</span>\
                    </div>';
            }
            var release_date = $('tr#release' + selected_releases[i].value + '_tr td.release-date').html();
                $('#releases_to_be_deleted').append('<tr><td>' + releaseInfo + '</td><td>' + artist_name + '</td><td>'+ release_date + '</td></tr>');
        }
        $('.table-sorter').tablesorter();
    }
    function deleteReleases() {
        modalWindow4();
    }
    function deleteSelectedReleases() {
        showRefinedMask('Deleting...');
        var selected_releases = $('#view_exarelease_form').serialize();
        var selected_releases_arr = $('#view_exarelease_form').serializeArray();
        var loadingBtnLoader = '<?php echo $loadingBtnLoader; ?>';
        $('#delete_releases_button').addClass('loader-active').append(loadingBtnLoader);
        $.ajax({
            type: 'POST',
            url: '/multiplereleases/deletemultiplereleases',
            data: selected_releases + '&format=json',
            dataType: 'json',
            success: function (objResponse, textStatus, XMLHttpRequest) {
                if (objResponse.error == undefined) {
                    $('.delete-releases-text').hide();
                    $('#confirm_delete_releases_table').hide();
                    $('#delete_release_success_msg').removeClass('notDisplay');
                    $('#delete_releases_button').hide();
                    $('#multiple_releases_close_button').html('Close');
                    setInterval(function () {
                        $("#multiple_releases_close_button").click();
                    }, 2000);
                    document.location.href = '/index/viewexareleases?filterType=submitted,in_progress,error_correction,rejected&productType=1,2,3,5&release_date=desc';
                } else {
                    alert('<?=$this->escapejs($this->translate('Sorry, an error occurred'))?> ');
                }
                hideRefinedMask();
            },
            error: function (xhr, textStatus, errorThrown) {
                var err_obj = eval('(' + xhr.responseText + ')');
                alert('Update error: ' + err_obj.additional_info);
                hideRefinedMask();
            }
        });
    }
    function confirmmultiplereleasesOnLoad() {
        var selected_releases = $('form tbody input:checkbox:checked').serializeArray();
        $('#num_of_releases_submitting').html(selected_releases.length);
    }
    function newArtistModalOnLoad() {
        $('#modal_overlayeditReleaseModal').css('top', $('#modal_overlaynewArtistModal').css('top'));
    }
    function newArtistFilmModalOnLoad() {
        $('#modal_overlayeditFilmReleaseModal').css('top', $('#modal_overlaynewArtistFilmModal').css('top'));
    }
</script>
<?php
$options = array(
    array(
        'uniqueID' => 'editReleaseModal',
        'url' => '/releasebuilder/createreleasemodal',
        'onBeforeClose' => 'createReleaseOnBeforeClose',
        'onBeforeLoad' => 'createReleaseOnBeforeLoad',
        'onLoad' => 'createReleaseOnLoad',
        'closeOnEsc' => true,
        'closeOnClick' => true,
        'loadSpeed' => 100,
        'top' => 10
    ),
    array(
        'uniqueID' => 'newArtistModal',
        'link' => '#newArtist',
        'url' => '/artist/addartistmodal',
        'closeOnEsc' => true,
        'closeOnClick' => false,
        'loadSpeed' => 100,
        'top' => 10,
        'oneInstance' => false,
        'onLoad' => 'newArtistModalOnLoad',
        'jsonParams' => array('ajax' => 1)
    ),
    array(
        'url' => '/multiplereleases/validatemultiplereleasesmodal',
        'onLoad' => 'validateReleaseOnLoad',
        'title' => 'Validate Release',
        'closeOnEsc' => true,
        'closeOnClick' => true,
        'loadSpeed' => 100,
        'top' => 10
    ),
    array(
        'url' => '/multiplereleases/confirmmultiplereleasesmodal',
        'onLoad' => 'confirmmultiplereleasesOnLoad',
        'closeOnEsc' => true,
        'closeOnClick' => true,
        'loadSpeed' => 100,
        'top' => 10
    ),
    array(
        'url' => '/multiplereleases/confirmdeletemultiplereleasesmodal',
        'onLoad' => 'deleteReleasesModalWindowOnLoad',
        'closeOnEsc' => true,
        'closeOnClick' => true,
        'loadSpeed' => 100,
        'top' => 10
    ),
    array(
        'url' => '/multiplereleases/paymentrequiredmodal',
        'closeOnEsc' => true,
        'closeOnClick' => true,
        'loadSpeed' => 100,
        'top' => 10
    ),
    array(
        'uniqueID' => 'editFilmReleaseModal',
        'useUniqueID' => true,
        'url' => '/releasebuilder/createfilmreleasemodal',
        'onBeforeClose' => 'createFilmReleaseOnBeforeClose',
        'onBeforeLoad' => 'createFilmReleaseOnBeforeLoad',
        'onLoad' => 'createFilmReleaseOnLoad',
        'closeOnEsc' => true,
        'closeOnClick' => true,
        'loadSpeed' => 100,
        'top' => 10
    ),
    array(
        'uniqueID' => 'newArtistFilmModal',
        'useUniqueID' => true,
        'link' => '#newArtist',
        'url' => '/artist/addartistmodal',
        'closeOnEsc' => true,
        'closeOnClick' => true,
        'loadSpeed' => 100,
        'top' => 10,
        'oneInstance' => false,
        'onLoad' => 'newArtistFilmModalOnLoad',
        'jsonParams' => array('ajax' => 1)
    )
);
echo $this->modalwindow($options, $this->featureVendorContext);
$loadbaroptions = array(
    array('loadingbarid' => 'onsaverelease', 'loadingtext' => 'Please Wait....'),
    array('loadingbarid' => 'onsavefilmrelease', 'loadingtext' => 'Please Wait....'));
echo $this->Loadingimage($loadbaroptions);
?>
