forked from renlok/WeBid
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathactive_auctions.php
More file actions
158 lines (140 loc) · 4.74 KB
/
active_auctions.php
File metadata and controls
158 lines (140 loc) · 4.74 KB
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
<?php
/***************************************************************************
* copyright : (C) 2008 - 2015 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']);
}
elseif ($user->logged_in)
{
$user_id = $user->user_data['id'];
}
else
{
$_SESSION['REDIRECT_AFTER_LOGIN'] = 'active_auctions.php';
header('location: user_login.php');
exit;
}
// check trying to access valid user id
$user->is_valid_user($user_id);
$NOW = time();
// 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 starts <= :time";
$params = array();
$params[] = array(':user_id', $user_id, 'int');
$params[] = array(':time', $NOW, '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 starts <= :time
ORDER BY ends ASC LIMIT :offset, :perpage";
$params = array();
$params[] = array(':user_id', $user_id, 'int');
$params[] = array(':time', $NOW, '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'] . '&fromfile=' . $uploaded_path . $row['id'] . '/' . $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 = :id";
$params[] = array(':id', $row['id'], 'int');
$db->query($query, $params);
$num_bids = $db->numrows();
$difference = $row['ends'] - $NOW;
$template->assign_block_vars('auctions', array(
'BGCOLOUR' => (!($k % 2)) ? '' : 'class="alt-row"',
'ID' => $row['id'],
'PIC_URL' => $row['pict_url'],
'TITLE' => $system->uncleanvars($row['title']),
'BNIMG' => get_lang_img(($row['bn_only'] == 'n') ? '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' => $num_bids,
'TIMELEFT' => FormatTimeLeft($difference),
'B_BUY_NOW' => ($row['buy_now'] > 0 && ($row['bn_only'] == 'y' || $row['bn_only'] == 'n' && ($row['num_bids'] == 0 || ($row['reserve_price'] > 0 && $row['current_bid'] < $row['reserve_price'])))),
'B_BNONLY' => ($row['bn_only'] == 'y')
));
$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';