###############################################################################
# ManageBoards.pl #
###############################################################################
# YaBB: Yet another Bulletin Board #
# Open-Source Community Software for Webmasters #
# Version: YaBB 2.4 #
# Packaged: April 12, 2009 #
# Distributed by: http://www.yabbforum.com #
# =========================================================================== #
# Copyright (c) 2000-2009 YaBB (www.yabbforum.com) - All Rights Reserved. #
# Software by: The YaBB Development Team #
# with assistance from the YaBB community. #
# Sponsored by: Xnull Internet Media, Inc. - http://www.ximinc.com #
# Your source for web hosting, web design, and domains. #
###############################################################################
$manageboardsplver = 'YaBB 2.4 $Revision$';
if ($GLOBAL::ACTION eq 'detailedversion') { return 1; }
sub ManageBoards {
&is_admin_or_gmod;
&LoadBoardControl;
if ($INFO{'action'} eq 'managecats') {
$colspan = qq~colspan="2"~;
$add = $admin_txt{'47'};
$act = 'catscreen';
$manage = qq~
$admin_txt{'49'}~;
$managedescr = $admin_txt{'678'};
$act2 = 'addcat';
$action_area = 'managecats';
} else {
$colspan = qq~colspan="4"~;
$add = $admin_txt{'50'};
$act = 'boardscreen';
$manage = qq~
$admin_txt{'51'}~;
$managedescr = $admin_txt{'677'};
$act2 = 'addboard';
$action_area = 'manageboards';
}
$yymain .= qq~
~;
$yytitle = "$admintxt{'a4_title'}";
&AdminTemplate;
}
sub BoardScreen {
&is_admin_or_gmod;
$i = 0;
while ($_ = each(%FORM)) {
if ($FORM{$_} && $_ =~ /^yitem_(.+)$/) {
$editboards[$i] = $1;
$i++;
}
}
$i = 1;
foreach $thiscat (@categoryorder) {
@theboards = split(/,/, $cat{$thiscat});
for (my $z = 0; $z < @theboards; $z++) {
for (my $j = 0; $j < @editboards; $j++) {
if ($editboards[$j] eq $theboards[$z]) {
$editbrd[$i] = $theboards[$z];
$i++;
splice(@editboards,$j,1);
last;
}
}
}
}
if ($FORM{'baction'} eq "edit") { &AddBoards(@editbrd); }
elsif ($FORM{'baction'} eq "delme") {
shift(@editbrd);
foreach my $bd (@editbrd) {
# Remove Board form category it belongs to
$category = ${$uid.$bd}{'cat'};
@bdlist = split(/,/, $cat{$category});
my $c = 0;
foreach (@bdlist) {
if ($_ eq $bd) { splice(@bdlist, $c, 1); last; }
$c++;
}
$cat{$category} = join(',', &undupe(@bdlist));
delete $board{$bd};
$yymain .= qq~$admin_txt{'55'}$bd
~;
}
# Actual deleting
&DeleteBoards(@editbrd);
&Write_ForumMaster;
} else {
&fatal_error("no_action","$FORM{'baction'}");
}
$action_area = "manageboards";
&AdminTemplate;
}
sub DeleteBoards {
&is_admin_or_gmod;
my @oldcontrols = &read_DBorFILE(0,FORUMCONTROL,$boardsdir,'forum','control');
foreach $board (@_) {
@messages = &read_DBorFILE(0,'',$boardsdir,$board,'txt');
foreach $curmessage (@messages) {
my ($id, undef) = split(/\|/, $curmessage, 2);
&delete_DBorFILE("$datadir/$id.txt");
&delete_DBorFILE("$datadir/$id.mail");
&delete_DBorFILE("$datadir/$id.ctb");
&delete_DBorFILE("$datadir/$id.data");
&delete_DBorFILE("$datadir/$id.poll");
&delete_DBorFILE("$datadir/$id.polled");
}
for (my $cnt = 0; $cnt < @oldcontrols; $cnt++) {
my $oldboard;
(undef, $oldboard, undef) = split(/\|/, $oldcontrols[$cnt], 3);
$yydebug .= "$cnt $oldboard \n";
if ($oldboard eq $board) {
$oldcontrols[$cnt] = "";
$yydebug .= "\$board{\"$oldboard\"}";
delete $board{"$board"};
last;
}
}
&delete_DBorFILE("$boardsdir/$board.txt");
&delete_DBorFILE("$boardsdir/$board.ttl");
&delete_DBorFILE("$boardsdir/$board.poster");
&delete_DBorFILE("$boardsdir/$board.mail");
my @buffer = &read_DBorFILE(0,ATM,$vardir,'attachments','txt');
my ($amcurrentboard,$amfn);
for (my $a = 0; $a < @buffer; $a++) {
(undef, undef, undef, undef, $amcurrentboard, undef, undef, $amfn, undef) = split(/\|/, $buffer[$a]);
if ($amcurrentboard eq $board) {
$buffer[$a] = '';
&delete_DBorFILE("$upload_dir/$amfn");
}
}
&write_DBorFILE(0,ATM,$vardir,'attachments','txt',@buffer);
&BoardTotals("delete", $board);
}
&write_DBorFILE(0,FORUMCONTROL,$boardsdir,'forum','control',sort(grep { $_; } @oldcontrols));
}
sub AddBoards {
my @editboards = @_;
&is_admin_or_gmod;
$addtext = $admin_txt{'50'};
if ($INFO{'action'} eq 'boardscreen') { $FORM{'amount'} = $#editboards; $addtext = $admin_txt{'50a'}; }
$yymain .= qq~
~;
$yytitle = "$admin_txt{'50'}";
$action_area = "manageboards";
&AdminTemplate;
}
sub DrawPerms {
my ($permissions,$permstype) = @_;
my ($foundit, %found, $groupsel, $groupsel2, $name);
my $count = 0;
if ($permissions eq "") { $permissions = "xk8yj56ndkal"; }
my @perms = split(/, /, $permissions);
foreach $perm (@perms) {
$foundit = 0;
if ($permstype == 1) {
$name = $admin_txt{'65f'};
if ($perm eq "Topic Starter") {
$foundit = 1;
$found{$name} = 1;
$groupsel .= qq~\n~;
}
if ($count == $#perms && $found{$name} != 1) { $groupsel2 .= qq~\n~; }
}
($name, undef) = split(/\|/, $Group{"Administrator"}, 2);
if ($perm eq "Administrator") {
$foundit = 1;
$found{$name} = 1;
$groupsel .= qq~\n~;
}
if ($count == $#perms && $found{$name} != 1) { $groupsel2 .= qq~\n~; }
($name, undef) = split(/\|/, $Group{"Global Moderator"}, 2);
if ($perm eq "Global Moderator") {
$foundit = 1;
$found{$name} = 1;
$groupsel .= qq~\n~;
}
if ($count == $#perms && $found{$name} != 1) { $groupsel2 .= qq~\n~; }
if ($foundit != 1 || $count == $#perms) {
foreach (@nopostorder) {
($name, undef) = split(/\|/, $NoPost{$_}, 2);
if ($perm eq $_) {
$foundit = 1;
$found{$_} = 1;
$groupsel .= qq~\n~;
}
if ($found{$_} != 1 && $count == $#perms) { $groupsel2 .= qq~\n~; }
}
if ($foundit != 1 || $count == $#perms) {
foreach (sort { $b <=> $a } keys %Post) {
($name, undef) = split(/\|/, $Post{$_}, 2);
if ($perm eq $name) {
$foundit = 1;
$found{$name} = 1;
$groupsel .= qq~\n~;
}
if ($count == $#perms && ($found{$name} != 1 || $found{$name} eq "")) { $groupsel2 .= qq~\n~; }
}
}
}
$count++;
}
$groupsel . $groupsel2;
}
sub AddBoards2 {
&is_admin_or_gmod;
$anncount = 0;
$rbincount = 0;
my (@boardcontrol,@changes);
for (my $i = 1; $i != $FORM{'amount'} + 1; $i++) {
if ($FORM{"pic$i"} ne '' && $FORM{"pic$i"} !~ m~^[0-9a-zA-Z_\.\#\%\-\:\+\?\$\&\~\.\,\@/]+\.(gif|png|bmp|jpg)$~) { &fatal_error("invalid_picture"); }
##### Dealing with Required Info here #####
if ($FORM{"id$i"} eq '') { next; }
$id = $FORM{"id$i"};
if ($FORM{"ann$i"}) { $anncount++; }
if ($FORM{"rbin$i"}) { $rbincount++; }
&fatal_error('announcement_defined') if ($anncount > 1);
&fatal_error('recycle_bin_defined') if ($rbincount > 1);
&fatal_error('invalid_character',"$admin_txt{'61'} $admin_txt{'241'}") if ($id !~ /\A[0-9A-Za-z#%+-\.@^_]+\Z/);
if ($FORM{'screenornot'} ne "boardscreen") {
# adding a board
# make sure no board already exists with that id
&fatal_error("board_defined","$id") if (exists $board{"$id"});
my @bdlist = split(/\,/, $cat{$FORM{"cat$i"}});
push(@bdlist, "$id");
$cat{$FORM{"cat$i"}} = join(',', @bdlist);
&write_DBorFILE(0,'',$boardsdir,$id,'txt',(''));
}
if ($FORM{'screenornot'} eq "boardscreen") {
# editing a board
my $category = ${$uid.$id}{'cat'};
# move category of board
if ($category ne $FORM{"cat$i"}) {
${$uid.$id}{'cat'} = qq~$FORM{"cat$i"}~;
my @bdlist = split(/,/, $cat{$category});
# Remove Board from old Category
my $k = 0;
foreach $bd (@bdlist) {
if ($id eq $bd) { splice(@bdlist, $k, 1); }
$k++;
}
$cat{"$category"} = join(',', @bdlist);
# Add Category to new Category
my $ncat = $FORM{"cat$i"};
if ($cat{$ncat} ne "") { $cat{$ncat} .= ",$id"; }
else { $cat{$ncat} = $id; }
}
if (&checkfor_DBorFILE("$boardsdir/$id.txt")) { # fix a(nnboard) in the boardid.txt
my @boardtomodify = &read_DBorFILE(0,'',$boardsdir,$id,'txt');
my $x;
if ($FORM{"ann$i"} && (split /\|/, $boardtomodify[0])[8] !~ /a/i) {
for ($x = 0; $x < @boardtomodify; $x++) {
$boardtomodify[$x] =~ s/(.*\|)(0?)(.*)/ $1 . ($2 eq '0' ? "0a$3" : "a$3") /e;
}
} elsif (!$FORM{"ann$i"} && (split /\|/, $boardtomodify[0])[8] =~ /a/i) {
for ($x = 0; $x < @boardtomodify; $x++) {
$boardtomodify[$x] =~ s/(.*\|)(.*)/ $1 . &take_a_off($2) /e;
}
sub take_a_off { my $y = shift; $y =~ s/a//g; $y; }
}
if ($x) {
&write_DBorFILE(0,'',$boardsdir,$id,'txt',@boardtomodify);
}
}
}
$bname = $FORM{"name$i"};
&FromChars($bname);
&ToHTML($bname);
# If someone has the bright idea of starting a membergroup with a $
# We need to escape it for them, to prevent us interpreting it as a var...
$FORM{"viewperms$i"} =~ s~\$~\\\$~g;
$board{"$id"} = "$bname|$FORM{\"viewperms$i\"}|$FORM{\"show$i\"}";
$bdescription = $FORM{"description$i"};
&FromChars($bdescription);
$bdescription =~ s/\r//g;
$bdescription =~ s~\n~
~g;
if ($do_scramble_id) {
my @mods;
foreach (split(', ', $FORM{"moderators$i"})) {
push(@mods, &decloak($_));
}
$FORM{"moderators$i"} = join(', ', @mods);
}
if ($FORM{"zero$i"} eq '') { $FORM{"zero$i"} = 0; }
$FORM{"minage$i"} =~ tr/[0-9]//cd; ## remove non numbers
$FORM{"maxage$i"} =~ tr/[0-9]//cd; ## remove non numbers
if ($FORM{"minage$i"} < 0) { $FORM{"minage$i"} = ""; }
if ($FORM{"maxage$i"} < 0) { $FORM{"maxage$i"} = ""; }
if ($FORM{"minage$i"} > 180) { $FORM{"minage$i"} = ""; }
if ($FORM{"maxage$i"} > 180) { $FORM{"maxage$i"} = ""; }
if ($FORM{"maxage$i"} && $FORM{"maxage$i"} < $FORM{"minage$i"}) { $FORM{"maxage$i"} = $FORM{"minage$i"}; }
push(@boardcontrol, "$FORM{\"cat$i\"}|$id|$FORM{\"pic$i\"}|$bdescription|$FORM{\"moderators$i\"}|$FORM{\"moderatorgroups$i\"}|$FORM{\"topicperms$i\"}|$FORM{\"replyperms$i\"}|$FORM{\"pollperms$i\"}|$FORM{\"zero$i\"}|$FORM{\"membergroups$i\"}|$FORM{\"ann$i\"}|$FORM{\"rbin$i\"}|$FORM{\"att$i\"}|$FORM{\"minage$i\"}|$FORM{\"maxage$i\"}|$FORM{\"gender$i\"}\n");
push(@changes, $id);
$yymain .= qq~'$FORM{"name$i"}' $admin_txt{'48'}
~;
}
# do the saving here, after all new boards passed the tests (fatal_error)
&BoardTotals("add", @changes);
&Write_ForumMaster;
my @oldcontrols = &read_DBorFILE(0,FORUMCONTROL,$boardsdir,'forum','control');
my $oldboard;
for (my $cnt = 0; $cnt < @oldcontrols; $cnt++) {
(undef, $oldboard, undef) = split(/\|/, $oldcontrols[$cnt], 3);
foreach my $changedboard (@changes) {
if ($changedboard eq $oldboard) { $oldcontrols[$cnt] = ""; }
}
}
push(@oldcontrols, @boardcontrol);
&write_DBorFILE(0,FORUMCONTROL,$boardsdir,'forum','control',sort(grep { $_; } @oldcontrols));
$action_area = "manageboards";
&AdminTemplate;
}
sub ReorderBoards {
&is_admin_or_gmod;
if ($#categoryorder > 0) {
foreach $category (@categoryorder) {
chomp $category;
($categoryname, undef) = split(/\|/, $catinfo{$category});
&ToChars($categoryname);
if ($category eq $INFO{"item"}) {
$categorylistsel = qq~~;
} else {
$categorylist .= qq~~;
}
}
}
@bdlist = split(/,/, $cat{ $INFO{"item"} });
$bdcnt = @bdlist;
$bdnum = $bdcnt;
if ($bdcnt < 4) { $bdcnt = 4; }
($curcatname, $catperms) = split(/\|/, $catinfo{ $INFO{"item"} });
&ToChars($curcatname);
# Prepare the list of current boards to be put in the select box
$boardslist = qq~~;
$yymain .= qq~
~;
$yytitle = "$admin_txt{'832'}";
$action_area = "manageboards";
&AdminTemplate;
}
sub ReorderBoards2 {
&is_admin_or_gmod;
@itemorder = split(/,/, $cat{ $INFO{"item"} });
my $moveitem = $FORM{'selectboards'};
my $category = $INFO{"item"};
if ($moveitem) {
if ($FORM{'moveup'} || $FORM{'movedown'}) {
if ($FORM{'moveup'}) {
for ($i = 0; $i < @itemorder; $i++) {
if ($itemorder[$i] eq $moveitem && $i > 0) {
$j = $i - 1;
$itemorder[$i] = $itemorder[$j];
$itemorder[$j] = $moveitem;
last;
}
}
} elsif ($FORM{'movedown'}) {
for ($i = 0; $i < @itemorder; $i++) {
if ($itemorder[$i] eq $moveitem && $i < $#itemorder) {
$j = $i + 1;
$itemorder[$i] = $itemorder[$j];
$itemorder[$j] = $moveitem;
last;
}
}
}
$cat{$category} = join(',', grep { $_; } @itemorder);
} else {
if ($category ne $FORM{"selectcategory"}) {
${$uid.$moveitem}{'cat'} = qq~$FORM{'selectcategory'}~;
my @bdlist = split(/,/, $cat{$category});
my $k = 0;
foreach $bd (@bdlist) {
if ($moveitem eq $bd) { splice(@bdlist, $k, 1); }
$k++;
}
$cat{"$category"} = join(',', @bdlist);
my $ncat = $FORM{"selectcategory"};
if ($cat{$ncat} ne "") { $cat{$ncat} .= ",$moveitem"; }
else { $cat{$ncat} = $moveitem; }
$category = qq~$FORM{"selectcategory"}~;
}
}
&Write_ForumMaster;
my @oldcontrols = &read_DBorFILE(0,FORUMCONTROL,$boardsdir,'forum','control');
for (my $cnt = 0; $cnt < @oldcontrols; $cnt++) {
my ($dummy, $oldboard,$pic,$bdescription,$moderators,$moderatorgroups,$topicperms,$replyperms,$pollperms,$zero,$membergroups,$ann,$rbin,$att,$minage,$maxage,$gender) = split(/\|/, $oldcontrols[$cnt]);
if ($moveitem eq $oldboard) {
$oldcontrols[$cnt] = qq~$category|$moveitem|$pic|$bdescription|$moderators|$moderatorgroups|$topicperms|$replyperms|$pollperms|$zero|$membergroups|$ann|$rbin|$att|$minage|$maxage|$gender~;
}
}
&write_DBorFILE(0,FORUMCONTROL,$boardsdir,'forum','control',sort(grep { $_; } @oldcontrols));
}
$yySetLocation = qq~$adminurl?action=reorderboards;item=$category;theboard=$moveitem~;
&redirectexit;
}
sub ConfRemBoard {
$yymain .= qq~
~;
$yytitle = "$admin_txt{'31'} - '$FORM{'boardname'}'?";
$action_area = "manageboards";
&AdminTemplate;
}
1;