F:\WEBSITES\testbed\zipped\yabb_svn_new\branches\2.5.2\cgi-bin\yabb2\Sources\MoveSplitSplice.pl F:\WEBSITES\testbed\zipped\yabb_svn_new\trunk\cgi-bin\yabb2\Sources\MoveSplitSplice.pm
############################################################################### ###############################################################################
# MoveSplitSplice.pl                                                          # # MoveSplitSplice.pm                                                          #
  # $Date: 01.05.16 $                                                           #
############################################################################### ###############################################################################
# YaBB: Yet another Bulletin Board                                            # # YaBB: Yet another Bulletin Board                                            #
# Open-Source Community Software for Webmasters                               # # Open-Source Community Software for Webmasters                               #
# Version:        YaBB 2.5.2                                                  # # Version:        YaBB 2.6.12                                                 #
# Packaged:       October 21, 2012                                            # # Packaged:       January 5, 2016                                             #
# Distributed by: http://www.yabbforum.com                                    # # Distributed by: http://www.yabbforum.com                                    #
# =========================================================================== # # =========================================================================== #
# Copyright (c) 2000-2012 YaBB (www.yabbforum.com) - All Rights Reserved.     # # Copyright (c) 2000-2016 YaBB (www.yabbforum.com) - All Rights Reserved.     #
# Software by:  The YaBB Development Team                                     # # Software by:  The YaBB Development Team                                     #
#               with assistance from the YaBB community.                      # #               with assistance from the YaBB community.                      #
############################################################################### ###############################################################################
  use CGI::Carp qw(fatalsToBrowser);
  our $VERSION = '2.6.12';
   
$movesplitspliceplver = 'YaBB 2.5.2 $Revision: 1.0 $'; $movesplitsplicepmver = 'YaBB 2.6.12 $Revision: 1710 $';
if ($action eq 'detailedversion') { return 1; } if ( $action eq 'detailedversion' ) { return 1; }
   
&LoadLanguage('MoveSplitSplice');  LoadLanguage('MoveSplitSplice'); 
   
sub Split_Splice {  get_template('Display'); 
   if (!$staff) { &fatal_error("split_splice_not_allowed"); }  
   &Split_Splice_2 if $FORM{'ss_submit'} || $INFO{'ss_submit'};  
   
   $output = qq~<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">  
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">  
<head>  
<title>$sstxt{'1'}</title>  
<meta http-equiv="Content-Type" content="text/html; charset=$yycharset" />  
<link rel="stylesheet" href="$forumstylesurl/$usestyle.css" type="text/css" />  
   
</head>  sub Split_Splice { 
<body>     if ( !$staff ) { fatal_error('split_splice_not_allowed'); } 
<a name="pagetop">&nbsp;</a><br />     if ( $FORM{'ss_submit'} || $INFO{'ss_submit'} ) { Split_Splice_2(); } 
<div id="maincontainer">  
<div id="container">  
<br />  
<br />~;  
   
   my $curboard  = $INFO{'board'};  
   my $curthread = $INFO{'thread'};  
   unless (exists $FORM{'oldposts'}) { $FORM{'oldposts'} = $INFO{'oldposts'}; }  
   unless (exists $FORM{'leave'})    { $FORM{'leave'} = $INFO{'leave'}; }  
   if     (exists $INFO{'newinfo'})  { $FORM{'newinfo'} = $INFO{'newinfo'}; }  
   my $newcat    = $FORM{'newcat'} || $INFO{'newcat'};  
   my $newboard  = $FORM{'newboard'} || $INFO{'newboard'};  
   unless (exists $FORM{'newthread'}) { $FORM{'newthread'} = $INFO{'newthread'}; }  
   my $newthread = $FORM{'newthread'} || "new";  
   unless (exists $FORM{'newthread_subject'}) { $FORM{'newthread_subject'} = $INFO{'newthread_subject'}; }  
   unless (exists $FORM{'position'})          { $FORM{'position'} = $INFO{'position'}; }  
   
   require "$sourcedir/YaBBC.pl";  
   &LoadCensorList;  
   
   # Get posts of current thread  
   unless (ref($thread_arrayref{$curthread})) {  
       fopen(FILE, "$datadir/$curthread.txt");  
       @{$thread_arrayref{$curthread}} = <FILE>;  
       fclose(FILE);  
   }  
   my @messages = @{$thread_arrayref{$curthread}};  
   
   my ($counter,$size1);  
   for ($counter = 0; $counter < @messages; $counter++) {  
       $message = (split(/\|/, $messages[$counter], 10))[8];  
       ($message, undef) = &Split_Splice_Move($message,1);  
       &DoUBBC;  
   
       $convertstr = $message;  
       $convertcut = 50;  
       &CountChars;  
       $message = $convertstr;  
       $message .= " ..." if $cliped;  
   
       &ToChars($message);  
       $message =~ s/<(p|br|div).*?>/ /g;  
       $message =~ s/<.*?>//g; # remove HTML-tags  
       $message = &Censor($message);  
   
       $messages[$counter] = qq~<option value="$counter" ~ . ($FORM{'oldposts'} =~ /\b$counter\b/ ? q~selected="selected"~ : '') . qq~>~ . ($counter ? "$sstxt{'40'} $counter" : $sstxt{'41'}) . qq~: $message</option>\n~;  
   }  
   @messages = reverse(@messages) if ($ttsureverse && ${$uid.$username}{'reversetopic'}) || $ttsreverse;  
   my $postlist = ($FORM{'oldposts'} eq "all" ? qq~<option value="all" selected="selected">$sstxt{'26'}</option>\n~ : qq~<option value="all">$sstxt{'26'}</option>\n~) . join('', @messages);  
   $size1 = @messages + 1;  
   $size1 = $size1 > 10 ? 10 : $size1; # maximum size of multiselect field  
   
   # List of options of what, if anything, to leave in place of the posts moved  
   my @leaveopts = ($sstxt{'11'}, $sstxt{'12'}, $sstxt{'13'});  
   for ($counter = 0; $counter < @leaveopts; $counter++) {  
       $leavelist .= qq~<option value="$counter" ~ . ($FORM{'leave'} == $counter ? q~selected="selected"~ : '') . qq~>$leaveopts[$counter]</option>\n~;  
   }  
   
   # Get categories and make the current one the default selection  
   my $catlist = qq~<option value="cats" >$sstxt{'28'}</option>\n~;  
   foreach (@categoryorder) {  
       my ($catname, $catperms) = split(/\|/, $catinfo{$_}, 3);  
       next if !&CatAccess($catperms);  
       $catlist .= qq~<option value="$_" ~ . ($newcat eq $_ ? q~selected="selected"~ : '') . qq~>$catname</option>\n~;  
   }  
   
   # Get boards and make the current one the default selection  
   $boardlist = qq~<option value="boards" >$sstxt{'29'}</option>\n~;  
   foreach (split (/,/, $cat{$newcat})) {  
       my ($boardname, $boardperms) = split(/\|/, $board{$_}, 3);  
       my $access = &AccessCheck($_, '', $boardperms);  
       next if !$iamadmin && $access ne "granted" && $boardview != 1;  
       $boardlist .= qq~<option value="$_" ~ . ($newboard eq $_ ? q~selected="selected"~ : '') . qq~>$boardname</option>\n~;  
   }  
   
   # Get threads and make the current one the default selection  
   my ($threadlist,$threadids,$positionlist);  
   if ($cat{$newcat} =~ /\b$newboard\b/) {  
       fopen(FILE, "$boardsdir/$newboard.txt");  
       my @threads = <FILE>;  
       fclose(FILE);  
   
       $threadlist = qq~<option value="new">$sstxt{'30'}</option>\n~;  
       my $threadid;  
       foreach (@threads) {  
           ($threadid, $message, undef) = split(/\|/, $_, 3);  
           next if $curthread eq $threadid;  
           $threadids .= "$threadid,";  
   
           ($message, undef) = &Split_Splice_Move($message,$threadid);  
           &DoUBBC;  
   
           $convertstr = $message;  
           $convertcut = 50;  
           &CountChars;  
           $message = $convertstr;  
           $message .= " ..." if $cliped;  
   
           &ToChars($message);  
           $message =~ s/<(p|br|div).*?>/ /g;  
           $message =~ s/<.*?>//g; # remove HTML-tags  
           $message = &Censor($message);  
   
           $threadlist .= qq~<option value="$threadid" ~ . ($newthread eq $threadid ? q~selected="selected"~ : '') . qq~>$message</option>\n~;  
       }  
   
       # Get new thread posts to select splice site  
       if ($FORM{'newthread'} ne "new") {  
           unless (ref($thread_arrayref{$newthread})) {  
               fopen(FILE, "$datadir/$newthread.txt");  
               @{$thread_arrayref{$newthread}} = <FILE>;  
               fclose(FILE);  
           }  
           @messages = @{$thread_arrayref{$newthread}};  
   
           for ($counter = 0; $counter < @messages; $counter++) {  
               $message = (split(/[\|]/, $messages[$counter], 10))[8];  
               ($message, undef) = &Split_Splice_Move($message,1);  
               &DoUBBC;  
   
               $convertstr = $message;  
               $convertcut = 50;  
               &CountChars;  
               $message = $convertstr;  
               $message .= " ..." if $cliped;  
   
               &ToChars($message);  
               $message =~ s/<(p|br|div).*?>/ /g;  
               $message =~ s/<.*?>//g; # remove HTML-tags  
               $message = &Censor($message);  
   
               $messages[$counter] = qq~<option value="$counter">~ . ($counter ? "$sstxt{'40'} $counter" : $sstxt{'41'}) . qq~: $message</option>\n~;  
           }  
           @messages = reverse(@messages) if ($ttsureverse && ${$uid.$username}{'reversetopic'}) || $ttsreverse;  
           $positionlist = qq~<option value="end">$sstxt{'31'}</option>\n~;  
           $positionlist .= qq~<option value="begin">$sstxt{'32'}</option>\n~ . join('', @messages);  
           if ($FORM{'position'} && $newthread == $FORM{'old_position_thread'}) {  
               $positionlist =~ s/(value="$FORM{'position'}")/$1 selected="selected"/;  
           }  
       }  
   }  
   
   $output .= qq~  
<script language="JavaScript1.2" src="$yyhtml_root/ubbc.js" type="text/javascript"></script>  
<form action="$scripturl?action=split_splice;board=$currentboard;thread=$INFO{'thread'}" method="post" name="split_splice" onsubmit="return submitproc()">  
<input type="hidden" name="formsession" value="$formsession" />  
<table border="0" cellspacing="1" cellpadding="8" class="bordercolor" align="center" width="90%">  
   <tr>  
       <td class="titlebg"><img src="$defaultimagesdir/admin_move_split_splice.gif" alt="$sstxt{'1'}" /> <b>$sstxt{'1'}</b></td>  
   </tr><tr>  
       <td class="catbg"><b>$sstxt{'2'}:</b></td>  
   </tr><tr>  
       <td class="windowbg"><b>$sstxt{'3'}</b></td>  
   </tr><tr>  
       <td class="windowbg2">  
           <label for="oldposts">$sstxt{'14'}<br />  
           <select name="oldposts" id="oldposts" size="$size1" multiple="multiple">$postlist</select><br />  
           <span class="small">$sstxt{'14a'}</span></label>  
       </td>  
   </tr><tr>  
       <td class="windowbg"><b>$sstxt{'4'}</b></td>  
   </tr><tr>  
       <td class="windowbg2">  
           <label for="leave">$sstxt{'15'}</label><br />  
           <select name="leave" id="leave">$leavelist</select>  
       </td>  
   </tr><tr>  
       <td class="catbg"><b>$sstxt{'5'}:</b></td>  
   </tr><tr>  
       <td class="windowbg"><b>$sstxt{'6'}</b></td>  
   </tr><tr>  
       <td class="windowbg2">  
           <label for="newcat">$sstxt{'16'}</label><br />  
           <select name="newcat" id="newcat" onchange="document.split_splice.submit();">$catlist</select>  
       </td>  
   </tr><tr>  
       <td class="windowbg"><b>$sstxt{'7'}</b></td>  
   </tr><tr>  
       <td class="windowbg2">  
           <label for="newboard">$sstxt{'17'}</label><br />  
           <select name="newboard" id="newboard" onchange="document.split_splice.submit();">$boardlist</select>  
       </td>  
   </tr><tr>  
       <td class="windowbg"><b>$sstxt{'8'}</b></td>  
   </tr><tr>  
       <td class="windowbg2">  
           <label for="newthread">$sstxt{'18'}</label><br />  
           <select name="newthread" id="newthread" onchange="document.split_splice.submit();">$threadlist</select>  
       </td>  
   </tr>~;  
   
   if ($newthread eq "new" || !$threadlist || $threadids !~ /\b$newthread\b/){  
       $output .= qq~<tr>  
       <td class="windowbg"><b>$sstxt{'9'}</b></td>  
   </tr><tr>  
       <td class="windowbg2">  
           <label for="newthread_subject">$sstxt{'20'}</label><br />  
           <input type="text" name="newthread_subject" id="newthread_subject" size="50" value="$FORM{'newthread_subject'}" />  
           <input type="hidden" name="position" value="$FORM{'position'}" />  
           <input type="hidden" name="old_position_thread" value="$FORM{'old_position_thread'}" />  
       </td>  
   </tr>~;  
   
   } else {  
       $output .= qq~<tr>  
       <td class="windowbg"><b>$sstxt{'10'}</b></td>  
   </tr><tr>  
       <td class="windowbg2">  
           <label for="position">$sstxt{'19'}</label><br />  
           <select name="position" id="position">$positionlist</select>  
           <input type="hidden" name="newthread_subject" value="$FORM{'newthread_subject'}" />  
           <input type="hidden" name="old_position_thread" value="$newthread" />  
       </td>  
   </tr>~;  
   }  
   
   $output .= qq~<tr>  
       <td class="windowbg"><b>$sstxt{'4'}</b></td>  
   </tr><tr>  
       <td class="windowbg2">  
           <input type="checkbox" name="newinfo" id="newinfo" value="1"~ . ($FORM{'newinfo'} ? ' checked="checked"' : '') . qq~ /> <label for="newinfo">$sstxt{'15a'}</label>  
       </td>  
   </tr><tr>  
       <td class="catbg" align="center"><input type="submit" name="ss_submit" value="$sstxt{'24'}" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="reset" value="$sstxt{'25'}" /></td>  
   </tr>  
</table>  
</form>  
<br />  
<br />  
</div>  
</div>  
</body>  
</html>~;  
   
   &print_output_header;     my $curboard  = $INFO{'board'}; 
   &print_HTML_output_and_finish;     my $curthread = $INFO{'thread'}; 
     if ( !exists $FORM{'oldposts'} ) { $FORM{'oldposts'} = $INFO{'oldposts'}; }
     if ( !exists $FORM{'leave'} )    { $FORM{'leave'}    = $INFO{'leave'}; }
     if ( exists $INFO{'newinfo'} )   { $FORM{'newinfo'}  = $INFO{'newinfo'}; }
     my $newcat   = $FORM{'newcat'}   || $INFO{'newcat'};
     my $newboard = $FORM{'newboard'} || $INFO{'newboard'};
     if ( !exists $FORM{'newthread'} ) {
         $FORM{'newthread'} = $INFO{'newthread'};
     }
     my $newthread = $FORM{'newthread'} || 'new';
     if ( !exists $FORM{'newthread_subject'} ) {
         $FORM{'newthread_subject'} = $INFO{'newthread_subject'};
     }
     if ( !exists $FORM{'position'} ) { $FORM{'position'} = $INFO{'position'}; }
   
     require Sources::YaBBC;
     LoadCensorList();
   
     # Get posts of current thread
     if ( !ref $thread_arrayref{$curthread} ) {
         fopen( FILE, "$datadir/$curthread.txt" );
         @{ $thread_arrayref{$curthread} } = <FILE>;
         fclose(FILE);
     }
     my @messages = @{ $thread_arrayref{$curthread} };
   
     my ( $counter, $size1 );
     for my $counter ( 0 .. $#messages ) {
         $message = ( split /\|/xsm, $messages[$counter], 10 )[8];
         ( $message, undef ) = Split_Splice_Move( $message, 1 );
         DoUBBC();
   
         $convertstr = $message;
         $convertstr =~ s/<(p|br|div).*?>/ /gxsm;
         $convertstr =~ s/<.*?>//gxsm;              # remove HTML-tags
         $convertcut = 50;
         CountChars();
         $message = $convertstr;
         if ($cliped) { $message .= ' ...'; }
   
         ToChars($message);
         $message = Censor($message);
   
         $messages[$counter] = qq~<option value="$counter" ~
           . (
             $FORM{'oldposts'} =~ /\b$counter\b/xsm
             ? q~selected="selected"~
             : q{}
           )
           . q~>~
           . ( $counter ? "$sstxt{'40'} $counter" : $sstxt{'41'} )
           . qq~: $message</option>\n~;
     }
     if ( ( $ttsureverse && ${ $uid . $username }{'reversetopic'} )
         || $ttsreverse )
     {
         @messages = reverse @messages;
     }
     my $postlist = (
         $FORM{'oldposts'} eq 'all' 
         ? qq~<option value="all" selected="selected">$sstxt{'26'}</option>\n~
         : qq~<option value="all">$sstxt{'26'}</option>\n~
     ) . join q{}, @messages;
     $size1 = @messages + 1;
     $size1 = $size1 > 10 ? 10 : $size1;    # maximum size of multiselect field
   
     # List of options of what, if anything, to leave in place of the posts moved
     my @leaveopts = ( $sstxt{'11'}, $sstxt{'12'}, $sstxt{'13'} );
     for my $counter ( 0 .. $#leaveopts ) {
         $leavelist .=
             qq~<option value="$counter" ~
           . ( $FORM{'leave'} == $counter ? q~selected="selected"~ : q{} )
           . qq~>$leaveopts[$counter]</option>\n~;
     }
   
     # Get categories and make the current one the default selection
     my $catlist = qq~<option value="cats" >$sstxt{'28'}</option>\n~;
     foreach (@categoryorder) {
         my ( $catname, $catperms ) = split /\|/xsm, $catinfo{$_}, 3;
         next if !CatAccess($catperms);
         $catlist .=
             qq~<option value="$_" ~
           . ( $newcat eq $_ ? q~selected="selected"~ : q{} )
           . qq~>$catname</option>\n~;
     }
   
     # Get boards and make the current one the default selection
     $boardlist = qq~<option value="boards">$sstxt{'29'}</option>\n~;
     my $indent = -2;
   
     *get_subboards = sub {
         my @x = @_;
         $indent += 2;
         foreach my $childbd (@x) {
             my $dash;
             if ( $indent > 0 ) { $dash = q{-}; }
             my ( $boardname, $boardperms ) = split /\|/xsm, $board{$childbd}, 3;
             ToChars($boardname);
             my $access = AccessCheck( $_, q{}, $boardperms );
             next if !$iamadmin && $access ne 'granted' && $boardview != 1;
   
             my $bdnopost =
               ( ${ $uid . $childbd }{'canpost'} || !$subboard{$childbd} )
               ? q{}
               : q~ class="nopost"~;
             $boardlist .=
                 qq~<option$bdnopost value="$childbd" ~
               . ( $newboard eq $childbd ? q~selected="selected"~ : q{} ) . q~>~
               . ( '&nbsp;' x $indent )
               . ( $dash x ( $indent / 2 ) )
               . qq~&nbsp;$boardname</option>\n~;
   
             if ( $subboard{$childbd} ) {
                 get_subboards( split /\|/xsm, $subboard{$childbd} );
             }
         }
         $indent -= 2;
         return;
     };
     get_subboards( split /,/xsm, $cat{$newcat} );
   
     # Get threads and make the current one the default selection
     my ( $threadlist, $threadids, $positionlist );
     fopen( FILE, "$boardsdir/$newboard.txt" );
     my @threads = <FILE>;
     fclose(FILE);
   
     $threadlist = qq~<option value="new">$sstxt{'30'}</option>\n~;
     my $threadid;
     foreach (@threads) {
         ( $threadid, $message, undef ) = split /\|/xsm, $_, 3;
         next if $curthread eq $threadid;
         $threadids .= "$threadid,";
   
         ( $message, undef ) = Split_Splice_Move( $message, $threadid );
         DoUBBC();
   
         $convertstr = $message;
         $convertcut = 50;
         CountChars();
         $message = $convertstr;
         if ($cliped) { $message .= ' ...'; }
   
         ToChars($message);
         $message =~ s/<(p|br|div).*?>/ /gxsm;
         $message =~ s/<.*?>//gxsm;              # remove HTML-tags
         $message = Censor($message);
   
         $threadlist .=
             qq~<option value="$threadid" ~
           . ( $newthread eq $threadid ? q~selected="selected"~ : q{} )
           . qq~>$message</option>\n~;
     }
   
     # Get new thread posts to select splice site
     if ( $FORM{'newthread'} ne 'new' ) {
         if ( !ref $thread_arrayref{$newthread} ) {
             fopen( FILE, "$datadir/$newthread.txt" );
             @{ $thread_arrayref{$newthread} } = <FILE>;
             fclose(FILE);
         }
         @messages = @{ $thread_arrayref{$newthread} };
   
         for my $counter ( 0 .. $#messages ) {
             $message = ( split /[\|]/xsm, $messages[$counter], 10 )[8];
             ( $message, undef ) = Split_Splice_Move( $message, 1 );
             DoUBBC();
   
             $convertstr = $message;
             $convertcut = 50;
             CountChars();
             $message = $convertstr;
             if ($cliped) { $message .= ' ...'; }
   
             ToChars($message);
             $message =~ s/<(p|br|div).*?>/ /gxsm;
             $message =~ s/<.*?>//gxsm;              # remove HTML-tags
             $message = Censor($message);
   
             $messages[$counter] =
                 qq~<option value="$counter">~
               . ( $counter ? "$sstxt{'40'} $counter" : $sstxt{'41'} )
               . qq~: $message</option>\n~;
         }
         if ( ( $ttsureverse && ${ $uid . $username }{'reversetopic'} )
             || $ttsreverse )
         {
             @messages = reverse @messages;
         }
         $positionlist = qq~<option value="end">$sstxt{'31'}</option>\n~;
         $positionlist .=
           qq~<option value="begin">$sstxt{'32'}</option>\n~;
         $positionlist .= join q{}, @messages;
         if (   $FORM{'position'}
             && $newthread == $FORM{'old_position_thread'} )
         {
             $positionlist =~
               s/(value="$FORM{'position'}")/$1 selected="selected"/xsm;
         }
     }
   
     if (   $newthread eq 'new' 
         || !$threadlist
         || $threadids !~ /\b$newthread\b/xsm )
     {
         $my_output = $mymove_output_a;
         $my_output =~ s/{yabb newthread_subject}/$FORM{'newthread_subject'}/sm;
         $my_output =~ s/{yabb position}/$FORM{'position'}/sm;
         $my_output =~
           s/{yabb old_position_thread}/$FORM{'old_position_thread'}/sm;
     }
     else {
         $my_output = $mymove_output_b;
         $my_output =~ s/{yabb positionlist}/$positionlist/sm;
         $my_output =~ s/{yabb newthread_subject}/$FORM{'newthread_subject'}/sm;
         $my_output =~ s/{yabb newthread}/$newthread/sm;
     }
   
     $my_checked = $FORM{'newinfo'} ? ' checked="checked"' : q{};
   
     $output = $mymove_top;
     $output =~ s/{yabb formsession}/$formsession/sm;
     $output =~ s/{yabb postlist}/$postlist/sm;
     $output =~ s/{yabb leavelist}/$leavelist/sm;
     $output =~ s/{yabb catlist}/$catlist/sm;
     $output =~ s/{yabb boardlist}/$boardlist/sm;
     $output =~ s/{yabb threadlist}/$threadlist/sm;
     $output =~ s/{yabb my_output}/$my_output/sm;
     $output =~ s/{yabb my_checked}/$my_checked/sm;
     $output =~ s/{yabb size1}/$size1/sm;
   
     print_output_header();
     print_HTML_output_and_finish();
     return;
} }
   
sub Split_Splice_2 { sub Split_Splice_2 {
   if (!$staff && $INFO{'newboard'} ne $binboard) { &fatal_error("split_splice_not_allowed"); }     if ( !$staff && $INFO{'newboard'} ne $binboard ) { 
         fatal_error('split_splice_not_allowed');
   my $curboard       = $INFO{'board'};     } 
   my $curthreadid    = $INFO{'thread'};  
   my $movingposts    = exists $INFO{'oldposts'} ? $INFO{'oldposts'} : $FORM{'oldposts'};     my $curboard    = $INFO{'board'}; 
   $FORM{'oldposts'}  = $movingposts;     my $curthreadid = $INFO{'thread'}; 
   my $leavemess      = exists $INFO{'leave'} ? $INFO{'leave'} : $FORM{'leave'};     my $movingposts = 
   my $forcenewinfo   = exists $INFO{'newinfo'} ? $INFO{'newinfo'} : $FORM{'newinfo'};       exists $INFO{'oldposts'} ? $INFO{'oldposts'} : $FORM{'oldposts'}; 
   my $newcat         = exists $INFO{'newcat'} ? $INFO{'newcat'} : $FORM{'newcat'};     $FORM{'oldposts'} = $movingposts; 
   my $newboard       = exists $INFO{'newboard'} ? $INFO{'newboard'} : $FORM{'newboard'};     my $leavemess = exists $INFO{'leave'} ? $INFO{'leave'} : $FORM{'leave'}; 
   my $newthreadid    = exists $INFO{'newthread'} ? $INFO{'newthread'} : $FORM{'newthread'};     my $forcenewinfo = 
   $FORM{'newthread'} = $newthreadid;       exists $INFO{'newinfo'} ? $INFO{'newinfo'} : $FORM{'newinfo'}; 
   my $newthreadsub   = exists $INFO{'newthread_subject'} ? $INFO{'newthread_subject'} : $FORM{'newthread_subject'};     my $newcat = exists $INFO{'newcat'} ? $INFO{'newcat'} : $FORM{'newcat'}; 
   my $newposition    = exists $INFO{'position'} ? $INFO{'position'} : $FORM{'position'};     my $newboard = 
   $FORM{'position'}  = $newposition;       exists $INFO{'newboard'} ? $INFO{'newboard'} : $FORM{'newboard'}; 
     my $newthreadid =
   # Error messages if something is not filled out right       exists $INFO{'newthread'} ? $INFO{'newthread'} : $FORM{'newthread'}; 
   &fatal_error('',"$sstxt{'22b'} $sstxt{'23'} $sstxt{'50'}") if $movingposts eq '';     $FORM{'newthread'} = $newthreadid; 
   &fatal_error('',"$sstxt{'22'}") if $newcat eq 'cats';     my $newthreadsub = 
   &fatal_error('',"$sstxt{'22a'}") if $newboard eq 'boards';       exists $INFO{'newthread_subject'} 
   &fatal_error('',"$sstxt{'51'} $sstxt{'50'}") if -e "$datadir/$curthreadid.poll" && -e "$datadir/$newthreadid.poll";       ? $INFO{'newthread_subject'} 
       : $FORM{'newthread_subject'};
   my (@postnum,@utdcurthread,@utdnewthread,$i);     my $newposition = 
   my $linkcount = 0;       exists $INFO{'position'} ? $INFO{'position'} : $FORM{'position'}; 
     $FORM{'position'} = $newposition;
   # Get current thread posts  
   unless (ref($thread_arrayref{$curthreadid})) {     # Error messages if something is not filled out right 
       fopen(FILE, "$datadir/$curthreadid.txt");     if ( $movingposts eq q{} ) { 
       @{$thread_arrayref{$curthreadid}} = <FILE>;         fatal_error( q{}, "$sstxt{'22b'} $sstxt{'23'} $sstxt{'50'}" ); 
       fclose(FILE);     } 
   }    if ( $newcat   eq 'cats' )   { fatal_error( q{}, "$sstxt{'22'}" ); }
   my @curthread = @{$thread_arrayref{$curthreadid}};     if ( $newboard eq 'boards' ) { fatal_error( q{}, "$sstxt{'22a'}" ); } 
   &MessageTotals("load", $curthreadid);     if ( -e "$datadir/$curthreadid.poll" && -e "$datadir/$newthreadid.poll" ) { 
         fatal_error( q{}, "$sstxt{'51'} $sstxt{'50'}" );
   # Store post numbers to be moved in array     } 
   if ((split(/\, /, $movingposts, 2))[0] eq "all") { @postnum = (0 .. $#curthread); }  
   else { @postnum = sort {$a <=> $b} split(/\, /, $movingposts); } # sort numerically ascending because may be reversed!     my ( @postnum, @utdcurthread, @utdnewthread, $i ); 
     my $linkcount = 0;
   # Check to see if current thread was the latest post for the board and if the last post was selected to change  
   &BoardTotals("load", $curboard);     # Get current thread posts 
   if(${$curthreadid}{'lastpostdate'} == ${$uid.$curboard}{'lastposttime'} && $leavemess == 2 && $postnum[$#postnum] == $#curthread) {    if ( !ref $thread_arrayref{$curthreadid} ) {
       $newest_post = 1;         fopen( FILE, "$datadir/$curthreadid.txt" ); 
   }         @{ $thread_arrayref{$curthreadid} } = <FILE>; 
         fclose(FILE);
   # Move selected posts to a brand new thread     } 
   if ($newthreadid eq "new") {     my @curthread = @{ $thread_arrayref{$curthreadid} }; 
       # Find a valid random ID for new thread.     MessageTotals( 'load', $curthreadid ); 
       $newthreadid = (split(/\|/, $curthread[$postnum[0]], 5))[3] + 1;  
       while (-e "$datadir/$newthreadid.txt") { $newthreadid++; }     # Store post numbers to be moved in array 
     if ( ( split /\, /sm, $movingposts, 2 )[0] eq 'all' ) {
       foreach (@postnum) {         @postnum = ( 0 .. $#curthread ); 
           if ($newthreadsub || $leavemess == 1) { # insert new subject name || add 'no_postcount' into copies     } 
               my @x = split(/\|/, $curthread[$_]);     else { 
               if ($newthreadsub) { $x[0] = $_ == $postnum[0] ? $newthreadsub : qq~$sstxt{'21'} $newthreadsub~; }         @postnum = sort { $a <=> $b } split /\, /sm, $movingposts; 
               if ($leavemess == 1) { $x[5] = 'no_postcount'; }     }    # sort numerically ascending because may be reversed! 
               push(@utdnewthread, join('|', @x));  
           } else {  # Check to see if current thread was the latest post for the board and if the last post was selected to change 
               push(@utdnewthread, $curthread[$_]);     BoardTotals( 'load', $curboard ); 
           }     if ( 
       }         ${$curthreadid}{'lastpostdate'} == ${ $uid . $curboard }{'lastposttime'} 
         && $leavemess == 2
   # Place selected posts in existing thread at selected position         && $postnum[-1] == $#curthread ) 
   } else {    {
       # Get existing thread posts         $newest_post = 1; 
       unless (ref($thread_arrayref{$newthreadid})) {     } 
           fopen(FILE, "$datadir/$newthreadid.txt");  
           @{$thread_arrayref{$newthreadid}} = <FILE>;     # Move selected posts to a brand new thread 
           fclose(FILE);     if ( $newthreadid eq 'new' ) { 
       }  
       my @newthread = @{$thread_arrayref{$newthreadid}};         # Find a valid random ID for new thread. 
       &MessageTotals("load", $newthreadid);         $newthreadid = ( split /\|/xsm, $curthread[ $postnum[0] ], 5 )[3] + 1; 
         while ( -e "$datadir/$newthreadid.txt" ) { $newthreadid++; }
       if    ($newposition eq "end")   { $newposition = $#newthread; }  
       elsif ($newposition eq "begin") {        foreach (@postnum) {
           foreach (@postnum) {             if ( $newthreadsub || $leavemess == 1 ) 
               if ($leavemess == 1) { # add 'no_postcount' into copies            {    # insert new subject name || add 'no_postcount' into copies
                   my @x = split(/\|/, $curthread[$_]);                 my @x = split /\|/xsm, $curthread[$_]; 
                   $x[5] = 'no_postcount';                 if ($newthreadsub) { 
                   push(@utdnewthread, join('|', @x));                     $x[0] = 
               } else {                         $_ == $postnum[0] 
                   push(@utdnewthread, $curthread[$_]);                       ? $newthreadsub 
               }                       : qq~$sstxt{'21'} $newthreadsub~; 
           }                }
           $newposition = -1;                 if ( $leavemess == 1 ) { $x[5] = 'no_postcount'; } 
       }                 push @utdnewthread, join q{|}, @x; 
       for ($i = 0; $i < @newthread; $i++){             } 
           push (@utdnewthread, $newthread[$i]);             else { 
           if ($newposition == $i) {                 push @utdnewthread, $curthread[$_]; 
               foreach (@postnum) {             } 
                   if ($leavemess == 1) { # add 'no_postcount' into copies         } 
                       my @x = split(/\|/, $curthread[$_]);  
                       $x[5] = 'no_postcount';         # Place selected posts in existing thread at selected position 
                       push(@utdnewthread, join('|', @x));     } 
                   } else {    else {
                       push(@utdnewthread, $curthread[$_]);  
                   }         # Get existing thread posts 
               }         if ( !ref $thread_arrayref{$newthreadid} ) { 
               $linkcount = $i + 1;             fopen( FILE, "$datadir/$newthreadid.txt" ); 
           }             @{ $thread_arrayref{$newthreadid} } = <FILE>; 
       }             fclose(FILE); 
   }        }
         my @newthread = @{ $thread_arrayref{$newthreadid} };
   # Remove or copy selected posts from current thread         MessageTotals( 'load', $newthreadid ); 
   if ($#postnum == $#curthread && $leavemess != 1){  
       if ($newboard ne $binboard) {         if ( $newposition eq 'end' ) { $newposition = $#newthread; } 
           my ($tmpsub,$tmpmessage);         elsif ( $newposition eq 'begin' ) { 
           my $hidename = &cloak($username);             foreach (@postnum) { 
           ($tmpsub, undef) = split(/\|/, $curthread[0], 2);                 if ( $leavemess == 1 ) {    # add 'no_postcount' into copies 
           if ($curboard eq $newboard) {                     my @x = split /\|/xsm, $curthread[$_]; 
               $tmpmessage = qq~[m by=$hidename dest=$newthreadid/$linkcount#$linkcount]~;                     $x[5] = 'no_postcount'; 
               $tmpsub = qq~[m by=$hidename dest=$newthreadid]: '$tmpsub'~;                     push @utdnewthread, join q{|}, @x; 
           } else {                 } 
               $tmpmessage = qq~[m by=$hidename destboard=$newboard dest=$newthreadid/$linkcount#$linkcount]~;                 else { 
               $tmpsub = qq~[m by=$hidename destboard=$newboard dest=$newthreadid]: '$tmpsub'~;                     push @utdnewthread, $curthread[$_]; 
           }                }
           &FromChars($tmpmessage);             } 
           $utdcurthread[0] = qq~$tmpsub|${$uid.$username}{'realname'}|${$uid.$username}{'email'}|$date|$username|no_postcount||$user_ip|$tmpmessage||||\n~;             $newposition = -1; 
         }
           eval { require "$datadir/movedthreads.cgi" };         for my $i ( 0 .. $#newthread ) { 
           $moved_file{$curthreadid} = $newthreadid;             push @utdnewthread, $newthread[$i]; 
           delete $moved_file{$newthreadid};             if ( $newposition == $i ) { 
           &save_moved_file;                 foreach (@postnum) { 
           $leavemess = 0;                     if ( $leavemess == 1 ) {    # add 'no_postcount' into copies 
       } else {                         my @x = split /\|/xsm, $curthread[$_]; 
           $leavemess = 2;                         $x[5] = 'no_postcount'; 
           $forcenewinfo = 1;                         push @utdnewthread, join q{|}, @x; 
       }                    }
                     else {
   } elsif ($leavemess != 1) {                         push @utdnewthread, $curthread[$_]; 
       $leavemess = 2 if $newboard eq $binboard;                     } 
       for ($i = 0; $i < @curthread; $i++){                 } 
           if ($movingposts =~ /\b$i\b/){                 $linkcount = $i + 1; 
               if ($leavemess == 0 && $i == $postnum[$#postnum]){             } 
                   my $tmpsub;         } 
                   ($tmpsub, undef) = split(/\|/, $curthread[$i], 2);     } 
                   push (@utdcurthread, qq~$tmpsub|${$uid.$username}{'realname'}|${$uid.$username}{'email'}|$date|$username|no_postcount||$user_ip|[split] [link=$scripturl?num=$newthreadid/$linkcount#$linkcount][splithere][/link][splithere_end]||||\n~);  
               }     # Remove or copy selected posts from current thread 
           } else {    if ( $#postnum == $#curthread && $leavemess != 1 ) {
               push (@utdcurthread, $curthread[$i]);         if ( $newboard ne $binboard ) { 
           }             my ( $tmpsub, $tmpmessage ); 
       }             my $hidename = cloak($username); 
             ( $tmpsub, undef ) = split /\|/xsm, $curthread[0], 2;
   } else { @utdcurthread = @curthread; }             if ( $curboard eq $newboard ) { 
                 $tmpmessage =
   if ($forcenewinfo) {                   qq~[m by=$hidename dest=$newthreadid/$linkcount#$linkcount]~; 
       my ($boardtitle,$tmpsub,$tmpmessage);                 $tmpsub = qq~[m by=$hidename dest=$newthreadid]: '$tmpsub'~; 
       ($boardtitle, undef) = split(/\|/, $board{$curboard}, 2);             } 
       $tmpmessage = ($#postnum == $#utdnewthread ? "[b][movedhere]" : "[b][postsmovedhere1] " . @postnum . " [postsmovedhere2]") . " [i]$boardtitle\[/i] [move by] [i]${$uid.$username}{'realname'}\[/i].[/b]";             else { 
       &FromChars($tmpmessage);                 $tmpmessage = 
       ($tmpsub, undef, undef, undef, undef, undef, undef) = split(/\|/, $utdnewthread[0], 7);  qq~[m by=$hidename destboard=$newboard dest=$newthreadid/$linkcount#$linkcount]~; 
       splice(@utdnewthread, ($linkcount + @postnum), 0,qq~$sstxt{'21'} $tmpsub|${$uid.$username}{'realname'}|${$uid.$username}{'email'}|$date|$username|no_postcount||$user_ip|$tmpmessage||||\n~);                 $tmpsub = 
   }  qq~[m by=$hidename destboard=$newboard dest=$newthreadid]: '$tmpsub'~; 
             }
   if (@utdcurthread) {             FromChars($tmpmessage); 
       for ($i = 0; $i < @utdcurthread; $i++) { # sort post numbers             $utdcurthread[0] = 
           my @x = split(/\|/, $utdcurthread[$i]);  qq~$tmpsub|${$uid.$username}{'realname'}|${$uid.$username}{'email'}|$date|$username|no_postcount||$user_ip|$tmpmessage||||\n~; 
           $x[6] = $i;  
           $utdcurthread[$i] = join('|', @x);             if ( eval { require Variables::Movedthreads; 1 } ) { 
       }                 $moved_file{$curthreadid} = $newthreadid; 
       # Update current thread                 delete $moved_file{$newthreadid}; 
       fopen(FILE, ">$datadir/$curthreadid.txt");                 save_moved_file(); 
       print FILE @utdcurthread;                 $leavemess = 0; 
       fclose(FILE);             } 
   } else {         } 
       require "$sourcedir/RemoveTopic.pl";         else { 
       my $moveit = $INFO{'moveit'};             $leavemess    = 2; 
       $INFO{'moveit'} = 1;            $forcenewinfo = 1;
       &RemoveThread;         } 
       $INFO{'moveit'} = $moveit;     } 
   }     elsif ( $leavemess != 1 ) { 
         if ( $newboard eq $binboard ) { $leavemess = 2; }
   for ($i = 0; $i < @utdnewthread; $i++) { # sort post numbers         for my $i ( 0 .. $#curthread ) { 
       my @x = split(/\|/, $utdnewthread[$i]);             if ( $movingposts =~ /\b$i\b/xsm ) { 
       $x[6] = $i;                 if ( $leavemess == 0 && $i == $postnum[-1] ) { 
       $utdnewthread[$i] = join('|', @x);                     my $tmpsub; 
   }                     ( $tmpsub, undef ) = split /\|/xsm, $curthread[$i], 2; 
   # Update new thread                     push @utdcurthread, 
   fopen(FILE, ">$datadir/$newthreadid.txt");  qq~$tmpsub|${$uid.$username}{'realname'}|${$uid.$username}{'email'}|$date|$username|no_postcount||$user_ip|[split] [link=$scripturl?num=$newthreadid/$linkcount#$linkcount][splithere][/link][splithere_end]||||\n~; 
   print FILE @utdnewthread;                 } 
   fclose(FILE);             } 
             else {
   # Update the .rlog files of the users                 push @utdcurthread, $curthread[$i]; 
   my ($reply,$ms,$mn,$md,$mu,$mnp,$mi,%mu,%curthreadusersdate,%curthreaduserscount,%newthreadusersdate,%newthreaduserscount,%BoardTotals);             } 
   $reply = 0;         } 
   foreach (@utdcurthread) { # $subject|$name|$email|$date|$username|$icon|0|$user_ip|$message|$ns|||$fixfile  
       ($ms, $mn, undef, $md, $mu, $mnp, undef, $mi, undef) = split(/\|/, $_, 9);     } 
       $BoardTotals{$curthreadid} = [$md,$mu,$reply,$ms,$mn,$mi] if ${$BoardTotals{$curthreadid}}[0] <= $md;     else { @utdcurthread = @curthread; } 
       $reply++;  
       next if $mnp eq 'no_postcount';     if ($forcenewinfo) { 
       $curthreadusersdate{$mu} = $md if $curthreadusersdate{$mu} < $md;         my ( $boardtitle, $tmpsub, $tmpmessage ); 
       $curthreaduserscount{$mu}++;         ( $boardtitle, undef ) = split /\|/xsm, $board{$curboard}, 2; 
       $mu{$mu} = 1;         $tmpmessage = ( 
   }             $#postnum == $#utdnewthread 
   $reply = 0;             ? '[b][movedhere]' 
   foreach (@utdnewthread) {             : '[b][postsmovedhere1] ' . @postnum . ' [postsmovedhere2]' 
       ($ms, $mn, undef, $md, $mu, $mnp, undef, $mi, undef) = split(/\|/, $_, 9);           ) 
       $BoardTotals{$newthreadid} = [$md,$mu,$reply,$ms,$mn,$mi] if ${$BoardTotals{$newthreadid}}[0] <= $md;           . " [i]$boardtitle\[/i] [move by] [i]${$uid.$username}{'realname'}\[/i].[/b]"; 
       $reply++;         FromChars($tmpmessage); 
       next if $mnp eq 'no_postcount';         ( $tmpsub, undef, undef, undef, undef, undef, undef ) = 
       $newthreadusersdate{$mu} = $md if $newthreadusersdate{$mu} < $md;           split /\|/xsm, $utdnewthread[0], 7; 
       $newthreaduserscount{$mu}++;         splice @utdnewthread, ( $linkcount + @postnum ), 0, 
       $mu{$mu} = 1;  qq~$sstxt{'21'} $tmpsub|${$uid.$username}{'realname'}|${$uid.$username}{'email'}|$date|$username|no_postcount||$user_ip|$tmpmessage||||\n~; 
   }    }
   foreach $mu (keys %mu) {  
       &Recent_Load($mu);     if (@utdcurthread) { 
       delete $recent{$curthreadid};         for my $i ( 0 .. $#utdcurthread ) {    # sort post numbers 
       delete $recent{$newthreadid};             my @x = split /\|/xsm, $utdcurthread[$i]; 
       if ($curthreaduserscount{$mu}) {             $x[6] = $i; 
           ${$recent{$curthreadid}}[0] = $curthreaduserscount{$mu};             $utdcurthread[$i] = join q{|}, @x; 
           ${$recent{$curthreadid}}[1] = $curthreadusersdate{$mu};         } 
       }  
       if ($newthreaduserscount{$mu}) {         # Update current thread 
           ${$recent{$newthreadid}}[0] = $newthreaduserscount{$mu};         fopen( FILE, ">$datadir/$curthreadid.txt" ); 
           ${$recent{$newthreadid}}[1] = $newthreadusersdate{$mu};         print {FILE} @utdcurthread or croak "$croak{'print'} FILE"; 
       }         fclose(FILE); 
       &Recent_Save($mu);     } 
   }     else { 
         require Sources::RemoveTopic;
   # For: Mark threads/boards as read         my $moveit = $INFO{'moveit'}; 
   &getlog;         $INFO{'moveit'} = 1; 
   my $boardlog = 1;         RemoveThread(); 
   # Mark new thread as read because you will be directed there at the end         $INFO{'moveit'} = $moveit; 
   delete $yyuserlog{"$newthreadid--unread"};     } 
   $yyuserlog{$newthreadid} = $date;  
     for my $i ( 0 .. $#utdnewthread ) {    # sort post numbers
   # Update .ctb, tags=>(board replies views lastposter lastpostdate threadstatus repliers)         my @x = split /\|/xsm, $utdnewthread[$i]; 
   # curthread         $x[6] = $i; 
   ${$curthreadid}{'replies'} = $#utdcurthread;         $utdnewthread[$i] = join q{|}, @x; 
   ${$curthreadid}{'lastpostdate'} = ${$BoardTotals{$curthreadid}}[0];     } 
   ${$curthreadid}{'lastposter'}   = ${$BoardTotals{$curthreadid}}[1] eq 'Guest' ? "Guest-${$BoardTotals{$curthreadid}}[4]" : ${$BoardTotals{$curthreadid}}[1];  
   # newthread