<?php

if ( ! @include_once( './mainfile.php' ) ) { exit( '!! INCLUDE ERROR. ACCESS DENIED !!' ); }
error_reporting( _E_VALUE );

/* vim: set expandtab tabstop=4 shiftwidth=4: */

// ***** BEGIN LICENSE BLOCK ( DO NOT REMOVE ) *****

// +----------------------------------------------------------------------+
// | phpBB 1.4.x Forum For MPN 188_8                                      |
// |                                                                      |
// | -> Topic Administration                                              |
// +----------------------------------------------------------------------+
// | VERSION: 0.1 Alpha                                                   |
// +----------------------------------------------------------------------+
// | LICENSE: GPL 2.0 (see docs/LICENSE_GPL)                              |
// |                                                                      |
// | This file is part of phpBB 1.4.x Forum For MPN 188_8.                |
// |                                                                      |
// | phpBB 1.4.x Forum For MPN 188_8 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, or (at your option) any             |
// | later version.                                                       |
// |                                                                      |
// | phpBB 1.4.x Forum For MPN 188_8 is distributed in the hope that it   |
// | will be useful, but WITHOUT ANY WARRANTY; without even the implied   |
// | warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.     |
// | See the GNU General Public License for more details.                 |
// |                                                                      |
// | You should have received a copy of the GNU General Public License    |
// | along with phpBB 1.4.x Forum For MPN 188_8; if not, write to the     |
// |                                                                      |
// | Free Software Foundation, Inc.                                       |
// | 59 Temple Place, Suite 330                                           |
// | Boston, MA 02111-1307  USA                                           |
// +----------------------------------------------------------------------+
// | AUTHOR(s):                                                           |
// |                                                                      |
// | The Original Code is the phpbb 1.4.4 Forum For MPN 188_8.            |
// | The Initial Developer of the Original Code is Eric Haddix.           |
// |                                                                      |
// | Portions created by Eric Haddix or Kiril Threndor                    |
// | <support@mpn.illearth.net> are                                       |
// | Copyright (C) 2003 Eric Haddix.  All Rights Reserved.                |
// +----------------------------------------------------------------------+
// | HISTORICAL AUTHORS & COPYRIGHTS:                                     |
// |                                                                      |
// | Portions created by Richard Tirtadji or King Richard                 |
// | <rtirtadji@hotmail.com> are                                          |
// | Copyright (C) 2001 Richard Tirtadji.  All Rights Reserved.           |
// |                                                                      |
// | Portions created by Hutdik Hermawan or hotFix                        |
// | <hutdik76@hotmail.com> are                                           |
// | Copyright (C) 2001 Hutdik Hermawan.  All Rights Reserved.            |
// |                                                                      |
// | Portions created by Nathan Codding, Hombergs, or Francisco Burzi     |
// | are Copyright (C) 2001 Francisco Burzi.  All Rights Reserved.        |
// +----------------------------------------------------------------------+
// | CONTRIBUTOR(s):                                                      |
// |                                                                      |
// |                                                                      |
// +----------------------------------------------------------------------+
// | MODIFICATIONS:                                                       |
// |                                                                      |
// |                                                                      |
// +----------------------------------------------------------------------+
// | REQUIRED FILES: functions.php                                        |
// |                                                                      |
// +----------------------------------------------------------------------+
// | NOTES:                                                               |
// |   The MPN 188_8 forum is nearly a complete, and in some cases entire,|
// |   recode of the phpNuke 4.4 forum which was based on phpBB 1.4.x.    |
// +----------------------------------------------------------------------+
// | SUPPORT:                                                             |
// |   WEB:   http://myphpnuke.com/                                       |
// |   EMAIL: support@mpn.illearth.net                                    |
// +----------------------------------------------------------------------+

/**
 * MPN_188_8_Modules
 *
 * @package MPN_188_8_Modules
 * @subpackage forum
 * @version $Id: topicadmin.php,v 1.8.2.8 2004/03/28 18:37:40 kirilt Exp $
 *
 * @author Kiril Threndor <support@mpn.illearth.net>
 * @copyright Mixed (see individual scripts)
 * @license http://www.gnu.org/licenses/gpl.html GPL 2.0
 * @support http://myphpnuke.com/
 * @todo finish CSS & XHTML conversion
 * @todo reformat old style formatted code to new coding style
 * @todo finish recode
 *
 * @tutorial
 * @filesource
 */

// ***** END LICENSE BLOCK ( DO NOT REMOVE ) *****

@( include_once __ROOT__ . 'core_ForumEntry.php' )
  OR goBack( translate( 'Include Error' ) );

@( include_once __ROOT__ . 'header.php' )
  OR goBack( translate( 'Include Error' ) );

echo '<div id="forum">' . "\n";

getModerators( $_REQUEST['forum'] );

if ( ! $GLOBALS['uinf']['mod'] && ! ( $GLOBALS['uinf']['level'] >= 2 ) )
{
    goBack( 'Insufficient Rights' );
    exit;
}

OpenTable();

if ( isset( $_POST['submit'] ) )
{
    echo "<center>";

    switch ($mode)
    {
        case 'del':
        $sql = "DELETE FROM ".$mpnTables['posts']." WHERE topic_id = '$topic'";
        if (!$result = mysql_query($sql))
        {
            forumerror('0009');
        }

        $sql = "DELETE FROM ".$mpnTables['forumtopics']." WHERE topic_id = '$topic'";
        if (!$result = mysql_query($sql))
        {
            forumerror('0009');
        }

        echo translate("The topic has been removed from the database.")."<br><a href=\"viewforum.$phpEx?forum=$forum\">".translate("Click here to return to the forum.")."</a><br><a href='forum.php'>".translate("Click here to return to the forum index.")."</a>";
        break;

        case 'move':
        $sql = "UPDATE ".$mpnTables['forumtopics']." SET forum_id = '$newforum' WHERE topic_id = '$topic'";
        if (!$r = mysql_query($sql))
        {
            forumerror(0010);
        }

        $sql = "UPDATE ".$mpnTables['posts']." SET forum_id = '$newforum' WHERE topic_id = '$topic'";
        if (!$r = mysql_query($sql))
        {
            forumerror('0010');
        }

        echo translate("The topic has been moved.")."<br><a href=\"viewtopic.$phpEx?topic=$topic&forum=$newforum\">".translate("Click here to view the updated topic.")."</a><br><a href='forum.php'>".translate("Click here to return to the forum index.")."</a>";
        break;

        case 'lock':
        $sql = "UPDATE ".$mpnTables['forumtopics']." SET topic_status = 1 WHERE topic_id = '$topic'";
        if (!$r = mysql_query($sql))
        {
            forumerror('0011');
        }

        echo translate("The topic has been locked.")."<br><a href=\"viewtopic.$phpEx?topic=$topic&forum=$forum\">".translate("Click here to view the updated topic.")."</a><br><a href='forum.php'>".translate("Click here to return to the forum index.")."</a>";
        break;

        case 'unlock':
        $sql = "UPDATE ".$mpnTables['forumtopics']." SET topic_status = '0' WHERE topic_id = '$topic'";
        if (!$r = mysql_query($sql))
        {
            forumerror('0012');
        }

        echo translate("The topic has been unlocked.")."<br><a href=\"viewtopic.$phpEx?topic=$topic&forum=$forum\">".translate("Click here to view the updated topic.")."</a><br><a href='forum.php'>".translate("Click here to return to the forum index.")."</a>";
        break;

        case 'viewip':

        $sql = "SELECT p.poster_ip, u.uname
                FROM ".$mpnTables['posts']." AS p
                    , ".$mpnTables['users']." AS u
                WHERE p.post_id = '$post_id'
                    && p.poster_id = u.uid";

        if (!$r = mysql_query($sql))
        {var_dump (mysql_error());echo"<br /><br />";
            forumerror('0013');
        }

        if (!$m = mysql_fetch_array($r))
        {
            forumerror('0014');
        }

        ?>
        <TABLE BORDER="0" CELLPADDING="1" CELLSPACEING="0" ALIGN="CENTER" VALIGN="TOP" WIDTH="95%"><TR><TD BGCOLOR="<?php echo $table_bgcolor?>">
        <TABLE BORDER="0" CELLPADDING="1" CELLSPACEING="1" WIDTH="100%">
        <TR BGCOLOR="<?php echo $bgcolor3?>" ALIGN="LEFT">
        <TD COLSPAN="2" ALIGN="CENTER"><?php echo translate("Users IP and Account information");?></TD>
        </TR>
        <TR BGCOLOR="<?php echo $bgcolor1?>" ALIGN="LEFT">
        <TD><?php echo translate("Nickname: ");?></TD>
        <TD><?php echo $m['uname']; ?></TD>
        </TR>
        <TR BGCOLOR="<?php echo $bgcolor1?>" ALIGN="LEFT">
        <TD><?php echo translate("User IP: ");?></TD>
        <TD><?php echo $m['poster_ip']; ?></TD>
        </TR>
        <TR>
        <TD colspan="2" align="center">
        <?php
        echo "<a href=\"viewforum.$phpEx?forum=$forum\">".translate("Click here to return to the forum.")."</a><br><a href='forum.php'>".translate("Click here to return to the forum index.")."</a>";
        ?>
        </TD>
        </TR>
        </TABLE></TD></TR></TABLE>
        <?php
        break;
    }

    echo "</center>";

}
else
{

    echo '<div class="center">' . "\n";

    echo '<h2>' . translate( 'Read This: ' ) . '</h2>' . "\n";

    echo '<br />' . "\n";

    switch ($mode)
    {
        case 'del':

            echo translate("Once you press the delete button at the bottom of this form the topic you have selected, and all its related posts, will be permanently removed.");

        break;

        case 'move':

            echo translate("Once you press the move button at the bottom of this form the topic you have selected, and its related posts, will be moved to the forum you have selected.");

        break;

        case 'lock':

            echo translate("Once you press the lock button at the bottom of this form the topic you have selected will be locked. You may unlock it at a later time if you like.");

        break;

        case 'unlock':

            echo translate("Once you press the unlock button at the bottom of this form the topic you have selected will be unlocked. You may lock it again at a later time if you like.");

        break;

        case 'viewip':

            echo translate( 'View This Users IP' );

        break;
    }

    echo '<br /><br />' . "\n";

    echo "<FORM ACTION=\"topicadmin.php\" METHOD=\"POST\">";

    if ($mode == 'move')
    {
         echo translate("Move Topic To: ");?>
         <SELECT NAME="newforum" SIZE="0">
        <?php
        $sql = "SELECT forum_id, forum_name FROM ".$mpnTables['forums']." WHERE forum_id != '$forum' ORDER BY forum_id";
        if ($result = mysql_query($sql))
        {
            if ($myrow = mysql_fetch_array($result))
            {
                do
                {
                    echo "<OPTION VALUE=\"" . $myrow['forum_id'] . "\">" . $myrow['forum_name'] . "</OPTION>\n";
                } while($myrow = mysql_fetch_array($result));
            }
            else
            {
                echo "<OPTION VALUE=\"-1\">".translate("No More Forums")."</OPTION>\n";
            }
        }
        else
        {
            echo "<OPTION VALUE=\"-1\">Database Error</OPTION>\n";
        }

        ?>
        </SELECT>
        <br /><br />
        <?php
    }

   switch ($mode)
    {
        case 'del':
        ?>
        <INPUT TYPE="HIDDEN" NAME="mode" VALUE="del">
        <INPUT TYPE="HIDDEN" NAME="topic" VALUE="<?php echo $topic?>">
        <INPUT TYPE="HIDDEN" NAME="forum" VALUE="<?php echo $forum?>">
        <INPUT class='button' TYPE="SUBMIT" NAME="submit" VALUE="<?php echo translate("Delete Topic");?>">
        <?php
        break;

        case 'move':
        ?>
        <INPUT TYPE="HIDDEN" NAME="mode" VALUE="move">
        <INPUT TYPE="HIDDEN" NAME="topic" VALUE="<?php echo $topic; ?>">
        <INPUT TYPE="HIDDEN" NAME="forum" VALUE="<?php echo $forum; ?>">
        <INPUT class='button' TYPE="SUBMIT" NAME="submit" VALUE="<?php echo translate("Move Topic");?>">
        <?php
        break;

        case 'lock':
        ?>
        <INPUT TYPE="HIDDEN" NAME="mode" VALUE="lock">
        <INPUT TYPE="HIDDEN" NAME="topic" VALUE="<?php echo $topic?>">
        <INPUT TYPE="HIDDEN" NAME="forum" VALUE="<?php echo $forum?>">
        <INPUT class='button' TYPE="SUBMIT" NAME="submit" VALUE="<?php echo translate("Lock Topic");?>">
        <?php
        break;

        case 'unlock':
        ?>
        <INPUT TYPE="HIDDEN" NAME="mode" VALUE="unlock">
        <INPUT TYPE="HIDDEN" NAME="topic" VALUE="<?php echo $topic; ?>">
        <INPUT TYPE="HIDDEN" NAME="forum" VALUE="<?php echo $forum; ?>">
        <INPUT class='button' TYPE="SUBMIT" NAME="submit" VALUE="<?php echo translate("Unlock Topic");?>">
        <?php
        break;

        case 'viewip':
        ?>
        <INPUT TYPE="HIDDEN" NAME="mode" VALUE="viewip">
        <INPUT TYPE="HIDDEN" NAME="post_id" VALUE="<?php echo $post_id; ?>">
        <INPUT TYPE="HIDDEN" NAME="forum" VALUE="<?php echo $forum; ?>">
       <INPUT class='button' TYPE="SUBMIT" NAME="submit" VALUE="<?php echo translate("View IP");?>">
        <?php
        break;
    }

    ?>
    <INPUT TYPE="HIDDEN" NAME="level" VALUE="<?php echo $GLOBALS['uinf']['level']; ?>">
    </form>
    <?php

} // End if/then

CloseTable();

echo '</div>' . "\n";

@( include_once __ROOT__ . 'footer.php' )
  OR goBack( translate( 'Include Error' ) );


// ##### HISTORICAL NOTICES #####


/************************************************************************/
/* PHP-NUKE: Web Portal System                                          */
/* ===========================                                          */
/*                                                                      */
/* Copyright (c) 2001 by Francisco Burzi (fburzi@ncc.org.ve)            */
/* http://phpnuke.org                                                   */
/*                                                                      */
/* =========================                                            */
/* Part of phpBB integration                                            */
/* Copyright (c) 2001 by                                                */
/*    Richard Tirtadji AKA King Richard (rtirtadji@hotmail.com)         */
/*    Hutdik Hermawan AKA hotFix (hutdik76@hotmail.com)                 */
/* http://www.phpnuke.web.id                                            */
/*                                                                      */
/* 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.       */
/************************************************************************/

?>