Commit b9890f9c authored by Leigh B. Stoller's avatar Leigh B. Stoller

Add "archive" flag to webnews table. Change web interface to allow

archive (and restore) of news items. Add button at top to toggle
the display of archived items. All of this is admin mode only; mere users
see just the news.
parent 5a086ddf
...@@ -2027,6 +2027,8 @@ CREATE TABLE webnews ( ...@@ -2027,6 +2027,8 @@ CREATE TABLE webnews (
date datetime default NULL, date datetime default NULL,
author varchar(32) default NULL, author varchar(32) default NULL,
body text, body text,
archived tinyint(1) default '0',
archived_date datetime default NULL,
PRIMARY KEY (msgid), PRIMARY KEY (msgid),
KEY date (date) KEY date (date)
) TYPE=MyISAM; ) TYPE=MyISAM;
......
...@@ -2117,6 +2117,10 @@ last_net_act,last_cpu_act,last_ext_act); ...@@ -2117,6 +2117,10 @@ last_net_act,last_cpu_act,last_ext_act);
PRIMARY KEY (pid,eid,inner_id) PRIMARY KEY (pid,eid,inner_id)
) TYPE=MyISAM; ) TYPE=MyISAM;
1.272: Add "archived" flag to webnews table for hiding entries.
alter table webnews add archived tinyint(1) NOT NULL \
default '0' after body;
alter table webnews add archived_date datetime default NULL \
after archived;
...@@ -7,15 +7,18 @@ ...@@ -7,15 +7,18 @@
include("defs.php3"); include("defs.php3");
# #
# Standard Testbed Header # Standard Testbed Header is sent below.
# #
PAGEHEADER("News");
# #
# If user is an admin, present edit options. # If user is an admin, present edit options.
# #
$uid = GETLOGIN(); $uid = GETLOGIN();
if (! isset($show_archived)) {
$show_archived = 0;
}
$show_archived = ($show_archived ? 1 : 0);
if ($uid) { if ($uid) {
$isadmin = ISADMIN($uid); $isadmin = ISADMIN($uid);
} else { } else {
...@@ -23,6 +26,35 @@ if ($uid) { ...@@ -23,6 +26,35 @@ if ($uid) {
} }
if ($isadmin) { if ($isadmin) {
if (isset($deletec)) {
$safeid = addslashes($deletec);
DBQueryFatal("DELETE FROM webnews WHERE msgid='$safeid'");
header("Location: news.php3?show_archived=$show_archived");
return;
}
if (isset($archive)) {
$safeid = addslashes($archive);
DBQueryFatal("update webnews set archived=1,archived_date=now() ".
"where msgid='$safeid'");
header("Location: news.php3?show_archived=$show_archived");
return;
}
if (isset($restore)) {
$safeid = addslashes($restore);
DBQueryFatal("update webnews set archived=0,archived_date=NULL ".
"where msgid='$safeid'");
header("Location: news.php3?show_archived=$show_archived");
return;
}
PAGEHEADER("News");
if (isset($delete)) { if (isset($delete)) {
$delete = addslashes($delete); $delete = addslashes($delete);
echo "<center>"; echo "<center>";
...@@ -37,17 +69,6 @@ if ($isadmin) { ...@@ -37,17 +69,6 @@ if ($isadmin) {
die(""); die("");
} }
if (isset($deletec)) {
$deleteConf = addslashes($deletec);
DBQueryFatal("DELETE FROM webnews WHERE msgid='$deletec'");
echo "<h2>Deleted message.</h2>";
echo "<h3><a href='news.php3'>Back to news</a></h3>";
PAGEFOOTER();
die("");
}
if (isset($add)) { if (isset($add)) {
if (!isset($subject) || !strcmp($subject,"") ) { if (!isset($subject) || !strcmp($subject,"") ) {
# USERERROR("No subject!",1); # USERERROR("No subject!",1);
...@@ -182,7 +203,9 @@ if ($isadmin) { ...@@ -182,7 +203,9 @@ if ($isadmin) {
echo "<button name='addnew'>Add a new message</button>\n"; echo "<button name='addnew'>Add a new message</button>\n";
echo "</form>"; echo "</form>";
} }
}
else {
PAGEHEADER("News");
} }
?> ?>
...@@ -195,11 +218,27 @@ if ($isadmin) { ...@@ -195,11 +218,27 @@ if ($isadmin) {
<br /> <br />
<?php <?php
# Allow admin caller to flip the archive bit.
$show_archive_clause = "where archived=0";
if ($isadmin) {
if ($show_archived) {
$show_archive_clause = "";
echo "<a href='news.php3?show_archived=0'>Hide Archived Messages</a>\n";
}
else {
echo "<a href='news.php3?show_archived=1'>Show Archived Messages</a>\n";
}
}
$query_result= $query_result=
DBQueryFatal("SELECT subject, author, body, msgid, ". DBQueryFatal("SELECT subject, author, body, msgid, ".
"DATE_FORMAT(date,'%W, %M %e, %Y, %l:%i%p') as prettydate, ". "DATE_FORMAT(date,'%W, %M %e, %Y, %l:%i%p') as prettydate, ".
"(TO_DAYS(NOW()) - TO_DAYS(date)) as age ". "(TO_DAYS(NOW()) - TO_DAYS(date)) as age, ".
"archived, ".
"DATE_FORMAT(archived_date,'%W, %M %e, %Y, %l:%i%p') as ".
" archived_date ".
"FROM webnews ". "FROM webnews ".
"$show_archive_clause ".
"ORDER BY date DESC" ); "ORDER BY date DESC" );
if (!mysql_num_rows($query_result)) { if (!mysql_num_rows($query_result)) {
...@@ -208,6 +247,7 @@ if (!mysql_num_rows($query_result)) { ...@@ -208,6 +247,7 @@ if (!mysql_num_rows($query_result)) {
if ($isadmin) { if ($isadmin) {
echo "<form action='news.php3' method='post'>"; echo "<form action='news.php3' method='post'>";
echo "<input type='hidden' name=show_archived value='$show_archived'>";
} }
while ($row = mysql_fetch_array($query_result)) { while ($row = mysql_fetch_array($query_result)) {
...@@ -217,6 +257,8 @@ if (!mysql_num_rows($query_result)) { ...@@ -217,6 +257,8 @@ if (!mysql_num_rows($query_result)) {
$body = $row[body]; $body = $row[body];
$msgid = $row[msgid]; $msgid = $row[msgid];
$age = $row[age]; $age = $row[age];
$archived = $row[archived];
$archived_date = $row[archived_date];
echo "<a name=\"$msgid\" />\n"; echo "<a name=\"$msgid\" />\n";
echo "<table class='nogrid' echo "<table class='nogrid'
...@@ -233,6 +275,9 @@ if (!mysql_num_rows($query_result)) { ...@@ -233,6 +275,9 @@ if (!mysql_num_rows($query_result)) {
echo "</th></tr>\n". echo "</th></tr>\n".
"<tr><td style='padding: 4px; padding-top: 2px;'><font size=-1>"; "<tr><td style='padding: 4px; padding-top: 2px;'><font size=-1>";
echo "<b>$date</b>; posted by <b>$author</b>."; echo "<b>$date</b>; posted by <b>$author</b>.";
if ($archived) {
echo "<font color=red> Archived on <b>$archived_date</b></font>.\n";
}
if ($isadmin) { if ($isadmin) {
echo " (Message <b>#$msgid</b>)"; echo " (Message <b>#$msgid</b>)";
...@@ -245,8 +290,14 @@ if (!mysql_num_rows($query_result)) { ...@@ -245,8 +290,14 @@ if (!mysql_num_rows($query_result)) {
echo "<button name='edit' value='$msgid'>". echo "<button name='edit' value='$msgid'>".
"Edit</button>". "Edit</button>".
"<button name='delete' value='$msgid'>". "<button name='delete' value='$msgid'>".
"Delete</button>\n"; "Delete</button>";
echo "</td></tr>"; if ($archived)
echo "<button name='restore' value='$msgid'>".
"Restore</button>";
else
echo "<button name='archive' value='$msgid'>".
"Archive</button>";
echo "</td></tr>\n";
} }
echo "<tr><td style='padding: 4px; padding-top: 2px;'>". echo "<tr><td style='padding: 4px; padding-top: 2px;'>".
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment