# News Categories Addon
# version 2.0 (enhanced) build 3
# by plushpuffin and wrestlingg@mer
# email: plushpuffin@yahoo.com and wrestlinggamer@houston.rr.com
#
push(@Addons_Loaded, 'News Categories 2.0b3');
push(@Addons_DisplaySubForm, 'NewsCatSubForm');
push(@Addons_PageHandler, 'NewsCatPageHandler');
push(@Addons_BuildNews_Post, 'NewsCatBuild');
push(@Addons_MainPage, 'NewsCat_MainPage');
push(@Addons_NPHTMLFoot, 'NewsCat_HTMLFoot');
push(@Addons_RemoveNews2, 'NewsCatRemoveNews2');
push(@Addons_RemoveNewsSave, 'NewsCatRemoveNewsSave');
push(@Addons_SaveNews_3, 'NewsCatSubmitSaveBuild');
push(@Addons_RemoveNewsSave_2, 'NewsCatRemoveNewsSaveBuild');
$Addons_List{'News Categories 2.0b3'} = ['npa_newscat2.pl',
q~Manages different categories and news files (profiles) from one copy of NewsPro. enhanced by <a href="mailto:plushpuffin@yahoo.com">plushpuffin</a> - <b><a href="http://plushpuffin.virtualave.net">plushpuffin's addon garden</a></b>~,''];
$filext = $NPConfig{'ArcHtmlExt'};

sub NewsCatBuild {
	&NewsCatLoadConfig;
	foreach $i (sort keys %newsprofiles) {
		if ($newsprofiles{$i}->[0]) {
			unless($newsprofiles{$i}->[16] && $newsprofiles{$i}->[12]) {
				&BuildProfile;
			}
		}
	}
}

sub NewsCatTotalReBuild {
	&NewsCatLoadConfig;
	&loadND;
	require $ndisplaypl;
	foreach $i (sort keys %newsprofiles) {
		if ($newsprofiles{$i}->[0]) {
			&BuildProfile;
		}
	}
}

sub NewsCatBuildStatic {
	&NewsCatLoadConfig;
	require $ndisplaypl;
	foreach $i (sort keys %newsprofiles) {
		if ($newsprofiles{$i}->[0] && $newsprofiles{$i}->[12] && $newsprofiles{$i}->[16]) {
			&BuildProfile;
		}
	}
}

sub NewsCatSubmitSaveBuild {
	if ($newsktalk) {
		$ktalkURL = $snid;
		$ktalkURL =~ s/[^\d\,]//g;
		$ktalkURL = "$talkbaseURL/$ktalkURL$talkext";
		$ktalknum = 0;
	}
	else {
		$ktalkURL = '';
		$ktalknum = 0;
	}
	local @NewsData;
	local $newsid = $snid;
	&SubmitFormFields;
	my @ffields = @formfields;
	push(@ffields, @ffield_add);
	foreach (@ffields) {
		$NewsData[0]->{$_} = ${$_};
	}
	&NewsCatBuildStatic;
}

sub NewsCatRemoveNewsSaveBuild {
	NewsCatRNSB2( \@NewsData );
}

sub NewsCatRNSB2 {
	my $reff = shift;
	my( $key, $val );
	local @NewsData;
	while( ($key,$val) = each(%ChangedItems) ) {
		if( $val ) {
			push( @NewsData, $$reff[$key] );
		}
	}
	&NewsCatBuildStatic;
}

sub BuildProfile {
	$prof = $newsprofiles{$i};
	# Filter by category and date.
	my $filtsub;
	if ($prof->[8]) {$filtsub = $prof->[8];}
	else {$filtsub = 'NewsCatFilter';}
	@FilteredND = &$filtsub(split(/\!/, $prof->[2]), $prof->[3]);
	# Filter by maximum number.
	if (@FilteredND > $prof->[4] || $prof->[11]) {
		my $maxnum = $#FilteredND - $prof->[11];
		my $minnum = $maxnum - $prof->[4];
		$minnum++;
		$minnum = $minnum < 0 ? 0 : $minnum;
		@FilteredND = @FilteredND[$minnum..$maxnum];
	}
	# Filtered! Build news.
	$newsnum = $#FilteredND;
	$content = '';
	my( $ff, $content );
	if( $prof->[12] eq 'split' ) {
		my( @stattext, @statsubs, @stattmpl, @statfile, $statfile, $statsubs, $stattmpl, $statnum, $statmax, $filebase );
		@statsubs = ();
		push( @statsubs, $prof->[5] ) if( $prof->[5] );
		@stattmpl = ();
		push( @stattmpl, $prof->[6] ) if( $prof->[6] );
		@_ = split( /;*\s*;\s*;*/, $prof->[14] );
		foreach (@_) {
			push( @stattmpl, $_ ) if( $_ );
		}
		@_ = split( /;*\s*;\s*;*/, $prof->[15] );
		foreach (@_) {
			push( @statsubs, $_ ) if( $_ );
		}
		while ($newsnum >= 0) {
			foreach $ff (keys %{$FilteredND[$newsnum]}) {
				${$ff} = $FilteredND[$newsnum]->{$ff};
			}
			$newsdate = &GetTheDate($newstime);
			@stattext = split( /<pr>/i, $newstext );
			$statmax = scalar @stattext;
			@statfile = ( &NCMakeFName );
			$filebase = &NCMakePartialFName;
			for( $_ = 2; $_ <= @stattext; $_++ ) {
				$statfile[$_-1] = "$filebase$_.$filext";
			}
			for( $statnum = 0; $statnum < $statmax; $statnum++ ) {
				$newstext = $stattext[$statnum];
				$FileName = $statfile[$statnum];
				$statsubs = $statsubs[$statnum] || $statsubs[$#statsubs];
				$stattmpl = $stattmpl[$statnum] || $stattmpl[$#stattmpl];
				$prevhref = $statnum ? $statfile[$statnum-1] : '';
				$nexthref = $statnum < $statmax ? $statfile[$statnum+1] : '';
				&{$statsubs};
				NPopen(NCFILE, ">$prof->[9]/$FileName");
				if( $stattmpl ) {
					print NCFILE ProcessTMPL("$NPConfig{'admin_path'}/$stattmpl",$newshtml,$newssubject);
				}
				else {
					print NCFILE $newshtml;
				}
				close(NCFILE);
			}
			$newsnum--;
		}
	}
	elsif( $prof->[12] eq 'static' ) {
		my( $statfile );
		while ($newsnum >= 0) {
			foreach $ff (keys %{$FilteredND[$newsnum]}) {
				${$ff} = $FilteredND[$newsnum]->{$ff};
			}
			$newsdate = &GetTheDate($newstime);
			$FileName = &NCMakeFName;
			&{$prof->[5]};
			$content .= $newshtml;
			NPopen(NCFILE, ">$prof->[9]/$FileName");
			if( $prof->[6] ) {
				print NCFILE ProcessTMPL("$NPConfig{'admin_path'}/$prof->[6]",$newshtml,$newssubject);
			}
			else {
				print NCFILE $newshtml;
			}
			close(NCFILE);
			$newsnum--;
		}
	}
	else {
		$FileName = $prof->[1];
		while ($newsnum >= 0) {
			foreach $ff (keys %{$FilteredND[$newsnum]}) {
				${$ff} = $FilteredND[$newsnum]->{$ff};
			}
			$newsdate = &GetTheDate($newstime);
			&{$prof->[5]};
			if ($prof->[10]) {$content .= qq~<a name="newsitem$newsid"></a>~;}
			$content .= $newshtml;
			$newsnum--;
		}
		# News built. Now open the text file.
		NPopen(NCFILE, ">$prof->[9]/$prof->[1]");
		print NCFILE $content;
		close(NCFILE);
		# Done. Now generate HTML.
		if ($prof->[6]) {
			my $htmlfilename;
			if ($prof->[1] =~ /(.+)\./) {
				$htmlfilename = $1;
			} else {
				$htmlfilename = $prof->[1];
			}
			$htmlfilename .= ".$NPConfig{'ArcHtmlExt'}";
			NPopen(NCFILE, ">$prof->[9]/$htmlfilename");
			print NCFILE ProcessTMPL("$NPConfig{'admin_path'}/$prof->[6]",$content,$prof->[7]);
			close(NCFILE);
		}
	}

}

sub NewsCatSubForm {
	push(@formfields, 'newscat');
	$FormFieldsName{'newscat'} = "News Category";
	my @NCats = split(/\|x\|/, $NPConfig{'NewsCategories'});
	$FormFieldsCustom{'newscat'} = q~<select name="newscat">
	<option value="" selected>(default)</option>~;
	my $ncat;
	foreach $ncat (sort @NCats) {
		$FormFieldsCustom{'newscat'} .= qq~
		<option value="$ncat">$ncat</option>~;
	}
	$FormFieldsCustom{'newscat'} .= q~
	</select>~;
}

sub NewsCatSaveProf {
	my $prof = $in{'editprofsave'};
	@{$newsprofiles{$prof}} = ($newsprofiles{$prof}->[0], $in{'textfile'}, join('!', split(/\|x\|/, $in{'newscategories'})),
	$in{'maxage'}, $in{'maxnum'}, $in{'newssub'}, $in{'tmplfile'}, $in{'tmpltitle'}, $in{'filtsub'}, $in{'filepath'},
	$in{'anchors'},$in{'skipnum'},$in{'staticopt'},$in{'staticname'},$in{'statictmpls'},$in{'staticsubs'},$in{'autobuildstatic'});
	&NewsCatSaveConfig;
}

sub NewsCatEditProf {
	my %koption;
	my $prof = $in{'profname'};
	my @selectedcats = split(/\!/, $newsprofiles{$prof}->[2]);
	my (%selectedcats,$option1,$option2);
	foreach $i (@selectedcats) {
		$selectedcats{$i} = 'selected';
	}
	&NPHTMLHead("Edit profile $prof");
	$_ = 2 + scalar @newscategories;
	$_ = $_ < 15 ? $_ : 15;
	print qq~
	<form action="$scripturl?newscat" method="POST">
	<input type="hidden" name="editprofsave" value="$prof">
	Name of generated text file (i.e. $prof.txt): <input type="text" name="textfile" value="$newsprofiles{$prof}->[1]"><br><br>
	Absolute path of directory in which files will be created, with no trailing slash (i.e. $NPConfig{'htmlfile_path'}): <input type="text" name="filepath" value="$newsprofiles{$prof}->[9]" size="60"><br><br>
	
	<table width="80%" border="0"><tr><td valign="top">Include only news from categories: (multiple selections allowed)
	<br><br>To make multiple selections: Windows users hold down CTRL, Mac users hold down Option, most UNIX users hold down CTRL, users of other operating systems see your browser's help.
	</td><td>
	<select name="newscategories" size="$_" multiple>
	<option value="AllCategories" $selectedcats{'AllCategories'}>(All Categories)</option>
	<option value="(default)" $selectedcats{'(default)'}>(Default Category)</option>
	~;
	foreach $i (@newscategories) {
		print qq~
		<option value="$i" $selectedcats{$i}>$i</option>~;
	}
	$option1 = $newsprofiles{$prof}->[10] ? ' selected' : '';
	$option2 = $newsprofiles{$prof}->[10] ? '' : ' selected';
	print qq~
	</select></td></tr></table><br><br>
	Do not include news older than <input type="text" name="maxage" value="$newsprofiles{$prof}->[3]">
	days (to disable filtering by date, enter a large number 10000).<br><br>
	Include a maximum of <input type="text" name="maxnum" value="$newsprofiles{$prof}->[4]">
	news items (to disable filtering by item number, enter a large number like 10000).<br><br>
	Skip first <input type="text" name="skipnum" value="$newsprofiles{$prof}->[11]">
	news items after filtering. (to disable, enter a value of 0).<br><br>
	EXPERT USERS ONLY! \@NewsData filtering sub. Most users should leave this blank. <input type="text" name="filtsub" value="$newsprofiles{$prof}->[8]"><br><br>
	Generate news using ndisplay.pl subroutine <input type="text" name="newssub" value="$newsprofiles{$prof}->[5]">
	(i.e. DoNewsHTML for the general news style, DoHeadlineHTML for headlines).<br><br>
	Generate HTML file using .tmpl file  <input type="text" name="tmplfile" value="$newsprofiles{$prof}->[6]">
	located in your NewsPro directory (to disable HTML file creation, leave blank).<br>
	If generating HTML file, enter page title: <input type="text" name="tmpltitle" value="$newsprofiles{$prof}->[7]"><br>
	Create &lt;a name&gt; tags with news? Unless you're going to be including more than one news file on a single HTML page, you should leave this on.
	<select name="anchors"><option value="1"$option1>Yes</option><option value="0"$option2>No</option></select>
	<BR><BR><table border="1" cellspacing="2" cellpadding="2" align="center">
	<tr><td align="center"><h3>Static Page Options</h3></td></tr>
	~;
	%koption = ();
	$koption{$newsprofiles{$prof}->[12]} = ' selected';
	print qq~
	<tr><td>Static page options.
	<select name="staticopt">
		<option value=""$koption{''}>no static pages (normal)</option>
		<option value="static"$koption{'static'}>static pages</option>
		<option value="split"$koption{'split'}>split static pages at &lt;PR&gt; tags</option>
	</select><BR>
	~;
	print q~
	<ul>If you choose &quot;split static pages at &lt;PR&gt; tags&quot;...<BR>
	<li>Put the tag &lt;PR&gt; (uppercase or lowercase - it doesn't matter) in your news text.<BR>
	Your news will be split at the exact locations of these tags into several files.</li>
	<li>you can refer to the previous and next page in your DoNews subroutine with $prevhref and $nexthref.<BR>
	$prevhref will be blank on the first page, and $nexthref will be blank on the last page.</li>
	<li>The current file name can be accessed using the variable $FileName.</li>
	</ul></td></tr>
	~;

	&SubmitFormFields;
	push(@formfields, 'newsid', 'newstime', 'newsrand');
	my @selectedfields = split(/\|x\|/, $newsprofiles{$prof}->[13]);
	my (%bannedfields, %selectedfields );
	my @bannedfields = split(/\|x\|/, $NPConfig{'NCbannedFF'});
	my %bannedfields;
	foreach $i (@bannedfields) {
		$bannedfields{$i} = 1;
	}
	foreach $i (@selectedfields) {
		$selectedfields{$i} = ' selected';
	}
	$bannedfields{'newsname'} = 1;
	$bannedfields{'newsdate'} = 1;
	$bannedfields{'newscat'} = 1;
	print qq~<tr><td>Select the field to use when generating the static page's file name:
	<select name="staticname">
	~;
	foreach $i (@formfields) {
		if( $bannedfields{$i} && ! $selectedfields{$i} ) { next; }
		print qq~
		<option value="$i"$selectedfields{$i}>$i</option>~;
	}
	$option1 = $newsprofiles{$prof}->[16] ? ' selected' : '';
	$option2 = $newsprofiles{$prof}->[16] ? '' : ' selected';
	print qq~
	</select>
	(only relevant when creating each news item on its own page, or when linking to static pages from another profile)
	</td></tr>
	<tr><td>
	Auto-rebuild static pages when news is submitted or modified?
	<select name="autobuildstatic"><option value="1"$option1>Yes</option><option value="0"$option2>No</option></select>
	This will only rebuild/create static pages that <i><b>need</b></i> to be rebuilt/created. Very efficient, highly recommended.
	Please note that if this option is set to &quot;Yes&quot;, and you manually delete static pages or whatever, you
	must then force a total rebuild in order to recreate the pages. Essentially, setting this option will cause this
	static-page-profile to rebuild on submit-save/modify-save and NOT during Build News. If this option is set to
	&quot;No&quot;, then this profile will build normally.
	</td></tr>
	~;

	print qq~
	<tr><td><h4>for use with split-static-pages only : Template-Per-Page</h4>
	<ul>If you like, you can specify a different template to use for every page.
		<li>The default template for this profile will be used for the first page.</li>
		<li>In the following text field you should list the templates you wish to use for every subsequent page.</li>
		<li>Separate the file names with semicolons.</li>
		<li>If a news item has more pages than templates, the last template listed will be used for the remaining pages.</li>
	</ul>
	<input type="text" name="statictmpls" value="$newsprofiles{$prof}->[14]" size="70">
	</td></tr>
	<tr><td><h4>for use with split-static-pages only : Subroutine-Per-Page</h4>
	<ul>If you like, you can specify a different subroutine to use for every page.
		<li>The default subroutine for this profile will be used for the first page.</li>
		<li>In the following text field you should list the subroutines you wish to use for every subsequent page.</li>
		<li>Separate the subroutine names with semicolons.</li>
		<li>If a news item has more pages than subroutines, the last subroutine listed will be used for the remaining pages.</li>
	</ul>
	<input type="text" name="staticsubs" value="$newsprofiles{$prof}->[15]" size="70">
	</td></tr></table>
	<br><br><input type="submit" name="submit" value="Save Changes"></form>
	~;
	&NPHTMLFoot;
}

sub NewsCatFilter {
	my $mintime = pop;
	$mintime = $mintime * 86400;
	my @filtcats = @_;
	my %filtcats;
	my $nd;
	undef @NewNewsData;
	my @NewNewsData;
	foreach $i (@filtcats) {
		unless ($i eq '(default)') {
			$filtcats{$i} = 1;
		}
		else {
			$filtcats{''} = 1;
		}
	}
	foreach $nd (@NewsData) {
		# First, check if it matches the category.
		if ($filtcats{$nd->{'newscat'}} || $filtcats{'AllCategories'}) {
			# It matches. Now check the time.
			if ($nd->{'newstime'} >= (time - $mintime)) {
				# It's good. Add to the new array.
				push(@NewNewsData, $nd);
			}
		}
	}
	return @NewNewsData;
}

sub NewsCatFilterReverse {
	my @NND = reverse(&NewsCatFilter(@_));
	return @NND;
}

sub NewsCatFilterAlpha {
	my @NND = &NewsCatFilter(@_);
	my @NNDsorted = map { $_->[0] }
		sort { $b->[1] cmp $a->[1] }
		map { [ $_, ($_->{'newssubject'})[0] ] } @NND;
	return @NNDsorted;
}

sub NewsCatLoadConfig {
	@newscategories = sort(split(/\|x\|/, $NPConfig{'NewsCategories'}));
	@nprof = split(/\|x\|/, $NPConfig{'NewsProfiles'});
	for( $i = 0; $i < @nprof; $i++ ) {
		@nprof2 = split(/\~/, $nprof[$i]);
		my $j = shift(@nprof2);
		if ($j) {
		$nprof[$i] = $j;
		$newsprofiles{$j} = [];
		@{$newsprofiles{$j}} = @nprof2;
		}
	}
}

sub NewsCatSaveConfig {
	$NPConfig{'NewsCategories'} = join('|x|', @newscategories);
	my @nprof = ('');
	foreach $i (sort keys %newsprofiles) {
		push(@nprof, join('~', $i, @{$newsprofiles{$i}}));
	}
	$NPConfig{'NewsProfiles'} = join('|x|', @nprof);
	&WriteConfigInfo;
}

sub NewsCatMain {
	unless ($UserPermissions{$Cookies{'uname'}} == 3) {
		&NPdie('You are not authorized to access this');
	}
	&NewsCatLoadConfig;
	if ($in{'editprof'} && $newsprofiles{$in{'profname'}}) {
		&NewsCatEditProf;
		exit;
	}
	if ($in{'editprofsave'}) {
		&NewsCatSaveProf;
	}
	if ($in{'removecat'}) {
		my $new_newscategories;
		foreach $i (@newscategories) {
			unless ($i eq $in{'removecat'}) {
				push(@new_newscategories, $i);
			}
		}
		@newscategories = @new_newscategories;
		&NewsCatSaveConfig;
	}
	if ($in{'removeprof'}) {
		if ($newsprofiles{$in{'profname'}}) {
			delete $newsprofiles{$in{'profname'}};
		}
		&NewsCatSaveConfig;
	}
	if ($in{'addcat'}) {
		$in{'addcat'} =~ s/\W//g;
		if ($in{'addcat'} ne "") {
			push(@newscategories, $in{'addcat'});
		}
		&NewsCatSaveConfig;
	}
	if ($in{'addprof'}) {
		$in{'addprof'} =~ s/\W//g;
		unless ($newsprofiles{$in{'addprof'}} || $in{'addprof'} eq "") {
			$newsprofiles{$in{'addprof'}} = ['0', "$in{'addprof'}.txt", 'AllCategories', '10000', '100000', 'DoNewsHTML', '', '', '', $NPConfig{'htmlfile_path'},'0','0','','newssubject','','','1'];
		}
		&NewsCatSaveConfig;
	}
	if ($in{'savecheck'}) {
		foreach $i (keys %newsprofiles) {
			$newsprofiles{$i}->[0] = $in{"cc--$i"};
		}
		&NewsCatSaveConfig;
	}
	&NPHTMLHead("News Categories 2");
	print q~
	<div align="center"><h3>News Categories 2</h3><table width="80%" border="0">
	~;
	foreach $i (@newscategories) {
		print qq~
		<tr> 
		<td>$i</td>
		<td> <div align="center"> <form action="$scripturl?newscat" method="POST">
		<input type="hidden" name="removecat" value="$i">
		<input type="submit" name="Submit" value="Remove"></form>
		</div> </td> </tr>
		~;
	}
	print qq~
</table>
<b>Add new category:</b><form action="$scripturl?newscat" method="POST">
<input type="text" name="addcat" value="Name"><input type="submit" name="submit" value="Submit">
</form><hr width="75%">
	~;
	print qq~
	<h3>News Profiles 2</h3><table width="80%" border="1" cellpadding="10">
	<form action="$scripturl?newscat" method="POST">
	<tr><td valign="middle" align="center"><font size="+1">Profile Name</font></td>
	<td valign="middle" align="center" width="100">File Creation</td>
	<td valign="middle" align="center" width="150"><div align="center">Enabled / Disabled</div></td></tr>
	~;
	my( $yescheck, $noncheck );
	my @prof = sort keys %newsprofiles;
	my $psize = scalar @prof;
	foreach $i (@prof) {
		$yescheck = $newsprofiles{$i}->[0] ? ' checked' : '';
		$noncheck = $newsprofiles{$i}->[0] ? '' : ' checked';
		print qq~<tr><td valign="middle">$i</td><td width="100" align="center">~;
		print ( $newsprofiles{$i}->[0] ? q~<b>enabled</b>~ : q~<i>disabled</i>~ );
		print qq~</td><td align="center" width="150">
		<input type="radio" name="cc--$i" value="1"$yescheck> / <input type="radio" name="cc--$i" value="0"$noncheck>
		</td></tr>~;
	}
	$psize++;
	print qq~
	<tr><td colspan="9" valign="middle"><div align="center">
	<input type="submit" name="savecheck" value="Save Enable States">
	</div></td></tr></form>
	</table><br><br>
	<table width="80%" border="1" cellpadding="10" cellspacing="10"><tr><td align="left">
	<form action="$scripturl?newscat" method="POST">
	<input type="submit" name="removeprof" value="Delete Selected Profile"></td></tr><tr><td align="middle">
	<select name="profname" size="$psize"><option value="" selected>(none selected)</option>~;
	foreach $i (@prof) {
		print qq~<option value="$i">$i</option>~;
	}
	print q~</select></td></tr><tr><td align="right">
	<input type="submit" name="editprof" value="Edit Selected Profile">
	</td></tr></form></table>~;
	print qq~
	<b>Add new profile:</b><form action="$scripturl?newscat" method="POST">
	<input type="text" name="addprof" value="Name"><br><input type="submit" name="submit" value="Submit">
	</form>
	~;
	&NPHTMLFoot;
}


#	Get the current news item's file name
#	(static page file field must be set for the current profile,
#	even if that profile doesn't do static pages)
sub NCMakeFName
{
	$_ = ${$prof->[13]} || ${'newsid'};
	$_ =~ s~\W~~g;
	$_ = substr( $_, 0, 24 );
	$_ .= ".$filext";
	return $_;
}

#	Generate file name for the current newsitem,
#	using the name of the field passed in as the
#	file field.
#		eg:	GetFName( 'newssubject' )
sub NCGetFName
{
	$_ = shift || 'newsid';
	$_ = ${$_};
	$_ =~ s~\W~~g;
	$_ = substr( $_, 0, 24 );
	$_ .= ".$filext";
	return $_;
}

#	Same as MakeFName, but it doesn't put the
#	file extension at the end.
sub NCMakePartialFName
{
	$_ = ${$prof->[13]} || ${'newsid'};
	$_ =~ s~\W~~g;
	$_ = substr( $_, 0, 24 );
	return $_;
}

sub NewsCatPageHandler {
	if (query_string() eq "newscat") {
		&NewsCatMain;
		exit;
	}
	elsif (query_string() eq "newscattotalrebuild") {
		&NPHTMLHead('All Enabled Profiles ReBuilt');
		print q~All currently enabled news profiles have been totally rebuilt.~;
		&NewsCatTotalReBuild;
		&NPHTMLFoot;
		exit;
	}
}

sub NewsCatRemoveNewsSave {
	push(@formfields, 'newscat');
}

sub NewsCatRemoveNews2 {
	my @NCats = split(/\|x\|/, $NPConfig{'NewsCategories'});
	my $nci;
	print qq~ Category:
	<select name="newscat--$newsnum"><option value=""~;
	unless ($newscat) {
		print " selected";
	}
	print ">(default)</option>";
	foreach $nci (@NCats) {
		print qq~
		<option value="$nci"~;
		if ($nci eq $newscat) {
			print " selected";
		}
		print qq~>$nci</option>~;
	}
	print "</select>";
}

sub NewsCat_HTMLFoot {
	if ($up == 3) {
			print qq~ <a href="$scripturl?newscat" class="navlink">NewsCat 2</a> | <a href="$scripturl?newscattotalrebuild" class="navlink">NewsCat2_Total_Rebuild</a> |~;
	}
}
sub NewsCat_MainPage {
	if ($up == 3) {
		print qq~
		<b><a href="$scripturl?newscat">NewsCat 2</a>:</b> Configure news categories and profiles, features that allow you to create multiple news files. enhanced by <a href="mailto:plushpuffin\@yahoo.com">plushpuffin</a><br><br>
		~;
	}
}
1;