-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathqualityTests.php
executable file
·142 lines (112 loc) · 3.93 KB
/
qualityTests.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="globalUsage/style.css" class="">
<title>Quality Tests</title>
</head>
<body>
<h1><u>Quality Tests</u></h1>
<?php include "globalUsage/dropdownmenu.html"?>
<br><br><br>
<form action="qualityTests.php" method="post" class= "sameLine" id = "flaw_form">
<input type="number" name="order_id" placeholder = "order_id" class = "qualityTest">
<input type="number" name="product_id" placeholder = "product_id" class = "qualityTest">
<select name="product_type" class = "qualityTest">
<option value="">Product</option>
<option value="cart">Cart</option>
<option value="computerbox">Computerbox</option>
</select>
<select name="state" id="state" class = "qualityTest">
<option value="">State</option>
<option value="failed">Failed</option>
<option value="minor_flaw">Minor Flaw</option>
<option value="passed">Passed</option>
</select>
<script>
function check(){
var ff = document.getElementById("flaw_form");
var state = document.getElementById("state").value;
if(state == "failed"){
ff.setAttribute('action',"flaw_page.php");
}
else{
ff.setAttribute('action',"qualityTests.php");
}
return true;
}
</script>
<input onclick = "check()" type="submit" value = "Submit Test" class = "qualityTest-submit">
</form>
<br><br><br><br><br>
<table class = "test_results">
<tr class = "test_results">
<th>order_id</th>
<th>product_type</th>
<th>product_id</th>
<th>state</th>
<th>flaw_id</th>
</tr>
<?php
require 'globalUsage/db.php';
if (!empty($_POST)) {
if(isset($_POST['order_id']) && isset($_POST['product_id']) && isset($_POST['product_type']) && isset($_POST['state'])){
$order_id = $_POST["order_id"];
$product_id = $_POST["product_id"];
$product_type = $_POST["product_type"];
$state = $_POST["state"];
// if we can insert the quality test right away (state != failed)
if($state !== "failed" && !isset($_POST['severity']) && !isset($_POST['flaw_type'])){
if($order_id !== "" && $product_id !== "" && $product_type !== "" && $state !== ""){
$quality_test_delete = "DELETE FROM quality_test WHERE quality_test.order_id = '$order_id'";
mysqli_query($link, $quality_test_delete);
$insert_quality_test = "INSERT INTO quality_test(order_id, product_type, product_id, state) VALUES
('$order_id', '$product_type', '$product_id', '$state');";
mysqli_query($link, $insert_quality_test);
}
} // when we also insert a flaw.
else{
$flaw_type = $_POST['flaw_type'];
$severity = $_POST['severity'];
$flaw_insert = "INSERT INTO flaw(flaw_type, severity) VALUES
('$flaw_type', '$severity')";
mysqli_query($link, $flaw_insert);
$flaw_id = mysqli_insert_id($link);
$quality_test_delete = "DELETE FROM quality_test WHERE quality_test.order_id = '$order_id'";
mysqli_query($link, $quality_test_delete);
$insert_quality_test = "INSERT INTO quality_test(order_id, product_type, product_id, state, flaw_id) VALUES
('$order_id', '$product_type', '$product_id', '$state', '$flaw_id');";
mysqli_query($link, $insert_quality_test);
}
}
}
$query = "SELECT * FROM quality_test WHERE quality_test.state IS NULL";
if ($result = mysqli_query($link, $query)){
if (mysqli_num_rows($result) > 0){
$i = 0;
while(($row = mysqli_fetch_assoc($result)) && $i<100){
echo "<tr><td>"
. $row["order_id"] . "</td><td>"
. $row["product_type"] . "</td><td>"
. $row["product_id"] . "</td><td>"
. $row["state"] . "</td><td>"
. $row["flaw_id"] .
"</td></tr>" ;
$i ++;
}
echo "</table>";
}else{
echo "0 results";
}
mysqli_free_result($result);
}
else if (!$result){
$message = 'Invalid query: ' .mysql_error() . "\n";
$message .= 'Whole query: ' . $query;
die($message);
}
mysqli_close($link);
?>
</body>
</html>