============================================================================================================================
Modification Name: Banner Ad Rotator

Version: 3.0

Author: GuldantheWarlock (GuldantheWarlock@xmbgarage.com)

Based on Banner Ad Rotator by:
  Peter Eltringham (Original)
  John Briggs (Version 2.1)
  Train (Michael Fraker) (Version 2.2)

Description:
This modification will give you the ability to add Ad Banners to your header and/or footer which will rotate the banners.
This modification will keep records of what ads have been clicked, which may be viewed in the admin panel

Supported Version: XMB 1.9.5 Nexus SP1

License Notes:
This modification is released under the GPL License v3. A copy is provided with this software package.

Please backup your files before installing this modification.
Neither XMBGarage nor the author can be held responsible if your board stops functioning properly due to you installing this modification.
============================================================================================================================
=======
Step 1:
=======
====================================
Go To Administration Panel --> Insert Raw SQL
====================================
===================================
Paste The Following Code and Submit Changes:
===================================

ALTER TABLE `$table_settings` ADD `ads` SET('on','off') NOT NULL default 'on';

CREATE TABLE `$table_adrecord` (
  `id` INT(7) NOT NULL auto_increment,
  `aid` INT(7) NOT NULL,
  `time` INT(15) NOT NULL,
  `browser` VARCHAR(50) NOT NULL default '',
  `os` varchar(50) NOT NULL default '',
  PRIMARY KEY(`id`)
) TYPE=MyISAM;

CREATE TABLE `$table_ads` (
  `aid` INT(7) NOT NULL auto_increment,
  `name` VARCHAR(255) NOT NULL default '',
  `url` TEXT NOT NULL,
  `img` TEXT NOT NULL,
  `adoption` SET('header', 'footer', 'both') NOT NULL default 'both',
  `adstatus` SET('on','off') NOT NULL default 'on',
  PRIMARY KEY(`aid`)
) TYPE=MyISAM;

============================================================================================================================
=======
Step 2:
=======
=======================
Edit File:  lang/English.lang.php
=======================
============================
Add Code To End Of File Above  ?>
============================

// Banner Ad Rotator Mod Begin
$lang['ads'] = 'Advertisments';
$lang['ads_name'] = 'Client:';
$lang['ads_url'] = 'Url:';
$lang['ads_img'] = 'Image:';
$lang['ads_option'] = 'Options:';
$lang['ads_status'] = 'Status:';
$lang['ads_header'] = 'Header';
$lang['ads_footer'] = 'Footer';
$lang['ads_both'] = 'Both';
$lang['ads_updatesuccess'] = 'Ads Updated Sucessfully!';
$lang['ads_addedsuccess'] = 'Ad Added Sucessfully!';
$lang['ads_create'] = 'Create';
$lang['ads_notfound'] = 'There are no ads to display.';
$lang['ads_create'] = 'Create New Ad:';
$lang['ads_clicks'] = 'Clicks:';
// Banner Ad Rotator Mod End

============================================================================================================================
=======
Step 3:
=======
============
Edit cp.php:
============
==========
Find Code:
==========

        $notifycheck[0] = $notifycheck[1] = $notifycheck[2] = false;

===============
Add Code Above:
===============

        // Banner Ad Rotator Mod Begin
        $adson = $adsoff = '';
        switch ($SETTINGS['ads']) {
            case 'on':
                $adson = $selHTML;
                break;
            default:
                $adsoff = $selHTML;
                break;
        }
        // Banner Ad Rotator Mod End

==========
Find Code:
==========

        printsetting1($lang['reportpoststatus'], 'reportpostnew', $reportposton, $reportpostoff);

===============
Add Code Below:
===============

        // Banner Ad Rotator Mod Begin
        printsetting1($lang['ads'], 'adsnew', $adson, $adsoff);
        // Banner Ad Rotator Mod End
        
==========
Find Code:
==========

        $resetSigNew = ($resetSigNew == 'on') ? 'on' : 'off';

===============
Add Code Below:
===============

        // Banner Ad Rotator Mod Begin
        $adsnew = ($adsnew == 'on') ? 'on' : 'off';
        // Banner Ad Rotator Mod End
        
==========
Find Code:
==========

$db->query("UPDATE $table_settings SET langfile='$langfilenew'

============================
Add Code To End Of Line Before  ");
============================

, ads='$adsnew'

==========
Find Code:
==========

echo "</table></td></tr></table>";
end_time();
eval('echo "'.template('footer').'";');

===============
Add Code Above:
===============

// Banner Ad Rotator Mod Begin
if ($action == 'ads') {
    if (!X_SADMIN) {
        error($lang['superadminonly'], false, '</td></tr></table></td></tr></table><br />');
    }

    if (!isset($_POST['newadsubmit'])) {
        ?>
        <tr bgcolor="<?php echo $altbg2?>">
        <td align="center">
        <form method="post" action="cp.php?action=ads">
        <table cellspacing="0" cellpadding="0" border="0" width="100%" align="center">
        <tr>
        <td bgcolor="<?php echo $bordercolor?>">
        <table border="0" cellspacing="<?php echo $borderwidth?>" cellpadding="<?php echo $tablespace?>" width="100%">
        <tr class="category">
        <td colspan="7" align="center"><font color="<?php echo $cattext?>"><strong><?php echo $lang['ads']?></strong></font></td>
        </tr>
        <tr class="header">
        <td align="center"><?php echo $lang['deletebutton']?></td>
        <td align="center"><?php echo $lang['ads_name']?></td>
        <td align="center"><?php echo $lang['ads_url']?></td>
        <td align="center"><?php echo $lang['ads_img']?></td>
        <td align="center"><?php echo $lang['ads_option']?></td>
        <td align="center"><?php echo $lang['ads_status']?></td>
        <td align="center"><?php echo $lang['ads_clicks']?></td>
        </tr>
        <?php
        $query = $db->query("SELECT a.*, COUNT(r.id) AS click_count FROM $table_ads a LEFT JOIN $table_adrecord r ON r.aid=a.aid GROUP BY aid ORDER BY aid ASC");
        $rowsFound = $db->num_rows($query);
        while ($ads = $db->fetch_array($query)) {
            $adoptionheader = $adoptionfooter = $adoptionboth = '';
            switch ($ads['adoption']) {
                case 'header':
                    $adoptionheader = $selHTML;
                    break;
                case 'footer':
                    $adoptionfooter = $selHTML;
                    break;
                default:
                    $adoptionboth = $selHTML;
                    break;
            }
            $adstatuson = $adstatusoff = '';
            switch ($ads['adstatus']) {
                case 'on':
                    $adstatuson = $selHTML;
                    break;
                default:
                    $adstatusoff = $selHTML;
                    break;
            }
            ?>
            <tr bgcolor="<?php echo $altbg2?>" class="ctrtablerow">
            <td><input type="checkbox" name="delete<?php echo $ads['aid']?>" value="<?php echo $ads['aid']?>" /></td>
            <td><input type="text" name="name<?php echo $ads['aid']?>" value="<?php echo stripslashes($ads['name'])?>" /></td>
            <td><input type="text" name="url<?php echo $ads['aid']?>" value="<?php echo stripslashes($ads['url'])?>" /></td>
            <td><input type="text" name="img<?php echo $ads['aid']?>" value="<?php echo stripslashes($ads['img'])?>" /></td>
            <td>
            <select name="adoption<?php echo $ads['aid']?>">
            <option value="header" <?php echo $adoptionheader?>><?php echo $lang['ads_header']?></option>
            <option value="footer" <?php echo $adoptionfooter?>><?php echo $lang['ads_footer']?></option>
            <option value="both" <?php echo $adoptionboth?>><?php echo $lang['ads_both']?></option>
            </select>
            </td>
            <td>
            <select name="adstatus<?php echo $ads['aid']?>">
            <option value="on" <?php echo $adstatuson?>><?php echo $lang['texton']?></option>
            <option value="off" <?php echo $adstatusoff?>><?php echo $lang['textoff']?></option>
            </select>
            </td>
            <td><?php echo $ads['click_count']?></td>
            </tr>
            <?php
       }
       $db->free_result($query);
       if ($rowsFound < 1) {
           ?>
           <tr class="ctrtablerow" bgcolor="<?php echo $altbg1?>">
           <td colspan="7"><?php echo $lang['ads_notfound']?></td>
           </tr>
           <?php
       }
       ?>
       <tr class="header">
       <td colspan="7"><?php echo $lang['ads_create']?></td>
       </tr>
       <tr class="header">
       <td align="center">&nbsp;</td>
       <td align="center"><?php echo $lang['ads_name']?></td>
       <td align="center"><?php echo $lang['ads_url']?></td>
       <td align="center"><?php echo $lang['ads_img']?></td>
       <td align="center"><?php echo $lang['ads_option']?></td>
       <td align="center" colspan="2"><?php echo $lang['ads_status']?></td>
       </tr>
       <tr bgcolor="<?php echo $altbg2?>" class="ctrtablerow">
       <td><?php echo $lang['textnewcode']?>:</td>
       <td><input type="text" name="namenew" value="" /></td>
       <td><input type="text" name="urlnew" value="" /></td>
       <td><input type="text" name="imgnew" value="" /></td>
       <td>
       <select name="adoptionnew">
       <option value="header"><?php echo $lang['ads_header']?></option>
       <option value="footer"><?php echo $lang['ads_footer']?></option>
       <option value="both"><?php echo $lang['ads_both']?></option>
       </select>
       </td>
       <td colspan="2">
       <select name="adstatusnew">
       <option value="on"><?php echo $lang['texton']?></option>
       <option value="off"><?php echo $lang['textoff']?></option>
       </select>
       </td>
       </tr>
       <tr bgcolor="<?php echo $altbg2?>" class="ctrtablerow">
       <td colspan="7"><input type="submit" class="submit" name="newadsubmit" value="<?php echo $lang['textsubmitchanges']?>" /></td>
       </tr>
       </table>
       </td>
       </tr>
       </table>
       </form>
       </td>
       </tr>
       <?php
    }

    if (isset($_POST['newadsubmit'])) {
        $query = $db->query("SELECT * FROM $table_ads");
        while ($adstuff = $db->fetch_array($query)) {
            $name = "name$adstuff[aid]";
            $name = isset(${$name}) ? "${$name}" : '';
            $url = "url$adstuff[aid]";
            $url = isset(${$url}) ? "${$url}" : '';
            $img = "img$adstuff[aid]";
            $img = isset(${$img}) ? "${$img}" : '';
            $adstatus = "adstatus$adstuff[aid]";
            $adstatus = isset(${$adstatus}) ? "${$adstatus}" : '';
            $adoption = "adoption$adstuff[aid]";
            $adoption = isset(${$adoption}) ? "${$adoption}" : '';
            $delete = "delete$adstuff[aid]";
            $delete = isset(${$delete}) ? "${$delete}" : '';

            if (isset($delete) && $delete != '') {
                $db->query("DELETE FROM $table_ads WHERE aid='$delete'");
                $db->query("DELETE FROM $table_adrecord WHERE aid='$delete'");
            } else {
                $name = addslashes(trim($name));
                $url = addslashes(trim($url));
                $img = addslashes(trim($img));
                $db->query("UPDATE $table_ads SET name='$name', url='$url', img='$img', adoption='$adoption', adstatus='$adstatus' WHERE aid='$adstuff[aid]'");
            }
        }
        $db->free_result($query);

        if (isset($namenew) && $namenew != '') {
            $namenew = addslashes(trim($namenew));
            $urlnew = addslashes(trim($urlnew));
            $imgnew = addslashes(trim($imgnew));
            $db->query("INSERT INTO $table_ads (name, url, img, adoption, adstatus) VALUES ('$namenew', '$urlnew', '$imgnew', '$adoptionnew', '$adstatusnew')");
        }
        echo '<tr bgcolor="'.$altbg2.'" class="ctrtablerow"><td>'.$lang['ads_addedsuccess'].'</td></tr>';
        redirect("cp.php?action=ads", 1.5, X_REDIRECT_JS);
    }
}
// Banner Ad Rotator Mod End

============================================================================================================================
=======
Step 4:
=======
===========================
Edit File: include/admin.user.inc.php
===========================
==========
Find Code:
==========

    <td class="tablerow" align="left" valign="top" width="20%" bgcolor="<?php echo $altbg2?>">
    </td>
    
================
Replace Code With:
================

    <td class="tablerow" align="left" valign="top" width="20%" bgcolor="<?php echo $altbg2?>">
    <!-- Banner Ad Rotator Mod Begin -->
    &raquo;&nbsp;<a href="cp.php?action=ads"><?php echo $lang['ads']?></a><br />
    <!-- Banner Ad Rotator Mod End -->
    </td>
    
============================================================================================================================
=======
Step 5:
=======
=============
Edit header.php
=============
==========
Find Code:
==========

$threadSubject = '';

===============
Add Code Below:
===============

// Banner Ad Rotator Mod Begin
$headerads = '';
$footerads = '';
// Banner Ad Rotator Mod End

==========
Find Code:
==========

$tables = array(

================
Replace Code With:
================

$tables = array('adrecord','ads',

========================
Add To End Of File Above  ?>
========================

// Banner Ad Rotator Mod Begin
if ($SETTINGS['ads'] == 'on') {
    $query  = $db->query("SELECT aid, name, img, url FROM $table_ads WHERE adoption IN('header', 'both') AND adstatus='on' ORDER BY RAND() LIMIT 1");
    $headad = $db->fetch_array($query);
    $db->free_result($query);

    if (!empty($headad)) {
        $headad['img']  = stripslashes($headad['img']);
        $headad['name'] = stripslashes($headad['name']);

        $imgurl = (strpos($headad['img'], 'http://') !== false) ? $headad['img'] : './images/ads/'.$headad['img'];

        $headerads = '<div style="text-align: center;"><a href="ads.php?aid='.(int)$headad['aid'].'" onclick="window.open(this.href);return false;"><img src="'.$imgurl.'" alt="'.$headad['name'].'" style="border: 0px;" /></a></div><br />';
    }

    $query  = $db->query("SELECT aid, name, img, url FROM $table_ads WHERE adoption IN('footer', 'both') AND adstatus='on' ORDER BY RAND() LIMIT 1");
    $footad = $db->fetch_array($query);
    $db->free_result($query);

    if (!empty($footad)) {
        $footad['img']  = stripslashes($footad['img']);
        $footad['name'] = stripslashes($footad['name']);

        $imgurl = (strpos($footad['img'], 'http://') !== false) ? $footad['img'] : './images/ads/'.$footad['img'];

        $footerads = '<div style="text-align: center;"><a href="ads.php?aid='.(int)$footad['aid'].'" onclick="window.open(this.href);return false;"><img src="'.$imgurl.'" alt="'.$footad['name'].'" style="border: 0px;" /></a></div>';
    }
}
// Banner Ad Rotator Mod End

============================================================================================================================
=======
Step 6:
=======
===============================
Go To Administration Panel --> Templates
===============================
=================
Edit Template: header
=================
===========================
Add Code To Bottom Of Template:
===========================

$headerads

============================================================================================================================
=======
Step 7:
=======
===============================
Go To Administration Panel --> Templates
===============================
=================
Edit Template: footer
=================
==========
Find Code:
==========

<table align="center">
<tr>
<td align="center" class="smalltxt">
<br />

===============
Add Code Below:
===============

$footerads
<br />

============================================================================================================================
=======
Step 8:
=======

Upload the 'ads' folder from the Contents folder to your forum's 'images' directory.
Upload your ad banners to this 'ads' folder.
Upload ads.php from the Contents folder to your forum's root directory

============================================================================================================================
Enjoy!