<?php
// Show Movie Details
if(isset($_REQUEST['movie_slug'])) {
    require_once(dirname(__FILE__) . "/config.php");
    $slug = trim($_REQUEST['movie_slug']);
    $show_all_content = false;

    /*$optres['css'][] = "../style.css";
    $optres['js'][] = "../js/jquery-latest.js";*/
    $optres['css'][] = $path . "assets/plugins/prettyphoto/prettyPhoto.css";
    $optres['js'][] = $path . "assets/plugins/prettyphoto/jquery.prettyPhoto.js";

    require_once(dirname(__FILE__) . "/../../imCinemaAdmin/classes/movie.class.php");
    //$mc = $_req_data['content_code'];
    $t = new Movie();
    $t->get_movie_by_slug($slug);
    if($t->poster_large == "") $t->poster_large = $t->poster;
    $mc = $t->movie_code;
    $img_path = "$include_www/imCinemaAdmin/movies/" . $mc . "/";

    $poster = ($t->poster_large != "") ? $t->poster_large : $t->poster;
    $poster_file = dirname(__FILE__) . "/../../imCinemaAdmin/movies/" . $t->movie_code . "/" . $poster;
    $no_poster_file = dirname(__FILE__) . "/../../imCinemaAdmin/movies/no-poster.png";
    $poster_path = file_exists($poster_file) ? $poster_file : $no_poster_file;

    $poster_path = str_replace(dirname(__FILE__) . "/../../", $full_uri, $poster_path);


    $webpage_title_en = $t->title . ' (' . $t->year . ')';
    $meta['description'] = '';
    if(trim($t->plot) != "" && trim($t->plot) != trim($t->storyline)) {
        $meta['description'] = trim($t->plot);
    }

    ?>
    <header>
        <h1 class="page-title"><?php echo $t->title . ' (' . $t->year . ')';?></h1>
    </header>
    <div class="article-body cyprus">
        <div class="container-fluid">
            <div class="row movie-specs">
                <div class="col-sm-3 col-xs-10 mv-poster" data-mh="group-name-<?=$mc?>">
                    <img src="<?=$poster_path;?>" class="img-responsive" rel="<?php echo $mc;?>">
                    <div class="mv-media">

                        <?php
                        $mi = $t->media_images;
                        if($mi != "") {
                            $mi = explode("|", $mi);
                            $mi_url = $img_path . $mi[0];
                            echo '<a href="', $mi_url , '" rel="',$t->movie_code,'|',$mi[0],'" class="media_image"><i class="fa fa-photo fa-fw"></i> Media Images</a>';
                        }

                        $mt = $t->trailers;
                        if(trim($mt) != "") {
                            $text_trailers = "Trailer";
                            $mt = explode("|", $mt);
                            if(count($mt) > 1) $text_trailers = "Trailers";
                            echo '<a href="', $mt[0] , '" rel="',$t->movie_code,'" class="trailers"><i class="fa fa-film fa-fw"></i> Watch ',$text_trailers,'</a>';
                        }
                        ?>
                    </div>
                </div>
                <div class="col-sm-7 col-xs-10 mv-details" data-mh="group-name-<?=$mc?>">
                    <table class="table">
                        <thead>
                        <tr>
                            <th colspan="2" class="col-xs-10">Movie Details</th>
                        </tr>
                        </thead>
                        <tbody>
                        <tr>
                            <td class="col-sm-2 col-xs-3">Genres:</td>
                            <td class="col-sm-8 col-xs-7"><span class="text-danger"><?php echo $t->genres;?></span></td>
                        </tr>
                        <tr>
                            <td class="col-sm-2 col-xs-3">Runtime:</td>
                            <td class="col-sm-8 col-xs-7"><?php echo $t->runtime;?> min</td>
                        </tr>
                        <tr>
                            <td class="col-sm-2 col-xs-3">Rating:</td>
                            <td class="col-sm-8 col-xs-7">
                                <strong><span class="text-danger"><?php echo $t->cy_rating;?></span></strong>
                                <?php
                                if(isset($ratings[$t->cy_rating])) echo '<span class="text-muted"> - ' . $ratings[$t->cy_rating] . '</span>';
                                ?>
                            </td>
                        </tr>
                        <tr>
                            <td class="col-sm-2 col-xs-3">Director:</td>
                            <td class="col-sm-8 col-xs-7"><?php echo $t->directors;?></td>
                        </tr>
                        <tr>
                            <td class="col-sm-2 col-xs-3">Stars:</td>
                            <td class="col-sm-8 col-xs-7"><?php echo $t->stars;?></td>
                        </tr>

                        <?php
                        if(trim($t->plot) != "" && trim($t->plot) != trim($t->storyline)) {
                            ?>
                            <tr>
                                <td class="col-sm-2 col-xs-3">Plot:</td>
                                <td class="col-sm-8 col-xs-7"><?php echo $t->plot; ?></td>
                            </tr>

                            <?php
                        }
                        ?>
                        <?php
                        if(trim($t->storyline) != "") {
                            ?>
                            <tr>
                                <td class="col-sm-2 col-xs-3">Storyline:</td>
                                <td class="col-sm-8 col-xs-7"><?php echo $t->storyline;?></td>
                            </tr>
                            <?php
                        }
                        ?>
                        </tbody>
                    </table>
                </div>
            </div>



            <?php
            $q = "select c.*, s.* from im_cinemas c, im_showtimes s where c.cinema_code=s.cinema_code and s.movie_code='$mc' order by s.location ASC, c.cinema_title ASC;";
            $r = @mysql_query($q);
            if($r && mysql_num_rows($r)>0) {
            ?>
            <div class="row cinema-schedules movie-cinemas">
                <h2>
                    <?php
                    echo '<strong>Cyprus cinemas</strong>' . ' playing <em>' . stripslashes($t->title) . '</em>';
                    if ($admin_view) {
                        echo '<a href="javascript:;" rel="' . $dd . '|' . $t->movie_code . '" class="pull-right hidden-xs add_cinema_sched btn btn-warning btn-xs">Add Cinema</a>';
                    }
                    ?>
                </h2>
                <?php

                $all_cinemas = [];

                while ($row = mysql_fetch_assoc($r)) {
                    $loc = $row['location'];
                    if(!isset($all_cinemas[$loc])) $all_cinemas[$loc] = [];
                    $all_cinemas[$loc][] = $row;
                }

                foreach($all_cinemas as $loc => $cinemas) {
                    ?>
                    <div class="box box-default box-solid">
                        <div class="box-header with-border cinema-locations">
                            <h3><strong><?=$loc?> cinemas</strong> playing <em><?=$t->title;?></em></h3>
                        </div>
                        <div class="container-fluid">

                            <?php
                            foreach($cinemas as $row) {
                                ?>
                                <?php
                                if ($sales_view) {
                                    //echo '<pre>', var_export($row, true), '</pre>';
                                }
                                $cin = $row;
                                ?>
                                    <div class="row cinema-item">
                                        <div class="col-sm-3">
                                            <div class="row">
                                                <div class="col-xs-10 cinema-title-container">
                                                    <?php
                                                    if ($sales_view) {
                                                        echo '<a href="javascript:;" class="edit_cinema_sched cinema-title" rel="' . $cin['id'] . '">' . $cin['cinema_title'] . '</a>';
                                                    } else {
                                                        echo '<span class="cinema-title">' . $cin['cinema_title'] . '</span>';
                                                    }
                                                    ?>
                                                </div>
                                            </div>

                                            <div class="row cine-info">
                                                <div class="col-sm-10 col-xs-4">
                                                    <span><i class="fa fa-phone fa-fw"></i> <?php echo $cin['phone']; ?></span>
                                                </div>
                                                <?php
                                                if ($cin['movie_gr'] == 1) {
                                                ?>
                                                <div class="col-sm-5 col-xs-3"><span class="label label-info"
                                                                                     title="Greek Language">Greek</span></div>
                                                <div class="col-sm-5 col-xs-3"><span class="label label-danger" title="3D Movie">3D Movie</span>
                                                </div>
                                                <?php
                                                }
                                                /*if($cin['movie_3d'] == 1) {
                                                    */ ?><!--
                                                        <div class="col-xs-5"><img src="<?php /*echo $path . 'images/navigation/3dmovie.jpg';*/ ?>" width="45" height="33" border="0" alt="3D Movie"></div>
                                                        --><?php
                                                /*                                                }*/

                                                ?>
                                            </div>

                                        </div>
                                        <div class="col-sm-7">
                                            <?php
                                            display_schedule($cin['showtimes']);
                                            ?>
                                        </div>

                                    </div>
                                <?php
                            }

                            ?>

                        </div>
                     </div>
                    <?php
                }
            }
            ?>
        </div>
    </div>
    <?php
    include_once(dirname(__FILE__) . "/im_related.php");

}