<?php
include_once "template.php";
include_once 
"../link/function.php";
include_once 
"../class/clsDocType.php";
include_once 
"../class/clsDepartment.php";
include_once 
"funct.php";
include_once 
"../link/keyThai.php";

$oC = new clsConnection($GLOBALS['DBHOST'], $GLOBALS['DBNAME_EOFFICE'], $GLOBALS['DBUSER_EOFFICE'], $GLOBALS['DBPASS_EOFFICE']);

$oDt = new doctype($oC); 
$oDP = new Department($oC);
$InputThai=$oSys->SearchByInputThai();
?>
<html>
<head>
<script language="javascript" src="../source/calendarDateInput.js"></script>
<meta http-equiv="Content-Type" content="text/html; charset=tis-620">
<link href="../source/style.css" rel="stylesheet" type="text/css">
</head>
<style>
/*
<!--
A:link {text-decoration: none; color: #000000}
A:visited {text-decoration: none; color: #000000}
A:hover {text-decoration: none; font-weight: bold; color: #000066} 
-->
*/
</style>
<body>
<table  width="100%"  align="center">
<tr><td >
<fieldset>
      <legend><font size="2" color="<?php echo $GLOBALS["COLOR_FONT_3"]; ?>"><a href="?mm=1">รายงาน</a>
    </font>
    <img src="../picture/ico3.gif" width="10" border="0" align="absmiddle">รายงานสรุปจำนวนหนังสือรายการประเภทต่างๆแยกตามหน่วยงานย่อยรายไตรมาส</font>
    </legend>
        <form name="ff"  target="_blank">
        <table width="70%" border="0" align="center" cellpadding="0" cellspacing="0" bordercolor="#DADADA" style="border-collapse:collapse">
          <tr> 
            <td width="18%" height="22"><font color="<?php echo $GLOBALS["COLOR_FONT_2"]; ?>" size="2"><strong>เลือกหน่วยงาน&nbsp;:</strong></font></td>
            <td width="82%"><select name="deptId">
                <option value="0">- เลือกหน่วยงาน -</option>
                <? $oDP->SearchBydeptDateDocGroup($oDP->SearchMaxDocGroup());
                            while(
$oDP->GetRecord()){?>
                <option value="<? echo $oDP->deptId;?><? if($oDP->deptId==$deptId){   echo "selected";  }?>><? echo $oDP->deptName?></option>
                <? ?>
              </select></td>
          </tr>
          <tr> 
            <td colspan="2">&nbsp; </td>
          </tr>
          <tr> 
            <td><font color="<?php echo $GLOBALS["COLOR_FONT_2"]; ?>" size="2"><strong>รายงานประจำปี&nbsp;:</strong></font> 
              
            </td>
            <td><input name="searchY" type="text" size="5" value=<?  echo a2th(Date('Y')+543); ?> onKeyPress="event.keyCode=CheckInput(event.keyCode,'<? echo $InputThai?>'); return event.keyCode;"></td>
          </tr>
          <tr> 
            <td colspan="2" ><hr color="#000099"></hr>
              </td>
          </tr>
          <tr> 
            <td colspan="2"  align="right"><input name="" type="button" value="ออกรายงาน" onClick = "sendPage();"></td>
          </tr>
        </table>
         </form></fieldset> 
</td>
</tr>
</table>
</body>
</html>    
<script language="javascript">
  function chkDate(){
    val = document.getElementById('selectVal').value;
    if(val == 2){
        f = document.ff;
        var date1 = f.DocDateCreateStart.value.split("/");
        var date2 = f.DocDateCreateEnd.value.split("/");
        //Set the two dates
        date1 = new Date(eval(date1[2]), eval(date1[1]-1), eval(date1[0]));
        date2 = new Date(eval(date2[2]), eval(date2[1]-1), eval(date2[0])); //Month is 0-11 in JavaScript
        //Set 1 day in milliseconds
        var one_day = 1000*60*60*24;
        //Calculate difference btw the two dates, and convert to days
        var diff = Math.ceil((date2.getTime()-date1.getTime())/(one_day));
        if(diff < 0){
            alert("กรุณาตรวจสอบช่วง 'วันที่เริ่มต้น' ควรน้อยกว่า 'วันที่สิ้นสุด' !");
            return false;
        }else{
            return true;
        }
    }else{
        return true;
    }
 }
 function sendPage() {
     if(document.ff.deptId.value==0){
                alert("กรุณาเลือกหน่วยงาน");
                document.ff.PtID.focus();
                return false ;
    }else{
            if(document.ff.searchY.value==''){
                alert("กรุณากรอกปี");
                document.ff.searchY.focus();
                return false ;
            }else{
                    var links;
                    var searchY=document.ff.searchY.value;
                    var deptId=document.ff.deptId.value;
                    
                    links = "./printRepSumDocDept.php?yearDoc="+searchY+"&deptId="+deptId;
                    window.open(links,'','toolbar=0, scrollbars=1, location=0, statusbar=0, menubar=1, resizable=1, width=1012, height=620, left = 150, top = 15');
            }
    }
}
function radioSelectType(val){
    document.getElementById('RPtype').value=val;
}
function radioSelectVal(val){
    document.getElementById('selectVal').value=val;
}
</script>