|
|
|
ใครก็ได้ช่วยแก้ไขโค๊ดนี้หน่อยคราบ ลองมาหลายวันแล้วแก้ไม่ออกซักที |
|
|
|
|
|
|
|
การแสดงข้อมูล โดยเลือกสถานะมาแสดง และลบข้อมูล แก้ไขในหน้าเดียว
Code (PHP)
<?php
include("include/class.testlogin.php");
?>
<?php
$newup = $newdown = 0;
$newexpire = "0000-00-00";
if(isset($_REQUEST['action'])) {
$sql = "select * from login where login_ID = '".$_REQUEST['login_ID']."'";
$result = mysql_query($sql);
$group = mysql_fetch_object($result);
switch($_REQUEST['action']) {
case 'lock' :
$sql = "update account set status = '0' where username = '".$_REQUEST['user']."'";
mysql_query($sql);
$message = "<font color=green>ล็อกผู้ใช้ที่ต้องการเรียบร้อยแล้ว</font>";
break;
case 'unlock' :
$sql = "update login set status = '1' where username = '".$_REQUEST['user']."'";
mysql_query($sql);
$message = "<font color=green>ปลดล็อกผู้ใช้ที่ต้องการเรียบร้อยแล้ว</font>";
break;
case 'delete' :
$sql = "DELETE FROM radcheck where username = '".$_REQUEST['user']."'";
mysql_query($sql);
$sql = "DELETE FROM radusergroup where username = '".$_REQUEST['user']."'";
mysql_query($sql);
$sql = "DELETE FROM account where username = '".$_REQUEST['user']."'";
mysql_query($sql);
$sql = "update account set status = '-1' where username = '".$_REQUEST['user']."'";
mysql_query($sql);
$message = "<font color=green>ลบผู้ใช้ที่ต้องการออกเรียบร้อยแล้ว</font>";
break;
case 'move' :
$sql = "update radusergroup set groupname = '".$_REQUEST['group']."' where username = '".$_REQUEST['user']."'";
// echo $sql;
mysql_query($sql);
$message = "<font color=green>ย้ายกลุ่มเรียบร้อยแล้ว</font>";
break;
case 'edit' :
break;
case 'success' :
$message = "<font color=green>บันทึกข้อมูลการแก้ไขเรียบร้อยแล้ว</font>";
break;
case 'saveadd' :
$error = 0;
$newup = $_REQUEST['newgroupupload'];
$newdown = $_REQUEST['newgroupdownload'];
$newexpire = $_REQUEST['newgroupexpire'];
if(trim($_REQUEST['newgroupdesc']) == '') {
$error = 1;
$message = "<span class=\"alert\">กรุณากรอกชื่อกลุ่มด้วย</span>";
} else {
$sql = "select * from groups where gdesc = '".trim($_REQUEST['newgroupdesc'])."'";
if(mysql_num_rows(mysql_query($sql))) {
$message = "<span class=\"alert\">ชื่อกลุ่ม '".trim($_REQUEST['newgroupdesc'])."' ซ้ำ กรุณาเปลี่ยนชื่อกลุ่มใหม่</span>";
$error = 1;
} else {
if($newdown != 0) {
$down = $newdown * 1024;
$sql = "insert into radgroupreply values ('', 'group".$_REQUEST['newgname']."', 'WISPr-Bandwidth-Max-Down', ':=', '$down')";
mysql_query($sql);
}
if($newup != 0) {
$upload = $newup * 1024;
$sql = "insert into radgroupreply values ('', group'".$_REQUEST['newgname']."', 'WISPr-Bandwidth-Max-Up', ':=', '$upload')";
mysql_query($sql);
}
$sql = "insert into groups values('','group".$_REQUEST['newgname']."','".$_REQUEST['newgroupdesc']."', '$newup', '$newdown', '0', '$newexpire', 'md5', '0')";
// echo $sql;
mysql_query($sql);
$message = "<font color=green>บันทึกข้อมูลกลุ่มใหม่เรียบร้อยแล้ว</font>";
}
}
break;
}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<meta name="author" content="Burapha Linux Laboratory" />
<meta name="keywords" content="authentication system" />
<meta name="description" content="Burapha Linux Authentication Project" />
<link href="css/main.css" type=text/css rel=stylesheet>
<title>-:- Authent!cation -:-</title>
</head>
<body>
<div id="content">
<table width="95%" border="0" align="center" cellpadding="0" cellspacing="10" class="header">
<tr>
<td width="9%" align="center"><img src="images/User-Computer-icon.png" alt="" width="48" height="48" /></td>
<td width="47%"><a href="detail_emp.php?option=show_employee">User Data</a><br />
<span class="normal">ข้อมูลผู้ใช้งานระบบ</span></td>
<td width="44%" align="right" valign="bottom">
<? $sql = "select * from login where status != 'status' and status != 'status'";
$result = mysql_query($sql);
$num = mysql_num_rows($result);
?>
<span class="normal"><? if(!isset($_REQUEST['status'])) { ?>กรุณาเลือกกลุ่มผู้ใช้งานระบบ<? } else { ?>
<?
$sql = "select * from login where nametype= '".$_REQUEST['status']."'";
$result2 = mysql_query($sql);
$data2 = mysql_fetch_object($result2);
echo "กลุ่ม" . $data2->nametype . "";
?>
<? } ?>
</span><img src="images/b_ar.gif" align="absbottom" onClick="showhide(1);event.cancelBubble=1" style="cursor:hand" />
<div onmouseover="showhide(2);" onmouseout="showhide(0)" id="innermenu" style="position:absolute; width:260px; height:<?= $num * 25 ?>px;background-color:#FFFFCC; visibility:hidden; text-align:left; border: 1px #ddd dashed; padding: 10px 10px 10px 10px; font-weight: normal" class="normal">
<script language="JavaScript1.2">
function gl(linkname,dest){
document.write('<li><a href="'+dest+'">'+linkname+'</a></li>')
}
function showhide(state){
var cacheobj=document.getElementById("innermenu").style
if (state==0)
cacheobj.visibility="hidden"
else if(state==2)
cacheobj.visibility="visible"
else
cacheobj.visibility=cacheobj.visibility=="hidden"? "visible" : "hidden"
}
//Specify your links here- gl(Item text, Item URL)
<? while($groups = mysql_fetch_object($result)) { ?>
gl("กลุ่ม<?= $login->status ?>","detail_emp.php?option=show_employee&group=<?= $login->status ?>")
<? } ?>
//Extend this list as needed
document.onclick=function(){showhide(0)}
</script>
</div>
</td>
</tr>
</table>
<form action="" method="post" id="groupform" name="groupform">
<? if(isset($_REQUEST['action']) && ($_REQUEST['action'] == "edit" || $_REQUEST['action'] == "save" )) {
$message = "กรุณากรอกข้อมูลในช่องที่ท่านต้องการแก้ไขแล้วคลิกบันทึก<BR>";
$sql = "SELECT * FROM login where username = '".$_REQUEST['username']."'";
//echo $sql;
$link->query($sql);
$users = $link->getnext();
foreach($_REQUEST as $key => $value) {
$$key = $value;
//echo $key . " => " . $value . "<BR>";
}
if($_REQUEST['action'] == "save") {
$error = array();
for($i = 0; $i < 20; $i++) {
$error[$i] = false;
}
# check firstname
if(empty($firstname)) {
$error[0] = true;
}
# check lastname
if(empty($lastname)) {
$error[1] = true;
}
# check username
if(empty($username)) {
$error[2] = true;
}
if(!$error[2]) {
# check username duplicate
if($user != $username) {
$sql = "select * from login where username = '$username'";
// echo $sql;
$link->query($sql);
if($link->num_rows() > 0) {
$error[3] = true;
}
}
}
# check password
# check password and confirm password
if($password != $password2) {
$error[8] = true;
}
$pass = true;
for($i = 0; $i <= 8; $i++) {
if($error[$i]) {
$pass = false;
}
}
if($pass) {
if(!empty($password)) {
switch($users->encryption) {
case 'md5' : $newpass = substr(md5($password),0,15); break;
case 'crypt' : $newpass = substr(md5($password),0,15); break;
default : $newpass = substr(md5($password),0,15); break;
}
$sql = "update login set name = '$name', password = '$password', firstname = '$firstname', lastname = '$lastname', where username = '$username->username'";
mysql_query($sql);
//$sql = "update radcheck set username = '$username', value = '$newpass' where username = '$users->username' AND attribute = 'Password'";
//mysql_query($sql);
} else {
//$sql = "update account set username = '$username', firstname = '$firstname', lastname = '$lastname' where username = '$users->username'";
//mysql_query($sql);
//$sql = "update radcheck set username = '$username' where username = '$users->username'";
//mysql_query($sql);
}
//$sql = "update radusergroup set username = '$username' where username = '$users->username'";
//mysql_query($sql);
//$sql = "update radacct set username = '$username' where username = '$users->username'";
//mysql_query($sql);
echo "<script>window.location='detail_emp.php?option=show_employee&action=success&group=".$_REQUEST['group']."';</script>";
}
} else {
$firstname = $users->firstname;
$lastname = $users->lastname;
$username = $users->username;
}
?>
<table width="98%" border="0" cellspacing="5" cellpadding="0">
<tr>
<td colspan="2" align="center"><?php
if(!empty($message)) { echo "<BR>".$message; }
?> </td>
</tr>
<? if($error[0]) { ?>
<tr>
<td width="32%" align="right"> </td>
<td width="68%" class="red">กรุณากรอกชื่อของคุณด้วยครับ</td>
</tr>
<? } ?>
<tr>
<td width="32%" align="right">ชื่อ : </td>
<td width="68%"><label>
<input name="firstname" type="text" class="inputbox-normal" id="firstname" style="background: <? if($error[0]) echo "#FFF0F0"; ?>" value="<?= $firstname ?>">
<span class="red">*
<input name="action" type="hidden" id="action" value="save" />
</span></label></td>
</tr>
<? if($error[1]) { ?>
<tr>
<td align="right"> </td>
<td class="red">กรุณากรอกนามสกุลของคุณด้วยครับ</td>
</tr>
<? } ?>
<tr>
<td align="right">นามสกุล : </td>
<td><label>
<input name="lastname" type="text" class="inputbox-normal" id="lastname" style="background: <? if($error[1]) echo "#FFF0F0"; ?>" value="<?= $lastname ?>">
<span class="red">*</span></label></td>
</tr>
<? if($error[2]) { ?>
<tr>
<td align="right"> </td>
<td class="red">กรุณากรอกชื่อผู้ใช้ที่คุณต้องการด้วยครับ</td>
</tr>
<? } ?>
<? if($error[3]) { ?>
<tr>
<td align="right"> </td>
<td class="red">ชื่อผู้ใช้ที่คุณต้องการมีผู้อื่นใช้แล้ว กรุณากรอกใหม่ด้วยครับ</td>
</tr>
<? } ?>
<tr>
<td align="right">ชื่อผู้ใช้ : </td>
<td><label>
<input name="username" type="text" class="inputbox-normal" id="username" style="background: <? if($error[2] || $error[3]) echo "#FFF0F0"; ?>" value="<?= $username ?>">
<span class="red">*</span></label></td>
</tr>
<tr>
<td align="right"> </td>
<td><span class="comment">กรอกเป็นตัวอักษรภาษาอังกฤษและตัวเลขเท่านั้น</span></td>
</tr>
<? if($error[4]) { ?>
<tr>
<td align="right"> </td>
<td class="red">กรุณากรอกรหัสผ่านด้วยครับ</td>
</tr>
<? } ?>
<? if($error[5]) { ?>
<tr>
<td align="right"> </td>
<td class="red">ความยาวของรหัสผ่านต้องยาวอย่างน้อย 8 อักขระครับ</td>
</tr>
<? } ?>
<tr>
<td align="right">รหัสผ่าน : </td>
<td><label>
<input name="password" type="password" class="inputbox-normal" id="password" style="background: <? if($error[4] || $error[5] || $error[8]) echo "#FFF0F0"; ?>" value="<?= $password ?>">
<span class="red">*</span></label></td>
</tr>
<tr>
<td align="right"> </td>
<td class="comment">ความยาวอย่างน้อย 8 อักขระ</td>
</tr>
<? if($error[6]) { ?>
<tr>
<td align="right"> </td>
<td class="red">กรุณายืนยันรหัสผ่านด้วยครับ</td>
</tr>
<? } ?>
<? if($error[7]) { ?>
<tr>
<td align="right"> </td>
<td class="red">ความยาวของรหัสผ่านต้องยาวอย่างน้อย 8 อักขระครับ</td>
</tr>
<? } ?>
<? if($error[8]) { ?>
<tr>
<td align="right"> </td>
<td class="red">รหัสผ่านทั้งสองไม่ตรงกัน</td>
</tr>
<? } ?>
<tr>
<td align="right">ยืนยันรหัสผ่าน : </td>
<td><label>
<input name="password2" type="password" class="inputbox-normal" id="password2" style="background: <? if($error[6] || $error[7] || $error[8]) echo "#FFF0F0"; ?>" value="<?= $password2 ?>">
<span class="red">*</span> </label></td>
</tr>
<tr>
<td align="right"> </td>
<td><label>
<input type="submit" name="button" id="button" class="button" value="บันทึก">
<input type="button" name="button2" id="button2" class="button" value="ยกเลิก" onclick="window.location='detail_emp.php?option=show_login&group=<?= $_REQUEST['group'] ?>'" />
</label></td>
</tr>
<tr>
<td align="right"> </td>
<td> </td>
</tr>
</table>
<? } else { ?>
<table width="98%" align="center" cellspacing="1" class="admintable">
<tr>
<td height="35" colspan="3" align="left"><? if(isset($_REQUEST['group'])) { ?>
จำนวนสมาชิกในกลุ่ม
<?= $data2->gdesc ?>
มีทั้งสิ้น <b class="red">
<? $sql = "select * from login where status = '".$_REQUEST['group']."'";
echo mysql_num_rows(mysql_query($sql)); ?>
</b> คน
<? } ?></td>
<td height="35" colspan="3" align="right"><?php
if(isset($message)) { ?>
<?= $message ?>
<? }
?></td>
</tr>
<tr>
<td width="55" align="center" class="key">ลำดับ</td>
<td width="212" align="center" class="key">ชื่อ</td><br />
<td width="212" align="center" class="key">นามสกุล</td>
<td width="90" align="center" class="key">ชื่อผู้ใช้</td>
<td width="99" align="center" class="key">รหัสผ่าน</td>
<td width="94" align="center" class="key">ดำเนินการ</td>
</tr>
<?php
$count = 0;
$sql = "select * from login where login.status = '".$_REQUEST['group']."' and login.username = login.username and login.status != '-1' order by logint.status";
//echo $sql;
$result = mysql_query($sql);
while($users = mysql_fetch_object($result)) {
$count++;
($count % 2 != 0) ? $bgcolor = "#E6F2FF" : $bgcolor = "#D7EBFF";
?>
<tr>
<td width="55" align="center" valign="top" bgcolor="<?= $bgcolor ?>"><?= $count ?></td>
<td width="212" align="left" valign="top" bgcolor="<?= $bgcolor ?>">
<?= $name->firstname ?></td>
<td align="left" valign="top" bgcolor="<?= $bgcolor ?>">
<?= $surname->lastname ?></td>
<td align="center" valign="top" bgcolor="<?= $bgcolor ?>"><?= $username->username ?> <?= substr($username->dateregis,0,10) ?>
</td>
<td width="76" align="center" valign="top" bgcolor="<?= $bgcolor ?>"><? if($password->password) { ?>
<? } else { ?>
<? } ?></td>
<td width="94" align="center" valign="top" bgcolor="<?= $bgcolor ?>"><a href="index2.php?option=manage_user&group=<?= $_REQUEST['group'] ?>&user=<?=$users->username?>&action=edit"><img src="images/configure.png" alt="แก้ไข" /></a> <a href="index2.php?option=manage_user&group=<?= $_REQUEST['group'] ?>&user=<?=$users->username?>&action=delete"><img src="images/delete.png" alt="ลบ" /></a>
<? $sql = "select * from login where status != 'status' and status != 'status'";
$result2 = mysql_query($sql);
$num = mysql_num_rows($result2);
?>
<img src="images/go.png" alt="ย้ายกลุ่ม" onclick="showhide<?= $users->username?>(1);event.cancelBubble=1" style="cursor:hand" />
<div onmouseover="showhide<?= $users->username?>(2);" onmouseout="showhide<?= $users->username?>(0)" id="innermenu<?= $users->username?>" style="position:absolute; width:260px; height:<?= $num * 25 ?>px;background-color:#FFFFCC; visibility:hidden; text-align:left; border: 1px #ddd dashed; padding: 10px 10px 10px 10px; line-height:25px; font-weight: normal" class="normal">
<script language="JavaScript1.2">
function gl<?= $users->username?>(linkname,dest){
document.write('<li><a href="'+dest+'">'+linkname+'</a></li>')
}
function showhide<?= $users->username?>(state){
var cacheobj=document.getElementById("innermenu<?= $users->username?>").style
if (state==0)
cacheobj.visibility="hidden"
else if(state==2)
cacheobj.visibility="visible"
else
cacheobj.visibility=cacheobj.visibility=="hidden"? "visible" : "hidden"
}
//Specify your links here- gl(Item text, Item URL)
<? while($groups = mysql_fetch_object($result2)) { ?>
gl<?= $users->username?>("ย้ายไปกลุ่ม<?= $groups->gdesc ?>","index2.php?option=manage_user&action=move&user=<?= $users->username?>&group=<?= $groups->gname ?>")
<? } ?>
//Extend this list as needed
document.onclick=function(){showhide<?= $user->username?>(0)}
</script>
</div></td>
</tr>
<? } ($count % 2 == 0) ? $bgcolor = "#E6F2FF" : $bgcolor = "#D7EBFF";
?>
</table>
<? } ?>
</form>
</div>
</body>
</html>
Tag : PHP, MySQL
|
|
|
|
|
|
Date :
2012-08-10 10:47:02 |
By :
กุ้ง |
View :
1090 |
Reply :
2 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ติดปัญหาตรงไหนอ่าค่ะ
|
|
|
|
|
Date :
2012-08-10 13:29:28 |
By :
LuckyStar |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ผมก็นั่งดูหลายทีแระ ติดตรงไหนล่ะคับ เอา error มาดูหน่อย
|
|
|
|
|
Date :
2012-08-10 14:37:11 |
By :
ichiko |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 04
|