<?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");

	_account_change($_GET['uid']);

	if (CALENDAR_DIARY_MODE == 'diary') {
		$_SESSION['diary_back_view'] = $_SERVER['SCRIPT_NAME'].'?'.$_SERVER['QUERY_STRING'];
		$_SESSION['diary_back_view_name'] = '月間カレンダーに戻る';
	}
	if (isset($_GET['mode'])) {
		$_SESSION['calendar_mode'] = $_GET['mode'];
	}
	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'];
		}
	}
	if ($_GET['wh'] <> '') {
		$_SESSION['calendar_weather_mode'] = $_GET['wh'];
	}
	if ($_GET['tm'] <> '') {
		$_SESSION['calendar_temp_mode'] = $_GET['tm'];
		$_SESSION['calendar_weather_mode'] = 'tmp';
	} elseif ($_SESSION['calendar_temp_mode'] == '') {
		$_SESSION['calendar_temp_mode'] = 'Ave';
	}
	if (isset($_GET['ken'])) {
		$_SESSION['calendar_ken'] = $_GET['ken'];
	} elseif ($_SESSION['calendar_ken'] == '') {
		$_SESSION['calendar_ken'] = DEFAULT_TODOFUKEN_ID;
	}
	$arg_pool_prefix = "calendar_schedule";

	$http_arg = array();
	$http_arg['y'] = '';
	$http_arg['m'] = '';
	$http_arg['d'] = '';

	$http_arg['pl'] = PAGE_LINE_DEFAULT;
	$http_arg['cat'] = '';
	$http_arg['key'] = '';
	$http_arg['sort'] = '';

	$http_arg['selY'] = '';
	$http_arg['selM'] = '';
	$http_arg['selD'] = '';
	$http_arg['toY'] = '';
	$http_arg['toM'] = '';
	$http_arg['toD'] = '';

	_GET_to_http_arg_pool($http_arg, $arg_pool_prefix, 'selY,selM,selD,toY,toM,toD,y,m,key,sort,pl');
	$category = $http_arg['cat'];
	$keystring = keystr_fix($http_arg['key']);

	$year = $http_arg['y'];
	$month = $http_arg['m'];
	if ($year == '') {
		$year = date("Y");
	}
	if ($month == '') {
		$month = date("n");
	}
	html_header(HTML_TITLE);
	page_header();
	contents_header();

	$prev_year_m = $month;
	$prev_year_y = $year - 1;
	$next_year_m = $month;
	$next_year_y = $year + 1;
	if ($month == 1) {
		$prev_month_m = 12;
		$prev_month_y = $year - 1;
		$next_month_m = $month + 1;
		$next_month_y = $year;
	} elseif ($month == 12) {
		$prev_month_m = $month - 1;
		$prev_month_y = $year;
		$next_month_m = 1;
		$next_month_y = $year + 1;
	} else {
		$prev_month_m = $month - 1;
		$prev_month_y = $year;
		$next_month_m = $month + 1;
		$next_month_y = $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) ?>">
<table><tr><td nowrap>
<span id="calendar_category_select" class="block_left_xxx">
<?php
	filter_category_select($category, $_SESSION['current_id'], $http_arg);
?>
</span>
<span id="filter_key_select" class="block_left_xxx left_mini_margin">
<?php
	filter_key_select($keystring, $http_arg);
?>
</span>
<span id="filter_mode_change" class="block_left_xxx left_mini_margin">
<?php
	filter_mode_change(True);	// 詳細表示有
?>
</span>
</td></tr></table>
</form>
<div id="calendar_main">
<table>
<tr><td>
<?php
	calendar_month($year, $month, $_SESSION['current_id'], $category, $keystring);
?>
</td><td>
<?php
	if (TODO_VIEW_USE == 'YES') {
		todo_body();
	}
?>
	<div id="calendar_3_month">
	<table class="year_calendar_frame">
	<?php
		if ($month == 1) {
			$year = $year - 1;
			$month = 12;
		} else {
			$month = $month - 1;
		}
		for ($ix=1; $ix<=3; $ix++) {
	?>
			<tr><td class="year_calendar_frame_month">
	<?php
			calendar_month($year, $month, $_SESSION['current_id'], $category, $keystring, "calendar_tbl_mini");
			if ($month == 12) {
				$year++;
				$month = 1;
			} else {
				$month++;
			}
	?>
			</td></tr>
	<?php
		}
	?>
	</table>
	</div>
</td></tr>
</table>
</div>
<?
	page_footer();
	html_footer();
	exit();
?>
<?php
function todo_body() {
	$sql = 'select * from m_todo where id_account = ' . $_SESSION['current_id'];
	$sql .= ' and c_delete = 0 order by c_priority desc, id_todo asc';
	$rs = my_mysql_query($sql);
	$rowcnt = mysql_num_rows($rs);
?>
	<div id="calendar_todo_box">
	<script language="javascript" src="../scripts/jquery.js" type="text/javascript"></script>
	<script type="text/javascript">;
	$(function(){
		todo_view()
	});
	function todo_view(){
		var d = new Date();	// キャッシュを利用されないため
		$("#todo_list").load("../todo/read-min.php?time="+d.getTime().toString());
	}
	function todo_view_all(){	// ToDo追加子ウインドウからの戻り用。
		todo_view();
	}
	function popup_todo() {
		w01 = window.open("../todo/index.php","","toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=440,height=500");
	}
	</script>
	<table id="calendar_todo_table" style="border-color: <?= TODO_VIEW_FRAME_COLOR ?>; background-color: <?= TODO_VIEW_FRAME_COLOR ?>;">
	<tr><th id="calendar_todo_title">
	<a href="javascript:popup_todo()">ToDo</a>
	</th></tr>
	<tr><td id="calendar_todo_data" style="border-color: <?= TODO_VIEW_FRAME_COLOR ?>;">
		<div id="todo_list"></div>
	</td></tr>
	</table>
	</div>
<?php
	return;
}
?>
