// Preamble
$pageName = "Edit News";
$need = 'auth';
require "parts/preamble.php"; // Load most of document
if (!$userInfo['u_admin']) // no access from non-admin
bailout ('
You don\'t have access to this page. Bug an admin to delete a news post.
');
need ('sql');
function convertToHTML ($string)
{
$table = array_flip (get_html_translation_table (HTML_ENTITIES));
return strtr ($string, $table);
}
function convertFromHTML ($string)
{
$table = get_html_translation_table (HTML_ENTITIES);
return strtr ($string, $table);
}
function newsEntrySummary ($array)
{
need ("date");
return
''
.' ' . $array[n_id] . ' | '
.' ' . dateFromSQLDateTime ($array[n_date]) . ' | '
.' ' . $array[n_user] . ' | '
.' ' . substr (convertFromHTML (StripSlashes ($array[n_news])), 0, 60) . '… | '
.'
';
}
function newsEntryEditor ($array)
{
need ("date");
$id = $array[n_id];
$usr = $array[n_user];
$txt = convertFromHTML(stripSlashes($array[n_news]));
$date = dateFromSQLDateTime($array[n_date]);
?>
}
need ('sql');
global $newsID;
global $newsUser;
global $newsItem;
$newsID = $_GET['newsID'];
$newsItem = $_POST['newsItem'];
$newsUser = $_POST['newsUser'];
if ($conn = mysql_pconnect (sqlHost, sqlRWUser, sqlRWPass)) {
if ($newsID) {
if ($newsUser && $newsItem) {
$newsItem = AddSlashes ($newsItem);
$query = "UPDATE news_main SET n_user='$newsUser', n_news='$newsItem' WHERE n_id='$newsID'";
if ($result = mysql_db_query (sqlDB, $query, $conn)) {
if ($numRows = mysql_affected_rows ($conn)) {
echo 'Your modifications have been processed successfully.';
} else {
echo '
Your modifications were correctly formed, but had no effect on the database.';
}
} else {
echo "
There was an error in your input. If you don't know what it is, I'm not going to tell you.";
}
} else {
$query = "SELECT n_id, n_date, n_user, n_news FROM news_main "
. "WHERE n_id=$newsID";
$result = mysql_db_query (sqlDB, $query, $conn);
if ($result) {
$numRows = mysql_num_rows ($result);
if ($numRows == 1) {
$news = mysql_fetch_array ($result);
newsEntryEditor ($news);
} else {
echo "
MOOOOO! Rows = $numRows";
}
} else {
echo "
MOOOOO! No result.";
}
}
} else {?>
Edit News
$query = 'SELECT n_id, n_date, n_user, n_news FROM news_main' .
' ORDER BY n_date DESC';
if ($result = mysql_db_query (sqlDB, $query, $conn)) {
if ($numRows = mysql_num_rows ($result)) {?>
ID |
Date |
User |
Text |
for ($i = 0; $i < $numRows; $i++) {
$news[$i] = mysql_fetch_array ($result);
echo newsEntrySummary ($news[$i]);
}
} else {
}
} else {
}
tableFooter ();
?>
}
} else {
echo 'You suck, butthead.';
}
?>
require siteHome . "/parts/postamble.php"; // Finish this sucker up
?>