F:\WEBSITES\testbed\zipped\yabb_svn_new\branches\2.5.2\cgi-bin\yabb2\Sources\RemoveTopic.pl F:\WEBSITES\testbed\zipped\yabb_svn_new\trunk\cgi-bin\yabb2\Sources\RemoveTopic.pm
############################################################################### ###############################################################################
# RemoveTopic.pl                                                              # # RemoveTopic.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';
   
$removetopicplver = 'YaBB 2.5.2 $Revision: 1.0 $'; $removetopicpmver = 'YaBB 2.6.12 $Revision: 1710 $';
if ($action eq 'detailedversion') { return 1; } if ( $action eq 'detailedversion' ) { return 1; }
   
sub RemoveThread { sub RemoveThread {
   my ($threadline, $a, @message);     my $thread = $INFO{'thread'}; 
     if ( $thread =~ /\D/xsm ) { fatal_error('only_numbers_allowed'); }
   
   $thread = $INFO{'thread'};     if ( !$staff && !$iamposter ) { 
   &fatal_error ('only_numbers_allowed') if ($thread =~ /\D/);         fatal_error('delete_not_allowed'); 
     }
   if (!$iammod && !$iamadmin && !$iamgmod && !$iamposter) {    if ( !$currentboard ) {
       &fatal_error("delete_not_allowed");         MessageTotals( 'load', $thread ); 
   }         $currentboard = ${$thread}{'board'}; 
   if (!$currentboard) {     } 
       &MessageTotals("load", $thread);     my $threadline = q{}; 
       $currentboard = ${$thread}{'board'};     fopen( BOARDFILE, "<$boardsdir/$currentboard.txt", 1 ) 
   }       or fatal_error( 'cannot_open', "$boardsdir/$currentboard.txt", 1 ); 
   $threadline = '';     my @buffer = <BOARDFILE>; 
   fopen(BOARDFILE, "+<$boardsdir/$currentboard.txt", 1) || &fatal_error("cannot_open","$boardsdir/$currentboard.txt", 1);     fclose( BOARDFILE ); 
   my @buffer = <BOARDFILE>;     for my $aa ( 0 .. $#buffer ) { 
   for ($a = 0; $a < @buffer; $a++) {        if ( $buffer[$aa] =~ m{\A$thread\|}xsm ) {
       if ($buffer[$a] =~ m~\A$thread\|~) {             $threadline = $buffer[$aa]; 
           $threadline = $buffer[$a];             $buffer[$aa] = q{}; 
           $buffer[$a] = "";             last; 
           last;         } 
       }    }
   }     fopen( BOARDFILE, ">$boardsdir/$currentboard.txt", 1 ) 
   truncate BOARDFILE, 0;       or fatal_error( 'cannot_open', "$boardsdir/$currentboard.txt", 1 ); 
   seek BOARDFILE, 0, 0;     print {BOARDFILE} @buffer or croak "$croak{'print'} BOARDFILE"; 
   print BOARDFILE @buffer;     fclose(BOARDFILE); 
   fclose(BOARDFILE);  
     if ($threadline) {
   if ($threadline) {        if ( !ref $thread_arrayref{$thread} ) {
       unless (ref($thread_arrayref{$thread})) {             fopen( FILE, "$datadir/$thread.txt" ) 
           fopen(FILE, "$datadir/$thread.txt") || &fatal_error("cannot_open","$datadir/$thread.txt", 1);               or fatal_error( 'cannot_open', "$datadir/$thread.txt", 1 ); 
           @{$thread_arrayref{$thread}} = <FILE>;            @{ $thread_arrayref{$thread} } = <FILE>;
           fclose(FILE);            fclose(FILE);
       }        }
   
       &BoardTotals("load", $currentboard);         BoardTotals( 'load', $currentboard ); 
       unless ((split(/\|/, $threadline))[8] =~ /m/) {        if ( ( split /\|/xsm, $threadline )[8] !~ /m/sm ) {
           ${$uid.$currentboard}{'threadcount'}--;             ${ $uid . $currentboard }{'threadcount'}--; 
           ${$uid.$currentboard}{'messagecount'} -= @{$thread_arrayref{$thread}};             ${ $uid . $currentboard }{'messagecount'} -= 
            # &BoardTotals("update", ...) is done in &BoardSetLastInfo               @{ $thread_arrayref{$thread} }; 
       }  
       &BoardSetLastInfo($currentboard,\@buffer);             # &BoardTotals("update", ...) is done in &BoardSetLastInfo 
       # remove thread files         } 
       unlink("$datadir/$thread.txt");         BoardSetLastInfo( $currentboard, \@buffer ); 
       unlink("$datadir/$thread.ctb");  
       unlink("$datadir/$thread.mail");         # remove thread files 
       unlink("$datadir/$thread.poll");         unlink "$datadir/$thread.txt"; 
       unlink("$datadir/$thread.polled");         unlink "$datadir/$thread.ctb"; 
       # remove attachments         unlink "$datadir/$thread.mail"; 
       require "$admindir/Attachments.pl";         unlink "$datadir/$thread.poll"; 
       my %remattach;         unlink "$datadir/$thread.polled"; 
       $remattach{$thread} = undef;  
       &RemoveAttachments(\%remattach);         # remove attachments 
   }         require Admin::Attachments; 
         my %remattach;
   # remove from movedthreads.cgi only if it's the final thread         $remattach{$thread} = undef; 
   # then look backwards to delete the other entries in         RemoveAttachments( \%remattach ); 
   # the Moved-Info-row if their files were deleted     } 
   eval { require "$datadir/movedthreads.cgi" };  
   unless ($moved_file{$thread}) {     # remove from Movedthreads.pm only if it's the final thread 
       my $save_moved;     # then look backwards to delete the other entries in 
       &moved_loop($thread);     # the Moved-Info-row if their files were deleted 
       sub moved_loop {  
           my $th = shift;     *moved_loop = sub { 
           foreach (keys %moved_file) {         my $th = shift; 
               if (exists $moved_file{$_} && $moved_file{$_} == $th && !-e "$datadir/$th.txt") {        foreach ( keys %moved_file ) {
                   delete $moved_file{$_};             if (   exists $moved_file{$_} 
                   $save_moved = 1;                 && $moved_file{$_} == $th 
                   &moved_loop($_);                 && !-e "$datadir/$th.txt" ) 
               }             { 
           }                 delete $moved_file{$_}; 
       }                 $save_moved = 1; 
       &save_moved_file if $save_moved;                 moved_loop($_); 
   }            }
         }
   if ($INFO{'moveit'} != 1) {     }; 
       $yySetLocation = qq~$scripturl?board=$currentboard~;     if ( eval { require Variables::Movedthreads; 1 } ) { 
       &redirectexit;         if ( !$moved_file{$thread} ) { 
   }             moved_loop($thread); 
             if ($save_moved) { save_moved_file(); }
         }
     }
   
     if ( $INFO{'moveit'} != 1 ) {
         $yySetLocation = qq~$scripturl?board=$currentboard~;
         redirectexit();
     }
     return;
} }
   
sub DeleteThread { sub DeleteThread {
   $delete = $FORM{'thread'} || $INFO{'thread'} || $_[0];     my @x = @_; 
     $delete = $FORM{'thread'} || $INFO{'thread'} || $x[0];
   
   if (!$currentboard) {    if ( !$currentboard ) {
       &MessageTotals("load", $delete);         MessageTotals( 'load', $delete ); 
       $currentboard = ${$delete}{'board'};        $currentboard = ${$delete}{'board'};
   }    }
   if ($FORM{'ref'} eq "favorites") {    if ( $FORM{'ref'} eq 'favorites' ) {
       $INFO{'ref'} = "delete";         $INFO{'ref'} = 'delete'; 
       require "$sourcedir/Favorites.pl";         require Sources::Favorites; 
       &RemFav($delete);         RemFav($delete); 
   }    }
   if ((!$adminbin || (!$iamadmin && !$iamgmod)) && $binboard ne "" && $currentboard ne $binboard) {     if (   ( !$adminbin || ( !$iamadmin && !$iamgmod && !$iamfmod ) ) 
       require "$sourcedir/MoveSplitSplice.pl";         && $binboard ne q{} 
       $INFO{'moveit'} = 1;         && $currentboard ne $binboard ) 
       $INFO{'board'} = $currentboard;     { 
       $INFO{'thread'} = $delete;         require Sources::MoveSplitSplice; 
       $INFO{'oldposts'} = 'all';         $INFO{'moveit'}    = 1; 
       $INFO{'leave'} = 2;         $INFO{'board'}     = $currentboard; 
       $INFO{'newinfo'} = 1;         $INFO{'thread'}    = $delete; 
       $INFO{'newboard'} = $binboard;         $INFO{'oldposts'}  = 'all'; 
       $INFO{'newthread'} = 'new';         $INFO{'leave'}     = 2; 
       &Split_Splice_2;         $INFO{'newinfo'}   = 1; 
   } elsif ($iamadmin || $iamgmod || $binboard eq "") {         $INFO{'newboard'}  = $binboard; 
       $INFO{'moveit'} = 1;         $INFO{'newthread'} = 'new'; 
       $INFO{'thread'} = $delete;         Split_Splice_2(); 
       &RemoveThread;     } 
   }     elsif ( $iamadmin || $iamgmod || $iamfmod || $binboard eq q{} ) { 
   $yySetLocation = qq~$scripturl?board=$currentboard~;         $INFO{'moveit'} = 1; 
   &redirectexit;         $INFO{'thread'} = $delete; 
         RemoveThread();
     }
     $yySetLocation = qq~$scripturl?board=$currentboard~;
     redirectexit();
     return;
} }
   
sub Multi { sub Multi {
   if (!$iammod && !$iamadmin && !$iamgmod) { &fatal_error("not_allowed"); }    if ( !$staff ) { fatal_error('not_allowed'); }
   
   require "$sourcedir/SetStatus.pl";     require Sources::SetStatus; 
   require "$sourcedir/MoveSplitSplice.pl";     require Sources::MoveSplitSplice; 
   
   my $mess_loop;    my $mess_loop;
   if ($FORM{'allpost'} =~ m/all/i) {    if ( $FORM{'allpost'} =~ m/all/ism ) {
       &BoardTotals("load", $currentboard);         BoardTotals( 'load', $currentboard ); 
       $mess_loop = ${$uid.$currentboard}{'threadcount'};         $mess_loop = ${ $uid . $currentboard }{'threadcount'}; 
   } else {     } 
       $mess_loop = $maxdisplay;     else { 
   }         $mess_loop = $maxdisplay; 
     }
   my $count = 1;  
   while ($mess_loop >= $count) {     my $count = 1; 
       my ($lock, $stick, $move, $delete, $ref, $hide);     while ( $mess_loop >= $count ) { 
         my ( $lock, $stick, $move, $delete, $ref, $hide );
       if ($FORM{'multiaction'} eq '') {  
           $lock   = $FORM{"lockadmin$count"};         if ( $FORM{'multiaction'} eq q{} ) { 
           $stick  = $FORM{"stickadmin$count"};             $lock   = $FORM{"lockadmin$count"}; 
           $move   = $FORM{"moveadmin$count"};             $stick  = $FORM{"stickadmin$count"}; 
           $delete = $FORM{"deleteadmin$count"};             $move   = $FORM{"moveadmin$count"}; 
           $hide   = $FORM{"hideadmin$count"};             $delete = $FORM{"deleteadmin$count"}; 
       } elsif ($FORM{'multiaction'} eq 'lock') {             $hide   = $FORM{"hideadmin$count"}; 
           $lock = $FORM{"admin$count"};         } 
       } elsif ($FORM{'multiaction'} eq 'stick') {        elsif ( $FORM{'multiaction'} eq 'lock' ) {
           $stick = $FORM{"admin$count"};            $lock = $FORM{"admin$count"};
       } elsif ($FORM{'multiaction'} eq 'move') {         } 
           $move = $FORM{"admin$count"};         elsif ( $FORM{'multiaction'} eq 'stick' ) { 
       } elsif ($FORM{'multiaction'} eq 'delete') {             $stick = $FORM{"admin$count"}; 
           $delete = $FORM{"admin$count"};         } 
       } elsif ($FORM{'multiaction'} eq 'hide') {        elsif ( $FORM{'multiaction'} eq 'move' ) {
           $hide = $FORM{"admin$count"};            $move = $FORM{"admin$count"};
       }        }
         elsif ( $FORM{'multiaction'} eq 'delete' ) {
       if ($FORM{'ref'} eq "favorites") {             $delete = $FORM{"admin$count"}; 
           $ref = qq~$scripturl?action=favorites~;         } 
       } else {        elsif ( $FORM{'multiaction'} eq 'hide' ) {
           $ref = qq~$scripturl?board=$currentboard~;             $hide = $FORM{"admin$count"}; 
       }        }
   
       if ($lock) {        if ( $FORM{'ref'} eq 'favorites' ) {
           $INFO{'moveit'} = 1;             $ref = qq~$scripturl?action=favorites~; 
           $INFO{'thread'} = $lock;         } 
           $INFO{'action'} = "lock";         else { 
           $INFO{'ref'}    = $ref;             $ref = qq~$scripturl?board=$currentboard~; 
           &SetStatus;         } 
       }  
       if ($stick) {        if ($lock) {
           $INFO{'moveit'} = 1;            $INFO{'moveit'} = 1;
           $INFO{'thread'} = $stick;             $INFO{'thread'} = $lock; 
           $INFO{'action'} = "sticky";             $INFO{'action'} = 'lock'; 
           $INFO{'ref'}    = $ref;            $INFO{'ref'}    = $ref;
           &SetStatus;             SetStatus(); 
       }        }
       if ($move) {        if ($stick) {
           $INFO{'moveit'} = 1;            $INFO{'moveit'} = 1;
           $INFO{'board'} = $currentboard;             $INFO{'thread'} = $stick; 
           $INFO{'thread'} = $move;             $INFO{'action'} = 'sticky'; 
           $INFO{'oldposts'} = 'all';             $INFO{'ref'}    = $ref; 
           $INFO{'leave'} = 0;             SetStatus(); 
           $INFO{'newinfo'} ||= $FORM{"newinfo"};         } 
           $INFO{'newboard'} = $FORM{"toboard"};         if ($move) { 
           $INFO{'newthread'} = 'new';             $INFO{'moveit'}   = 1; 
           &Split_Splice_2;             $INFO{'board'}    = $currentboard; 
       }             $INFO{'thread'}   = $move; 
       if ($hide) {             $INFO{'oldposts'} = 'all'; 
           $INFO{'moveit'} = 1;             $INFO{'leave'}    = 0; 
           $INFO{'action'} = 'hide';             $INFO{'newinfo'} ||= $FORM{'newinfo'}; 
           $INFO{'thread'} = $hide;             $INFO{'newboard'}  = $FORM{'toboard'}; 
           &SetStatus;             $INFO{'newthread'} = 'new'; 
       }            if ( !$INFO{'newboard'} ) { redirectmove($currentboard); }
       if ($delete) {            else {
           if (!$currentboard) {                 Split_Splice_2(); 
               &MessageTotals("load", $delete);             } 
               $currentboard = ${$delete}{'board'};         } 
           }         if ($hide) { 
           if ($FORM{'ref'} eq "favorites") {             $INFO{'moveit'} = 1; 
               $INFO{'ref'} = "delete";             $INFO{'action'} = 'hide'; 
               require "$sourcedir/Favorites.pl";             $INFO{'thread'} = $hide; 
               &RemFav($delete);             SetStatus(); 
           }        }
           if ((!$adminbin || (!$iamadmin && !$iamgmod)) && $binboard ne "" && $currentboard ne $binboard) {        if ($delete) {
               $INFO{'moveit'} = 1;             if ( !$currentboard ) { 
               $INFO{'board'} = $currentboard;                 MessageTotals( 'load', $delete ); 
               $INFO{'thread'} = $delete;                 $currentboard = ${$delete}{'board'}; 
               $INFO{'oldposts'} = 'all';             } 
               $INFO{'leave'} = 2;             if ( $FORM{'ref'} eq 'favorites' ) { 
               $INFO{'newinfo'} = 1;                 $INFO{'ref'} = 'delete'; 
               $INFO{'newboard'} = $binboard;                 require Sources::Favorites; 
               $INFO{'newthread'} = 'new';                 RemFav($delete); 
               &Split_Splice_2;             } 
           } elsif ($iamadmin || $iamgmod || $binboard eq "") {             if (   ( !$adminbin || ( !$iamadmin && !$iamgmod && !$iamfmod ) ) 
               $INFO{'moveit'} = 1;                 && $binboard ne q{} 
               $INFO{'thread'} = $delete;                 && $currentboard ne $binboard ) 
               &RemoveThread;             { 
           }                 $INFO{'moveit'}    = 1; 
       }                 $INFO{'board'}     = $currentboard; 
       $count++;                 $INFO{'thread'}    = $delete; 
   }                 $INFO{'oldposts'}  = 'all'; 
   $yySetLocation = qq~$scripturl?board=$currentboard~;                 $INFO{'leave'}     = 2; 
   &redirectexit;                 $INFO{'newinfo'}   = 1; 
                 $INFO{'newboard'}  = $binboard;
                 $INFO{'newthread'} = 'new';
                 Split_Splice_2();
             }
             elsif ( $iamadmin || $iamgmod || $iamfmod || $binboard eq q{} ) {
                 $INFO{'moveit'} = 1;
                 $INFO{'thread'} = $delete;
                 RemoveThread();
             }
         }
         $count++;
     }
     $yySetLocation = qq~$scripturl?board=$currentboard~;
     redirectexit();
     return;
} }
   
1; 1;