<?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 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"; ?>
<?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", "");
	}
?>
<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">
	<table><tr>
		<td nowrap><a href="<?= _MYHOME_REF_PATH ?>/guide/?arg=session">利用ガイド</a></li>
<?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" -->
<?
}
// ****************************************************************
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;"><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" src="../scripts/cookie.js" type="text/javascript"></script>
<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) {
// ****************************************************************
	if ($filename <> "") {
		if ($user_id <> '') {
			$filepath = ATTACH_FILE_FOLDER.$user_id.'/'.$filename;
		} else {
			$filepath = ATTACH_FILE_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 (rightlower($filename,4) == '.wmv') {
?>
		<div id="<?= $filename ?>">the player will be placed here</div>
		<script type="text/javascript">
			var elm = document.getElementById("<?= $filename ?>");
			var src = 'wmvplayer.xaml';
			var cfg = {
				file:'<?= $filepath ?>',
				width:'<?= $video_width ?>',
				height:'<?= $video_height ?>'
			};
			var ply = new jeroenwijering.Player(elm,src,cfg);
		</script>
<?php
			} else {
?>
		<div id="<?= $filename ?>">The player will show in this paragraph</div>
		<script type="text/javascript">
			movie_preview("<?= $filename ?>", "<?= $filepath ?>", "<?= $video_width ?>", "<?= $video_height ?>", "<?= $video_jpeg ?>");
		</script>
<?php
			}
		} elseif ($img_view && is_img_filename($filename)) {
?>
		<a href="<?= $filepath ?>" target="_blank"><img src="<?= $filepath ?>" class="bicubic" border=0 width=<?= $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
}
?>
