-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpage-1.php
195 lines (171 loc) · 7.12 KB
/
page-1.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
<?php
require_once('database.php');
// Get clinics
$queryClinic = 'SELECT * FROM Clinic';
$statement = $db->prepare($queryClinic);
$statement->execute();
$clinics = $statement->fetchAll();
$statement->closeCursor();
// Get treatment types
$queryTreatmentType = 'SELECT * FROM Treatment_TypeI';
$statement = $db->prepare($queryTreatmentType);
$statement->execute();
$treatmentTypes = $statement->fetchAll();
$statement->closeCursor();
// TREATMENT_TYPESI DATA - self applied PHP features
// Default sorting by clinic name
if (isset($_GET['sort'])) {
if ($_GET['sort'] == 'name_asc') {
usort($treatmentTypes, function ($a, $b) {
return strcmp($a['name'], $b['name']);
});
} else if ($_GET['sort'] == 'name_desc') {
usort($treatmentTypes, function ($a, $b) {
return strcmp($b['name'], $a['name']);
});
}
}
// Sorting function by price // self applied PHP features
if (isset($_GET['sort'])) {
if ($_GET['sort'] == 'asc') {
usort($treatmentTypes, function ($a, $b) {
return $a['price'] - $b['price'];
});
} else if ($_GET['sort'] == 'desc') {
usort($treatmentTypes, function ($a, $b) {
return $b['price'] - $a['price'];
});
}
}
// CLINIC DATA- self applied PHP features
// Sorting function by telephone
if (isset($_GET['sort'])) {
if ($_GET['sort'] == 'phone_asc') {
usort($clinics, function ($a, $b) {
return strcmp($a['Clinic_Telephone'], $b['Clinic_Telephone']);
});
} else if ($_GET['sort'] == 'phone_desc') {
usort($clinics, function ($a, $b) {
return strcmp($b['Clinic_Telephone'], $a['Clinic_Telephone']);
});
}
}
// Sorting function by address // self applied PHP features
if (isset($_GET['sort'])) {
if ($_GET['sort'] == 'address_asc') {
usort($clinics, function ($a, $b) {
return strcmp($a['Clinic_Address'], $b['Clinic_Address']);
});
} else if ($_GET['sort'] == 'address_desc') {
usort($clinics, function ($a, $b) {
return strcmp($b['Clinic_Address'], $a['Clinic_Address']);
});
}
}
// Search function // self applied PHP features
if(isset($_GET['search'])) {
$search = $_GET['search'];
$treatmentTypes = array_filter($treatmentTypes, function($treatment) use ($search) {
return strpos(strtolower($treatment['name']), strtolower($search)) !== false;
});
}
?>
<?php include 'includes/header.php'; ?>
<main>
<div class="container">
<h5>Our Dental Treatment</h5>
<div class="row">
<div class="col-md-12">
<!--- self applied PHP features---->
<div class="row">
<div class="col-md-6">
<form method="get" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<label for="sort-name">Sort by name:</label>
<select name="sort" id="sort-name" class="form-control" onchange="this.form.submit()">
<option value="">Select an option</option>
<option value="name_asc" <?php if (isset($_GET['sort']) && $_GET['sort'] === 'name_asc') { echo 'selected'; } ?>>A-Z</option>
<option value="name_desc" <?php if (isset($_GET['sort']) && $_GET['sort'] === 'name_desc') { echo 'selected'; } ?>>Z-A</option>
</select>
</form>
</div>
<!--------------------------------->
<!--- self applied PHP features---->
<div class="col-md-6">
<form method="get" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<label for="sort-price">Sort by price:</label>
<select name="sort" id="sort-price" class="form-control" onchange="this.form.submit()">
<option value="">Select an option</option>
<option value="asc" <?php if (isset($_GET['sort']) && $_GET['sort'] === 'asc') { echo 'selected'; } ?>>Low to High</option>
<option value="desc" <?php if (isset($_GET['sort']) && $_GET['sort'] === 'desc') { echo 'selected'; } ?>>High to Low</option>
</select>
</form>
</div>
</div>
<!--------------------------------->
</div>
<?php foreach ($treatmentTypes as $treatment) : ?>
<div class="col-md-3 mb-3">
<div class="text-center">
<img class="form-image" src="images/<?php echo $treatment['image']; ?>" alt="<?php echo $treatment['name']; ?>" class="img-fluid">
</div>
<h4><?php echo $treatment['name']; ?></h4>
<p><strong>Price: </strong> €<?php echo $treatment['price']; ?></p>
<p><strong>Duration: </strong><?php echo $treatment['duration']; ?> minutes</p>
<p><strong>Materials: </strong><?php echo $treatment['materials']; ?></p>
<form action="contact.php" method="post">
<input type="hidden" name="record_type" value="treatment_type">
<input type="hidden" name="record_id" value="<?php echo $treatment['id']; ?>">
<input type="submit" value="Book now" class="btn btn-primary">
</form>
</div>
<?php endforeach; ?>
</div>
</div>
<div class="container">
<h5>Visit any of our Clinic around the country </h5>
<div class="col-md-12">
<div class="row">
<!--- self applied PHP features---->
<div class="col-md-6">
<form method="get" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<label for="sort">Sort by address:</label>
<select name="sort" id="sort" class="form-control" onchange="this.form.submit()">
<option value="">Select an option</option>
<option value="address_asc" <?php if (isset($_GET['sort']) && $_GET['sort'] === 'address_asc') { echo 'selected'; } ?>>Low to High</option>
<option value="address_desc" <?php if (isset($_GET['sort']) && $_GET['sort'] === 'address_desc') { echo 'selected'; } ?>>High to Low</option>
</select>
</form>
</div>
<!--------------------------------->
<!--- self applied PHP features---->
<div class="col-md-6">
<form method="get" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<label for="sort">Sort by phone:</label>
<select name="sort" id="sort" class="form-control" onchange="this.form.submit()">
<option value="">Select an option</option>
<option value="phone_asc" <?php if (isset($_GET['sort']) && $_GET['sort'] === 'phone_asc') { echo 'selected'; } ?>>Low to High</option>
<option value="phone_desc" <?php if (isset($_GET['sort']) && $_GET['sort'] === 'phone_desc') { echo 'selected'; } ?>>High to Low</option>
</select>
</form>
</div>
</div>
<!--------------------------------->
</div>
<div class="row">
<?php foreach ($clinics as $clinic) : ?>
<div class="col-md-3 mb-3">
<h4><?php echo $clinic['Clinic_Name']; ?></h4>
<p><strong>Address:</strong> <a href="https://www.google.com/maps/search/?api=1&query=<?php echo urlencode($clinic['Clinic_Address']); ?>"><?php echo $clinic['Clinic_Address']; ?></a></p>
<p><strong>Telephone:</strong> <a href="tel:<?php echo $clinic['Clinic_Telephone']; ?>"><?php echo $clinic['Clinic_Telephone']; ?></a></p>
<p><strong>Email:</strong> <?php echo $clinic['Clinic_Email']; ?></p>
<form action="contact.php" method="post">
<input type="hidden" name="record_type" value="clinic">
<input type="hidden" name="record_id" value="<?php echo $clinic['Clinic_Id']; ?>">
<input type="submit" value="Book now" class="btn btn-primary">
</form>
</div>
<?php endforeach; ?>
</div>
</div>
</main>
<?php include 'includes/footer.php'; ?>