-
Notifications
You must be signed in to change notification settings - Fork 0
/
create_offer.php
204 lines (183 loc) · 4.81 KB
/
create_offer.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
193
194
195
196
197
198
199
200
201
202
203
204
<?php
require_once('header.php');
$request_id = $_GET['request_id'];
$request = new Request($db_host, $db_name, $db_user, $db_pass);
$req = $request->getById($request_id);
if(!$req) {
header('Location: requests.php');
}
$title = '';
$description = '';
$amount = '';
$price = '';
$quality = '';
$delivery_date = '';
$sent = false;
if(isset($_POST['form_sent'])) {
$sent = true;
if($_POST['title']) {
$title = $_POST['title'];
} else {
$error['title'] = true;
}
if($_POST['description']) {
$description = $_POST['description'];
} else {
$error['description'] = true;
}
if($_POST['delivery_date']) {
$delivery_date = $_POST['delivery_date'];
$delivery_date = date("Y-m-d", strtotime($delivery_date));
} else {
$error['delivery_date'] = true;
}
if($_POST['amount']) {
$amount = str_replace(" ", '', $_POST['amount']);
if(!is_numeric($amount)) {
$error['amount'] = true;
}
} else {
$error['amount'] = true;
}
if($_POST['price']) {
$price = str_replace(" ", '', $_POST['price']);
if(!is_numeric($price)) {
$error['price'] = true;
}
} else {
$error['amount'] = true;
}
if($_POST['quality']) {
$quality = $_POST['quality'];
} else {
$error['quality'] = true;
}
if(empty($error)) {
$offer = new Offer($db_host, $db_name, $db_user, $db_pass);
$offer->create($req['request_id'], $_SESSION['customer_id'], $title, $description, $delivery_date, $amount, $quality, $price);
header('Location: requests.php');
}
}
?>
<main role="main" class="container">
<div class="row">
<div class="col-12 col-md-12 request-col">
<h1>Angebot zu Nachfrage <?= htmlentities($req['title']) ?> erstellen</h1>
</div>
</div>
<div class="row">
<div class="col-12 col-md-12">
<div class="form-container">
<form name="create_request" method="POST" action="" novalidate="">
<input type="hidden" name="form_sent" value="1" />
<div class="form-group">
<label for="title">Titel*</label>
<input type="text" name="title" class="form-control
<?php
if($sent) {
if(isset($error['title'])) {
echo 'is-invalid';
} else {
echo 'is-valid';
}
}
?>
" placeholder="Titel" value="<?= $title ?>">
<div class="invalid-feedback">
Titel ungültig
</div>
</div>
<div class="form-group">
<label for="description">Beschreibung*</label>
<textarea rows="10" name="description" class="form-control
<?php
if($sent) {
if(isset($error['description'])) {
echo 'is-invalid';
} else {
echo 'is-valid';
}
}
?>
" ><?= $description ?></textarea>
<div class="invalid-feedback">
Beschreibung ungültig
</div>
</div>
<div class="form-group">
<label for="delivery_date">Lieferdatum*</label>
<input type="text" id="datepicker" name="delivery_date" class="form-control
<?php
if($sent) {
if(isset($error['delivery_date'])) {
echo 'is-invalid';
} else {
echo 'is-valid';
}
}
?>
" id="delivery_date" placeholder="Lieferdatum" value="<?= $delivery_date ?>">
<div class="invalid-feedback">
Lieferdatum ungültig
</div>
</div>
<div class="form-group">
<label for="amount">Menge*</label>
<input type="text" name="amount" class="form-control
<?php
if($sent) {
if(isset($error['amount'])) {
echo 'is-invalid';
} else {
echo 'is-valid';
}
}
?>
" id="amount" placeholder="Menge" value="<?= $amount ?>">
<div class="invalid-feedback">
Menge ungültig
</div>
</div>
<div class="form-group">
<label for="price">Preis*</label>
<input type="text" name="price" class="form-control
<?php
if($sent) {
if(isset($error['price'])) {
echo 'is-invalid';
} else {
echo 'is-valid';
}
}
?>
" id="price" placeholder="Preis" value="<?= $price ?>">
<div class="invalid-feedback">
Preis ungültig
</div>
</div>
<div class="form-group">
<label for="quality">Qualität*</label>
<input type="text" name="quality" class="form-control
<?php
if($sent) {
if(isset($error['quality'])) {
echo 'is-invalid';
} else {
echo 'is-valid';
}
}
?>
" id="quality" placeholder="Qualität" value="<?= $quality ?>">
<div class="invalid-feedback">
Qualität ungültig
</div>
</div>
<button type="submit" class="btn btn-primary">Absenden</button>
</form>
</div>
</div>
</div>
</main>
<?php
require_once('footer.php');
?>