<?php 
	header('Content-Type: text/html; charset=UTF-8');
	require_once('./config.inc');
	
	$LogIO->logOutput(KLOG_INFO, 'GET情報をURLデコード');
	$get = decodeVariables($_GET);
	$LogIO->logOutput(KLOG_INFO, 'GET情報をEntityにエンコード');
	$get = encodeForEntities($get);
	
	$param = array(
		array(
			'name' => 'action',
			'value' => isset($get['action']) ? ($get['action']) : null,
			'check' => array(
				'type' => 'string',
				'max' => 50,
				//'required' => true,
			)
		),
		array(
			'name' => 'a_key',
			'value' => isset($get['a_key']) ? ($get['a_key']) : null,
			'check' => array(
				'type' => 'string',
				'max' => 50,
			)
		),
		array(
			'name' => 'account',
			'value' => isset($get['account']) ? ($get['account']) : null,
			'check' => array(
				'type' => 'string',
				'max' => 128,
			)
		),
		array(
			'name' => 'account_country',
			'value' => isset($get['account_country']) ? ($get['account_country']) : null,
			'check' => array(
				'type' => 'string',
				'max' => 2,
			)
		),
		array(
			'name' => 'source_url',
			'value' => isset($get['source_url']) ? ($get['source_url']) : null,
			'check' => array(
				'type' => 'string',
				'max' => 50,
				'regexp' => '/google/',
			)
		),
		array(
			'name' => 'hl',
			'value' => isset($get['hl']) ? ($get['hl']) : null,
			'check' => array(
				'type' => 'string',
				'max' => 2,
				//'required' => true,
			)
		),
		array(
			'name' => 'name',
			'value' => isset($get['name']) ? ($get['name']) : null,
			'check' => array(
				'type' => 'string',
				'max' => 128,
				//'required' => true,
			)
		),
		array(
			'name' => 'street',
			'value' => isset($get['street']) ? ($get['street']) : null,
			'check' => array(
				'type' => 'string',
				'max' => 128,
				//'required' => true,
			)
		),
		array(
			'name' => 'streetnum',
			'value' => isset($get['streetnum']) ? ($get['streetnum']) : null,
			'check' => array(
				'type' => 'string',
				'max' => 20,
			)
		),
		array(
			'name' => 'postalcode',
			'value' => isset($get['postalcode']) ? ($get['postalcode']) : null,
			'check' => array(
				'type' => 'string',
				'max' => 15,
			)
		),
		array(
			'name' => 'province',
			'value' => isset($get['province']) ? ($get['province']) : null,
			'check' => array(
				'type' => 'string',
				'max' => 128,
			)
		),
		array(
			'name' => 'city',
			'value' => isset($get['city']) ? ($get['city']) : null,
			'check' => array(
				'type' => 'string',
				'max' => 128,
				//'required' => true,
			)
		),
		array(
			'name' => 'country',
			'value' => isset($get['country']) ? ($get['country']) : null,
			'check' => array(
				'type' => 'string',
				'max' => 2,
				//'required' => true,
			)
		),
		array(
			'name' => 'phone',
			'value' => isset($get['phone']) ? ($get['phone']) : null,
			'check' => array(
				'type' => 'string',
				'max' => 20,
			)
		),
		array(
			'name' => 'notes',
			'value' => isset($get['notes']) ? ($get['notes']) : null,
			'check' => array(
				'type' => 'string',
				'max' => 70,
			)
		),
		array(
			'name' => 'attribution',
			'value' => isset($get['attribution']) ? $get['attribution'] : null,
			'check' => array(
				'type' => 'string',
				//'max' => 35,
				//'required' => true,
			)
		),
		array(
			'name' => 'lat',
			'value' => isset($get['lat']) ? (float)($get['lat']) : null,
			'check' => array(
				'type' => 'float',
			)
		),
		array(
			'name' => 'long',
			'value' => isset($get['long']) ? (float)($get['long']) : null,
			'check' => array(
				'type' => 'float',
			)
		),
		array(
			'name' => 'ts',
			'value' => isset($get['ts']) ? (int)($get['ts']) : null,
			'check' => array(
				'type' => 'integer',
			)
		),
		array(
			'name' => 'sig',
			'value' => isset($get['sig']) ? $get['sig'] : null,
			'check' => array(
				'type' => 'string',
				'max' => 25,
			)
		),
	);
	
	$validate = new Validater;
	$LogIO->logOutput(KLOG_INFO, 'GET情報のバリデート');
	$non_valid = $validate->check($param);
	
	$install_flag = false;
	if($non_valid['count'] == 0){
		if(isset($_COOKIE['feeds_installed']) && strtolower($_COOKIE['feeds_installed']) == 'true'){
		//	$install_flag = true;
		}
		$get_url = getParamToUrl($_GET);
		$return_url = (!empty($_SERVER['HTTP_REFERER'])) ? $_SERVER['HTTP_REFERER'] : $get['source_url'];
	}
	
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
	<title><?php echo $str_lang[0]; ?></title>
	<link rel="stylesheet" type="text/css" href="./css/common.css" />
	<script type="text/javascript" src="./js/common.js"></script>
<?php if($install_flag){ ?>
	<script type="text/javascript">
		//<![CDATA[
		//	window.onload = function(){ document.transfer_form.submit(); }
		//]]>
	</script>
<?php }else{ ?>
	<script type="text/javascript">
		//<![CDATA[
			window.onload = function(){ buttonInit_button_disable(); }
		//]]>
	</script>
<?php } ?>
</head>
<body>
<?php if(!$install_flag){ ?>
<?php include('portal.php'); ?>
<div id="contents">
	<div id="header">
		<div class="float_right none">
			<?php echo $str_lang[13]; ?>
			<select id="langSelect" onchange="changeLanguage('sendto.php<?php echo $get_url; ?><?php echo (empty($get_url) ? '?' : '&'); ?>display_language='+this.value, false)">
	<?php foreach($lang_select as $key => $value){ ?>
				<option value="<?php echo $key; ?>"<?php if($request_lang == $key) echo ' selected="selected"'?>><?php echo $value; ?></option>
	<?php } ?>
			</select>
		</div>
		<h1><?php echo $str_lang[1]; ?></h1>
	</div>
	<div id="body" class="contents">

	<?php if($non_valid['count'] > 0){ //アクセスが不正な場合 ?>
		<p>
			<?php echo $str_lang[2]; ?>
			<a href="<?php printExternalURL($request_lang, 'help'); ?>"><?php echo $str_lang[12]; ?></a>
		</p>
	<?php }else{ //valid ?>
	
		<div class="button_field float_left">
			<div class="button_disable" id="button1"/>
				<div class="textbox">
					<span id="writer1"><?php echo $str_lang[5]; ?></span>
				</div>
			</div>
			<div class="button" id="button2" onclick="location.href='<?php printExternalURL($request_lang, 'download'); ?>'" />
				<div class="textbox">
					<span id="writer2"><?php echo $str_lang[6]; ?></span>
				</div>
			</div>
		</div>
		<div>
			<p>
				<?php echo $str_lang[23]; ?>
			</p>
			<p><br><br>
			</p>
			<p>
				<?php echo $str_lang[3]; ?>
			</p>
			<p>
				<?php echo $str_lang[4]; ?>
			</p>
			<noscript>
				<p>
					<?php echo $str_lang[11]; ?>
				</p>
			</noscript>
		</div>
		<div class="clear"></div>
	</div>
	<div class="button_field float_right">
		<div class="button" id="button3" onclick="history.go(-1)" />
			<div class="textbox">
				<span id="writer3"><?php echo $str_lang[7]; ?></span>
			</div>
		</div>
	</div>
	<div class="clear"></div>
	<?php include('copyright.php'); ?>
</div>
	<?php } ?>
<?php } ?>
	<!--<form action="transfer.php" method="post" name="transfer_form">
		<input type="hidden" name="display_language" id="displayLanguage" value="<?php echo isset($get['display_language']) ? $get['display_language']:''; ?>" />
		<input type="hidden" name="return_url" value="<?php echo $return_url; ?>" />
		<input type="hidden" name="name" value="<?php echo isset($get['name']) ? $get['name']:''; ?>" />
		<input type="hidden" name="street" value="<?php echo isset($get['street']) ? $get['street']:''; ?>" />
		<input type="hidden" name="streetnum" value="<?php echo isset($get['streetnum']) ? $get['streetnum']:''; ?>" />
		<input type="hidden" name="postalcode" value="<?php echo isset($get['postalcode']) ? $get['postalcode']:''; ?>" />
		<input type="hidden" name="province" value="<?php echo isset($get['province']) ? $get['province']:''; ?>" />
		<input type="hidden" name="city" value="<?php echo isset($get['city']) ? $get['city']:''; ?>" />
		<input type="hidden" name="country" value="<?php echo isset($get['country']) ? $get['country']:''; ?>" />
		<input type="hidden" name="phone" value="<?php echo isset($get['phone']) ? encodeVariables($get['phone']):''; ?>" />
		<input type="hidden" name="lat" value="<?php echo isset($get['lat']) ? $get['lat']:''; ?>" />
		<input type="hidden" name="long" value="<?php echo isset($get['long']) ? $get['long']:''; ?>" />
		<input type="hidden" name="attribution" value="<?php echo isset($get['attribution']) ? $get['attribution']:''; ?>" />
		<input type="hidden" name="notes" value="<?php echo isset($get['notes']) ? $get['notes']:''; ?>" />
	</form>

-->


<?php
	if($debug){
?>
<hr style="clear:both" />
<textarea style="width:80%;height:5em;" ondblclick="try{alert(eval(this.value))}catch(e){alert(e);}"></textarea>
<?php
		print('<table>');
		print('<caption style="font-weight:bold">GET</caption>');
		if(!empty($_GET)){
			foreach($_GET as $key => $value){
				print('<tr>');
				print('<th>'.$key.'</th><td>'.$value.'</td>');
				print('</tr>');
			}
		}else{
			print('<tr><td>no data</td></tr>');
		}

		print('</table>');
		
		print('<hr />');
		print('<table>');
		print('<caption style="font-weight:bold">POST</caption>');
		if(!empty($_POST)){
			foreach($_POST as $key => $value){
				print('<tr>');
				print('<th>'.$key.'</th><td>'.$value.'</td>');
				print('</tr>');
			}
		}else{
			print('<tr><td>no data</td></tr>');
		}
		print('</table>');
		
		print('<hr />');
		if($non_valid['count'] > 0){
			print('<ol>');
			foreach($non_valid['errmsg'] as $value){
				print('<li>'.$value.'</li>');
			}
			print('</ol>');
		}
	}
?>
</body>
</html>