<?php
include_once "template.php";
include_once 
"../class/clsTable.php";
include_once 
"../class/clsDepartment.php";
include_once 
"../class/clsPerson.php";
include_once 
"../link/function.php";

$oC = new clsConnection($GLOBALS['DBHOST'], $GLOBALS['DBNAME_EPEOPLE'], $GLOBALS['DBUSER_EPEOPLE'], $GLOBALS['DBPASS_EPEOPLE']);

$oDP = new Department($oC);
$oDp = new Department($oC);
$oDP2 = new Department($oC);
$oPS = new Person($oC);
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=tis-620">
<link href="../source/style.css" rel="stylesheet" type="text/css">
</head>
<body>
<br><? $startyear="2551";  $endyear="2551";  ?>
<table  width=703  align="center">
<tr><td height="150">
<fieldset>
      <legend><font size="2" color="<?php echo $GLOBALS["COLOR_FONT_3"]; ?>"><a href="?mm=1">ตั้งค่าการใช้งานระบบ</a>
      <img src="../picture/ico3.gif" width="10" height="10" border="0" align="absmiddle">กำหนดโครงสร้างเพื่อการส่งหนังสือในระบบสารบรรณ</font></legend>
      <table border="0" align="center" width="100%"><tr><td align="center"><br>
        <?
$oT 
= new clsTable(array("ส่วนราชการภายใน""ดำเนินการ"));
$oT->bgColor="#E9E9F3";
$oT->align="center";
$oDP->RSMainDepartment();

$rw=0;

while (
$oDP->GetRecord()){
    
ShowDeptM($oDP->deptId,$startyear,$endyear);        
}

$oT->rowStart("","#ffffff");
$oT->addCell("");
$oT->addCell("<img src=\"../picture/new.gif\" alt=\"เพิ่มส่วนราชการภายใน\" border=\"0\"  style=\"cursor:pointer;\" onclick=\"poppage($startyear,$endyear);\">""center");

$oT->rowEnd();

echo 
"<form name=ps method=post>";
echo 
"<input type=hidden name=method value=''>";
echo 
"<input type=hidden name=startyear value=''>";
echo 
$oT->output();
echo 
"</form>";

function 
ShowDeptM($deptId,$startyear,$endyear){
    global 
$oC;
    global 
$oT;
    global 
$Str;
    global 
$rw;

    
$oDp  = new Department($oC);
    
$oDp->SearchByKey($deptId);
    
$oDp->GetRecord();
    
/////////////////////////////////////////////
    
if ($oDp->deptLevel%2==0){                            
        
$bs="<b>";    
        
$be="</b>";
        
$b=1;    
    }
    
    
$lv =  $oDp->deptLevel+1;
    if(
$oDp->deptParentId==0){
    
$lv2 =1;
    }else{
    
$lv2 =  $oDp->deptLevel;
    }
    
    
$oT->addRow(array(str_repeat("<img src=../picture/blank.gif><img src=../picture/blank.gif><img src=../picture/blank.gif><img src=../picture/blank.gif><img src=../picture/blank.gif><img src=../picture/blank.gif><img src=../picture/blank.gif><img src=../picture/blank.gif>"$oDp->deptLevel*2). $bs ."   ".$oDp->deptName."  "$be ,    
            
"    <img src=\"../picture/new.gif\" alt=\"เพิ่มส่วนราชการย่อย\" border=\"0\" style=\"cursor:pointer;\" onclick=\"popup($lv,$oDp->deptId,$startyear,$endyear,$lv2);\">
                 <a href=\"javascript:doEditMenu('$oDp->deptId')\">
                     <img src=\"../picture/edit.gif\" alt=\"แก้ไข\"  border=\"0\" ></a>
                 <a href=\"javascript:doDelete(document.form1, '$oDp->deptName','$deptId','$startyear','$endyear')\">
                    <img src=\"../picture/del.gif\" alt=\"ลบ\"  border=\"0\"></a>"
,
                
"<input type=hidden name='deptId[]'  value=\"$oDp->deptId\" readonly>"  ));
    
$oDp->RSmenuByDeptParent($deptId,$startyear,$endyear);
    while (
$oDp->GetRecord()){
        
ShowDeptM($oDp->deptId,$startyear,$endyear);
    }
}
?>
<script>
 function poppage(startyear,endyear){     
window.open("deptpop1.php?startyear="+startyear+"&endyear="+endyear+"&deptLevel="+0+"&deptParent="+0,"loaddorder","width=400,height=200,top=200,left=300,menubar=no,resizeable=yes,toolbar=no,scrollbar=yes");
 }
 function popup(deptLevel,deptParentId,startyear,endyear,lv2){     
window.open("deptpop1.php?startyear="+startyear+"&endyear="+endyear+"&deptLevel="+deptLevel+"&deptParentId="+deptParentId+"&dg="+lv2,"loaddorder","width=400,height=200,top=200,left=300,menubar=no,resizeable=yes,toolbar=no,scrollbar=yes");
 }
function doEditMenu(deptId){
    window.open("deptpop2.php?deptId=" + deptId,"loaddorder","width=600,height=250,top=200,left=300,menubar=no,resizeable=yes,toolbar=no,scrollbar=yes");    
}
function doDelete(f, txt,deptId,startyear,endyear){
    if (confirm('ต้องการลบส่วนราชการ  ' + txt +  ' ใช่หรือไม่') ) {
        window.location="processdept.php?method=delete&startyear="+startyear+"&endyear="+endyear+"&&deptId=" + deptId;
    }
}
</script>
      </td></tr></table>
      
</fieldset>
         <table width="704" border="0" align="center">
        <tr> 
          <td width="76" align="left"><font color="<?php echo $GLOBALS["COLOR_FONT_3"]; ?>" size="2">&nbsp;<strong>หมายเหตุ 
            : </strong>&nbsp;</font></td>
          <td width="618" align="left"><font color="<?php echo $GLOBALS["COLOR_FONT_3"]; ?>" size="2"><img src="../picture/icoa15.jpg" alt=""  border="0"> 
            <font color="<?php echo $GLOBALS["COLOR_FONT_3"]; ?>" size="2">คลิกเพื่อกำหนดงานให้บุคลากรในฝ่าย </font></td>
        </tr>
            <tr> 
          <td width="76">&nbsp;</td>
          <td width="618" align="left">
            <font color="<?php echo $GLOBALS["COLOR_FONT_3"]; ?>" size="2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ตัวเลขที่อยู่ใน () หมายถึงจำนวนบุคลากรที่สังกัดงาน </font></td>
        </tr>
        <tr> 
          <td width="76" align="left">&nbsp;</td>
          <td width="618" align="left"><font color="<?php echo $GLOBALS["COLOR_FONT_3"]; ?>" size="2"><img src="../picture/new.gif"  border="0" align="absmiddle"> 
            คลิกเพื่อเพิ่มงาน </font></td>
        </tr>
                <tr> 
          <td width="76" align="left">&nbsp;</td>
          <td width="618" align="left"><font color="<?php echo $GLOBALS["COLOR_FONT_3"]; ?>" size="2"><img src="../picture/edit.gif"  border="0" align="absmiddle"> 
            คลิกเพื่อแก้ไขชื่องาน </font></td>
        </tr>
        <tr> 
          <td width="76" align="left">&nbsp;</td>
          <td width="618" align="left"><font color="<?php echo $GLOBALS["COLOR_FONT_3"]; ?>" size="2"><img src="../picture/del.gif"  border="0" align="absmiddle"> 
            คลิกเพื่อลบงาน</font></td>
        </tr>
      </table> <br><br>

</td>
</tr>
</table>
</body>
</html>