<?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: topics.php,v 1.7.2.7 2004/08/15 12:58:04 kirilt Exp $

/************************************************************************/
/* PHP-NUKE: Web Portal System                                          */
/* ===========================                                          */
/*                                                                      */
/* Copyright (c) 2001 by Francisco Burzi (fburzi@ncc.org.ve)            */
/* http://phpnuke.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.       */
/************************************************************************/

checkAccess( 'articles', array( 'article', 'topic' ) );

/*********************************************************/
/* Topics Manager Functions                              */
/*********************************************************/

function topicsmanager() {
    global $hlpfile, $admin, $tipath, $mpnTables,$phpEx;
    include("header.$phpEx");
    GraphicAdmin($hlpfile);
    $result = mysql_query("select topicid, topicname, topicimage, topictext from ".$mpnTables['topics']." order by topicname");
    if (mysql_num_rows($result)==0) {
        echo "
        <table border=0 bgcolor=000000 cellpadding=0 cellspacing=1 width=95%><tr><td>
        <table border=0 bgcolor=FFFFFF cellpadding=8 cellspacing=1 width=100%>";
    }
    if (mysql_num_rows($result) > 0) {
    OpenTable();
        $count = 0;
    echo "
    <b><center>".translate("Current Active Topics")."</b><br>".translate("Click to Edit")."</center><br>
    <center><table border=0 width=100% align=center cellpadding=2><tr>";

        while(list($topicid, $topicname, $topicimage, $topictext) = mysql_fetch_array($result))
        {
            $topicname = stripslashes( $topicname );
            $topicimage = stripslashes( $topicimage );
            $topictext = stripslashes( $topictext );
        ?>
            <td align=center>
            <?php /*echo "<a href=admin.$phpEx?op=topicedit&topicid=$topicid>
            <img src = \"".$tipath.$topicimage."\"></a><br><font size=2><b>$topictext</b>"; */?>
            <?php echo "<a href=admin.$phpEx?op=topicedit&topicid=$topicid>"
            ."<img src = \"".$tipath.$topicimage."\" border = 0></a><br><font size=2><b>$topictext</b>"; ?>
        </td>
        <?php

        // Thanks to John Hoffmann from softlinux.org for the next 5 lines ;)

        $count++;
        if ($count == 4) {
            echo "</tr><tr>";
            $count = 0;
        }
        }
    echo "</tr></table>";
    }
    ?>
    </td></tr></table></td></tr></table>
    <br><a name=Add>
    <?php OpenTable(); ?>
    <font size=4><b><?php echo translate("Add a New Topic"); ?></b><font size=2>
    <br><br>
    <?php echo "<form action=\"admin.$phpEx\" method=\"post\"><br>"; ?>
    <b><?php echo translate("Topic Name:"); ?></b> <?php echo translate("(just a name without spaces - max: 20 characters)"); ?><br>
    <?php echo translate("for example: gamesandhobbies"); ?><br>
    <input class=textbox type="text" name="topicname" size=20 maxlength=20 value="<?php echo "$topicname"; ?>"><br><br>
    <b><?php echo translate("Topic Text:"); ?></b> <?php echo translate("(the full topic text or description - max: 40 characters)"); ?><br>
    <?php echo translate("for example: Games and Hobbies"); ?><br>
    <input class=textbox type="text" name="topictext" size=40 maxlength=40 value="<?php echo "$topictext"; ?>"><br><br>
    <b><?php echo translate("Topic Image:"); ?></b> <?php echo translate("(image name + extension located in"); ?> <?php echo "$tipath"; ?>)<br>
    <?php echo translate("for example: games.gif"); ?><br>
    <input class=textbox type="text" name="topicimage" size=20 maxlength=20 value="<?php echo "$topicimage"; ?>"><br><br>

    <?php

    // Kiril: New Sanitizer

        echo "<input type='hidden' name='stripit_form' value='topicname|topictext|topicimage|name|url' />\n";
        echo "<input type='hidden' name='mpn_sectype' value='2' />\n";

    // End Sanitizer

    ?>

    <input type=hidden name=op value=topicmake>
    <INPUT class='button' type="submit" value="<?php echo translate("Add Topic!"); ?>">
    </form>
    </td></tr></table></td></tr></table>
    <?php
    mysql_free_result($result);
    include("footer.$phpEx");
}

function topicedit($topicid) {
    global $tipath, $mpnTables,$phpEx;
    include("header.$phpEx");
    if (!isset($hlpfile))
    {
        $hlpfile = null;
    }

    GraphicAdmin($hlpfile);
    $result = mysql_query("select topicid, topicname, topicimage, topictext from ".$mpnTables['topics']." where topicid=$topicid");
    list($topicid, $topicname, $topicimage, $topictext) = mysql_fetch_array($result);

    $topicname = stripslashes( $topicname );
    $topicimage = stripslashes( $topicimage );
    $topictext = stripslashes( $topictext );

    OpenTable();
    echo "<img src = \"".$tipath,$topicimage."\" border=0>";
    ?>
    <font size=4><b><?php echo translate("Edit Topic:"); ?> <?php echo "$topictext"; ?></b><font size=2>
    <br><br>
    <?php echo "<form action=\"admin.$phpEx\" method=\"post\"><br>"; ?>
    <b><?php echo translate("Topic Name:"); ?></b> <?php echo translate("(just a name without spaces - max: 20 characters)"); ?><br>
    <?php echo translate("for example: gamesandhobbies"); ?><br>
    <input class=textbox type="text" name="topicname" size=20 maxlength=20 value="<?php echo "$topicname"; ?>"><br><br>
    <b><?php echo translate("Topic Text:"); ?></b> <?php echo translate("(the full topic text or description - max: 40 characters)"); ?><br>
    <?php echo translate("for example: Games and Hobbies"); ?><br>
    <input class=textbox type="text" name="topictext" size=40 maxlength=40 value="<?php echo "$topictext"; ?>"><br><br>
    <b><?php echo translate("Topic Image:"); ?></b> <?php echo translate("(image name + extension located in"); ?> <?php echo "$tipath"; ?>)<br>
    <?php echo translate("for example: games.gif"); ?><br>
    <input class=textbox type="text" name="topicimage" size=20 maxlength=20 value="<?php echo "$topicimage"; ?>"><br><br>

    <b><?php echo translate("Add Related Links:"); ?></b><br>
    <?php echo translate("Site Name: "); ?><input class=textbox type="text" name="name" size=30 maxlength=30><br>
    <?php echo translate("URL: "); ?><input class=textbox type="text" name="url" value="http://" size=50 maxlength=200><br><br>

    <b><?php echo translate("Active Related Links:"); ?></b><br>
    <?php
    $res=mysql_query("select rid, name, url from ".$mpnTables['related']." where tid=$topicid");
    echo "<table width=100% border=0><tr><td>";
    while(list($rid, $name, $url) = mysql_fetch_row($res))
    {
        $name = stripslashes( $name );
        $url = stripslashes( $url );

        echo "<font size=1><li> <a href=$url>$name</a></td><td>";
        echo "<font size=1><a href=$url>$url</a></td><td><font size=1>[ <a href=admin.$phpEx?op=relatededit&tid=$topicid&rid=$rid>".translate("Edit")."</a> | <a href=admin.$phpEx?op=relateddelete&tid=$topicid&rid=$rid>".translate("Delete")."</a> ]</td></tr><tr><td>";
    }
    echo "</td></tr></table>";

    // Kiril: New Sanitizer

        echo "<input type='hidden' name='stripit_form' value='topicname|topictext|topicimage|name|url' />\n";
        echo "<input type='hidden' name='mpn_sectype' value='2' />\n";

    // End Sanitizer

    ?>
    <input type=hidden name=topicid value="<?php echo "$topicid"; ?>">
    <input type=hidden name=op value=topicchange>
    <table border=0><tr><td>
    <INPUT class='button' type="submit" value="<?php echo translate("Save Changes!"); ?>">
    </form></td><td>
    <?php echo "<form action=\"admin.$phpEx\" method=\"post\"><br>"; ?>
    <input type=hidden name=topicid value="<?php echo "$topicid"; ?>">
    <input type=hidden name=op value=topicdelete>
    <INPUT class='button' type="submit" value="<?php echo translate("Delete Topic!"); ?>">
    </form></td></tr></table>
    </td></tr></table></td></tr></table>
    <?php
    include("footer.$phpEx");
}

function relatededit($tid, $rid)
{
    global $tipath, $mpnTables,$phpEx;
    include("header.$phpEx");
    GraphicAdmin($hlpfile);
    $result=mysql_query("select name, url from ".$mpnTables['related']." where rid=$rid");
    list($name, $url) = mysql_fetch_row($result);

    $name = stripslashes( $name );
    $url = stripslashes( $url );

    $result2=mysql_query("select topictext, topicimage from ".$mpnTables['topics']." where topicid=$tid");
    list($topictext, $topicimage) = mysql_fetch_row($result2);

    $topictext = stripslashes( $topictext );
    $topicimage = stripslashes( $topicimage );


    OpenTable();
    echo "
    <center><font size=4>
    <img src = \"".$tipath.$topicimage,"\" alt = \"".$topictext."\" border = 0 align = \"right\">
    <b>".translate("Edit Related Link")."</b><br>
    <font size=2><b>".translate("Topic:")."</b> $topictext</center>
    <form action=\"admin.$phpEx\" method=\"post\">
    <font size=2>
    ".translate("Site Name: ")."<input type=text class=textbox name=name value=\"$name\" size=30 maxlength=30><br><br>
    ".translate("URL: ")."<input type=text class=textbox name=url value=\"$url\" size=60 maxlength=200><br><br>\n";

    // Kiril: New Sanitizer

        echo "<input type='hidden' name='stripit_form' value='name|url' />\n";
        echo "<input type='hidden' name='mpn_sectype' value='2' />\n";

    // End Sanitizer


    echo "<input type=hidden name=op value=relatedsave>
    <input type=hidden name=tid value=$tid>
    <input type=hidden name=rid value=$rid>
    <input class='button' type=submit value=".translate("Save Changes").">
    </form></td></tr></table></td></tr></table>";
    include("footer.$phpEx");
}

function relatedsave($tid, $rid, $name, $url)
{
    global $mpnTables,$phpEx;
    mysql_query("update ".$mpnTables['related']." set name='$name', url='$url' where rid=$rid");

    $_SERVER['F_LIB'] -> redirectRequest( 'admin.php?op=topicedit&topicid=' . $tid );

}

function relateddelete($tid, $rid)
{
    global $mpnTables,$phpEx;
    mysql_query("delete from ".$mpnTables['related']." where rid='$rid'");

    $_SERVER['F_LIB'] -> redirectRequest( 'admin.php?op=topicedit&topicid=' . $tid );

}

function topicmake($topicname, $topicimage, $topictext) {
    global $mpnTables,$phpEx;

    /*$topicname = stripslashes(FixQuotes($topicname));
    $topicimage = stripslashes(FixQuotes($topicimage));
    $topictext = stripslashes(FixQuotes($topictext));*/

    mysql_query("INSERT INTO ".$mpnTables['topics']." VALUES (NULL,'$topicname','$topicimage','$topictext','0')");

    $_SERVER['F_LIB'] -> redirectRequest( 'admin.php?op=topicsmanager#Add' );

}

function topicchange($topicid, $topicname, $topicimage, $topictext, $name, $url) {
    global $mpnTables,$phpEx;

    /*$topicname = stripslashes(FixQuotes($topicname));
    $topicimage = stripslashes(FixQuotes($topicimage));
    $topictext = stripslashes(FixQuotes($topictext));
    $name = stripslashes(FixQuotes($name));
    $url = stripslashes(FixQuotes($url));*/

    mysql_query("update ".$mpnTables['topics']." set topicname='$topicname', topicimage='$topicimage', topictext='$topictext' where topicid=$topicid");
    if (!$name) {
    } else {
        mysql_query("insert into ".$mpnTables['related']." VALUES (NULL, '$topicid','$name','$url')");
    }

    $_SERVER['F_LIB'] -> redirectRequest( 'admin.php?op=topicedit&topicid=' . $topicid );

}

function topicdelete($topicid, $ok=0) {
    global $mpnTables,$phpEx;
    if ($ok==1) {
        $result=mysql_query("select sid from ".$mpnTables['stories']." where topic='$topicid'");
        list($sid) = mysql_fetch_row($result);
        mysql_query("delete from ".$mpnTables['stories']." where topic='$topicid'");
        mysql_query("delete from ".$mpnTables['topics']." where topicid='$topicid'");
        mysql_query("delete from ".$mpnTables['related']." where tid='$topicid'");
        $result=mysql_query("select sid from ".$mpnTables['comments']." where sid='$sid'");
        list($sid) = mysql_fetch_row($result);
        mysql_query("delete from ".$mpnTables['comments']." where sid='$sid'");

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

    } else {
        global $tipath, $topicimage, $hlpfile;
        include("header.$phpEx");
        GraphicAdmin($hlpfile);
        $result2=mysql_query("select topicimage, topictext from ".$mpnTables['topics']." where topicid='$topicid'");
        list($topicimage, $topictext) = mysql_fetch_row($result2);
        OpenTable();
        echo "
        <center><img src = \"".$tipath.$topicimage."\" border = 0>
        <b>".translate("Delete Topic")." $topictext</b><br><br>
        ".translate("Are you sure you want to delete Topic")." $topictext?<br>
        ".translate("This will delete ALL it's stories and it's comments!")."<br><br>
        [ <a href=\"admin.$phpEx?op=topicsmanager\">".translate("No")."</a> | <a href=\"admin.$phpEx?op=topicdelete&topicid=$topicid&ok=1\">".translate("Yes")."</a> ]</center><br><br>
        </td></tr></table></td></tr></table>";
        include("footer.$phpEx");
    }
}

switch ($_REQUEST['op']) {

        case "topicsmanager":
            topicsmanager();
            break;

        case "topicedit":
            topicedit($_REQUEST['topicid']);
            break;

        case "topicmake":
            topicmake($_REQUEST['topicname'], $_REQUEST['topicimage'], $_REQUEST['topictext']);
            break;

        case "topicdelete":
			if (!isset($_REQUEST['ok'])) {
			    $_REQUEST['ok']=0;
			}
            topicdelete($_REQUEST['topicid'], $_REQUEST['ok']);
            break;

        case "topicchange":
            topicchange($_REQUEST['topicid'], $_REQUEST['topicname'], $_REQUEST['topicimage'], $_REQUEST['topictext'], $_REQUEST['name'], $_REQUEST['url']);
            break;

    case "relatedsave":
        relatedsave($_REQUEST['tid'], $_REQUEST['rid'], $_REQUEST['name'], $_REQUEST['url']);
        break;

    case "relatededit":
        relatededit($_REQUEST['tid'], $_REQUEST['rid']);
        break;

    case "relateddelete":
        relateddelete($_REQUEST['tid'], $_REQUEST['rid']);
        break;

}

?>
