Quick Search:

View

Revision:

Diff

Diff from 1497 to:

Annotations

Annotate by Age | Author | Mixed | None
/fisheye/browse/osCommerce/branches/hpdl/oscommerce/includes/classes/banner.php

Annotated File View

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