This repository has been archived by the owner on Sep 25, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 125
/
closed_auctions.php
148 lines (130 loc) · 5.18 KB
/
closed_auctions.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
<?php
/***************************************************************************
* copyright : (C) 2008 - 2017 WeBid
* site : http://www.webidsupport.com/
***************************************************************************/
/***************************************************************************
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version. Although none of the code may be
* sold. If you have been sold this script, get a refund.
***************************************************************************/
include 'common.php';
if (!empty($_GET['user_id'])) {
$user_id = intval($_GET['user_id']);
// check trying to access valid user id
$user->checkUserValid($user_id);
} elseif ($user->logged_in) {
$user_id = $user->user_data['id'];
} else {
$_SESSION['LOGIN_MESSAGE'] = $MSG['5000'];
$_SESSION['REDIRECT_AFTER_LOGIN'] = 'closed_auctions.php';
header('location: user_login.php');
exit;
}
// get number of closed auctions for this user
$query = "SELECT count(id) AS auctions FROM " . $DBPrefix . "auctions
WHERE user = :user_id
AND closed = 1";
$params = array();
$params[] = array(':user_id', $user_id, 'int');
$db->query($query, $params);
$TOTALAUCTIONS = $db->result('auctions');
// Handle pagination
if (!isset($_GET['PAGE']) || $_GET['PAGE'] == 1 || $_GET['PAGE'] == '') {
$OFFSET = 0;
$PAGE = 1;
} else {
$PAGE = intval($_GET['PAGE']);
$OFFSET = ($PAGE - 1) * $system->SETTINGS['perpage'];
}
$PAGES = ceil($TOTALAUCTIONS / $system->SETTINGS['perpage']);
if ($PAGES < 1) {
$PAGES = 1;
}
$query = "SELECT * FROM " . $DBPrefix . "auctions
WHERE user = :user_id
AND closed = 1
ORDER BY ends ASC LIMIT :offset, :perpage";
$params = array();
$params[] = array(':user_id', $user_id, 'int');
$params[] = array(':offset', $OFFSET, 'int');
$params[] = array(':perpage', $system->SETTINGS['perpage'], 'int');
$db->query($query, $params);
$auction_data = $db->fetchall();
foreach ($auction_data as $row) {
$bid = $row['current_bid'];
$starting_price = $row['current_bid'];
if (strlen($row['pict_url']) > 0) {
$row['pict_url'] = $system->SETTINGS['siteurl'] . 'getthumb.php?w=' . $system->SETTINGS['thumb_show'] . '&auction_id=' . $row['id'] . '&fromfile=' . $row['pict_url'];
} else {
$row['pict_url'] = get_lang_img('nopicture.gif');
}
// number of bids for this auction
$query = "SELECT bid FROM " . $DBPrefix . "bids WHERE auction = :user_id";
$params = array();
$params[] = array(':user_id', $row['id'], 'int');
$db->query($query, $params);
$num_bids = $db->numrows();
$current_time = new DateTime('now', $dt->UTCtimezone);
$end_time = new DateTime($row['ends'], $dt->UTCtimezone);
$difference = $current_time->diff($end_time);
$template->assign_block_vars('auctions', array(
'BGCOLOUR' => (!($TOTALAUCTIONS % 2)) ? '' : 'class="alt-row"',
'ID' => $row['id'],
'PIC_URL' => $row['pict_url'],
'TITLE' => htmlspecialchars($row['title']),
'BNIMG' => get_lang_img(($row['bn_only'] == 0) ? 'buy_it_now.gif' : 'bn_only.png'),
'BNVALUE' => $row['buy_now'],
'BNFORMAT' => $system->print_money($row['buy_now']),
'BIDVALUE' => $row['minimum_bid'],
'BIDFORMAT' => $system->print_money($row['minimum_bid']),
'NUM_BIDS' => $num_bids,
'TIMELEFT' => $difference->format('%a') . ' ' . $MSG['126'],
'B_BUY_NOW' => ($row['buy_now'] > 0 && ($row['bn_only'] || $row['bn_only'] == 0 && ($row['num_bids'] == 0 || ($row['reserve_price'] > 0 && $row['current_bid'] < $row['reserve_price'])))),
'B_BNONLY' => ($row['bn_only'])
));
}
if ($TOTALAUCTIONS == 0) {
$template->assign_block_vars('no_auctions', array());
}
// get this user's nick
$query = "SELECT nick FROM " . $DBPrefix . "users WHERE id = :user_id";
$params = array();
$params[] = array(':user_id', $user_id, 'int');
$db->query($query, $params);
$TPL_user_nick = $db->result('nick');
$LOW = $PAGE - 5;
if ($LOW <= 0) {
$LOW = 1;
}
$COUNTER = $LOW;
$pagenation = '';
while ($COUNTER <= $PAGES && $COUNTER < ($PAGE + 6)) {
if ($PAGE == $COUNTER) {
$pagenation .= '<b>' . $COUNTER . '</b> ';
} else {
$pagenation .= '<a href="closed_auctions.php?PAGE=' . $COUNTER . '&user_id=' . $user_id . '"><u>' . $COUNTER . '</u></a> ';
}
$COUNTER++;
}
$template->assign_vars(array(
'B_MULPAG' => ($PAGES > 1),
'B_NOTLAST' => ($PAGE < $PAGES),
'B_NOTFIRST' => ($PAGE > 1),
'USER_ID' => $user_id,
'USERNAME' => $TPL_user_nick,
'THUMBWIDTH' => $system->SETTINGS['thumb_show'],
'NEXT' => intval($PAGE + 1),
'PREV' => intval($PAGE - 1),
'PAGE' => $PAGE,
'PAGES' => $PAGES,
'PAGENA' => $pagenation
));
include 'header.php';
$template->set_filenames(array(
'body' => 'auctions_closed.tpl'
));
$template->display('body');
include 'footer.php';