<?php
/* +--------------------------------------------------------------
| PHPFreeNews - News Headlines on your website |
| Developed by Jim Willsher. |
| http://www.phpfreenews.co.uk |
+-------------------------------------------------------------+
*/
if (! defined('IN_PHPFN'))
die('Illegal attempt to access script directly!');
// Retrieve the "new" flags
$NewArchived = (isset($_POST['NewArchived']) ? $_POST['NewArchived'] : 'N/C');
$NewVisible = (isset($_POST['NewVisible']) ? $_POST['NewVisible'] : 'N/C');
$NewSticky = (isset($_POST['NewSticky']) ? $_POST['NewSticky'] : 'N/C');
$NewApproved = (isset($_POST['NewApproved']) ? $_POST['NewApproved'] : 'N/C');
$NewCatAction = (isset($_POST['NewCatAction']) ? $_POST['NewCatAction'] : 'N/C');
$NewCatID = (isset($_POST['NewCatID']) ? $_POST['NewCatID'] : '-');
$NewTemplateID = (isset($_POST['NewTemplateID']) ? $_POST['NewTemplateID'] : 'N/C');
$NewAuthor = (isset($_POST['NewAuthor']) ? $_POST['NewAuthor'] : 'N/C');
// Form Submitted?
if (isset($_POST['NumItems']))
{
$ArticlesToUpdate = array();
// Process all the elements
$NumItems = $_POST['NumItems'];
for ($i=1; $i <= $NumItems; $i++)
if (isset($_POST['id' . $i]))
$ArticlesToUpdate[] = $_POST['id' . $i];
// Only one article? Append a dummy one (otherwise the SQL 'IN' statement is invalid)
if (count($ArticlesToUpdate) == 1)
$ArticlesToUpdate[] = -1;
// Implode into a comma-separated lists
$ArticleList = implode(",", $ArticlesToUpdate);
// If changing the attributes of articles, process these in one pass
if ($NewArchived != 'N/C' || $NewVisible != 'N/C' || $NewSticky != 'N/C' || $NewApproved != 'N/C' || $NewTemplateID != 'N/C')
{
$sql = "UPDATE news_posts SET ID=ID";
if ($NewArchived != 'N/C')
$sql .= ", Archived = '$NewArchived'";
if ($NewVisible != 'N/C')
$sql .= ", Visible = '$NewVisible'";
if ($NewSticky != 'N/C')
$sql .= ", Sticky = '$NewSticky'";
if ($NewApproved != 'N/C')
$sql .= ", Approved = '$NewApproved'";
if ($NewTemplateID != 'N/C')
$sql .= ", TemplateID = '$NewTemplateID'";
if ($NewAuthor != 'N/C')
$sql .= ", AuthorID = '$NewAuthor'";
$sql .= " WHERE ID IN ($ArticleList)";
mysql_query($sql);
}
// Copying (assigning) articles to a category?
if ($NewCatAction == 1 && $NewCatID != '-')
{
mysql_query("DELETE FROM news_postcategories WHERE CatID = '$NewCatID' AND ArticleID IN ($ArticleList)");
foreach ($ArticlesToUpdate as $Key=> $ArticleID)
mysql_query("INSERT INTO news_postcategories SET ArticleID = '$ArticleID', CatID = '$NewCatID'");
}
// Removing articles from a category?
if ($NewCatAction == 2 && $NewCatID != '-')
mysql_query("DELETE FROM news_postcategories WHERE ArticleID IN ($ArticleList) AND CatID = '$NewCatID'");
$_SESSION['Info'] = 'The articles you selected have now been updated according to your requirements.';
}
// If specified, store into the session the restriction-information
SetAdminCurrentRestrictions();
$RestrictCatId = $_SESSION['RestrictCategory'];
$Archived = $_SESSION['RestrictArchived'];
$Visible = $_SESSION['RestrictVisible'];
$Sticky = $_SESSION['RestrictSticky'];
$Author = $_SESSION['RestrictAuthor'];
$PerPage = $_SESSION['PerPage'];
$ShowPage = isset($_REQUEST['ShowPage']) ? $_REQUEST['ShowPage'] : 1;
// Determine the number of records in the file, and work out the number of pages
$Query = "SELECT DISTINCT news_posts.* FROM news_posts";
// Apply any category-restriction
$Query .= ApplyAdminCategoryRestriction($RestrictCatId);
// Always restrict by Locked criteria
$Query .= " AND Locked='0'";
// Restrict by Archived?
if ($Archived != '-')
$Query .= ' AND Archived=' . $Archived;
// Restrict by Visible?
if ($Visible != '-')
$Query .= ' AND Visible=' . $Visible;
// Restrict by Sticky?
if ($Sticky != '-')
$Query .= ' AND Sticky=' . $Sticky;
// Restrict by Author?
if ($Author != '-')
$Query .= ' AND AuthorID=' . $Author;
// Now obtain the record count
$ResultSet = mysql_query($Query) or die("Query failed : " . mysql_error());
$NumRecords = mysql_num_rows($ResultSet);
$RecStart = $PerPage * ($ShowPage-1);
$PageNavBar = ConstructPagingBar($_SERVER['PHP_SELF'].'?action=Mass', $NumRecords, $PerPage, $ShowPage, $RecStart, $AdminPageBarEntries, '', '');
DisplayGroupHeading("Mass Maintenance");
?>
<div><b>NB: Any changes made on this screen will NOT be reflected in the Audit functionality.</b></div>
<br />
<table class="Admin">
<tr>
<td class="FieldPrompt">
<form name="filter" action="<?=$AdminScript?>?action=Mass" method="post">
Per Page <?= BuildPerPageDropdown('PerPage', $PerPage, true) ?>
Cat. <?= BuildCategoryDropdown('RestrictCatId', $RestrictCatId, false, true, true) ?>
State <?= BuildArchivedDropdown('Archived', $Archived, true) ?>
Vis. <?= BuildVisibleDropdown('Visible', $Visible, true) ?>
Sticky <?= BuildStickyDropdown('Sticky', $Sticky, true) ?>
Author <?= BuildAuthorDropdown('Author', $Author, true) ?>
<input class="but" type="submit" name="submit" value="Filter" />
</form>
</td>
</tr>
</table>
<?php DisplayInfoMessage(); ?>
<br />
<table class="Admin">
<tr>
<td>
<form name="mass" action="<?=$AdminScript?>?action=Mass" method="post" onsubmit="return ConfirmMassAction(document.mass, 'NumItems', 'id')" >
<table cellpadding="1">
<?php
// Apply any limits, and perform the search
$i=0;
$Query .= " LIMIT $RecStart, $PerPage";
$ResultSet = mysql_query($Query);
while ($row = mysql_fetch_array($ResultSet))
{
$i++;
$ArticleID = $row['ID'];
$ShowDateString = date($NewsDisplay_DateFormat, strtotime($row['PostDateTime'])) . ' ' . date($NewsDisplay_TimeFormat, strtotime($row['PostDateTime']));
?>
<tr>
<td>
<input type="checkbox" name="id<?=$i?>" value="<?=$ArticleID?>" />
</td>
<td>
<?=$row['Headline']?><br />
<div class="NewsListDateTime"><?= $ShowDateString ?></div>
</td>
</tr>
<?php
}
?>
<tr>
<td colspan="2">
<div align="center">
<?= $PageNavBar ?>
</div>
</td>
</tr>
<tr>
<td colspan="2">
<hr />
<b>New Attributes</b><br /><br />
State <?= BuildArchivedDropdown('NewArchived', $NewArchived, false, true) ?>
Vis. <?= BuildVisibleDropdown('NewVisible', $NewVisible, false, true) ?>
Sticky <?= BuildStickyDropdown('NewSticky', $NewSticky, false, true) ?>
Approved <?= BuildApprovedDropdown('NewApproved', $NewApproved, false, true) ?>
<br />
Category <?= BuildCopyMoveDropdown('NewCatAction', $NewCatAction, true) ?>
<?= BuildCategoryDropdown('NewCatID', $NewCatID, true) ?>
Template <?= BuildTemplateDropdown('NewTemplateID', $NewTemplateID, false, false, true) ?>
Author <?= BuildAuthorDropdown('NewAuthor', $NewAuthor, false, true) ?>
</td>
</tr>
<tr>
<td colspan="2">
<br />
<input type="hidden" name="NumItems" value="<?=$i?>" />
<input class="but" type="button" name="SelectAll" value="Select All" onclick="SelectAllBoxes(document.mass, 'NumItems', 'id')" />
<input class="but" type="button" name="DeSelectAll" value="De-Select All" onclick="DeSelectAllBoxes(document.mass, 'NumItems', 'id')" />
<input class="but" type="submit" name="submit" value="Apply"/>
</td>
</tr>
</table>
</form>
</td>
</tr>
</table>