[ Index ]

PHP Cross Reference of Mambo 4.6.5

[ Variables ]     [ Functions ]     [ Classes ]     [ Constants ]     [ Statistics ]

title

Body

[close]

/modules/ -> mod_banners.php (source)

   1  <?php
   2  /**
   3  * @package Mambo
   4  * @author Mambo Foundation Inc see README.php
   5  * @copyright (C) 2000 - 2009 Mambo Foundation Inc.
   6  * See COPYRIGHT.php for copyright notices and details.
   7  * @license GNU/GPL Version 2, see LICENSE.php
   8  *
   9  * Redistributions of files must retain the above copyright notice.
  10  *
  11  * Mambo is free software; you can redistribute it and/or
  12  * modify it under the terms of the GNU General Public License
  13  * as published by the Free Software Foundation; version 2 of the License.
  14  */
  15  
  16  /** ensure this file is being included by a parent file */
  17  defined( '_VALID_MOS' ) or die( 'Direct Access to this location is not allowed.' );
  18  
  19  $clientids = $params->get( 'banner_cids', '' );
  20  $where = '';
  21  if( $clientids <> '' ) {
  22      $where = "\nAND cid in ($clientids)";
  23  }
  24      
  25  $moduleclass_sfx = $params->get( 'moduleclass_sfx' );
  26  
  27  $sql = "SELECT count(*) AS numrows FROM #__banner WHERE showBanner=1"
  28      . (($where<>'') ? $where : "");
  29  $database->setQuery( $sql );
  30  
  31  $numrows = $database->loadResult();
  32  if ($numrows === null) {
  33      echo $database->stderr( true );
  34      return;
  35  }
  36  
  37  if ($numrows > 1) {
  38      mt_srand( (double) microtime()*1000000 );
  39      $bannum = mt_rand( 0, --$numrows );
  40  } else {
  41      $bannum = 0;
  42  }
  43  
  44  $sql = "SELECT * FROM #__banner WHERE showBanner=1 "
  45      . (($where<>'') ? $where : "")
  46      . "\nLIMIT $bannum,1";
  47  $database->setQuery( $sql );
  48  
  49  $banner = null;
  50  if ($database->loadObject( $banner )) {
  51      $database->setQuery( "UPDATE #__banner SET impmade=impmade+1 WHERE bid='$banner->bid'" );
  52      if(!$database->query()) {
  53          echo $database->stderr( true );
  54          return;
  55      }
  56      $banner->impmade++;
  57      
  58      if ($numrows > 0) {
  59          // Check if this impression is the last one and print the banner
  60          if ($banner->imptotal == $banner->impmade) {
  61              $query = "INSERT INTO #__bannerfinish (cid, type, name, impressions, clicks, imageurl, datestart, dateend)
  62                  VALUES ('$banner->cid', '$banner->type', '$banner->name', '$banner->impmade', '$banner->clicks', '$banner->imageurl', '$banner->date', now())";
  63              $database->setQuery($query);
  64              if(!$database->query()) {
  65                  die($database->stderr(true));
  66              }
  67              
  68              $query="DELETE FROM #__banner WHERE bid=$banner->bid";
  69              $database->setQuery($query);
  70              if(!$database->query()) {
  71                  die($database->stderr(true));
  72              }
  73          }
  74  
  75          if (trim( $banner->custombannercode )) {
  76              echo $banner->custombannercode;
  77          } else if (eregi( "(\.bmp|\.gif|\.jpg|\.jpeg|\.png)$", $banner->imageurl )) {
  78              $imageurl = "$mosConfig_live_site/images/banners/$banner->imageurl";
  79              echo "<a href=\"".sefRelToAbs("index.php?option=com_banners&amp;task=click&amp;bid=$banner->bid")."\" target=\"_blank\"><img src=\"$imageurl\" border=\"0\" alt=\"".T_('Banner')."\" /></a>";
  80              
  81          } else if (eregi("\.swf$", $banner->imageurl)) {
  82              $imageurl = "$mosConfig_live_site/images/banners/".$banner->imageurl;
  83              echo "<object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\"http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0\" border=\"5\">
  84                      <param name=\"movie\" value=\"$imageurl\"><embed src=\"$imageurl\" loop=\"false\" pluginspage=\"http://www.macromedia.com/go/get/flashplayer\" type=\"application/x-shockwave-flash\"></embed></object>";
  85          }
  86      }
  87  } else {
  88      echo "&nbsp;";
  89  }
  90  ?>