|
|
|
ไม่ให้ admin ลบตัวเองได้ แต่ลบคนอื่นได้ ช่วยแนะนำด้วยครับ(มือใหม่) |
|
|
|
|
|
|
|
อยากให้แอดมินที่เข้าใช้ระบบ ลบ User หรือ Employee ได้ **
และให้แอดมินลบตัวเองไม่ได้ครับ
#อันนี้โค้ดครับ ผมใช้ Dream //
Code (PHP)
<?php require_once('../Connections/ConnectSW.php'); ?>
<?php
if (!isset($_SESSION)) {
session_start();
}
$MM_authorizedUsers = "admin";
$MM_donotCheckaccess = "false";
// *** Restrict Access To Page: Grant or deny access to this page
function isAuthorized($strUsers, $strGroups, $UserName, $UserGroup) {
// For security, start by assuming the visitor is NOT authorized.
$isValid = False;
// When a visitor has logged into this site, the Session variable MM_Username set equal to their username.
// Therefore, we know that a user is NOT logged in if that Session variable is blank.
if (!empty($UserName)) {
// Besides being logged in, you may restrict access to only certain users based on an ID established when they login.
// Parse the strings into arrays.
$arrUsers = Explode(",", $strUsers);
$arrGroups = Explode(",", $strGroups);
if (in_array($UserName, $arrUsers)) {
$isValid = true;
}
// Or, you may restrict access to only certain users based on their username.
if (in_array($UserGroup, $arrGroups)) {
$isValid = true;
}
if (($strUsers == "") && false) {
$isValid = true;
}
}
return $isValid;
}
$MM_restrictGoTo = "indexsrisawat.dwt.php";
if (!((isset($_SESSION['MM_Username'])) && (isAuthorized("",$MM_authorizedUsers, $_SESSION['MM_Username'], $_SESSION['MM_UserGroup'])))) {
$MM_qsChar = "?";
$MM_referrer = $_SERVER['PHP_SELF'];
if (strpos($MM_restrictGoTo, "?")) $MM_qsChar = "&";
if (isset($_SERVER['QUERY_STRING']) && strlen($_SERVER['QUERY_STRING']) > 0)
$MM_referrer .= "?" . $_SERVER['QUERY_STRING'];
$MM_restrictGoTo = $MM_restrictGoTo. $MM_qsChar . "accesscheck=" . urlencode($MM_referrer);
header("Location: ". $MM_restrictGoTo);
exit;
}
?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
if (PHP_VERSION < 6) {
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
}
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}
mysql_select_db($database_ConnectSW, $ConnectSW);
$query_accessRecord = "SELECT * FROM accessibility";
$accessRecord = mysql_query($query_accessRecord, $ConnectSW) or die(mysql_error());
$row_accessRecord = mysql_fetch_assoc($accessRecord);
$totalRows_accessRecord = mysql_num_rows($accessRecord);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script language="JavaScript">
function chkdel(){if(confirm(' กรุณายืนยันการลบอีกครั้ง !!! ')){
return true;
}else{
return false;
}
}
</script>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!-- TemplateBeginEditable name="doctitle" -->
<title>Untitled Document</title>
<!-- TemplateEndEditable -->
<!-- TemplateBeginEditable name="head" -->
<!-- TemplateEndEditable -->
<style type="text/css">
@import url("../buttons1.css");
body {
margin-left: 0px;
margin-top: 0px;
margin-right: 0px;
margin-bottom: 0px;
color: #000;
}
.dddd {
color: #FFF;
font-weight: bold;
font-size: 24px;
}
.sss {
color: #000;
}
.over {
background-color: #69F;
}
</style>
<STYLE type=text/css>
.link_12_dark_blue:link {
font-family: MS Sans Serif, Tahoma, sans-serif;
font-size: 15px;
text-decoration: none;
color:#0066CC;
}
.link_12_dark_blue:visited {
font-family: MS Sans Serif, Tahoma, sans-serif;
font-size: 15px;
text-decoration: none;
color:#0066CC;
}
.link_12_dark_blue:active {
font-family: MS Sans Serif, Tahoma, sans-serif;
font-size: 15px;
text-decoration: none;
color:#0066CC;
}
.link_12_dark_blue:hover {
font-family: MS Sans Serif, Tahoma, sans-serif;
font-size: 15px;
text-decoration: none;
color:#FF0000;
}
</STYLE>
</head>
<body background="../pmj/workshop/20-2/bg.jpg">
<table width="1100" border="1" align="center" cellpadding="0" cellspacing="0">
<tr>
<th scope="col"><img src="../topmain4.jpg" width="1100" height="200" /></th>
</tr>
<tr>
<th scope="row" class="sss" align="right" bgcolor="#6699FF">
ยินดีต้อนรับ คุณ:<?php echo $_SESSION['MM_name_ac']; ?>[สถานะ : <?php echo $_SESSION['MM_UserType']; ?>]
<input name="btnlogout" type="button" class="button-tiny" id="btnlogout" value="LOG OUT!" onclick='location.replace("logout.php")' />
</tr>
<tr>
<th align="center" bgcolor="#333333" scope="row"><span class="dddd">ลบข้อมูลสิทธิ์การเข้าใช้</span></th>
</tr>
<tr>
<th align="center" class="sss" bgcolor="#CCE3E9" scope="row"><table width="1100" border="0" cellspacing="0" cellpadding="0">
<tr>
<th align="left" scope="col"><a href="accessmenu.dwt.php" class="link_12_dark_blue" style="text-decoration: none;"><<<BACK>>></a></th>
</tr>
</table>
<table border="1" align="center">
<tr align="center" bgcolor="#FFFFCC">
<td>รหัสประจำตัวประชาชน</td>
<td>ชื่อ-นามสกุล</td>
<td>เพศ</td>
<td>ที่อยู่</td>
<td>เบอร์โทรศัพท์</td>
<td>สถานะ</td>
<td align="center">Option</td>
</tr>
<?php do { ?>
<tr onmouseover="className="over"" onmouseout="className=""" >
<td align="center"><?php echo $row_accessRecord['code_ac']; ?></td>
<td><?php echo $row_accessRecord['name_ac']; ?></td>
<td align="center"><?php echo $row_accessRecord['sex_ac']; ?></td>
<td><?php echo $row_accessRecord['address_ac']; ?></td>
<td><?php echo $row_accessRecord['phone_ac']; ?></td>
<td align="center"><?php echo $row_accessRecord['usertype']; ?></td>
<td align="center">
<a href="../deleteacc1.php?codeacc=<?php echo $row_accessRecord['code_ac']; ?>"class="style2" OnClick="return chkdel();">
<object classid="clsid:166B1BCA-3F9C-11CF-8075-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/director/sw.cab#version=10,1,1,0" width="25" height="25" hspace="2">
<param name="src" value="../x5.png" />
<embed src="../x5.png" width="25" height="25" pluginspage="http://www.adobe.com/shockwave/download/" hspace="2"></embed>
</object></a></td>
</tr>
<?php } while ($row_accessRecord = mysql_fetch_assoc($accessRecord)); ?>
</table>
<blockquote>
<p> </p>
</blockquote> </th>
</tr>
</table>
</body>
</html>
<?php
mysql_free_result($accessRecord);
?>
Tag : PHP, MySQL
|
ประวัติการแก้ไข 2016-12-01 13:34:40 2016-12-01 13:38:17
|
|
|
|
|
Date :
2016-12-01 13:29:40 |
By :
tomzone2 |
View :
2589 |
Reply :
7 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if($status != 'admin'){
echo 'ลบได้';
}else{
echo 'ลบไม่ได้';
}
|
|
|
|
|
Date :
2016-12-01 13:34:59 |
By :
Who am i |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ตอนนี้ทำให้มัน alert ว่าลบไม่ได้แล้วครับ
แต่ติดตรงมัน alert ทุกอันที่จะลบครับ
**อย่างที่ต้องคือ ** alert เฉพาะฟิลที่สถานะ = admin ** ครับ
help me plz
//ไฟล์ deleteacc1.php ** ไฟล์ที่ใช้รับค่าจากฟอร์มด้านบน deleteacc.php**
Code (PHP)
<?php require_once('Connections/ConnectSW.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
if (PHP_VERSION < 6) {
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
}
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}
session_start();
if($_SESSION['MM_Username'] != ""){ // start
}
if (isset($_GET['codeacc']))
{
$id = $_GET['codeacc'];
$select = "SELECT code_ac = '{$id}' FROM accessibility WHERE usertype = 'admin'";
$result = mysql_query($select)or die(mysql_error());
$count = mysql_num_rows($result);
if ($count) {
$message = "ข้อมูลถูกใช้งานอยู่ไม่สามารถลบได้ในขณะนี้";
echo "<script type='text/javascript'>alert('$message');</script>";
}
else if((isset($_GET['codeacc'])) && ($_GET['codeacc'] != "")) {
$deleteSQL = sprintf("DELETE FROM accessibility WHERE code_ac=%s",
GetSQLValueString($_GET['codeacc'], "text"));
mysql_select_db($database_ConnectSW, $ConnectSW);
$Result1 = mysql_query($deleteSQL, $ConnectSW) or die(mysql_error());
$deleteGoTo = "Templates/accessmenu.dwt.php";
if (isset($_SERVER['QUERY_STRING'])) {
$deleteGoTo .= (strpos($deleteGoTo, '?')) ? "&" : "?";
$deleteGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $deleteGoTo));
}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
</body>
</html>
|
ประวัติการแก้ไข 2016-12-01 14:22:48
|
|
|
|
Date :
2016-12-01 14:14:11 |
By :
tomzone2 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ถ้าอะไร ๆ เท่ากับ แอดมิน ก็ไม่ต้องสร้างปุ่มให้มันกดลบ ไม่มีปุ่มก็ลบไม่ได้
if else ตาม คห. 2
|
|
|
|
|
Date :
2016-12-01 16:02:03 |
By :
apisitp |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ช่วยดูให้อีกทีครับ ผมใส่แล้ว มันก็ Error
รบกวนด้วยนะครับ เหลือตัวนี้ตัวสุดท้ายหล่ะครับ
Code (PHP)
<?php
if($row_accessRecord['usertype'] == 'admin'){
}
else{
<a href="../deleteacc1.php?codeacc=<? echo $row_accessRecord['code_ac']; ?>"class="style2" OnClick="return chkdel();">
<object classid="clsid:166B1BCA-3F9C-11CF-8075-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/director/sw.cab#version=10,1,1,0" width="25" height="25" hspace="2">
<param name="src" value="../x5.png" />
<embed src="../x5.png" width="25" height="25" pluginspage="http://www.adobe.com/shockwave/download/" hspace="2"></embed>
</object></a></td>
?>
<?php
}
?>
|
ประวัติการแก้ไข 2016-12-01 17:52:53
|
|
|
|
Date :
2016-12-01 17:31:41 |
By :
tomzone2 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ต้องแยกให้ออกน่ะครับ ว่าอันไหน Tag html อันไหน Tag php
|
|
|
|
|
Date :
2016-12-01 19:23:52 |
By :
Who am i |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 00
|