<?php
/**
 * $Source: /home/cvs/nukescripts/kernel/babanners2.php,v $
 * $Revision: 1.1.0a $
 * $Author: cyril $
 * $Date: 2006/06/19 21:03:12 $
 *
 */
/********************************************************/
/* NSN Banner Ads                                       */
/* By: NukeScripts Network (webmaster@nukescripts.net)  */
/* http://www.nukescripts.net                           */
/* Copyright © 2000-2005 by NukeScripts Network         */
/********************************************************/
defined('MAXIMUS') or die ('Access denied babanners2 MAXIMUS directly...');

$modname = "Banner_Ads";
global $adminmail, $sitename, $nukeurl;
$testdate = date ("Y-m-d");
$bresult = $GLOBALS['db']->sql_query("SELECT `bid` FROM `".TABLE_NSNBA_BANNERS."` WHERE `pid`='2' AND `active`='1'");
$numrows = $GLOBALS['db']->sql_numrows($bresult);
if($numrows>0) {
  if($numrows==1) {
    list ($bannum) = $GLOBALS['db']->sql_fetchrow($bresult);
  } else if($numrows>1) {
    $i = 1;
    while(list ($id) = $GLOBALS['db']->sql_fetchrow($bresult)) {
      $abid[$i] = $id;
      $i++;
    }
    $bannum = $abid[rand(1, $numrows)];
  }
} else {
  $bannum = 0;
}
if(!defined('ADMIN_ALLOW')) { $GLOBALS['db']->sql_query("UPDATE `".TABLE_NSNBA_BANNERS."` SET `impmade`=impmade+1 WHERE `bid`='$bannum'"); }
if($numrows>0) {
  $bidinfo = $GLOBALS['db']->sql_fetchrow($GLOBALS['db']->sql_query("SELECT * FROM `".TABLE_NSNBA_BANNERS."` WHERE `pid`='2' AND `active`='1' AND `bid`='$bannum'"));
  $cidinfo = $GLOBALS['db']->sql_fetchrow($GLOBALS['db']->sql_query("SELECT * FROM `".TABLE_NSNBA_CLIENTS."` WHERE `cid`='".$bidinfo['cid']."'"));
  if(($bidinfo['imptotal'] <= $bidinfo['impmade']) AND ($bidinfo['imptotal'] != 0)) {
    get_lang($modname);
    $GLOBALS['db']->sql_query("UPDATE `".TABLE_NSNBA_BANNERS."` SET `active`='0' WHERE `bid`='$bannum'");
    $fecha = date("F jS Y, h:iA.");
    $subject  = _BA_BANSTATAT." $sitename";
    $message  = _BA_COMPSTAT." $sitename:\n\n";
    $message .= _BA_CONNME.": ".$cidinfo['name']."\n";
    $message .= _BA_BANNUM.": $bannum\n";
    $message .= _BA_IMGSRC.": $nukeurl/".$bidinfo['imageurl']."\n";
    $message .= _BA_CLKU.": ".$bidinfo['clickurl']."\n\n";
    $message .= _BA_IMPPUR.": ".$bidinfo['imptotal']."\n";
    $message .= _BA_IMPMAD.": ".$bidinfo['impmade']."\n";
    $message .= _BA_CLKS.": ".$bidinfo['clicks']."\n";
    $message .= _BA_REPORTON.": $fecha";
    $from = "$sitename <$adminmail>";
    mail($cidinfo['email'], $subject, $message, "From: $from\nX-Mailer: PHP/" . phpversion());
  }
  if(($testdate > $bidinfo['dateend']) AND ($bidinfo['dateend'] != "0000-00-00")) {
    get_lang($modname);
    $GLOBALS['db']->sql_query("UPDATE `".TABLE_NSNBA_BANNERS."` SET `active`='0' WHERE `bid`='$bannum'");
    $fecha = date("F jS Y, h:iA.");
    $subject  = _BA_BANSTATAT." $sitename";
    $message  = _BA_COMPSTAT." $sitename:\n\n";
    $message .= _BA_CONNME.": ".$cidinfo['name']."\n";
    $message .= _BA_BANNUM.": $bannum\n";
    $message .= _BA_IMGSRC.": $nukeurl/".$bidinfo['imageurl']."\n";
    $message .= _BA_CLKU.": ".$bidinfo['clickurl']."\n\n";
    $message .= _BA_IMPMAD.": ".$bidinfo['impmade']."\n";
    $message .= _BA_CLKS.": ".$bidinfo['clicks']."\n";
    $message .= _BA_STRDTE.": ".$bidinfo['datestr']."\n";
    $message .= _BA_ENDDTE.": ".$bidinfo['dateend']."\n";
    $message .= _BA_REPORTON.": $fecha";
    $from = "$sitename <$adminmail>";
    mail($cidinfo['email'], $subject, $message, "From: $from\nX-Mailer: PHP/" . phpversion());
  }
  if($bidinfo['flash']==1 AND $bidinfo['code']==0) {
    $babanners2  = "\n\n<object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0\" width='".$bidinfo['width']."' height='".$bidinfo['height']."'>";
    $babanners2 .= "\n<param name=movie value='images/banners/clicksba_h.swf'>";
    $babanners2 .= "\n<param name=quality value=high>";
    $babanners2 .= "\n<param name=FlashVars value='imageurl=".$bidinfo['imageurl']."&bid=$bannum'>";
    $babanners2 .= "\n<embed src='images/banners/clicksba_h.swf?imageurl=".$bidinfo['imageurl']."&bid=$bannum' quality=high pluginspage=\"http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash\" type=\"application/x-shockwave-flash\" width='".$bidinfo['width']."' height='".$bidinfo['height']."'>";
    $babanners2 .= "\n</embed> ";
    $babanners2 .= "\n</object>\n\n";
  } elseif($bidinfo['flash']==0 AND $bidinfo['code']==1) {
    $fp = fopen ($bidinfo['imageurl'], "rb");
    $contents = fread ($fp, filesize ($bidinfo['imageurl']));
    fclose ($fp);
    $babanners2  = "$contents";
  } else {
    $babanners2  = "<a href='clicksba.php?bid=$bannum' target='_blank'><img src='".$bidinfo['imageurl']."' border='0' alt='".$bidinfo['alttext']."' title='".$bidinfo['alttext']."' height='".$bidinfo['height']."' width='".$bidinfo['width']."'></a>";
  }
} else {
  $babanners2 = "<a href='modules.php?name=$modname'><img src='modules/$modname/images/ban-banner-1.png' border='0' alt='$sitename' title='$sitename'></a>";
}
$bresult3 = $GLOBALS['db']->sql_query("SELECT `bid`, `datestr` FROM `".TABLE_NSNBA_BANNERS."` WHERE `pid`='2' AND `active`='-1'");
$numrows3 = $GLOBALS['db']->sql_numrows($bresult3);
if($numrows3>0) {
  while(list ($id, $datestr) = $GLOBALS['db']->sql_fetchrow($bresult3)) {
    if(($testdate >= $datestr) AND ($datestr != "0000-00-00")) {
      $GLOBALS['db']->sql_query("UPDATE `".TABLE_NSNBA_BANNERS."` SET `active`='1' WHERE `bid`='$id'");
    }
  }
}