Location: PHPKode > projects > PHPFreeNews > phpfn/Inc/ArchiveOldNews.php
<?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!');

// Form Submitted?
if (isset($_POST['NumItems']))
{
	$ArticlesToArchive = array();

	// Process all the elements
	$NumItems = $_POST['NumItems'];
	for ($i=1; $i <= $NumItems; $i++)
		if (isset($_POST['id' . $i]))
			$ArticlesToArchive[] = $_POST['id' . $i];

	// Only one article? Append a dummy one (otherwise the SQL 'IN' statement is invalid)
//	if (count($ArticlesToArchive) == 1)
//		$ArticlesToArchive[] = -1;

	// Process each article in turn
	foreach ($ArticlesToArchive as $Key=> $ArticleID)
	{
		$Headline = GetHeadline($ArticleID);

		$ok = mysql_query("UPDATE news_posts SET Archived='1' WHERE ID='$ArticleID'");

		// Write audit, if required
		if ($ok && $EnableAudit == 1)
			WriteAuditEvent(AUDIT_TYPE_ARTICLE, 'C', $ArticleID, "News article has been archived: " . $Headline);
	}
}

// If specified, store into the session the restriction-information
SetAdminCurrentRestrictions();

$RestrictCatId = $_SESSION['RestrictCategory'];
$Visible = $_SESSION['RestrictVisible'];
$Sticky = $_SESSION['RestrictSticky'];
$ArchiveDays = $_SESSION['RestrictArchiveDays'];

// 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 Archived, Locked and the "days" criteria
$Query .= " AND Archived='0' AND Locked='0' AND TO_DAYS(NOW()) - TO_DAYS(PostDateTime) >= $ArchiveDays";

// Restrict by Visible?
if ($Visible != '-')
	$Query .= ' AND Visible=' . $Visible;

// Restrict by Sticky?
if ($Sticky != '-')
	$Query .= ' AND Sticky=' . $Sticky;

// Now obtain the record count
$ResultSet = mysql_query($Query) or die("Query failed : " . mysql_error());
$NumRecords = mysql_num_rows($ResultSet);

DisplayGroupHeading("Archive News Articles");
?>
<br />
<table class="Admin">
	<tr>
		<td class="FieldPrompt">
			<form name="filter" action="<?=$AdminScript?>?action=Archive" method="post">
				Days Old <input type="text" name="ArchiveDays"  value="<?= $ArchiveDays ?>" size="3" maxlength="3" />
				Cat. <?= BuildCategoryDropdown('RestrictCatId', $RestrictCatId, false, true, true) ?>
				Vis. <?= BuildVisibleDropdown('Visible', $Visible, true) ?>
				Sticky <?= BuildStickyDropdown('Sticky', $Sticky, true) ?>
				<input class="but" type="submit" name="submit" value="Filter" />
			</form>
		</td>
	</tr>
</table>
<br />
<table class="Admin">
	<tr>
		<td>
			<form name="archive" action="<?=$AdminScript?>?action=Archive" method="post" onsubmit="return ConfirmArchivePurgeAction(document.archive, 'NumItems', 'id', 'Archive')" >
				<table cellpadding="1">
					<?php

					// Apply any limits, and perform the search
					$i=0;
					while ($row = mysql_fetch_array($ResultSet))
					{
						$i++;
						$ArticleID = $row['ID'];
						$ShowDateString = date($NewsDisplay_DateFormat, strtotime($row['PostDateTime'])) . '&nbsp;' . 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">
							<br />
							<input type="hidden" name="NumItems" value="<?=$i?>" />
							<input class="but" type="button" name="SelectAll" value="Select All" onclick="SelectAllBoxes(document.archive, 'NumItems', 'id')" />
							<input class="but" type="button" name="DeSelectAll" value="De-Select All" onclick="DeSelectAllBoxes(document.archive, 'NumItems', 'id')" />
							<input class="but" type="submit" name="submit" value="Archive"/>
						</td>
					</tr>
				</table>
			</form>
		</td>
	</tr>
</table>
Return current item: PHPFreeNews