<?php

//-----------------------------------------------------
// 1 環境設定
//-----------------------------------------------------
// 座標解析エラーが発生しました。
if (file_exists("/var/www/html/jsoncheck/PRODUCTION.txt")) {
    $home_url = "http://jsoncheck.work";
} else {
    $home_url = "http://localhost/jsoncheck/index.php";
    $base_dir = "C:\\xampp\\htdocs\\jsoncheck\\";
}
$access_history_api3_file = $base_dir . "./display_log/access_history_api3_" . date("Ym") . ".log";
$access_history_api2_file = $base_dir . "./display_log/access_history_api2_" . date("Ym") . ".log";
// 座標解析エラーが発生しました。
$log_file            = "./log/log_file_" . date( "Ym" ) . ".log" ;

define("ACCESS_HISTORY_DISPLAY_ROW_COUNT", "15"); // 過去のりれぎとして表示する行数





$date = "" ;
$date = $_GET['date'] ; // 日指定の場合
if( $date  != '' ){
	$access_history_file = "./access_log/access_history_" . date("Ym")   . ".log" ;
} else {
	$access_history_file = "./access_log/access_history_" . date("Ym")  . ".log" ;
}

if ( file_exists( $log_file ) == false ) {
	touch( $log_file );
	chmod( $log_file , 0666 );
} 
if ( file_exists( $access_history_file ) == false ) {
	touch( $access_history_file );
	chmod( $access_history_file , 0666 );
} 

//define( "DEBUG_FLAG" , "1") ; // 1:debugありテスト用 0:debugなし本番用
define( "DEBUG_FLAG" , "0") ; // 1:debugありテスト用 0:debugなし本番用
define( "ACCESE_HISTORY_DISPLAY_ROW_COUNT" , "50") ; // 過去のりれぎとして表示する行数
// 変数その他
$access_history_api3_contents = ""; // 画面出力するアクセスヒストリファイルの内容（指定した行数only格納）
$access_history_api2_contents = ""; // 画面出力するアクセスヒストリファイルの内容（指定した行数only格納）

$title         = "" ;
$message       = "" ;           // 画面出力用
$access_history_contents = "" ; // 画面出力するアクセスヒストリファイルの内容（指定した行数only格納）
$access_history_line     = "" ; // 画面出力するアクセスヒストリファイルの内容
$jigyosyo_text = "" ;           // ログ出力用 jigyosyoテーブルにデータある場合にデータ格納する
$ken_all_text  = "" ;           // ログ出力用 ken_allテーブルにデータある場合にデータ格納する
$log_text      = "" ;           // ログ出力用 ログファイル
$message_jigyosyo  = "" ;
$message_ken_all   = "" ;
$map_infowindow    = "" ;
$alert             = "" ;
$now_result_info   = "" ; // 地図下の search result を表示する

$jigyosyo_text2    = "" ;
$now_address_line  = "" ;
$top_page          = "" ;  // トップページ（paraなし）の場合 1を設定

$now_result_info_building = "" ;
$now_result_info_latlng = "" ;
$now_result_info_postal_code = "" ;
$meta_description       = "" ;
$meta_keywords       = "" ;
// base_url 設定
$base_url = "" ;
foreach ($_GET as $g_key => $g_value){
	if( $base_url == "" ){
		$base_url .= "?" . $g_key.'='.$g_value;
	} else {
		$base_url .= "&" . $g_key.'='.$g_value;
	}
}



//---------------------------------------------------------------
// 過去のりれぎ ファイル表示
// 表示するのにソート
// api3用
//---------------------------------------------------------------
//echo "jjj999j[" . $access_history_api3_file . "]"  ;
if (file_exists($access_history_api3_file)) {
//echo "jjj000[jj" ;
	$f_api3 = file($access_history_api3_file);
	krsort($f_api3);
	$i = 0;
	foreach ($f_api3 as $key => $value) {
//echo "jjj111jj" ;
//var_dump($value);

//echo "■■■■■■■■■■■■■■999" ;

	    $v = [];
	    $v = explode("#####", $value);
//	    $v = explode($value , "#####");
	    $i++;
//echo "jjj5[" . $v . "]jjj" ;


	    if (count($v) > 1) {
	        // v0 時間 v1 結果 v2 v3
		// v[1] == 0 成功
	        if ($v[1] == "0") {
//	            $access_history_api3_contents .= "<a href=./index.php?json=" . urlencode($v[2]) . "&searchword=" . urlencode($v[3]) . ">" . $v[0] . " 文字列[" . rtrim($v[3]) . "]は正規表現[" . $v[2] . "]のjson文法をチェックしました</a><br>";
//	            $access_history_api3_contents .= "<a href='./index.php?json=" . urlencode($v[2]) . "'>" . $v[0] . " 正規表現[" . $v[2] . "]のjson文法をチェックしました</a><br>";

			if( $date  != '' ){

			//echo "■■■■■■■■■■■■■■1" ;

				$history_date = str_replace('/','',$v[0]);
				$count1 = strlen(strchr($history_date,$date)) ; 

				if ($count1==0) { 
			//		print "[" . $history_date . "]に文字列[" .  $date  . "]は存在しません。<br/>" ; 
//			            $access_history_api3_contents .= "<a href='./index.php?json=" . urlencode($v[2]) . "'>" . $v[0] . " 正規表現[" . $v[2] . "]のjson文法をチェックしました</a><br>";
				} else {
			//		print "[" . $history_date . "]に文字列[" .  $date  . "]は存在します。<br/>" ; 
			            $access_history_api3_contents .= "<a href='./index.php?json=" . urlencode($v[2]) . "'>" . $v[0] . " 正規表現[" . $v[2] . "]のjson文法をチェックしました</a><br>";
				}


			} else {
			//echo "■■■■■■■■■■■■■■2" ;
			// 日付指定なしなのですべて表示
			    $access_history_api3_contents .= "<a href='./index.php?json=" . urlencode($v[2]) . "'>" . $v[0] . " は正規表現[" . $v[2] . "]のjson文法をチェックしました</a><br>";
			}
//	            $access_history_api3_contents .= "■31<br>" ;
	        } else {
//	            $access_history_api3_contents .= "<a href=./index.php?json=" . urlencode($v[2]) . "&searchword=" . urlencode($v[3]) . ">" . $v[0] . " 文字列[" . rtrim($v[3]) . "]は正規表現[" . $v[2] . "]のパターンにマッチングしませんでした</a><br>";
//	            $access_history_api3_contents .= "■32<br>" ;
	        }
	    }
	    if ($i >= ACCESS_HISTORY_DISPLAY_ROW_COUNT) {
	        break;
	    }
	}
}


//---------------------------------------------------------------
// 過去のりれぎ ファイル表示
// 表示するのにソート
// api2用
//---------------------------------------------------------------
if (file_exists($access_history_api2_file)) {
	$f_api2 = file($access_history_api2_file);
	krsort($f_api2);
	$i = 0;

	foreach ($f_api2 as $key => $value) {
	    $v = [];
	    $v = explode("#####", $value);
//	    $i++;

	    if (count($v) > 1) {
	        // v0 時間 v1 結果 v2 v3
		// v[1] == 0 成功
	        if ($v[1] == "0") {

//echo "vv0[" . $v[0] . "]<br>" ;
//echo "vv1[" . $v[1] . "]<br>" ;
//echo "vv2[" . $v[2] . "]<br>" ;
//echo "vv3[" . $v[3] . "]<br>" ; //これがないってえらーになる

			if( $date  != '' ){
				// 日付指定がある場合
				$history_date = str_replace('/','',$v[0]);
				$count1 = strlen(strchr($history_date,$date)) ; 
				if ($count1==0) { 
					//文字列は存在しません" ; 
		//	            $access_history_api3_contents .= "<a href='./index.php?json=" . urlencode($v[2]) . "'>" . $v[0] . " 正規表現[" . $v[2] . "]のjson文法をチェックしました</a>★★1<br>";
//			            $access_history_api2_contents .= "<a href='./index.php?json=" . urlencode($v[2]) . "'>" . $v[0] . " 正規表現[" . $v[2] . "]を整形しました</a><br>";
				} else {
					//文字列は存在する" ; 
		//	            $access_history_api3_contents .= "<a href='./index.php?json=" . urlencode($v[2]) . "'>" . $v[0] . " 正規表現[" . $v[2] . "]のjson文法をチェックしました</a>★★2<br>";
			            $access_history_api2_contents .= "<a href='./index.php?json=" . urlencode($v[2]) . "'>" . $v[0] . " 正規表現[" . $v[2] . "]を整形しました</a><br>";
				}
			} else {
				// 日付指定がない場合はすべて表示
				$access_history_api2_contents .= "<a href='./index.php?json=" . urlencode($v[2]) . "'>" . $v[0] . " 正規表現[" . $v[2] . "]を整形しました</a><br>";
			}

//	            $access_history_api2_contents .= "<a href=./index.php?json=" . urlencode($v[2]) . "&searchword=" . urlencode($v[3]) . ">" . $v[0] . " 文字列[" . rtrim($v[3]) . "]は正規表現[" . $v[2] . "]を整形しました</a><br>";
//	            $access_history_api2_contents .= "<a href=./index.php?json=" . urlencode($v[2]) . "&searchword=" . urlencode($v[3]) . ">" . $v[0] . " 正規表現[" . $v[2] . "]を整形しました</a><br>";
//	            $access_history_api2_contents .= "<a href='./index.php?json=" . urlencode($v[2]) . "'>" . $v[0] . " 正規表現[" . $v[2] . "]を整形しました</a><br>";
//	            $access_history_api2_contents .= "■21<br>" ;
		    $i++;
	        } else {
//	            $access_history_api2_contents .= "<a href=./index.php?json=" . urlencode($v[2]) . "&searchword=" . urlencode($v[3]) . ">" . $v[0] . " 文字列[" . rtrim($v[3]) . "]は正規表現[" . $v[2] . "]のパターンにマッチングしませんでした</a><br>";
//	            $access_history_api2_contents .= "■22<br>" ;
	        }
	    }
	    if ($i >= ACCESS_HISTORY_DISPLAY_ROW_COUNT) {
	        break;
	    }
	}
}


//----------------------------------------------
// 3-4 ログファイル出力
//----------------------------------------------































function calendar($year = '', $month = '' , $user_id = '' ) {
    if (empty($year) && empty($month)) {
        $year = date('Y');
        $month = date('n');
    }
    //月末の取得
    $l_day = date('j', mktime(0, 0, 0, $month + 1, 0, $year));
    //初期出力
    $html = <<<EOM
<table class="calendar">
    <caption>{$year}年{$month}月</caption>
    <tr>
        <th class="sun">日</th>
        <th class="youbi">月</th>
        <th class="youbi">火</th>
        <th class="youbi">水</th>
        <th class="youbi">木</th>
        <th class="youbi">金</th>
        <th class="sat">土</th>
    </tr>\n
EOM;
    $lc = 0;
    //月末分繰り返す
    for ($i = 1; $i < $l_day + 1;$i++) {
        //曜日の取得
        $week = date('w', mktime(0, 0, 0, $month, $i, $year));
        //曜日が日曜日の場合
        if ($week == 0) {
            $html .= "\t<tr>\n";
            $lc++;
        }
        //1日の場合
        if ($i == 1) {
            if($week != 0) {
                $html .= "\t<tr>\n";
                $lc++;
            }
            $html .= repeatEmptyTd($week);
        }
        if ($i == date('j') && $year == date('Y') && $month == date('n')) {
            //現在の日付の場合
//            $html .= "\t\t<td class=\"today\">{$i}</td>\n";
//            $html .= "\t\t<td class=\"today\"><a href='./calendar.php?date=" . date('Ymd') . "'>{$i}</a></td>\n";
            $html .= "\t\t<td class=\"today\"><a href='./history.php?date=" . date('Ymd') . "'>{$i}</a></td>\n";

        } else {

			if ( $year . $month  < date('Yn') ) {
				// 過去の月
            	$html .= "\t\t<td><a href='./history.php?date=" . $year . sprintf("%02d",$month) . sprintf("%02d",$i) . "'>{$i}</a></td>\n";

			} else {
				// 今月の処理
	            // 現在の日付ではない場合
				// $html .= "\t\t<td>{$i}</td>\n";
				if ( $i < date('j') ) {
					// 過去
	            	$html .= "\t\t<td><a href='./history.php?date=" . $year . sprintf("%02d",$month) . sprintf("%02d",$i) . "'>{$i}</a></td>\n";

				} else {
					// みらい
	            	$html .= "\t\t<td>{$i}</td>\n";
				}

			}

        }
        //月末の場合
        if ($i == $l_day) {
            $html .= repeatEmptyTd(6 - $week);
        }
        //土曜日の場合
        if ($week == 6) {
            $html .= "\t</tr>\n";
        }
    }
    if ($lc < 6) {
        $html .= "\t<tr>\n";
        $html .= repeatEmptyTd(7);
        $html .= "\t</tr>\n";
    }
    if ($lc == 4) {
        $html .= "\t<tr>\n";
        $html .= repeatEmptyTd(7);
        $html .= "\t</tr>\n";
    }
    $html .= "</table>\n";
    return $html;
}
 
function repeatEmptyTd($n = 0) {
    return str_repeat("\t\t<td> </td>\n", $n);
}






















?>

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
	<link rel="shortcut icon" href="./favicon.ico" />

<?php


//if( $title != "" ){
	if( $date != "" ){
		echo "<title>" . $date . "のjsonチェック  " .  $title  . "</title>\n" ;
		echo "<meta name='description' content='" . $date . "のjsonチェック' />\n" ;
		echo "<meta name='keywords' content='" .    $date    . "のjsonチェック' />\n" ;
	} else {
		echo "<title>jsonフォーマットチェックのヒストリー</title>\n" ;
		echo "<meta name='description' content='jsonフォーマットチェックのヒストリー' />\n" ;
		echo "<meta name='keywords' content='jsonフォーマットチェックのヒストリー' />\n" ;

//	echo "<title>" . $title  . "</title>\n" ;
	}
//} else {
//	echo "<title>jsonフォーマットチェックのヒストリー</title>\n" ;
//}  
  
//if( $meta_description != "" ){
//	echo "<meta name='description' content='" . $meta_description . "' />\n" ;
//} else {
//	echo "<meta name='description' content='jsonフォーマットチェックのヒストリー' />\n" ;
//}  

if( $meta_keywords != "" ){
	echo "<meta name='keywords' content='" .    $meta_keywords    . "' />\n" ;
} else {
	echo "<meta name='keywords' content='jsonフォーマットチェックのヒストリー' />\n" ;
}  

?>    



    <!-- Mobile Specific Metas
  ================================================== -->
    <meta name="viewport" content="width=device-width, initial-scale=1">

    
    <!-- CSS
  ================================================== -->
    <!-- Bootstrap -->
    <link href="assets/css/bootstrap.min.css" rel="stylesheet">
    <!-- FontAwesome -->
    <link rel="stylesheet" href="css/font-awesome.min.css">
    <!-- Elegant icon font -->
     <link rel="stylesheet" href="css/line-icons.min.css">
    <!-- Animation -->
    <link rel="stylesheet" href="css/animate.css">
    <!-- Prettyphoto -->
    <link rel="stylesheet" href="css/prettyPhoto.css">
    <!-- Owl Carousel -->
    <link rel="stylesheet" href="css/owl.carousel.css">
    <link rel="stylesheet" href="css/owl.theme.css">
    <!-- Scrolling nav css -->
    <link rel="stylesheet" href="css/scrolling-nav.css">
    <!-- Template styles-->
    <link rel="stylesheet" href="css/style.css">
    <!-- Responsive styles-->
	<link rel="stylesheet" href="css/responsive.css">

    <!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
    <!--[if lt IE 9]>
      <script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
      <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
    <![endif]-->

<style type='text/css'>
<!--
// css 
.thumbnail       { text-align:center; font-size:0.9em; }
.thumbnail_box   { width:170px; }
.img-responsive  { margin-bottom:3px; }
.search_box      { float:left; width:310px; margin-bottom:30px; }
.search_subtitle { font-size:2.0em; font-weight:bold; margin-bottom:10px; }
.search_sample   { margin-top:5px; }
body             { padding:0px; margin:0px; font-family:Lucida Grande, Tahoma, Verdana, "メイリオ", Meiryo,"ヒラギノ角ゴ Pro W3", "Hiragino Kaku Gothic Pro", Osaka, "ＭＳ Ｐゴシック", "MS PGothic", sans-serif; }
.about-content   { }
#about           { padding-top:0px; padding-bottom:0px; }
.now_result_info_en { font-size:0.3em; }
h4 { margin:0px; padding:0px; line-height: 14px; height:36px; }
.about-inner     { }
.about-inner i   { height:28px; color:#FF5555; font-weight:normal; }    
.number_info_tani { font-size:0.6em; }
.item-content li h4{ color:#FFFFFF; }
.img_pin         { color:#3388FF; font-weight:bold; font-size:1.0em; }
.number_data     { font-size:1.8em; line-height:180%; }
.subtitle        { font-size:2.5em;}


.calendar    { font-size:18px; width:80%; }
.calendar td { text-align:right; padding:3px; }
.youbi    { width:100px; text-align:right; }
.sat      { width:100px; text-align:right; }
.sun      { width:100px; text-align:right; }


-->
</style>



  </head>
  <body data-spy="scroll" data-target=".navbar-fixed-top"  style="padding-bottom:0px; margin-bottom:0px;">
<!-- Header start -->
	<header id="header" role="banner" style="background:#333333; padding-top:0px; margin-top:0px;">
		<nav class="navbar navbar-default navbar-fixed-top"  id="tf-menu" style="padding:0px; margin:0px; background:#555555;">
			<div class="container">
				<div class="row">
					<!-- Logo start -->
					<div class="navbar-header">
					    <div class="navbar-brand">
						    <a href="<?= $home_url ?>" class="page-scroll">
						    	<img class="img-responsive" src="img/logo7.png" alt="logo">
						    </a> 
					    </div>                   
					</div>

					<!--/ Logo end -->
				</div><!--/ Row end -->
			</div><!--/ Container end -->
		</nav>
	</header><!--/ Header end -->
    <!-- END MAIN NAV -->

<div id="slider-part"></div>

<br>
<br>
<br>
<br>
        <div style="text-align:center; width :100%; margin-top:5px; margin-bottom:10px; margin-left:auto; margin-right:auto; ">
            <a href="<?= $home_url ?>" style="color:#333333; ">
                <center>
                    <img class="img-responsive" src="img/logo8.png" alt="logo" style="width:500px;" alt="jsonチェック">
                </center>
            </a>
        </div>


<div id="sec2"></div>

<br>

<div id="sec3"></div>

<div id="sec7"></div>
	<h2 style="width :80%; margin-bottom:20px;  margin-left:auto; margin-right:auto; "><span class="icon icon-map-pin img_pin" ></span>&nbsp;過去の<span>検索履歴</span></h2>

	<!-- section about start -->
	<section id="about">
		<div class="container">



        <div class="row" >
            <div class="heading-inner text-center"  style="padding-bottom:0px; margin-bottom:0px;">
                <br>
                <div style="text-align:left;">
                    <?php
                    echo $access_history_api3_contents;
                    ?>
                </div>
            </div>
        </div> <!-- heading row end -->


        <div class="row" >
            <div class="heading-inner text-center"  style="padding-bottom:0px; margin-bottom:0px;">
                <br>
                <div style="text-align:left;">
                    <?php
                    echo $access_history_api2_contents;
                    ?>
                </div>
            </div>
        </div> <!-- heading row end -->



		</div>	<!-- container end -->
	</section>
	<!-- section about end -->

<br>
<br>

<center>

<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<ins class="adsbygoogle"
     style="display:block; text-align:center;"
     data-ad-format="fluid"
     data-ad-layout="in-article"
     data-ad-client="ca-pub-8933330050465971"
     data-ad-slot="1524557015"></ins>
<script>
     (adsbygoogle = window.adsbygoogle || []).push({});
</script>

</center>
<br>
<br>









<center>
<?php

// カレンダー
// calendar_now	
echo calendar(date('Y'), date('n')) ;    // 通常（現在の日付）
echo "<br>" ;
//calendar_before 
echo calendar(date('Y'), date('n')-1 ) ; // 特定年月のカレンダーを表示する場合

?>
</center>
<br>










	<!-- section Footer start  -->
	<footer id="footer" style="padding:0px; padding-top:10px; padding-bottom:10px;  background:#222222; color:#FFFFFF;">
		<div class="container"  style="width :95%;  margin-left:auto; margin-right:auto;">
jsonフォーマットをチェックします
<div style="padding-top:10px;">
<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fjsoncheck.work%2F&amp;layout=button_count&amp;width=220&amp;action=like&amp;colorscheme=light&amp;height=21" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:100px; height:21px;"></iframe>
&nbsp;&nbsp;
<a href="http://twitter.com/share" class="twitter-share-button" data-count="horizontal" data-lang="ja">Tweet</a><script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script>
</div>

		</div> <!-- container end  -->
	</footer>
	<!-- section Footer end  -->



	
	<!-- Back To Top Button -->
    <div id="back-top">
        <a href="#slider-part" class="page-scroll btn btn-primary" ><i class="fa fa-angle-double-up"></i></a>
    </div>
    <!-- End Back To Top Button -->

    <!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
    <!-- Include all compiled plugins (below), or include individual files as needed -->
    <script src="assets/js/bootstrap.min.js"></script>
    <!-- initialize jQuery Library -->
    <script type="text/javascript" src="js/jquery.js"></script>
    <!-- Owl Carousel -->
    <script type="text/javascript" src="js/owl.carousel.js"></script>
    <!-- PrettyPhoto -->
    <script type="text/javascript" src="js/jquery.prettyPhoto.js"></script>
    <!-- Wow Animation -->
    <script type="text/javascript" src="js/wow.min.js"></script>
    <!-- SmoothScroll -->
    <script type="text/javascript" src="js/smooth-scroll.js"></script>
    <!-- Eeasing -->
    <script type="text/javascript" src="js/jquery.easing.1.3.js"></script>
    <!-- Counter -->
    <script type="text/javascript" src="js/jquery.counterup.min.js"></script>
    <!-- Waypoints -->
    <script type="text/javascript" src="js/jquery.waypoints.min.js"></script>
    <!-- Scrolling navigation -->
    <script type="text/javascript" src="js/scrolling-nav.js"></script>
    <!-- Google Map API Key Source -->
    <script src="http://maps.google.com/maps/api/js?sensor=false"></script>
    <!-- Custom js -->
    <script type="text/javascript" src="js/custom.js"></script>
	<script>
		new WOW().init();
	</script>
    <script>
        
   $('.counter').counterUp({
            delay: 100,
            time: 2000
        });
    </script>
  </body>
</html>
