<?php
include ("inc/inc_common.php");
include ("inc/inc_connect.php");
include ("inc/inc_admincheck.php");

if ($cAdminLevel < 1)
{
    //kick out non-moderators...
    header("Location: topic.php?topicid=$topicid&groupid=$groupid#post$delid");
    exit;
}

if ($undelete == 1)
{
    //unhide...
    $query = "UPDATE $forumtable SET intPostHidden = '0', strHider = '$gfcookie[1]' WHERE intId = '$delid'";
    mysql_query( $query, $link ) or die ( "Error! : ".mysql_error() );
    $result = mysql_query( "SELECT * FROM $forumtable WHERE intTopicId = '$topicid' ORDER BY intId DESC" );
    $num_rows = mysql_num_rows( $result );
    //Dispay records
    while ( $a_row = mysql_fetch_object( $result ) )
    {
        if (isset ($a_row->strTopicName))
        {
            $thisreplies = $a_row->intReplies;
        }
    }
    if ($thisreplies == "")
    {
        $thisreplies = "1";
    }
    $thisreplies ++;
    $query = "UPDATE $forumtable SET intReplies = '$thisreplies' WHERE intTopicId = '$topicid'";
    mysql_query( $query, $link ) or die ( "Could not add data to \"tblMain\" table: ".mysql_error() );
    header("Location: topic.php?topicid=$topicid&groupid=$groupid#post$delid");
    exit;
}


if ($softdelete == 1)
{
    //hide from non-moderators...
    $query = "UPDATE $forumtable SET intPostHidden = '1', strHider = '$gfcookie[1]' WHERE intId = '$delid'";
    mysql_query( $query, $link ) or die ( "Error! : ".mysql_error() );

}
else
{
    //or delete entirely
    $query = "DELETE FROM $forumtable WHERE intId = '$delid'";
    mysql_query( $query, $link ) or die ( "Could not delete from \"$forumtable\" table: ".mysql_error() );
}


//delete one from the number of replies this topic has...


$result = mysql_query( "SELECT * FROM $forumtable WHERE intTopicId = '$topicid' ORDER BY intId DESC" );
$num_rows = mysql_num_rows( $result );
//Dispay records
while ( $a_row = mysql_fetch_object( $result ) )
{
    if (isset ($a_row->strTopicName))
    {
        $thisreplies = $a_row->intReplies;
    }
}

if ($thisreplies == "")
{
    $thisreplies = "1";
}
$thisreplies -= 1;


$query = "UPDATE $forumtable SET intReplies = '$thisreplies' WHERE intTopicId = '$topicid'";
mysql_query( $query, $link ) or die ( "Could not add data to \"tblMain\" table: ".mysql_error() );

header("Location: topic.php?topicid=$topicid&groupid=$groupid#post$delid");
exit;
