<?php
$file = __FILE__;
include ("inc/inc_common.php");
include ("inc/inc_connect.php");

if ($action == "check")
{
    $result = mysql_query( "SELECT * FROM $grouptable WHERE intId = '$groupid'" );
    $num_rows = mysql_num_rows( $result );
    while ( $a_row = mysql_fetch_object( $result ) )
    {
        $pass2 = $a_row->strPassword;
    }
    if ($pass1 == $pass2)
    {
        // Enter info into the password database
        if (isset($gfcookie[1]))
        {
            //purge any older records

            $query = "DELETE FROM $passwordtable WHERE strName = '$gfcookie[1]' AND intTopicId = '$groupid'";
            mysql_query( $query, $link )
                or die ( "Could not add data to \"tblactivetopics\" table: "
                .mysql_error() );

            //now add the new one...

            $query = "INSERT INTO $passwordtable
            ( strName, intTopicId, strPassword )
            values( '$gfcookie[1]', '$groupid', '$pass1' )";

            mysql_query( $query, $link )
                or die ( "Could not add data to \"tblactivetopics\" table: "
                .mysql_error() );
        }
        header("Location:topics.php?groupid=$groupid");
        exit;
    }
    else
    {
        header("Location:topicpass.php?groupid=$groupid&wrong=1");
        exit;
    }
}

include ("inc/inc_admincheck.php");
// See if user has already entered the password correctly...

$result = mysql_query( "SELECT * FROM $grouptable WHERE intId = '$groupid'" );
$num_rows = mysql_num_rows( $result );
while ( $a_row = mysql_fetch_object( $result ) )
{
    $resultb = mysql_query( "SELECT * FROM $passwordtable WHERE intTopicId = '$groupid' AND strName = '$gfcookie[1]'" );
    $bnum_rows = mysql_num_rows( $resultb );
    while ( $b_row = mysql_fetch_object( $resultb ) )
    {
        $password1 = $b_row->strPassword;
    }
    if ($password1 == $a_row->strPassword)
    {
        header("Location:topics.php?groupid=$groupid");
        exit;
    }
    /*if ($cAdminLevel > 4)
    {
        header("Location:topics.php?groupid=$groupid");
        exit;
    }*/
}

include ("inc/inc_getdate.php");
include ("inc/inc_forumname.php");
$page = "Asking for Group $groupid's password";
$pagelink = $file."?groupid=".$groupid;
include("inc/inc_setonline.php");
$title = $userid."Password Entry";
include ("inc/inc_head.php");
include ("inc/inc_body.php");
print "<center><br><br><br><br><br> <table border=1 cellpadding=0 cellspacing=0 bordercolor=\"$bordercolor\" width=\"60%\" bgcolor=\"$fgcolour\"><tr><td><br><center><font size=$fontsize face=\"$font\" color=\"$fontcolor\">";



if ($wrong == 1)
{
    print "Sorry, that is the wrong password.<br>";
}

print "Please enter the password for this forum.<br>
<form method=\"post\" action=\"topicpass.php?action=check\">
<input type=\"password\" name=\"pass1\" onfocus=\"document.onkeypress=function(){};\" style=\"background-image: url('images/textbox_background.gif')\"><br>
<input type=\"submit\" value=\"Submit\">
<input type=\"hidden\" value=\"$groupid\" name=\"groupid\">
<br><br></td></tr></table>";

include("inc/inc_footer.php");
?>
