-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfindapet.jsp
259 lines (223 loc) · 9.8 KB
/
findapet.jsp
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
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page import="pawfect_home.*"%>
<%@ page import="java.text.SimpleDateFormat, java.util.List, java.util.ArrayList,java.time.LocalDate, java.time.format.DateTimeFormatter, java.time.temporal.ChronoUnit, java.time.ZoneId, java.util.Date" %>
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>List of listing</title>
<link rel="stylesheet" href="css/findapet.css">
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-KK94CHFLLe+nY2dmCWGMq91rCGa5gtU4mk92HdvYe+M/SXH301p5ILy+dN9+nJOZ" crossorigin="anonymous">
<link href="https://fonts.googleapis.com/css?family=Quicksand:400,700&display=swap" rel="stylesheet">
<style>
body {
overflow-x: hidden;
}
</style>
</head>
<body>
<!--navbar-->
<header>
<%@ include file= "navbar.jsp" %>
</header>
<div class = background>
<!-- Background Image with Title -->
<div class="bg-image">
<div class="container">
<div class = text-box>
<div class="title">
<h1>Find your temporary pet</h1>
</div >
<p class = "text">Browse our listings to find <br>the pawfect temporary companion!</p>
</div>
</div>
</div>
<!--Ratio buttons-->
<div class = h2>
<h2>Discover Our Listings</h2>
</div>
<%
int numberpost = 0;
if (user == null) {
%>
<div class="text-center">
<div class="alert alert-warning d-inline-block" role="alert" style="border-radius: 1rem; margin-top: 10px;">
You must be registered to declare your interest a pet!
</div>
</div>
<% } %>
<!--Group Card-->
<%
ListingDAO listingd = new ListingDAO();
List<Listing> listoflistings = listingd.getListings();
if (listoflistings.isEmpty()) { %>
<div class="text-center">
<div class="alert alert-info d-inline-block" role="info" style="border-radius: 1rem; margin-top: 10px;">
At this moment there is no pets to care.<br> Please try again later :)
</div>
</div>
<% } else {
%>
<div class="row row-cols-1 row-cols-md-3 g-4">
<%
int count = 0;
for (Listing post : listoflistings) {
count++;
UserDAO userd = new UserDAO();
PetDAO petd = new PetDAO();
User userofpost = userd.getUsersByUsername(post.getUsername());
Pet petofpost = petd.getPetByPostid(post.getPostid());
if (!(userofpost != null && petofpost != null)) {
break;
} else {
%>
<%
if (user == null || !(userofpost.getUsername().equals(user.getUsername()))) {
numberpost++;
%>
<!-- Post of pet -->
<div class="col">
<div class="card h-100">
<div class="row g-0">
<div class="col-md-6">
<img class="img-thumbnail" src="<%=petofpost.getPicture()%>" alt="Card Image" >
</div>
<div class="col-md-6">
<div class="card-body">
<h5 class="card-title"><u><%=petofpost.getPet_name() %></u></h5>
<div class="row">
<div class="col">
<p><strong>Location:</strong> <%=userofpost.getLocation() %></p>
</div>
</div>
<div class="row">
<div class="col">
<p><strong>Price:</strong> $<%=post.getPrice()%> per day</p>
</div>
</div>
<div class="row">
<div class="col">
<p><strong>Dates:</strong> <%=post.getStart_date() %> | <%=post.getEnd_date() %></p>
</div>
</div>
<div class="row">
<div class="col">
<p><small>Uploaded at <%=post.getUpload_date() %></small></p>
</div>
</div>
<button type="button" class="btn btn-success" data-toggle="modal" data-target="#cardModal<%=count%>">See More</button>
</div>
</div>
</div>
</div>
</div>
<!-- Info of pet -->
<%
String body = "";
String recipient = userofpost.getEmail();
String usernameOfOwner = userofpost.getUsername();
if (user != null) {
body = String.format("<html><body>Dear %s,<br><br>His/Her fullname is %s %s and his/her username is %s<br>More details<br>Location: %s<br>Phone: %s<br>Email: %s</body></html>" +
"<br>Please contact him/her and let him/her know about your pet!",
usernameOfOwner, user.getFirstname(), user.getLastname(), user.getUsername(),
user.getLocation(), user.getPhone(), user.getEmail());
}
%>
<form method="POST" action="findapetController.jsp" class="modal fade" id="cardModal<%=count%>" tabindex="-1" role="dialog" aria-labelledby="cardModal1Label" aria-hidden="true">
<input type="hidden" name="body" value="<%= body %>">
<input type="hidden" name="recipient" value="<%= recipient %>">
<div class="modal-dialog modal-lg" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="cardModal1Label">More Information</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<div class="row">
<div class="col-md-6">
<img src="<%=petofpost.getPicture()%>" class="img-fluid mb-2" alt="Larger Image">
</div>
<div class="col-md-6">
<h5><u><%=petofpost.getPet_name() %></u></h5>
<p>Animal: <%=petofpost.getKind_of_pet()%>
<br> Breed: <%=petofpost.getBreed()%>
<% if (post.getStay_at_owner()){ %>
<br> Stay at owner: No
<% } else { %>
<br> Stay at owner: Yes
<% } %>
<br> Location: <%=userofpost.getLastname()%>
<br>Dates: <%=post.getStart_date() %> | <%=post.getEnd_date() %>
<%
Date startDate = post.getStart_date();
Date endDate = post.getEnd_date();
// Format Date objects into strings if needed
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
String startDateString = dateFormat.format(startDate);
String endDateString = dateFormat.format(endDate);
// Calculate the difference in days
ZoneId zoneId = ZoneId.of("UTC");
long millisecondsPerDay = 24 * 60 * 60 * 1000;
long daysDifference = (endDate.getTime() - startDate.getTime()) / millisecondsPerDay;
//include and the first day
double totalPrice = (1 + daysDifference) * post.getPrice();
%>
<br>Total Price: $<%= totalPrice %>
<% if (post.getDescription().equals("")) { %>
<br> Description: None</p>
<% } else { %>
<br> Description: <%=post.getDescription()%></p>
<% }
if (user == null) {
%>
<div class="col-md-6">
<p class="danger-text" style="color: gray; font-size: smaller;">**You can not declare your interested as quest. Please sign in or login.**
</div>
<%
} else {
%>
<button type="submit" class="btn btn-success"
data-container="body" data-placement="bottom"
data-content="Are you sure for your interesting?">I am interested!
</button>
<%
}
%>
</div>
</div>
</div>
</div>
</div>
</form>
<% } %>
<% } %>
<% }
}
%>
</div>
<% if (numberpost == 0) { %>
<div class="text-center">
<div class="alert alert-warning d-inline-block" role="alert" style="border-radius: 1rem; margin-top: 10px;">
At this moment there is no pets to care from other owners.<br> Please try again later :)
</div>
</div>
<% } %>
<div>
<hr style="border: none; background-color: #49392d;">
</div>
<%@ include file="footer.jsp" %>
<!-- jQuery -->
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<link rel="stylesheet" href="path/to/bootstrap.min.css">
<script src="path/to/jquery.min.js"></script>
<script src="path/to/bootstrap.min.js"></script>
<!-- Bootstrap JavaScript -->
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.min.js"></script>
<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@popperjs/[email protected]/dist/umd/popper.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
</body>
</html>