<?php
	require("__include-common.php");
	require("../account/__logincheck.php");
	require("_my_calendar.php");

	_account_change($_GET['uid']);

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

	$arg_pool_prefix = "calendar_schedule";

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

	_GET_to_http_arg_pool($http_arg, $arg_pool_prefix, 'y,m,key');

	$category = $http_arg['cat'];
	$keystring = $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) ?>">
<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_mode_change(True);	// 詳細表示有
?>
</div>
</form>
<!--
<div id="calendar_ymd_change">
<ul>
<li><a href="<?= $_SERVER['SCRIPT_NAME'] ?>?y=<?= date('Y') ?>&m=<?= date('n') ?>&cat=<?= $category ?>&key=<?= urlencode($keystring) ?>">今月</a></li>
<li><a href="<?= $_SERVER['SCRIPT_NAME'] ?>?y=<?= $prev_year_y ?>&m=<?= $prev_year_m ?>&cat=<?= $category ?>&key=<?= urlencode($keystring) ?>">&lt;&lt;前年</a></li>
<li><a href="<?= $_SERVER['SCRIPT_NAME'] ?>?y=<?= $prev_month_y ?>&m=<?= $prev_month_m ?>&cat=<?= $category ?>&key=<?= urlencode($keystring) ?>">←前月</a></li>
<li><a href="<?= $_SERVER['SCRIPT_NAME'] ?>?y=<?= $next_month_y ?>&m=<?= $next_month_m ?>&cat=<?= $category ?>&key=<?= urlencode($keystring) ?>">→次月</a></li>
<li><a href="<?= $_SERVER['SCRIPT_NAME'] ?>?y=<?= $next_year_y ?>&m=<?= $next_year_m ?>&cat=<?= $category ?>&key=<?= urlencode($keystring) ?>">&gt;&gt;次年</a></li>
</ul>
</div>
-->
<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;
}
?>
