/
addbusform.php
192 lines (170 loc) · 8.66 KB
/
addbusform.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
181
182
183
184
185
186
187
188
189
190
191
192
<?php
require_once 'garageTableGateway.php'; //require the garage table gateway
require_once 'connection.php'; //require the connection to the database
require_once 'busTableGateway.php'; //tequire the bus table gateway
$connection = Connection::getInstance(); //Use the connection class getinstance of the connection
$gateway = new garageTableGateway($connection); //use the connection to connect to the garage table
$garages = $gateway->getGarages(); //$garages will use the gateway to get Garages for viewing the garage a bus is assigned too
//Function to set the value of the formdata to the respective fieldname
function setValue($formdata, $fieldname) {
if (isset($formdata) && isset($formdata[$fieldname])) {
echo $formdata[$fieldname];
}
}
//Function to set the check boxs to the value
function setChecked($formdata, $fieldName, $fieldValue) {
if (isset($formdata[$fieldName]) && isset($formdata[$fieldName])) {
if (is_array($formdata[$fieldName]) && in_array($fieldValue, $formdata[$fieldName])) {
echo 'checked = "checked"';
} else if ($formdata[$fieldName] == $fieldValue) {
echo 'checked = "checked"';
}
}
}
if (!isset($formdata)) {
$formdata = array();
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Add Bus Form</title>
<!--all styles and scripts will be contained in these php scripts-->
<?php require 'utilities/styles.php'; ?>
<?php require 'utilities/scripts.php'; ?>
</head>
<body>
<div class="container-fluid">
<!--container for the content.-->
<div class="row">
<!--row to hold the header-->
<?php require 'utilities/header.php'; ?>
</div>
<!--All content in container-->
<!--All data will be displayed from database-->
<!-- Opening databse area -->
<div class="row page-header home_content ">
<br>
<hr>
<h4 class="center-content">Bus Add</h4>
<hr>
<!-- Opening form area -->
<form action="createBus.php" id="databaseAdd" name="databaseAdd"
method="POST" class="form-horizontal col-lg-push-2 col-lg-8 col-lg-pull-2" >
<!-- Data will go inside of here -->
<div class="form-group">
<!--keeps form data together-->
Registration Number
<input type="text" id="regNum" name="regNum" class="form-control"
value="<?php setValue($formdata, 'regNum') ?>"/><span class="errors"
id="regError">
<!-- Garage address errors will go here -->
<?php
if (isset($errors['regNum']))//if there are any errors in the field
// output the error message
echo $errors['regNum'];
?>
</span>
</div>
<div class="form-group">
<!--keeps form data together-->
Bus Make
<input type="text" id="make" name="make" class="form-control"
value="<?php setValue($formdata, 'make') ?>"/><span class="errors" id="makeError">
<!-- Phone errors will go here -->
<?php
if (isset($errors['make'])) //if there are any errors in the field
// output the error message
echo $errors['make'];
?>
</span>
</div>
<div class="form-group">
<!--keeps form data together-->
Bus Model
<input type="text" id="model" name="model" class="form-control"
value="<?php setValue($formdata, 'model') ?>"/><span class="errors"
id="modelError">
<!-- Manager name errors will go here -->
<?php
if (isset($errors['model']))//if there are any errors in the field
// output the error message
echo $errors['model'];
?>
</span>
</div>
<div class="form-group">
<!--keeps form data together-->
Engine Size
<input type="text" id="engine" name="engine" class="form-control"
value="<?php setValue($formdata, 'engine') ?>"/> <span class="errors"
id="engineError">
<?php
if (isset($errors['engine']))//if there are any errors in the field
// output the error message
echo $errors['engine'];
?>
<!-- Garage Name Errors will go here -->
</span>
</div>
<div class="form-group">
<!--keeps form data together-->
Date Bought
<input type="text" id="boughtDate" name="boughtDate" class="form-control"
value="<?php setValue($formdata, 'boughtDate') ?>" placeholder="(yyyy/mm/dd)"/><span class="errors" id="dateError">
<!-- Date Error will go here -->
<?php
if (isset($errors['boughtDate']))//if there are any errors in the field
// output the error message
echo $errors['boughtDate'];
?>
</span>
</div>
<div class="form-group">
<!--keeps form data together-->
Next Service
<input type="text" id="service" name="service" class="form-control"
value="<?php setValue($formdata, 'service') ?>"/><span class="errors"
id="serviceError">
<!-- Email Error will go here -->
<?php
if (isset($errors['service']))//if there are any errors in the field
// output the error message
echo $errors['service'];
?>
</span>
</div>
<div class="form-group">
<!--keeps form data together-->
Garage Id
<select id="gID" name="gID" class="form-control" value="<?php setValue($formdata, 'gID') ?>"/>
<?php
foreach ($garages as $garage) {
echo '<option value="' . $garage['garageID'] . '">' . $garage['nameofGarage'] . '</option>';
}
?></select><span class="errors" id="idError">
<!-- URL Error will go here -->
<?php
if (isset($errors['gID']))//if there are any errors in the field
// output the error message
echo $errors['gID'];
?>
</span>
</div>
<div class="form-group">
<!--keeps form data together-->
<input type="submit"
id="addbus"
value="Add Bus"
name="add"
class="btn btn-success">
</div>
<!-- Closing data area -->
<!-- Closing form area -->
</form>
</div>
<!--Closing container-->
</div>
<?php require 'utilities/footer.php'; ?>
</body>
</html>