1 Star 0 Fork 0

sky/company

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
jobEdit.php 3.31 KB
一键复制 编辑 原始数据 按行查看 历史
sky 提交于 2024-01-04 15:13 . 提交项目
<?php
include_once('config/config.php');
$LoginAdmin = checkAuth();
if ($_GET) {
$id = $_GET['id'] ?? 0;
}
if ($_POST) {
$name = trim($_POST['name']);
$depid = trim($_POST['depid']);
if (!$name) {
showMsg('职位名称不能为空!');
}
//封装数据
$data = array(
"name" => $name,
"depid" => $depid
);
$sql = "select * from `pre_job` where `name` = '$name' and `depid` = '$depid' and `id` != '$id'";
$res = find($sql);
if (count($res) > 0) {
showMsg('职位已存在!');
}
// 更新数据
$result = update('job', $data, "`id` = '$id'");
if ($result['code'] === 0) {
showMsg($result['msg']);
} else {
showMsg($result['msg'], 'jobList.php');
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<?php include_once('common/meta.php'); ?>
</head>
<body>
<?php include_once('common/header.php'); ?>
<?php include_once('common/menu.php') ?>>
<div class="content">
<div class="header">
<h1 class="page-title">更新职位</h1>
</div>
<ul class="breadcrumb">
<li><a href="jobList.php">职位列表</a> <span class="divider">/</span></li>
<li class="active">更新职位</li>
</ul>
<div class="container-fluid">
<div class="row-fluid">
<div class="well">
<div id="myTabContent" class="tab-content">
<div class="tab-pane active in" id="home">
<form method="post" enctype="multipart/form-data">
<label>职位</label>
<input type="text" name="name" placeholder="请输入新的职位名称" class="input-xxlarge">
<label>部门</label>
<select name="depid" id="depid">
<option value="0">请选择</option>
</select>
<label></label>
<input class="btn btn-primary" type="submit" value="提交" />
</form>
</div>
</div>
</div>
<?php include_once('common/footer.php'); ?>
</div>
</div>
</div>
</body>
</html>
<?php include_once('common/script.php'); ?>
<script>
// 立即执行函数 --> 设置表单默认值
(async function() {
// 加载部门数据
await $.ajax({
type: 'post',
url: 'api.php',
data: {
action: 'dep',
adminid: <?php echo $LoginAdmin['id'] ?>
},
dataType: 'json',
success: res => {
if (res.code === 0) {
console.log(res.msg);
} else {
let option = '';
for (let item of res.data) {
option += `<option value="${item.id}">${item.name}</option>`;
}
$('#depid').append(option);
}
}
});
// 获取更新对象
let param_str = location.search;
let lt = param_str.lastIndexOf('=');
let id = param_str.substring(lt + 1);
let job;
await $.ajax({
type: 'post',
url: 'api.php',
data: {
action: 'get_job_by_id',
adminid: <?php echo $LoginAdmin['id']; ?>,
id
},
dataType: 'json',
success: res => {
if (res.code == 0) {
console.log(res.msg);
} else {
job = res.data
}
}
});
// 设置表单默认值
//
$('input[name="name"]').val(job.name);
// 部门
$('select[name="depid"]').val(job.depid);
})();
</script>
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/JIE_XIAOQIU/company.git
git@gitee.com:JIE_XIAOQIU/company.git
JIE_XIAOQIU
company
company
master

搜索帮助

0d507c66 1850385 C8b1a773 1850385