<?php
@session_start();

$icons_path = dirname(__FILE__) . "/../../imCinemaAdmin/cin_imgs/";
$show_all_content = true;



$include_www = "//" . $_SERVER['HTTP_HOST'];
//$include_www = "http://lc.cypruswebsitescom.local";

$optres ['css'][] = $path . "amodules/im_cinemas/css/im_cinemas.css";
$optres ['js'][] = $path . "assets/js/jquery.matchHeight-min.js";

if($admin_view) {
   // $optres ['css'][] = $path . "amodules/im_cinemas/css/im_cinemas_admin.css";
}


/**
 * @param $s
 */









 
if($show_all_content) {

	$dd = "null";
	if(isset($module_params['module_location'])) {
		$module_location = $module_params['module_location'];
		$dd = $module_params['module_location'];
	}

	if($admin_view) {
		?>
		<div class="alert alert-info">
			<a class="btn btn-warning btn-xs" href="<?php echo $protocol.$_SERVER['HTTP_HOST'];?>/imCinemaAdmin/index.php" target="_blank">Create New Movie</a> |
			<a class="btn btn-primary btn-xs" href="javascript:;" rel="<?php echo $dd;?>" class="add_movie">Add new movie for <?php echo ucwords($dd);?></a>
		</div>
		<?php
	}


    $optres['css'][] = $path . "assets/plugins/prettyphoto/prettyPhoto.css";
    $optres['js'][] = $path . "assets/plugins/prettyphoto/jquery.prettyPhoto.js";
	if($sales_view) {
		$optres['css'][] = $path . "assets/css/jquery-ui.min.css";
		$optres['js'][] = $path . "js/jquery-ui.min.js";
	}
	
	// Get The Playin Movies
	$movies = array();
	$q = "select m.* from im_movies m, im_showtimes s where m.movie_code=s.movie_code and s.location='$dd' order by m.title asc;";
	$r = @mysql_query($q);
	if($r && mysql_num_rows($r)>0) {
		while ($row = mysql_fetch_assoc($r)) {
			$tmp = $row;
			foreach ($tmp as $fld=>$val) {
				$tmp[$fld] = stripslashes($val);
			}
			$tmp['cinema_location'] = $dd;
			
			$movies [$row['movie_code']] = $tmp;
		}
	}
	
	if(count($movies) > 0) {
		foreach ($movies as $mc=>$m) {
			require_once(dirname(__FILE__) . "/../../imCinemaAdmin/classes/movie.class.php");
			$t = new Movie();
			$t->get_movie_by_code($mc);
			$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);
			
			//$movie_popup_url = makeFriendlyUrl($t->title) . "-" . $req_modules['im_cinemas']['module_code'] . '-' . $t->movie_code . '.html';

            $movie_popup_url = $homepage_url . "movie/" . $m['slug'];
			
			?>
			<section class="box box-default box-solid">
                <header class="box-header with-border">
                    <h2><a href="<?php echo $movie_popup_url;?>" class="movie-link" target="_blank"><?php echo $m['title'] . ' (' . $m['year'] . ')';?></a><?php
                        if($admin_view) {
                            ?>
                            <a href="<?php echo $protocol.$_SERVER['HTTP_HOST'];?>/imCinemaAdmin/index.php?ex_movie=<?php echo $t->movie_code;?>&select_movie=1" target="_blank" class="btn btn-warning btn-xs hidden-xs">Edit Showtimes</a>
                            <?php
                        }
                        ?>
                    </h2>
                </header>
                <div class="container-fluid">
                    <div class="row">
                        <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">
                                <tbody>
                                <tr class="row">
                                    <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 class="row">
                                    <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 class="row">
                                    <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 class="row">
                                    <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 class="row">
                                    <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 class="row">
                                        <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 class="row">
                                        <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>

					<div class="row cinema-schedules">
						<h3>
							<?php
							echo '<strong>' . ucfirst($dd) . '</strong>' . ' cinemas 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>';
							}
							?>
						</h3>

                        <?php
                        $q = "select c.*, s.* from im_cinemas c, im_showtimes s where c.cinema_code=s.cinema_code and s.movie_code='$mc' and s.location='$dd' order by c.cinema_title ASC;";
                        $r = @mysql_query($q);
                        if($r && mysql_num_rows($r)>0) {
                            while ($row = mysql_fetch_assoc($r)) {
                                if($sales_view) {
                                    //echo '<pre>', var_export($row, true), '</pre>';
                                }
                                $cin = $row;
                                ?>
                                <div class="container-fluid">
                                    <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>
                                </div>


                                <?php
                            }
                        }
                        ?>

					</div>

                </div>

			</section>
			<?php
		}
		
		?>
		
		<?php
		
	}
}

$optres['js'][] = $path . "amodules/im_cinemas/js/im_cinemas.js";

if($admin_view) {
    $js_urls = [
        "edit_schedule_url" => $protocol.$_SERVER['HTTP_HOST']. "/amodules/im_cinemas/ajax/",
        "add_movie_url" => $protocol.$_SERVER['HTTP_HOST'] . '/amodules/im_cinemas/ajax/add_movie.php',
        "edit_cinema_sched_url" => $protocol.$_SERVER['HTTP_HOST']. '/amodules/im_cinemas/ajax/edit_cinema_sched.php',
        "add_cinema_sched_url" => $protocol.$_SERVER['HTTP_HOST']. '/amodules/im_cinemas/ajax/add_cinema_sched.php',
    ];

    ?>
    <script>
    var js_urls = <?=json_encode($js_urls);?>;
    </script>
    <?php

    $optres['js'][] = $path . "amodules/im_cinemas/js/im_cinemas_admin.js";
}