123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306 |
- <?php
- include "conn.php";
- checkLogin("权限管理");
- ?>
- <!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>管理区域</title>
- <link rel="stylesheet" href="css/common.css" type="text/css" />
- <script language="javascript" src="js/jquery-1.7.2.min.js"></script>
- <script type="text/javascript" src="js/js.js"></script>
- </head>
- <body>
- <div id="man_zone">
- <?php
- $act = $_GET['act'] ?? '';
- if ($act == "save") {
- $isedit = false;
- $id = $_POST['id'] ?? '';
- if ($id != "" && is_numeric($id)) {
- $isedit = true;
- }
- $powername = textEncode($_POST['powername'] ?? '');
- $powercontent = isset($_POST['powercontent']) ? implode(',', $_POST['powercontent']) : '';
- if ($isedit) {
- // Check if power name exists
- $sql = "SELECT COUNT(id) as count FROM power WHERE powername = ? AND id != ?";
- $stmt = $conn->prepare($sql);
- $stmt->execute([$powername, $id]);
- if ($stmt->fetch(PDO::FETCH_ASSOC)['count'] > 0) {
- echo "<script>alert('Sorry,该权限名称已经存在,请检查更换');history.back()</script>";
- exit;
- }
- $sql = "UPDATE power SET powername = ?, powercontent = ? WHERE id = ?";
- $stmt = $conn->prepare($sql);
- $stmt->execute([$powername, $powercontent, $id]);
- } else {
- // Check if power name exists
- $sql = "SELECT COUNT(id) as count FROM power WHERE powername = ?";
- $stmt = $conn->prepare($sql);
- $stmt->execute([$powername]);
- if ($stmt->fetch(PDO::FETCH_ASSOC)['count'] > 0) {
- echo "<script>alert('Sorry,该权限名称已经存在,请检查更换');history.back()</script>";
- exit;
- }
- $sql = "INSERT INTO power (powername, powercontent, powerstate) VALUES (?, ?, 1)";
- $stmt = $conn->prepare($sql);
- $stmt->execute([$powername, $powercontent]);
- }
- $page = $_GET['Page'] ?? '';
- $keys = urlencode($_GET['Keys'] ?? '');
- $ord = urlencode($_GET['Ord'] ?? '');
- header("Location: ?keys=$keys&Ord=$ord&Page=$page");
- exit;
- }
- if ($act == "add" || $act == "edit") {
- $id = $_GET['id'] ?? '';
- $isedit = false;
- $powername = '';
- $powercontent = '';
- if ($id != "" && is_numeric($id)) {
- $isedit = true;
- $sql = "SELECT powername, powercontent FROM power WHERE id = ?";
- $stmt = $conn->prepare($sql);
- $stmt->execute([$id]);
- if ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
- $powername = textUncode($row['powername']);
- $powercontent = $row['powercontent'];
- } else {
- $isedit = false;
- }
- }
- $page = $_GET['Page'] ?? '';
- $keys = urlencode($_GET['Keys'] ?? '');
- $ord = urlencode($_GET['Ord'] ?? '');
- $hrefstr = "?keys=$keys&Ord=$ord&Page=$page";
- ?>
- <form name="form1" method="post" action="<?php echo $hrefstr; ?>&act=save">
- <table width="100%" border="0" cellpadding="3" cellspacing="1" class="table1">
- <tbody>
- <tr>
- <th width="8%">权限名称</th>
- <td><input type="text" id="powername" name="powername" value="<?php echo $powername; ?>" class="txt1" /><input type="hidden" name="id" value="<?php echo $id; ?>" /></td>
- </tr>
- <tr>
- <th width="8%">可用权限</th>
- <td>
- <fieldset>
- <legend>信息管理</legend>
- <input type="checkbox" id="powerchk1" name="powercontent[]" value="单页管理" <?php if (strpos($powercontent, "单页管理") !== false) echo 'checked="checked"'; ?> /><label for="powerchk1">单页管理</label>
- <input type="checkbox" id="powerchk2" name="powercontent[]" value="分类管理" <?php if (strpos($powercontent, "分类管理") !== false) echo 'checked="checked"'; ?> /><label for="powerchk2">分类管理</label>
- <input type="checkbox" id="powerchk3" name="powercontent[]" value="专题管理" <?php if (strpos($powercontent, "专题管理") !== false) echo 'checked="checked"'; ?> /><label for="powerchk3">专题管理</label>
- <input type="checkbox" id="powerchk4" name="powercontent[]" value="信息管理" <?php if (strpos($powercontent, "信息管理") !== false) echo 'checked="checked"'; ?> /><label for="powerchk4">信息管理</label><br />
- </fieldset>
- <fieldset>
- <legend>售后管理</legend>
- <input type="checkbox" id="powerchk21" name="powercontent[]" value="售后_单页" <?php if (strpos($powercontent, "售后_单页") !== false) echo 'checked="checked"'; ?> /><label for="powerchk21">单页管理</label>
- <input type="checkbox" id="powerchk22" name="powercontent[]" value="售后_信息" <?php if (strpos($powercontent, "售后_信息") !== false) echo 'checked="checked"'; ?> /><label for="powerchk22">信息管理</label><br />
- </fieldset>
- </td>
- </tr>
- <tr>
- <th></th>
- <td><input type="submit" name="save" id="save" value="确定" class="btn1" /> <input type="reset" name="save" id="save" value="重置" class="btn1" /> <input type="button" value="返回" class="btn1" onClick="location.href='<?php echo $hrefstr; ?>'" /></td>
- </tr>
- </tbody>
- </table>
- </form>
- <?php
- exit;
- }
- if ($act == "postchk") {
- $keys = urlencode($_GET['Keys'] ?? '');
- $ord = urlencode($_GET['Ord'] ?? '');
- $page = $_GET['Page'] ?? '';
- $chkact = $_POST['chkact'] ?? '';
- if (isset($_POST['chkbox']) && is_array($_POST['chkbox'])) {
- $ids = array_map('intval', $_POST['chkbox']);
- $placeholders = str_repeat('?,', count($ids) - 1) . '?';
-
- switch ($chkact) {
- case "0":
- case "1":
- $sql = "UPDATE power SET powerstate = ? WHERE id IN ($placeholders)";
- array_unshift($ids, $chkact);
- break;
- default:
- $sql = "DELETE FROM power WHERE id IN ($placeholders)";
- break;
- }
-
- $stmt = $conn->prepare($sql);
- $stmt->execute($ids);
- }
-
- header("Location: ?Keys=$keys&Ord=$ord&Page=$page");
- exit;
- }
- $keys = $_GET['Keys'] ?? '';
- $keyscode = textEncode($keys);
- $ord = $_GET['Ord'] ?? '';
- $page = $_GET['Page'] ?? '';
- $orderby = "id DESC";
- if (in_array($ord, ['powername', 'powername Desc', 'powerstate', 'powerstate Desc', 'powercontent', 'powercontent Desc'])) {
- $orderby = "$ord, id DESC";
- }
- $sql = "SELECT id, powername, powercontent, powerstate FROM power
- WHERE id <> 1 AND (powername LIKE ? OR powercontent LIKE ?)
- ORDER BY $orderby";
- $stmt = $conn->prepare($sql);
- $stmt->execute(["%$keyscode%", "%$keyscode%"]);
- $results = $stmt->fetchAll(PDO::FETCH_ASSOC);
- $total_records = count($results);
- $records_per_page = 10;
- $total_pages = ceil($total_records / $records_per_page);
- if ($page == "") $page = 1;
- if ($page == "end") $page = $total_pages;
- if (!is_numeric($page) || $page < 1) $page = 1;
- $page = (int)$page;
- if ($page > $total_pages) $page = $total_pages;
- $start = ($page - 1) * $records_per_page;
- $results = array_slice($results, $start, $records_per_page);
- $keys = urlencode($keys);
- $ord = urlencode($ord);
- $hrefstr = "?keys=$keys";
- ?>
- <form id="form1" method="post" action="?act=postchk&Keys=<?php echo $keys; ?>&Ord=<?php echo $ord; ?>&Page=<?php echo $page; ?>" onSubmit="return false">
- <table width="100%" border="0" cellpadding="3" cellspacing="1" class="table1">
- <thead>
- <tr>
- <th width="4%"><input type="checkbox" name="chkall" id="chkall" onClick="chkboxall(this,'chkbox')" /></th>
- <th width="6%">序号</th>
- <th width="20%"><a href="<?php echo $hrefstr; ?><?php echo ($ord=="powername" ? "&ord=powername+Desc" : "&ord=powername"); ?>">权限名称<?php echo ($ord=="powername" ? "↓" : ($ord=="powername+Desc" ? "↑" : "")); ?></a></th>
- <th width="54%"><a href="<?php echo $hrefstr; ?><?php echo ($ord=="powercontent" ? "&ord=powercontent+Desc" : "&ord=powercontent"); ?>">可用权限<?php echo ($ord=="powercontent" ? "↓" : ($ord=="powercontent+Desc" ? "↑" : "")); ?></a></th>
- <th width="8%"><a href="<?php echo $hrefstr; ?><?php echo ($ord=="powerstate" ? "&ord=powerstate+Desc" : "&ord=powerstate"); ?>">状态<?php echo ($ord=="powerstate" ? "↓" : ($ord=="powerstate+Desc" ? "↑" : "")); ?></a></th>
- <th width="8%">操作</th>
- </tr>
- </thead>
- <tbody>
- <?php
- if (!empty($results)) {
- $tempNum = ($page - 1) * $records_per_page;
- foreach ($results as $row) {
- $tempNum++;
- ?>
- <tr onMouseOver="this.style.background='#F7FCFF'" onMouseOut="this.style.background='#FFFFFF'">
- <td align="center"><input type="checkbox" name="chkbox[]" value="<?php echo $row['id']; ?>" /></td>
- <td align="center"><?php echo $tempNum; ?></td>
- <td align="center"><?php echo $row['powername']; ?></td>
- <td align="center"><?php echo $row['powercontent']; ?></td>
- <td align="center"><?php echo ($row['powerstate'] == 1 ? "正常" : "停用"); ?></td>
- <td align="center"><a href="?Keys=<?php echo $keys; ?>&Ord=<?php echo $ord; ?>&Page=<?php echo $page; ?>&act=edit&id=<?php echo $row['id']; ?>" class="ico_edit">修改</a></td>
- </tr>
- <?php
- }
- } else {
- if ($keys == "") {
- ?>
- <tr>
- <td align="center" colspan="7">Sorry,当前暂无权限</td>
- </tr>
- <?php
- } else {
- ?>
- <tr>
- <td align="center" colspan="7"><a href="?">Sorry,没有找到"<?php echo $keyscode; ?>"相关的权限,点击返回</a></td>
- </tr>
- <?php
- }
- }
- ?>
- </tbody>
- <tfoot>
- <tr>
- <td colspan="7">
- <div class="showpagebox">
- <?php
- if ($total_pages > 1) {
- $pageName = "?Keys=$keys&Ord=$ord&";
- $pagelen = 3;
- if ($page > 1) {
- echo "<a href=\"{$pageName}Page=1\">首页</a>";
- echo "<a href=\"{$pageName}Page=" . ($page-1) . "\">上一页</a>";
- }
- if ($pagelen * 2 + 1 >= $total_pages) {
- $startPage = 1;
- $endPage = $total_pages;
- } else {
- if ($page <= $pagelen + 1) {
- $startPage = 1;
- $endPage = $pagelen * 2 + 1;
- } else {
- $startPage = $page - $pagelen;
- $endPage = $page + $pagelen;
- }
- if ($page + $pagelen > $total_pages) {
- $startPage = $total_pages - $pagelen * 2;
- $endPage = $total_pages;
- }
- }
- for ($i = $startPage; $i <= $endPage; $i++) {
- if ($i == $page) {
- echo "<a class=\"current\">$i</a>";
- } else {
- echo "<a href=\"{$pageName}Page=$i\">$i</a>";
- }
- }
- if ($page < $total_pages) {
- if ($total_pages - $page > $pagelen) {
- echo "<a href=\"{$pageName}Page=$total_pages\">...$total_pages</a>";
- }
- echo "<a href=\"{$pageName}Page=" . ($page+1) . "\">下一页</a>";
- echo "<a href=\"{$pageName}Page=$total_pages\">尾页</a>";
- }
- echo "<input type=\"text\" id=\"Pagego\" value=\"$page\" onFocus=\"if(this.value == '$page'){this.value='';};\" onBlur=\"if(this.value == ''){this.value='$page';}\" onKeyUp=\"this.value=this.value.replace(/\D/g,'')\" onKeyDown=\"if(event.keyCode==13){location.href='{$pageName}Page='+document.getElementById('Pagego').value}\" />";
- }
- ?>
- </div>
- <div class="searchbox">
- <input type="text" id="keys" value="<?php echo ($keyscode == "") ? "请输入搜索关键词" : $keyscode; ?>"
- onFocus="if(this.value == '<?php echo ($keyscode == "") ? "请输入搜索关键词" : $keyscode; ?>'){this.value='';}"
- onBlur="if(this.value == ''){this.value='<?php echo ($keyscode == "") ? "请输入搜索关键词" : $keyscode; ?>';}"
- onKeyDown="if(event.keyCode==13){location.href='?Keys='+escape(document.getElementById('keys').value)}" />
- <input type="button" id="searchgo" value="go" onClick="location.href='?Keys='+escape(document.getElementById('keys').value)" />
- </div>
- <div class="postchkbox">
- <select id="chkact" name="chkact">
- <option value="1">正常</option>
- <option value="0">停用</option>
- <option value="-1">删除</option>
- </select>
- <input type="button" value="执行" onClick="postchk(2)" class="btn1" />
- </div>
- </td>
- </tr>
- </tfoot>
- </table>
- </form>
- </div>
- </body>
- </html>
|