<?php
/**
 * $Source: /home/cvs/nukescripts/kernel/babanners1.php,v $
 * $Revision: 1.1.0a $
 * $Author: cyril $
 * $Date: 2006/06/19 21:03:12 $
 *
 */
/************************************************************************/
/* Maximus CMS: Web Portal System                                       */
/* ==============================                                       */
/*                                                                      */
/* Copyright (c) 2002 - 2006                                            */
/* http://www.php-maximus.fr                                            */
/* dev@php-maximus.org                                                  */
/*                                                                      */
/* This program is free software. You can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation; either version 2 of the License.       */
/************************************************************************/
/* Based on PHP-NUKE: Web Portal System                                 */
/************************************************************************/
/********************************************************/
/* 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 babanners1 MAXIMUS directly...');

$modname = "Banner_Ads";

global $adminmail, $sitename, $nukeurl;
$testdate = date ("Y-m-d");
if($numrows>0) {
$i = 1;
while( $rar1 = $GLOBALS['db']->sql_fetchrow($bresult)) {
$id = $GLOBALS['db']->XMFnum($rar1['bid']);
$abid[$i] = $id;
$i++;
}
$bannum = $abid[rand(1, $numrows)];
} else {
$bannum = 0;
}
if(!defined('ADMIN_ALLOW')) { $sqlup = "UPDATE `".TABLE_NSNBA_BANNERS."` SET `impmade`=impmade+1 WHERE `bid`='$bannum'";
if ( !($up = $GLOBALS['db']->sql_query($sqlup)) )
{ query_die(GENERAL_ERROR, 'Could not obtain _nsnba_banners', '', __LINE__, __FILE__, $sqlup);}
}
if($numrows>0) {
  $sql1 = "SELECT * FROM `".TABLE_NSNBA_BANNERS."` WHERE `pid`='1' AND `active`='1' AND `bid`='$bannum'";
if ( !($bresult1 = $GLOBALS['db']->sql_query($sql1)) )
{ query_die(GENERAL_ERROR, 'Could not obtain _nsnba_banners', '', __LINE__, __FILE__, $sql1);}
  $bidinfo = $GLOBALS['db']->sql_fetchrow($bresult1);


  $sql2 = "SELECT * FROM `".TABLE_NSNBA_CLIENTS."` WHERE `cid`='".$bidinfo['cid']."'";
if ( !($bresult2 = $GLOBALS['db']->sql_query($sql2)) )
{ query_die(GENERAL_ERROR, 'Could not obtain _nsnba_clients', '', __LINE__, __FILE__, $sql2);}
  $cidinfo = $GLOBALS['db']->sql_fetchrow($result2);


  if(($bidinfo['imptotal'] <= $bidinfo['impmade']) AND ($bidinfo['imptotal'] != 0)) {
get_lang($modname);
$sql3 = "UPDATE `".TABLE_NSNBA_BANNERS."` SET `active`='0' WHERE `bid`='$bannum'";
if ( !($bresult3 = $GLOBALS['db']->sql_query($sql3)) )
{ query_die(GENERAL_ERROR, 'Could not obtain _nsnba_banners', '', __LINE__, __FILE__, $sql3);}
    $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);
    $sqlup2 = "UPDATE `".TABLE_NSNBA_BANNERS."` SET `active`='0' WHERE `bid`='$bannum'";
if ( !($bresultup = $GLOBALS['db']->sql_query($sqlup2)) )
{ query_die(GENERAL_ERROR, 'Could not obtain _nsnba_banners', '', __LINE__, __FILE__, $sqlup2);}
    $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) {
    $babanners1  = "\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']."'>";
    $babanners1 .= "\n<param name=movie value='images/banners/clicksba_h.swf'>";
    $babanners1 .= "\n<param name=quality value=high>";
    $babanners1 .= "\n<param name=FlashVars value='imageurl=".$bidinfo['imageurl']."&bid=$bannum'>";
    $babanners1 .= "\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']."'>";
    $babanners1 .= "\n</embed> ";
    $babanners1 .= "\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);
    $babanners1  = "$contents";
  } else {
    $babanners1  = "<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 {
  $babanners1 = "<a href=\"modules.php?name=$modname\"><img src=\"modules/$modname/images/ban-banner-1.png\" border=\"0\" alt=\"$sitename\" title=\"$sitename\"></a>";
}
$sql4 = "SELECT `bid`, `datestr` FROM `".TABLE_NSNBA_BANNERS."` WHERE `pid`='1' AND `active`='-1'";
if ( !($bresult4 = $GLOBALS['db']->sql_query($sql4)) )
{ query_die(GENERAL_ERROR, 'Could not obtain _nsnba_banners', '', __LINE__, __FILE__, $sql4);}
$numrows4 = $GLOBALS['db']->sql_numrows($bresult4);
if($numrows4>0) {
while($rar3 = $GLOBALS['db']->sql_fetchrow($bresult4)) {
$id = stripslashes($rar3['bid']);
$datestr = stripslashes($rar['datestr']);
    if(($testdate >= $datestr) AND ($datestr != "0000-00-00")) {
      $sql5 = "UPDATE `".TABLE_NSNBA_BANNERS."` SET `active`='1' WHERE `bid`='$id'";
if ( !($bresult5 = $GLOBALS['db']->sql_query($sql5)) )
{ query_die(GENERAL_ERROR, 'Could not obtain _nsnba_banners', '', __LINE__, __FILE__, $sql5);}
    }
  }
}