PHP语言 -- 新建流程
<body> <h1>新建流程</h1> <div> <div>请选择节点人员代号:</div> <div> <?php session_start() include "DBDA.php"; $db = new DBDA(); $sqlu = "select * from Users"; $attru = $db->Query($sqlu); foreach($attru as $arru) { echo "<input type='radio' value ='{$arru[0]}' class='user' name='user' />{$arru[2]} "; } ?> </div> <input type="button" value="添加节点" id="addjd" /> <div> <?php if(empty($_SESSION["user"])) { echo "当前节点人员为空"; } else { $attr = $_SESSION["user"]; foreacho ($attr as $k=>$v) { $sqlname ="select Name from Users where Uid='{$v}'"; $name = $db->StrQuery($sqlname); echo "<div>{$k}--{$name}-<input type='button' value='删除' bs='{$k}' class='del'/></div>"; } } ?> </div>
<div>请输入流程名称:<input type="text" id="lcname" /></div>
<div><input type="button" id="sure" value="添加" /></div>
</div>
<div><a href = "Main.php">返回</a></div> <script type="text/javascript"> $(document).ready(function(e){
//添加节点 $("#addjd").click(function(){ var user = $(".user"); for(var i=0;i<user.length;i++) { if(user.eq(i)[0].checked) { var uid = user.eq(i).val(); $.ajax({ url:"addjd.php", data:{uid:uid}, type:"POST", dataType:"TEXT", success:function(data){
windiow.location = "xinjian.php" } }); } } })
//删除节点
$(".del").click(function(){
var code = $(this).attr("bs")
$.ajax({
url:"del.php",
data:{code:code},
type:"POST",
datatype:"TEXT"
success:function(data){
window.location = "xinjian.php";
}
});
})
//添加(新建流程)
$("#sure").click(function(){
var name = $("#lcname").val();
$.ajax({
url:"add.php",
data:{name:name},
dataType: "TEXT",
type:"POST",
success:function(data){
alert($data);
}
});
})
}); </script> </body>
addjd.php
<?php session_start(); $uid = $_POST["uid"]; if(empty($_SESSION["user"])) { $attr = array($uid); $_SESSION["user"] = $attr; } else { $attr = $_SESSION["user"]; array_push($attr,$uid);//追加元素 $_SESSION["user"]=$attr //覆盖原来的session }
del.php
<?php session_start(); $code = $_POST["code"]; $attr = $_SESSION["user"]; unset($attr[$code]); //删除数据 $attr = array_values($attr); $_SESSION["user"]=$attr;
add.php
<?php session_start(); include "DBDA.php"; $db = new DBDA(); $name = $_POST["name"]; if(empty($_SESSION["user"])) { echo "请选择节点人员"; } else { $attr = $_SESSION["user"]; $code = date("YmdHis",time()); $sqll = "insert into LiuCheng values('{$code}','{$name}')"; if($db->Query($sqll,0)) { foreach($attr as $K=>$v) { $sqlf = "insert into FlowPath values('','{$code}','{$v}','{$k}')"; $db->Query($sqlf,0); } } echo "添加成功"; }