-
Notifications
You must be signed in to change notification settings - Fork 0
/
vender.php
180 lines (171 loc) · 5.23 KB
/
vender.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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
<!DOCTYPE html>
<?php
include 'functions.php';
// Check if any GET parameters are set. If they are, we need to get those
// results, other wise we need to set up the page for an addition to the database.
if(isset($_GET['type'], $_GET[$_GET['type']]))
{
// There was something set we need to check what it was and do a search based off of that.
// This must match the search param otherwise it won't work...
$newAdd = FALSE;
$listVendors = FALSE;
}
else if(isset($_GET['add']))
{
$newAdd = TRUE;
$listVendors = FALSE;
}
else
{
// Nothing was set and we need to load up the page to list all the venders
$listVendors = TRUE;
$newAdd = FALSE;
}
// Functions
// Load the given vendor's information.
function loadVenderValue($key)
{
$conn = connectToDB();
$sql = "SELECT * FROM ListOfVendors WHERE ".$_GET['type']."=".$_GET[$_GET['type']];
$result = $conn->query($sql);
// Check if we got any results.
if ($result->num_rows > 0)
{
// Copy over all the values in to php variables.
// i_ means int and s_ means string (varchar).
$row = $result->fetch_assoc();
return$row[$key];
}
else
{
echo "0 results for ".$_GET['type']." with value of ".$_GET[$_GET['type']];
}
$conn->close();
}
// Function to print all the venders.
function printAllVendors()
{
$conn = connectToDB();
$sql = "SELECT * FROM ListOfVendors";
$result = $conn->query($sql);
echo "<table>";
echo "<tr><th>Vendor Name</th></tr>";
if ($result->num_rows > 0)
{
// Output data of each row
while($row = $result->fetch_assoc())
{
echo "<tr><td><a href=\".\\vender.php?type=VID&VID=".$row["VID"]."\">".$row["VendorName"]."</a></td></tr>";
}
}
else
{
echo "0 results in ListOfVendors";
}
$conn->close();
}
?>
<!-- Actual page -->
<html>
<head>
<?php if($newAdd AND !$listVendors) : ?>
<title> Add New Vender </title>
<?php elseif(!$newAdd AND !$listVendors) : ?>
<title> Editing <?php echo $s_VendorName ; ?></title>
<?php else : ?>
<title> List Of All vendors </title>
<?php endif;?>
</head>
<body>
<!-- Add new Vendor Mode-->
<?php if($newAdd AND !$listVendors) : ?>
<h1> Add New Vender </h1>
<a href="./vender.php">List vendors </a>
<form action="./addVendor.php" method="post">
Vender Name:
<input type="text" name="venderName">
<br>
Address:
<input type="text" name="address" >
<br>
City:
<input type="text" name="city" >
<br>
State:
<input type="text" name="state" >
<br>
Country:
<input type="text" name="country" >
<br>
Postal Code:
<input type="text" name="zip" >
<br>
UCR Account ID:
<input type="text" name="UCRAccID" >
<br>
Contact:
<input type="text" name="contact" >
<br>
Phone:
<input type="text" name="phone" >
<br>
Fax:
<input type="text" name="fax" >
<br>
Website:
<input type="text" name="website" >
<br><br>
<input type="submit" value="Add">
</form>
<!-- Edit a vendor -->
<?php elseif(!$newAdd AND !$listVendors) : ?>
<h1> Editing <?php echo loadVenderValue("VendorName") ; ?> </h1>
<a href="./vender.php?add">Add a vendor </a>
<a href="./vender.php">List vendors </a>
<form action="updateVendor.php" method="post">
Vender ID:
<input type="text" name="vid" value="<?php echo loadVenderValue("VID") ; ?>" readonly>
<br>
Vender Name:
<input type="text" name="venderName" value="<?php echo loadVenderValue("VendorName") ; ?>">
<br>
Address:
<input type="text" name="address" value="<?php echo loadVenderValue("Address") ; ?>">
<br>
City:
<input type="text" name="city" value="<?php echo loadVenderValue("City") ; ?>">
<br>
State:
<input type="text" name="state" value="<?php echo loadVenderValue("State") ; ?>">
<br>
Country:
<input type="text" name="country" value="<?php echo loadVenderValue("Country") ; ?>">
<br>
Postal Code:
<input type="text" name="zip" value="<?php echo loadVenderValue("Zip") ; ?>">
<br>
UCR Account ID:
<input type="text" name="UCRAccID" value="<?php echo loadVenderValue("UCRAccount") ; ?>">
<br>
Contact:
<input type="text" name="contact" value="<?php echo loadVenderValue("POC") ; ?>">
<br>
Phone:
<input type="text" name="phone" value="<?php echo loadVenderValue("Phone") ; ?>">
<br>
Fax:
<input type="text" name="fax" value="<?php echo loadVenderValue("Fax") ; ?>">
<br>
Website:
<input type="text" name="website" value="<?php echo loadVenderValue("Website") ; ?>">
<br><br>
<input type="submit" value="Update">
</form>
<!-- List a vendor -->
<?php else : ?>
<h1> List Of All vendors </h1>
<a href="./vender.php?add">Add a vendor </a>
<?php printAllVendors(); ?>
<?php endif;?>
</body>
</html>