<?php
// ****************************************************************
function html_header($title, $add_header_file='', $background_color='', $body_opt='', $add_meta='', $my_header='__html-my-header.php') {
// ****************************************************************
	ini_set("default_charset","UTF-8");
?>
<!DOCTYPE html>
<html lang="ja">
<head>
<?php if ($add_meta <> '') echo $add_meta."\n"; ?>
<?php
	require($my_header);
	if ($add_header_file <> "") {
		$array = file($add_header_file);
		$add_header = join("",$array);
		echo $add_header;
	}
	if (!defined("PAGE_BODY_STYLE")) {
		define("PAGE_BODY_STYLE", "");
	}
?>
<style type="text/css">
#page_navi a {
	color: <?= $_SESSION['page_navi_link_color'] ?>;
	background-color: <?= $_SESSION['page_navi_link_bg'] ?>;
}
#page_navi_current a {
	color: <?= $_SESSION['page_navi_current_color'] ?>;
	background-color: <?= $_SESSION['page_navi_current_bg'] ?>;
}
#page_navi a:hover {
	color: <?= $_SESSION['page_navi_hover_color'] ?>;
	background-color: <?= $_SESSION['page_navi_hover_bg'] ?>;
}
#page_navi a:active {
	color: <?= $_SESSION['page_navi_active_color'] ?>;
	background-color: <?= $_SESSION['page_navi_active_bg'] ?>;
}
</style>
<link rel="shortcut icon" href="<?= FAVICON_ICON ?>" type="image/ico">
<link rel="icon" href="<?= FAVICON_ICON ?>" type="image/ico">
<script language="javascript" src="../scripts/cookie.js" type="text/javascript"></script>
<title><?= $title ?></title>
</head>
<?php	if ($background_color <> '') { ?>
<body style="<?= PAGE_BODY_STYLE ?> background-color: <?= $background_color ?>;"<?= $body_opt ?>>
<?php	} elseif ($_SESSION['login_friends_body_background_color_'.$_SESSION['current_id']].'' <> '') { ?>
<body style="<?= PAGE_BODY_STYLE ?> background-color: <?= $_SESSION['login_friends_body_background_color_'.$_SESSION['current_id']] ?>;"<?= $body_opt ?>>
<?php	} else { ?>
<body style="<?= PAGE_BODY_STYLE ?>"<?= $body_opt ?>>
<?php	} ?>
<div id="page_body">
<?php
}
// ****************************************************************
function html_footer() {
// ****************************************************************
?>
</div><!-- id="page_body" -->
</body>
</html>
<?php
}
// ****************************************************************
function page_header($id_check = True) {
// ****************************************************************
	require(_DEFINE_CONTENTS_FILE);		// default: "__define_contents.php"
?>
<div id="page_header">
	<div id="page_navi">
	<ul>
<?php
	$pos = strrpos($_SERVER['SCRIPT_NAME'],'/');
	$url = substr(strtolower($_SERVER['SCRIPT_NAME']),0,$pos);
	$pos = strrpos($url,"/");
	$contents = substr($url,$pos+1).'/';
	$len = strlen($contents);
	$contents_check = False;
	foreach ($navi_item as $id=>$item) {
		if ($contents == strtolower(right($item['href'],$len))) {
			$contents_check = True;
?>
		<li id="page_navi_current"><a href="<?= _MYHOME_REF_PATH ?>/<?= $item['href'] ?>?<?= $item['query'] ?>"><?= $item['name'] ?></a></li>
<?php
		} else {
?>
		<li><a href="<?= _MYHOME_REF_PATH ?>/<?= $item['href'] ?>?<?= $item['query'] ?>"><?= $item['name'] ?></a></li>
<?php
		}
	}
?>
	</ul>
	</div>
	<div id="page_login_account">
<script type="text/javascript">
function accountMenuChange() {
	if (loadCookie("account_menu_view") == "none") {
		document.getElementById('accountmenu').style.display='inline';
		document.getElementById('arrow_left').style.display='none';
		document.getElementById('arrow_right').style.display='inline';
		saveCookie("account_menu_view", "inline", 365, "/");
	} else {
		document.getElementById('accountmenu').style.display='none';
		document.getElementById('arrow_left').style.display='inline';
		document.getElementById('arrow_right').style.display='none';
		saveCookie("account_menu_view", "none", 365, "/");
	}
}
</script>
	<?php
		if ($_COOKIE['account_menu_view'] == 'none') {
			$account_menu = 'none';
			$arrow_right = 'none';
			$arrow_left = 'inline';
		} else {
			$account_menu = 'inline';
			$arrow_right = 'inline';
			$arrow_left = 'none';
		}
	?>
	<span style="display:inline;float:left;"><a href="javascript:accountMenuChange()" style="background-color:transparent;"><img id="arrow_left" style="display:<?= $arrow_left ?>;margin:5px 5px 0 0;" src="../icon/arrow_left.png"><img id="arrow_right" style="display:<?= $arrow_right ?>;margin:5px 5px 0 0;" src="../icon/arrow_right.png"></a></span>
	<table id="accountmenu" style="float:left; display:<?= $account_menu ?>;"><tr>
		<td nowrap><a href="<?= _MYHOME_REF_PATH ?>/guide/?arg=session">利用ガイド</a></td>
<?php
	if ($_SESSION['logincheck'] == "OK") {
?>
		<td nowrap><a href="<?= _MYHOME_REF_PATH ?>/account/list-user.php">ユーザ一覧</a></td>
		<td nowrap><a href="<?= _MYHOME_REF_PATH ?>/account/myprofile.php">My設定</a></td>
	<?php if ($_SESSION['システム管理者'] == "YES") { ?>
		<td nowrap><a href="<?= _MYHOME_REF_PATH ?>/account/logout.php">ログアウト/管理</a></td>
	<?php } else { ?>
		<td nowrap><a href="<?= _MYHOME_REF_PATH ?>/account/logout.php">ログアウト</a></td>
	<?php } ?>
		<td nowrap id="login_account_handle"><?= $_SESSION['login_handle'] ?></td>
<?php
	} else {
		if (USER_SELF_NEW_ACCOUNT <> 'NO') {
?>
		<td nowrap><a href="<?= _MYHOME_REF_PATH ?>/account/newaccount.php">ユーザー登録</a></td>
<?php
		}
?>
		<td nowrap><a href="<?= _MYHOME_REF_PATH ?>/account/login.php">ログイン</a></td>
<?php
	}
?>
	</tr></table>
	</div>
</div><!-- id="page_header" -->
<div id="page_contents">
<?php
	if (!$contents_check) {
		if (strpos($_SERVER['SCRIPT_NAME'],'guide') === False and strpos($_SERVER['SCRIPT_NAME'],'account') === False) {
			error_msg ("このコンテンツは利用できません。");		// __define_contents.phpで定義されていない場合
			html_footer();
			exit();
		}
	}
	if ($id_check == True) {
		if ($_SESSION['login_id'] == "") {
			//error_msg("ログインしてください。");
			echo "<div><a href='../account/login.php'>ログイン</a><div>";
			html_footer();
			exit();
		}
	}
}
// ****************************************************************
function page_header_return_index() {
// ****************************************************************
?>
<a href="../tools/" class="return_index">■</a>
<?php
}
// ****************************************************************
function page_footer() {
// ****************************************************************
?>
</div><!-- id="page_contents" -->
<div id="page_footer">
<a href="http://ok2nd.web.fc2.com/" target="_blank" style="color:#8080ff; font-size: 12px;">Powered by ok.2nd</a>
</div><!-- id="page_footer" -->
<?php
}
// ****************************************************************
function contents_menu($menu_item) {
// ****************************************************************
?>
<div id="contents_navi">
	<ul>
<?php
	foreach ($menu_item as $id=>$item) {
		$pos = strrpos($_SERVER['SCRIPT_NAME'],"/")+1;
		$len = strlen($item['href']);
		if (substr(strtolower($_SERVER['SCRIPT_NAME']),$pos,$len) == $item['href']) {
?>
		<li id="contents_navi_current"><a href="<?= $item['href'] ?>?<?= $item['query'] ?>"><?= $item['name'] ?></a></li>
<?php
		} else {
?>
		<li><a href="<?= $item['href'] ?>?<?= $item['query'] ?>"<?php if ($item['target']<>'') echo ' target="'.$item['target'].'"' ?>><?= $item['name'] ?></a></li>
<?php
		}
?>
<?php
	}
?>
	</ul>
</div><!-- id="contents_navi" -->
<?php
}
// ****************************************************************
function change_account_menu() {
// ****************************************************************
	if ($_SESSION['login_friends_number'] >= _ACCOUNT_CHANGE_USER_NUM) {
?>
	<script language="JavaScript">
	function SelectionAccount(form, sel) {
		for (i = 0; i < sel.options.length; i++) {
			if (sel.options[i].selected == true) {
				window.location.href = "<?= _MYHOME_REF_PATH ?>/account/change-account.php?uid=" + escape(sel.options[i].value) + "&ret=<?= $_SERVER['SCRIPT_NAME'] ?>";
			}
		}
	}
	</script>
<div id="contents_change_account_select">
	<input type="checkbox" name="cb_ac" id="cb_ac" value="一括" onClick="CheckboxAccountChgSw()"<?= $_COOKIE['account_chg_all'] == 'all' ? ' checked' : '' ?>><label for="cb_ac">一括</label>&nbsp;&nbsp;
	<select name="Account" onChange="SelectionAccount(this.form, this)">
<?php
		for ($ix=0; $ix<=$_SESSION['login_friends_number']; $ix++) {
			$friends_id = $_SESSION['login_friends_id_'.$ix];
?>
		<option value="<?= $friends_id ?>"<?= $friends_id == $_SESSION['current_id'] ? ' selected' : '' ?>><?= $_SESSION['login_friends_handle_'.$friends_id] ?>
<?php
		}
?>
	</select>
</div><!-- id="contents_change_account_select" -->
<?php
	} else {
?>
<div id="contents_change_account">
	<table><tr><td style="vertical-align: top;">
	<input type="checkbox" name="cb_ac" id="cb_ac" value="一括" style="width: 14px; height: 14px;"
		onClick="CheckboxAccountChgSw()"<?= $_COOKIE['account_chg_all'] == 'all' ? ' checked' : '' ?>>
	</td><td style="vertical-align: top;"><ul><label for="cb_ac">一括</label>&nbsp;&nbsp;
<?php
		for ($ix=0; $ix<=$_SESSION['login_friends_number']; $ix++) {
			$friends_id = $_SESSION['login_friends_id_'.$ix];
			if ($friends_id == $_SESSION['current_id']) {
?><li id="contents_change_account_current"><?= $_SESSION['login_friends_handle_'.$friends_id] ?></li><?php
			} else {
?><li><a href='../account/change-account.php?uid=<?= $friends_id ?>&ret=<?= $_SERVER['SCRIPT_NAME'] ?>'><?= $_SESSION['login_friends_handle_'.$friends_id] ?></a></li><?php
			}
		}
?></ul>
	</td></tr></table>
</div><!-- id="contents_change_account" -->
<?php
	}
?>
<script language="JavaScript">
function CheckboxAccountChgSw() {
	if (loadCookie("account_chg_all") == "all") {
		saveCookie("account_chg_all", "each", 365, "/");
	} else {
		saveCookie("account_chg_all", "all", 365, "/");
	}
}
</script>
<?php
}
// ****************************************************************
function attach_file_view($user_id, $filename, $add_str="", $img_width=50, $img_view=True, $name_view=True,
		$video_view=False, $video_width=100, $video_height=75, $folder='') {
// ****************************************************************
	if ($filename <> "") {
		if ($folder == '') {
			$folder = ATTACH_FILE_FOLDER;
		}
		if ($user_id <> '') {
			$filepath = $folder.$user_id.'/'.$filename;
		} else {
			$filepath = $folder.$filename;
		}
		if (VIDEO_PREVIEW == 'YES' && $video_view && is_preview_video_filename($filename)) {
			if (photo_VIDEO_FFMPEG == "YES") {
				$video_jpeg = '../photo/video-jpeg.php?file='.urlencode(realpath($filepath));
			} else {
				$video_jpeg = '';
			}
			if (is_ext_filename_str($filename, VIDEO_PREVIEW_WMV)) {
?>
		<div id="<?= $filename ?>">the player will be placed here</div>
		<script type="text/javascript">
			wmv_preview_no_auto("<?= $filename ?>", "<?= $filepath ?>", "<?= $video_width ?>", "<?= $video_height ?>");
		</script>
<?php
			} else {
				$flv_view = '../__common__/flv-view.php?file=' . $filepath;	// 日本語名ファイル対策
?>
		<div id="<?= $filename ?>">the player will be placed here</div>
		<script type="text/javascript">
			movie_preview_no_auto("<?= $filename ?>", "<?= $flv_view ?>", "<?= $video_width ?>", "<?= $video_height ?>");
		</script>
<?php
			}
		} elseif ($img_view && is_img_filename($filename)) {
			list($width, $height) = getimagesize(myfile_ENCODE(realpath($filepath)));
			if ($width >= $height) {
				$width_height = 'width';
			} else {
				$width_height = 'height';
			}
?>
		<a href="<?= $filepath ?>" target="_blank"><img src="<?= $filepath ?>" class="bicubic" border=0 <?= $width_height ?>=<?= $img_width ?> /></a>
<?php
		} else {
			if ($name_view) {
				$view = mb_substr($filename,9);
			} else {
				$view = '<img src="../images/paste.png" border=0 />';
			}
?>
		<a class="std" href="<?= $filepath ?>" target="_blank"><?= $view ?></a>
<?php
		}
		echo $add_str;
	}
?>
<?php
	return(0);
}
// ****************************************************************
function is_preview_video_filename($str) {
// ****************************************************************
	static $video_ext = NULL;
	if ($video_ext == NULL) {
		if (VIDEO_PREVIEW_EXT.'' <> '') {
			$video_ext = explode(',', VIDEO_PREVIEW_EXT);
		}
	}
	if ($video_ext != NULL) {
		return is_ext_filename($str, $video_ext);
	} else {
		return false;
	}
}
// ****************************************************************
function images_print_table($dir_path, $column, $file_table, $file_count) {
// ****************************************************************
?>
<table>
<tr><td>
	<table>
<?php
	if ($file_count > $column) {
		$num_in_coloumn = ceil($file_count / $column);	// 切り上げ整数化
	} else {
		$num_in_coloumn = $file_count;
	}
	$cnt = 0;
	foreach ($file_table as $file) {
		$filePath = $dir_path . "/" . $file;
		$cnt++;
		if ($cnt > $num_in_coloumn) {
?>
	</table>
</td>
<td>
	<table>
<?php
			$cnt = 1;
		}
?>
		<tr><td><img src="<?= $filePath ?>"></td><td nowrap><?= $file ?></td></tr>
<?php
	}
?>
	</table>
</td></tr>
</table>
<?php
}
?>
