[TEP-COMMIT] [CVS catalog] move the banner functions to a new osC_Banner class

hpdl-OfajU3CKLf1/[email protected] 28 Nov 2004 18:37:14 -0000
Newsgroups gmane.comp.web.oscommerce.cvs
Message-ID <[email protected]>
<html>
<head>
<style><!--
  body {background-color:#ffffff;}
  .file {border:1px solid #eeeeee;margin-top:1em;margin-bottom:1em;}
  .pathname {font-family:monospace; float:right;}
  .fileheader {margin-bottom:.5em;}
  .diff {margin:0;}
  .tasklist {padding:4px;border:1px dashed #000000;margin-top:1em;}
  .tasklist ul {margin-top:0;margin-bottom:0;}
  tr.alt {background-color:#eeeeee}
  #added {background-color:#ddffdd;}
  #addedchars {background-color:#99ff99;font-weight:bolder;}
  tr.alt #added {background-color:#ccf7cc;}
  #removed {background-color:#ffdddd;}
  #removedchars {background-color:#ff9999;font-weight:bolder;}
  tr.alt #removed {background-color:#f7cccc;}
  #info {color:#888888;}
  #context {background-color:#eeeeee;}
  td {padding-left:.3em;padding-right:.3em;}
  tr.head {border-bottom-width:1px;border-bottom-style:solid;}
  tr.head td {padding:0;padding-top:.2em;}
  .task {background-color:#ffff00;}
  .comment {padding:4px;border:1px dashed #000000;background-color:#ffffdd}
  .error {color:red;}
  hr {border-width:0px;height:2px;background:black;}
--></style>
</head>
<body>
<table cellspacing="0" cellpadding="0" border="0" rules="cols">
<tr class="head"><td colspan="4">Commit in <b><tt>catalog/catalog</tt></b><span id="info"> on MAIN</span></td></tr>
<tr><td><tt><a href="#file1">redirect.php</a></tt></td><td align="right" id="added">+5</td><td align="right" id="removed">-7</td><td nowrap="nowrap" align="center"><a href="http://cvs.oscommerce.com/viewcvs.cgi/catalog/catalog/redirect.php?rev=1.12&amp;content-type=text/vnd.viewcvs-markup">1.12</a> <a href="http://cvs.oscommerce.com/viewcvs.cgi/catalog/catalog/redirect.php.diff?r1=1.12&amp;r2=1.13">-&gt;</a> <a href="http://cvs.oscommerce.com/viewcvs.cgi/catalog/catalog/redirect.php?rev=1.13&amp;content-type=text/vnd.viewcvs-markup">1.13</a></td></tr>
<tr class="alt"><td><tt>includes/<a href="#file2">footer.php</a></tt></td><td align="right" id="added">+2</td><td align="right" id="removed">-2</td><td nowrap="nowrap" align="center"><a href="http://cvs.oscommerce.com/viewcvs.cgi/catalog/catalog/includes/footer.php?rev=1.30&amp;content-type=text/vnd.viewcvs-markup">1.30</a> <a href="http://cvs.oscommerce.com/viewcvs.cgi/catalog/catalog/includes/footer.php.diff?r1=1.30&amp;r2=1.31">-&gt;</a> <a href="http://cvs.oscommerce.com/viewcvs.cgi/catalog/catalog/includes/footer.php?rev=1.31&amp;content-type=text/vnd.viewcvs-markup">1.31</a></td></tr>
<tr><td><tt>includes/classes/<a href="#file3"><span id="added">banner.php</span></a></tt></td><td align="right" id="added">+241</td><td></td><td nowrap="nowrap" align="right">added <a href="http://cvs.oscommerce.com/viewcvs.cgi/catalog/catalog/includes/classes/banner.php?rev=1.1&amp;content-type=text/vnd.viewcvs-markup">1.1</a></td></tr>
<tr class="alt"><td><tt>includes/functions/<span id="removed">banner.php</span></tt></td><td></td><td></td><td nowrap="nowrap"><a href="http://cvs.oscommerce.com/viewcvs.cgi/catalog/catalog/includes/functions/banner.php?rev=1.14&amp;content-type=text/vnd.viewcvs-markup">1.14</a> removed</td></tr>
<tr><td><tt>includes/modules/services/<a href="#file5">banner.php</a></tt></td><td align="right" id="added">+13</td><td align="right" id="removed">-6</td><td nowrap="nowrap" align="center"><a href="http://cvs.oscommerce.com/viewcvs.cgi/catalog/catalog/includes/modules/services/banner.php?rev=1.1&amp;content-type=text/vnd.viewcvs-markup">1.1</a> <a href="http://cvs.oscommerce.com/viewcvs.cgi/catalog/catalog/includes/modules/services/banner.php.diff?r1=1.1&amp;r2=1.2">-&gt;</a> <a href="http://cvs.oscommerce.com/viewcvs.cgi/catalog/catalog/includes/modules/services/banner.php?rev=1.2&amp;content-type=text/vnd.viewcvs-markup">1.2</a></td></tr>
<tr><td></td><td align="right" id="added">+261</td><td align="right" id="removed">-15</td><td></td></tr>
</table>
<small id="info">1 added + 1 removed + 3 modified, total 5 files</small><br />
<pre class="comment">
move the banner functions to a new osC_Banner class

add a banner service module parameter to control if duplicate banners in
the same group should be displayed on the same page or not
</pre>
<hr /><a name="file1" /><div class="file">
<span class="pathname"><a href="http://cvs.oscommerce.com/viewcvs.cgi/catalog">catalog</a>/<a href="http://cvs.oscommerce.com/viewcvs.cgi/catalog/catalog">catalog</a><br /></span>
<div class="fileheader"><big><b>redirect.php</b></big> <small id="info"><a href="http://cvs.oscommerce.com/viewcvs.cgi/catalog/catalog/redirect.php?rev=1.12&amp;content-type=text/vnd.viewcvs-markup">1.12</a> <a href="http://cvs.oscommerce.com/viewcvs.cgi/catalog/catalog/redirect.php.diff?r1=1.12&amp;r2=1.13">-&gt;</a> <a href="http://cvs.oscommerce.com/viewcvs.cgi/catalog/catalog/redirect.php?rev=1.13&amp;content-type=text/vnd.viewcvs-markup">1.13</a></small></div>
<pre class="diff"><small id="info">diff -u -r1.12 -r1.13
--- redirect.php	2004/01/10 20:18:01	1.12
+++ redirect.php	2004/11/28 18:37:10	1.13
@@ -5,7 +5,7 @@
</small></pre><pre class="diff" id="context">   osCommerce, Open Source E-Commerce Solutions
   http://www.oscommerce.com
 
</pre><pre class="diff" id="removed">-  Copyright (c) 200<span id="removedchars">3</span> osCommerce
</pre><pre class="diff" id="added">+  Copyright (c) 200<span id="addedchars">4</span> osCommerce
</pre><pre class="diff" id="context"> 
   Released under the GNU General Public License
 */
</pre><pre class="diff"><small id="info">@@ -14,12 +14,10 @@
</small></pre><pre class="diff" id="context"> 
   switch ($_GET['action']) {
     case 'banner':
</pre><pre class="diff" id="removed">-      $banner_query = tep_db_query("select banners_url from " . TABLE_BANNERS . " where banners_id = '" . (int)$_GET['goto'] . "'");
-      if (tep_db_num_rows($banner_query)) {
-        $banner = tep_db_fetch_array($banner_query);
-        tep_update_banner_click_count($_GET['goto']);
-
-        tep_redirect($banner['banners_url']);
</pre><pre class="diff" id="added">+      if (isset($_GET['goto']) &amp;&amp; is_numeric($_GET['goto'])) {
+        if ($osC_Services-&gt;isStarted('banner') &amp;&amp; $osC_Banner-&gt;isActive($_GET['goto'])) {
+          tep_redirect($osC_Banner-&gt;getURL($_GET['goto'], true));
+        }
</pre><pre class="diff" id="context">       }
       break;
 
</pre></div>
<hr /><a name="file2" /><div class="file">
<span class="pathname"><a href="http://cvs.oscommerce.com/viewcvs.cgi/catalog">catalog</a>/<a href="http://cvs.oscommerce.com/viewcvs.cgi/catalog/catalog">catalog</a>/<a href="http://cvs.oscommerce.com/viewcvs.cgi/catalog/catalog/includes">includes</a><br /></span>
<div class="fileheader"><big><b>footer.php</b></big> <small id="info"><a href="http://cvs.oscommerce.com/viewcvs.cgi/catalog/catalog/includes/footer.php?rev=1.30&amp;content-type=text/vnd.viewcvs-markup">1.30</a> <a href="http://cvs.oscommerce.com/viewcvs.cgi/catalog/catalog/includes/footer.php.diff?r1=1.30&amp;r2=1.31">-&gt;</a> <a href="http://cvs.oscommerce.com/viewcvs.cgi/catalog/catalog/includes/footer.php?rev=1.31&amp;content-type=text/vnd.viewcvs-markup">1.31</a></small></div>
<pre class="diff"><small id="info">diff -u -r1.30 -r1.31
--- footer.php	2004/11/24 15:55:04	1.30
+++ footer.php	2004/11/28 18:37:11	1.31
@@ -43,12 +43,12 @@
</small></pre><pre class="diff" id="context">   &lt;/tr&gt;
 &lt;/table&gt;
 &lt;?php
</pre><pre class="diff" id="removed">-  if ($osC_Services-&gt;isStarted('banner') &amp;&amp; ($banner = tep_banner_exists('dynamic', '468x50'))) {
</pre><pre class="diff" id="added">+  if ($osC_Services-&gt;isStarted('banner') &amp;&amp; $osC_Banner-&gt;exists('468x50')) {
</pre><pre class="diff" id="context"> ?&gt;
 &lt;br&gt;
 &lt;table border="0" width="100%" cellspacing="0" cellpadding="0"&gt;
   &lt;tr&gt;
</pre><pre class="diff" id="removed">-    &lt;td align="center"&gt;&lt;?php echo tep_display_banner('dynamic', '468x50'); ?&gt;&lt;/td&gt;
</pre><pre class="diff" id="added">+    &lt;td align="center"&gt;&lt;?php echo $osC_Banner-&gt;display(); ?&gt;&lt;/td&gt;
</pre><pre class="diff" id="context">   &lt;/tr&gt;
 &lt;/table&gt;
 &lt;?php
</pre></div>
<hr /><a name="file3" /><div class="file">
<span class="pathname" id="added"><a href="http://cvs.oscommerce.com/viewcvs.cgi/catalog">catalog</a>/<a href="http://cvs.oscommerce.com/viewcvs.cgi/catalog/catalog">catalog</a>/<a href="http://cvs.oscommerce.com/viewcvs.cgi/catalog/catalog/includes">includes</a>/<a href="http://cvs.oscommerce.com/viewcvs.cgi/catalog/catalog/includes/classes">classes</a><br /></span>
<div class="fileheader" id="added"><big><b>banner.php</b></big> <small id="info">added at <a href="http://cvs.oscommerce.com/viewcvs.cgi/catalog/catalog/includes/classes/banner.php?rev=1.1&amp;content-type=text/vnd.viewcvs-markup">1.1</a></small></div>
<pre class="diff"><small id="info">diff -N banner.php
--- /dev/null	Sun Nov 28 19:37:11 2004
+++ /tmp/cvsAAABXaqIO	Sun Nov 28 19:37:12 2004
@@ -0,0 +1,241 @@
</small></pre><pre class="diff" id="added">+&lt;?php
+/*
+  $Id$
+
+  osCommerce, Open Source E-Commerce Solutions
+  http://www.oscommerce.com
+
+  Copyright (c) 2004 osCommerce
+
+  Released under the GNU General Public License
+*/
+
+  class osC_Banner {
+
+/* Public variables */
+    var $show_duplicates_in_group = false;
+
+/* Private variables */
+    var $_exists_id,
+        $_shown_ids = array();
+
+/* Class constructor */
+
+    function osC_Banner() {
+      if (SERVICE_BANNER_SHOW_DUPLICATE == 'True') {
+        $this-&gt;show_duplicates_in_group = true;
+      }
+    }
+
+/* Public methods */
+
+    function activate($id) {
+      $this-&gt;_setStatus($id, true);
+    }
+
+    function activateAll() {
+      global $osC_Database;
+
+      $Qbanner = $osC_Database-&gt;query('select banners_id, date_scheduled from :table_banners where date_scheduled != ""');
+      $Qbanner-&gt;bindTable(':table_banners', TABLE_BANNERS);
+      $Qbanner-&gt;execute();
+
+      if ($Qbanner-&gt;numberOfRows() &gt; 0) {
+        while ($Qbanner-&gt;next()) {
+          if (date('Y-m-d H:i:s') &gt;= $Qbanner-&gt;value('date_scheduled')) {
+            $this-&gt;activate($Qbanner-&gt;valueInt('banners_id'));
+          }
+        }
+      }
+
+      $Qbanner-&gt;freeResult();
+    }
+
+    function expire($id) {
+      $this-&gt;_setStatus($id, false);
+    }
+
+    function expireAll() {
+      global $osC_Database;
+
+      $Qbanner = $osC_Database-&gt;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');
+      $Qbanner-&gt;bindTable(':table_banners', TABLE_BANNERS);
+      $Qbanner-&gt;bindTable(':table_banners_history', TABLE_BANNERS_HISTORY);
+      $Qbanner-&gt;execute();
+
+      if ($Qbanner-&gt;numberOfRows() &gt; 0) {
+        while ($Qbanner-&gt;next()) {
+          if (tep_not_null($Qbanner-&gt;value('expires_date'))) {
+            if (date('Y-m-d H:i:s') &gt;= $Qbanner-&gt;value('expires_date')) {
+              $this-&gt;expire($Qbanner-&gt;valueInt('banners_id'));
+            }
+          } elseif (tep_not_null($Qbanner-&gt;valueInt('expires_impressions'))) {
+            if ( ($Qbanner-&gt;valueInt('expires_impressions') &gt; 0) &amp;&amp; ($Qbanner-&gt;valueInt('banners_shown') &gt;= $Qbanner-&gt;valueInt('expires_impressions')) ) {
+              $this-&gt;expire($Qbanner-&gt;valueInt('banners_id'));
+            }
+          }
+        }
+      }
+
+      $Qbanner-&gt;freeResult();
+    }
+
+    function isActive($id) {
+      global $osC_Database;
+
+      $Qbanner = $osC_Database-&gt;query('select banners_id from :table_banners where status = 1 and banners_id = :banners_id');
+      $Qbanner-&gt;bindTable(':table_banners', TABLE_BANNERS);
+      $Qbanner-&gt;bindInt(':banners_id', $id);
+      $Qbanner-&gt;execute();
+
+      if ($Qbanner-&gt;numberOfRows() &gt; 0) {
+        return true;
+      }
+
+      return false;
+    }
+
+    function exists($group) {
+      global $osC_Database;
+
+      $Qbanner = $osC_Database-&gt;query('select banners_id from :table_banners where status = 1 and banners_group = :banners_group');
+
+      if ( ($this-&gt;show_duplicates_in_group === false) &amp;&amp; (sizeof($this-&gt;_shown_ids) &gt; 0) ) {
+        $Qbanner-&gt;appendQuery('and banners_id not in (:banner_ids)');
+        $Qbanner-&gt;bindRaw(':banner_ids', implode(',', $this-&gt;_shown_ids));
+      }
+
+      $Qbanner-&gt;bindTable(':table_banners', TABLE_BANNERS);
+      $Qbanner-&gt;bindValue(':banners_group', $group);
+      $Qbanner-&gt;executeRandom();
+
+      if ($Qbanner-&gt;numberOfRows() &gt; 0) {
+        $this-&gt;_exists_id = $Qbanner-&gt;valueInt('banners_id');
+
+        return true;
+      }
+
+      return false;
+    }
+
+    function display($id = '') {
+      global $osC_Database;
+
+      $banner_string = false;
+
+      if (empty($id) &amp;&amp; isset($this-&gt;_exists_id) &amp;&amp; is_numeric($this-&gt;_exists_id)) {
+        $id = $this-&gt;_exists_id;
+
+        unset($this-&gt;_exists_id);
+      }
+
+      $Qbanner = $osC_Database-&gt;query('select * from :table_banners where banners_id = :banners_id and status = 1');
+      $Qbanner-&gt;bindTable(':table_banners', TABLE_BANNERS);
+      $Qbanner-&gt;bindInt(':banners_id', $id);
+      $Qbanner-&gt;execute();
+
+      if ($Qbanner-&gt;numberOfRows() &gt; 0) {
+        if (tep_not_null($Qbanner-&gt;value('banners_html_text'))) {
+          $banner_string = $Qbanner-&gt;value('banners_html_text');
+        } else {
+          $banner_string = '&lt;a href="' . tep_href_link(FILENAME_REDIRECT, 'action=banner&amp;goto=' . $Qbanner-&gt;valueInt('banners_id')) . '" target="_blank"&gt;' . tep_image(DIR_WS_IMAGES . $Qbanner-&gt;value('banners_image'), $Qbanner-&gt;value('banners_title')) . '&lt;/a&gt;';
+        }
+
+        $this-&gt;_updateDisplayCount($Qbanner-&gt;valueInt('banners_id'));
+
+        if ($this-&gt;show_duplicates_in_group === false) {
+          $this-&gt;_shown_ids[] = $Qbanner-&gt;valueInt('banners_id');
+        }
+      }
+
+      $Qbanner-&gt;freeResult();
+
+      return $banner_string;
+    }
+
+    function getURL($id, $increment_click = false) {
+      global $osC_Database;
+
+      $url = false;
+
+      $Qbanner = $osC_Database-&gt;query('select banners_url from :table_banners where banners_id = :banners_id and status = 1');
+      $Qbanner-&gt;bindTable(':table_banners', TABLE_BANNERS);
+      $Qbanner-&gt;bindInt(':banners_id', $id);
+      $Qbanner-&gt;execute();
+
+      if ($Qbanner-&gt;numberOfRows() &gt; 0) {
+        $url = $Qbanner-&gt;value('banners_url');
+
+        if ($increment_click === true) {
+          $this-&gt;_updateClickCount($id);
+        }
+      }
+
+      $Qbanner-&gt;freeResult();
+
+      return $url;
+    }
+
+/* Private methods */
+
+    function _setStatus($id, $active) {
+      global $osC_Database;
+
+      if ($active === true) {
+        $Qbanner = $osC_Database-&gt;query('update :table_banners set status = 1, date_status_change = now(), date_scheduled = NULL where banners_id = :banners_id');
+        $Qbanner-&gt;bindTable(':table_banners', TABLE_BANNERS);
+        $Qbanner-&gt;bindInt(':banners_id', $id);
+        $Qbanner-&gt;execute();
+      } else {
+        $Qbanner = $osC_Database-&gt;query('update :table_banners set status = 0, date_status_change = now() where banners_id = :banners_id');
+        $Qbanner-&gt;bindTable(':table_banners', TABLE_BANNERS);
+        $Qbanner-&gt;bindInt(':banners_id', $id);
+        $Qbanner-&gt;execute();
+      }
+
+      $Qbanner-&gt;freeResult();
+    }
+
+    function _updateDisplayCount($id) {
+      global $osC_Database;
+
+      $Qcheck = $osC_Database-&gt;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")');
+      $Qcheck-&gt;bindTable(':table_banners_history', TABLE_BANNERS_HISTORY);
+      $Qcheck-&gt;bindInt(':banners_id', $id);
+      $Qcheck-&gt;execute();
+
+      if ($Qcheck-&gt;valueInt('count') &gt; 0) {
+        $Qbanner = $osC_Database-&gt;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")');
+      } else {
+        $Qbanner = $osC_Database-&gt;query('insert into :table_banners_history (banners_id, banners_shown, banners_history_date) values (:banners_id, 1, now())');
+      }
+      $Qbanner-&gt;bindTable(':table_banners_history', TABLE_BANNERS_HISTORY);
+      $Qbanner-&gt;bindInt(':banners_id', $id);
+      $Qbanner-&gt;execute();
+
+      $Qcheck-&gt;freeResult();
+      $Qbanner-&gt;freeResult();
+    }
+
+    function _updateClickCount($id) {
+      global $osC_Database;
+
+      $Qcheck = $osC_Database-&gt;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")');
+      $Qcheck-&gt;bindTable(':table_banners_history', TABLE_BANNERS_HISTORY);
+      $Qcheck-&gt;bindInt(':banners_id', $id);
+      $Qcheck-&gt;execute();
+
+      if ($Qcheck-&gt;valueInt('count') &gt; 0) {
+        $Qbanner = $osC_Database-&gt;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")');
+      } else {
+        $Qbanner = $osC_Database-&gt;query('insert into :table_banners_history (banners_id, banners_clicked, banners_history_date) values (:banners_id, 1, now())');
+      }
+      $Qbanner-&gt;bindTable(':table_banners_history', TABLE_BANNERS_HISTORY);
+      $Qbanner-&gt;bindInt(':banners_id', $id);
+      $Qbanner-&gt;execute();
+
+      $Qcheck-&gt;freeResult();
+      $Qbanner-&gt;freeResult();
+    }
+  }
+?&gt;
</pre></div>
<hr /><a name="file4" /><div class="file">
<span class="pathname" id="removed"><a href="http://cvs.oscommerce.com/viewcvs.cgi/catalog">catalog</a>/<a href="http://cvs.oscommerce.com/viewcvs.cgi/catalog/catalog">catalog</a>/<a href="http://cvs.oscommerce.com/viewcvs.cgi/catalog/catalog/includes">includes</a>/<a href="http://cvs.oscommerce.com/viewcvs.cgi/catalog/catalog/includes/functions">functions</a><br /></span>
<div class="fileheader" id="removed"><big><b>banner.php</b></big> <small id="info">removed after <a href="http://cvs.oscommerce.com/viewcvs.cgi/catalog/catalog/includes/functions/banner.php?rev=1.14&amp;content-type=text/vnd.viewcvs-markup">1.14</a></small></div>
<pre class="diff"><small id="info">diff -N banner.php
--- /tmp/cvsAAAk7aiJO	Sun Nov 28 19:37:12 2004
+++ /dev/null	Sun Nov 28 19:37:11 2004
@@ -1,182 +0,0 @@
</small></pre><pre class="diff" id="removed">-&lt;?php
-/*
-  $Id$
-
-  osCommerce, Open Source E-Commerce Solutions
-  http://www.oscommerce.com
-
-  Copyright (c) 2004 osCommerce
-
-  Released under the GNU General Public License
-*/
-
-////
-// Sets the status of a banner
-  function tep_set_banner_status($banners_id, $status) {
-    global $osC_Database;
-
-    if ($status == '1') {
-      $Qbanner = $osC_Database-&gt;query('update :table_banners set status = 1, date_status_change = now(), date_scheduled = NULL where banners_id = :banners_id');
-      $Qbanner-&gt;bindRaw(':table_banners', TABLE_BANNERS);
-      $Qbanner-&gt;bindInt(':banners_id', $banners_id);
-      $Qbanner-&gt;execute();
-    } else {
-      $Qbanner = $osC_Database-&gt;query('update :table_banners set status = 0, date_status_change = now() where banners_id = :banners_id');
-      $Qbanner-&gt;bindRaw(':table_banners', TABLE_BANNERS);
-      $Qbanner-&gt;bindInt(':banners_id', $banners_id);
-      $Qbanner-&gt;execute();
-    }
-
-    $Qbanner-&gt;freeResult();
-  }
-
-////
-// Auto activate banners
-  function tep_activate_banners() {
-    global $osC_Database;
-
-    $Qbanner = $osC_Database-&gt;query('select banners_id, date_scheduled from :table_banners where date_scheduled != ""');
-    $Qbanner-&gt;bindRaw(':table_banners', TABLE_BANNERS);
-    $Qbanner-&gt;execute();
-
-    if ($Qbanner-&gt;numberOfRows()) {
-      while ($Qbanner-&gt;next()) {
-        if (date('Y-m-d H:i:s') &gt;= $Qbanner-&gt;value('date_scheduled')) {
-          tep_set_banner_status($Qbanner-&gt;valueInt('banners_id'), '1');
-        }
-      }
-    }
-
-    $Qbanner-&gt;freeResult();
-  }
-
-////
-// Auto expire banners
-  function tep_expire_banners() {
-    global $osC_Database;
-
-    $Qbanner = $osC_Database-&gt;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');
-    $Qbanner-&gt;bindRaw(':table_banners', TABLE_BANNERS);
-    $Qbanner-&gt;bindRaw(':table_banners_history', TABLE_BANNERS_HISTORY);
-    $Qbanner-&gt;execute();
-
-    if ($Qbanner-&gt;numberOfRows()) {
-      while ($Qbanner-&gt;next()) {
-        if (tep_not_null($Qbanner-&gt;value('expires_date'))) {
-          if (date('Y-m-d H:i:s') &gt;= $Qbanner-&gt;value('expires_date')) {
-            tep_set_banner_status($Qbanner-&gt;valueInt('banners_id'), '0');
-          }
-        } elseif (tep_not_null($Qbanner-&gt;valueInt('expires_impressions'))) {
-          if ( ($Qbanner-&gt;valueInt('expires_impressions') &gt; 0) &amp;&amp; ($Qbanner-&gt;valueInt('banners_shown') &gt;= $Qbanner-&gt;valueInt('expires_impressions')) ) {
-            tep_set_banner_status($Qbanner-&gt;valueInt('banners_id'), '0');
-          }
-        }
-      }
-    }
-
-    $Qbanner-&gt;freeResult();
-  }
-
-////
-// Display a banner from the specified group or banner id ($identifier)
-  function tep_display_banner($action, $identifier) {
-    global $osC_Database;
-
-    if ($action == 'dynamic') {
-      $Qbannercheck = $osC_Database-&gt;query('select count(*) as count from :table_banners where status = 1 and banners_group = :banners_group');
-      $Qbannercheck-&gt;bindRaw(':table_banners', TABLE_BANNERS);
-      $Qbannercheck-&gt;bindValue(':banners_group', $identifier);
-      $Qbannercheck-&gt;execute();
-
-      if ($Qbannercheck-&gt;valueInt('count') &gt; 0) {
-        $Qbanner = $osC_Database-&gt;query('select banners_id, banners_title, banners_image, banners_html_text from :table_banners where banners_group = :banners_group and status = 1');
-        $Qbanner-&gt;bindRaw(':table_banners', TABLE_BANNERS);
-        $Qbanner-&gt;bindValue(':banners_group', $identifier);
-        $Qbanner-&gt;executeRandom();
-      }
-
-      $Qbannercheck-&gt;freeResult();
-    } elseif ($action == 'static') {
-      $Qbanner = $osC_Database-&gt;query('select banners_id, banners_title, banners_image, banners_html_text from :table_banners where banners_id = :banners_id and status = 1');
-      $Qbanner-&gt;bindRaw(':table_banners', TABLE_BANNERS);
-      $Qbanner-&gt;bindInt(':banners_id', $identifier);
-      $Qbanner-&gt;execute();
-    }
-
-    if ($Qbanner-&gt;numberOfRows() === 1) {
-      if (tep_not_null($Qbanner-&gt;value('banners_html_text'))) {
-        $banner_string = $Qbanner-&gt;value('banners_html_text');
-      } else {
-        $banner_string = '&lt;a href="' . tep_href_link(FILENAME_REDIRECT, 'action=banner&amp;goto=' . $Qbanner-&gt;valueInt('banners_id')) . '" target="_blank"&gt;' . tep_image(DIR_WS_IMAGES . $Qbanner-&gt;value('banners_image'), $Qbanner-&gt;value('banners_title')) . '&lt;/a&gt;';
-      }
-
-      tep_update_banner_display_count($Qbanner-&gt;valueInt('banners_id'));
-
-      $Qbanner-&gt;freeResult();
-
-      return $banner_string;
-    } else {
-      return false;
-    }
-  }
-
-////
-// Check to see if a banner exists
-  function tep_banner_exists($action, $identifier) {
-    global $osC_Database;
-
-    if ($action == 'dynamic') {
-      $Qbanner = $osC_Database-&gt;query('select banners_id, banners_title, banners_image, banners_html_text from :table_banners where status = 1 and banners_group = :banners_group');
-      $Qbanner-&gt;bindRaw(':table_banners', TABLE_BANNERS);
-      $Qbanner-&gt;bindValue(':banners_group', $identifier);
-      $Qbanner-&gt;executeRandom();
-    } else {
-      $Qbanner = $osC_Database-&gt;query('select banners_id, banners_title, banners_image, banners_html_text from :table_banners where status = 1 and banners_id = :banners_id');
-      $Qbanner-&gt;bindRaw(':table_banners', TABLE_BANNERS);
-      $Qbanner-&gt;bindInt(':banners_id', $identifier);
-      $Qbanner-&gt;execute();
-    }
-
-    if ($Qbanner-&gt;numberOfRows()) {
-      return true;
-    } else {
-      return false;
-    }
-  }
-
-////
-// Update the banner display statistics
-  function tep_update_banner_display_count($banner_id) {
-    global $osC_Database;
-
-    $Qbannercheck = $osC_Database-&gt;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")');
-    $Qbannercheck-&gt;bindRaw(':table_banners_history', TABLE_BANNERS_HISTORY);
-    $Qbannercheck-&gt;bindInt(':banners_id', $banner_id);
-    $Qbannercheck-&gt;execute();
-
-    if ($Qbannercheck-&gt;valueInt('count') &gt; 0) {
-      $Qbanner = $osC_Database-&gt;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")');
-    } else {
-      $Qbanner = $osC_Database-&gt;query('insert into :table_banners_history (banners_id, banners_shown, banners_history_date) values (:banners_id, 1, now())');
-    }
-    $Qbanner-&gt;bindRaw(':table_banners_history', TABLE_BANNERS_HISTORY);
-    $Qbanner-&gt;bindInt(':banners_id', $banner_id);
-    $Qbanner-&gt;execute();
-
-    $Qbannercheck-&gt;freeResult();
-    $Qbanner-&gt;freeResult();
-  }
-
-////
-// Update the banner click statistics
-  function tep_update_banner_click_count($banner_id) {
-    global $osC_Database;
-
-    $Qbanner = $osC_Database-&gt;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")');
-    $Qbanner-&gt;bindRaw(':table_banners_history', TABLE_BANNERS_HISTORY);
-    $Qbanner-&gt;bindInt(':banners_id', $banner_id);
-    $Qbanner-&gt;execute();
-
-    $Qbanner-&gt;freeResult();
-  }
-?&gt;
<hr /><a name="file5" /><div class="file">
<span class="pathname"><a href="http://cvs.oscommerce.com/viewcvs.cgi/catalog">catalog</a>/<a href="http://cvs.oscommerce.com/viewcvs.cgi/catalog/catalog">catalog</a>/<a href="http://cvs.oscommerce.com/viewcvs.cgi/catalog/catalog/includes">includes</a>/<a href="http://cvs.oscommerce.com/viewcvs.cgi/catalog/catalog/includes/modules">modules</a>/<a href="http://cvs.oscommerce.com/viewcvs.cgi/catalog/catalog/includes/modules/services">services</a><br /></span>
<div class="fileheader"><big><b>banner.php</b></big> <small id="info"><a href="http://cvs.oscommerce.com/viewcvs.cgi/catalog/catalog/includes/modules/services/banner.php?rev=1.1&amp;content-type=text/vnd.viewcvs-markup">1.1</a> <a href="http://cvs.oscommerce.com/viewcvs.cgi/catalog/catalog/includes/modules/services/banner.php.diff?r1=1.1&amp;r2=1.2">-&gt;</a> <a href="http://cvs.oscommerce.com/viewcvs.cgi/catalog/catalog/includes/modules/services/banner.php?rev=1.2&amp;content-type=text/vnd.viewcvs-markup">1.2</a></small></div>
<pre class="diff"><small id="info">diff -u -r1.1 -r1.2
--- banner.php	2004/04/13 08:02:18	1.1
+++ banner.php	2004/11/28 18:37:12	1.2
@@ -18,11 +18,14 @@
</small></pre><pre class="diff" id="context">         $preceeds;
 
     function start() {
</pre><pre class="diff" id="removed">-      include('includes/functions/banner.php');
</pre><pre class="diff" id="added">+      global $osC_Banner;
</pre><pre class="diff" id="context"> 
</pre><pre class="diff" id="removed">-      tep_activate_banners();
-      tep_expire_banners();
</pre><pre class="diff" id="added">+      require('includes/classes/banner.php');
+      $osC_Banner = new osC_Banner();
</pre><pre class="diff" id="context"> 
</pre><pre class="diff" id="added">+      $osC_Banner-&gt;activateAll();
+      $osC_Banner-&gt;expireAll();
+
</pre><pre class="diff" id="context">       return true;
     }
 
</pre><pre class="diff"><small id="info">@@ -31,15 +34,19 @@
</small></pre><pre class="diff" id="context">     }
 
     function install() {
</pre><pre class="diff" id="removed">-      return false;
</pre><pre class="diff" id="added">+      global $osC_Database;
+
+      $osC_Database-&gt;simpleQuery("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Display Duplicate Banners', 'SERVICE_BANNER_SHOW_DUPLICATE', 'False', 'Show duplicate banners in the same banner group on the same page?', '6', '0', 'tep_cfg_select_option(array(\'True\', \'False\'), ', now())");
</pre><pre class="diff" id="context">     }
 
     function remove() {
</pre><pre class="diff" id="removed">-      return false;
</pre><pre class="diff" id="added">+      global $osC_Database;
+
+      $osC_Database-&gt;simpleQuery("delete from " . TABLE_CONFIGURATION . " where configuration_key in ('" . implode("', '", $this-&gt;keys()) . "')");
</pre><pre class="diff" id="context">     }
 
     function keys() {
</pre><pre class="diff" id="removed">-      return false;
</pre><pre class="diff" id="added">+      return array('SERVICE_BANNER_SHOW_DUPLICATE');
</pre><pre class="diff" id="context">     }
   }
 ?&gt;
</pre></div>
<center><small><a href="http://www.badgers-in-foil.co.uk/projects/cvsspam/" title="commit -&gt; email">CVSspam</a> 0.2.9</small></center>
</body></html>


-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users.
Discover which products truly live up to the hype. Start reading now. 
http://productguide.itmanagersjournal.com/