<?php
	define('PRIVATE_DIR_1', str_replace('/', '', photo_RESIZE_DIR_SMALL));
	define('PRIVATE_DIR_2', str_replace('/', '', photo_RESIZE_DIR_THUMB));
	define('PRIVATE_DIR_3', str_replace('/', '', photo_DELETE_TRASH_DIR));
	define('PRIVATE_DIR_4', str_replace('/', '', VIDEO_PREVIEW_CONVERT_FLV_DIR));
/*
	get: dir
		path: ディレクトリ・パス
		fim: フォルダ画像表示  ('on', 'off')
	get: header,file
		path: ディレクトリ・パス
		mode: t=サムネイル, b=サムネイル(B), s=スライド
		page: ページ
		pagemax: 頁枚数(頁内に表示する画像数)	IMAGE_MAX_SELECT
		flv: FLV/WMV動画再生 ('on', 'off')
		vss: 動画開始秒
		vst: 動画時間分割
		vsn: 動画時間分割分割数		VIDEO_TIMELINE_THUMB_NUM_SELECT
*/
	if (isset($_POST["path"]) && $_POST["path"] <> '') {
		$open_path = form_str_filepath($_POST["path"]);
	} elseif ($_GET['path'] <> '') {
		$open_path = my_GET('path');
	}
	$open_path = str_replace(DIRECTORY_SEPARATOR, '/', 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+1) <> photo_LIMITED_IMAGES_FOLDER.'/') {
				$open_path = photo_LIMITED_IMAGES_FOLDER;
				$_SESSION['photo_error'] = 'permission_error';
			} else {
				$_SESSION['photo_error'] = '';
			}
		}
	}
	$open_path = right_slash_strip($open_path);
	if ($_GET['imgmax'].'' <> '') {
		$_SESSION['photo_imgmax'] = $_GET['imgmax'];
		setcookie('photo_imgmax', $_SESSION['photo_imgmax'], time() + LOGIN_COOKIE_EXPIRE, '/');
	} else {
		if (isset($_COOKIE['photo_imgmax'])) {
			$_SESSION['photo_imgmax'] = $_COOKIE['photo_imgmax'];
		}
	}
	if ($_SESSION['photo_imgmax'].'' == '') {
		$_SESSION['photo_imgmax'] = IMAGE_MAX_DEFAULT;
	}
	if ($_GET['mode'].'' <> '') {
		if ($_SESSION['photo_view_mode'] == 's' && $_GET['mode'] != 's') {
			$_SESSION['photo_page'] = 1;
		}
		if ($_SESSION['photo_view_mode'] != 's' && $_GET['mode'] == 's') {
			$_SESSION['photo_page'] = 1;
		}
		$_SESSION['photo_view_mode'] = $_GET['mode'];
		setcookie('photo_view_mode', $_SESSION['photo_view_mode'], time() + LOGIN_COOKIE_EXPIRE, '/');
	} else {
		if (isset($_COOKIE['photo_view_mode'])) {
			$_SESSION['photo_view_mode'] = $_COOKIE['photo_view_mode'];
		}
	}
	if ($_GET['loupe'].'' <> '') {
		$_SESSION['photo_view_loupe'] = $_GET['loupe'];
		setcookie('photo_view_loupe', $_SESSION['photo_view_loupe'], time() + LOGIN_COOKIE_EXPIRE, '/');
	} else {
		if (isset($_COOKIE['photo_view_loupe'])) {
			$_SESSION['photo_view_loupe'] = $_COOKIE['photo_view_loupe'];
		}
	}
	if ($_SESSION['photo_view_mode'] == '') {
		$_SESSION['photo_view_mode'] = 't';
	}
	if ($_GET['page'].'' <> '') {
		$page = intval($_GET['page']);
		if ($page < 1) {
			$page = 1;
		}
	} elseif ($_SESSION['photo_page'].'' <> '') {
		$page = $_SESSION['photo_page'];
	} else {
		$page = 1;
	}
	$_SESSION['photo_page'] = $page;
	if ($_GET['flv'].'' <> '') {
		$_SESSION['slide_flv_preview'] = $_GET['flv'];
		setcookie('slide_flv_preview', $_SESSION['slide_flv_preview'], time() + LOGIN_COOKIE_EXPIRE, '/');
		$_SESSION['video_timeline_thumb'] = '';
	} else {
		if (isset($_COOKIE['slide_flv_preview'])) {
			$_SESSION['slide_flv_preview'] = $_COOKIE['slide_flv_preview'];
		}
	}
	if ($_GET['fim'].'' <> '') {
		$_SESSION['photo_folder_img1'] = $_GET['fim'];
		setcookie('photo_folder_img1', $_SESSION['photo_folder_img1'], time() + LOGIN_COOKIE_EXPIRE, '/');
	} else {
		if (isset($_COOKIE['photo_folder_img1'])) {
			$_SESSION['photo_folder_img1'] = $_COOKIE['photo_folder_img1'];
		}
	}
	if ($_COOKIE['slide_main_size'].'' <> '') {
		$_SESSION['slide_main_size'] = intval($_COOKIE['slide_main_size']);
	} elseif ($_SESSION['slide_main_size'].'' == '') {
		$_SESSION['slide_main_size'] = SLIDE_MAIN_SIZE;
	}
	if ($_COOKIE['photo_thumbs_size'].'' <> '') {
		$_SESSION['photo_thumbs_size'] = $_COOKIE['photo_thumbs_size'];
	} elseif ($_SESSION['photo_thumbs_size'].'' == '') {
		$_SESSION['photo_thumbs_size'] = SMALL_SIZE;
	}
	if ($_GET['it'].'' <> '') {
		$_SESSION['slide_interval_time'] = $_GET['it'];
	} elseif (isset($_COOKIE['slide_interval_time'])) {
		$_SESSION['slide_interval_time'] = $_COOKIE['slide_interval_time'];
	}
	if (empty($_SESSION['slide_interval_time'])) {
		$_SESSION['slide_interval_time'] = SLIDE_INTERVAL_TIME;
	}
	setcookie('slide_interval_time', $_SESSION['slide_interval_time'], time() + LOGIN_COOKIE_EXPIRE);
	if ($_GET['vst'].'' <> '') {
		$_SESSION['video_timeline_thumb'] = $_GET['vst'];
		$_SESSION['slide_flv_preview'] = '';
		setcookie('slide_flv_preview', '', time() + LOGIN_COOKIE_EXPIRE, '/');
	}
	if ($_GET['vsn'].'' <> '') {
		$_SESSION['video_timeline_thumb_num'] = $_GET['vsn'];
	} elseif ($_SESSION['video_timeline_thumb_num'].'' == '') {
		if ($_COOKIE['video_timeline_thumb_num'].'' <> '') {
			$_SESSION['video_timeline_thumb_num'] = $_COOKIE['video_timeline_thumb_num'];
		} else {
			$_SESSION['video_timeline_thumb_num'] = VIDEO_TIMELINE_THUMB_NUM;
		}
	}
	if ($_COOKIE['video_timeline_thumb_size'].'' <> '') {
		$_SESSION['video_timeline_thumb_size'] = $_COOKIE['video_timeline_thumb_size'];
	} elseif ($_SESSION['video_timeline_thumb_size'].'' == '') {
		$_SESSION['video_timeline_thumb_size'] = VIDEO_TIMELINE_THUMB_SIZE;
	}
	if ($_SESSION['photo_open_path'] <> $open_path) {
		$_SESSION['photo_open_path'] = $open_path;
		$_SESSION['photo_img_count'] = 0;
		unset($_SESSION['photo']);
		unset($_SESSION['photo_subdir']);
		unset($_SESSION['photo_subdir_img1']);
		unset($_SESSION['up_folder_subdir']);
		$_SESSION['photo_page'] = 1;
		$get_target_path_info = true;
	}
	$_SESSION['photo_view_sort_old'] = $_SESSION['photo_view_sort'].'';			// for ajax-photo-view.php
	$_SESSION['photo_view_sort_order_old'] = $_SESSION['photo_view_sort_order'].'';	// for ajax-photo-view.php
	if ($_GET['sort'].'' <> '') {
		if ($_GET['sort'] == $_SESSION['photo_view_sort']) {
			if ($_SESSION['photo_view_sort_order'].'' == 'desc') {
				$_SESSION['photo_view_sort_order'] = 'asc';
			} else {
				$_SESSION['photo_view_sort_order'] = 'desc';
			}
		} else {
			$_SESSION['photo_view_sort'] = $_GET['sort'];
			$_SESSION['photo_view_sort_order'] = 'asc';
		}
		setcookie('photo_view_sort', $_SESSION['photo_view_sort'], time() + LOGIN_COOKIE_EXPIRE, '/');
	} else {
		if (isset($_COOKIE['photo_view_sort'])) {
			$_SESSION['photo_view_sort'] = $_COOKIE['photo_view_sort'];
		} else if (empty($_SESSION['photo_view_sort'])) {
			$_SESSION['photo_view_sort'] = 'name';
		}
	}
?>
