<?php

$featureContext = array('user' => array('username' => $_SESSION['S_USERID']));

$dateFields = array('release_date', 'sale_start_date', 'preorder_date');
$dayOfWeek = '';
if (in_array($this->columnValue, $dateFields) && strtotime($this->fieldvalueNew)) {
    $dayOfWeek = ', ' . date('l', strtotime($this->fieldvalueNew));
}

if ($this->clickable) {
    $artistArr = array(
        'performer'        => 'primaryArtists',
        'featuring_artist' => 'featuringArtists',
        'feature_to_primary_artist' => 'featureToPrimaryArtists',
        'remixer_artist'   => 'remixerArtists',
        'composer'         => 'composer',
        'orchestra'        => 'orchestra',
        'ensemble'         => 'ensemble',
        'conductor'        => 'conductor',
        'producer'         => 'producer'
    );
    foreach ($artistArr as $key => $value) {
        $isExcludedBlacklistedFields = in_array($key, array('conductor', 'ensemble', 'orchestra', 'composer'));
        /* Display artist on separate line */
        if ($this->columnValue == $key) {
            if ($this->fieldvalueOld != $this->fieldvalueNew) {
                $className = 'error-correction-field ' . 'lired' . $this->columnValue;
            } else {
                $className = 'lired' . $this->columnValue;
            }
            $partistarr = explode('&nbsp;|&nbsp;', $this->fieldvalueNew);
        ?>
            <div onclick="createInputBox (
                '<?=$this->columnValue?>',
                '<?=$this->label?>',
                'releases',
                '0',
                '<?=htmlspecialchars($this->escapejs(str_replace('&nbsp;|&nbsp;', ',', $this->fieldvalueNew)), ENT_QUOTES); ?>'
            );" class="tool click error-correction-space">
            <?php
                $title = '';
                if ($this->fieldvalueOld != $this->fieldvalueNew && !empty($this->fieldvalueOld)) {
                    $fieldOldValues = str_replace('&nbsp;|&nbsp;', ', ', $this->fieldvalueOld);
                    $titleHtml = "<div class='font-weight'>Corrected</div><label class='top-space zero-margin-bottom'>" . $this->label . "</label><span class='full-width pull-left'>" . $fieldOldValues . "</span>";
                    $title = ' title="' . $titleHtml . '"';
                } ?>
                <div <?=$title?>>
                    <label class="no-margin no-padding <?=$className?>"><?=$this->label?></label>
                    <ul class="<?=$value?> approval-multiple-fields">
                        <?php
                        if (count($partistarr) == 0) { ?>
                            <li class="<?php echo $isExcludedBlacklistedFields ? '' : 'changeColor'; ?> approval-field">&nbsp;</li>
                        <?php
                        } else {
                            foreach ($partistarr as $partist) { ?>
                                <li class="<?php echo $isExcludedBlacklistedFields ? '' : 'changeColor'; ?> approval-field"><?=$partist?></li>
                        <?php
                            }
                        }
                        ?>
                    </ul>
                </div>
            </div>
        <?php
        }
    }
    if (!array_key_exists($this->columnValue, $artistArr)) { ?>
        <div id="span<?=$this->columnValue?>0"
            onclick="createInputBox(
                '<?=$this->columnValue?>',
                '<?=$this->label?>',
                'releases',
                '0',
                '<?=htmlentities($this->escapejs($this->fieldvalueNew), ENT_QUOTES, "UTF-8")?>'
            );"
            class="tool click error-correction-space ">
            <?php
                $title = '';
                $class = '';
                if ($this->fieldvalueOld != $this->fieldvalueNew) {
                    if (!empty($this->fieldvalueOld)) {
                        $titleHtml = "<div class='font-weight'>Corrected</div><label class='top-space zero-margin-bottom'>" . $this->label . "</label><span class='full-width pull-left'>" . htmlspecialchars($this->fieldvalueOld) . "</span>";
                        $title = ' title="' . $titleHtml . '"';
                    }
                    $class = ' class="error-correction-field"';
                }
            ?>
            <div <?=$title?> <?=$class?>>
                <label id="lbl<?=$this->columnValue?>"><?php echo $this->label; ?></label>
                <span class="approval-field" id="lbl<?=$this->columnValue?>">
                    <div>
                        <span class="changeColor">
                        <?php
                            $columName = array('DMS Master Carveouts', 'Dms Master Carveouts', 'Territory Carveouts', 'DMS Carveouts', 'Dms Carveouts');
                            if (in_array($this->label, $columName)) {
                        ?>
                        </span>
                        <a href="/cont_mgmt/track_restriction.php?upc=<?php echo $this->upc; ?>" target="_blank">
                            <?php echo $this->fieldvalueNew; ?>
                        </a>
                        <?php
                            } else {
                                echo htmlspecialchars($this->fieldvalueNew) . $dayOfWeek;
                            }
                        ?>
                    </div>
                </span>
            </div>
        </div>
    <?php
    }
} else { ?>
    <div class="error-correction-space">
        <label class="no-margin no-padding"><?=$this->label?></label>
        <div id="lbl<?=$this->columnValue?>">
            <span class="no-padding <?=(empty($this->fieldvalueNew) ? ' span-left-padding' : '')?>">
                <span class="changeColor">
                    <?php
                    $columName = array('DMS Master Carveouts', 'Dms Master Carveouts', 'Territory Carveouts', 'DMS Carveouts', 'Dms Carveouts');
                    if (in_array($this->label, $columName)) {
                    ?>
                </span>
                    <a href="/cont_mgmt/track_restriction.php?upc=<?php echo $this->upc; ?>" target="_blank">
                        <?php echo $this->fieldvalueNew . $dayOfWeek; ?>
                    </a>
                    <?php
                    } else {
                        echo $this->fieldvalueNew . $dayOfWeek;
                    } ?>
            </span>
        </div>
    </div>
<?php
}
?>
