<?
include_once("./_common.php");
include_once(G5_PATH."/head.sub.php");
$i=0;
?>
<style>
.board_top { clear:both; }

.board_list { clear:both; width:98%; table-layout:fixed; margin:5px 0 0 0; }
.board_list th { font-size:12px; } 
.board_list th { white-space:nowrap; height:35px; overflow:hidden; text-align:center; } 
.board_list th { border-top:1px solid #ddd; border-bottom:1px solid #ddd; } 

.board_list tr.bg0 { background-color:#fafafa; } 
.board_list tr.bg1 { background-color:#ffffff; } 

.board_list td { padding:.5em; }
.board_list td { border-bottom:0px solid #ddd; } 
.board_list td.num { font-size:11px; color:#888888; font-family:Tahoma; text-align:center; height:35px; }
.board_list td.checkbox { text-align:center; }
.board_list td.subject { font-size:12px; color:#888888; overflow:hidden; text-align:center; }
.board_list td.member { font-size:12px; color:#888888; font-weight:normal;  text-align:right;}
.board_list td.name { font-size:11px; font-weight:normal; padding:0 0 0 20px; }
.board_list td.datetime { font:normal 11px tahoma; color:#BABABA; text-align:center; }
.board_list td.hit { font:normal 11px tahoma; color:#BABABA; text-align:center; }
.board_list td.good { font:normal 11px tahoma; color:#BABABA; text-align:center; }
.board_list td.nogood { font:normal 11px tahoma; color:#BABABA; text-align:center; }

.board_list .notice { font-size:12px; color:#383838; font-weight:bold; }
.board_list .current { font:10px verdana; font-weight:bold; color:#E15916; }
.board_list .comment { font-family:Tahoma; font-size:10px; color:#EE5A00; }

.board_button { clear:both; margin:10px 0 0 0; }

.board_page { clear:both; text-align:center; margin:3px 0 0 0; }
.board_page a:link { color:#777; }

.board_search { text-align:center; margin:10px 0 0 0; }
.board_search .stx { height:20px; border:1px solid #9A9A9A; border-right:1px solid #D8D8D8; border-bottom:1px solid #D8D8D8; padding:4 0 0 5; }
</style><div style="padding:7"></div>
<? include(G5_PATH."/gnu_lib/menu.php");


if($excel == "y") {
 $title = "Report";
 header( "Content-type: application/vnd.ms-excel" );  
 header( "Content-Disposition: attachment; filename=도서통계-".date("dmYmsh").".xls");  
// $title 변수명으로 저장됩니다. 원하는 이름으로 바꾸세요
 header( "Content-Description: PHP4 Generated Data" );
}
?>

<link rel="stylesheet" href="<?php echo G5_URL ?>/css/default.css">
<script language=javascript>
  function win_print() {
              self.print();
  }
</script> 

<body > 
<table width=100%>
<?
if($check_year == "" ) $check_year = date("Y");
if($check_month == "" ) $check_month = date("m");

	$i=0;
	$query5 = "select left(wr_datetime, 4) as date_time from g5_write_library  group by wr_datetime order by wr_datetime desc";
	$result5 = sql_query($query5);
	while($row  = sql_fetch_array($result5)) {
		$datetime[$i] = $row[date_time];
	$i++;
	}

?>
<form name="fwrite" method="post" action="./print.php">
    <tr>
		<td   align=center><a href="print.php?excel=y">Export to excel</a></td><td><a href="print.php"> 총 누적 조회 </a></td>
			<td  align=right>년월별 조회</td><!--- 년별, 월별, 주간별 3단으로 출력-->
			<td align=right>년 <select name="check_year">
			<? for($i=0; $i < count($datetime); $i++) { ?>
			<option value="<?=$datetime[$i]?>">  <?=$datetime[$i]?>
<? } ?>
		</select> </td>
			<td width=30% align=right>월 <select name="check_month">
					<? $m=1; for($i=0; $i < 12; $i++) { ?>
			<option value="<?=$m?>"><?=$m?>
<? $m++; } ?>
		</select>&nbsp;&nbsp;&nbsp; 년도별 조회 시는 해당 년만 선택하세요.</td>
			<td><input type=image id="btn_submit" src="<?php echo G5_URL ?>/skin/board/library//img/btn_search.gif" border=0 accesskey='s'></td>
	</tr>
   

	<tr>
        <th colspan=18  align=center>
<table width=100% cellpadding="5" cellspacing="0" border="1" align="center" style="border-collapse:collapse; border:1px gray solid;"  class="board_list">
	

	
</form>	


<tr>
        <th colspan=3 align=center>총 누적</th>  <th width=10 rowspan=33>&nbsp; </th>  <th colspan=3 align=center>변도별</th><th width=10 rowspan=34> &nbsp;</th> <th colspan=3 align=center>월별</th> </tr>



<tr>
        <th>순위</th>

        <th>이름 </th>
		        <th>대여권수</th>           
			<th>순위</th>

        <th>이름 </th>
		        <th>대여권수</th>        
				<th>순위</th>

        <th>이름 </th>
		        <th>대여권수</th> 


<tr>

<?

	$i=0;
	$query5 = "select   wr_3,count(wr_3) as sum_name from g5_write_library  group by wr_3  limit 30";
	$result5 = sql_query($query5);
	while($row  = sql_fetch_array($result5)) {
		$total_name[$i] = $row[wr_3];
		$total_sum[$i] = $row[sum_name];
	$i++;
	}

?>
<?

	$i=0;
	$query5 = "select   wr_3,count(wr_3) as sum_name from g5_write_library where left(wr_datetime, 4) = '$check_year' group by wr_3  limit 30";
	$result5 = sql_query($query5);
	while($row  = sql_fetch_array($result5)) {
		$year_name[$i] = $row[wr_3];
		$year_sum[$i] = $row[sum_name];
	$i++;
	}

?>
<?

	$i=0;
	$year_month = $check_year."-".$check_month;
	$query5 = "select  wr_3, count(wr_3) as sum_name from g5_write_library  where left(wr_datetime, 7) = '$year_month' group by wr_3  limit 30";
	$result5 = sql_query($query5);
	while($row  = sql_fetch_array($result5)) {
			$month_name[$i] = $row[wr_3];
		$month_sum[$i] = $row[sum_name];
	$i++;
	}

?>


<? $m =0; for($i=0; $i < 30; $i++) { $m++;?>
<tr>
	<td  class="subject" ><?=$m?> </td>
	<td  class="subject"><?=$total_name[$i]?></td>
	<td class="subject"><?=$total_sum[$i]?></td>
	
	<td class="subject"><?=$m?> </td>
	<td class="subject"><?=$year_name[$i]?></td>
	<td class="subject"><?=$year_sum[$i]?></td>
	
	<td class="subject"><?=$m?> </td>
	<td class="subject"><?=$month_name[$i]?></td>
	<td class="subject"><?=$month_sum[$i]?></td>
</tr>
<? } ?>

	

</table>
</td>
	
</tr>
</table>

