<?php
//Set up the system
require('config.include.php');
//Auth stuff
require('auth.include.php');
//Save data if given
$saved=false;
if(isset($_POST['settings'])) {
	$tmpFile=@fopen('../wordblacklist.php','w+');
	if($tmpFile===false)
		die('Could not open "../wordblacklist.php" for writing, please check the file permissions.');
	$presettingsdata=explode("\n",fetch::unescapePostVar($_POST['settings']));
	$settingsdata=str_replace(array("\n","\r"),array('',''),$presettingsdata);
	foreach($settingsdata as $index=>$aword)
		if($aword=='')
			unset($settingsdata[$index]);
		else
			$settingsdata[$index]=strtolower($aword);
	$settingsdata=array_unique($settingsdata);
	fwrite($tmpFile,DIE_MSG.serialize($settingsdata));
	fclose($tmpFile);
	$saved=true;
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Edit Word Blacklist</title>
<link rel="stylesheet" href="admin.css" />
</head>

<body>
<div id="wrapper">
	<div id="header">
    	<?php echo('<a href="../" class="breadcrumb">'.SITE_TITLE.'</a> &raquo; <a href="dashboard.php" class="breadcrumb">Dashboard</a> &raquo; <a href="editblacklist.php" class="breadcrumb">Edit Word Blacklist</a>'); ?>
    </div>
    <div id="sidebar">
<?php
	require('nav.include.php');
?>
    </div>
    <div id="content">
        <div class="contentblock">
		<h2>Edit Word Blacklist</h2>
		<form action="editwordblacklist.php" method="post">
			One case-insensitive word per line, empty lines and duplicate entries are ignored.
			<textarea name="settings" cols="60" rows="30"><?php
				$list=substr(file_get_contents('../wordblacklist.php'),strlen(DIE_MSG));
				$listentries=unserialize($list);
				if(count($listentries)>0) {
					foreach($listentries as $word)
						echo($word."\n");
				}
			?></textarea>
			<br />
			<input type="submit" name="save" value="Save"/>
		</form>
		<?php
		if($saved)
			echo(count($settingsdata).' words saved.');
		?>
		</div>
    </div>
    <div id="footer">
    </div>
</div>
</body>
</html>