<?php
	require("__include-common.php");
	require("../account/__logincheck.php");
	require("_my_calendar.php");
	// mp_list_filter_key_select()を使うため
	require("../__common__/include-common-mp-list.php");

	if (isset($_GET['dt'])) {
		$_SESSION['schedule_detail'] = $_GET['dt'];
		setcookie('schedule_detail', $_SESSION['schedule_detail'], time() + LOGIN_COOKIE_EXPIRE, "/");
	} else {
		if (isset($_COOKIE['schedule_detail'])) {
			$_SESSION['schedule_detail'] = $_COOKIE['schedule_detail'];
		}
	}

	$arg_pool_prefix = "calendar_schedule";

	$http_arg = array();
	$http_arg['pl'] = PAGE_LINE_DEFAULT;		// mp_list 必須
	$http_arg['sort'] = '';				// mp_list 必須
	$http_arg['cat'] = '';				// mp_list 必須
	$http_arg['key'] = '';				// mp_list 必須

	$http_arg['y'] = '';
	$http_arg['m'] = '';
	$http_arg['d'] = '';
	$http_arg['key'] = '';

	_GET_to_http_arg_pool($http_arg, $arg_pool_prefix, 'y,m,d,key,pl');
	$keystring = keystr_fix($http_arg['key']);

	$year = $http_arg['y'];
	$month = $http_arg['m'];
	$day = $http_arg['d'];
	if ($year == '') {
		$year = date("Y");
	}
	if ($month == '') {
		$month = date("n");
	}
	if ($day == '') {
		$day = date("j");
	}

	html_header(HTML_TITLE);
	page_header();
	contents_header();

	$pw = mktime(0, 0, 0, $month, $day-7, $year);
	$nw = mktime(0, 0, 0, $month, $day+7, $year);

	$con = my_mysql_connect(_DB_SCHEMA);
?>
<div id="calendar_body">
<form method="POST" name="filter_form" action="<?= $_SERVER['SCRIPT_NAME'] ?>?<?= query_from_http_arg_pool($http_arg) ?>">
	<!--	<div id="calendar_category_select" class="block_left"> -->
	<?php
	//	filter_category_select($category, $_SESSION['current_id'], $http_arg);
	?>
	<!--	</div> -->
<div id="filter_key_select" class="block_left left_mini_margin">
<?php
	filter_key_select($keystring, $http_arg);
?>
</div>
<div id="filter_mode_change" class="block_left left_mini_margin">
<?php
	filter_detail_onoff();
?>
</div>
</form>
<div id="calendar_main">
	<table class='calendar_tbl_week'>
<?php
	$time = mktime(0, 0, 0, $month, $day, $year);
	$first_day = $day - date("w", $time);		// 先頭日  date("w",$time):曜日取得(0...6)
	$last_day = $first_day + 6;
	$first_time = mktime(0, 0, 0, $month, $first_day, $year);
	$last_time = mktime(0, 0, 0, $month, $last_day, $year);

//echo $year.$month.$day."<br>";
//echo $first_day."<br>";
//echo date('Y/n/j',$first_time)."---".date('Y/n/j',$last_time)."<br>";

	if (date('n',$first_time) == date('n',$last_time)) {
?>
	<caption><span class="calendar_caption_ym"><?= $year ?>年<?= $month ?>月</span>
		<span id="calendar_ymd_change">
		<ul>
		<li><a href="<?= $_SERVER['SCRIPT_NAME'] ?>?y=<?= date('Y') ?>&m=<?= date('n') ?>&d=<?= date('j') ?>&key=<?= urlencode($keystring) ?>">今週</a></li>
		<li><a href="<?= $_SERVER['SCRIPT_NAME'] ?>?y=<?= date('Y',$pw) ?>&m=<?= date('n',$pw) ?>&d=<?= date('j',$pw) ?>&key=<?= urlencode($keystring) ?>">←前週</a></li>
		<li><a href="<?= $_SERVER['SCRIPT_NAME'] ?>?y=<?= date('Y',$nw) ?>&m=<?= date('n',$nw) ?>&d=<?= date('j',$nw) ?>&key=<?= urlencode($keystring) ?>">→次週</a></li>
		</ul>
		</span>
		<br /><br style='font-size: 10px;' />
	</caption>
<?php
	} else {
?>
	<caption><span class="calendar_caption_ym"><?= date('Y',$first_time) ?>年<?= date('n',$first_time) ?>月 ～ <?= date('Y',$last_time) ?>年<?= date('n',$last_time) ?>月</span>
		<span id="calendar_ymd_change">
		<ul>
		<li><a href="<?= $_SERVER['SCRIPT_NAME'] ?>?y=<?= date('Y') ?>&m=<?= date('n') ?>&d=<?= date('j') ?>&key=<?= urlencode($keystring) ?>">今週</a></li>
		<li><a href="<?= $_SERVER['SCRIPT_NAME'] ?>?y=<?= date('Y',$pw) ?>&m=<?= date('n',$pw) ?>&d=<?= date('j',$pw) ?>&key=<?= urlencode($keystring) ?>">←前週</a></li>
		<li><a href="<?= $_SERVER['SCRIPT_NAME'] ?>?y=<?= date('Y',$nw) ?>&m=<?= date('n',$nw) ?>&d=<?= date('j',$nw) ?>&key=<?= urlencode($keystring) ?>">→次週</a></li>
		</ul>
		<br /><br style='font-size: 10px;' />
		</span>
	</caption>
<?php
	}
	calendar_week_header();
	for ($ix=0; $ix<=$_SESSION['login_friends_number']; $ix++) {
		$friends_id = $_SESSION['login_friends_id_'.$ix];
	//	calendar_week($year, $month, $day, $friends_id, $_SESSION['login_friends_handle_'.$ix], $keystring);
		calendar_week($year, $month, $day, $friends_id, $_SESSION['login_friends_handle_'.$friends_id], $keystring);
	}
?>
	</table>
</div>
</div>
<?
	page_footer();
	html_footer();
	exit();
?>
