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.
 
 
 
 
 
 

177 lines
5.9 KiB

<?php
include "header.php";
// 部門職別
$db_query = "select department_id, name, role_id, role from department order by department_id";
$res = mysqli_query($link, $db_query);
while ($row = mysqli_fetch_assoc($res)) {
$depart_arr[$row["department_id"]] = $row["name"];
$role_arr[$row["department_id"]][$row["role_id"]] = $row["role"];
}
mysqli_free_result($res);
// 選單結構
$data = array();
$db_query = "select * from menu order by main_menu_seq, sub_menu_seq";
$res = mysqli_query($link, $db_query);
while ($row = mysqli_fetch_assoc($res)) {
$data[$row["main_menu_seq"]]["main_menu"] = $row["main_menu"];
$data[$row["main_menu_seq"]][$row["sub_menu_seq"]]["sub_menu"] = $row["sub_menu"];
$data[$row["main_menu_seq"]][$row["sub_menu_seq"]]["link_content"] = $row["link_content"];
$data[$row["main_menu_seq"]][$row["sub_menu_seq"]]["status"] = $row["status"];
}
mysqli_free_result($res);
//print_r($data);exit;
?>
<style>
table {
margin-top:10px;
}
.table-off, .table-off > td, .table-off > th {
background-color: #d6d8db;
}
.label-checkbox { cursor: pointer; }
</style>
<script>
$(function () {
var jroleStr = '<?php echo json_encode($role_arr); ?>';
var jroleArr = JSON.parse(jroleStr);
var optStr = "";
$("select[name=department_id]").change(function(){
if ($(this).val() != "") {
optStr = "";
for (var i in jroleArr[$(this).val()]) {
if ('undefined' !== jroleArr[$(this).val()][i]) {
optStr += '<option value="'+i+'">'+jroleArr[$(this).val()][i]+'</option>';
}
}
$("select[name=role_id]").html(optStr);
} else $("select[name=role_id]").html('<option value="">請選擇</option>');
})
$('#submit').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 += ";X";
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 += ";X";
optWArr.push(optWStr);
})
$('#opt_w_all').val(optWArr);
});
});
</script>
<div class="container">
<?php
include "account_auth-record-submit.php";
/*
if($_SERVER["REQUEST_METHOD"] == "POST"){
if(empty($_POST["id"]) && empty($_POST["expert_id"]) && empty($_POST["personal_id"])){
echo "<p class='error'>Please fill up the required field!</p>";
} else {
echo "<p class='success'>Record has added successfully</p>";
}
}
*/
?>
<form class="form-inline" method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
<div>
<label for="department_id">部門</label>
<select name="department_id" required>
<option value="">請選擇</option>
<?php
foreach ($depart_arr as $k => $v) {
echo "<option value=\"".$k."\">".$v."</option>";
}
?>
</select>
</div>
<div>
<label for="role_id">職別</label>
<select name="role_id" required>
<?php
foreach ($role_arr[$data2["department_id"]] as $k => $v) {
echo "<option value=\"".$k."\">".$v."</option>";
}
?>
</select>
</div>
<table class="table table-bordered">
<thead>
<tr>
<th scope="col">主功能名稱</th>
<th scope="col">子功能名稱</th>
<th scope="col">控管</th>
</tr>
</thead>
<tbody>
<?php
foreach($data 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"';
?>
<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="R" data-auth="<?php echo $key.";".$k2; ?>">
可讀</label>
<label class="label-checkbox">
<input type="checkbox" name="opt_w" value="W" data-auth="<?php echo $key.";".$k2; ?>">
可寫</label>
</td>
</tr>
<?php
}
}
?>
</tbody>
</table>
<div>
<label for="creater">建檔人</label>
<input type="text" name="creater" id="creater" value="<?php echo $user_id; ?>" readonly>
<p class="error"><?php echo $creater_error; ?></p>
</div>
<div>
<!-- <label for="create_at">create_at</label> -->
<input type="hidden" name="create_at" id="create_at" value="<?php echo date("Y-m-d H:i:s"); ?>">
<p class="error"><?php echo $create_at_error; ?></p>
</div>
<div>
<br>
<button type="submit" id="submit" name="submit">確定</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="token" value="<?php echo $token; ?>">
</form>
</div>
<?php
include "footer.php";
?>