<?php

use Legacy\KatapyShare\SiteContext;

include_once '../katapyphp/katapysetup.php';

include_once '../sitecontext.php';
SiteContext::setup('../');
$uP = SiteContext::getUrlPrefix();
$dP = SiteContext::getDocPrefix();

include_once '../includes/lang.php';

include_once '../includes/nocache-header.php';

$rewind = false;
if (isset($_REQUEST['p1'], $_REQUEST['p2'])) {
//    $uP .= '../';
    $pieces = explode('-', $_REQUEST['p1']);
    $lib = $pieces[0];
    $pieces = explode('-', $_REQUEST['p2']);
    $seriesId = $pieces[0];
    //if (false == isset($_REQUEST['pagerefresh'])) {
        //use gallery cache in Redis
    //    $seriesEnc = RedisSession::getObjectCacheValue('galleries', $seriesId);
    //}
    //if (empty($seriesEnc)) {
        $series = KatapyVod::getGallery($seriesId, $lib);
    //    RedisSession::setObjectCacheValue('galleries', $seriesId, json_encode($series));
    //} else {
    //    $series = $seriesEnc;
    //}
    if ('N' == $series->publishflg) {
        header('Location: '.$uP.'home');

        exit();
    }
    //$location = KatapyCms::getGalleryLocation($series->id, $series->mediactrCd);
    $seasonId = null;
    // echo json_encode($location);
    if (isset($_REQUEST['p3'])) {
//        $uP .= '../';
        $pieces = explode('-', $_REQUEST['p3']);
        $seasonId = $pieces[0];
        if ('FOLDE' == $series->typeCd) {
            $series = KatapyVod::getGallery($seasonId, $lib);
        }
        if ('N' == $series->publishflg) {
            header('Location: '.$uP.'home');

            exit();
        }
    } elseif ('FOLDE' == $series->typeCd) {
        header('Location: '.$uP.'home');

        exit();
    }
    if (isset($_REQUEST['p4'])) {
//        $uP .= '../';
        $pieces = explode('-', $_REQUEST['p4']);
        $contentId = $pieces[0];
        $content = KatapyVod::getContent($contentId, $lib);
        if ('N' == $content->publishflg) {
            header('Location: '.$uP.'home');

            exit();
        }
        if (false !== strpos($_REQUEST['p4'], '-rewind')) {
            $rewind = true;
        }
        $seasonId = $content->catId;
    }
    if (null == $series) {
        //header("Location: " . $uP . "error404");
        header('Location: '.$uP.'home');

        exit();
    }
} else {
    header('Location: '.$uP.'home');

    exit();
}

//echo json_encode($series); die();

//automatically expire app content to refresh the screen
if (isset($_REQUEST['expire'])) {
    $url = SiteContext::getFullServerUrl().'/android/show.php?lib='.$library.'&cd='.$series->cd.'&byseries=true&expire';
    $response = file_get_contents($url);
    $url = SiteContext::getFullServerUrl().'/android/contents.php?lib='.$library.'&cd='.$series->cd.'&byseries=true&expire';
    $response = file_get_contents($url);
}
if (isset($_REQUEST['pagerefresh'])) {
    $url = SiteContext::getFullServerUrl().'/android/show.php?lib='.$library.'&cd='.$series->cd.'&byseries=true&pagerefresh';
    $response = file_get_contents($url);
    $url = SiteContext::getFullServerUrl().'/android/contents.php?lib='.$library.'&cd='.$series->cd.'&byseries=true&pagerefresh';
    $response = file_get_contents($url);
}

// echo json_encode($location);
$title = (null == $content) ? $series->nm : $content->nm; // . " Channel";

$metaDesc = (null == $content) ? strip_tags($siteName.' '.$series->nm.' - '.strip_tags($series->shortDesc)) : strip_tags($siteName.' '.$content->nm.' - '.strip_tags($content->shortDesc));
if (strlen($metaDesc) > 128) {
    $metaDesc = substr($metaDesc, 0, 128).'...';
}
$metaDesc = htmlentities($metaDesc);
$lrgimgthumb = (null == $content) ? $series->lrgimgthumb : $content->lrgimgthumb;
$nm = (null == $content) ? html_entity_decode($series->nm) : html_entity_decode($content->nm);

//$metaDesc = str_replace("&quot; ", "", $metaDesc);
//$metaDesc = str_replace(" &quot;", "", $metaDesc);
$metaDesc = str_replace('&quot;', '', $metaDesc);
$metaDesc = str_replace("\r\n", ' ', $metaDesc);
$metaDesc = str_replace("\n", ' ', $metaDesc);

$pageUrl = $_SERVER['REQUEST_URI'];
$rootUrl = (!empty($_SERVER['HTTPS']) ? 'https' : 'http').'://'.$_SERVER['HTTP_HOST']; // . '/';

//tagline
$tags = [];
if (null == $content) {
    if (false == empty($series->productionT)) {
        array_push($tags, substr($series->productionT, -4));
    }
    if (false == empty($series->runtime)) {
        array_push($tags, $series->runtime.' mins');
    }
    if (false == empty($series->tagline)) {
        array_push($tags, $series->tagline);
    }
    if (0 == sizeof($tags) && $usePlaceholders) {
        array_push($tags, $placeholder_tagline);
    }
    $shortDesc = false == empty($series->shortDesc) ? strip_tags($series->shortDesc) : ''; //$usePlaceholders?$placeholder_desc:"";
} else {
    if (empty($content->seriesId)) {
        array_push($tags, $content->catNm);
    } else {
        array_push($tags, $content->seriesNm);
    }
    if ($content->seriesNm != $content->catNm) {
        array_push($tags, $content->catNm);
    }
    if (false == empty($content->productionT)) {
        array_push($tags, substr($content->productionT, -4));
    }
    if (false == empty($content->runtime)) {
        array_push($tags, $content->runtime.' mins');
    }
    if (false == empty($content->tagline)) {
        array_push($tags, $content->tagline);
    }
    if (0 == sizeof($tags) && $usePlaceholders) {
        array_push($tags, $placeholder_tagline);
    }
    $shortDesc = false == empty($content->shortDesc) ? strip_tags($content->shortDesc) : ''; //$usePlaceholders?$placeholder_desc:"";
}
//$shortDesc = Encoding::fixUTF8($shortDesc);

$tagline = implode(' | ', $tags);

//season(s)
$season = null;
if ('SERIE' == $series->typeCd || 'SERIA' == $series->typeCd || 'MOVIE' == $series->typeCd || 'ALBUM' == $series->typeCd) {
    $galleries = KatapyVod::getSeasonsBySeries($series->cd, $lib);
    $seasons = EpisodeService::getSeasons($galleries);
} else {
    $seasons = [];
    $season = clone $series; //copy($series);
    $season->nm = 'Videos';
    array_push($seasons, $season);
}

//echo json_encode($seasons);
if (null == $season && null != $seasons && sizeof($seasons) > 0) {
    if (empty($seasonId)) {
        $season = $seasons[0];
    } else {
        $season = KatapyApp::getObjById($seasonId, $seasons);
    }
}

//echo json_encode($season);

//content
if (null != $season) {
    if ('VIDEO' == $series->typeCd || 'AUDIO' == $series->typeCd) {
        $seriesContent = KatapyVod::getContentsFromGallery($season->cd, $lib);
        $seasonContent = $seriesContent;
    } else {
        $seriesContent = KatapyVod::getContentsFromSeries($series->cd, $lib, 500);
        $seasonContent = EpisodeService::getListByCatId($season->id, $seriesContent);
    }
    $thumbnailColumns = 5;
    $thumbnailMax = 500;
    $thumbData = 'videos';
    $thumbnailMax = 8;
    $vt_displaymode = 'LANDS';
    // echo json_encode($seasonContent);
}
//fix short desc
if (empty($shortDesc) && 1 == sizeof($seasonContent)) {
    $shortDesc = strip_tags($seasonContent[0]->shortDesc);
}

//background
$bgImage = null;
if (null != $content && 'Video' == $content->mediatypeNm) {
    $bgImage = $content->imgUrl;
}
if (null == $bgImage) {
    $bgImage = KatapySections::getBackgroundImageForGallery($series->cd, $series->mediactrCd);
}
//echo "image: " . $bgImage; die();
if (null == $bgImage && sizeof($seasonContent) > 0) {
    $bgImage = $seasonContent[0]->imgUrl;
}
if (null == $bgImage) {
    $bgImage = $uP.'assets/default-bg2.jpg';
}

//load playstates to resume current content
$playstates = KatapyBookmark::loadPlaystates(200);
$watchlist = KatapyBookmark::loadWatchlist(100);
$isWatchlisted = EpisodeService::isSeriesOnWatchlist($watchlist, $series->id);
//echo "isWatchlisted = " . $isWatchlisted;

$isResume = false;
if (null == $content) {
    if ('MOVIE' == $series->typeCd) {
        $series = EpisodeService::applyPlaystateToMovie($series, $seasons, $playstates);
    } else {
        $series = EpisodeService::applyPlaystateToSeries($series, $seasonContent, $playstates);
    }
    $currentContent = $series->currentContent;
    if (null == $currentContent) {
        $currentContent = $seasonContent[0];
    }
} else {
    if (false == $rewind) {
        $content = EpisodeService::applyPlaystateToContent($content, $playstates);
    }
    $currentContent = $content;
}
$isResume = (false == empty($currentContent) && false == empty($currentContent->percent));
$isAuthorized = true;

//$locArray = array();
//if ($location->street1) { array_push($locArray, $location->street1); }
//if ($location->street2) { array_push($locArray, $location->street2); }
//if ($location->cityNm) { array_push($locArray, $location->cityNm); }
//if ($location->stateNm) { array_push($locArray, $location->stateNm . " " . $location->zip); }
//$address = implode(", ", $locArray);

$shareBaseUrl = $siteUrl.'/';
if (false === strpos($shareBaseUrl, '//')) {
    $shareBaseUrl = 'https://'.$shareBaseUrl;
}
//$shareBaseUrl .= $accapp . "/";
if (null != $content) {
    $shareUrl = SiteContext::getUrlForEpisode($shareBaseUrl, $content);
} else {
    $shareUrl = SiteContext::getUrlForSeries($shareBaseUrl, $series);
}

$isAudio = (false == empty($content) && 'Audio' == $content->mediatypeNm);
$isAudioGallery = ('AUDIO' == $series->typeCd || 'SERIA' == $series->typeCd || 'ALBUM' == $series->typeCd);

?>
<!DOCTYPE html>
<html lang="en" class="<?php echo $globalOptions; ?>">
<head>
    <meta itemprop="name" content="<?php echo $nm; ?>">
    <meta itemprop="description" content="<?php echo $metaDesc; ?>">
    <meta itemprop="image" content="<?php echo $lrgimgthumb; ?>">

    <meta name="twitter:card" content="video"/>
    <meta name="twitter:site" content="@katapy"/>
    <meta name="twitter:title" content="<?php echo $nm; ?>"/>
    <meta name="twitter:image" content="<?php echo $lrgimgthumb; ?>"/>
    <meta name="twitter:description" content="<?php echo $metaDesc; ?>"/>
    <meta name="twitter:creator" content="@katapy"/>
    <meta name="twitter:url" content="<?php echo $rootUrl.$pageUrl; ?>"/>
    <meta name="twitter:image:src" content="<?php echo $lrgimgthumb; ?>">

    <meta property="og:url" content="<?php echo $lrgimgthumb; ?>"/>
    <meta property="og:type" content="image/jpeg"/>
    <meta property="og:title" content="<?php echo $nm; ?>"/>
    <meta property="og:description" content="<?php echo $metaDesc; ?>"/>
    <meta property="og:image" content="<?php echo $lrgimgthumb; ?>"/>
    <meta property="og:image:width" content="1920"/>
    <meta property="og:image:height" content="1080"/>
    <meta property="og:site_name" content="<?php echo $siteName; ?>"/>
    <?php $excludeMetaTagsForSocial = true;

    include $dP.'includes/metainf.php'; ?>
    <title><?php echo empty($content) ? $series->nm : EpisodeService::getEpisodeName($currentContent); ?></title>
    <link rel="stylesheet" href="<?php echo $uP; ?>css/sweetalert2.min.css"/>
    <link rel="stylesheet" type="text/css" href="<?php echo $uP; ?>css/jssocials.css"/>
    <link rel="stylesheet" type="text/css" href="<?php echo $uP; ?>css/jssocials-theme-plain.css"/><!--
    <link rel="stylesheet" href="<?php echo $uP; ?>css/font-awesome.min.css" />-->
    <style type="text/css">
        .kt-hero-wrapper {
            margin-top: -5.3rem;
            padding-top: 5.3rem;
            background: #000000;
            padding-bottom: 0.1rem;
        }

        .kt-lg-heading {
            margin-top: 7rem !important;
        }
    </style>
    <?php if ($isAudio) { ?>
        <style type="text/css">
            .video-js-wrapper {
                height: 0px !important;
                width: 100%;
            }

            .video-js-wrapper .embed-responsive {
                height: 66px !important;
            }

            .video-js .vjs-big-play-button {
                display: none !important;
            }

            .video-js .vjs-control-bar {
                display: flex !important;
                top: 2px;
                left: 2px !important;
                visibility: visible !important;
                opacity: 1 !important;
            }

            .video-js .vjs-title-display {
                display: none !important;
            }

            .video-js .vjs-rewind-control {
                display: none !important;
            }

            .video-js .vjs-fullscreen-control {
                display: none !important;
            }

            .video-js {
                background-image: none !important;
            }

            @media (max-width: 1200px) {
                .video-js-wrapper .embed-responsive {
                    height: 72px !important;
                }

                .video-js .vjs-custom-control-spacer {
                    display: flex !important;
                    padding: 10px;
                }
            }
        </style>
    <?php } ?>
</head>

<body class="<?php echo $globalOptions; ?> kt-series">
<?php

// NAV

?>
<?php include $dP.'includes/nav.php'; ?>
<h1 class="vis-hid" id="page-heading" data-gallery-id="<?php echo $series->id; ?>"><?php echo $siteName; ?></h1>
<!--<div class="kt-btn-back kt-hand" style="top:0"><a href="javascript:AppActions.loadPage('home');"><i class="fa fa-chevron-left mr-2"></i><span>Back</span></a></div>-->
<div class="kt-top-img">
    <div class="kt-img" style="background-image:url('<?php echo $bgImage; ?>');"></div>
    <div class="kt-shadow"></div>
</div>
<div class="kt-hero-wrapper">
    <?php if (null == $content) { ?>
        <div class="kt-btn-back"><a class="link-effect"
                                    href="javascript:AppActions.loadPage('home');"><span>Accueil</span></a><i
                    class="fa fa-chevron-left mr-2 ml-2"></i><span class="last"><?php echo $series->nm; ?></span></div>
    <?php } else { ?>
        <div class="kt-btn-back"><a class="link-effect"
                                    href="javascript:AppActions.loadPage('home');"><span>Accueil</span></a><i
                    class="fa fa-chevron-left mr-2 ml-2"></i><a class="link-effect"
                                                                href="javascript:AppActions.loadPage('<?php echo SiteContext::getUrlForSeries('', $series); ?>');"><span
                        class="last"><?php echo $series->nm; ?></span></a><i
                    class="fa fa-chevron-left mr-2 ml-2"></i><span
                    class="last"><?php echo EpisodeService::getEpisodeName($currentContent); ?></span></div>
    <?php } ?>
    <?php

    // Title
     ?>
    <div class="kt-hero fade">

        <div class="kt-img-overlay pl-3 pl-md-4">
            <div class="kt-img-overlay_content">
                <h1 class="kt-lg-heading two-lines"><?php echo empty($content) ? $series->nm : EpisodeService::getEpisodeName($currentContent); ?></h1>
                <!--title="<?php echo htmlentities($series->nm); ?>" data-toggle="tooltip" data-placement="bottom"-->
                <p class="kt-hero-details three-lines"><?php echo $tagline; ?></p>
                <p class="kt-lg-info four-lines"><?php echo $shortDesc; ?></p>
                <?php

                // TAGS
                 ?>

                <div class="mb-3">

                    <?php //display categories with links
                    $tags_field = $series->folderNm; // . "," . $series->categories;
                    if (null != $tags_field && '' != $tags_field && 'N/A' != $tags_field) { ?>
                        <p class="kt-keywords">Catégories:
                            <?php
                            $tags = [];
                            $tags = array_unique(preg_replace('/^ /', '', explode(',', $tags_field)));
                            foreach ($tags as $rowcount => $tag) {
                                if (' ' != $tag) {
                                    echo '<a class="kt-keyword link-effect" href="'.$uP.'videos/'.$series->folderId.'-'.SiteContext::encodePrettyUrlParam(trim($tag)).'">'.$tag.'</a>';
                                }
                            } ?>
                        </p>
                    <?php } ?>

                    <?php //display author with links
                    $tags_field = (null == $content) ? $series->author : $content->author;
                    if (null == $tags_field) {
                        $tags_field = (null == $content) ? $series->actors : $content->actors;
                    }
                    if (null != $tags_field && '' != $tags_field && 'N/A' != $tags_field) { ?>
                        <p class="kt-keywords">Intervenants:
                            <?php
                            $tags = [];
                            $tags = array_unique(preg_replace('/^ /', '', explode(',', $tags_field)));
                            foreach ($tags as $rowcount => $tag) {
                                //$vt_url = SiteContext::getUrlForGenre($uP, $vt);
                                if (' ' != $tag) {
                                    echo '<a class="kt-keyword link-effect" href="'.$uP.'intervenants/1-'.urlencode(trim($tag)).'">'.$tag.'</a>';
                                }
                            } ?>
                        </p>
                    <?php } ?>

                </div>
                <?php if ($isResume && false == $isAudio) {
                                // PROGRESS BAR
                     ?>
                    <p class="kt-md-info">
                    <div class="progress kt-event-progress">
                        <div class="progress-bar" data-percentage="<?php echo $currentContent->percent; ?>"></div>
                    </div>
                    <div class="text-white push-5-r kt-event-progress-label"><?php echo EpisodeService::getMinutesLeftFormatted($currentContent); //echo $currentContent->seekTime;?></div>
                    </p>
                <?php
                            } ?>
                <?php

                // ACTION BUTTONS

                $actionLabel = EpisodeService::getPlayActionLabel($currentContent, $series, $isResume);
                $actionLabel_set = '';
                if ('Coming Soon' == $actionLabel) {
                    $actionLabel_set = 'coming_soon';
                } elseif ('Resume') {
                    $actionLabel_set = 'resume';
                } else {
                    $actionLabel_set = 'watch_vod';
                }
                ?>
                <div class="kt-btn-list-x mt-5">
                    <?php if ($isAuthorized) {
                    if ($isAudioGallery) {
                        $playUrl = SiteContext::getUrlForEpisode($uP, $currentContent);
                    } else {
                        $playUrl = SiteContext::getUrlForContent($uP, $currentContent);
                    }
                    if (false == $isAudio) {
                        ?>
                            <button class="btn btn-light btn-lg"
                                    onclick="javascript:location.href='<?php echo $playUrl; ?>';"
                                    <?php if (false !== strpos($actionLabel, '...')) { ?>data-toggle="tooltip"
                                    title="<?php echo EpisodeService::getEpisodeName($currentContent); ?>"<?php } ?>><?php echo $lang_data->{$actionLabel_set}->{$lang_set}; ?></button>
                            <?php if ($isResume) { ?>
                                <button class="btn btn-outline-light btn-lg"
                                        onclick="javascript:location.href='<?php echo $playUrl; ?>-rewind';">Start Over
                                </button>
                            <?php } // of isResume?>
                        <?php
                    } // of isAudio == false?>
                    <?php
                } else { // of if isAuthorized == true?>
                        <button class="btn btn-light btn-lg">Rent or Buy</button>
                    <?php } ?>
                    <button class="btn btn-outline-light btn-lg kt-share-btn"
                            data-toggle="dropdown"><?php echo $lang_data->share->{$lang_set}; ?></button>
                    <br><br><br>
                    <div class="kt-dropdown-share d-none">
                        <?php
                        if (null == $content) {
                            $subject = strtoupper($appcd)." - {$series->nm}";
                            //if ($location) $subject .= " - $location->street1, $location->stateNm $location->zip";
                            $description = $series->shortDesc;
                        } else {
                            $subject = strtoupper($appcd)." - {$content->nm}";
                            //if ($location) $subject .= " - $location->street1, $location->stateNm $location->zip";
                            $description = $content->shortDesc;
                        }

                        ?>
                        <div class="share-container" data-subject='<?php echo urlencode($subject); ?>'
                             data-description='<?php echo urlencode($description); ?>'
                             data-url='<?php echo urlencode($shareUrl); ?>'></div>
                    </div>

                    <?php if (false) { //($lib != $library) {?>
                        <div class="kt-btn-group">
                            <button class="btn btn-outline-light btn-lg" data-toggle="dropdown">More Options</button>
                            <!--onclick="location.href='<?php echo $shopUrl; ?>';"-->
                            <div class="dropdown-menu dropdown-menu-right font-size-sm"
                                 aria-labelledby="dropdown-default-primary" x-placement="bottom-end">
                                <!--<a class="dropdown-item" href="javascript:console.log('related documents');">Related Documents</a>
                                <div class="dropdown-divider"></div>-->

                                <a class="dropdown-item" href="<?php echo $shopUrl; ?>" target="_blank">More Purchase
                                    Options</a>
                            </div>
                        </div>
                    <?php } ?>
                    <br clear="all">
                </div>
                <?php
                //$infoQ = '';
                //if ($location->nm) {$infoQ .= str_replace(' ', '+', $location->nm);}
                //if ($location->street1) {$infoQ .= '+'.str_replace(' ', '+', $location->street1);}
                //if ($location->cityNm) {$infoQ .= ',+'.str_replace(' ', '+', $location->cityNm);}
                //if ($location->stateNm) {$infoQ .= ',+'.str_replace(' ', '+', $location->stateNm);}
                ?><!--
          <div class="kt-btn-icons-list row">
             <div class="col-3 col-md-auto">
                <a class="btn kt-btn-icon" href="https://www.google.com/maps/dir/?api=1&destination=<?php echo $infoQ; ?>" target="_blank"><i class="fas fa-directions"></i><span>Directions</span></a>
            </div> 
             <div class="col-3 col-md-auto kt-addto-btn">
                <a class="btn kt-btn-icon"><i class="fas fa-plus"></i><span><?php echo $lang_data->add_to->{$lang_set}; ?>...</span></a>
            </div> 
            <div class="col-3 col-md-auto kt-share-btn">
                <a class="btn kt-btn-icon"><i class="fas fa-share"></i><span><?php echo $lang_data->share->{$lang_set}; ?></span></a>
            </div> 
            <div class="col-3 col-md-auto">
                <a href="http://google.com/search?q=<?php echo $infoQ; ?>" target="_blank" class="btn kt-btn-icon"><i class="fas fa-store-alt"></i><span>More Info</span></a>
            </div>
          </div> -->
                <?php
                //$evt_nm = $series->nm;
                //$evt_desc = $series->shortDesc;
                //$evt_location = $infoQ;
                //$googleCalUrl = "http://www.google.com/calendar/event?action=TEMPLATE&text=" . urlencode($evt_nm) . "&details=" .  urlencode($evt_desc) . "&location=" . urlencode($evt_location) . "&trp=false&sprop=" . urlencode($siteName) . "&sprop=name:" .urlencode($siteUrl);
                //$iCalUrl = $uP . "ical?id=" . $series->id . "&lib=" . $lib;
                ?>
                <div class="kt-dropdown"><!--
              <div class="kt-dropdown-addto d-none">
                <a href="<?php echo $iCalUrl; ?>" class="d-block my-1" download><?php echo $lang_data->add_to_outlook->{$lang_set}; ?></a>
                <a href="javascript:window.open('<?php echo $googleCalUrl; ?>');" class="d-block my-1"><?php echo $lang_data->add_to_google_calendar->{$lang_set}; ?></a>
              </div>-->

                </div>

                <?php if ($isAudio) { ?>
                    <br/>
                    <div class="kt-btn-list-x mt-5 mb-5">
                        <?php $playerembed = 'html';
                        $video = $content;

                        include $dP.'src/vodplayer-home-alt.php'; ?>
                    </div>
                <?php } //of if $isAudio?>

            </div>
        </div>
        <br clear="all">
    </div>
</div>

<?php

// AUDIO EPISODES

if ('AUDIO' == $series->typeCd || 'SERIA' == $series->typeCd || 'ALBUM' == $series->typeCd) {
    echo '<div class="container-fluid audio-episodes" style="background:#EFEFEF;position: absolute;padding-top: 2rem">';
    echo '<div class="row">';

    foreach ($seasons as $key => $season) {
        $seasonContent = EpisodeService::getListByCatId($season->id, $seriesContent);
        $owlLazyLoad = 'false';

        include $dP.'includes/featured-section-audioseason.php';
    }

    echo '</div>';

    include $dP.'includes/footer.php';
    echo '</div>';
} elseif ('SERIE' == $series->typeCd && sizeof($seasons) > 1) { ?>
    <div class="container-fluid" style="margin-top: 2rem;background:#EFEFEF;position: absolute;padding-top: 2rem">
        <?php
        foreach ($seasons as $key => $season) {
            $seasonContent = EpisodeService::getListByCatId($season->id, $seriesContent);

            // SEASON EPISODES ?>
            <?php include $dP.'modules/slider-section_season.php'; ?>
        <?php
        } ?>
        <?php include $dP.'includes/footer.php'; ?>
    </div>
    <?php
} else {
            // VIDEO GRID

    $featureContent = EpisodeService::getListByCatId($seasons[0]->id, $seriesContent);
            $featureContent = array_reverse($featureContent);
            $isSeries = false;
            $thumbData = 'videos';
            $dataLink = 'SHOW';
            $vt_displaymode = 'LANDS';
            $thumbnailColumns = 4;
            $maxGalleryThumbs = 200;
            $sliderTitle = 'Episodes'; ?>

    <div class="container-fluid" style="margin-top: 2rem;background:#EFEFEF;position: absolute;padding-top: 2rem">

        <h2 class="kt-slider-title" style="margin-left: 1rem; padding-top: 1rem;"><?php echo $sliderTitle; ?></h2>
        <div class="row tiled video-thumbnail-results kt-slider mt-0 <?php echo $globalOptions; ?> <?php echo $sliderOptions; ?>"
             data-type="galleries" data-max="<?php echo $maxGalleryThumbs; ?>"
             data-refresh="<?php echo (isset($_REQUEST['pagerefresh'])) ? 'true' : 'false'; ?>">
            <!--<div class="owl-carousel owl-theme owl-item owl-item-<?php echo $thumbnailColumns; ?>">-->
            <?php
            $i = 0;
            $count = 0;
            while ($i < sizeof($featureContent)) {
                $vt = $featureContent[$i];
                //echo $thumbData;
                if (('videos' == $thumbData && 'Video' == $vt->mediatypeNm) || ('galleries' == $thumbData && 'Inbox' != $vt->nm)) {
                    ++$count;
                    //echo '<div class="col-md-2">';
                    if ($isSeries) {
                        include $dP.'includes/series-poster.php';
                    } else {
                        //include $dP."includes/series-thumb.php";
                        include $dP.'modules/tile/tile-thumb.php';
                        //include $dP."modules/slider/slider-thumb.php";
                        //echo '</div>';
                    }
                }
                ++$i;
            } ?>
            <div class="col-xs-12 text-center push-20-t coming-soon hidden">
                <h2 class="text-muted push-20-t" style="text-shadow: none; font-size: 20px; padding-left: 3rem">No
                    results.</h2>
            </div>

        </div>

        <?php include $dP.'includes/footer.php'; ?>

    </div>

<?php
        } ?>


<?php

// Tags PICKER

if (false) {//} (sizeof($seasonContent)>1) {
    $tag = 'Videos'; ?>
    <?php include $dP.'modules/slider-section_tags.php'; ?>
<?php
} ?>

<?php

// FOOTER

?>

<script src="<?php echo $uP; ?>js/jquery-1.11.1.min.js"></script> <?php //core framework?>
<script src="<?php echo $uP; ?>js/bootstrap.min.js"></script> <?php //core framework?>
<script src="<?php echo $uP; ?>js/owl.carousel.js"></script> <?php //thumbnail carousel?>
<script src="<?php echo $uP; ?>js/jquery.ui.totop.min.js"></script> <?php //button "to TOP"?>
<script src="<?php echo $uP; ?>js/jquery.easing.min.js"></script> <?php //button "to TOP"?>
<script src="<?php echo $uP; ?>js/jquery.lazy.min.js"></script> <?php //for thumbnail images?>
<script src="<?php echo $uP; ?>js/jquery.sticky.js"></script> <?php //for sticky nav?>
<script src="<?php echo $uP; ?>js/cookie-consent.js"></script> <?php //GDPR?>
<script type="text/javascript" src="<?php echo $uP; ?>js/v<?php echo $version; ?>_jssocials.js"></script>
<?php if ($isAudio) { ?>
    <script src="<?php echo $uP; ?>js/v<?php echo $version; ?>_main-2.0.1.js" id="page-script" data-capture="<?php $data = new stdClass();
    $data->appcd = $appcd;
    $data->groupcd = $groupcd;
    $data->base = $katapyCaptureBase;
    $data->redisid = $user->redisid;
    $data->ktyid = $user->ktyid;
    $data->date = $user->date;
    $data->country = $user->country;
    $data->channels = $user->channels;
    $data->concurrency = $trackConcurrentDevices;
    $data->ps = $trackPlaystates;
    $data->isauth = $isLoggedIn;
    $data->segment = $segmentSize;
    echo base64_encode(json_encode($data)); ?>"></script>
    <script src="<?php echo $uP; ?>js/pages/video.js"></script>
    <script src="<?php echo $uP; ?>katapyphp/js/base64.js"></script>
<?php } else { ?>
    <script src="<?php echo $uP; ?>js/v<?php echo $version; ?>_main-2.0.1.js" id="page-script"></script>
<?php } ?>
<script src="<?php echo $uP; ?>js/pages/v<?php echo $version; ?>_series.js"></script>
<script src="<?php echo $uP; ?>ph/json2.js"></script>
<script src="<?php echo $uP; ?>ph/v<?php echo $version; ?>_playhistory.js"></script>
<script type="text/javascript" src="<?php echo $uP; ?>modules/js/slider.js"></script>
<?php if ($isAudio) {
        $playerembed = 'script';

        include $dP.'src/vodplayer-home-alt.php';
    } ?>
<script>
    playhistory.uP = "<?php echo str_replace('http:', '', SiteContext::getServerUrl()); ?>";
    $(function () {
        $(".jssocials-share-facebook .jssocials-share-label").html('<?php echo $lang_data->share->{$lang_set}; ?>');
        $(".jssocials-share-twitter .jssocials-share-label").html('<?php echo $lang_data->tweet->{$lang_set}; ?>');
        $(".jssocials-share-email .jssocials-share-label").html('<?php echo $lang_data->email->{$lang_set}; ?>');
    });

    <?php if ($isAudio) { ?>
    Tracker.setTrack(<?php echo $video->id; ?>, "<?php echo str_replace('"', '', $video->nm); ?>", <?php echo $video->seriesId; ?>);
    App.initSessionTracking();
    <?php //add to playhistory
    if ($pigeonEnabled && $isLoggedIn && 'Previews' != $video->catNm && 'Trailers' != $video->catNm && 'Clips' != $video->catNm && null == $evt) {  ?>
    var obj = new Object();
    //obj.id = "<?php echo $folder->id; ?>";
    //playhistory.addPlayhistory(JSON.stringify(obj));
    obj.id = "<?php echo $video->id; ?>";
    playhistory.addContentPlayhistory(JSON.stringify(obj));
    <?php } ?>
    <?php } // of isAudio?>
</script>

<script>
    App.loader('show');
</script>
</body>
</html>
