PHP process control and PHP Process Control

Source: Internet
Author: User

PHP process control and PHP Process Control

In a company, employees must have high-level, middle-level, and general employees. In this way, if a company employee encounters a problem and needs to ask for leave or make some requests, you need to apply. Some of the applications can be directly applied to your superiors. Sometimes, the most important thing is that you must apply for them at different layers to solve the problem, this reminds us of the process. Today we are writing a simple process control. The design of the table personnel may be less accurate, but the logic is the same.

Here I have designed four tables in the database: users flowpath liucheng userflow

 

The above shows the four tables I used. Now I want to display all the employee names, which of the following persons can be selected before the application can be completed? Then, we need to enter the information we want to apply for. Finally, we need to save and hand it in so that the superior can agree.

First, I want to create the main page. php displays the content I need, and then displays the button function in it. If the content is simple, php is embedded directly, others are called Using ajax, which may seem clearer. ps: of course, this is self-feeling.

There is no doubt that jquery will be used, so we need to call the jquery package first.

<script src="jquery-3.1.1.min.js"> </script>

At the beginning of the home page, we still need to display the employee's names so that we can easily select node characters. I use the embedded php method. This step is the most basic and will certainly be clear, I will not describe it in detail here

1 

Next is the button for adding nodes.

<Div> <input type = "button" value = "add node" id = "jd"/> </div>

Now that the button already exists, we will think of the button function: to add the node personnel selected above to the bottom of the button

// Add a node Click Event $ ("# jd "). click (function () {var uid = $ ("# user "). val (); // click "add node" to add the value in the select statement. Then, we need to extract the value $. ajax ({url: "chuli. php ", data: {uid: uid}, type:" POST ", dataType:" TEXT ", success: function (data) {window. location. href = "main. php "; // refresh the page }});})

The processing page is similar to the function of adding a shopping cart. First we will think of the content in the current node. If not, we need to create an array first, and then store the existing content using session.

1 <? Php 2 session_start (); // you must first enable session 3 4 $ uid =$ _ POST ["uid"]; 5 if (empty ($ _ SESSION ["user"]) // if there is no content in the node, you need to create an array first, put the uid in it and save 6 {7 $ arr = array ($ uid); 8 $ _ SESSION ["user"] = $ arr; 9} 10 else // If the content already exists, store the content in the array 11 {12 $ arr =$ _ SESSION ["user"]; 13 array_push ($ arr, $ uid); 14 $ _ SESSION ["user"] = $ arr; 15}

 After the processing page is written, return to the node to be added. If the node is not empty, we need to display the added node, if it is null, nothing will be displayed (you don't need to consider it here ),

<? Phpif (! Empty ($ _ SESSION ["user"]) {$ attr = $ _ SESSION ["user"]; foreach ($ attr as $ k => $ v) {$ sname = "select name from users where uid = '{$ v}'"; $ name = $ db-> StrQuery ($ sname ); echo "<div> {$ k} -- {$ name} -- <input type = 'button 'value = 'Delete 'key =' {$ k} 'class = 'del' /> </div> "; // It will be simpler to use indexes here. What we can use for indexes is $ k }}?>

Click "add node". The delete button is displayed. The next step is to click "delete". Here, ajax is used.

 

<div><input type="text" id="nr"/></div>

 

1 // Click Event 2 $ (". del "). click (function () {3 var key = $ (this ). attr ("key"); // It is very convenient to take the key value in the deletion. ajax ({5 url: "shanchu. php ", 6 data: {key: key}, 7 type:" POST ", 8 dataType:" TEXT ", 9 success: function (aa) 10 {11 window. location. href = "main. php "; 12} 13}) 14 })

The code for deleting a page is as follows:

<? Phpsession_start (); $ arr =$ _ SESSION ["user"]; // Save the content of the previous node to $ arr $ key = $ _ POST ["key"]; // retrieve the index value unset ($ arr [$ key]); // Delete the selected $ arr = array_values ($ arr ); // re-arrange the order of existing nodes $ _ SESSION ["user"] = $ arr;

After the deletion is completed, click Delete to delete the added content. Then, we need to consider entering the content process name and finally saving the added node and the written process name.

1 <div> enter the process name: <input type = "text" id = "nr"/> </div> 2 <br/> 3 <input type = "button" value = "save" id = "btn "/>
1 // Click Event 2 $ ("# btn") for the Save button "). click (function () {3 var nr = $ ("# nr "). val (); 4 $. ajax ({5 url: "baocun. php ", 6 data: {nr: nr}, 7 type:" POST ", 8 dataType:" TEXT ", 9 success: function (bc) {10 alert ("saved successfully"); 11 12} 13 14}) 15 })
1 <? Php 2 session_start (); 3 include ("DADB. class. php "); 4 $ db = new DADB (); 5 $ nr = $ _ POST [" nr "]; 6 $ code = time (); 7 $ SQL = "insert into liucheng VALUES ('{$ code}', '{$ nr }')"; // Add content 8 $ db-> Query ($ SQL, 0) to the liucheng table ); 9 10 // After the node is added to the liucheng table, the node is saved as 11 12 $ arr = $ _ SESSION ["user"] in the flowpath table. 13 foreach ($ arr as $ k => $ v) 14 {15 $ sqn = "insert into flowpath VALUES ('', '{$ code }', '{$ v}', '{$ k}') "; 16 $ db-> Query ($ sqn, 0); 17}

You can save it here. Click "save" and refresh the database to display the saved content.

After the application is submitted, we will consider who will review the application. It involves whether the application has been approved after a superior logon, because it has been written many times before logon, I will not write any more here, just use a simple pseudo-login.

 

<Body> <? Phpsession_start (); $ _ SESSION ["user"] = "zhangsan"; // The username here can be changed to any one in the database to check whether it has been reviewed, or is the review approved?> </Body>

 

Now we have to launch the process.

1 

When you see the launch button, you will naturally think of a click event for the launch button. Then there will be a click event to process the page. We use chuli1.php to add content to the userflow table.

1 <script type = "text/javascript"> 2 $ ("# faqi "). click (function () {3 var lc = $ ("# liucheng "). val (); 4 var text = $ ("# text "). val (); 5 $. ajax ({6 url: "chuli1.php", 7 data: {lc: lc, text: text}, 8 type: "POST", 9 dataType: "TEXT", 10 success: function (data) {11 alert ("initiated successfully"); 12} 13}) 14}) 15 </script>
<? Phpsession_start (); $ uid = $ _ SESSION ["user"]; // $ code = $ _ POST ["lc"] stored on the pseudo-Logon page; // $ content =$ _ POST ["text"] passed from the launch page; $ time = date ("Y-m-d H: m: s "); include ("DADB. class. php "); $ db = new DADB (); $ SQL =" insert into userflow VALUES ('', '{$ code}', '{$ uid }', '{$ content}', 0, '{$ time}', 0) "; // add content to userflow $ db-> Query ($ SQL, 0 );

The review page is displayed after the launch.

 

1 

 

Below is the page,

<? Phpsession_start (); include (".. /fengzhuang/DBDA. class. php "); $ db = new DBDA (); // process down $ code = $ _ GET [" code "]; $ SQL = "update userflow set towhere = towhere + 1 where ids = '{$ code}'"; $ db-> Query ($ SQL, 0 ); // determine whether the process ends $ SQL = "select * from userflow where ids = '{$ code}'"; $ arr = $ db-> Query ($ SQL ); $ lcdh = $ arr [0] [1]; // Process Code $ tw = $ arr [0] [6]; // where the process goes $ SQL = "select count (*) from flowpath where code = '{$ lcdh}'"; $ count = $ db-> StrQuery ($ SQL ); // number of nodes in the process if ($ tw >=$ count) {$ SQL = "update userflow set isok = 1 where ids = '{$ code }'"; $ db-> Query ($ SQL, 0);} header ("location: shenhe. php ");

Note: If you use pseudo-Logon, you must first run it and then run other pages. Otherwise, the uid cannot be obtained.

 

 

 

 

 

 

 

 

 

 

 

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.