You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

182 lines
6.5 KiB

<?php
include "header.php";
$id = isset($_GET['id']) ? $_GET['id'] : die('ERROR: Record ID not found.');
// 選單結構
$menu = array();
$db_query = "select * from menu where status = 'Y' order by main_menu_seq, sub_menu_seq";
$res = mysqli_query($link, $db_query);
while ($row = mysqli_fetch_assoc($res)) {
$menu[$row["main_menu_seq"]]["main_menu"] = $row["main_menu"];
$menu[$row["main_menu_seq"]][$row["sub_menu_seq"]]["sub_menu"] = $row["sub_menu"];
$menu[$row["main_menu_seq"]][$row["sub_menu_seq"]]["mlink"] = $row["mlink"];
$menu[$row["main_menu_seq"]][$row["sub_menu_seq"]]["link_content"] = $row["link_content"];
$menu[$row["main_menu_seq"]][$row["sub_menu_seq"]]["status"] = $row["status"];
$menu[$row["main_menu_seq"]][$row["sub_menu_seq"]]["id"] = $row["id"];
}
mysqli_free_result($res);
$data = array();
// sql语法存在变数中
$db_query = "select * from department where id = '$id'";
// 用mysqli_query方法执行(sql语法)将结果存在变数中
$data = mysqli_query($link,$db_query);
foreach($data as $data) :
$permission_arr = json_decode(urldecode($data["permission"]), true);
$person = "";
$sql = "select accountid, name from account where department_id = '".$data["department_id"]."' and role_id = '".$data["role_id"]."' and accounttype <> 'X'";
$result = mysqli_query($link, $sql);
while ($row_a = mysqli_fetch_row($result)) {
$person .= $row_a[1]."(".$row_a[0].")、";
}
mysqli_free_result($result);
?>
<style>
table {
margin-top:10px;
}
.table-off, .table-off > td, .table-off > th {
background-color: #d6d8db;
}
.label-checkbox {
cursor: pointer;
}
body > div > form > table > thead > tr > th:nth-child(3) > label > span {
font-size:14px;
}
.nextline {
width: 100%;
height: 0;
}
</style>
<script>
$(function () {
$("input[name=rall]").click(function(){
$("input[name=opt_r]").not(this).prop('checked', this.checked);
});
$("input[name=wall]").click(function(){
$("input[name=opt_w]").not(this).prop('checked', this.checked);
});
$('#update').click(function(){
var optRStr = "";
var optRArr = [];
$("input[name=opt_r]").each(function(){
optRStr = "";
optRStr += $(this).attr('data-auth');
if ($(this).prop('checked')) optRStr += ";"+$(this).val();
else optRStr += ";0";
optRArr.push(optRStr);
})
$('#opt_r_all').val(optRArr);
var optWStr = "";
var optWArr = [];
$("input[name=opt_w]").each(function(){
optWStr = "";
optWStr += $(this).attr('data-auth');
if ($(this).prop('checked')) optWStr += ";"+$(this).val();
else optWStr += ";0";
optWArr.push(optWStr);
})
$('#opt_w_all').val(optWArr);
});
});
</script>
<div class="container">
<form class="form-inline" method="post" action="account_auth-record-update.php">
<input type="hidden" name="id" value="<?php echo $id; ?>">
<div>
<label for="department_name">部門</label>
<input type="text" name="department_name" id="department_name" value="<?php echo $data['name']; ?>" readonly>
</div>
<div>
<label for="role_name">職別</label>
<input type="text" name="role_name" id="role_name" value="<?php echo $data['role']; ?>" readonly>
</div>
<table class="table table-bordered">
<thead>
<tr>
<th scope="col">主功能名稱</th>
<th scope="col">子功能名稱</th>
<th scope="col">
<label class="label-checkbox"><input type="checkbox" name="rall">
全選</label>
</th>
<th scope="col">
<label class="label-checkbox"><input type="checkbox" name="wall">
全選</label>
</th>
</tr>
</thead>
<tbody>
<?php
foreach($menu as $key => $val) {
foreach($val as $k2 => $v2) {
if ($k2 == "main_menu") continue;
$td_str = ($k2 == 1) ? '<td rowspan="'.(count($val)-1).'">'.$val["main_menu"].'</td>' : '';
$sta_str = ($v2["status"] == "Y") ? '' : ' class="table-off"';
$chk_r = $chk_w = "";
if (!empty($permission_arr[$v2["mlink"]])) {
if ($permission_arr[$v2["mlink"]]&1) $chk_r = " checked";
if ($permission_arr[$v2["mlink"]]&2) $chk_w = " checked";
}
?>
<tr<?php echo $sta_str; ?>>
<?php echo $td_str; ?>
<td>
<?php echo $v2["sub_menu"]; ?>
</td>
<td>
<label class="label-checkbox">
<input type="checkbox" name="opt_r" value="1" data-auth="<?php echo $v2["id"]; ?>"<?php echo $chk_r; ?>>
可讀</label>
</td>
<td>
<label class="label-checkbox">
<input type="checkbox" name="opt_w" value="2" data-auth="<?php echo $v2["id"]; ?>"<?php echo $chk_w; ?>>
可寫</label>
</td>
</tr>
<?php
}
}
?>
</tbody>
</table>
<div>
<label>所屬人員</label>
<textarea name="person-info" rows="6" cols="70" class="form-control" readonly><?php echo rtrim($person, "、"); ?></textarea>
</div>
<div class="nextline"></div>
<div>
<label for="creater">建檔人</label>
<input type="text" name="creater" id="creater" value="<?php echo $data['creater']; ?>" readonly>
</div>
<div>
<br>
<button type="submit" name="update" id="update">確定</button>
</div>
<input type="hidden" name="opt_r_all" id="opt_r_all">
<input type="hidden" name="opt_w_all" id="opt_w_all">
<input type="hidden" name="department_id" id="department_id" value="<?php echo $data["department_id"]; ?>">
<input type="hidden" name="role_id" id="role_id" value="<?php echo $data["role_id"]; ?>">
<input type="hidden" name="token" value="<?php echo $token; ?>">
<input type="hidden" name="create_at" id="create_at" value="<?php echo date("Y-m-d H:i:s"); ?>">
</form>
</div>
<?php
endforeach;
include "footer.php";
?>