<?php
	session_start();
	defined( '_VALID_' ) or die( 'Direct Access to this location is not allowed.' );
	error_reporting(E_ERROR);
	if($_SESSION['admin_plan']!="plan"){
	?><script>
			alert("คุณไม่มีสิทธิ์");
		</script><?die( 'Direct Access to this location is not allowed.  ให้เฉพาะผู้บริหาร module ' );
	}
	$vid_person=$_SESSION['login_user_id'];
	require_once("modules/plan/planproject/plan_authen.php");  //session_
?>
<html>
<META http-equiv=Content-Type content="text/html; charset=utf-8">
<body bgcolor="#cc00cc" text="#000000" link="blue" vlink="purple" alink="red">
<p align="center">
	<Font Size=4 color='#FFFFFF'><BR>:::  เพิ่มผู้บันทึกข้อมูลในระบบ  :::</Font>
<BR><BR>
<TABLE width="100%"  border="0" align="center" cellpadding="2" cellspacing="2" height="50">
<Form id='user_form' name='frm1'>
<TR>
<TD  width="50%"  valign="top"> 
<TABLE  align="center"  width="60%" border="0" borderColor=#FF0033 cellpadding="0" cellspacing="0">
			<tr> 
            <td align="right" ><b><font size="3" face="MS Sans Serif" color="#FFFFFF">ชื่อ - สกุล :</font></b></td>
                    <td>
		<?
		echo   "<Select  name='idperson' size='1'  STYLE=\"font-family: 'sans-serif', fantasy; font-size: 12pt; border:0px\" onChange=\"openDir( this.form )\"=>";
		echo  '<option  style="background-color:navy; color:white;"  value ="" >  # เลือกชื่อสมาชิก </option>' ;
	   require_once("dbconfig.inc.php");
			$sql = "SELECT *  FROM   person_main order by position_code"; 
			$dbquery =DBfieldQuery($sql);
			$num_rows = mysql_num_rows($dbquery);
			$i=0;
			while ($i < $num_rows)
			{
				$result = mysql_fetch_array($dbquery);
				$mid_person = $result[person_id];
				$prename_perm =  trim($result[prename]);
				$name_perm =  trim($result[name]);
				$surname_perm =  trim($result[surname]);
				$myname=$prename_perm.$name_perm.'  '.$surname_perm;
				echo '<option  value="' . $result['person_id'] .'|'. $myname. '">'. $myname.'</option>'; 
			$i++;
			}
?>
    </Select>
                    </td></tr><tr><td colspan='2'>&nbsp;</td></tr>
		<?
			$sql = "SELECT *  FROM   person_main where person_id=$vid_person LIMIT 1 ";
			$dbquery =DBfieldQuery($sql);
			$result = mysql_fetch_array($dbquery);
			$vid_person = $result[person_id];
			if ($vid_person==$_SESSION['login_user_id']){$vid_person='#x#x#x#x#x#x#';}
				echo "	<Input Type=Hidden Name=vname_perm>";
		?>
	<tr > 
            <td align="right"  width='20%'  ><b><font size="3" face="MS Sans Serif" color="#FFFFFF">หมายเลขบัตร :</font></b></td>
                    <td  align="left"  width='30%'  > <input  size=13  type readonly=text name="vid_person" maxlength=13 value=<?=$vid_person?>><b><font size="3" face="MS Sans Serif" color="#FFFFFF">  เลขบัตร 13 หลัก</font></b>
					</td></tr>
					<tr> 
                    <td align="right"><b><font size="3" face="MS Sans Serif" color="#FFFFFF">view :</font></b></td>
                    <td align="left"><input  type=checkbox  name="vperm_view"  onClick="check( this.form )" > <b><font size="3" face="MS Sans Serif" color="#FFFFFF">  สิทธิ์การดูข้อมูล</font></b>
					</td></tr>
				<tr> 
                    <td align="right"><b><font size="3" face="MS Sans Serif" color="#FFFFFF">read :</font></b></td>
                    <td align="left"> <input  type=checkbox  name="vperm_read"  onClick="check( this.form )" ><b><font size="3" face="MS Sans Serif" color="#FFFFFF">  สิทธิ์การเปิดอ่านเอกสาร</font></b>
					</td></tr>	
				<tr> 
                    <td align="right"><b><font size="3" face="MS Sans Serif" color="#FFFFFF">add :</font></b></td>
                    <td align="left"><input  type=checkbox  name="vperm_add"  onClick="check( this.form )" ><b><font size="3" face="MS Sans Serif" color="#FFFFFF">  สิทธิ์การบันทึกข้อมูล</font></b> 
                    </td></tr>
					<tr> 
                    <td align="right"><b><font size="3" face="MS Sans Serif" color="#FFFFFF">edit :</font></b></td>
                    <td align="left"><input  type=checkbox  name="vperm_edit"  onClick="check( this.form )" ><b><font size="3" face="MS Sans Serif" color="#FFFFFF">  สิทธิ์การแก้ไขข้อมูล</font></b>
					</td></tr>
				<tr> 
                    <td align="right"><b><font size="3" face="MS Sans Serif" color="#FFFFFF">delete :</font></b></td>
                    <td align="left"><input  type=checkbox  name="vperm_dele"  onClick="check( this.form )" ><b><font size="3" face="MS Sans Serif" color="#FFFFFF">  สิทธิ์การลบข้อมูล</font></b>
					</td></tr>	
				<tr> 
                    <td align="right"><b><font size="3" face="MS Sans Serif" color="#FFFFFF">comment :</font></b></td>
                    <td align="left"><input  type=checkbox  name="vcomment"  onClick="check( this.form )" ><b><font size="3" face="MS Sans Serif" color="#FFFFFF">  สิทธิ์การใช้ระบบรายงานโครงการ</font></b> 
                    </td></tr>
				<tr> 
                    <td align="right"><b><font size="3" face="MS Sans Serif" color="#FFFFFF">moderate :</font></b></td>
                    <td align="left"><input  type=checkbox  name="vmoderate"  onClick="check( this.form )" ><b><font size="3" face="MS Sans Serif" color="#FFFFFF">  สิทธิ์การใช้งานร่วมกับ admin</font></b>
                    </td></tr>
				<tr> 
                    <td align="right"><b><font size="3" face="MS Sans Serif" color="#FFFFFF">admin :</font></b></td>
                    <td align="left"><input  type=checkbox  name="vadmin"  onClick="check( this.form )" ><b><font size="2" face="MS Sans Serif" color="#66FF00">  สิทธิ์การใช้งานที่ต้องการความปลอดภัยสูงสุด ใน module นี้</font></b>
                    </td></tr>
               </table>
		</TD>
	 </table>
 <?
echo "<p align='center'>";
echo "<input type=\"submit\" name=\"submit\" id=\"submit\" onclick='goto_url_update(this.form)'  class=\"button\" value=\"บันทึก\">";
?>
<BR>
<Table width="80%" Border="0" borderColor="#005CB9"  Bgcolor="#FFFFFF" align="center">
<TR width="50%"  > <TD  valign="top" align="center"> 
<Table Border="1" borderColor=#990000  Bgcolor="#F8E874" Face="Ms Sans Serif" text="#FFFFFF"  align="center">
<?php
echo   "<Tr bgcolor='#FFEAFF'><Td     valign='center'  align='center' >ชื่อ - สกุล</td>";
echo   "<Td   width='8%'   valign='center'  align='center' >view</td>";
echo   "<Td   width='7%'   valign='center'  align='center' > read </td>";
echo   "<Td    width='7%'   valign='center'  align='center' > add </td>";
echo   "<Td    width='7%'   valign='center'  align='center' > edit </td>";
echo   "<Td    width='7%'   valign='center'  align='center' > delet </td>";
echo   "<Td   width='7%'    valign='center'  align='center' >comment</td>";
echo   "<Td   width='7%'    valign='center'  align='center' >moderate</td>";
echo   "<Td   width='7%'   valign='center'  align='center' >admin</td>";
echo   "<Td    width='7%'   valign='center'  align='center' >id_defalt</td>";
echo   "<Td  width='6'  ><IMG SRC='images/b_usredit.png' WIDTH='16' HEIGHT='16' BORDER=0 ALT=''></td></tr>";
$sql = "SELECT *  FROM  plan_permission";

$dbquery=DBfieldQuery($sql);
while ($result = mysql_fetch_array($dbquery))
	{
	$id_person =$result[id_person];
	$name_perm =$result[name_perm];
	$password_new = $result[password_new];
	$password_old =$result[password_old];
	$perm_view =$result[perm_view];
	$perm_read =$result[perm_read];
	$perm_add =$result[perm_add];
	$perm_edit =$result[perm_edit];
	$perm_dele =$result[perm_dele];
	$comment =$result[comment];
	$moderate =$result[moderate];
	$admin =$result[admin];
	$id_defalt =$result[id_defalt];
if($_SESSION['mpms_moderate']==1){
	echo   "<Tr bgcolor='#FFFFCC' ><Td align='center' ><FONT size='2' face='MS Sans Serif' color='#000099'>$name_perm</td>";
if($result[perm_view]==1)
	echo   "<Td align='center' ><img src=\"./images/yes.png\" WIDTH='16' HEIGHT='16' BORDER=0></td>";
else echo   "<Td>&nbsp;</td>";
if($result[perm_read]==1)
	echo   "<Td align='center' ><img src=\"./images/yes.png\" WIDTH='16' HEIGHT='16' BORDER=0></td>";
else echo   "<Td>&nbsp;</td>";		
if($result[perm_add]==1)
	echo   "<Td align='center' ><img src=\"./images/yes.png\" WIDTH='16' HEIGHT='16' BORDER=0></td>";
else echo   "<Td>&nbsp;</td>";	
if($result[perm_edit]==1)
	echo   "<Td align='center' ><img src=\"./images/yes.png\" WIDTH='16' HEIGHT='16' BORDER=0></td>";
else echo   "<Td>&nbsp;</td>";
if($result[perm_dele]==1)
	echo   "<Td align='center' ><img src=\"./images/yes.png\" WIDTH='16' HEIGHT='16' BORDER=0></td>";
else echo   "<Td>&nbsp;</td>";	
if($result[comment]==1)
	echo   "<Td align='center' ><img src=\"./images/yes.png\" WIDTH='16' HEIGHT='16' BORDER=0></td>";
else echo   "<Td>&nbsp;</td>";
if($result[moderate]==1)
	echo   "<Td align='center' ><img src=\"./images/yes.png\" WIDTH='16' HEIGHT='16' BORDER=0></td>";
else echo   "<Td>&nbsp;</td>";
if($result[admin]==1)
	echo   "<Td align='center' ><img src=\"./images/yes.png\" WIDTH='16' HEIGHT='16' BORDER=0></td>";
else echo   "<Td>&nbsp;</td>";
	echo   "<Td align='center' ><FONT size='2' face='MS Sans Serif' color='#000099'>$id_defalt</td>";
}
if($_SESSION['mpms_admin']==1)
{
	echo   "<Td><div align=center><a href=?option=plan&task=planproject/plan_deleuser&id_person=$id_person  target=  _top><img src=\"./images/b_drop.png\" WIDTH='16' HEIGHT='16' BORDER=0 ALT='ลบผู้ใช้งาน'></a></div></Td>";
}
	$i++;
	}
?>
</Table></TD></TR>
</FORM> <!--  <Form id='user_form' name='frm1'>  -->
</Table>
</Center>

<script language="JavaScript">
function openDir( mylist_form ) { 
	var newIndex = mylist_form.idperson.selectedIndex; 
			if(newIndex==0)
			 { // Don't display anything if first option is selected form.size.value = ""; 
			mylist_form.vid_person.value = ""; 
			 alert( "กรุณาเลือกชื่อสมาชิก!" ); 
			 return;
			 }
	mylist_form.vid_person.value = mylist_form.idperson.options[mylist_form.idperson.selectedIndex].value.split("|")[0];
	mylist_form.vname_perm.value =mylist_form.idperson.options[mylist_form.idperson.selectedIndex].value.split("|")[1];
	return ;
}
/*====================*/
function check(mylist_form)
{
	var newIndex = mylist_form.idperson.selectedIndex; 
			if(newIndex==0)
			 {
			 alert( "กรุณาเลือกชื่อสมาชิก!" ); 
			 return;
			 }
}
/*====================*/
function goto_url_update(mylist_form){
		var newIndex = mylist_form.idperson.selectedIndex; 
switch (newIndex)
	{
	case 0:
			 alert( "กรุณาเลือกชื่อสมาชิก!" ); 
			callfrm("?option=plan&task=planproject/plan_setuser"); 
			 break;
	default:
			callfrm("?option=plan&task=planproject/plan_adduser"); 
	}
	}
</script>
</body>
</html>
<!-- <Form id='user_form' name='frm1'> -->