<?php

@( (bool)FALSE === strpos( $_SERVER['REQUEST_URI'], basename( __FILE__ ) ) ) OR exit( '!! ACCESS DENIED !!' );
error_reporting( _E_VALUE );


/* vim: set expandtab tabstop=4 shiftwidth=4: */
// +----------------------------------------------------------------------+
// | myPHPNuke Version 188_8 RC2                                          |
// +----------------------------------------------------------------------+
// | License: GNU/GPL - http://www.gnu.org/copyleft/gpl.html              |
// +----------------------------------------------------------------------+
// | Support: http://myphpnuke.com/                                       |
// +----------------------------------------------------------------------+
// | Author: myPHPNuke Dev Team                                           |
// +----------------------------------------------------------------------+
// | Copyright: © 2001-2004 myPHPNuke Dev Team                            |
// +----------------------------------------------------------------------+
// $Id: rand_banners.php,v 1.6.2.6 2004/08/15 12:58:22 kirilt Exp $




######################################################################
# Partner-Addon for PHP-NUKE Version 1.0 Beta
# ===========================
#
# Copyright (c) 2001 by Dietrich Bojko (webmaster@jimmy-net.de)
# http://www.jimmy-net.de
#
# This modules is the main administration part
#
# 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.
######################################################################
// 10-24-2001 trini0:- Took out the hard coded tables & fixed syntax.


function ListBanner() {
    global $admin, $bgcolor1, $bgcolor2, $mpnTables,$phpEx;
    //openTable();
    //randbannerconfig();
    //closeTable();

    OpenTable();
    echo "<center><font size=3><b>".translate("Random Banners Admin")."</b></center>";
    echo "<br><br>";

    echo "<table width=95% border=0 align=center><tr>
        <td bgcolor=\"$bgcolor1\"><font size=2><b>" .translate("ID")."</b></td>
        <td bgcolor=\"$bgcolor1\"><font size=2><b>" .translate("URL")."</b></td>
        <td bgcolor=\"$bgcolor1\"><font size=2><b>" .translate("Image")."</b></td>
        <td bgcolor=\"$bgcolor1\"><font size=2><b>" .translate("Description")."</b></td>
        <td bgcolor=\"$bgcolor1\"><font size=2><b></b></td></tr>";
        $result = mysql_query("SELECT banner_id, url, image, description FROM ".$mpnTables['rand_banners']." order by banner_id");

        while(list($banner_id, $url, $image, $descriptions) = mysql_fetch_row($result)) {


            echo "<tr>
            <td bgcolor=\"$bgcolor2\"><font size=1>$banner_id</td>
            <td bgcolor=\"$bgcolor2\"><font size=1>$url</td>
            <td bgcolor=\"$bgcolor2\"><font size=1>$image</td>
            <td bgcolor=\"$bgcolor2\"><font size=1>$descriptions</td>
            <td bgcolor=\"$bgcolor2\"><font size=1>
            <a href=admin.$phpEx?fct=rand_banners&op=EditBanner&banner_id=$banner_id>".translate("Edit")."</a>|<a href=admin.$phpEx?fct=rand_banners&op=DeleteBanner&banner_id=$banner_id&ok=0>".translate("Delete")."</a></td></tr>
            ";
        }
        echo "</table></td></tr></table></td></tr></table><br>";

    OpenTable();
    echo "<b>".translate("Add a New Banner")."</b></center><br><br>
        <font size=2>
        <form action=admin.$phpEx method=post>";
        echo "".translate("Image URL: ")."<input class=textbox type=text name=image size=\"80\" maxlength=\"150\" value=\"http://\"><br>
        ".translate("Site URL: ")."<input class=textbox type=text name=url size=80 maxlength=150 value=\"http://\"><br>
        ".translate("Description: (max 150 characters)")."<br><textarea class=textbox name=descriptions cols=60 rows=5 ></textarea><br>
    <input type=hidden name=op value=AddBanner>
        <input type=hidden name=fct value=rand_banners>
        <input class='button' type=submit value=\"".translate("Add Banner")."\">";

    echo "</form></td></tr></table></td></tr></table>";

}

function EditBanner($banner_id) {
    global $mpnTables,$phpEx;
        OpenTable();

        $result=mysql_query("SELECT banner_id, url, image, description FROM ".$mpnTables['rand_banners']." where banner_id='$banner_id'");
        list($banner_id, $url, $image, $descriptions) = mysql_fetch_row($result);

        echo "<font size=3>
        <center><b>".translate("Edit Banner")."</b><br><br>
        <img src=$image border=0><br><br>
        <font size=2></center>
        <form action=admin.$phpEx method=post>";
        echo "" .translate("Site URL:")."&nbsp;&nbsp;<input class=textbox type=text name=url size=80 maxlength=150 value=$url><br>
        " .translate("Image URL:")."&nbsp;&nbsp;<input class=textbox type=text name=image size=80 maxlength=150 value=$image><br>
        ".translate("Description: (max 150 characters)")."<br><textarea class=textbox name=description cols=60 rows=5>$descriptions</textarea><br>
        <input type=hidden name=banner_id value=$banner_id>
        <input type=hidden name=op value=UpdateBanner>
        <input type=hidden name=fct value=rand_banners>
        <input class='button' type=submit value=\"".translate("Edit Banner")."\">
        </form></td></tr></table></td></tr></table>
        ";
}

function UpdateBanner($banner_id, $url, $image, $description) {
    global $mpnTables,$phpEx;
        mysql_query("update ".$mpnTables['rand_banners']." set banner_id='$banner_id', url='$url', image='$image', description='$description' where banner_id='$banner_id'");

        $_SERVER['F_LIB'] -> redirectRequest( 'admin.php?fct=rand_banners' );

}


function AddBanner($banner_id, $url, $image, $descriptions) {
    global $mpnTables,$phpEx;
    mysql_query("INSERT INTO ".$mpnTables['rand_banners']." (banner_id, url, image, description) VALUES ('','$url','$image','$descriptions')");
    if (mysql_errno() > 0) { echo mysql_errno() . " --- " . mysql_error() . "<br>"; }

    $_SERVER['F_LIB'] -> redirectRequest( 'admin.php?fct=rand_banners' );
}


function DeleteBanner($banner_id, $ok=0) {
    global $mpnTables,$phpEx;
    if($ok==1) {
        mysql_query("DELETE FROM ".$mpnTables['rand_banners']." WHERE banner_id='$banner_id'");

        $_SERVER['F_LIB'] -> redirectRequest( 'admin.php?fct=rand_banners' );

    } else {
        OpenTable();
        echo "<center><br>";
        echo "<font size=2 color=Red>";
        echo "<b>".translate("WARNING: Are you sure you want to delete this site banner?")."</b><br><br></font>";
        echo "[ <a href=admin.$phpEx?fct=rand_banners&op=DeleteBanner&banner_id=$banner_id&ok=1>".translate("Yes")."</a> | <a href=admin.$phpEx?fct=rand_banners>".translate("No")."</a> ]<br><br>";
        echo "</TD></TR></TABLE></TD></TR></TABLE>";
    }
}


function randbannerconfig() {

global $hlpfile, $admin,$phpEx;

if (!isset($config)) { include("config.$phpEx"); }

    OpenTable();

    echo "<center><font size=3><b>" . translate("Rand banner config ") . "</b></center><br>";
    echo "<font size=2>";
    echo "<form action=\"admin.$phpEx?fct=rand_banners\" method=\"post\">";
    echo "<table border=0 width=100%><tr><td>";

    echo "</td></tr>";


echo "<tr><td>" . translate("Number of banner:") . " </td><td>";

    echo "<input type=\"text\" name=\"xmaxbanner\" size=\"4\" value=\"$maxbanner\"></td></tr>";
    echo "<tr><td colspan=2><small><i>" . translate("(Number of banner which will be displayed in the block)")."</i></small></td></tr>";


echo "</table>";
    echo "<input type=hidden name=fct value=rand_banners>";
    echo "<input type=hidden name=op value=randbannersauve>";
        echo "<input class='button' type=submit value=".translate("Change").">";
            echo "</form>";
        //echo "</td></tr></table></td></tr></table>";
closetable();

}

function randbannersauve($xmaxbanner) {
    global $fct, $phpEx;


    $check_ary = array( $_POST['xmaxbanner'] );

    $verify_check_ary = $_SERVER['SAN'] -> verifyContent( $check_ary, 5 );

    // Check Num Only

    if ( in_array( (bool)FALSE, $verify_check_ary ) )
    {
        goBack( translate( 'Please Make Sure You Have Numbers In Number Only Fields' ) );
       exit;
    }

    $content = "";
    $content .= "<?php\n";
    $content .= require './admin/configs_header.php';
    $content .= "\n";
    $content .= "\$maxbanner = $xmaxbanner;\n\n";
    $content .= "?>";

    $filename = 'admin/' . $fct . '/config.php';

    if ( ! $_SERVER['F_LIB'] -> writeFile( $filename, 'w+b', $content ) )
    {
        goBack( translate( 'File Write Error.  Check Permissions On ' ) . $filename );
        exit;
    }

    $_SERVER['F_LIB'] -> redirectRequest( 'admin.php?fct=rand_banners' );

}

?>
