<?php
include("../includes/site_config.php");
require_once('../session_handler.inc');
require_once('../error.php');
//require_once('../functions.php');
//require_once('../includes/functions.php');
require_once('../lib/lib.Functions.php');
//include_once __INCLUDE_CLASS_PATH."/class.Language.php";
require_once('../lib/class.SpamChecker.php');
//include_once __INCLUDE_CLASS_PATH."/class.SpamChecker.php";
$spamChecker = & new SpamChecker();
//require_once('../lib/class.Pager.php'); 
$pager = new Pager(1,50);
$Sess_UserType=$_SESSION[Sess_UserType];
 $id = $_REQUEST['id'];
 
if ($Sess_UserType != "A") {
    exit;
}
//$skin=new Skin;
$area = 'member';
//$pager->SetUrl($CONST_LINK_ROOT."/admin/admin_spamwords.php");
$pager->SetUrl($CONST_LINK_ROOT."/admin/admin_spamwords.php");

 $name = $_REQUEST['name'];
 $action = $_REQUEST['action'];

switch ( $action ) {
    case 'save':
        $spamChecker -> InitForSave ( (object) array ( 'SpamWord' => $name ) );
        $spamChecker -> Save();
    break;
    case 'delete':
        
        $spamChecker -> Delete( $id );
       // redirect ($CONST_LINK_ROOT.'/admin/admin_spamwords.php');
    break;
	
	 case 'edit':
          
		   $strquery=mysql_query("UPDATE spamwords set SpamWord= '$name' WHERE SpamWord_ID='$id' ");
		   
        //$spamChecker -> Edit( $id );
		 
        
	   break;
    default:
	$spamWords = $spamChecker -> getList ( $pager );
    
}

$spamWords = $spamChecker -> getList ( $pager );
?>
<script>
function MM_openBrWindow(theURL,winName,features) { //v2.0

  window.open(theURL,winName,features);
  return false;
}
</script>
<?



include("include/header.php");


?>
<div class="mainwidth">
<div class="admin-page-header"><div class="admin-page-heading">&nbsp;&nbsp;Edit Spam Words</div></div>
<div class="clear"></div>
<div class="admin-page">
<table width="<?php print("$CONST_TABLE_WIDTH"); ?>" align="<?php print("$CONST_TABLE_ALIGN"); ?>" border="0" cellspacing="<?php print("$CONST_TABLE_CELLSPACING"); ?>" cellpadding="<?php print("$CONST_TABLE_CELLPADDING"); ?>">
        <tr>
      <td align="right">      </td>
    </tr>
    <tr>
      <td class="admin-head"><?php echo ADM_SPAMWORDS_SECTION_NAME ?></td>
    </tr>
	<tr>
      <td>

<?php /* LIST TABLE */ ?>
    <?// include "../pager.php"?>
    <table width="100%"  border="0" cellspacing="<?php print("$CONST_SUBTABLE_CELLSPACING"); ?>" cellpadding="<?php print("$CONST_SUBTABLE_CELLPADDING"); ?>">
<?php foreach ( $spamWords as $spamRow ) { ?>
    <tr align=left class="normal" >
      <td>
        <?=$spamRow->SpamWord;?>      </td>
	   <td align="right" width="5%" nowrap="nowrap">
     
	 <!-- <a href="javascript:;" 
onclick="MM_openBrWindow('spamwords_edit.php?&id=<?=$spamRow->SpamWord_ID;?>','','width=200,height=200');"><?=ADM_SPAMWORDS_EDIT_LINK_TITLE;?></a>-->
	<a href="<?=$_SERVER['PHP_SELF']?>?id=<?=$spamRow->SpamWord_ID?>&edit_text=edit_text"><?=GENERAL_EDIT?></a>
        <a href="<?=$CONST_LINK_ROOT;?>/admin/admin_spamwords.php?action=delete&id=<?=$spamRow->SpamWord_ID;?>"><?=ADM_SPAMWORDS_DELETE_LINK_TITLE;?></a>      </td>
    </tr>
<?php } ?>
    </table>      </td>
    </tr>
    <tr>
	
	<? if(!isset($_REQUEST['edit_text'])){?>
<form method="post" action="<?php echo $CONST_LINK_ROOT?>/admin/admin_spamwords.php<?php print("?PHPSESSID=".session_id()); ?>" name="frmAddSpamword">
<input type="hidden" name="action" value="save">
            <td align="center">
    <table width="100%"  border="0" cellspacing="<?php print("$CONST_SUBTABLE_CELLSPACING"); ?>" cellpadding="<?php print("$CONST_SUBTABLE_CELLPADDING"); ?>">
                <tr>
                  <td colspan="2" class="tdhead">&nbsp;</td>
                </tr>
                <tr>
                  <td width="25%" class="admin-head2">
                    <?=ADM_SPAMWORDS_WORD_TITLE;?>
                :</td>
                  <td width="75%" class="normal" align="right">
			
			
					<input type="text" name="name" class="inputl" value="" > </td>
					</tr><tr><td>&nbsp;</td><td align="right">
					<input name="submit" type="submit" class="normal" value="<?=ADM_SPAMWORDS_ADD_LINK_TITLE;?>" >                  						
					</td>
                </tr>
                </table></td>
          </form>
		  <? } else {
		
		$sql_result = mysql_query("SELECT * FROM spamwords where SpamWord_ID = $id", $link);
		$spam_edit = mysql_fetch_object($sql_result);
		
		?>
		<form method="post" action="<?php echo $CONST_LINK_ROOT?>/admin/admin_spamwords.php?id=<?=$spam_edit->SpamWord_ID?>" name="frmAddSpamword">
<input type="hidden" name="action" value="edit">
            <td align="center">
    <table width="100%"  border="0" cellspacing="<?php print("$CONST_SUBTABLE_CELLSPACING"); ?>" cellpadding="<?php print("$CONST_SUBTABLE_CELLPADDING"); ?>">
                <tr>
                  <td colspan="2" class="tdhead">&nbsp;</td>
                </tr>
                <tr>
                  <td width="25%" class="admin-head2">
                    <?=ADM_SPAMWORDS_EDIT_TITLE?>
                :</td>
                  <td width="75%" class="normal" align="right">
			
			
					<input type="text" name="name" class="inputl" value="<?=$spam_edit->SpamWord?>" > 
					
					                  						
					</td>
                </tr>
				<tr> <td>&nbsp;</td>
				<td align="right"><input name="submit" type="submit" class="normal" value="<?=ADM_SPAMWORDS_EDIT_LINK_TITLE?>" > <input name="button" type="button" class="normal" onclick="window.location = '<?=$_SERVER['PHP_SELF']?>'" value="<?=GENERAL_CANCEL?>"></td>
                </table></td>
          </form>
		<? }?>


      </td>
    </tr>
</table></div><div class="admin-page-bottom"></div></div>
<?php include("include/footer.php"); ?>