PHP implements process management and php implements process management.
Core logic: process management plays an important role in various systems. You can put a set process into the system and specify several nodes. As long as all nodes pass, you can pass.
Create four database tables:
1. We will first create a new flow page flow. php, and first make the node ready.
<! DOCTYPE html> // Add the node button and click $ ("# add "). click (function () {var uid = $ ("# users "). val (); $. ajax ({url: "flowchuli. php ", type:" POST ", data: {uid: uid, type: 0}, dataType:" TEXT ", success: function () {window. location. href = "flow. php ";}});})
// Add $ (". del "). click (function () {var k = $ (this ). attr ("code"); // get index attributes $. ajax ({url: "flowchuli. php ", type:" POST ", data: {k: k, type: 1}, dataType:" TEXT ", success: function () {window. location. href = "flow. php ";}}) ;}) // Add $ (" # addbtn ") to the Save button "). click (function () {var name = $ ("# name "). val (); $. ajax ({url: "flowchuli. php ", type:" POST ", data: {name: name, type: 2}, dataType:" TEXT ", success: function () {alert ("Added successfully! ") ;}}) ;}) </Script>
2. Create flowchuli. php
<? Phpsession_start (); require_once ". /DBDA. class. php "; $ db = new DBDA (); $ type = $ _ POST [" type "]; switch ($ type) {case 0: $ uid = $ _ POST ["uid"]; if (empty ($ _ SESSION ["jd"]) {// save node $ arr = array ($ uid ); // newly created array $ _ SESSION ["jd"] = $ arr; // saved to session} else {$ arr =$ _ SESSION ["jd"]; // retrieve the array $ arr [] = $ uid; // append the variable to the array $ _ SESSION ["jd"] = $ arr;} break; case 1: $ k = $ _ POST ["k"]; $ arr = $ _ SESSION ["jd"]; unset ($ arr [$ k]); $ arr = array_values ($ arr); // sorts the array again. If the returned value is $ _ SESSION ["jd"] = $ arr; break; case 2: $ name = $ _ POST ["name"]; $ code = time (); // automatically generated $ SQL = "insert into flow values ('{$ code }', '{$ name}') "; // Process Table $ db-> query ($ SQL); // process node table $ arr =$ _ SESSION [" jd "]; foreach ($ arr as $ k => $ v) {$ SQL = "insert into flowpath values (0, '{$ code}', '{$ v }', {$ k}) "; $ db-> query ($ SQL);} break ;}
Effect
Click "select node personnel" to adjust the list of all personnel from the database. Now, put "Li Si", "Ma Qi", and "Zhang San" in the process to complete the leave process:
Note: The Code must use varchar instead of time, because the timestamp is used above.
3. Now we have logged on to the user page flowlogin. php and submitted all the steps for the leave process:
<! DOCTYPE html> // Click Event of the logon button $ ("# login "). click (function () {var uid = $ ("# uid "). val (); var pwd = $ ("# pwd "). val (); $. ajax ({type: "post", url: "flowloginchuli. php ", data: {uid: uid, pwd: pwd}, dataType:" TEXT ", success: function (data) {if (data. trim () = "OK") {window. location. href = "flowmain. php ";} else {alert (" incorrect user name or password! ") ;}}}) ;}) </Script>
4. After logging on to the homepage, jump to flowmain. php.
<! DOCTYPE html>
5. Initiate flow. php
<! DOCTYPE html>
6. flowfq. php
<?phpsession_start();require_once "./DBDA.class.php";$db = new DBDA();$code = $_POST["flow"];$uid = $_SESSION["uid"];$content = $_POST["content"];$time = date("Y-m-d H:i:s");$sql = "insert into userflow values(0,'{$code}','{$uid}','{$content}',0,'{$time}',0)";$db->query($sql);header("location:flowmain.php");
7. Audit page flowsh. php
<! DOCTYPE html>
8. flowshchuli. php
<? Phpsession_start (); $ uid = $ _ SESSION ["uid"]; require_once ". /DBDA. class. php "; $ db = new DBDA (); $ ids = $ _ GET [" ids "]; $ SQL = "update userflow set towhere = towhere + 1 where ids = '{$ ids}'"; $ db-> query ($ SQL); // judge; whether the process ends (use related subqueries) $ swc = "update userflow a set isok = 1 where ids = '{$ ids}' towhere> = (select count (*) from flowpath B where B. code =. code) "; header (" location: flowsh. php ");
Process results
Li Si's page:
After clicking "pass:
Database: The process ends after towhere is changed to 1.
Then, Ma Qi:
Then there is James:
Database: The process ends after isok is changed to 1.