forked from lorinn/B3-First_Year_TeamProject
-
Notifications
You must be signed in to change notification settings - Fork 0
/
offers.php
147 lines (133 loc) · 4.96 KB
/
offers.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
<?php
session_start();
include('config.php');
include_once("functions.php");
$answer = escape_value($_GET['id']);
$offer_item_id = escape_value($_GET['idq']);
$offer_trade_id = escape_value($_GET['idw']);
$offer_trade_name = escape_value($_GET['ide']);
$offer_trade_email = escape_value($_GET['idr']);
while ($row = mysql_fetch_assoc($query4))
{
$item_name = $row['name'];
$status = $row['status'];
}
echo $offer_item_id;
echo $offer_trade_id;
echo $offer_trade_name;
if($answer == 'accept')
{
$to = $offer_trade_email;
$subject = "MyUniTrader offer notification";
$message = "Hello! Your offer was accepted! Please contact the owner!";
$headers = "From MyUniTrader";
mail($to,$subject,$message,$headers);
if($offer_trade_name == '-')
{
mysql_query("UPDATE `items`
SET `status`='0'
WHERE `item_id`='$offer_item_id'");
mysql_query("DELETE FROM `Trade` WHERE `bidded_item_id` = $offer_trade_id AND `item_id` = $offer_item_id");
}
else
{ mysql_query("UPDATE `items`
SET `status`='0'
WHERE `item_id`='$offer_item_id'");
mysql_query("UPDATE `items`
SET `status`='0'
WHERE `item_id`='$offer_trade_id'");
mysql_query("DELETE FROM `Trade` WHERE `bidded_item_id` = $offer_trade_id AND `item_id` = $offer_item_id");
}
header("Location: offers.php");
}
if($answer == 'decline')
{
$to = $offer_trade_email;
$subject = "MyUniTrader offer notification";
$message = "Hello! Your offer was declined! Please contact the owner!";
$headers = "From MyUniTrader";
mail($to,$subject,$message,$headers);
mysql_query("DELETE FROM `Trade` WHERE `bidded_item_id` = $offer_trade_id AND `item_id` = $offer_item_id");
header("Location: offers.php");
}
$user_id = $_SESSION['user_id'];
$check = mysql_query("SELECT * FROM Trade WHERE owner_id ='$user_id' OR bidder_id ='$user_id'");
while($check_row = mysql_fetch_assoc($check))
{
if($user_id == $check_row['owner_id'])
mysql_query("UPDATE Trade SET owner_view='1' WHERE owner_id='$user_id'");
elseif ($user_id == $check_row['bidder_id'])
mysql_query("UPDATE Trade SET bidder_view='1' WHERE bidder_id='$user_id'");
}
include('header_menuleft.php');
echo "
<table border='0'>
<tr>
<th id='title_table'><h5>Item name</h5></th>
<th id='title_table'><h5>Owner name</h5></th>
<th id='title_table'><h5>Offered item</h5></th>
<th id='title_table'><h5>Offered price</h5></th>
<th id='title_table'><h5>Trader name</h5></th>
<th id='title_table'><h5>Date</h5></th>
<th id='title_table'><h5>Answer</h5></th>
</tr>";
$item_found=0;
$query3 = mysql_query("SELECT * FROM Trade WHERE owner_id = '$user_id' OR bidder_id='$user_id'");
while ($row = mysql_fetch_assoc($query3))
{
$item_found=1;
$item_id = $row['item_id'];
$item_type = $row['item_type'];
$owner_id = $row['owner_id'];
$bidder_item_id = $row['bidded_item_id'];
$bidder_id = $row['bidder_id'];
$date = $row['date'];
$bidder_price = $row['price'];
$query4 = mysql_query("SELECT * FROM items WHERE item_id = '$item_id' ");
while ($row = mysql_fetch_assoc($query4))
{
$item_name = $row['name'];
$status = $row['status'];
}
$query5 = mysql_query("SELECT * FROM items WHERE item_id = '$bidder_item_id' ");
if($bidder_item_id == 0)
$bidder_item_name = "-";
else
{
while ($row = mysql_fetch_assoc($query5))
{
$bidder_item_name = $row['name'];
}
}
$query6 = mysql_query("SELECT * FROM users WHERE user_id = '$owner_id' ");
while ($row = mysql_fetch_assoc($query6))
{
$owner_name = $row['name'];
}
$query7 = mysql_query("SELECT * FROM users WHERE user_id = '$bidder_id' ");
while ($row = mysql_fetch_assoc($query7))
{
$bidder_name = $row['name'];
$bidder_email = $row['email'];
}
if($status != 0)
{echo "<tr id='item_table'>
<td> <a href='item_page.php?id=".$item_id."'>".$item_name."</a></td>
<td> ".$owner_name ."</td>
<td> ".$bidder_item_name."</td>
<td> ".$bidder_price."</a></td>
<td> ".$bidder_name."</a></td>
<td> ".$date."</a></td>";
if($_SESSION['user_id'] == $owner_id)
{echo "<td> <a href='offers.php?id=accept&idq=".$item_id."&idw=".$bidder_item_id."&ide=".$bidder_item_name."&idr=".$bidder_email."'><button>Accept offer</button></a>
<a href='offers.php?id=decline&idq=".$item_id."&idw=".$bidder_item_id."&ide=".$bidder_item_name."&idr=".$bidder_email."'><button>Decline offer</button></a></td>
</tr>"; }
else
echo "<td></td></tr>";
}
}
echo "</table>";
if ($item_found != 1)
echo "Sorry, there are no items in your Offer list!";
include('footer.php');
?>