Repository navigation
Expand file tree
/
Copy pathtransport.php
More file actions
131 lines (110 loc) · 3.92 KB
/
Copy pathtransport.php
File metadata and controls
131 lines (110 loc) · 3.92 KB
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
<?php
require_once("./included_functions.php");
require_once("session.php");
new_header("Transportation Assignment", "");
//outputs message letting you know if it worked or not
$mysqli = db_connection();
if (($output = message()) !== null) {
echo $output;
}
//project number that you want to change the transportation assignment of
$num=$_GET["project"];
//puts in headers on web page
echo "<div style='width: 65%; padding-left: 35%;'>";
echo "<center>";
echo "<h3>Assign Transportation</h3>";
echo "</center>";
echo "<div style='text-align: left;'>";
//condition to check if you submited something
if (isset($_POST["submit"])) {
//makes sure you filled in all boxes
if(isset($_POST["transport"]) && $_POST["transport"] !== ""){
//create query to update transportation assignment of
$query2 = "Select number from Transportation where type='".$_POST['transport']."'";
$result2 = $mysqli->query($query2);
if($result2 && $result2->num_rows >= 1){
while($row=$result2->fetch_assoc()){
$transportNum = $row['number'];
}
}
$query="UPDATE Projects SET transportation=".$transportNum." WHERE Project_Number=".$num;
//execute query
$result = $mysqli->query($query);
//checks if there is a result
if($result) {
//if added to the database posts and redirects to project table
$_SESSION["message"] = "Has been updated";
redirect_to("execProjectView.php");
exit;
}
else {
//if a problem occured with adding to the database
$_SESSION["message"] = "Error! Could not update";
redirect_to("execProjectView.php");
exit;
}
}
else{
$query="UPDATE Projects SET transportation=NULL WHERE Project_Number=".$num;
//execute query
$result = $mysqli->query($query);
//checks if there is a result
if($result) {
//if added to the database posts and redirects to project table
$_SESSION["message"] = "Has been updated";
redirect_to("execProjectView.php");
exit;
}
else {
//if a problem occured with adding to the database
$_SESSION["message"] = "Error2! Could not update";
redirect_to("execProjectView.php");
exit;
}
}
// else {
// //sets message to remind you to fill in all boxes if you forgot one
// $_SESSION["message"] = "Unable to update!";
// header("Location: transport.php");
// exit;
// }
}
else {
//creates form
echo "<form method='POST' action='transport.php?project=".$num."'>";
echo "Select transportation:<select name='transport'>";
$query = "Select type, number from Transportation";
$result = $mysqli->query($query);
if($result && $result->num_rows >= 1){
while($row=$result->fetch_assoc()){
$query2 = "Select transportation from Projects where Project_Number=".$num;
$result2 = $mysqli->query($query2);
if($result2 && $result2->num_rows >= 1){
while($row2=$result2->fetch_assoc()){
if($row['number'] === $row2['transportation']){
echo"<option selected='selected'>".$row['type']."</option>";
echo "<option value = ''>None</option>";
}
else{
echo "<option value = '".$row['type']."'>".$row['type']."</option>";
}
//option selected if that is what it was previously set to
if($row2['transportation'] === null && $row['number'] == 2){
echo"<option selected='selected'>None</option>";
}
}
}
}
}
// options for organizations to select gathered from the database
echo "</select>";
echo "<input type='submit' name='submit' class='button tiny round' value='Assign'>";
echo "</form>";
}
echo "</div>";
echo "</div>";
//adds link back to main page where you can navigate to what you want to do
echo "<br /><p>«:<a href='execProjectView.php'>Back to Projects</a>";
echo "<br /><p>«:<a href='index.php'>Back to Main Page</a>";
?>
<?php new_footer("Who's Who", $mysqli); ?>