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.
65 lines
2.4 KiB
65 lines
2.4 KiB
<?php
|
|
include "header.php";
|
|
|
|
if(isset($_POST['update'])) {
|
|
foreach ($_POST as $k => $v) {
|
|
$$k = htmlspecialchars(stripslashes(trim($v)));
|
|
}
|
|
//print_r($_POST);exit;
|
|
|
|
// 選單各功能的權限
|
|
$prog_arr = [];
|
|
$opt_r_arr = explode(",", $opt_r_all);
|
|
$opt_w_arr = explode(",", $opt_w_all);
|
|
foreach ($opt_r_arr as $key => $val) {
|
|
list($menu_id, $auth_r) = explode(";", $val);
|
|
list($menu_id, $auth_w) = explode(";", $opt_w_arr[$key]);
|
|
|
|
// 找出相關程式
|
|
$sql = "select link_content from menu where id = '$menu_id'";
|
|
$res = mysqli_query($link, $sql);
|
|
if ($row = mysqli_fetch_assoc($res)) {
|
|
if ($row["link_content"]) {
|
|
$tmp_arr = explode("\r\n", $row["link_content"]);
|
|
foreach ($tmp_arr as $v) {
|
|
$prog_arr[$v] = $auth_r|$auth_w;
|
|
}
|
|
}
|
|
}
|
|
mysqli_free_result($res);
|
|
|
|
if (($key%10)==0) usleep(200000);
|
|
}
|
|
|
|
// 開始更新權限
|
|
$permission = json_encode($prog_arr, JSON_UNESCAPED_SLASHES);
|
|
$sql = "update department set permission = '$permission', create_at = '$create_at' where id = '$id'";
|
|
mysqli_query($link, $sql);
|
|
$affected = mysqli_affected_rows($link);
|
|
|
|
// 更新user權限
|
|
$sql = "select accountid from account where department_id = '$department_id' and role_id = '$role_id'";
|
|
$res = mysqli_query($link, $sql);
|
|
while ($row = mysqli_fetch_row($res)) {
|
|
$db_query = "insert into account_auth (accountid, permission) values ('$row[0]', '$permission') ";
|
|
$db_query .= "ON DUPLICATE KEY UPDATE accountid = '$row[0]', permission = '$permission'";
|
|
$res_u = mysqli_query($link, $db_query);
|
|
}
|
|
mysqli_free_result($res);
|
|
|
|
mysqli_close($link);
|
|
if ($affected > 0) {
|
|
echo "<script type ='text/JavaScript'>";
|
|
echo "alert('update成功');";
|
|
echo "location.href='account_auth-index.php?function_name=account_auth&".$token_link."';";
|
|
echo "</script>";
|
|
} elseif ($affected == 0) {
|
|
echo "<script type ='text/JavaScript'>";
|
|
echo "alert('無新增資料');";
|
|
echo "location.href='account_auth-index.php?function_name=account_auth&".$token_link."';";
|
|
echo "</script>";
|
|
} else {
|
|
echo "{$db_query} 語法執行失敗,錯誤訊息SSS: " . mysqli_error($link);
|
|
}
|
|
}
|
|
?>
|