<?
function date_diff($d1, $d2){
	$d1 = (is_string($d1) ? strtotime($d1) : $d1);
	$d2 = (is_string($d2) ? strtotime($d2) : $d2);

	$diff_secs = abs($d1 - $d2);
	$base_year = min(date("Y", $d1), date("Y", $d2));

	$diff = mktime(0, 0, $diff_secs, 1, 1, $base_year);
	return array(
			"years" => date("Y", $diff) - $base_year,
			"months_total" => (date("Y", $diff) - $base_year) * 12 + date("n", $diff) - 1,
			"months" => date("n", $diff) - 1,
			"days_total" => floor($diff_secs / (3600 * 24)),
			"days" => date("j", $diff) - 1,
			"hours_total" => floor($diff_secs / 3600),
			"hours" => date("G", $diff),
			"minutes_total" => floor($diff_secs / 60),
			"minutes" => (int) date("i", $diff),
			"seconds_total" => $diff_secs,
			"seconds" => (int) date("s", $diff)
			);
}

function file_time($f){
	$mtime = filemtime($f);
	$mtime = $mtime + 3600*9;

	if (date('I') == 1) {
		// Win DST is enabled, adjust standard time
		// files back to 'real' file UTC.
		if (date('I', $mtime) == 0) {
			$mtime -= 3600;
		}
	} else {
		// Win DST is disabled, adjust daylight time 
		// files forward to 'real' file UTC.
		if (date('I', $mtime) == 1) {
			$mtime += 3600;
		}
	}

	return gmdate('Y/m/d H:i:s', $mtime);
}
function print_dir($dir){

	$d = dir($dir);

	while (false !== ($entry = $d->read())) {

		if(strpos($entry,".") == 1){
			continue;
		}

		if(strcmp($entry, ".")==0 || strcmp($entry, "..")==0 || strcmp($entry, ".ssh")==0){
			continue;
		}

		if(is_dir($dir . "/" . $entry)){
			//echo("<font color=blue>" . $dir . "/" . $entry . "</font><br />");
			print_dir($dir . "/" . $entry);
		}
		else{

			$extn = substr($entry, strrpos($entry,".")+1);

			//if(strcasecmp($extn, "html") == 0 || strcasecmp($extn, "htm") == 0){
			if(strcasecmp($extn, "html") == 0 || strcasecmp($extn, "htm") == 0 || strcasecmp($extn, "jsp") == 0){

				$ftime = file_time($dir . "/" . $entry);

				$diffh = date_diff( ereg_replace("/", "-", $ftime),  date('Y-m-d H:m:s') );
				$diff = date_diff( ereg_replace("/", "-", substr($ftime,0,10)),  date('Y-m-d') );

				//echo(ereg_replace("/", "-", substr($ftime,0,10)));
				//print_r($diff);
				//echo("[" . $diff['days'] . "]");

				if($diff['months']==0 && $diff['days'] == 0 && $diffh['hours']<6){
					echo("[ <font color=red><b>" . $ftime  . "</b></font> ]");
				}
				else if($diff['months']==0 && $diff['days'] == 0){
					echo("[ <font color=red>" . $ftime  . "</font> ]");
				}
				else if($diff['months']==0 && $diff['days'] == 1){
					echo("[ <font color=blue>" . $ftime  . "</font> ]");
				}
				else if($diff['months']==0 && $diff['days'] == 2){
					echo("[ <font color=green>" . $ftime  . "</font> ]");
				}
				else if($diff['months']==0 && $diff['days'] == 3){
					echo("[ <font color=black>" . $ftime  . "</font> ]");
				}
				else {
					echo("[ <font color=#666666>" . $ftime  . "</font> ]");
				}

				echo("&nbsp; <a href=\"" . $dir . "/" . $entry . "\">". $dir . "/" . $entry . "</a>");


				echo("<br />\r");

			}
		}
	}
	$d->close();
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="ko">
<head>
<meta http-equiv="Content-Language" content="ko" />
<meta http-equiv="Content-Type" content="text/html; charset=euc-kr" />
<meta http-equiv="imagetoolbar" content="no" />
<meta http-equiv="Pragma" content="no-cache" />
<title>CJON 코딩</title>
<script language="javascript" type="text/javascript" src="/js/HtmlFunction.js"></script>
<script language="javascript" type="text/javascript" src="/js/StrFunction.js"></script>
<script language="javascript" type="text/javascript" src="/js/Calendar.js"></script>
<script language="javascript" type="text/javascript" src="/js/EditorScript.js"></script>
<script language="javascript" type="text/javascript" src="/js/main.js"></script>
<style type="text/css">
body {font-size:10pt;}
body a:link, body a:visited { color: #666; text-decoration: none; }
body a:active, body a:hover { color: blue; text-decoration: underline; }
</style>
</head>
<body style="margin:10px;">
<table border=0 cellspacing=1 cellpadding=0>
	<tr>
		<td>
			<?
			echo("Today : " . date('Y/m/d H:i:s'));
			?>
		</td>
		<td width="30"></td>
		<td bgcolor=red style='padding:0px 2px 0px 2px;'><font color=white><b>6시간</b></font></td>
		<td bgcolor=red style='padding:0px 2px 0px 2px;'><font color=white>today</font></td>
		<td bgcolor=blue style='padding:0px 2px 0px 2px;'><font color=white>1 day</font></td>
		<td bgcolor=green style='padding:0px 2px 0px 2px;'><font color=white>2 day</font></td>
		<td bgcolor=black style='padding:0px 2px 0px 2px;'><font color=white>3 day</font></td>
	</tr>
</table>
<br />
<?
$a = file("/home/user/abrand/cnc/cooking");
for($i=0; $i<sizeOf($a); $i++){
	echo("<br>".$a[$i]);
}
print_dir(".");
?>
</body>
</html>
