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.
 
 
 
 
 
 

302 lines
15 KiB

<style>
input,
select {
margin: 0 0 !important;
vertical-align: middle !important;
}
.mybutton {
padding: 3px !important;
}
</style>
<?php
include "header.php";
$id = isset($_GET['id']) ? $_GET['id'] : die('ERROR: Record ID not found.');
// sql语法存在变数中
$db_query = "SELECT * FROM menu WHERE id = $id";
// 用mysqli_query方法执行(sql语法)将结果存在变数中
$result = mysqli_query($link, $db_query);
$data = mysqli_fetch_assoc($result);
mysqli_free_result($result);
$db_query = "
SELECT * FROM department
ORDER BY department_id ASC
";
$result = mysqli_query($link, $db_query);
$data2 = mysqli_fetch_all($result, MYSQLI_ASSOC);
mysqli_free_result($result);
//$link_content = str_replace(',', PHP_EOL, $data['link_content']);
?>
<div class="container">
<form class="form-inline" method="post" action="menu-record-update.php">
<input type="hidden" name="id" value="<?php echo $id; ?>">
<div class="row col-md-12 col-sm-12">
<div class="col-md-2 col-sm-12">
<label for="main_menu">主功能名稱</label>
<input type="text" name="main_menu" id="main_menu" value="<?php echo $data['main_menu']; ?>" required>
</div>
<div class="col-md-2 col-sm-12">
<label for="main_menu_seq">主功能排序</label>
<select name="main_menu_seq" id="main_menu_seq">
<?php
for ($i = 1; $i < 21; $i++) {
echo '<option value="' . $i . '"';
if ($i == $data["main_menu_seq"]) echo " selected";
echo '>' . $i . '</option>';
}
?>
</select>
</div>
<div class="col-md-2 col-sm-12">
<label for="sub_menu">子功能名稱</label>
<input type="text" name="sub_menu" id="sub_menu" value="<?php echo $data['sub_menu']; ?>" required>
</div>
<div class="col-md-2 col-sm-12">
<label for="sub_menu_seq">子功能排序</label>
<select name="sub_menu_seq" id="sub_menu_seq">
<?php
for ($i = 1; $i < 21; $i++) {
echo '<option value="' . $i . '"';
if ($i == $data["sub_menu_seq"]) echo " selected";
echo '>' . $i . '</option>';
}
?>
</select>
</div>
<div class="col-md-2 col-sm-12">
<label for="sub_menu_eng">子功能英文名</label>
<input type="text" name="sub_menu_eng" id="sub_menu_eng" value="<?php echo $data['sub_menu_eng']; ?>" required>
</div>
<div class="col-md-2 col-sm-12">
<label for="mlink">主網址</label>
<input type="text" name="mlink" id="mlink" size="30" value="<?php echo $data['mlink']; ?>" required>
</div>
<div class="col-md-4 col-sm-12">
<label for="status">狀態</label>
<select name="status" id="status">
<option value="N" <?php if ($data["status"] == "N") echo " selected"; ?>>隱藏</option>
<!--<option value="T"<?php if ($data["status"] == "T") echo " selected"; ?>>測試</option>-->
<option value="Y" <?php if ($data["status"] == "Y") echo " selected"; ?>>正常</option>
</select>
</div>
<div class="col-md-4 col-sm-12">
<label for="creater">建檔人</label>
<input type="text" name="creater" id="creater" value="<?php echo $data['creater']; ?>" readonly>
</div>
<div class="col-md-12 col-sm-12" style="margin-top:15px;">
<label class='col-md-12' for="link_content">程式列表</label>
<textarea name="link_content" id="link_content" rows="10" cols="60" class="form-control" required><?php echo $data['link_content']; ?></textarea>
</div>
</div>
<div class="row col-md-12 col-sm-12" style="margin-top:15px;">
<div class="col-md-4 col-sm-12">
<label class='col-md-12' for="selectL1">可讀權限</label>
<select multiple="multiple" id="selectL1" style="width:100%;height:300px; border:4px #A0A0A4 outset; padding:4px; ">
<?php
foreach ($data2 as $row) {
$menu_permission = json_decode($row['permission']);
$status = false;
foreach ($menu_permission as $key => $value) {
if ($key == $data['mlink'] && in_array($value, ['1'])) {
$status = true;
break;
}
}
if (!$status)
echo "<option value='" . $row['id'] . "'>" . $row['name'] . "_" . $row['role'] . "</option>";
}
?>
</select>
</div>
<div class="col-md-1 col-sm-12">
<label class='col-md-12' for="add"> </label>
<button id="add1" type="button" class="btn mybutton">添加</button>
<button id="remove1" type="button" class="btn mybutton">移除</button>
<button id="add_all1" type="button" class="btn mybutton">全部添加</button>
<button id="remove_all1" type="button" class="btn mybutton">全部移除</button>
</div>
<div class="col-md-4 col-sm-12">
<label class='col-md-12' for="selectR1"> </label>
<select multiple="multiple" id="selectR1" name="can_read[]" style="width:100%;height:300px;;border:4px #A0A0A4 outset; padding:4px;">
<?php
foreach ($data2 as $row) {
$menu_permission = json_decode($row['permission']);
foreach ($menu_permission as $key => $value) {
if ($key == $data['mlink'] && in_array($value, ['1'])) {
echo "<option value='" . $row['id'] . "'>" . $row['name'] . "_" . $row['role'] . "</option>";
}
}
}
?>
</select>
</div>
</div>
<div class="row col-md-12 col-sm-12" style="margin-top:15px;">
<div class="col-md-4 col-sm-12">
<label class='col-md-12' for="selectL2">可寫權限</label>
<select multiple="multiple" id="selectL2" style="width:100%;height:300px; border:4px #A0A0A4 outset; padding:4px; ">
<?php
foreach ($data2 as $row) {
$menu_permission = json_decode($row['permission']);
$status = false;
foreach ($menu_permission as $key => $value) {
if ($key == $data['mlink'] && in_array($value, ['2', '3'])) {
$status = true;
break;
}
}
if (!$status)
echo "<option value='" . $row['id'] . "'>" . $row['name'] . "_" . $row['role'] . "</option>";
}
?>
</select>
</div>
<div class="col-md-1 col-sm-12">
<label class='col-md-12' for="add"> </label>
<button id="add2" type="button" class="btn mybutton">添加</button>
<button id="remove2" type="button" class="btn mybutton">移除</button>
<button id="add_all2" type="button" class="btn mybutton">全部添加</button>
<button id="remove_all2" type="button" class="btn mybutton">全部移除</button>
</div>
<div class="col-md-4 col-sm-12">
<label class='col-md-12' for="selectR2"> </label>
<select multiple="multiple" id="selectR2" name="can_write[]" style="width:100%;height:300px;;border:4px #A0A0A4 outset; padding:4px;">
<?php
foreach ($data2 as $row) {
$menu_permission = json_decode($row['permission']);
foreach ($menu_permission as $key => $value) {
if ($key == $data['mlink'] && in_array($value, ['2', '3'])) {
echo "<option value='" . $row['id'] . "'>" . $row['name'] . "_" . $row['role'] . "</option>";
}
}
}
?>
</select>
</div>
</div>
<div class="row col-md-12 col-sm-12">
<div class="col-md-12 col-sm-12">
<button class="pull-right" type="submit" name="update" id="update_btn" disabled>請先鎖定再提交</button>
<button class="pull-right" type="button" onclick="lockAuthSelect()">鎖定權限</button>
</div>
</div>
<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>
<script>
$(function() {
lrSelectChange('selectL', 'selectR', '1');
lrSelectChange('selectL', 'selectR', '2');
});
function lockAuthSelect() {
$("#selectR1 option").prop("selected", true);
$("#selectR2 option").prop("selected", true);
$("#update_btn").text("提交").removeAttr("disabled");
}
function lrSelectChange(lSelect, rSelect, id) {
lSelect = lSelect + id;
rSelect = rSelect + id;
//移到右边
$('#add' + id).click(function() {
//获取选中的选项,删除并追加给对方
for (var i = 0; i < $('#' + lSelect + ' option:selected').length; i++) {
$('#' + lSelect + ' option:selected')[i].text = $('#' + lSelect + ' option:selected')[i].text
$('#' + lSelect + ' option:selected')[i].value = $('#' + lSelect + ' option:selected')[i].value
}
$('#' + lSelect + ' option:selected').appendTo('#' + rSelect);
$("#update_btn").text("請先鎖定再提交").attr("disabled", "disabled");
});
//移到左边
$('#remove' + id).click(function() {
for (var i = 0; i < $('#' + rSelect + ' option:selected').length; i++) {
$('#' + rSelect + ' option:selected')[i].text = $('#' + rSelect + ' option:selected')[i].text
$('#' + rSelect + ' option:selected')[i].value = $('#' + rSelect + ' option:selected')[i].value
}
$('#' + rSelect + ' option:selected').appendTo('#' + lSelect + '');
$("#update_btn").text("請先鎖定再提交").attr("disabled", "disabled");
});
//全部移到右边
$('#add_all' + id).click(function() {
for (var i = 0; i < $('#' + lSelect + ' option').length; i++) {
$('#' + lSelect + ' option')[i].text = $('#' + lSelect + ' option')[i].text
$('#' + lSelect + ' option')[i].value = $('#' + lSelect + ' option')[i].value
}
//获取全部的选项,删除并追加给对方
$('#' + lSelect + ' option').appendTo('#' + rSelect + '');
$("#update_btn").text("請先鎖定再提交").attr("disabled", "disabled");
});
//全部移到左边
$('#remove_all' + id).click(function() {
for (var i = 0; i < $('#' + rSelect + ' option').length; i++) {
$('#' + rSelect + ' option')[i].text = $('#' + rSelect + ' option')[i].text
$('#' + rSelect + ' option')[i].value = $('#' + rSelect + ' option')[i].value
}
$('#' + rSelect + ' option').appendTo('#' + lSelect + '');
$("#update_btn").text("請先鎖定再提交").attr("disabled", "disabled");
});
//双击选项,左边到右边
$('#' + lSelect + '').dblclick(function() { //绑定双击事件
for (var i = 0; i < $('#' + lSelect + ' option:selected').length; i++) {
$('#' + lSelect + ' option:selected')[i].text = $('#' + lSelect + ' option:selected')[i].text
$('#' + lSelect + ' option:selected')[i].value = $('#' + lSelect + ' option:selected')[i].value
}
$('#' + lSelect + ' option:selected').appendTo('#' + rSelect + '');
$("#update_btn").text("請先鎖定再提交").attr("disabled", "disabled");
});
//双击选项,右边到左边
$('#' + rSelect + '').dblclick(function() {
for (var i = 0; i < $('#selectR1 option:selected').length; i++) {
$('#' + rSelect + ' option:selected')[i].text = $('#' + rSelect + ' option:selected')[i].text
$('#' + rSelect + ' option:selected')[i].value = $('#' + rSelect + ' option:selected')[i].value
}
$('#' + rSelect + ' option:selected').appendTo('#' + lSelect + '');
$("#update_btn").text("請先鎖定再提交").attr("disabled", "disabled");
});
$('#' + rSelect + '').click(function() {
$("#update_btn").text("請先鎖定再提交").attr("disabled", "disabled");
if ($('#' + rSelect + ' option:selected').length > 1) { //右侧选中多个时,只允许点击一个使其变序
return;
}
if (($("option:selected", this).text().substring($("option:selected", this).text().length - 4, $("option:selected", this).text().length)) == '(升序)') {
var a = $("option:selected", this).text();
$("option:selected", this).prop('text', a)
var b = $("option:selected", this).val();
b = b.replace("$asc", "$desc")
$("option:selected", this).prop('value', b)
return
}
if (($("option:selected", this).text().substring($("option:selected", this).text().length - 4, $("option:selected", this).text().length)) == '(降序)') {
var a = $("option:selected", this).text();
$("option:selected", this).prop('text', a)
var b = $("option:selected", this).val();
b = b.replace("$desc", "$asc")
$("option:selected", this).prop('value', b)
return
}
});
}
$(function() {
});
</script>
<?php
include "footer.php";
?>