<?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: blocks.php,v 1.16.2.8 2004/08/15 12:58:06 kirilt Exp $




######################################################################
# PHP-NUKE: Web Portal System
# ===========================
#
# Copyright (c) 2000 by Francisco Burzi (fburzi@ncc.org.ve)
# http://phpnuke.org
#
# This module 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.
######################################################################
# PHP-NUKE 4.4: Quote of the day Add-On
# =====================================
#
#        Brought to you by Erik Slooff
#
# Copyright (c) 2000 by Erik Slooff (erik@slooff.com)
#
# http://www.slooff.com
#
######################################################################


// Basic function to display the admin stuff for the blocks
function BlocksAdmin() {
    global $admin,$phpEx;
    OpenTable();
    echo "</center><font size=4><b>" .translate("Add Block")."</b><br>
    <a href =\"admin.$phpEx?fct=blocks&op=BlocksDisplay&page=1&side=-1\">" .translate("Modify Blocks")."</a></font><br><br>
    <font size=2>
    <form action=admin.$phpEx?fct=blocks method=post>
    <table border=0 width=\"100%\"><tr><td width=\"30%\" align=\"right\">
    ".translate("Side of the block:")."</td><td>
    <select name=\"bside\">
    <option value=\"0\" selected>" .translate("Left")."</option>
    <option value=\"1\">" .translate("Right")."</option>
    </select>
    </td></tr><tr><td align=\"right\">
    ".translate("Display order:")."
    </td><td>
    <input class=textbox type=text name=bweight size=2 maxlength=2 value=0>
    </td></tr><tr><td align=\"right\">
    ".translate("Visible for:")."
    </td><td>
    <select name=\"badmin\">
    <option value=\"0\" selected>".translate("All")."</option>
    <option value=\"1\">".translate("Registered users")."</option>
    <option value=\"2\">".translate("Admins")."</option>
    </select>
    </td></tr><tr><td align=\"right\">
    " .translate("Position of the additional content:")."</td><td>
    <select name=\"bposition\">
    <option value=\"0\" selected>" .translate("Above")."</option>
    <option value=\"1\">" .translate("After")."</option>
    </select>
    " .translate("the original content")."
    </td></tr><tr><td align=\"right\">
    " .translate("Block is visible:")."</td><td>
    <select name=\"bvisible\">
    <option value=\"0\">" .translate("No")."</option>
    <option value=\"1\" selected>" .translate("Yes")."</option>
    </select>
    </td></tr><tr><td align=\"right\">
    " .translate("Blocktype:")."</td><td>
    <select name=\"bspecial\">";
    for ($i = 0; $i <= 24; $i++) {
        if ($i == 0) {
            echo "<option value=\"$i\" selected>" .get_block_type($i)."</option>";
        } else {
            echo "<option value=\"$i\">" .get_block_type($i)."</option>";
        }
    }
    echo "</select>
    </td></tr><tr><td align=\"right\">
    " .translate("Title:")."</td><td>
    <input class=\"textbox\" type=\"text\" name=\"btitle\" size=\"60\" maxlength=\"60\">
    </td></tr><tr><td align=\"right\">
    " .translate("Content:")."</td><td>
    <textarea class=\"textbox\" name=\"bcontent\" cols=70 rows=20></textarea>
    <br /><p>" . translate( "If you are using <b>Include A File</b> block,<br />ONLY put the name (and path if necessary) in the content field" ) . "<br />" . translate( "EXAMPLE" ) . ": <b>" . translate( "test.html" ) . "</b> " . translate( "or with a path" ) . " <b>" . translate( "./myfolder/test.php" ) . "</b>\n";

    addFormatOption();

    echo "</p><br /><br /></td></tr>
    <tr><td align=\"right\">
    ".translate("Category:")."</td><td>
    <select name=\"bcategory\">
    <option value=\"0\" selected>".translate("None")."
    <option value=\"1\">".translate("Mainblock")."
    <option value=\"2\">".translate("Adminblock")."
    <option value=\"3\">".translate("Leftblock")."
    <option value=\"4\">".translate("Rightblock")."
    <option value=\"5\">".translate("Userblock")."
    </select>
    </td></tr>
    <tr><td>
    </td></tr></table>\n";

    // Kiril: New Sanitizer

    echo "<input type='hidden' name='clickit_form' value='bcontent' />\n";
    echo "<input type='hidden' name='stripit_form' value='bweight|btitle' />\n";
    echo "<input type='hidden' name='mpn_sectype' value='2' />\n";

    // End Sanitizer

    echo "<input type=hidden name=op value=BlocksAdd>
    <input class='button' type=submit value=" .translate("Add").">
    </form>
    </td></tr></table></td></tr></table>";
}

function BlocksAdd($bside, $bweight, $badmin, $bposition, $bvisible, $bspecial, $btitle, $bcontent,$bcategory) {
    global $mpnTables,$phpEx;
    $result = mysql_query("select count(*) from ".$mpnTables['blocks']." where side = '$bside' and weight='$bweight'");
    list($counter) = mysql_fetch_row($result);
    if ($counter >= 1) {
        mysql_query("update ".$mpnTables['blocks']." set weight=weight+1 where side='$bside' and weight>='$bweight'");
    }
    mysql_query("insert into ".$mpnTables['blocks']." (bid, side, weight, admin, position, visible, special, title, content, category) values (NULL, '$bside', '$bweight', '$badmin', '$bposition', '$bvisible', '$bspecial', '$btitle', '$bcontent','$bcategory')");

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

}

function BlocksDisplay($page,$side) {
    global $keyword, $side, $page, $mpnTables,$phpEx;
    OpenTable();
    if ($side == -1) {
        $sql = "SELECT COUNT(*) as help FROM ".$mpnTables['blocks'];
    } else {
        $sql = "SELECT COUNT(*) as help FROM ".$mpnTables['blocks']." where side='$side'";
    }
    $result = mysql_query($sql);
    list($numrecords) = mysql_fetch_row($result);
    $entriesperpage = 23;
    $totalpages = ceil($numrecords / $entriesperpage);
    if ($numrecords > 0) {
        echo "</center><font size=4><b>" .translate("Modify Blocks")."</b></font><br>
        <a href=\"admin.$phpEx?fct=blocks&op=BlocksDisplay&page=1&side=-1\">" .translate("Display all blocks")."</a>
        &nbsp;<a href=\"admin.$phpEx?fct=blocks&op=BlocksDisplay&page=1&side=0\">" .translate("Display only leftblocks")."</a>
        &nbsp;<a href=\"admin.$phpEx?fct=blocks&op=BlocksDisplay&page=1&side=1\">" .translate("Display only rightblocks")."</a>
        <br><br><font size=2>
        <table border=1 width=\"100%\">";
        echo "<tr><td>" .translate("Title")."</td><td>"
        .translate("Side")."</td><td>"
        .translate("Order")."</td><td>"
        .translate("Visible for")."</td><td>"
        .translate("Position")."</td><td>"
        .translate("Visible")."</td><td>"
        .translate("Blocktype")."</td><td align=\"center\">"
        .translate("Action")."</td></tr>";
        $start = $entriesperpage * ($page - 1);
        if ($side == -1) {
            $sql = "SELECT bid, side, weight, admin, position, visible, special, title FROM ".$mpnTables['blocks']." order by side,weight,bid limit $start, $entriesperpage";
        } else {
            $sql = "SELECT bid, side, weight, admin, position, visible, special, title FROM ".$mpnTables['blocks']." where side = '$side' order by side,weight,bid limit $start, $entriesperpage";
        }
        $result = mysql_query($sql);
        while(list($bbid, $bbside, $bbweight, $bbadmin,$bbposition,$bbvisible,$bbspecial,$bbtitle) = mysql_fetch_array($result)) {
            echo "<tr><td width=\"30%\">";
            if (($bbspecial == 0) or ($bbtitle != "")) {
                echo substr($bbtitle,0,50);
            } elseif ($bbspecial == 1) {
                echo translate("Random Quote");
            } elseif ($bbspecial == 2) {
                echo translate("Who's Online");
            } elseif ($bbspecial == 3) {
                echo translate("Usermenu");
            } elseif ($bbspecial == 4) {
                echo translate("Categories");
            } elseif ($bbspecial == 5) {
                echo translate("Today's Big Story");
            } elseif ($bbspecial == 6) {
                echo translate("Search");
            } elseif ($bbspecial == 7) {
                echo translate("Survey");
            } elseif ($bbspecial == 8) {
                echo translate("Login");
            } elseif ($bbspecial == 9) {
                echo translate("Ephemerids");
            } elseif ($bbspecial == 10) {
                echo translate("Headlines");
            } elseif ($bbspecial == 11) {
                echo translate("Past Articles");
            } elseif ($bbspecial == 12) {
                echo translate("Waiting Content");
            } elseif ($bbspecial == 13) {
                echo translate("last seen");
            } elseif ($bbspecial == 14) {
                echo translate("Recent Reviews");
            } elseif ($bbspecial == 15) {
                echo translate("Top reviews");
            } elseif ($bbspecial == 16) {
                echo translate("Recent Links");
            } elseif ($bbspecial == 17) {
                echo translate("Top Links");
            } elseif ($bbspecial == 18) {
                echo translate("Partnersites");
        } elseif ($bbspecial == 19) {
                echo translate("ChatboxII");
        } elseif ($bbspecial == 20) {
                echo translate("Random Banner");
        } elseif ($bbspecial == 21) {
                echo translate("Random Gallery");
        } elseif ($bbspecial == 22) {
                echo translate("Stats");
        } elseif ($bbspecial == 23) {
            echo translate("Include a File");
        } elseif ($bbspecial == 24) {
            echo translate("Theme Options");

        }

            echo "</td><td>";
            if ($bbside == 0) {
                echo translate("Left");
            } else {
                echo translate("Right");
            }
            echo "</td><td>$bbweight</td><td>";
            if ($bbadmin == 0) {
                echo translate("All");
            } elseif ($bbadmin == 1) {
                echo translate("Registered users");
            } else {
                echo translate("Admins");
            }
            echo "</td><td>";
            if ($bbposition == 0) {
                echo translate("Above");
            } else {
                echo translate("After");
            }
            echo "</td><td>";
            if ($bbvisible == 0) {
                echo translate("No");
            } else {
                echo translate("Yes");
            }
            echo "</td><td>";
            echo get_block_type($bbspecial);
            echo "</td><td align=\"center\"><a href=\"admin.$phpEx?fct=blocks&op=BlocksEdit&bid=$bbid&page=$page&side=$side\">" .translate("Edit")."</a> | <a href=\"admin.$phpEx?fct=blocks&op=BlocksDelete&bid=$bbid&page=$page&side=$side\">" .translate("Delete")."</a></td>";
            echo "</tr>";
        }
        echo "</table><br>";
        if ($page > 1) {
            $prevpage = $page - 1;
        } else {
            $prevpage = 0;
        }
        if ($page < $totalpages) {
            $nextpage = $page + 1;
        } else {
            $nextpage = 0;
        }
        echo "<table border=0 width=\"100%\"><tr><td align=\"center\" width=\"33%\">";
        if ($prevpage != 0) {
            echo "<a href=\"admin.$phpEx?fct=blocks&op=BlocksDisplay&page=$prevpage&side=$side\">" .translate("Previous Page")."</a>";
        } else {
            echo " ";
        }
        echo "</td><td align=\"center\" width=\"33%\">";
        echo "<a href=\"admin.$phpEx?fct=blocks\">" .translate("back")."</a>";
        echo "</td><td align=\"center\" width=\"33%\">";
        if ($nextpage !=0) {
            echo "<a href=\"admin.$phpEx?fct=blocks&op=BlocksDisplay&page=$nextpage&side=$side\">" .translate("Next Page")."</a>";
        } else {
            echo " ";
        }
        echo "</td></tr></table>";
    } else {
        echo translate("No Blocks found");
    }
    echo "</td></tr></table></td></tr></table>";

}

function BlocksDelete($bid,$page,$side) {
    global $phpEx;
    OpenTable();
    echo "</center><font size=4><b>" .translate("Delete Block")."</b><br><br>";
    echo "<center>";
    echo "<font size=3 color=Red>";
    echo "<b>".translate("WARNING: Are you sure you want to delete this block?")."</b><br><br><font color=Black>";
    echo "[ <a href=admin.$phpEx?fct=blocks&op=BlocksDeleteOk&bid=$bid&page=$page&side=$side>".translate("Yes")."</a> | <a href=admin.$phpEx?fct=blocks&op=BlocksDisplay&page=$page&side=$side>".translate("No")."</a> ]<br><br>";
    echo "</td></tr></table></td></tr></table>";
}

function BlocksDeleteOk($bid,$page,$side) {
    global $mpnTables,$phpEx;
    mysql_query("DELETE FROM ".$mpnTables['blocks']." where bid='$bid'");

        $_SERVER['F_LIB'] -> redirectRequest( 'admin.php?fct=blocks&op=BlocksDisplay&page=' . $page . '&side=' . $side );


}

function BlocksEdit($bid,$page,$side) {
    global $mpnTables,$phpEx;
    $result = mysql_query("SELECT side, weight, admin, position, visible, special, title, content, category FROM ".$mpnTables['blocks']." WHERE bid = '$bid'");
    list($bside, $bweight, $badmin, $bposition, $bvisible, $bspecial, $btitle, $bcontent, $bcategory) = mysql_fetch_row($result);

    /*$btitle = htmlspecialchars($btitle);
    $bcontent = stripslashes($bcontent);
    $bcontent = htmlspecialchars($bcontent);*/

    // Kiril: New Sanitizer

    $sanity_ary = compact( 'bweight', 'btitle', 'bcontent' );
    $_SERVER['SAN'] -> slashIT( $sanity_ary );
    extract( $sanity_ary );
    unset( $sanity_ary );

    // End New Saintizer

    OpenTable();
    echo "</center><font size=4><b>" .translate("Edit Block")."</b><br><br>
    <font size=2>
    <form action=admin.$phpEx?fct=blocks method=post>
    <table border=0 width=100%><tr><td width=\"30%\" align=\"right\">
    ".translate("Side of the block:")."</td><td>
    <select name=\"bbside\">";
    if ($bside == 0) {
        echo "<option value=\"0\" selected>" .translate("Left")."</option>
        <option value=\"1\">" .translate("Right")."</option>";
    } else {
        echo "<option value=\"0\">" .translate("Left")."</option>
        <option value=\"1\" selected>" .translate("Right")."</option>";
    }
    echo "</select>
    </td></tr><tr><td align=\"right\">
    ".translate("Display order:")."
    </td><td>
    <input class=textbox type=text name=bbweight size=2 maxlength=2 value=\"$bweight\">
    </td></tr><tr><td align=\"right\">
    ".translate("Visible for:")."
    </td><td>
    <select name=\"bbadmin\">";
    if ($badmin == 0) {
        echo "<option value=\"0\" selected>".translate("All")."</option>"
        ."<option value=\"1\">".translate("Registered users")."</option>"
        ."<option value=\"2\">".translate("Admins")."</option>";
    } elseif ($badmin == 1) {
        echo "<option value=\"0\">".translate("All")."</option>"
        ."<option value=\"1\" selected>".translate("Registered users")."</option>"
        ."<option value=\"2\">".translate("Admins")."</option>";
    } else {
        echo "<option value=\"0\">".translate("All")."</option>"
        ."<option value=\"1\">".translate("Registered users")."</option>"
        ."<option value=\"2\" selected>".translate("Admins")."</option>";
    }
    echo "</select>
    </td></tr><tr><td align=\"right\">
    " .translate("Position of the additional content:")."</td><td>
    <select name=\"bbposition\">";
    if ($bposition == 0) {
        echo "<option value=\"0\" selected>" .translate("Above")."</option>
        <option value=\"1\">" .translate("After")."</option>";
    } else {
        echo "<option value=\"0\">" .translate("Above")."</option>
        <option value=\"1\" selected>" .translate("After")."</option>";
    }
    echo "</select>" .translate("the original content")."</td></tr><tr><td align=\"right\">
    " .translate("Block is visible:")."</td><td>
    <select name=\"bbvisible\">";
    if ($bvisible == 0) {
        echo "<option value=\"0\" selected>" .translate("No")."</option>
        <option value=\"1\">" .translate("Yes")."</option>";
    } else {
        echo "<option value=\"0\">" .translate("No")."</option>
        <option value=\"1\" selected>" .translate("Yes")."</option>";
    }
    echo "</select>
    </td></tr><tr><td align=\"right\">
    " .translate("Blocktype:")."</td><td>
    <select name=\"bbspecial\">";
    for ($i = 0; $i <= 24; $i++) {
        if ($i == $bspecial) {
            echo "<option value=\"$i\" selected>" .get_block_type($i)."</option>";
        } else {
            echo "<option value=\"$i\">" .get_block_type($i)."</option>";
        }
    }
    echo "</select>
    </td></tr><tr><td align=\"right\">
    " .translate("Title:")."</td><td>
    <input class=\"textbox\" type=\"text\" name=\"bbtitle\" size=\"60\" maxlength=\"60\" value=\"$btitle\">
    </td></tr><tr><td align=\"right\">
    " .translate("Content:")."</td><td>
    <textarea class=\"textbox\" name=\"bbcontent\" cols=70 rows=20>$bcontent</textarea>
    <br /><p>" . translate( "If you are using <b>Include A File</b> block,<br />ONLY put the name (and path if necessary) in the content field" ) . "<br />" . translate( "EXAMPLE" ) . ": <b>" . translate( "test.html" ) . "</b> " . translate( "or with a path" ) . " <b>" . translate( "./myfolder/test.php" ) . "</b>\n";

    addFormatOption();

    echo "</p><br /><br /></td></tr>
    <tr><td align=\"right\">
    ".translate("Category:")."</td><td>
    <select name=\"bbcategory\">";
    for ($i = 0; $i <= 5; $i++) {
        if ($i == $bcategory) {
            $sel = "selected";
        } else {
            $sel ="";
        }
        echo "<option value=\"$i\" $sel>".get_block_cat($i)."</option>";
    }
    echo "</select>
    </td></tr>
    <tr><td>
    </td></tr></table>\n";

    // Kiril: New Sanitizer

    echo "<input type='hidden' name='clickit_form' value='bbcontent' />\n";
    echo "<input type='hidden' name='stripit_form' value='bbweight|bbtitle' />\n";
    echo "<input type='hidden' name='mpn_sectype' value='2' />\n";

    // End Sanitizer

    echo "<input type=hidden name=op value=BlocksSave>
    <input type=hidden name=page value=$page>
    <input type=hidden name=side value=$side>
    <input type=hidden name=bbid value=$bid>
    <input class='button' type=submit value=" .translate("Save").">
    </form>
    </td></tr></table></td></tr></table>";
}

function BlocksSave($bbid, $bbside, $bbweight, $bbadmin, $bbposition, $bbvisible, $bbspecial, $bbtitle, $bbcontent,$bbcategory, $page,$side)
{
    global $mpnTables,$phpEx;

    // Slashes Are Added By The Sanitizer

    $sql = "UPDATE ".$mpnTables['blocks']." set side='$bbside', weight='$bbweight', admin = '$bbadmin', position = '$bbposition', visible = '$bbvisible', special = '$bbspecial', title = '$bbtitle', content = '$bbcontent', category = '$bbcategory' WHERE bid='$bbid'";

    if ( ! mysql_query( $sql ) )
    {
        goBack( mysql_error() );
        exit;
    }

   // mysql_query("UPDATE ".$mpnTables['blocks']." set side='$bbside', weight='$bbweight', admin = '$bbadmin', position = '$bbposition', visible = '$bbvisible', special = '$bbspecial', title = '$bbtitle', content = '$bbcontent', category = '$bbcategory' WHERE bid='$bbid'");


        $_SERVER['F_LIB'] -> redirectRequest( 'admin.php?fct=blocks&op=BlocksDisplay&page=' . $page . '&side=' . $side );


}

function get_block_type($number) {
    $what = null;

    if ($number == 0) {
        $what = translate("Custom block");
    } elseif ($number == 1) {
        $what = translate("Quotes block");
    } elseif ($number == 2) {
        $what = translate("Who's online block");
    } elseif ($number == 3) {
        $what = translate("User block");
    } elseif ($number == 4) {
        $what = translate("Category block");
    } elseif ($number == 5) {
        $what = translate("Big story block");
    } elseif ($number == 6) {
        $what = translate("Search block");
    } elseif ($number == 7) {
        $what = translate("Poll block");
    } elseif ($number == 8) {
        $what = translate("Login block");
    } elseif ($number == 9) {
        $what = translate("Ephemerids block");
    } elseif ($number == 10) {
        $what = translate("Headlines block");
    } elseif ($number == 11) {
        $what = translate("Past Articles block");
    } elseif ($number == 12) {
        $what = translate("Waiting content block");
    } elseif ($number == 13) {
        $what = translate("Last seen block");
    } elseif ($number == 14) {
        $what = translate("Recent reviews block");
    } elseif ($number == 15) {
        $what = translate("Top reviews block");
    } elseif ($number == 16) {
        $what = translate("Recent links block");
    } elseif ($number == 17) {
        $what = translate("Top links block");
    } elseif ($number == 18) {
        $what = translate("Partnersite block");
    } elseif ($number == 19) {
        $what = translate("ChatboxII");
    } elseif ($number == 20) {
                $what =  translate("Random Banners");
    } elseif ($number == 21) {
                $what = translate("Random Gallery");
    } elseif ($number == 22) {
                $what = translate("Stats");
    } elseif ($number == 23) {
                $what = translate("Include A File");
    } elseif ($number == 24) {
                $what = translate("Theme Options");
    }
    return($what);
}

function get_block_cat($i) {
    if ($i == 0) {
        $what = translate("None");
    } elseif ($i == 1) {
        $what = translate("Mainblock");
        } elseif ($i == 2) {
        $what = translate("Adminblock");
        } elseif ($i == 3) {
        $what = translate("Leftblock");
        } elseif ($i == 4) {
        $what = translate("Rightblock");
        } elseif ($i == 5) {
        $what = translate("Userblock");
        }

    return($what);
}

?>
