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 126
/
active_auctions.php
140 lines (125 loc) · 4.97 KB
/
active_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
<?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 (isset($_GET['user_id']) && !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'] = 'active_auctions.php';
header('location: user_login.php');
exit;
}
// get number of active auctions for this user
$query = "SELECT count(id) AS auctions FROM " . $DBPrefix . "auctions
WHERE user = :user_id
AND closed = 0
AND suspended = 0
AND starts <= CURRENT_TIMESTAMP";
$params = array();
$params[] = array(':user_id', $user_id, 'int');
$db->query($query, $params);
$num_auctions = $db->result('auctions');
// Handle pagination
if (!isset($_GET['PAGE']) || $_GET['PAGE'] == '' || $_GET['PAGE'] < 1) {
$OFFSET = 0;
$PAGE = 1;
} else {
$PAGE = intval($_GET['PAGE']);
$OFFSET = ($PAGE - 1) * $system->SETTINGS['perpage'];
}
$PAGES = ceil($num_auctions / $system->SETTINGS['perpage']);
if (!isset($PAGES) || $PAGES < 1) {
$PAGES = 1;
}
$query = "SELECT * FROM " . $DBPrefix . "auctions
WHERE user = :user_id
AND closed = 0
AND suspended = 0
AND starts <= CURRENT_TIMESTAMP
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);
$k = 0;
while ($row = $db->fetch()) {
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');
}
$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' => (!($k % 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['current_bid'],
'BIDFORMAT' => $system->print_money($row['current_bid']),
'NUM_BIDS' => $row['num_bids'],
'TIMELEFT' => $dt->formatTimeLeft($difference),
'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'])
));
$k++;
}
// get this user's nick
$query = "SELECT nick FROM " . $DBPrefix . "users WHERE id = :user_id";
$params[] = array(':user_id', $user_id, 'int');
$db->query($query, $params);
$TPL_user_nick = $db->result('nick');
$page_title = $MSG['219'] . ': ' . $TPL_user_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="active_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_RSSFEED' => sprintf($MSG['932'], $TPL_user_nick),
'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' => 'active_auctions.tpl'
));
$template->display('body');
include 'footer.php';