Location: PHPKode > projects > Fretsweb > fretsweb-1.2/fretsweb/admin/newshandle.php
<?php

/*
Fretsweb - A Frets on Fire chart server
Copyright (C) 2009, Daan Sprenkels

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

require_once "common.php";

//Login Test
session_start();
if($_SESSION['in'] < 1)
{
	header('location: login.php?need=moderator');
	die();
}

if(isset($_POST['addmessage']))
{
	if($_POST['text'] < 3)
	{
		if($_POST['title'] < 3)
		{
			cfeed($_POST['title'], $_POST['text'], 'usermessage');
			$info = "Added new message.";
		}
		else
		{
			$info = "Title is too short.";
		}
	}
	else
	{
		$info = "Text is too short.";
	}
}
elseif(isset($_GET['delete']))
{
	$sql = "SELECT * FROM `contest_news` WHERE `id`='{$_GET['delete']}'";
	$query = mysql_query($sql);
	if(mysql_num_rows($query) > 0)
	{
		$sql = "DELETE FROM `contest_news` WHERE `id`={$_GET['delete']}";
		mysql_query($sql);
		$info = "Deleted news-message with id: {$_GET['delete']}.";
	}
	else
	{
		$info = "No news-message with id {$_GET['delete']}. So it's not deleted.";
	}
}

?>
<html>
 <head>
  <title>News feed</title>
  <link href="../css.php" rel="stylesheet" type="text/css" />
  <link href="../images/favicon.png" rel="icon">
 </head>
 <body>
<center>
<h2>News feed</h2>
<?php
include_once "log.php";

if(isset($info))
	echo "<p class=\"info\">$info</p>";

if($feed > 0)
{
	echo '<p>Feed is enabled, go to the configuration panel to change this.</p>';
}
else
{
	echo '<p>Feed is disabled, go to the configuration panel to change this.</p>';
}
echo '<table class="regular">';
echo '<tr><th>Head</th><th>P</th><th>Contents</th><th/></tr>';
$sql = "SELECT `id`, `title`, `text`, `code`, `priority`, `time` FROM `contest_news`";
$query = mysql_query($sql);
while ($row = mysql_fetch_assoc($query))
{
	echo '<tr>';
	echo "<th style=\"vertical-align: middle;\">{$row['code']} at {$row['time']}</th>";
	echo "<td style=\"vertical-align: middle;\">{$row['priority']}</td>";
	echo "<td style=\"vertical-align: middle;\">" . str_replace("\n", "<br/>", $row['text']) . "</td>";
	echo "<td style=\"vertical-align: middle;\"><a href=\"{$_SERVER['PHP_THIS']}?delete={$row['id']}\"><img src=\"../images/cross.png\" alt=\"Del\"></a></td>";
	echo '</tr>';
}
echo '</table>';
?>
<form action="<?php echo $_SERVER['PHP_THIS']; ?>" method="post">
<p>Title: <input type="text" name="title"></p>
<p><textarea name="text" cols="64" rows="6"></textarea></p>
<p><input type="submit" name="addmessage" value="Add new message"></p>
</form>
<p><b><a href="index.php">Back to main administration panel</a></b><p>
</center>
 </body>
</html>
<?php 
	// close db!
	mysql_close( $db_link ); 
?>
Return current item: Fretsweb