<?php
	define('PATH', './');
	require(PATH.'lib/conf.php');

	$INDEX = fopen(LOGDIR.'toroku.idx', 'r');
	$allno = fgets($INDEX, 4096);
	while(!feof($INDEX)) {
		list($no, $flag, $user, $date, $edate, $item_name) = split('<>', fgets($INDEX, 4096));
		if (!$no || $flag != '0') { continue; }
		if ($date > date("Y/m/d H:i")) { continue; }
		if ($edate && $edate <= date("Y/m/d")) { continue; }
		if ($user != $FORM['c']) { continue; }
		$LOG[] = array(
			'no'		=> $no,
			'flag'		=> $flag,
			'user'		=> $user,
			'date'		=> $date,
			'edate'		=> $edate,
			'item_name'	=> $item_name
		);
	}
	multisort($LOG, 'date', SORT_DESC);

	//ページング
	$pager_param = array(
		'itemData'		=> $LOG,
		'perPage'		=> PAGEDISPNUM,
		'delta'			=> 5,
		'mode'			=> 'Sliding',
		'separator'		=> '|',
		'prevImg'		=> '&lt;&lt;戻る',
		'nextImg'		=> '次へ&gt;&gt;',
		'firstPageText'	=> '先頭',
		'lastPageText'	=> '最後'
	);
	$pager =& Pager::factory($pager_param);
	$navigation = $pager -> getLinks();
	$LOG = $pager->getPageData();
?>
<?php header('Content-Type: text/html;charset='.mb_internal_encoding());?>
<?php require(PATH.'lib/header.php') ?>
<?php
	if (isset($LOG)) {
		foreach ($LOG as $key => $array) {
			// $XML = XML_unserialize(file_get_contents(LOGDIR."{$array['no']}.xml"));

			$array = json_decode(json_encode(simplexml_load_string(mb_convert_encoding(file_get_contents(LOGDIR."{$array['no']}.xml"), 'UTF8', 'EUC-JP'))), true);
			mb_convert_variables('EUC-JP', 'UTF-8', $array);
			$XML['toroku'] = $array;

			//日付分割
			list($date, $time) = split(' ', $XML['toroku']['date']);
			list($year, $month, $day) = split('/', $date);
			// $year = '平成'.substr($year+12, -2);
			$date = $year.'年'.sprintf("%d", $month).'月'.sprintf("%d", $day).'日';
			$time = ereg_replace('([0-9]{2}):([0-9]{2})', '\\1時\\2分', $time);
?>
	<table border="0" cellspacing="0" cellpadding="0" class="toroku">
		<tr>
			<td><?php echo $XML['toroku']['org_name']; ?></td>
			<td><?php echo $date; ?>&nbsp;<?php echo $time; ?></td>
			<td><?php echo $XML['toroku']['item_name']; ?></td>
		</tr>
		<tr>
			<td colspan="3"><?php echo $XML['toroku']['outline']; ?></td>
		</tr>
	</table>
	<br>
<?php
		}
	}
?>
	<div align="center">
		<a href="index.php">戻る</a>
	</div>
<?php require(PATH.'lib/footer.php') ?>
