<?php
	require("__include-common.php");
	require("../account/__logincheck.php");
	if ($_GET["path"] <> '') {
		$open_path = form_str_filepath($_GET["path"]);
	}
	$open_path = str_replace("\\", "/", right_slash_strip($open_path));
	if ($open_path == "") {
		if ($_SESSION['photo_open_path'] <> "") {
			$open_path = $_SESSION['photo_open_path'];
		} else {
			$open_path = $_SESSION['login_friends_album_folder_'.$_SESSION['current_id']];
			if ($open_path == "") {
				$open_path = DEFAULT_IMAGES_FOLDER;
			}
		}
	}
	if (defined("photo_LIMITED_IMAGES_FOLDER") and photo_LIMITED_IMAGES_FOLDER <> '') {
		if ($_SESSION['システム管理者'] <> "YES" or photo_LIMITED_ADMIN_NOLIMIT <> 'YES') {
			$len = strlen(photo_LIMITED_IMAGES_FOLDER);
			if (substr($open_path, 0, $len) <> photo_LIMITED_IMAGES_FOLDER) {
				$open_path = photo_LIMITED_IMAGES_FOLDER;
			}
		}
	}
	if ($_GET['page'].'' <> '') {
		$page = intval($_GET['page']);
		if ($page < 1) {
			$page = 1;
		}
	} else {
		$page = 1;
	}
	$slidemode = $_GET['slidemode'].'';
	if ($_GET['auto'].'' <> '') {
		$_SESSION['slide_view_auto'] = $_GET['auto'];
	}
	if ($_GET['rep'].'' <> '') {
		$_SESSION['slide_view_repeat'] = $_GET['rep'];
	}
	if ($_SESSION['photo_open_path'] <> $open_path) {
		$_SESSION['photo_open_path'] = $open_path;
		$_SESSION['photo_subdir_count'] = 0;
		$_SESSION['photo_img_count'] = 0;
		unset($_SESSION['photo_subdir']);
		unset($_SESSION['photo_img']);
		unset($_SESSION['photo_img_type']);
		get_target_path_info($open_path);
	}
	$add_meta = '';
	if ($_SESSION['slide_view_auto'] == 'on') {
		if ($page < ceil($_SESSION['photo_img_count'])) {
			$add_meta = '<meta http-equiv="refresh" content="'.$_SESSION['slide_interval_time'].';';
			$add_meta .= 'url='.$_SERVER['SCRIPT_NAME'].'?page='.strval($page+1);
			$add_meta .= '&path='.urlencode($open_path);
			$add_meta .= '&mode=s&slidemode='.$slidemode.'">';
		} elseif ($_SESSION['slide_view_repeat'] == 'on') {
			$add_meta = '<meta http-equiv="refresh" content="'.$_SESSION['slide_interval_time'].';';
			$add_meta .= 'url='.$_SERVER['SCRIPT_NAME'].'?page=1';
			$add_meta .= '&path='.urlencode($open_path);
			$add_meta .= '&mode=s&slidemode='.$slidemode.'">';
		}
	}
	$filename = $_SESSION['photo_img'][$page];
	$filepath = $open_path . "/" . $filename;
	$filepath_url = urlencode($filepath);
	if ($_SESSION['photo_img_type'][$page] == 'video') {
		$getimg = "video-jpeg.php?file=".$filepath_url."&ss=".$_SESSION['video_thumb_ss'];
		$click = "video-view.php?file=".$filepath_url;
		$height_size = $_SESSION['slide_main_size'] - 2;
		$img_style = 'width: 100%;';
	} else {
		list($width, $height) = getimagesize(mb_convert_encoding($filepath, 'SJIS-win', 'UTF-8'));
		$getimg = "img-view.php?img=".$filepath_url;
		if ($width > $height) {
			$img_style = 'width: 100%;';
		} else {
			$img_style = 'height: 100%;';
		}
	}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html lang="ja">
<head>
<?php if ($add_meta <> '') echo $add_meta."\n"; ?>
<meta http-equiv="Content-Language" content="ja">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta http-equiv="Content-Style-Type" content="text/css">
<meta http-equiv="Content-Script-Type" content="text/javascript">
<meta name="author" content="ok.2nd">
<title><?= $filename ?></title>
<style type="text/css">
* { margin: 0px; padding: 0px; }
html,body {
	width: 100%;
	height: 100%;
	overflow: hidden;
}
img {
	-ms-interpolation-mode: bicubic;
	<?= $img_style ?>
}
div#slide_view {
	text-align: center;
	width: 100%;
	height: 100%;
<?php 	if ($slidemode <> 'wallpaper') { ?>
	background-color: #000000; */
<?php	} ?>
}
div#move_control {
	position: absolute;
	top: 0px; left: 0px;
	width: 100%; height: 100%;
	z-index: 1;
}
#move_control table {
	width:100%; height: 100%;
}
td#left {
	height: 90%;
	text-align: left;
}
td#right {
	height: 90%;
	text-align: right;
}
td#bottom {
	height: 10%;
	text-align: center;
	vertical-align: bottom;
}
.move {
	color: #ffffff;
	text-decoration: none;
	font-size: 200%;
}
.return {
	color: #ffffff;
	text-decoration: none;
	font-size: 200%;
	margin: 0 5px;
}
.auto {
	color: #ffffff;
	text-decoration: none;
	font-size: 100%;
	margin: 0 5px;
}
.page {
	color: #ffffff;
	font-size: 100%;
	margin: 0 5px;
}
</style>
</head>
<?php 	if ($slidemode == 'wallpaper') { ?>
<body  style="background-image: url('<?= $getimg ?>');">
<?php	} ?>
<div id="slide_view">
<?php 	if ($slidemode <> 'wallpaper') { ?>
	<?php if ($_SESSION['photo_img_count'] <> 0) { ?>
	<img src="<?= $getimg ?>" alt="<?= $filename ?>" title="<?= $filename ?>" />
	<?php } ?>

<?php	} ?>
<div>
<div id="move_control">
<table>
<tr>
<td id="left">
<?php
	if ($page > 1) {
		$movepage = $page - 1;
	} else {
		if ($_SESSION['slide_view_repeat'] == 'on') { 
			$movepage = $_SESSION['photo_img_count'];
		} else {
			$movepage = $page;
		}
	}
?>
	<a class="move" href="?path=<?= urlencode($open_path) ?>&page=<?= $movepage ?>&slidemode=<?= $slidemode ?>">&lt;</a>
</td>
<td id="right">
<?php
	if ($page < $_SESSION['photo_img_count']) {
		$movepage = $page + 1;
	} else {
		if ($_SESSION['slide_view_repeat'] == 'on') { 
			$movepage = 1;
		} else {
			$movepage = $page;
		}
	}
?>
	<a class="move" href="?path=<?= urlencode($open_path) ?>&page=<?= $movepage ?>&slidemode=<?= $slidemode ?>">&gt;</a>
</td>
</tr>
<tr>
<td id="bottom" colspan=2>
	<a class="return" href="index.php?path=<?= urlencode($open_path) ?>&page=<?= $page ?>&mode=s&auto=off">×</a>
	<?php if ($_SESSION['slide_view_auto'] == 'on') { ?>
	<a class="auto" href="?path=<?= urlencode($open_path) ?>&page=<?= $page ?>&auto=off&slidemode=<?= $slidemode ?>">Auto <span style="color: #ffff40">On</span></a>
	<?php } else { ?>
	<a class="auto" href="?path=<?= urlencode($open_path) ?>&page=<?= $page ?>&auto=on&slidemode=<?= $slidemode ?>">Auto Off</a>
	<?php } ?>
	<?php if ($_SESSION['slide_view_repeat'] == 'on') { ?>
	<a class="auto" href="?path=<?= urlencode($open_path) ?>&page=<?= $page ?>&rep=off&slidemode=<?= $slidemode ?>">Repeat <span style="color: #ffff40">On</span></a>
	<?php } else { ?>
	<a class="auto" href="?path=<?= urlencode($open_path) ?>&page=<?= $page ?>&rep=on&slidemode=<?= $slidemode ?>">Repeat Off</a>
	<?php } ?>
	<?php if ($slidemode == 'wallpaper') { ?>
	<a class="auto" href="?path=<?= urlencode($open_path) ?>&page=<?= $page ?>">Wallpaper <span style="color: #ffff40">On</span></a>
	<?php } else { ?>
	<a class="auto" href="?path=<?= urlencode($open_path) ?>&page=<?= $page ?>&slidemode=wallpaper">Wallpaper Off</a>
	<?php } ?>
	<span class="page"><?= $page ?> / <?= $_SESSION['photo_img_count'] ?></span>
</td>
</tr>
</table>
</div>
</body>
</html>
<?php
function get_target_path_info($open_path) {
	$path_SJIS = mb_convert_encoding($open_path, 'SJIS-win', 'UTF-8');
	if ($dir = opendir($path_SJIS)) {
		$subdir_count = 0;
		$img_count = 0;
		$files = scandir($path_SJIS);
		foreach ($files as $file) {
			if ($file != "." && $file != "..") {
				if (is_dir($path_SJIS . "/" . $file)) {
					$_SESSION['photo_subdir'][++$subdir_count]
						= mb_convert_encoding($file, 'UTF-8', 'SJIS-win');
				} elseif (is_img_filename($file)) {
					$_SESSION['photo_img'][++$img_count]
						= mb_convert_encoding($file, 'UTF-8', 'SJIS-win');
				} else {
					if (photo_VIDEO_FFMPEG == "YES") {
						if (is_video_filename($file)) {
							$_SESSION['photo_img'][++$img_count]
							= mb_convert_encoding($file, 'UTF-8', 'SJIS-win');
							$_SESSION['photo_img_type'][$img_count] = 'video';
						}
					}
				}
			}
		}
		closedir($dir);
	}
	$_SESSION['photo_subdir_count'] = $subdir_count;
	$_SESSION['photo_img_count'] = $img_count;
}
?>
