############################################################################### # ManageBoards.pm # ############################################################################### # YaBB: Yet another Bulletin Board # # Open-Source Community Software for Webmasters # # Version: YaBB 2.5.4 # # Packaged: October 15, 2012 # # Distributed by: http://www.yabbforum.com # # =========================================================================== # # Copyright (c) 2000-2012 YaBB (www.yabbforum.com) - All Rights Reserved. # # Software by: The YaBB Development Team # # with assistance from the YaBB community. # ############################################################################### use CGI::Carp qw(fatalsToBrowser); our $VERSION = '2.5.4'; $manageboardspmver = 'YaBB 2.5.4 $Revision$'; if ( $action eq 'detailedversion' ) { return 1; } $admin_images = "$yyhtml_root/Templates/Admin/default"; sub ManageBoards { is_admin_or_gmod(); LoadBoardControl(); get_forum_master(); if ( $INFO{'action'} eq 'managecats' ) { $colspan = q~colspan="2"~; $add = $admin_txt{'47'}; $act = 'catscreen'; $manage = qq~$admin_txt{'829'}  $admin_txt{'49'}~; $managedescr = $admin_txt{'678'}; $act2 = 'addcat'; $action_area = 'managecats'; } else { $colspan = q~colspan="4"~; $add = $admin_txt{'50'}; $act = 'boardscreen'; $manage = qq~$admin_img{'cat_img'}  $admin_txt{'51'}~; $managedescr = $admin_txt{'677'}; $act2 = 'addboard'; $action_area = 'manageboards'; } $yymain .= qq~
$manage
$managedescr
~; foreach my $catid (@categoryorder) { @bdlist = split /,/xsm, $cat{$catid}; ( $curcatname, $catperms ) = split /\|/xsm, $catinfo{"$catid"}; ToChars($curcatname); if ( $INFO{'action'} eq 'managecats' ) { $tempcolspan = q{}; $tempclass = 'windowbg2'; $temphrefclass = q{}; } else { $tempcolspan = q~colspan="4"~; $tempclass = 'catbg'; $temphrefclass = q~class="catbg a"~; } $yymain .= qq~ ~; if ( $INFO{'action'} eq 'managecats' ) { $yymain .= qq~ ~; } $yymain .= q~
$admin_txt{'832'}  $curcatname
~; if ( $INFO{'action'} ne 'managecats' ) { my $indent = -3; # recursive loop to display all sub boards *show_boards = sub { my @brdlist = @_; $indent += 3; foreach my $curboard (@brdlist) { ( $boardname, $boardperms, $boardview ) = split /\|/xsm, $board{$curboard}; $boardname =~ s/\"\;/"/gxsm; ToChars($boardname); $descr = ${ $uid . $curboard }{'description'}; $descr =~ s/\
/\n/gsm; my $bicon = q{}; if ( ${ $uid . $curboard }{'pic'} ) { $bicon = ${ $uid . $curboard }{'pic'}; } if ( $bicon =~ /\//ixsm ) { $bicon = qq~ ~; } elsif ($bicon) { $bicon = qq~ ~; } if ( ${ $uid . $curboard }{'ann'} == 1 ) { $bicon = qq~ $admin_txt{'64g'}~; } if ( ${ $uid . $curboard }{'rbin'} == 1 ) { $bicon = qq~ $admin_txt{'64i'}~; } $convertstr = $descr; if ( $convertstr !~ /<.+?>/xsm ) { # Don't cut it if there's HTML in it. $convertcut = 60; CountChars(); } my $descr = $convertstr; ToChars($descr); if ($cliped) { $descr .= q{...}; } my $tmpwidth = 100 - $indent; my $tmpwidth2 = 90 - $indent; my @children = split /\|/xsm, $subboard{$curboard}; $reorder_subs = @children > 0 ? qq~$admin_txt{'252'}~ : q{}; my $del_txt = $admin_txt{'251'}; my $edit_txt = $admin_txt{'253'}; if ( ${ $uid . $curboard }{'parent'} ) { $del_txt =~ s/{(.*?)}/$admin_txt{'254'}$1/gxsm; $edit_txt =~ s/{(.*?)}/$admin_txt{'254'}$1/gxsm; } else { $del_txt =~ s/{(.*?)}/$1/gxsm; $edit_txt =~ s/{(.*?)}/$1/gxsm; } $yymain .= q~
$boardname
$admin_txt{'250'} $edit_txt $del_txt ~ . $reorder_subs . qq~
$bicon
$descr
~; if ( $subboard{$curboard} ) { show_boards(@children); } } $indent -= 3; }; show_boards(@bdlist); } } $yymain .= qq~
$admin_txt{'53'} $admin_txt{'54'}
$admin_img{'cat_img'} $add
~; $yytitle = "$admintxt{'a4_title'}"; AdminTemplate(); return; } sub BoardScreen { is_admin_or_gmod(); get_forum_master(); $i = 0; while ( $_ = each %FORM ) { if ( $FORM{$_} && $_ =~ /^yitem_(.+)$/xsm ) { $editboards[$i] = $1; $i++; } } $i = 1; foreach my $thiscat (@categoryorder) { my @catboards = split /,/xsm, $cat{$thiscat}; # make an array of all sub boards recursively *recursive_boards = sub { my @x = @_; push @theboards, @x; foreach my $childbd (@x) { if ( $subboard{$childbd} ) { recursive_boards( split /\|/xsm, $subboard{$childbd} ); } } }; recursive_boards(@catboards); for my $z ( 0 .. ( @theboards - 1 ) ) { my $found = 0; for my $j ( 0 .. ( @editboards - 1 ) ) { if ( $editboards[$j] eq $theboards[$z] ) { $editbrd[$i] = $theboards[$z]; $found = 1; $i++; splice @editboards, $j, 1; last; } } } } if ( $FORM{'baction'} eq 'edit' ) { AddBoards(@editbrd); } elsif ( $FORM{'baction'} eq 'delme' ) { shift @editbrd; get_forum_master(); foreach my $bd (@editbrd) { # Remove Board form category it belongs to unless it's a sub board, then it's not in the cat list if ( !${ $uid . $bd }{'parent'} ) { $category = ${ $uid . $bd }{'cat'}; @bdlist = split /,/xsm, $cat{$category}; my $c = 0; foreach (@bdlist) { if ( $_ eq $bd ) { splice @bdlist, $c, 1; last; } $c++; } $cat{$category} = join q{,}, undupe(@bdlist); } else { # if it has a parent, remove it from its parent's child board list my @bdlist = split /\|/xsm, $subboard{ ${ $uid . $bd }{'parent'} }; # Remove Board from old parent board my $k = 0; foreach (@bdlist) { if ( $bd eq $_ ) { splice @bdlist, $k, 1; } $k++; } $subboard{ ${ $uid . $bd }{'parent'} } = join q{|}, @bdlist; } # remove the $subboard{} hash that contains children list, since it's a parent board and move children up if ( $subboard{$bd} ) { foreach my $childbd ( split /\|/xsm, $subboard{$bd} ) { # if this one has a parent board, move its children up to that, otherwise to category. if ( ${ $uid . $bd }{'parent'} ) { if ( $subboard{ ${ $uid . $bd }{'parent'} } ) { $subboard{ ${ $uid . $bd }{'parent'} } .= qq~|$childbd~; } else { $subboard{ ${ $uid . $bd }{'parent'} } = $childbd; } ${ $uid . $childbd }{'parent'} = ${ $uid . $bd }{'parent'}; } else { $cat{ ${ $uid . $bd }{'cat'} } .= ",$childbd"; ${ $uid . $childbd }{'parent'} = q{}; } push @del_updateparent, $childbd; } delete $subboard{$bd}; } 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(); return; } sub DeleteBoards { my @x = @_; is_admin_or_gmod(); fopen( FORUMCONTROL, "+<$boardsdir/forum.control" ) || fatal_error( 'cannot_open', "$boardsdir/forum.control", 1 ); seek FORUMCONTROL, 0, 0; my @oldcontrols = ; foreach my $board (@x) { fopen( BOARDDATA, "$boardsdir/$board.txt" ); @messages = ; fclose(BOARDDATA); foreach my $curmessage (@messages) { my ( $id, undef ) = split /\|/xsm, $curmessage, 2; unlink "$datadir/$id\.txt"; unlink "$datadir/$id\.mail"; unlink "$datadir/$id\.ctb"; unlink "$datadir/$id\.data"; unlink "$datadir/$id\.poll"; unlink "$datadir/$id\.polled"; } for my $cnt ( 0 .. ( @oldcontrols - 1 ) ) { my $oldboard; ( undef, $oldboard, undef ) = split /\|/xsm, $oldcontrols[$cnt], 3; $yydebug .= "$cnt $oldboard \n"; if ( $oldboard eq $board ) { $oldcontrols[$cnt] = q{}; $yydebug .= qq~\$board{\"$oldboard\"}~; delete $board{"$board"}; last; } } unlink "$boardsdir/$board.txt"; unlink "$boardsdir/$board.ttl"; unlink "$boardsdir/$board.poster"; unlink "$boardsdir/$board.mail"; fopen( ATM, "+<$vardir/attachments.txt", 1 ); seek ATM, 0, 0; my @buffer = ; my ( $amcurrentboard, $amfn ); for my $aa ( 0 .. ( @buffer - 1 ) ) { ( undef, undef, undef, undef, $amcurrentboard, undef, undef, $amfn, undef ) = split /\|/xsm, $buffer[$aa]; if ( $amcurrentboard eq $board ) { $buffer[$aa] = q{}; unlink "$upload_dir/$amfn"; } } truncate ATM, 0; seek ATM, 0, 0; print {ATM} @buffer or croak "$croak{'print'} ATM"; fclose(ATM); BoardTotals( 'delete', $board ); } # Update parents for subboards that had a parent deleted. if (@del_updateparent) { for my $cnt ( 0 .. ( @oldcontrols - 1 ) ) { my ( $oldcat, $oldboard, $pic, $bdescription, $moderators, $moderatorgroups, $topicperms, $replyperms, $pollperms, $zero, $membergroups, $ann, $rbin, $att, $minage, $maxage, $gender, $canpost, $parent, $rules, $brulestitle, $brulesdesc, $rulescollapse,$brdpasswr,$brdpassw ) = split /\|/xsm, $oldcontrols[$cnt]; foreach my $changedboard (@del_updateparent) { if ( $changedboard eq $oldboard ) { $oldcontrols[$cnt] = qq~$oldcat|$oldboard|$pic|$bdescription|$moderators|$moderatorgroups|$topicperms|$replyperms|$pollperms|$zero|$membergroups|$ann|$rbin|$att|$minage|$maxage|$gender|$canpost|${$uid.$changedboard}{'parent'}|$rules|$brulestitle|$brulesdesc|$rulescollapse|$brdpasswr|$brdpassw\n~; last; } } } } my @boardcontrol = grep { $_; } @oldcontrols; truncate FORUMCONTROL, 0; seek FORUMCONTROL, 0, 0; print {FORUMCONTROL} sort @boardcontrol or croak "$croak{'print'} FORUMCONTROL"; fclose(FORUMCONTROL); fopen( FORUMCONTROL, "$boardsdir/forum.control" ); @forum_control = ; fclose(FORUMCONTROL); return; } sub AddBoards { my @editboards = @_; is_admin_or_gmod(); $addtext = $admin_txt{'50'}; if ( $INFO{'action'} eq 'boardscreen' ) { $FORM{'amount'} = $#editboards; $addtext = $admin_txt{'50a'}; } if ( $INFO{'parent'} ) { $FORM{'amount'} = 1; } get_forum_master(); LoadBoardControl(); # build recursive drop down of boards in each category for selecting parent board *get_subboards = sub { my @x = @_; $indent += 2; foreach my $childbd (@x) { my $dash; if ( $indent > 0 ) { $dash = q{-}; } ( $chldboardname, undef, undef ) = split /\|/xsm, $board{"$childbd"}; ToChars($chldboardname); $catboardlist{$thiscat} .= qq~$childbd|~ . ( q{ } x $indent ) . ( $dash x ( $indent / 2 ) ) . qq~ $chldboardname|~; if ( $subboard{$childbd} ) { get_subboards( split /\|/xsm, $subboard{$childbd} ); } } $indent -= 2; }; foreach $thiscat (@categoryorder) { # $thiscat cannot be localized my @catboards = split /\,/xsm, $cat{$thiscat}; my $indent = -2; $catboardlist{$thiscat} = q~||~; get_subboards(@catboards); $catboardlist_js .= qq~ catboardlist['$thiscat'] = "$catboardlist{$thiscat}"; ~; } $yymain .= qq~
$admin_img{'cat_img'} $addtext
$admin_txt{'57'}
~; # Check if and which board are set for announcements or recycle bin # Start Looping through and repeating the board adding wherever needed $istart = 0; $annexist = q{}; $rbinexist = q{}; # for ( $i = 1 ; $i != $FORM{'amount'} + 1 ; $i++ ) { for my $i ( 1 .. $FORM{'amount'} ) { # differentiate between edit or add boards if ( $editboards[$i] eq q{} && $INFO{'action'} eq 'boardscreen' ) { next; } if ( $INFO{'action'} eq 'boardscreen' ) { $id = $editboards[$i]; } else { $boardtext = "$admin_txt{'58'} $i:"; } # print javascript hash of board names and their equivalent category if ( !$INFO{'parent'} ) { $brd_javascript .= qq~editbrds[$i] = "${$uid.$editboards[$i]}{'cat'}|$editboards[$i]|${$uid.$editboards[$i]}{'parent'}";\n~; } else { $brd_javascript .= qq~editbrds[$i] = "$INFO{'category'}||$INFO{'parent'}";\n~; } my $boardcat = ${ $uid . $editboards[$i] }{'cat'}; foreach my $catid (@categoryorder) { @bdlist = split /,/xsm, $cat{$catid}; ( $curcatname, $catperms ) = split /\|/xsm, $catinfo{"$catid"}; if ( $INFO{'action'} eq 'boardscreen' || $INFO{'parent'} ) { if ( $catid eq $boardcat || $catid eq $INFO{'category'} ) { $selected = q~ selected="selected"~; } else { $selected = q{}; } } ToChars($curcatname); $catsel{$i} .= qq~~; } $catsel .= q~~; if ( $istart == 0 ) { $istart = $i; } ( $boardname, $boardperms, $boardview ) = split /\|/xsm, $board{"$id"}; ToChars($boardname); if ( $INFO{'action'} eq 'boardscreen' ) { $boardtext = $boardname; } $boardpic = ${ $uid . $editboards[$i] }{'pic'}; $description = ${ $uid . $editboards[$i] }{'description'}; $description =~ s/
/\n/gsm; ToChars($description); $moderators = ${ $uid . $editboards[$i] }{'mods'}; $moderatorgroups = ${ $uid . $editboards[$i] }{'modgroups'}; $boardminage = ${ $uid . $editboards[$i] }{'minageperms'}; $boardmaxage = ${ $uid . $editboards[$i] }{'maxageperms'}; $boardgender = ${ $uid . $editboards[$i] }{'genderperms'}; $genselect = qq~~; my $canpostch; if ( ${ $uid . $id }{'canpost'} == 1 || $INFO{'action'} ne 'boardscreen' ) { $canpostch = q~ checked="checked"~; } # Make children list if it contains sub boards my $childrenlist; if ( $subboard{$id} ) { foreach my $childbd ( split /\|/xsm, $subboard{$id} ) { my ( $chldboardname, undef, undef ) = split /\|/xsm, $board{"$childbd"}; ToChars($chldboardname); $childrenlist .= qq~$chldboardname, ~; } $childrenlist =~ s/, $//gsm; } if ( $childrenlist eq q{} ) { $childrenlist = $admin_txt{'246'}; } # Retrieve Optional Details $ann = q{}; $rbin = q{}; $zeroch = q{}; $attch = q{}; $showpriv = q{}; $brdpic = q{}; $brdrssch = q{}; ### RSS on Board Index ### $brdpasswr = q{}; $brdpassw = ${$uid.$editboards[$i]}{'brdpassw'}; $brdpassw3 = q{}; $brdpassw2 = q{}; if ($brdpassw ne q{}) { $brdpassw2 = qq~$boardpass_txt{'900pt'}~; } if (${$uid.$editboards[$i]}{'brdpasswr'} == 1) { $brdpasswr = q~ checked="checked"~; } if ( $boardview == 1 ) { $showpriv = q~ checked="checked"~; } if ( ${ $uid . $id }{'zero'} == 1 ) { $zeroch = q~ checked="checked"~; } if ( ${ $uid . $id }{'attperms'} == 1 ) { $attch = q~ checked="checked"~; } if ( ${ $uid . $id }{'brdrss'} == 1 ) { $brdrssch = q~ checked="checked"~; } ### RSS on Board Index ### if ( ${ $uid . $id }{'ann'} == 1 ) { $annch = q~ checked="checked"~; $brdpic = q~ disabled="disabled"~; } elsif ( $annboard ne q{} ) { $annch = q~ disabled="disabled"~; $annexist = 1; } if ( ${ $uid . $id }{'rbin'} == 1 ) { $rbinch = q~ checked="checked"~; $brdpic = q~ disabled="disabled"~; } elsif ( $binboard ne q{} ) { $rbinch = q~ disabled="disabled"~; $rbinexist = 1; } $en_rules = q{}; if ( ${ $uid . $id }{'rules'} == 1 ) { $en_rules = q~ checked="checked"~; } $en_rulescoll = q{}; if ( ${ $uid . $id }{'rulescollapse'} == 1 ) { $en_rulescoll = q~ checked="checked"~; } $rulestitle = ${ $uid . $editboards[$i] }{'rulestitle'}; ToChars($rulestitle); $rulesdesc = ${ $uid . $editboards[$i] }{'rulesdesc'}; $rulesdesc =~ s/
/\n/gsm; ToChars($rulesdesc); #Get Board permissions here my $startperms = DrawPerms( ${ $uid . $id }{'topicperms'}, 0 ); my $replyperms = DrawPerms( ${ $uid . $id }{'replyperms'}, 1 ); my $viewperms = DrawPerms( $boardperms, 0 ); my $pollperms = DrawPerms( ${ $uid . $id }{'pollperms'}, 0 ); $yymain .= qq~~; if ( $id ne q{} ) { $yymain .= qq~ ~; } else { $yymain .= qq~ ~; } $yymain .= qq~
$boardtext
$admin_txt{'59'}: $admin_txt{'60'}
$admin_txt{'61'} $id
$admin_txt{'63'}:
$selector_txt{linklabel}
$admin_txt{'63a'}
$admin_txt{'63b'}
$admin_txt{'63c'}

$selector_txt{instructions}
~; # Allows admin to select entire membergroups to be a board moderator $k = 0; my $box = q{}; foreach (@nopostorder) { @groupinfo = split /\|/xsm, $NoPost{$_}; $box .= qq~~; $k++; } if ( $k > 5 ) { $k = 5; } if ( $k > 0 ) { $yymain .= qq~ ~; } else { $yymain .= qq~$admin_txt{'15'}~; } $yymain .= qq~
$admin_txt{'248'}: $childrenlist
$admin_txt{'64'} $admin_txt{'64a'}
$admin_txt{'rules'}:
$admin_txt{'100'}: $admin_txt{'100a'}
$genselect
$boardpass_txt{'900pw'}:

$boardpass_txt{'900pwb'}

$boardpass_txt{'900pf'}
$brdpassw2
$admin_txt{'65'}: $admin_txt{'65a'} $admin_txt{'14'}
~; } $yymain .= qq~
$admin_img{'prefimg'} $admin_txt{'10'}
~; $yytitle = "$admin_txt{'50'}"; if ( $INFO{'action'} eq 'boardscreen' ) { $yytitle = "$admin_txt{'50a'}"; } $action_area = 'manageboards'; AdminTemplate(); return; } sub DrawPerms { my ( $permissions, $permstype ) = @_; my ( $foundit, %found, $groupsel, $groupsel2, $name ); my $count = 0; if ( $permissions eq q{} ) { $permissions = 'xk8yj56ndkal'; } my @perms = split /, /sm, $permissions; foreach my $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 /\|/xsm, $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 /\|/xsm, $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~; } ( $name, undef ) = split /\|/xsm, $Group{'Mid Moderator'}, 2; if ( $perm eq 'Mid 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 /\|/xsm, $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 ( reverse sort { $a <=> $b } keys %Post ) { ( $name, undef ) = split /\|/xsm, $Post{$_}, 2; if ( $perm eq $name ) { $foundit = 1; $found{$name} = 1; $groupsel .= qq~\n~; } if ( $count == $#perms && ( $found{$name} != 1 || $found{$name} eq q{} ) ) { $groupsel2 .= qq~\n~; } } } } $count++; } return $groupsel . $groupsel2; } sub AddBoards2 { is_admin_or_gmod(); get_forum_master(); $anncount = 0; $rbincount = 0; my ( @boardcontrol, @changes, @updatecats ); LoadBoardControl(); for my $i ( 1 .. $FORM{'amount'} ) { if ( $FORM{"pic$i"} ne q{} && $FORM{"pic$i"} !~ m{^[0-9a-zA-Z_\.\#\%\-\:\+\?\$\&\~\.\,\@/]+\.(gif|png|bmp|jpg)$}xsm ) { fatal_error('invalid_picture'); } ##### Dealing with Required Info here ##### if ( $FORM{"id$i"} eq q{} ) { next; } $id = $FORM{"id$i"}; if ( $FORM{"ann$i"} ) { $anncount++; } if ( $FORM{"rbin$i"} ) { $rbincount++; } if ( $anncount > 1 ) { fatal_error('announcement_defined'); } if ( $rbincount > 1 ) { fatal_error('recycle_bin_defined'); } if ( $id !~ /\A[0-9A-Za-z#%+-\.@^_]+\Z/xsm ) { fatal_error( 'invalid_character', "$admin_txt{'61'} $admin_txt{'241'}" ); } if ( $FORM{'screenornot'} ne 'boardscreen' ) { # adding a board # make sure no board already exists with that id if ( exists $board{"$id"} ) { fatal_error( 'board_defined', "$id" ); } # add to category if it's not a sub board, otherwise add it to subboard list for its parent if ( !$FORM{"parent$i"} ) { my @bdlist = split /\,/xsm, $cat{ $FORM{"cat$i"} }; push @bdlist, "$id"; $cat{ $FORM{"cat$i"} } = join q{,}, @bdlist; } else { if ( $subboard{ $FORM{"parent$i"} } ne q{} ) { $subboard{ $FORM{"parent$i"} } .= qq~|$id~; } else { $subboard{ $FORM{"parent$i"} } = $id; } } fopen( BOARDINFO, ">$boardsdir/$id.txt" ); print {BOARDINFO} q{} or croak "$croak{'print'}' BOARDINFO"; fclose(BOARDINFO); } 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"}~; # recursively change the category of child boards. if ( $subboard{$id} ) { *cat_change = sub { my @x = @_; foreach my $childbd (@x) { ${ $uid . $childbd }{'cat'} = qq~$FORM{"cat$i"}~; push @updatecats, $childbd; if ( $subboard{$childbd} ) { cat_change( split /\|/xsm, $subboard{$childbd} ); } } }; cat_change( split /\|/xsm, $subboard{$id} ); } # if it's not a sub board, remove from the old category if ( !${ $uid . $id }{'parent'} ) { my @bdlist = split /,/xsm, $cat{$category}; # Remove Board from old Category my $k = 0; foreach my $bd (@bdlist) { if ( $id eq $bd ) { splice @bdlist, $k, 1; } $k++; } $cat{"$category"} = join q{,}, @bdlist; } # Add Category to new Category, but only if it isn't a sub board if ( !$FORM{"parent$i"} ) { my $ncat = $FORM{"cat$i"}; if ( $cat{$ncat} ne q{} ) { $cat{$ncat} .= ",$id"; } else { $cat{$ncat} = $id; } } } # move parent board of board if ( ${ $uid . $id }{'parent'} ne $FORM{"parent$i"} ) { # if it had a parent, remove it from that list, otherwise it didnt have a parent so remove it from cat list if ( ${ $uid . $id }{'parent'} ) { my @bdlist = split /\|/xsm, $subboard{ ${ $uid . $id }{'parent'} }; # Remove Board from old parent board my $k = 0; foreach my $bd (@bdlist) { if ( $id eq $bd ) { splice @bdlist, $k, 1; } $k++; } $subboard{ ${ $uid . $id }{'parent'} } = join q{|}, @bdlist; } # only remove from old category if it now has a parent and its in the same cat as before, otherwise # cat had to have been changed to get a parent in a different cat, and the cat change takes care of # removing it from the previous category elsif ( $category eq $FORM{"cat$i"} ) { my @bdlist = split /,/xsm, $cat{$category}; # Remove Board from old Category my $k = 0; foreach my $bd (@bdlist) { if ( $id eq $bd ) { splice @bdlist, $k, 1; } $k++; } $cat{$category} = join q{,}, @bdlist; } # if we're removing the parent board, move it back up to it's category, otherwise add to new parent board if ( $FORM{"parent$i"} eq q{} ) { # only move up to cat if cat is the same as previously if ( $category eq $FORM{"cat$i"} ) { my @bdlist = split /\,/xsm, $cat{ $FORM{"cat$i"} }; push @bdlist, "$id"; $cat{ $FORM{"cat$i"} } = join q{,}, @bdlist; } } else { # Add to new parent board if ( $subboard{ $FORM{"parent$i"} } ) { $subboard{ $FORM{"parent$i"} } .= qq~|$id~; } else { $subboard{ $FORM{"parent$i"} } = $id; } } } if ( -e "$boardsdir/$id.txt" ) { # fix a(nnboard) in the boardid.txt fopen( BOARDINFO, "$boardsdir/$id.txt" ) || fatal_error( 'cannot_open', "$openboard/$id.txt", 1 ); my @boardtomodify = ; fclose(BOARDINFO); my $x; if ( $FORM{"ann$i"} && ( split /\|/xsm, $boardtomodify[0] )[8] !~ /a/ism ) { for my $x ( 0 .. ( @boardtomodify - 1 ) ) { $boardtomodify[$x] =~ s/(.*\|)(0?)(.*)/ $1 . ($2 eq '0' ? "0a$3" : "a$3") /exsm; } } elsif ( !$FORM{"ann$i"} && ( split /\|/xsm, $boardtomodify[0] )[8] =~ /a/ism ) { *take_a_off = sub { my $y = shift; $y =~ s/a//gsm; return $y; }; for my $x ( 0 .. ( @boardtomodify - 1 ) ) { $boardtomodify[$x] =~ s/(.*\|)(.*)/ $1 . take_a_off($2) /exsm; } } if ($x) { fopen( BOARDINFO, ">$boardsdir/$id.txt" ) || fatal_error( 'cannot_open', "$openboard/$id.txt", 1 ); print {BOARDINFO} @boardtomodify or croak "$croak{'print'} BOARDINFO"; fclose(BOARDINFO); } } } $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/\$/\\\$/gxsm; $board{"$id"} = "$bname|$FORM{\"viewperms$i\"}|$FORM{\"show$i\"}"; $bdescription = $FORM{"description$i"}; FromChars($bdescription); $bdescription =~ s/\r//gxsm; $bdescription =~ s/\n/
/gsm; if ($do_scramble_id) { my @mods; foreach ( split /\, /sm, $FORM{"moderators$i"} ) { push @mods, decloak($_); } $FORM{"moderators$i"} = join q{, }, @mods; } if ( $FORM{"brdrss$i"} eq q{} ) { $FORM{"brdrss$i"} = 0; } ### RSS on Board Index ### if ( $FORM{"zero$i"} eq q{} ) { $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"} = q{}; } if ( $FORM{"maxage$i"} < 0 ) { $FORM{"maxage$i"} = q{}; } if ( $FORM{"minage$i"} > 180 ) { $FORM{"minage$i"} = q{}; } if ( $FORM{"maxage$i"} > 180 ) { $FORM{"maxage$i"} = q{}; } if ( $FORM{"maxage$i"} && $FORM{"maxage$i"} < $FORM{"minage$i"} ) { $FORM{"maxage$i"} = $FORM{"minage$i"}; } ### Board Rules Start ### if ( $FORM{"rules$i"} eq q{} ) { $FORM{"rules$i"} = 0; } if ( $FORM{"rulescollapse$i"} eq q{} ) { $FORM{"rulescollapse$i"} = 0; } $brulestitle = $FORM{"rulestitle$i"}; FromChars($brulestitle); $brulesdesc = $FORM{"rulesdesc$i"}; FromChars($brulesdesc); $brulesdesc =~ s/\r//gxsm; $brulesdesc =~ s/\n/
/gsm; ### Board Rules End ### $FORM{"pasww$i"} =~ s/ //gsm; if ($FORM{"pasww$i"} ne q{}) { if ($FORM{"pasww$i"} !~ /\A[\s0-9A-Za-z!@#$%\^&*\(\)_\+|`~\-=\\:;'",\.\/?\[\]\{\}]+\Z/sm) { fatal_error("$register_txt{'240'} $register_txt{'36'} $register_txt{'241'}") } $encryptopass = encode_password($FORM{"pasww$i"}); } else { if ($FORM{"paswwr$i"}) { $encryptopass = $FORM{"brdpassw$i"}; } else { $encryptopass = q{};} } 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\"}|$FORM{\"canpost$i\"}|$FORM{\"parent$i\"}|$FORM{\"rules$i\"}|$brulestitle|$brulesdesc|$FORM{\"rulescollapse$i\"}|$FORM{\"paswwr$i\"}|$encryptopass|$FORM{\"brdrss$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) if ( $FORM{'screenornot'} ne 'boardscreen' ) { BoardTotals( 'add', @changes ); } Write_ForumMaster(); fopen( FORUMCONTROL, "+<$boardsdir/forum.control" ); seek FORUMCONTROL, 0, 0; my @oldcontrols = ; my $oldboard; # Update categories for subboards that got changed. for my $cnt ( 0 .. ( @oldcontrols - 1 ) ) { ( undef, $oldboard, undef ) = split /\|/xsm, $oldcontrols[$cnt], 3; foreach my $changedboard (@updatecats) { if ( $changedboard eq $oldboard ) { my ( $oldcat, $therest ) = split /\|/xsm, $oldcontrols[$cnt], 2; $oldcontrols[$cnt] = qq~${$uid.$changedboard}{'cat'}|$therest~; last; } } } for my $cnt ( 0 .. ( @oldcontrols - 1 ) ) { ( undef, $oldboard, undef ) = split /\|/xsm, $oldcontrols[$cnt], 3; foreach my $changedboard (@changes) { if ( $changedboard eq $oldboard ) { $oldcontrols[$cnt] = q{}; last; } } } push @oldcontrols, @boardcontrol; @boardcontrol = grep { $_; } @oldcontrols; truncate FORUMCONTROL, 0; seek FORUMCONTROL, 0, 0; print {FORUMCONTROL} sort @boardcontrol or croak "$croak{'print'} FORUMCONTOL"; fclose(FORUMCONTROL); $yytitle = $admin_txt{'50a'}; $action_area = 'manageboards'; AdminTemplate(); return; } sub ReorderBoards { is_admin_or_gmod(); get_forum_master(); if ( $INFO{'subboards'} ) { LoadBoardControl(); } if ( $#categoryorder > 0 ) { foreach my $category (@categoryorder) { chomp $category; ( $categoryname, undef ) = split /\|/xsm, $catinfo{$category}; ToChars($categoryname); if ( ( $category eq $INFO{'item'} && !$INFO{'subboards'} ) || ( $category eq ${ $uid . $INFO{'item'} }{'cat'} && $INFO{'subboards'} ) ) { $categorylistsel = qq~~; } else { $categorylist .= qq~~; } # build option lists for parent boards my @catboards = split /,/xsm, $cat{$category}; my $indent = -2; $catboardlist{$category} = q~~; *get_subboards2 = sub { my @x = @_; $indent += 2; foreach my $childbd (@x) { my $dash; if ( $indent > 0 ) { $dash = q{-}; } ( $chldboardname, undef, undef ) = split /\|/xsm, $board{"$childbd"}; ToChars($chldboardname); $catboardlist{$category} .= qq~~; if ( $subboard{$childbd} ) { get_subboards2( split /\|/xsm, $subboard{$childbd} ); } } $indent -= 2; }; get_subboards2(@catboards); $catboardlist_js .= qq~ catboardlist['$category'] = "$catboardlist{$category}"; ~; } } # get list of subboards if that's what we're reordering otherwise boards in the selected category if ( $INFO{'subboards'} ) { @bdlist = split /\|/xsm, $subboard{ $INFO{'item'} }; $INFO{'subboards'} = ';subboards=1'; ( $curname, $boardperms, $boardview ) = split /\|/xsm, $board{ $INFO{'item'} }; ToChars($curname); $cur_txt = $admin_txt{'832a'}; } else { @bdlist = split /,/xsm, $cat{ $INFO{'item'} }; ( $curname, $catperms ) = split /\|/xsm, $catinfo{ $INFO{'item'} }; ToChars($curname); $cur_txt = $admin_txt{'832'}; } $bdcnt = @bdlist; $bdnum = $bdcnt; if ( $bdcnt < 4 ) { $bdcnt = 4; } # Prepare the list of current boards to be put in the select box $boardslist = qq~~; if ( $INFO{'subboards'} ) { $cat_or_bd_txt = $admin_txt{'739h'}; $admin_txt{'739c'} =~ s/{(.*?)}/$admin_txt{'739j'}$1/gsm; $admin_txt{'739d'} =~ s/{(.*?)}/$admin_txt{'739j'}$1/gsm; $admin_txt{'739f'} =~ s/{(.*?)}/$admin_txt{'739j'}$1/gsm; } else { $cat_or_bd_txt = $admin_txt{'739'}; $admin_txt{'739c'} =~ s/{(.*?)}/$1/gsm; $admin_txt{'739d'} =~ s/{(.*?)}/$1/gsm; $admin_txt{'739f'} =~ s/{(.*?)}/$1/gsm; } $yymain .= qq~

$admin_img{'board'} $cur_txt ($curname)
~; if ($bdnum) { $yymain .= qq~
$boardslist
$admin_txt{'739d'}
~; if ( $#categoryorder > 0 ) { $yymain .= qq~

~; } $yymain .= qq~

 
~; } else { $yymain .= qq~
$admin_txt{'739e'}
~; } $yymain .= q~
~; $yymain .= qq~ ~; $yytitle = "$admin_txt{'832'}"; $action_area = 'manageboards'; AdminTemplate(); return; } sub ReorderBoards2 { is_admin_or_gmod(); get_forum_master(); if ( $INFO{'subboards'} ) { @itemorder = split /\|/xsm, $subboard{ $INFO{'item'} }; } else { @itemorder = split /,/xsm, $cat{ $INFO{'item'} }; } LoadBoardControl(); my $moveitem = $FORM{'selectboards'}; my $catorbd = $INFO{'item'}; my @updatecats; if ($moveitem) { if ( $FORM{'moveup'} || $FORM{'movedown'} ) { if ( $FORM{'moveup'} ) { for my $i ( 0 .. ( @itemorder - 1 ) ) { if ( $itemorder[$i] eq $moveitem && $i > 0 ) { $j = $i - 1; $itemorder[$i] = $itemorder[$j]; $itemorder[$j] = $moveitem; last; } } } elsif ( $FORM{'movedown'} ) { for my $i ( 0 .. ( @itemorder - 1 ) ) { if ( $itemorder[$i] eq $moveitem && $i < $#itemorder ) { $j = $i + 1; $itemorder[$i] = $itemorder[$j]; $itemorder[$j] = $moveitem; last; } } } if ( $INFO{'subboards'} ) { $subboard{$catorbd} = join q{|}, grep { $_; } @itemorder; } else { $cat{$catorbd} = join q{,}, grep { $_; } @itemorder; } } else { my $category = ${ $uid . $moveitem }{'cat'}; if ( ${ $uid . $moveitem }{'cat'} ne $FORM{'selectcategory'} ) { ${ $uid . $moveitem }{'cat'} = qq~$FORM{'selectcategory'}~; my @bdlist = split /,/xsm, $cat{$category}; # recursively change the category of child boards. if ( $subboard{$moveitem} ) { *cat_change2 = sub { my @x = @_; foreach my $childbd (@x) { ${ $uid . $childbd }{'cat'} = qq~$FORM{'selectcategory'}~; push @updatecats, $childbd; if ( $subboard{$childbd} ) { cat_change2( split /\|/xsm, $subboard{$childbd} ); } } }; cat_change2( split /\|/xsm, $subboard{$moveitem} ); } # remove from the category list only if it was not a subboard if ( !${ $uid . $moveitem }{'parent'} ) { my $k = 0; foreach my $bd (@bdlist) { if ( $moveitem eq $bd ) { splice @bdlist, $k, 1; } $k++; } $cat{$category} = join q{,}, @bdlist; } # add to new category if there's no parent selected if ( !$FORM{'selectboard'} ) { # add to new cat list my $ncat = $FORM{'selectcategory'}; if ( $cat{$ncat} ne q{} ) { $cat{$ncat} .= ",$moveitem"; } else { $cat{$ncat} = $moveitem; } } } # if parent has changed if ( ${ $uid . $moveitem }{'parent'} ne $FORM{'selectboard'} ) { # if it had a parent, remove it from that list, otherwise it didnt have a parent so remove it from cat list if ( ${ $uid . $moveitem }{'parent'} ) { my @bdlist = split /\|/xsm, $subboard{ ${ $uid . $moveitem }{'parent'} }; # Remove Board from old parent board my $k = 0; foreach my $bd (@bdlist) { if ( $moveitem eq $bd ) { splice @bdlist, $k, 1; } $k++; } $subboard{ ${ $uid . $moveitem }{'parent'} } = join q{|}, @bdlist; } # only remove from old category if it now has a parent and its in the same cat as before, otherwise # cat had to have been changed to get a parent in a different cat, and the cat change takes care of # removing it from the previous category elsif ( $category eq $FORM{'selectcategory'} ) { my @bdlist = split /,/xsm, $cat{$category}; # Remove Board from old Category my $k = 0; foreach my $bd (@bdlist) { if ( $moveitem eq $bd ) { splice @bdlist, $k, 1; } $k++; } $cat{$category} = join q{,}, @bdlist; } # if we're removing the parent board, move it back up to it's category, otherwise add to new parent board if ( $FORM{'selectboard'} eq q{} ) { # only move up to cat if cat is the same as previously if ( $category eq $FORM{'selectcategory'} ) { my @bdlist = split /\,/xsm, $cat{ $FORM{'selectcategory'} }; push @bdlist, "$moveitem"; $cat{ $FORM{'selectcategory'} } = join q{,}, @bdlist; } } else { # Add to new parent board if ( $subboard{ $FORM{'selectboard'} } ) { $subboard{ $FORM{'selectboard'} } .= qq~|$moveitem~; } else { $subboard{ $FORM{'selectboard'} } = $moveitem; } } ${ $uid . $moveitem }{'parent'} = $FORM{'selectboard'}; } } Write_ForumMaster(); fopen( FORUMCONTROL, "+<$boardsdir/forum.control" ); seek FORUMCONTROL, 0, 0; my @oldcontrols = ; for my $cnt ( 0 .. ( @oldcontrols - 1 ) ) { my ( undef, $oldboard, $pic, $bdescription, $moderators, $moderatorgroups, $topicperms, $replyperms, $pollperms, $zero, $membergroups, $ann, $rbin, $att, $minage, $maxage, $gender, $canpost, $parent, $rules, $brulestitle, $brulesdesc, $rulescollapse,$brdpasswr,$brdpassw, $brdrss ) = split /\|/xsm, $oldcontrols[$cnt]; if ( $moveitem eq $oldboard ) { $oldcontrols[$cnt] = qq~${$uid.$moveitem}{'cat'}|$moveitem|$pic|$bdescription|$moderators|$moderatorgroups|$topicperms|$replyperms|$pollperms|$zero|$membergroups|$ann|$rbin|$att|$minage|$maxage|$gender|$canpost|${$uid.$moveitem}{'parent'}|$rules|$rulestitle|$rulesdesc|$rulescollapse|$brdpasswr|$brdpassw|$brdrss\n~; } foreach my $changedboard (@updatecats) { if ( $changedboard eq $oldboard ) { $oldcontrols[$cnt] = qq~${$uid.$changedboard}{'cat'}|$changedboard|$pic|$bdescription|$moderators|$moderatorgroups|$topicperms|$replyperms|$pollperms|$zero|$membergroups|$ann|$rbin|$att|$minage|$maxage|$gender|$canpost|${$uid.$changedboard}{'parent'}|$rules|$rulestitle|$rulesdesc|$rulescollapse|$brdpasswr|$brdpassw|$brdrss\n~; } } } my @boardcontrol = grep { $_; } @oldcontrols; truncate FORUMCONTROL, 0; seek FORUMCONTROL, 0, 0; print {FORUMCONTROL} sort @boardcontrol or croak "$croak{'print'} FORUMCONTROL"; fclose(FORUMCONTROL); } $yySetLocation = qq~$adminurl?action=reorderboards;item=$category;theboard=$moveitem~; if ( !$INFO{'subboards'} ) { $yySetLocation = qq~$adminurl?action=reorderboards;item=$catorbd;theboard=$moveitem~; } else { $yySetLocation = qq~$adminurl?action=reorderboards;item=$catorbd;theboard=$moveitem;subboards=1~; } redirectexit(); return; } sub ConfRemBoard { $yymain .= qq~
$admin_txt{'31'} - '$FORM{'boardname'}'?
$admin_txt{'617'}
$admin_txt{'163'} - $admin_txt{'164'}
~; $yytitle = "$admin_txt{'31'} - '$FORM{'boardname'}'?"; $action_area = 'manageboards'; AdminTemplate(); return; } 1;