<?
//  odaeri/sitemap.xml
/*
2016-10-01 16:13
lastmod: $updateTime 을 찾아라....

추적 컬럼들...
KeywordTable.geoId
DeptPoint.geoId
FakeOrders.deptPointId

필요한 최종 컬럼:
FakeOrders.driveDate

select keyc.driveDate,b.pointName from
    KeywordTable a, DeptPoint b, FakeOrders c
    where a.geoId=b.geoId
    and b.deptPointId=c.deptPointId
    order by driveDate desc limit 10

이 쿼리로 되긴 하는데....
"신용산역" 이 선택되면 해당 동이 누락되는 부작용이 발생...
select keywordTableId,c.driveDate,b.pointName from
    KeywordTable a, DeptPoint b, FakeOrders c
    where a.geoId=b.geoId
    and b.deptPointId=c.deptPointId
    group by keywordTableId
    order by driveDate desc limit 100

역 키워드를 포함시키기 위한 union 쿼리...
(select keywordTableId,keyword,c.driveDate,b.pointName from
    KeywordTable a, DeptPoint b, FakeOrders c
    where a.geoId=b.geoId
    and b.deptPointId=c.deptPointId
    and keywordGroup != 'station'
    group by keywordTableId
    order by driveDate desc)
union
(select keywordTableId,keyword,c.driveDate,b.pointName from
    KeywordTable a, DeptPoint b, FakeOrders c
    where a.geoId=b.geoId
    and b.deptPointId=c.deptPointId
    and keywordGroup = 'station'
    group by keywordTableId
    order by driveDate desc)

동 & 역 은 뽑았지만, 구,읍,시 는 누락되었다.
일단 동& 역 으로 맵을 만들어주고, 구,읍,시 를 포함시킬 방법을 찾자...

2016-10-03
시/구/읍/면 의 lastmod ....


*/

//	주요 시스템상수.
include("./conf/config.inc");

//	DBClass Lib
include("$projectDirectory/lib/DBLib.inc");
//	범용 소형펑션 Lib
include("$libraryDirectory/generalFuncs.inc");
//	전용 펑션 Lib
include("$projectDirectory/lib/daeriLib.inc");


//	세션 스타트 & DB 컨넥트.
session_start();
/*
echo($botName);
exit;
*/
$a = new DBClass("Connect");
$preQuery = "set names utf8";
$a->runQuery($preQuery);

$b = new DBClass("Connect");

//exit;
/*
                    [6819] => 2016-09-17 00:51:49
                    [6760] => 2016-10-01 18:39:12
                    [6836] => 2016-10-01 00:47:17
                    [6849] => 2016-08-23 23:07:22
                    [6865] => 2016-09-28 22:02:02
                    [6873] => 2016-09-26 22:55:32
                    [6774] => 2016-09-29 23:00:02
                    [6884] => 2016-05-11 22:33:35
                    [6893] => 2016-10-01 21:44:24
                    [6921] => 2016-09-26 22:24:17
      향남읍        [6796] => 2016-10-01 21:36:56
                    [0] => 2016-10-01 20:19:45
                    [6801] => 2016-09-29 22:08:02
*/

$date = new DateTime();
//	%Y-%m-%dT%H:%i:%s
//	article.xml 의 lastmod
$date->add(DateInterval::createFromDateString('-2 days'));
//$articleDateStr = $date->format('Y-n-d') . "T00:00:00" ;
$articleDateStr = $date->format('Y-m-d');
//	landing.xml 의 lastmod
$date = new DateTime();
$date->add(DateInterval::createFromDateString('-1 week'));
$landingDateStr = $date->format('Y-m-d');
//	static.xml 의 lastmod
$date = new DateTime();
$date->add(DateInterval::createFromDateString('-2 days'));
$staticsDateStr = $date->format('Y-m-d');


//	index.html 의 최종수정시각...
//	inquiry 의 최종시각 익일... 은 하루전 12:59:00
$issueTime = $now - 86000;
$indexIssueDateStr = str_replace(" ","T", date("Y-m-d 12:59:00", $issueTime))."+09:00";

/////////////////////////////////////////////////////////////////////////////////////////
////	XML start
header("Content-type: text/xml;charset=utf-8");
//header("Pragma: no-cache");
$xmlStr.= "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n";

$xmlStr.= "<sitemapindex xmlns='http://www.sitemaps.org/schemas/sitemap/0.9'>
<sitemap>
	<loc>https://".$defaultDomain."/sitemap_articles.xml</loc>
	<lastmod>".$indexIssueDateStr."</lastmod>
</sitemap>
<sitemap>
	<loc>https://".$defaultDomain."/sitemap_statics.xml</loc>
	<lastmod>".$indexIssueDateStr."</lastmod>
</sitemap>
<sitemap>
	<loc>https://".$defaultDomain."/sitemap_landing.xml</loc>
	<lastmod>".$indexIssueDateStr."</lastmod>
</sitemap>
";



$xmlStr.= $urlBlock;

$xmlStr.= "</sitemapindex>\n";
echo("$xmlStr");



//	뷰 리퀘스트를 모두 로그한다.
//	네이버의 아파치 로그가 남질 않아서.. 네이버 IP 와 요청 패턴을 추적하기 위함..
$time= date("Y-n-j H:i:s",$now);
$newLogStr = $time."\t".$_SERVER[REMOTE_ADDR]."\t#".$_SERVER[REQUEST_URI]."\t(".$_SERVER[HTTP_USER_AGENT].")\n";
if(strpos($_SERVER[REMOTE_ADDR],"220.78.113.")===false) logThisAction( $newLogStr );

//	인콰이어 액션을 로그한다.
function logThisAction( $logStr ) {
	global $now;
	$fp = fopen("/home/odaeri/public_html/log/sitemapViewLog.txt","a+");
	if (!$fp) {
		echo "$errstr ($errno)<br />\n";
		fclose($fp);
		return;
	} else {
		fwrite($fp,$logStr);
		fclose($fp);
	//	echo "$logStr<br />\n";
	}
}
