-
Notifications
You must be signed in to change notification settings - Fork 0
/
my_listings.php
159 lines (124 loc) · 4.85 KB
/
my_listings.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
<?php
include 'components/connect.php';
if(isset($_COOKIE['user_id'])){
$user_id = $_COOKIE['user_id'];
}else{
$user_id = '';
header('location:login.php');
}
if(isset($_POST['delete'])){
$delete_id = $_POST['property_id'];
$delete_id = filter_var($delete_id, FILTER_SANITIZE_STRING);
$verify_delete = $conn->prepare("SELECT * FROM `property` WHERE id = ?");
$verify_delete->execute([$delete_id]);
if($verify_delete->rowCount() > 0){
$select_images = $conn->prepare("SELECT * FROM `property` WHERE id = ?");
$select_images->execute([$delete_id]);
while($fetch_images = $select_images->fetch(PDO::FETCH_ASSOC)){
$image_01 = $fetch_images['image_01'];
$image_02 = $fetch_images['image_02'];
$image_03 = $fetch_images['image_03'];
$image_04 = $fetch_images['image_04'];
$image_05 = $fetch_images['image_05'];
unlink('uploaded_files/'.$image_01);
if(!empty($image_02)){
unlink('uploaded_files/'.$image_02);
}
if(!empty($image_03)){
unlink('uploaded_files/'.$image_03);
}
if(!empty($image_04)){
unlink('uploaded_files/'.$image_04);
}
if(!empty($image_05)){
unlink('uploaded_files/'.$image_05);
}
}
$delete_saved = $conn->prepare("DELETE FROM `saved` WHERE property_id = ?");
$delete_saved->execute([$delete_id]);
$delete_requests = $conn->prepare("DELETE FROM `requests` WHERE property_id = ?");
$delete_requests->execute([$delete_id]);
$delete_listing = $conn->prepare("DELETE FROM `property` WHERE id = ?");
$delete_listing->execute([$delete_id]);
$success_msg[] = 'listing deleted successfully!';
}else{
$warning_msg[] = 'listing deleted already!';
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>My Listings</title>
<!-- font awesome cdn link -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.2.0/css/all.min.css">
<!-- custom css file link -->
<link rel="stylesheet" href="css/style.css">
</head>
<body>
<?php include 'components/user_header.php'; ?>
<section class="my-listings">
<h1 class="heading">my listings</h1>
<div class="box-container">
<?php
$total_images = 0;
$select_properties = $conn->prepare("SELECT * FROM `property` WHERE user_id = ? ORDER BY date DESC");
$select_properties->execute([$user_id]);
if($select_properties->rowCount() > 0){
while($fetch_property = $select_properties->fetch(PDO::FETCH_ASSOC)){
$property_id = $fetch_property['id'];
if(!empty($fetch_property['image_02'])){
$image_coutn_02 = 1;
}else{
$image_coutn_02 = 0;
}
if(!empty($fetch_property['image_03'])){
$image_coutn_03 = 1;
}else{
$image_coutn_03 = 0;
}
if(!empty($fetch_property['image_04'])){
$image_coutn_04 = 1;
}else{
$image_coutn_04 = 0;
}
if(!empty($fetch_property['image_05'])){
$image_coutn_05 = 1;
}else{
$image_coutn_05 = 0;
}
$total_images = (1 + $image_coutn_02 + $image_coutn_03 + $image_coutn_04 + $image_coutn_05);
?>
<form accept="" method="POST" class="box">
<input type="hidden" name="property_id" value="<?= $property_id; ?>">
<div class="thumb">
<p><i class="far fa-image"></i><span><?= $total_images; ?></span></p>
<img src="uploaded_files/<?= $fetch_property['image_01']; ?>" alt="">
</div>
<div class="price"><i class="fas fa-usd"></i><span><?= $fetch_property['price']; ?></span></div>
<h3 class="name"><?= $fetch_property['property_name']; ?></h3>
<p class="location"><i class="fas fa-map-marker-alt"></i><span><?= $fetch_property['address']; ?></span></p>
<div class="flex-btn">
<a href="update_property.php?get_id=<?= $property_id; ?>" class="btn">update</a>
<input type="submit" name="delete" value="delete" class="btn" onclick="return confirm('delete this listing?');">
</div>
<a href="view_property.php?get_id=<?= $property_id; ?>" class="btn">view property</a>
</form>
<?php
}
}else{
echo '<p class="empty">no properties added yet! <a href="post_property.php" style="margin-top:1.5rem;" class="btn">add new</a></p>';
}
?>
</div>
</section>
<script src="https://cdnjs.cloudflare.com/ajax/libs/sweetalert/2.1.2/sweetalert.min.js"></script>
<?php include 'components/footer.php'; ?>
<!-- custom js file link -->
<script src="js/script.js"></script>
<?php include 'components/message.php'; ?>
</body>
</html>