hpdl
|
1
|
1
|
<?php
|
|
2
|
/*
|
mattice
|
151
|
3
|
$Id: banner.php 757 2006-08-23 12:22:54Z hpdl $
|
hpdl
|
1
|
4
|
|
|
5
|
osCommerce, Open Source E-Commerce Solutions
|
|
6
|
http://www.oscommerce.com
|
|
7
|
|
|
8
|
Copyright (c) 2004 osCommerce
|
|
9
|
|
|
10
|
Released under the GNU General Public License
|
|
11
|
*/
|
|
12
|
|
|
13
|
class osC_Banner {
|
|
14
|
|
|
15
|
/* Public variables */
|
|
16
|
var $show_duplicates_in_group = false;
|
|
17
|
|
|
18
|
/* Private variables */
|
|
19
|
var $_exists_id,
|
|
20
|
$_shown_ids = array();
|
|
21
|
|
|
22
|
/* Class constructor */
|
|
23
|
|
|
24
|
function osC_Banner() {
|
|
25
|
if (SERVICE_BANNER_SHOW_DUPLICATE == 'True') {
|
|
26
|
$this->show_duplicates_in_group = true;
|
|
27
|
}
|
|
28
|
}
|
|
29
|
|
|
30
|
/* Public methods */
|
|
31
|
|
|
32
|
function activate($id) {
|
|
33
|
$this->_setStatus($id, true);
|
|
34
|
}
|
|
35
|
|
|
36
|
function activateAll() {
|
|
37
|
global $osC_Database;
|
|
38
|
|
|
39
|
$Qbanner = $osC_Database->query('select banners_id, date_scheduled from :table_banners where date_scheduled != ""');
|
|
40
|
$Qbanner->bindTable(':table_banners', TABLE_BANNERS);
|
|
41
|
$Qbanner->execute();
|
|
42
|
|
|
43
|
if ($Qbanner->numberOfRows() > 0) {
|
|
44
|
while ($Qbanner->next()) {
|
|
45
|
if (date('Y-m-d H:i:s') >= $Qbanner->value('date_scheduled')) {
|
|
46
|
$this->activate($Qbanner->valueInt('banners_id'));
|
|
47
|
}
|
|
48
|
}
|
|
49
|
}
|
|
50
|
|
|
51
|
$Qbanner->freeResult();
|
|
52
|
}
|
|
53
|
|
|
54
|
function expire($id) {
|
|
55
|
$this->_setStatus($id, false);
|
|
56
|
}
|
|
57
|
|
|
58
|
function expireAll() {
|
|
59
|
global $osC_Database;
|
|
60
|
|
|
61
|
$Qbanner = $osC_Database->query('select b.banners_id, b.expires_date, b.expires_impressions, sum(bh.banners_shown) as banners_shown from :table_banners b, :table_banners_history bh where b.status = 1 and b.banners_id = bh.banners_id group by b.banners_id');
|
|
62
|
$Qbanner->bindTable(':table_banners', TABLE_BANNERS);
|
|
63
|
$Qbanner->bindTable(':table_banners_history', TABLE_BANNERS_HISTORY);
|
|
64
|
$Qbanner->execute();
|
|
65
|
|
|
66
|
if ($Qbanner->numberOfRows() > 0) {
|
|
67
|
while ($Qbanner->next()) {
|
hpdl
|
757
|
68
|
if (!osc_empty($Qbanner->value('expires_date'))) {
|
hpdl
|
1
|
69
|
if (date('Y-m-d H:i:s') >= $Qbanner->value('expires_date')) {
|
|
70
|
$this->expire($Qbanner->valueInt('banners_id'));
|
|
71
|
}
|
hpdl
|
757
|
72
|
} elseif (!osc_empty($Qbanner->valueInt('expires_impressions'))) {
|
hpdl
|
1
|
73
|
if ( ($Qbanner->valueInt('expires_impressions') > 0) && ($Qbanner->valueInt('banners_shown') >= $Qbanner->valueInt('expires_impressions')) ) {
|
|
74
|
$this->expire($Qbanner->valueInt('banners_id'));
|
|
75
|
}
|
|
76
|
}
|
|
77
|
}
|
|
78
|
}
|
|
79
|
|
|
80
|
$Qbanner->freeResult();
|
|
81
|
}
|
|
82
|
|
|
83
|
function isActive($id) {
|
|
84
|
global $osC_Database;
|
|
85
|
|
|
86
|
$Qbanner = $osC_Database->query('select banners_id from :table_banners where status = 1 and banners_id = :banners_id');
|
|
87
|
$Qbanner->bindTable(':table_banners', TABLE_BANNERS);
|
|
88
|
$Qbanner->bindInt(':banners_id', $id);
|
|
89
|
$Qbanner->execute();
|
|
90
|
|
|
91
|
if ($Qbanner->numberOfRows() > 0) {
|
|
92
|
return true;
|
|
93
|
}
|
|
94
|
|
|
95
|
return false;
|
|
96
|
}
|
|
97
|
|
|
98
|
function exists($group) {
|
|
99
|
global $osC_Database;
|
|
100
|
|
|
101
|
$Qbanner = $osC_Database->query('select banners_id from :table_banners where status = 1 and banners_group = :banners_group');
|
|
102
|
|
|
103
|
if ( ($this->show_duplicates_in_group === false) && (sizeof($this->_shown_ids) > 0) ) {
|
|
104
|
$Qbanner->appendQuery('and banners_id not in (:banner_ids)');
|
|
105
|
$Qbanner->bindRaw(':banner_ids', implode(',', $this->_shown_ids));
|
|
106
|
}
|
|
107
|
|
|
108
|
$Qbanner->bindTable(':table_banners', TABLE_BANNERS);
|
|
109
|
$Qbanner->bindValue(':banners_group', $group);
|
|
110
|
$Qbanner->executeRandom();
|
|
111
|
|
|
112
|
if ($Qbanner->numberOfRows() > 0) {
|
|
113
|
$this->_exists_id = $Qbanner->valueInt('banners_id');
|
|
114
|
|
|
115
|
return true;
|
|
116
|
}
|
|
117
|
|
|
118
|
return false;
|
|
119
|
}
|
|
120
|
|
|
121
|
function display($id = '') {
|
|
122
|
global $osC_Database;
|
|
123
|
|
|
124
|
$banner_string = false;
|
|
125
|
|
|
126
|
if (empty($id) && isset($this->_exists_id) && is_numeric($this->_exists_id)) {
|
|
127
|
$id = $this->_exists_id;
|
|
128
|
|
|
129
|
unset($this->_exists_id);
|
|
130
|
}
|
|
131
|
|
|
132
|
$Qbanner = $osC_Database->query('select * from :table_banners where banners_id = :banners_id and status = 1');
|
|
133
|
$Qbanner->bindTable(':table_banners', TABLE_BANNERS);
|
|
134
|
$Qbanner->bindInt(':banners_id', $id);
|
|
135
|
$Qbanner->execute();
|
|
136
|
|
|
137
|
if ($Qbanner->numberOfRows() > 0) {
|
hpdl
|
757
|
138
|
if (!osc_empty($Qbanner->value('banners_html_text'))) {
|
hpdl
|
1
|
139
|
$banner_string = $Qbanner->value('banners_html_text');
|
|
140
|
} else {
|
hpdl
|
754
|
141
|
$banner_string = osc_link_object(osc_href_link(FILENAME_REDIRECT, 'action=banner&goto=' . $Qbanner->valueInt('banners_id')), osc_image(DIR_WS_IMAGES . $Qbanner->value('banners_image'), $Qbanner->value('banners_title')), 'target="_blank"');
|
hpdl
|
1
|
142
|
}
|
|
143
|
|
|
144
|
$this->_updateDisplayCount($Qbanner->valueInt('banners_id'));
|
|
145
|
|
|
146
|
if ($this->show_duplicates_in_group === false) {
|
|
147
|
$this->_shown_ids[] = $Qbanner->valueInt('banners_id');
|
|
148
|
}
|
|
149
|
}
|
|
150
|
|
|
151
|
$Qbanner->freeResult();
|
|
152
|
|
|
153
|
return $banner_string;
|
|
154
|
}
|
|
155
|
|
|
156
|
function getURL($id, $increment_click = false) {
|
|
157
|
global $osC_Database;
|
|
158
|
|
|
159
|
$url = false;
|
|
160
|
|
|
161
|
$Qbanner = $osC_Database->query('select banners_url from :table_banners where banners_id = :banners_id and status = 1');
|
|
162
|
$Qbanner->bindTable(':table_banners', TABLE_BANNERS);
|
|
163
|
$Qbanner->bindInt(':banners_id', $id);
|
|
164
|
$Qbanner->execute();
|
|
165
|
|
|
166
|
if ($Qbanner->numberOfRows() > 0) {
|
|
167
|
$url = $Qbanner->value('banners_url');
|
|
168
|
|
|
169
|
if ($increment_click === true) {
|
|
170
|
$this->_updateClickCount($id);
|
|
171
|
}
|
|
172
|
}
|
|
173
|
|
|
174
|
$Qbanner->freeResult();
|
|
175
|
|
|
176
|
return $url;
|
|
177
|
}
|
|
178
|
|
|
179
|
/* Private methods */
|
|
180
|
|
|
181
|
function _setStatus($id, $active) {
|
|
182
|
global $osC_Database;
|
|
183
|
|
|
184
|
if ($active === true) {
|
|
185
|
$Qbanner = $osC_Database->query('update :table_banners set status = 1, date_status_change = now(), date_scheduled = NULL where banners_id = :banners_id');
|
|
186
|
$Qbanner->bindTable(':table_banners', TABLE_BANNERS);
|
|
187
|
$Qbanner->bindInt(':banners_id', $id);
|
|
188
|
$Qbanner->execute();
|
|
189
|
} else {
|
|
190
|
$Qbanner = $osC_Database->query('update :table_banners set status = 0, date_status_change = now() where banners_id = :banners_id');
|
|
191
|
$Qbanner->bindTable(':table_banners', TABLE_BANNERS);
|
|
192
|
$Qbanner->bindInt(':banners_id', $id);
|
|
193
|
$Qbanner->execute();
|
|
194
|
}
|
|
195
|
|
|
196
|
$Qbanner->freeResult();
|
|
197
|
}
|
|
198
|
|
|
199
|
function _updateDisplayCount($id) {
|
|
200
|
global $osC_Database;
|
|
201
|
|
|
202
|
$Qcheck = $osC_Database->query('select count(*) as count from :table_banners_history where banners_id = :banners_id and date_format(banners_history_date, "%Y%m%d") = date_format(now(), "%Y%m%d")');
|
|
203
|
$Qcheck->bindTable(':table_banners_history', TABLE_BANNERS_HISTORY);
|
|
204
|
$Qcheck->bindInt(':banners_id', $id);
|
|
205
|
$Qcheck->execute();
|
|
206
|
|
|
207
|
if ($Qcheck->valueInt('count') > 0) {
|
|
208
|
$Qbanner = $osC_Database->query('update :table_banners_history set banners_shown = banners_shown + 1 where banners_id = :banners_id and date_format(banners_history_date, "%Y%m%d") = date_format(now(), "%Y%m%d")');
|
|
209
|
} else {
|
|
210
|
$Qbanner = $osC_Database->query('insert into :table_banners_history (banners_id, banners_shown, banners_history_date) values (:banners_id, 1, now())');
|
|
211
|
}
|
|
212
|
$Qbanner->bindTable(':table_banners_history', TABLE_BANNERS_HISTORY);
|
|
213
|
$Qbanner->bindInt(':banners_id', $id);
|
|
214
|
$Qbanner->execute();
|
|
215
|
|
|
216
|
$Qcheck->freeResult();
|
|
217
|
$Qbanner->freeResult();
|
|
218
|
}
|
|
219
|
|
|
220
|
function _updateClickCount($id) {
|
|
221
|
global $osC_Database;
|
|
222
|
|
|
223
|
$Qcheck = $osC_Database->query('select count(*) as count from :table_banners_history where banners_id = :banners_id and date_format(banners_history_date, "%Y%m%d") = date_format(now(), "%Y%m%d")');
|
|
224
|
$Qcheck->bindTable(':table_banners_history', TABLE_BANNERS_HISTORY);
|
|
225
|
$Qcheck->bindInt(':banners_id', $id);
|
|
226
|
$Qcheck->execute();
|
|
227
|
|
|
228
|
if ($Qcheck->valueInt('count') > 0) {
|
|
229
|
$Qbanner = $osC_Database->query('update :table_banners_history set banners_clicked = banners_clicked + 1 where banners_id = :banners_id and date_format(banners_history_date, "%Y%m%d") = date_format(now(), "%Y%m%d")');
|
|
230
|
} else {
|
|
231
|
$Qbanner = $osC_Database->query('insert into :table_banners_history (banners_id, banners_clicked, banners_history_date) values (:banners_id, 1, now())');
|
|
232
|
}
|
|
233
|
$Qbanner->bindTable(':table_banners_history', TABLE_BANNERS_HISTORY);
|
|
234
|
$Qbanner->bindInt(':banners_id', $id);
|
|
235
|
$Qbanner->execute();
|
|
236
|
|
|
237
|
$Qcheck->freeResult();
|
|
238
|
$Qbanner->freeResult();
|
|
239
|
}
|
|
240
|
}
|
|
241
|
?>
|