<?
include_once("pagebody.php");
pageHeader();
$pageTitle="รายงานสรุป การกำหนดสิทธิ์การใช้งานในระบบงาน-กลุ่มผู้ใช้งาน รายบุคคล";

$submit $_REQUEST['submit'];
$txtSrch trim($_POST['txtSrch']);
$aUsID $_POST['UsID'];

echo 
"<table width=100% class=\"pageTitleBgColor\" align=\"center\">\n";
echo 
"<tr><td align=center>$pageTitle</td></tr>\n";
echo 
"</table>";
?>
<!--your code here-------------------------------------------------------------------------->
<br>
<p align=center>
<form name=form1 method=post>
<table bgcolor=#eeeeee align="center">
    <tr>
        <td>รหัสผู้ใช้/ชื่อ-นามสกุล</td>
        <td><input type="text" name="txtSrch" value="<?=$txtSrch?>">
                <input type="submit"  name="submit" value="Search"></td>
        </tr>
 </table>
</form>
</p>
<!--------------------------------------------------->
<?
if ($txtSrch==""){
    echo 
"<p align=center><font color='red'>กรุณาป้อน รหัสผู้ใช้/ชื่อ-นามสกุล</font></p>";        
}else{
    
$oC = new clsConnection($GLOBALS['HOST'], $GLOBALS['DB'], $GLOBALS['USER'], $GLOBALS['PASSWORD']);
    if (
count($aUsID)==0){
        include_once(
"clsUmUserR.php");
        
$oUs = new umuserr($oC);
        
$oUs->RSUserByLogin_Name($txtSrch);
        
$i=1;
?>
        <form name=form method="POST">
        <input type="hidden" name="txtSrch" value="<?=$txtSrch?>">
        <table align="center" cellspacing="1" border="0" width=40%>
        <tr align="right" bgcolor="#dddddd"><td colspan="3">พบ <?=$oUs->numRows ?>รายการ</td></tr>
        <tr bgcolor="#dddddd"><th>เลือก</th><th>รหัสผู้ใช้</th><th>ชื่อ-นามสกุล</th></tr>
<?
        
while ($oUs->GetRecord()){
            
$bgcolor = ($i%2)? "#ffffff" "#ddeeff"
            echo 
"<tr bgcolor=$bgcolor>\n";
            echo 
"<td align=center><input type=checkbox name=UsID[] value='$oUs->UsID'></td>\n";
            echo 
"<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$oUs->UsLogin</td>\n";
            echo 
"<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$oUs->UsName</td>\n";
            echo 
"</tr>";
            
$i++;
        }
?>
        <tr  bgcolor=#ffffff>
          <td colspan="2">
            <a href="javascript:doCheckAll(this.form,true);">ทั้งหมด</a> | 
            <a href="javascript:doCheckAll(this.form,false);">ไม่เลือกเลย</a>
        </td>
        <td><input type="submit" name="Search1" value=" OK "></td>
        </tr>
        </table>
        </form>
<?
    
}else{
        
//==========----------========----------====================----------========----------
?>
    <table bgcolor="#dddddd" align="center" cellpadding="0" cellspacing="0">
    <tr><td>
        <table align="center" cellspacing="1"  cellpadding="3" width="100%">
<?
        $i
=1;
        foreach (
$aUsID as $val){
            include_once(
"clsUmUserR.php");
            
$oUs = new umuserr($oC);
            
            
// get user info
            
$oUs->SearchByKey($val);
            
$oUs->GetRecord();
?>
            <tr bgcolor="#eeeddd">
                <th>ลำดับ</th><th>ID</th><th>ชื่อ-นามสกุล</th><th>ชื่อเข้าใช้ระบบงาน</th><th>ระบบงาน-กลุ่มผู้ใช้งาน</th><th>หมายเหตุ</th> </tr>
<?
            $svi 
$i;
            
$svUsID $oUs->UsID;
            
$svUsName $oUs->UsName;
            
$svUsLogin $oUs->UsLogin;
            
            
// get system assigned by user
            
$oUsSys = new umuserr($oC);
            
$oUsSys->RSWorkOnSystemName($svUsID);
            while (
$oUsSys->GetRecord()){
                
$svStID $oUsSys->StID;
                
$svStNameT $oUsSys->StNameT;
                
// print first row in each System
?>                
                <tr bgcolor="White">
                    <td align="center"><?=$svi?></td>
                    <td align="center"><?=$svUsID?></td>
                    <td align="center"><?=$svUsName?></td>
                    <td align="center"><?=$svUsLogin?></td>
                    <td><b><?=$svStNameT?><b></td>
                    <td><pre> </td> </tr>    
<?
                
//clear save value for next line in the same System
                
$svi "&nbsp;";
                
$svUsID "&nbsp;";
                
$svUsName "&nbsp;";
                
$svUsLogin "&nbsp;";
                
$svStNameT "&nbsp;";
                
                
//print Group name in each System
                
$oUsGp = new umuserr($oC);
                
$oUsGp->RSGroupName($val$svStID);
                while (
$oUsGp->GetRecord()){
?>
                    <tr bgcolor="White">
                        <td><?=$svi?></td>
                        <td><?=$svUsID?></td>
                        <td><?=$svUsName?></td>
                        <td><?=$svUsLogin?></td>
                        <td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                              <?=$oUsGp->GpNameT?></td>
                        <td><pre> </td> </tr>
<?
                
// while ($oUsGp->GetRecord())
                
            
// while ($oUsSys->GetRecord())

            
$i++;
?>
            <tr bgcolor="White">
            <td colspan=6>&nbsp;</td> </tr>
<?
        
// foreach ($aUsID as $val)
?>
        </table>
    </td></tr></table><br />
<?
        
//==========----------========----------====================----------========----------
    
}
        
}
?>


<!--------------------------------------------------------------------->
<? pageFooter(); ?>
<!--------------------------------------------------------------------->
<!--put javascript here-->
<script language="javascript">
function doCheckAll(form, do_check){
        for (var i=0; i<form.length; i++){
                if (form.elements[i].type == 'checkbox')
                        form.elements[i].checked = do_check;
        }
}
</script>

<table>
</table>