<?php
$admin = 2;
$file = __FILE__;
include ("../inc/inc_common.php");
include ("../inc/inc_connect.php");
include ("../inc/inc_admincheck.php");
include ("../inc/inc_getdate.php");
include ("../inc/inc_forumname.php");
$page = "Admin - Swearing Filters";
$pagelink = $file;
include("../inc/inc_setonline.php");
$title = "$name1 Admin - $gfcookie[1] - Swearing Filters";
include ("../inc/inc_head.php");
include ("../inc/inc_body.php");
$title = "Swearing Filters";
include ("../inc/inc_title.php");

if ($action == "add")
{
    $result=mysql_query("SELECT * FROM $sweartable ORDER BY intId");
    $num_rows = mysql_num_rows( $result );
    while ( $a_row = mysql_fetch_object( $result ) )
    {
        $id = $a_row->intId;
        if ($a_row->strReplace1 != $replace1[$a_row->intId] AND isset($replace1[$a_row->intId]))
        {
            $replace = $replace1[$a_row->intId];
            $query = "UPDATE $sweartable SET strReplace1 = '$replace' WHERE intId = '$id'";
            mysql_query( $query, $link ) or die ( "Error! : ".mysql_error() );
        }

        if ($a_row->strReplace2 != $replace2[$a_row->intId] AND isset($replace2[$a_row->intId]))
        {
            $replace = $replace2[$a_row->intId];
            $query = "UPDATE $sweartable SET strReplace2 = '$replace' WHERE intId = '$id'";
            mysql_query( $query, $link ) or die ( "Error! : ".mysql_error() );
        }

        if ($a_row->strReplace3 != $replace3[$a_row->intId] AND isset($replace3[$a_row->intId]))
        {
            $replace = $replace3[$a_row->intId];
            $query = "UPDATE $sweartable SET strReplace3 = '$replace' WHERE intId = '$id'";
            mysql_query( $query, $link ) or die ( "Error! : ".mysql_error() );
        }

        if ($a_row->strReplace4 != $replace4[$a_row->intId] AND isset($replace4[$a_row->intId]))
        {
            $replace = $replace4[$a_row->intId];
            $query = "UPDATE $sweartable SET strReplace4 = '$replace' WHERE intId = '$id'";
            mysql_query( $query, $link ) or die ( "Error! : ".mysql_error() );
        }

        if ($a_row->strReplace5 != $replace5[$a_row->intId] AND isset($replace5[$a_row->intId]))
        {
            $replace = $replace5[$a_row->intId];
            $query = "UPDATE $sweartable SET strReplace5 = '$replace' WHERE intId = '$id'";
            mysql_query( $query, $link ) or die ( "Error! : ".mysql_error() );
        }
    }
}


if ($action == "new")
{
    $query = "INSERT INTO $sweartable ( strSwear) values( '$new')";
    mysql_query( $query, $link ) or die ( "Error! : ".mysql_error() );
}

if ($action == "delete")
{
    $query = "DELETE FROM $sweartable WHERE intID = '$id'";
    mysql_query( $query, $link ) or die ( "Error! : ".mysql_error() );
}




print "<br><center>
<table border=1 cellpadding=3 cellspacing=0 style=\"border-collapse: collapse\" bordercolor=\"$bordercolor\" width=\"85%\" bgcolor=\"$fgcolour\"><tr><td align=\"center\"><font face=\"$font\" size=2><br><br>
<form method=\"post\" action=\"admin_swearing.php?action=add\">
<table border=0 cellspacing=0 style=\"font-family: $font; font-size: $fontpoint\" width=\"100%\"><tr>
<td align=\"center\"><img border=0 src=\"../images/delete_icon.gif\"></td>
<td align=\"center\"><b>Word To Replace</b></td>
<td align=\"center\"><b>Replacement 1</b></td>
<td align=\"center\"><b>Replacement 2</b></td>
<td align=\"center\"><b>Replacement 3</b></td>
<td align=\"center\"><b>Replacement 4</b></td>
<td align=\"center\"><b>Replacement 5</b></td></tr>
<tr>
<td align=\"center\"><br></td>
<td align=\"center\"><br></td>
<td align=\"center\"><br></td>
<td align=\"center\"><br></td>
<td align=\"center\"><br></td>
<td align=\"center\"><br></td>
<td align=\"center\"><br></td></tr>";

$result=mysql_query("SELECT * FROM $sweartable ORDER BY intId");
$num_rows = mysql_num_rows( $result );
while ( $a_row = mysql_fetch_object( $result ) )
{
    $counter = 0;
    print "<tr>
    <td align=\"center\">
    <a OnClick=\"return confirm('Are you sure you want to delete this word?')\" href=\"admin_swearing.php?id=$a_row->intId&action=delete\"><img border=0 src=\"../images/delete_icon.gif\"></a>
    </td>
    <td align=\"center\"><a href=\"admin_swearingchange.php?id=$a_row->intId&num=1\">$a_row->strSwear</a></td>";

    if ($a_row->strReplace1 == "")
    {
        print "<td align=\"center\"><input type=\"text\" onfocus=\"document.onkeypress=function(){};\" name=\"replace1[$a_row->intId]\" size=\"14\" style=\"background-image: url('../images/textbox_background.gif')\"></td>";
    }
    else
    {
        print "<td align=\"center\"><a href=\"admin_swearingchange.php?id=$a_row->intId&num=2\">$a_row->strReplace1</a></td>";
        $counter ++;
    }

    if ($a_row->strReplace2 == "")
    {
        print "<td align=\"center\"><input type=\"text\" onfocus=\"document.onkeypress=function(){};\" name=\"replace2[$a_row->intId]\" size=\"14\" style=\"background-image: url('../images/textbox_background.gif')\"></td>";
    }
    else
    {
        print "<td align=\"center\"><a href=\"admin_swearingchange.php?id=$a_row->intId&num=3\">$a_row->strReplace2</a></td>";
        $counter ++;
    }

    if ($a_row->strReplace3 == "")
    {
        print "<td align=\"center\"><input type=\"text\" onfocus=\"document.onkeypress=function(){};\" name=\"replace3[$a_row->intId]\" size=\"14\" style=\"background-image: url('../images/textbox_background.gif')\"></td>";
    }
    else
    {
        print "<td align=\"center\"><a href=\"admin_swearingchange.php?id=$a_row->intId&num=4\">$a_row->strReplace3</a></td>";
        $counter ++;
    }

    if ($a_row->strReplace4 == "")
    {
        print "<td align=\"center\"><input type=\"text\" onfocus=\"document.onkeypress=function(){};\" name=\"replace4[$a_row->intId]\" size=\"14\" style=\"background-image: url('../images/textbox_background.gif')\"></td>";
    }
    else
    {
        print "<td align=\"center\"><a href=\"admin_swearingchange.php?id=$a_row->intId&num=5\">$a_row->strReplace4</a></td>";
        $counter ++;
    }

    if ($a_row->strReplace5 == "")
    {
        print "<td align=\"center\"><input type=\"text\" onfocus=\"document.onkeypress=function(){};\" name=\"replace5[$a_row->intId]\" size=\"14\" style=\"background-image: url('../images/textbox_background.gif')\"></td>";
    }
    else
    {
        print "<td align=\"center\"><a href=\"admin_swearingchange.php?id=$a_row->intId&num=6\">$a_row->strReplace5</a></td>";
        $counter ++;
    }

    $id = $a_row->intId;

    $query = "UPDATE $sweartable SET intReplace = '$counter' WHERE intId = '$id'";
    mysql_query( $query, $link ) or die ( "Error! : ".mysql_error() );
}



print "</table><bR><br><table border=0><tr><td><input type=\"submit\" value=\"Make Changes\"></td></form><form method=\"POST\" action=\"admin_newswear.php\"><td><input type=\"submit\" value=\"Add New\"></td></form></tr></table>
<br></td></tr></table>";  // "and, challenging for the lead in "The Ugliest Piece Of Coding" award... Grimforum!" (Wild cheering, applause, etc...) =]

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