-
Notifications
You must be signed in to change notification settings - Fork 1
/
apply.php
78 lines (56 loc) · 3.05 KB
/
apply.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
<?php
session_start();
include 'db-connect.php';
$aid = $_GET["aid"];
$username = $_SESSION["username"];
$bool = 0;
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// FOR UPDATING DATABASE
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//Checks if user is the one who posted the apartment
$sql_search = "SELECT aid,tid,username from apply_apt where username = '".$username."'";
$result_search = $conn->query($sql_search);
if ($result_search->num_rows > 0) {
while($row = $result_search->fetch_assoc()) {
$said = $row["aid"];
$stid = $row["tid"];
if($said == $aid){
if($stid == 1){
$bool = 1;
}
}
}
}
if($bool != 1){
$sql = "INSERT INTO apply_apt (aid, username, tid) VALUES (".$aid.",'".$username."', 0)";
//Executes Statement
$conn->query($sql);
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// FOR UPDATING UI
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
$sql = "SELECT aid,likes,dislike,report from apartment where aid = ".$aid;
$result = $conn->query($sql);
if ($result->num_rows > 0) {
while($row = $result->fetch_assoc()) {
$aid = $row["aid"];
$sql_sl = 'SELECT app_status from apply_apt where TID=0 and username="'.$username.'" and aid = '. $aid;
$result_sl= $conn->query($sql_sl);
if ($result_sl->num_rows > 0) {
echo '
<button type = "button"> Applied </button>
<button onclick = "clickFunction(1,'.$row["aid"].','.$row["likes"].')" value = "'.$row["likes"].'" type = "button"> Like ('.$row["likes"].')</button>
<button onclick = "clickFunction(2,'.$row["aid"].','.$row["dislike"].')" value = "'.$row["dislike"].'" type = "button"> Dislike ('.$row["dislike"].')</button>
<button onclick = "clickFunction(0,'.$row["aid"].','.$row["report"].')" value = "'.$row["report"].'" type = "button"> Report ('.$row["report"].')</button>';
}else{
echo '
<button onclick = "applyFunction('.$row["aid"].')" type = "button"> Apply </button>
<button onclick = "clickFunction(1,'.$row["aid"].','.$row["likes"].')" value = "'.$row["likes"].'" type = "button"> Like ('.$row["likes"].')</button>
<button onclick = "clickFunction(2,'.$row["aid"].','.$row["dislike"].')" value = "'.$row["dislike"].'" type = "button"> Dislike ('.$row["dislike"].')</button>
<button onclick = "clickFunction(0,'.$row["aid"].','.$row["report"].')" value = "'.$row["report"].'" type = "button"> Report ('.$row["report"].')</button>';
}
}
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
$conn->close();
?>