|
Server : Apache/2.2.2 (Fedora) System : Linux App1.pathumtani.go.th 2.6.20-1.2320.fc5smp #1 SMP Tue Jun 12 19:40:16 EDT 2007 i686 User : apache ( 48) PHP Version : 5.2.9 Disable Function : NONE Directory : /var/www/html/pathumthani_eoffice/application/system/user/bin/ |
Upload File : |
<?
/*****************************************************************************
Function : แก้ไขข้อมูลของ epm_staffgroup
Version : 1.0
Last Modified : 16/8/2548
Changes :
*****************************************************************************/
$type=$_GET[type];
include "epm.inc.php";
$report_title = "กลุ่มบุคลากร";
$msg = "";
if ($_SERVER[REQUEST_METHOD] == "POST"){
$type=$_POST[type];
/*
// remove slashes from variable
foreach ($_POST as $key => $value){
if (!is_array($value) && !is_numeric($value)){
$_POST[$key] = stripslashes($value);
}
}
*/
if ($groupname == ""){
$msg = "กรุณาระบุชื่อของกลุ่มบุคลากร";
}else{
$sql_check_ref="select * from $table_staffgroup where refid_info LIKE '%$refid_info%' AND $table_staffgroup.gid !='$id' ";
$rs_c=mysql_query($sql_check_ref);
$row_c=mysql_num_rows($rs_c);
if($row_c){ echo "<br> <b>เลขส่วนหน้าที่ระบุไม่สามารถบันทึกได้ เนื่องจากมีการใช้งานโดย หน่วยงาน/กลุ่มภารกิจ อื่น</b>";}else{
if ($action == "new" || $action == "addsubgroup"){
if($type=="profile"){
$sql = "insert into $table_staffgroup ( org_id,groupname,comment,owner_id,parent,staffid) values ('$org_id','$groupname','$comment','$owner_id','$parent','$session_staffid');";
}elseif($type=="system"){
$sql = "insert into $table_staffgroup ( org_id,groupname,comment,owner_id,parent,refid_info) values ('$org_id','$groupname','$comment','$owner_id','$parent','$refid_info');";
}
}else if ($action == "edit"){
$sql = "update $table_staffgroup set groupname='$groupname',comment='$comment',org_id='$org_id',owner_id='$owner_id',refid_info='$refid_info' where gid = '$id'; ";
}else{
header("Location : ?org_id=$org_id&type=$type");
exit;
}
@mysql_query($sql);
if (mysql_errno() != 0){
$msg = "ไม่สามารถบันทึกลงฐานข้อมูลได้<BR>$sql<BR><BR>" . mysql_error() ;
}else{
// SUCCESS
if ($action == "new" || $action == "addsubgroup"){
$id = mysql_insert_id();
}
//จัดการ บุคลากรในกลุ่ม
mysql_query("delete from $table_groupmember where gid='$id';"); //ลบ
if ($_POST[member]){
foreach ($_POST[member] as $n => $staffid ){
mysql_query("insert into $table_groupmember (gid,staffid) values('$id','$staffid');"); //เพิ่มอันที่เลือก
}
}
//จัดการ สถานะกลุ่ม
mysql_query("delete from profile_permission where gid='$id';"); //ลบ
if ($_POST[permit]){
foreach ($_POST[permit] as $n => $pid ){
if(($n=="radio")&&($pid)) {$n="$pid";}
mysql_query("insert into profile_permission (gid,pid) values('$id','$n');"); //เพิ่มอันที่เลือก
}
}
echo "<script>alert('บันทึกข้อมูลเรียบร้อยแล้ว'); if (parent.leftFrame) {parent.leftFrame.location=parent.leftFrame.location;} location.href='?org_id=$org_id&type=$type';</script>";
// header("Location: ?org_id=$org_id");
exit;
}
}
}
$action = "";
}else if ($action == "delete" && $id > ""){
if (Query1("select count(*) from $table_staffgroup where parent='$id';") > 0){
echo "<script>alert('ไม่สามารถลบข้อมูลได้ เพราะยังมีกลุ่มย่อยภายใต้กลุ่มนี้อยู่'); location.href='?org_id=$org_id&type=$type';</script>";
exit;
}
if (Query1("select count(*) from $table_groupmember where gid='$id';") > 0){
echo "<script>alert('ไม่สามารถลบข้อมูลได้ เพราะยังมี ผู้ใช้ที่สังกัดกลุ่มนี้อยู่'); location.href='?org_id=$org_id&type=$type';</script>";
exit;
}
$gname = Query1("select groupname from $table_staffgroup where gid='$id' order by trim($table_staffgroup.groupname) ASC ; ");
if ($gname != "Guest" && $gname != "Administrator") { //ห้ามลบ Gues และ Administrator
@mysql_query("delete from $table_staffgroup where gid='$id';");
if (mysql_errno() > 0){
$msg = "ไม่สามารถลบข้อมูลได้";
}else{
echo "<script>alert('ลบข้อมูลเรียบร้อยแล้ว'); if (parent.leftFrame) {parent.leftFrame.location=parent.leftFrame.location;} location.href='?org_id=$org_id&type=$type';</script>";
}
}
$action = "";
}
?>
<HTML>
<HEAD>
<TITLE><?=$report_title?></TITLE>
<META http-equiv="Content-Type" content="text/html; charset=windows-874">
<LINK href="../../../common/style.css" rel=StyleSheet type="text/css">
<SCRIPT language=JavaScript>
function checkFields() {
missinginfo1 = "";
missinginfo = "";
if (document.form1.groupname.value == "") { missinginfo1 += "\n- ช่องชื่อกลุ่มบุคลากรไม่สามารถเป็นค่าว่าง"; }
if (missinginfo1 != "") {
missinginfo += "ไม่สามารถเพิ่มข้อมูลได้ เนื่องจาก \n";
missinginfo +="_____________________________\n";
missinginfo = missinginfo + missinginfo1 ;
missinginfo += "\n___________________________";
missinginfo += "\nกรุณาตรวจสอบ อีกครั้ง";
alert(missinginfo);
return false;
}
}
var checkflag = "false";
function check(field) {
if (checkflag == "false") {
for (i = 0; i < field.length; i++) {
field[i].checked = true;
}
checkflag = "true";
return "ไม่เลือกทั้งหมด";
} else {
for (i = 0; i < field.length; i++) {
field[i].checked = false;
}
checkflag = "false";
return "เลือกทั้งหมด";
}
}
function checkAll(field,x) {
for (i = 0; i < field.length; i++) {
field[i].checked = x;
}
}
</SCRIPT>
</HEAD>
<BODY bgcolor="#FFFFFF">
<BR>
<?
if ($_GET[action] == "edit" || $_GET[action] == "new" || $_GET[action] == "addsubgroup" ){
if ($_GET[action] == "edit"){
$sql = "select * from $table_staffgroup where gid='$id' ";
$result = mysql_query($sql);
$rs = mysql_fetch_assoc($result);
$title="แก้ไข";
if ($rs[groupname] == "Guest" || $rs[groupname] == "Administrator"){
$systemgroup = " onfocus='blur();' stylle='background: #8090A0;' "; // Lock
}else{
$systemgroup = "";
}
}else if ($_GET[action] == "addsubgroup"){
$title = "เพิ่ม";
$report_title = "กลุ่มย่อยในกลุ่ม " . Query1("select groupname from $table_staffgroup where gid='$parent' ;");
}else{
$rs = array();
$title = "เพิ่ม";
}
?>
<FORM action="" method="POST" NAME="form1" ONSUBMIT="checkFields();">
<INPUT TYPE="hidden" NAME="id" VALUE="<?=$id?>" >
<INPUT TYPE="hidden" NAME="parent" VALUE="<?=$parent?>" >
<INPUT TYPE="hidden" NAME="org_id" VALUE="<?=$org_id?>" >
<INPUT TYPE="hidden" NAME="action" VALUE="<?=$action?>" >
<INPUT TYPE="hidden" NAME="type" VALUE="<?=$type?>" >
<TABLE border=0 align=center cellspacing=1 cellpadding=3 bgcolor="#808080" width="98%">
<TR bgcolor="#A3B2CC">
<TD colspan=2> <FONT COLOR="WHITE" style="font-size:14pt;"><B><?=$title?>ข้อมูล<?=$report_title?></B></FONT></TD>
</TR>
<TR bgcolor=white valign=top>
<TD class="link_back">ชื่อกลุ่ม</TD>
<TD>
<INPUT TYPE="text" NAME="groupname" VALUE="<?=$rs[groupname]?>" size="80" maxlength=200 class=inputbox <?=$systemgroup?>> </TD>
</TR>
<? if($type=="system"){ ?>
<TR bgcolor=white valign=top>
<TD class="link_back">สิทธิ์</TD>
<TD>
<?
$sql_check="select * from profile_permission where gid='$id' ";
$result_check = mysql_query($sql_check);
while($crs = mysql_fetch_assoc($result_check)){
$check_status[$crs[pid]]="on";
}
$sql_status="select * from permission_status";
$result = mysql_query($sql_status);$radio_check=0;
while($rse = mysql_fetch_assoc($result)) {
if(!$rse[type]){
?>
<INPUT type="checkbox" name="permit[<?=$rse[pid]?>]" value="on" <? if($check_status[$rse[pid]]=="on"){echo "checked";}?>><?=$rse[status]?><BR>
<?
}else if($rse[type]=="radio"){ if($radio_check==0){echo "<hr>"; $radio_check++;}
?><INPUT type="radio" name="permit[radio]" value="<?=$rse[pid]?>" <? if($check_status[$rs[pid]]=="on"){echo "checked";}?>><?=$rse[status]?><?
}
}
?> </TD>
</TR>
<?}?>
<!--<TR bgcolor=white valign=top>
<TD class="link_back">หัวหน้า/ผู้รับผิดชอบ</TD>
<TD>
<SELECT name="owner_id">
<OPTION value="0"> - ไม่ระบุ -</OPTION>
<?
$sql = "select * from $table_staff where org_id='$org_id';";
$xresult = mysql_query($sql);
while ($xrs=mysql_fetch_assoc($xresult)){
if ($xrs[staffid] == $rs[owner_id]) $sel = "SELECTED"; else $sel="";
echo "<option value='$xrs[staffid]' $sel> $xrs[staffname] $xrs[staffsurname] </option>";
}
?>
</SELECT> </TD>
</TR>-->
<TR bgcolor=white valign=top>
<TD class="link_back"><STRONG>รหัสหน่วยงาน</STRONG></TD>
<TD><TABLE width="96%" border="0" cellspacing="0" cellpadding="0">
<TR>
<TD width="26%" align="center" valign="middle"><INPUT name="refid_info" type="text" id="refid_info"style="width:90px;" value="<?=$rs[refid_info]?>" /></TD>
<TD width="1%" align="left" valign="top"> </TD>
<TD width="74%" align="left" valign="middle">รหัสประจำหน่วยงาน คือ รหัสที่หน่วยงานลงทะเบียนไว้กับสารบรรณกลางของสำนักงานจังหวัด ที่ขึ้นต้นด้วย ลป เว้นวรรค และตามด้วยเลขรหัสประจำหน่วยงาน เช่นสำนักงานจังหวัดได้แก่ "ลป 0016"</TD>
</TR>
</TABLE></TD>
</TR>
<TR bgcolor=white valign=top>
<TD class="link_back">หมายเหตุ</TD>
<TD><TEXTAREA NAME="comment" ROWS="8" COLS="80"><?=$rs[comment]?></TEXTAREA></TD>
</TR>
<TR bgcolor="#DDDDEE" valign=top>
<TD class="link_back" colspan=2>บุคลากรในกลุ่ม</TD>
</TR>
<TR bgcolor="white" valign=top>
<TD colspan=2>
<INPUT TYPE="checkbox" NAME="chk" ONCLICK="checkAll(this.form.list,this.checked)"> เลือก / ไม่เลือก ทั้งหมด
<HR><BR>
<?
$sql = "select * from $table_staff where username <> 'admin_$org_id' and username <> 'root'; ";
$xresult = mysql_query($sql);
while ($xrs=mysql_fetch_assoc($xresult)){
if (Query1("select count(*) from $table_groupmember where gid='$id' and staffid='$xrs[staffid]';") > 0) {
$chk="CHECKED";
}/*else if (Query1("select count(*) from $table_groupmember t1 inner join $table_staffgroup t2 on t1.gid=t2.gid where t1.gid<>'$id' and t1.staffid='$xrs[staffid]' and t2.$table_groupmember not in ('Guest','Administrator');") > 0) {
//ตรวจสอบว่าอยู่กลุ่มอื่นแล้วหรือยัง
continue; //ไม่เอามาแสดง
}*/else {
$chk="";
}
if ($xrs[sex] == "M") $sex = "man"; else $sex="girl";
// if($db_mode=="epm"){ $disabled=" disabled ";}
echo " <INPUT TYPE='checkbox' NAME='member[]' id='list' VALUE='$xrs[staffid]' $chk $disabled> <img src='images/$sex.gif'> $xrs[staffname] $xrs[staffsurname] <BR>";
}
?> </TD>
</TR>
<TR bgcolor="#888899" valign=top>
<TD colspan=2 align=right>
<INPUT TYPE="submit" VALUE=" บันทึก " CLASS=xbutton>
<INPUT TYPE="reset" VALUE=" ยกเลิก " class=xbutton ONCLICK="location.href='?org_id=<?=$org_id?>';"> </TD>
</TR>
</TABLE>
</FORM>
<?
//====================================================================
}else if ($_GET[action] == "show" ){
$sql = "select * from $table_staffgroup where gid='$id';";
$result = mysql_query($sql);
$rs = mysql_fetch_assoc($result);
?>
<TABLE border=0 align=center cellspacing=1 cellpadding=3 bgcolor="#808080" width="98%">
<TR bgcolor="#A3B2CC">
<TD > <FONT COLOR="WHITE" style="font-size:14pt;"><IMG src="images/users.gif" align=middle> <B>ข้อมูล<?=$report_title?></B></FONT></TD>
<TD align=right>
<? // if(($id==$id_check ) || ($db_mode=="self")){ ?>
<INPUT TYPE="reset" VALUE=" แก้ไข " class=xbutton ONCLICK="location.href='?org_id=<?=$org_id?>&id=<?=$id?>&action=edit&type=<?=$type?>';">
<? // } ?> </TD>
</TR>
<TR bgcolor=white valign=top>
<TD class="link_back" width="150">ชื่อกลุ่ม</TD>
<TD><?=$rs[groupname]?></TD>
</TR>
<? if($type=="system"){ ?>
<TR bgcolor=white valign=top>
<TD class="link_back">สิทธิ์</TD>
<TD><LABEL></LABEL>
<?
$sql_check="select * from profile_permission where gid='$id' ";
$result_check = mysql_query($sql_check);
while($crs = mysql_fetch_assoc($result_check)){
$check_status[$crs[pid]]="on";
}
$sql_status="select * from permission_status";
$result = mysql_query($sql_status);
while($rse = mysql_fetch_assoc($result)) {
?>
<? if($check_status[$rse[pid]]=="on"){?><?=$rse[status]?><BR><?}?>
<?
}
?> </TD>
</TR>
<?}?>
<!--<TR bgcolor=white valign=top>
<TD class="link_back">หัวหน้า/ผู้รับผิดชอบ</TD>
<TD>
<?
$sql = "select * from $table_staff where org_id='$org_id' and staffid='$rs[owner_id]';";
$xresult = mysql_query($sql);
$xrs=mysql_fetch_assoc($xresult);
if ($xrs){
echo " $xrs[prename] $xrs[staffname] $xrs[staffsurname] ";
}else{
echo " - ไม่ระบุ -";
}
?> </TD>
</TR>-->
<TR bgcolor=white valign=top>
<TD class="link_back"><STRONG>รหัสหน่วยงาน</STRONG></TD>
<TD>
<TABLE width="96%" border="0" cellspacing="0" cellpadding="0">
<TR>
<TD width="26%" align="center" valign="middle"><?=$rs[refid_info]?></TD>
<TD width="1%" align="left" valign="top"> </TD>
<TD width="74%" align="left" valign="middle">รหัสประจำหน่วยงาน คือ รหัสที่หน่วยงานลงทะเบียนไว้กับสารบรรณกลางของสำนักงานจังหวัด ที่ขึ้นต้นด้วย ลป เว้นวรรค และตามด้วยเลขรหัสประจำหน่วยงาน เช่นสำนักงานจังหวัดได้แก่ "ลป 0016"</TD>
</TR>
</TABLE></TD>
</TR>
<TR bgcolor=white valign=top>
<TD class="link_back">หมายเหตุ</TD>
<TD><?=nl2br($rs[comment])?></TD>
</TR>
<TR bgcolor="#DDDDEE">
<TD class="link_back"><IMG src="dtree/img/users.gif" align=middle> กลุ่มย่อย</TD>
<TD align=right>
<? if($db_mode=="self"){ ?>
<INPUT TYPE="reset" VALUE=" เพิ่มกลุ่มย่อย " class=xbutton ONCLICK="location.href='?org_id=<?=$org_id?>&parent=<?=$id?>&action=addsubgroup&type=<?=$type?>';">
<? } ?> </TD>
</TR>
<TR bgcolor="white" valign=top>
<TD colspan=2>
<?
$n=0;
$sql = "select * from $table_staffgroup where parent='$id';";
$xresult = mysql_query($sql);
while ($xrs=mysql_fetch_assoc($xresult)){
$n++;
echo " <img src='dtree/img/users.gif' align=middle> $xrs[groupname]<BR>";
}
if ($n == 0) echo "- ไม่มีกลุ่มย่อย -<BR><BR>";
?> </TD>
</TR>
<TR bgcolor="#DDDDEE">
<TD class="link_back" colspan=2><IMG src="images/man.gif" align=middle> บุคลากรในกลุ่ม</TD>
</TR>
<TR bgcolor="white" valign=top>
<TD colspan=2>
<?
$n=0;
$sql = "select t2.* from $table_groupmember t1 inner join $table_staff t2 on t1.staffid=t2.staffid where t1.gid='$id' order by trim(t2.staffname) ;";
$xresult = mysql_query($sql);
while ($xrs=mysql_fetch_assoc($xresult)){
$n++;
if ($xrs[sex] == "M") $sex = "man"; else $sex="girl";
echo " <img src='images/$sex.gif' align=middle> $xrs[prename] $xrs[staffname] $xrs[staffsurname]<BR>";
}
if ($n == 0) echo "- ไม่มีบุคลากรในกลุ่มนี้ -<BR><BR>";
?> </TD>
</TR>
</TABLE>
<?
}else{
//====================================================================
?>
<TABLE border=0 align=center cellspacing=1 cellpadding=2 width="98%">
<TR><TD width=35><IMG src="images/group_icon.gif"></TD>
<TD> <B style="font-size: 12pt;">กลุ่มบุคลากรในหน่วยงาน <?=Query1("select NLABEL from $table_mainmenu where NID='$org_id';")?></B>
</TD></TR>
<TR valign=top height=1 bgcolor="#808080"><TD colspan=2></TD></TR>
<TR valign=top><TD colspan=2>
<BR><BR>
<? if($db_mode=="self"){ ?>
<IMG src="images/profile_collapsed.gif"> <A HREF="?action=new&org_id=<?=$org_id?>&type=<?=$type?>">เพิ่มข้อมูลใหม่</A>
<? } ?>
</TD>
</TR>
</TABLE>
<TABLE border=0 align=center cellspacing=1 cellpadding=2 bgcolor=black width="98%" class="sortable" id="unique_id">
<TR bgcolor="#A3B2CC">
<TH width=80>ลำดับ</TH>
<TH>ชื่อกลุ่ม</TH>
<? if($db_mode=="self"){ ?>
<TH width=80> </TH>
<? } ?>
</TR>
<?
$n = 0;
if($type=="profile"){
$sql = "select * from $table_staffgroup where org_id='$org_id' AND $table_staffgroup.staffid='$session_staffid' order by trim($table_staffgroup.groupname) ASC ;";
}elseif($type=="system"){
$sql = "select * from $table_staffgroup where org_id='$org_id' order by trim($table_staffgroup.groupname) ASC ;";
}
$result = mysql_query($sql);
while ($rs=mysql_fetch_assoc($result)){
if ($n++ % 2){
$bgcolor = "#F0F0F0";
}else{
$bgcolor = "#FFFFFF";
}
?>
<TR valign=top bgcolor="<?=$bgcolor?>">
<TD align=center ><?=$n?></TD>
<TD ><?=$rs[groupname]?></TD>
<? if($db_mode=="self"){ ?>
<TD align=center>
<?/*
if ($rs[gid] != 1){ // สงวนไว้ ไม่ได้แก้ ข้อมูลกลุ่มทั่วไป
if ($rs[groupname] == "Guest" || $rs[groupname] == "Administrator"){
echo "<I>System Group</I>";
}else{*/
?>
<A href="?action=edit&id=<?=$rs['gid']?>&org_id=<?=$org_id?>&type=<?=$type?>&type=<?=$type?>"><IMG src="../../../images/b_edit.png" alt="แก้ไข" width="16" height="16" border="0"></A>
<A href="#" ONCLICK="if (confirm('ต้องการลบข้อมูลนี้ใช่หรือไม่?')) location.href='?action=delete&id=<?=$rs['gid']?>&org_id=<?=$org_id?>&type=<?=$type?>';">
<IMG src="../../../images/b_drop.png" alt="ลบข้อมูล" width="16" height="16" border="0"></A>
<?
//} // if guest || admin
//} // if
?>
</TD>
<? } ?>
</TR>
<?
}// while
?>
</TABLE>
<?
}
?>
<BR><BR>
</BODY>
</HTML>