<?php
	require("../../_myhome/__common__/__define_common.php");
	require("../__common__/__define_mobile.php");
	require("__define.php");

	require("../lib/hawhaw.inc");

	require("../../_myhome/__common__/include-common-all.php");
	require("../../_myhome/calendar/_my_calendar.php");
	require("../__common__/include-common-mobile.php");

	$myPage = mobile_init('Calendar');

	_GET_ymd($year, $month, $day);

	$login_id = mobile_login_check($myPage);

	$con = mobile_mysql_connect($myPage, _DB_SCHEMA);

	mobile_ymd_print($myPage, $year, $month, $day);

	page_menu($myPage, $year, $month, $day);
	mobile_schedule_print($myPage, $year, $month, $day, $login_id, $login_id);
	page_menu($myPage, $year, $month, $day);

	mobile_page_view($myPage);
	exit;

function _GET_ymd(&$year, &$month, &$day) {
	if ($_GET['y'].'' <> '') {
		$year = $_GET['y'];
	} else {
		$year = date('Y');
	}
	if ($_GET['m'].'' <> '') {
		$month = $_GET['m'];
	} else {
		$month = date('n');
	}
	if ($_GET['d'].'' <> '') {
		$day = $_GET['d'];
	} else {
		$day = date('j');
	}
}
function mobile_ymd_print($myPage, $year, $month, $day) {
	mobile_add_text($myPage, $year.'年'.$month.'月'.$day.'日('.ymd_week($year, $month, $day).')');
	$holiday = holiday_check($year, $month, $day);
	if ($holiday) {
		mobile_add_text($myPage, $holiday, '', '#ff0000');
	}
}
function page_menu($myPage, $year, $month, $day) {
	move_ymd($myPage, '翌日', $year, $month, $day+1, 0);
	move_ymd($myPage, '前日', $year, $month, $day-1, 0);
	move_ymd($myPage, '今日', date('Y'), date('n'), date('j'), 0);
	mobile_add_link($myPage, 'トップ', '../');
}
function move_ymd($myPage, $name, $year, $month, $day, $br) {
	ymd_reset($year, $month, $day);
	mobile_add_link($myPage, $name, '?y='.$year.'&m='.$month.'&d='.$day, $br);
}
function mobile_schedule_print($myPage, $year, $month, $day, $login_id, $current_id) {
	$datestr = date('Y-m-d', mktime(0, 0, 0, $month, $day, $year));
	$sql = "select * from v_schedule where c_date = '".$datestr."' and c_delete = 0";
	if ($current_id != $login_id) {
		$sql .= " and c_privacy = 0";
	}
	$sql .= " and id_account = '".$current_id."'";
	$sql .= " order by c_time1";
	$rs = my_mysql_query($sql);
	while ($rec = mysql_fetch_array($rs)) {
		if ($rec['c_time1']."" <> "" || $rec['c_time2']."" <> "") {
			mobile_add_text($myPage, sch_time_format($rec['c_time1'], $rec['c_time2'], True), '', 'red', 0);
		}
		if ($rec['c_iconImage'] <> '') {
			mobile_add_image($myPage, $rec['c_iconImage']);
		}
		mobile_add_text($myPage, $rec['c_subject'], 'bold', $rec['c_categoryDisplayColor']);
		mobile_add_memo($myPage, $rec['c_memo']);
	}
}
?>
