D:\my docs\My Received Files\Yabb\Yabb\YaBB_2.5_AEB\cgi-bin\yabb2_old\Sources\ModifyMessage.pl D:\WEBSITES\testbed\cgi-bin\yabb252\Sources\ModifyMessage.pl
############################################################################### ###############################################################################
# ModifyMessage.pl                                                            # # ModifyMessage.pl                                                            #
############################################################################### ###############################################################################
# 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 Anniversary Edition                                # # Version:        YaBB 2.5.2                                                  #
# Packaged:       July 04, 2010                                               # # Packaged:       September 30, 2012                                          #
# Distributed by: http://www.yabbforum.com                                    # # Distributed by: http://www.yabbforum.com                                    #
# =========================================================================== # # =========================================================================== #
# Copyright (c) 2000-2010 YaBB (www.yabbforum.com) - All Rights Reserved.     # # Copyright (c) 2000-2012 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.                      #
# Sponsored by: Xnull Internet Media, Inc. - http://www.ximinc.com            # # Sponsored by: Xnull Internet Media, Inc. - http://www.ximinc.com            #
#               Your source for web hosting, web design, and domains.         # #               Your source for web hosting, web design, and domains.         #
############################################################################### ###############################################################################
   
$modifymessageplver = 'YaBB 2.5 AE $Revision: 1.33 $'; $modifymessageplver = 'YaBB 2.5.2 $Revision: 1.1 $';
if ($action eq 'detailedversion') { return 1; } if ($action eq 'detailedversion') { return 1; }
   
if (!$post_txt_loaded) { if (!$post_txt_loaded) {
   &LoadLanguage('Post');    &LoadLanguage('Post');
   $post_txt_loaded = 1;    $post_txt_loaded = 1;
} }
&LoadLanguage('FA'); &LoadLanguage('FA');
require "$sourcedir/SpamCheck.pl"; require "$sourcedir/SpamCheck.pl";
   
sub ModifyMessage { sub ModifyMessage {
   if ($iamguest) { &fatal_error("members_only"); }    if ($iamguest) { &fatal_error("members_only"); }
   if ($currentboard eq '') { &fatal_error("no_access"); }    if ($currentboard eq '') { &fatal_error("no_access"); }
   
   my ($mnum, $msub, $mname, $memail, $mdate, $mreplies, $musername, $micon, $mstate, $msubject, $mattach, $mip, $mmessage, $mns, $mlm, $mlmb);    my ($mnum, $msub, $mname, $memail, $mdate, $mreplies, $musername, $micon, $mstate, $msubject, $mattach, $mip, $mmessage, $mns, $mlm, $mlmb);
   $threadid = $INFO{'thread'};    $threadid = $INFO{'thread'};
   $postid   = $INFO{'message'};    $postid   = $INFO{'message'};
   
   my ($filetype_info, $filesize_info, $extensions);    my ($filetype_info, $filesize_info, $extensions);
   $extensions = join(" ", @ext);    $extensions = join(" ", @ext);
   $filetype_info = $checkext == 1 ? qq~$fatxt{'2'} $extensions~ : qq~$fatxt{'2'} $fatxt{'4'}~;    $filetype_info = $checkext == 1 ? qq~$fatxt{'2'} $extensions~ : qq~$fatxt{'2'} $fatxt{'4'}~;
   $filesize_info = $limit != 0    ? qq~$fatxt{'3'} $limit KB~   : qq~$fatxt{'3'} $fatxt{'5'}~;    $filesize_info = $limit != 0    ? qq~$fatxt{'3'} $limit KB~   : qq~$fatxt{'3'} $fatxt{'5'}~;
   
   ($mnum, $msub, $mname, $memail, $mdate, $mreplies, $musername, $micon, $mstate) = split(/\|/, $yyThreadLine);    ($mnum, $msub, $mname, $memail, $mdate, $mreplies, $musername, $micon, $mstate) = split(/\|/, $yyThreadLine);
   
   $postthread = 2;    $postthread = 2;
   
   if ($mstate =~ /l/i) {    if ($mstate =~ /l/i) {
       my $icanbypass = &checkUserLockBypass if $bypass_lock_perm;        my $icanbypass = &checkUserLockBypass if $bypass_lock_perm;
       if (!$icanbypass) { &fatal_error("topic_locked"); }        if (!$icanbypass) { &fatal_error("topic_locked"); }
   } elsif (!$iamadmin && !$iamgmod && !$iammod && $tlnomodflag && $date > $mdate + ($tlnomodtime * 3600 * 24)) {    } elsif (!$iamadmin && !$iamgmod && !$iammod && $tlnomodflag && $date > $mdate + ($tlnomodtime * 3600 * 24)) {
       &fatal_error("time_locked","$tlnomodtime$timelocktxt{'02'}");        &fatal_error("time_locked","$tlnomodtime$timelocktxt{'02'}");
   }    }
   if ($postid eq "Poll") {    if ($postid eq "Poll") {
       unless (-e "$datadir/$threadid.poll") { &fatal_error("not_allowed"); }        unless (-e "$datadir/$threadid.poll") { &fatal_error("not_allowed"); }
   
       fopen(FILE, "$datadir/$threadid.poll");        fopen(FILE, "$datadir/$threadid.poll");
       my @poll_data = <FILE>;        my @poll_data = <FILE>;
       fclose(FILE);        fclose(FILE);
       chomp(@poll_data);        chomp(@poll_data);
       ($poll_question, $poll_locked, $poll_uname, $poll_name, $poll_email, $poll_date, $guest_vote, $hide_results, $multi_choice, $poll_mod, $poll_modname, $poll_comment, $vote_limit, $pie_radius, $pie_legends, $poll_end) = split(/\|/, $poll_data[0]);        ($poll_question, $poll_locked, $poll_uname, $poll_name, $poll_email, $poll_date, $guest_vote, $hide_results, $multi_choice, $poll_mod, $poll_modname, $poll_comment, $vote_limit, $pie_radius, $pie_legends, $poll_end) = split(/\|/, $poll_data[0]);
       &ToChars($poll_question);        &ToChars($poll_question);
       &ToChars($poll_comment);        &ToChars($poll_comment);
   
       for (my $i = 1; $i < @poll_data; $i++) {        for (my $i = 1; $i < @poll_data; $i++) {
           ($votes[$i], $options[$i], $slicecolor[$i], $split[$i]) = split(/\|/, $poll_data[$i]);            ($votes[$i], $options[$i], $slicecolor[$i], $split[$i]) = split(/\|/, $poll_data[$i]);
           &ToChars($options[$i]);            &ToChars($options[$i]);
       }        }
   
       unless ($poll_uname eq $username || $iammod || $iamadmin || $iamgmod) { &fatal_error("not_allowed"); }        unless ($poll_uname eq $username || $iammod || $iamadmin || $iamgmod) { &fatal_error("not_allowed"); }
   
       $poll_comment =~ s~<br \/>~\n~g;        $poll_comment =~ s~<br \/>~\n~g;
       $poll_comment =~ s~<br>~\n~g;        $poll_comment =~ s~<br>~\n~g;
       $pollthread = 2;        $pollthread = 2;
       $settofield = "question";        $settofield = "question";
       $icon = 'poll_mod';        $icon = 'poll_mod';
   
   } else {    } else {
       unless (ref($thread_arrayref{$threadid})) {        unless (ref($thread_arrayref{$threadid})) {
           fopen(FILE, "$datadir/$threadid.txt") || &fatal_error("cannot_open","$datadir/$threadid.txt", 1);            fopen(FILE, "$datadir/$threadid.txt") || &fatal_error("cannot_open","$datadir/$threadid.txt", 1);
           @{$thread_arrayref{$threadid}} = <FILE>;            @{$thread_arrayref{$threadid}} = <FILE>;
           fclose(FILE);            fclose(FILE);
       }        }
       ($sub, $mname, $memail, $mdate, $musername, $micon, $mattach, $mip, $message, $mns, $mlm, $mlmb, $mfn) = split(/\|/, ${$thread_arrayref{$threadid}}[$postid]);        ($sub, $mname, $memail, $mdate, $musername, $micon, $mattach, $mip, $message, $mns, $mlm, $mlmb, $mfn) = split(/\|/, ${$thread_arrayref{$threadid}}[$postid]);
       chomp $mfn;        chomp $mfn;
   
       if ((${$uid.$username}{'regtime'} > $mdate || $musername ne $username) && !($iammod || $iamadmin || $iamgmod)) {        if ((${$uid.$username}{'regtime'} > $mdate || $musername ne $username) && !($iammod || $iamadmin || $iamgmod)) {
           &fatal_error("change_not_allowed");            &fatal_error("change_not_allowed");
       }        }
   
       $lastmod = $mlm ? &timeformat($mlm) : '-';        $lastmod = $mlm ? &timeformat($mlm) : '-';
       $nscheck = $mns ? ' checked'        : '';        $nscheck = $mns ? ' checked'        : '';
   
       $lastmod = qq~        $lastmod = qq~
<tr> <tr>
   <td valign="top" width="23%"><span class="text1"><b>$post_txt{'211'}:</b></span></td>    <td valign="top" width="23%"><span class="text1"><b>$post_txt{'211'}:</b></span></td>
   <td><span class="text1">$lastmod</span></td>    <td><span class="text1">$lastmod</span></td>
</tr> </tr>
~; ~;
       $icon = $micon;        $icon = $micon;
       if    ($icon eq "xx")          { $ic1  = " selected=\"selected\" "; }        if    ($icon eq "xx")          { $ic1  = " selected=\"selected\" "; }
       elsif ($icon eq "thumbup")     { $ic2  = " selected=\"selected\" "; }        elsif ($icon eq "thumbup")     { $ic2  = " selected=\"selected\" "; }
       elsif ($icon eq "thumbdown")   { $ic3  = " selected=\"selected\" "; }        elsif ($icon eq "thumbdown")   { $ic3  = " selected=\"selected\" "; }
       elsif ($icon eq "exclamation") { $ic4  = " selected=\"selected\" "; }        elsif ($icon eq "exclamation") { $ic4  = " selected=\"selected\" "; }
       elsif ($icon eq "question")    { $ic5  = " selected=\"selected\" "; }        elsif ($icon eq "question")    { $ic5  = " selected=\"selected\" "; }
       elsif ($icon eq "lamp")        { $ic6  = " selected=\"selected\" "; }        elsif ($icon eq "lamp")        { $ic6  = " selected=\"selected\" "; }
       elsif ($icon eq "smiley")      { $ic7  = " selected=\"selected\" "; }        elsif ($icon eq "smiley")      { $ic7  = " selected=\"selected\" "; }
       elsif ($icon eq "angry")       { $ic8  = " selected=\"selected\" "; }        elsif ($icon eq "angry")       { $ic8  = " selected=\"selected\" "; }
       elsif ($icon eq "cheesy")      { $ic9  = " selected=\"selected\" "; }        elsif ($icon eq "cheesy")      { $ic9  = " selected=\"selected\" "; }
       elsif ($icon eq "grin")        { $ic10 = " selected=\"selected\" "; }        elsif ($icon eq "grin")        { $ic10 = " selected=\"selected\" "; }
       elsif ($icon eq "sad")         { $ic11 = " selected=\"selected\" "; }        elsif ($icon eq "sad")         { $ic11 = " selected=\"selected\" "; }
       elsif ($icon eq "wink")        { $ic12 = " selected=\"selected\" "; }        elsif ($icon eq "wink")        { $ic12 = " selected=\"selected\" "; }
       $message =~ s~<br \/>~\n~ig;        $message =~ s~<br \/>~\n~ig;
       $message =~ s~<br>~\n~ig;        $message =~ s~<br>~\n~ig;
       $message =~ s/ \&nbsp; \&nbsp; \&nbsp;/\t/ig;        $message =~ s/ \&nbsp; \&nbsp; \&nbsp;/\t/ig;
       $settofield = "message";        $settofield = "message";
   }    }
   if ($ENV{'HTTP_USER_AGENT'} =~ /(MSIE) (\d)/) {    if ($ENV{'HTTP_USER_AGENT'} =~ /(MSIE) (\d)/) {
       if($2 >= 7.0) { $iecopycheck = ""; } else { $iecopycheck = qq~checked="checked"~; }        if($2 >= 7.0) { $iecopycheck = ""; } else { $iecopycheck = qq~checked="checked"~; }
   }    }
   $submittxt = $post_txt{'10'};    $submittxt = $post_txt{'10'};
   $destination = 'modify2';    $destination = 'modify2';
   $is_preview  = 0;    $is_preview  = 0;
   $post = 'postmodify';    $post = 'postmodify';
   $preview = 'previewmodify';    $preview = 'previewmodify';
   require "$sourcedir/Post.pl";    require "$sourcedir/Post.pl";
   $yytitle = $post_txt{'66'};    $yytitle = $post_txt{'66'};
   $mename = $mname;    $mename = $mname;
   &Postpage;    &Postpage;
   &template;    &template;
} }
   
sub ModifyMessage2 { sub ModifyMessage2 {
   if ($iamguest) { &fatal_error("members_only"); }    if ($iamguest) { &fatal_error("members_only"); }
   
   if ($FORM{'previewmodify'}) {    if ($FORM{'previewmodify'}) {
       $mename = qq~$FORM{'mename'}~;        $mename = qq~$FORM{'mename'}~;
       require "$sourcedir/Post.pl";        require "$sourcedir/Post.pl";
       &Preview;        &Preview;
   }    }
   
   # the post is to be deleted...    # the post is to be deleted...
   if ($INFO{'d'} == 1) {    if ($INFO{'d'} == 1) {
       $threadid = $FORM{'thread'};        $threadid = $FORM{'thread'};
       $postid   = $FORM{'id'};        $postid   = $FORM{'id'};
   
       if ($postid eq "Poll") {        if ($postid eq "Poll") {
           # showcase poll start            # showcase poll start
           # Look for a showcase.poll file to unlink.            # Look for a showcase.poll file to unlink.
           if (-e "$datadir/showcase.poll") {            if (-e "$datadir/showcase.poll") {
               fopen (FILE, "$datadir/showcase.poll");                fopen (FILE, "$datadir/showcase.poll");
               if ($threadid == <FILE>) {                if ($threadid == <FILE>) {
                   fclose (FILE);                    fclose (FILE);
                   unlink ("$datadir/showcase.poll");                    unlink ("$datadir/showcase.poll");
               } else {                } else {
                   fclose (FILE);                    fclose (FILE);
               }                }
           }            }
           # showcase poll end            # showcase poll end
           unlink("$datadir/$threadid.poll");            unlink("$datadir/$threadid.poll");
           unlink("$datadir/$threadid.polled");            unlink("$datadir/$threadid.polled");
           $yySetLocation = qq~$scripturl?num=$threadid~;            $yySetLocation = qq~$scripturl?num=$threadid~;
           &redirectexit;            &redirectexit;
   
       } else {        } else {
           unless (ref($thread_arrayref{$threadid})) {            unless (ref($thread_arrayref{$threadid})) {
               fopen(FILE, "$datadir/$threadid.txt") || &fatal_error("cannot_open","$datadir/$threadid.txt", 1);                fopen(FILE, "$datadir/$threadid.txt") || &fatal_error("cannot_open","$datadir/$threadid.txt", 1);
               @{$thread_arrayref{$threadid}} = <FILE>;                @{$thread_arrayref{$threadid}} = <FILE>;
               fclose(FILE);                fclose(FILE);
           }            }
           $msgcnt = @{$thread_arrayref{$threadid}};            $msgcnt = @{$thread_arrayref{$threadid}};
   
           # Make sure the user is allowed to edit this post.            # Make sure the user is allowed to edit this post.
           if ($postid >= 0 && $postid < $msgcnt) {            if ($postid >= 0 && $postid < $msgcnt) {
               ($msub, $mname, $memail, $mdate, $musername, $micon, $mattach, $mip, $mmessage, $mns, $mlm, $mlmb, $mfn) = split(/\|/, ${$thread_arrayref{$threadid}}[$postid]);                ($msub, $mname, $memail, $mdate, $musername, $micon, $mattach, $mip, $mmessage, $mns, $mlm, $mlmb, $mfn) = split(/\|/, ${$thread_arrayref{$threadid}}[$postid]);
               chomp $mfn;                chomp $mfn;
               if (${$uid.$username}{'regdate'} > $mdate || (!$iamadmin && !$iamgmod && !$iammod && $musername ne $username) || !$sessionvalid) { &fatal_error("delete_not_allowed"); }                if (${$uid.$username}{'regdate'} > $mdate || (!$iamadmin && !$iamgmod && !$iammod && $musername ne $username) || !$sessionvalid) { &fatal_error("delete_not_allowed"); }
               if (!$iamadmin && !$iamgmod && !$iammod && $tlnodelflag && $date > $mdate + ($tlnodeltime * 3600 * 24)) { &fatal_error("time_locked","$tlnodeltime$timelocktxt{'02a'}"); }                if (!$iamadmin && !$iamgmod && !$iammod && $tlnodelflag && $date > $mdate + ($tlnodeltime * 3600 * 24)) { &fatal_error("time_locked","$tlnodeltime$timelocktxt{'02a'}"); }
           } else {            } else {
               &fatal_error("bad_postnumber",$postid);                &fatal_error("bad_postnumber",$postid);
           }            }
           $iamposter = ($musername eq $username && $msgcnt == 1) ? 1 : 0;            $iamposter = ($musername eq $username && $msgcnt == 1) ? 1 : 0;
           $FORM{"del$postid"} = 1;            $FORM{"del$postid"} = 1;
           &MultiDel;            &MultiDel;
       }        }
   }    }
   
   my ($threadid, $postid, $msub, $mname, $memail, $mdate, $musername, $micon, $mattach, $mip, $mmessage, $mns, $mlm, $mlmb, $tnum, $tsub, $tname, $temail, $tdate, $treplies, $tusername, $ticon, $tstate, @threads, $tmpa, $tmpb, $newlastposttime, $newlastposter, $lastpostid, $views, $name, $email, $subject, $message, $ns,);    my ($threadid, $postid, $msub, $mname, $memail, $mdate, $musername, $micon, $mattach, $mip, $mmessage, $mns, $mlm, $mlmb, $tnum, $tsub, $tname, $temail, $tdate, $treplies, $tusername, $ticon, $tstate, @threads, $tmpa, $tmpb, $newlastposttime, $newlastposter, $lastpostid, $views, $name, $email, $subject, $message, $ns,);
   
   $threadid   = $FORM{'threadid'};    $threadid   = $FORM{'threadid'};
   $postid     = $FORM{'postid'};    $postid     = $FORM{'postid'};
   $pollthread = $FORM{'pollthread'};    $pollthread = $FORM{'pollthread'};
   
   if ($pollthread) {    if ($pollthread) {
       $maxpq          ||= 60;        $maxpq          ||= 60;
       $maxpo          ||= 50;        $maxpo          ||= 50;
       $maxpc          ||= 0;        $maxpc          ||= 0;
       $numpolloptions ||= 8;        $numpolloptions ||= 8;
       $vote_limit     ||= 0;        $vote_limit     ||= 0;
   
       unless (-e "$datadir/$threadid.poll") { &fatal_error("not_allowed"); }        unless (-e "$datadir/$threadid.poll") { &fatal_error("not_allowed"); }
   
       fopen(FILE, "$datadir/$threadid.poll");        fopen(FILE, "$datadir/$threadid.poll");
       my @poll_data = <FILE>;        my @poll_data = <FILE>;
       fclose(FILE);        fclose(FILE);
       chomp($poll_data);        chomp($poll_data);
       ($poll_question, $poll_locked, $poll_uname, $poll_name, $poll_email, $poll_date, $guest_vote, $hide_results, $multi_choice, $poll_mod, $poll_modname, $poll_comment, $vote_limit, $pie_radius, $pie_legends, $poll_end) = split(/\|/, $poll_data[0]);        ($poll_question, $poll_locked, $poll_uname, $poll_name, $poll_email, $poll_date, $guest_vote, $hide_results, $multi_choice, $poll_mod, $poll_modname, $poll_comment, $vote_limit, $pie_radius, $pie_legends, $poll_end) = split(/\|/, $poll_data[0]);
   
       unless ($poll_uname eq $username || $iammod || $iamadmin || $iamgmod) { &fatal_error("not_allowed"); }        unless ($poll_uname eq $username || $iammod || $iamadmin || $iamgmod) { &fatal_error("not_allowed"); }
   
       my $numcount = 0;        my $numcount = 0;
       unless ($FORM{"question"}) { &fatal_error("no_question"); }        unless ($FORM{"question"}) { &fatal_error("no_question"); }
       $FORM{"question"} =~ s/\&nbsp;/ /g;        $FORM{"question"} =~ s/\&nbsp;/ /g;
       my $testspaces = $FORM{"question"};        my $testspaces = $FORM{"question"};
       $testspaces =~ s/[\r\n\ ]//g;        $testspaces =~ s/[\r\n\ ]//g;
       $testspaces =~ s/\&nbsp;//g;        $testspaces =~ s/\&nbsp;//g;
       $testspaces =~ s~\[table\].*?\[tr\].*?\[td\]~~g;        $testspaces =~ s~\[table\].*?\[tr\].*?\[td\]~~g;
       $testspaces =~ s~\[/td\].*?\[/tr\].*?\[/table\]~~g;        $testspaces =~ s~\[/td\].*?\[/tr\].*?\[/table\]~~g;
       $testspaces =~ s/\[.*?\]//g;        $testspaces =~ s/\[.*?\]//g;
       if (length($testspaces) == 0 && length($FORM{"question"}) > 0) { fatal_error("useless_post","$testspaces"); }        if (length($testspaces) == 0 && length($FORM{"question"}) > 0) { fatal_error("useless_post","$testspaces"); }
   
       $poll_question = $FORM{"question"};        $poll_question = $FORM{"question"};
       &FromChars($poll_question);        &FromChars($poll_question);
       $convertstr = $poll_question;        $convertstr = $poll_question;
       $convertcut = $maxpq;        $convertcut = $maxpq;
       &CountChars;        &CountChars;
       $poll_question = $convertstr;        $poll_question = $convertstr;
       if ($cliped) { &fatal_error("error_occurred","$post_polltxt{'40'} $post_polltxt{'34a'} $maxpq $post_polltxt{'34b'} $post_polltxt{'36'}"); }        if ($cliped) { &fatal_error("error_occurred","$post_polltxt{'40'} $post_polltxt{'34a'} $maxpq $post_polltxt{'34b'} $post_polltxt{'36'}"); }
       &ToHTML($poll_question);        &ToHTML($poll_question);
   
       $guest_vote   = $FORM{'guest_vote'}   || 0;        $guest_vote   = $FORM{'guest_vote'}   || 0;
       $hide_results = $FORM{'hide_results'} || 0;        $hide_results = $FORM{'hide_results'} || 0;
       $multi_choice = $FORM{'multi_choice'} || 0;        $multi_choice = $FORM{'multi_choice'} || 0;
       $poll_comment = $FORM{'poll_comment'} || "";        $poll_comment = $FORM{'poll_comment'} || "";
       $vote_limit   = $FORM{'vote_limit'}   || 0;        $vote_limit   = $FORM{'vote_limit'}   || 0;
       $pie_legends  = $FORM{'pie_legends'}  || 0;        $pie_legends  = $FORM{'pie_legends'}  || 0;
       $pie_radius   = $FORM{'pie_radius'}   || 100;        $pie_radius   = $FORM{'pie_radius'}   || 100;
       $poll_end_days = $FORM{'poll_end_days'};        $poll_end_days = $FORM{'poll_end_days'};
       $poll_end_min  = $FORM{'poll_end_min'};        $poll_end_min  = $FORM{'poll_end_min'};
   
       if ($pie_radius =~ /\D/) { $pie_radius = 100; }        if ($pie_radius =~ /\D/) { $pie_radius = 100; }
       if ($pie_radius < 100)   { $pie_radius = 100; }        if ($pie_radius < 100)   { $pie_radius = 100; }
       if ($pie_radius > 200)   { $pie_radius = 200; }        if ($pie_radius > 200)   { $pie_radius = 200; }
   
       if ($vote_limit =~ /\D/) { $vote_limit = 0; &fatal_error("only_numbers_allowed","$post_polltxt{'62'}"); }        if ($vote_limit =~ /\D/) { $vote_limit = 0; &fatal_error("only_numbers_allowed","$post_polltxt{'62'}"); }
   
       &FromChars($poll_comment);        &FromChars($poll_comment);
       $convertstr = $poll_comment;        $convertstr = $poll_comment;
       $convertcut = $maxpc;        $convertcut = $maxpc;
       &CountChars;        &CountChars;
       $poll_comment = $convertstr;        $poll_comment = $convertstr;
       if ($cliped) { &fatal_error("error_occurred","$post_polltxt{'57'} $post_polltxt{'34a'} $maxpc $post_polltxt{'34b'} $post_polltxt{'36'}"); }        if ($cliped) { &fatal_error("error_occurred","$post_polltxt{'57'} $post_polltxt{'34a'} $maxpc $post_polltxt{'34b'} $post_polltxt{'36'}"); }
       &ToHTML($poll_comment);        &ToHTML($poll_comment);
       $poll_comment =~ s~\n~<br />~g;        $poll_comment =~ s~\n~<br />~g;
       $poll_comment =~ s~\r~~g;        $poll_comment =~ s~\r~~g;
   
       $poll_end_days = '' if !$poll_end_days || $poll_end_days =~ /\D/;        $poll_end_days = '' if !$poll_end_days || $poll_end_days =~ /\D/;
       $poll_end_min  = '' if !$poll_end_min  || $poll_end_min =~ /\D/;        $poll_end_min  = '' if !$poll_end_min  || $poll_end_min =~ /\D/;
       my $poll_end = $poll_end_days * 86400 if $poll_end_days;        my $poll_end = $poll_end_days * 86400 if $poll_end_days;
       $poll_end += $poll_end_min * 60 if $poll_end_min;        $poll_end += $poll_end_min * 60 if $poll_end_min;
       $poll_end += $date if $poll_end;        $poll_end += $date if $poll_end;
   
       my @new_poll_data;        my @new_poll_data;
       push @new_poll_data, qq~$poll_question|$poll_locked|$poll_uname|$poll_name|$poll_email|$poll_date|$guest_vote|$hide_results|$multi_choice|$date|$username|$poll_comment|$vote_limit|$pie_radius|$pie_legends|$poll_end\n~;        push @new_poll_data, qq~$poll_question|$poll_locked|$poll_uname|$poll_name|$poll_email|$poll_date|$guest_vote|$hide_results|$multi_choice|$date|$username|$poll_comment|$vote_limit|$pie_radius|$pie_legends|$poll_end\n~;
   
       for ($i = 1; $i <= $numpolloptions; $i++) {        for ($i = 1; $i <= $numpolloptions; $i++) {
           ($votes, undef) = split(/\|/, $poll_data[$i], 2);            ($votes, undef) = split(/\|/, $poll_data[$i], 2);
           if (!$votes) { $votes = "0"; }            if (!$votes) { $votes = "0"; }
           if ($FORM{"option$i"}) {            if ($FORM{"option$i"}) {
               $FORM{"option$i"} =~ s/\&nbsp;/ /g;                $FORM{"option$i"} =~ s/\&nbsp;/ /g;
               my $testspaces = $FORM{"option$i"};                my $testspaces = $FORM{"option$i"};
               $testspaces =~ s/[\r\n\ ]//g;                $testspaces =~ s/[\r\n\ ]//g;
               $testspaces =~ s/\&nbsp;//g;                $testspaces =~ s/\&nbsp;//g;
               $testspaces =~ s~\[table\].*?\[tr\].*?\[td\]~~g;                $testspaces =~ s~\[table\].*?\[tr\].*?\[td\]~~g;
               $testspaces =~ s~\[/td\].*?\[/tr\].*?\[/table\]~~g;                $testspaces =~ s~\[/td\].*?\[/tr\].*?\[/table\]~~g;
               $testspaces =~ s/\[.*?\]//g;                $testspaces =~ s/\[.*?\]//g;
               if (!length($testspaces)) { fatal_error("useless_post","$testspaces"); }                if (!length($testspaces)) { fatal_error("useless_post","$testspaces"); }
   
               &FromChars($FORM{"option$i"});                &FromChars($FORM{"option$i"});
               $convertstr = $FORM{"option$i"};                $convertstr = $FORM{"option$i"};
               $convertcut = $maxpo;                $convertcut = $maxpo;
               &CountChars;                &CountChars;
               $FORM{"option$i"} = $convertstr;                $FORM{"option$i"} = $convertstr;
               if ($cliped) { &fatal_error("error_occurred","$post_polltxt{'7'} $i $post_polltxt{'34a'} $maxpo $post_polltxt{'34b'} $post_polltxt{'36'}"); }                if ($cliped) { &fatal_error("error_occurred","$post_polltxt{'7'} $i $post_polltxt{'34a'} $maxpo $post_polltxt{'34b'} $post_polltxt{'36'}"); }
   
               &ToHTML($FORM{"option$i"});                &ToHTML($FORM{"option$i"});
               $numcount++;                $numcount++;
               push @new_poll_data, qq~$votes|$FORM{"option$i"}|$FORM{"slicecol$i"}|$FORM{"split$i"}\n~;                push @new_poll_data, qq~$votes|$FORM{"option$i"}|$FORM{"slicecol$i"}|$FORM{"split$i"}\n~;
           }            }
       }        }
       if ($numcount < 2) { &fatal_error("no_options"); }        if ($numcount < 2) { &fatal_error("no_options"); }
   
       # showcase poll start        # showcase poll start
       if ($iamadmin || $iamgmod) {        if ($iamadmin || $iamgmod) {
           my $scthreadid;            my $scthreadid;
           if (-e "$datadir/showcase.poll") {            if (-e "$datadir/showcase.poll") {
               fopen (FILE, "$datadir/showcase.poll");                fopen (FILE, "$datadir/showcase.poll");
               $scthreadid = <FILE>;                $scthreadid = <FILE>;
               fclose (FILE);                fclose (FILE);
           }            }
           if ($threadid == $scthreadid && !$FORM{'scpoll'}) {            if ($threadid == $scthreadid && !$FORM{'scpoll'}) {
               unlink("$datadir/showcase.poll");                unlink("$datadir/showcase.poll");
           } elsif ($FORM{'scpoll'}) {            } elsif ($FORM{'scpoll'}) {
               fopen (SCFILE, ">$datadir/showcase.poll");                fopen (SCFILE, ">$datadir/showcase.poll");
               print SCFILE $threadid;                print SCFILE $threadid;
               fclose (SCFILE);                fclose (SCFILE);
           }            }
       }        }
       # showcase poll end        # showcase poll end
   
       fopen(POLL, ">$datadir/$threadid.poll");        fopen(POLL, ">$datadir/$threadid.poll");
       print POLL @new_poll_data;        print POLL @new_poll_data;
       fclose(POLL);        fclose(POLL);
   
       $yySetLocation = qq~$scripturl?num=$threadid~;        $yySetLocation = qq~$scripturl?num=$threadid~;
   
       &redirectexit;        &redirectexit;
   }    }
   
   unless (ref($thread_arrayref{$threadid})) {    unless (ref($thread_arrayref{$threadid})) {
       fopen(FILE, "$datadir/$threadid.txt") || &fatal_error("cannot_open","$datadir/$threadid.txt", 1);        fopen(FILE, "$datadir/$threadid.txt") || &fatal_error("cannot_open","$datadir/$threadid.txt", 1);
       @{$thread_arrayref{$threadid}} = <FILE>;        @{$thread_arrayref{$threadid}} = <FILE>;
       fclose(FILE);        fclose(FILE);
   }    }
   
   # Make sure the user is allowed to edit this post.    # Make sure the user is allowed to edit this post.
   if ($postid >= 0 && $postid < @{$thread_arrayref{$threadid}}) {    if ($postid >= 0 && $postid < @{$thread_arrayref{$threadid}}) {
       ($msub, $mname, $memail, $mdate, $musername, $micon, $mattach, $mip, $mmessage, $mns, $mlm, $mlmb, $mfn) = split(/\|/, ${$thread_arrayref{$threadid}}[$postid]);        ($msub, $mname, $memail, $mdate, $musername, $micon, $mattach, $mip, $mmessage, $mns, $mlm, $mlmb, $mfn) = split(/\|/, ${$thread_arrayref{$threadid}}[$postid]);
       chomp $mfn;        chomp $mfn;
       unless ((${$uid.$username}{'regdate'} < $mdate && $musername eq $username) || $iammod || $iamadmin || $iamgmod) {        unless ((${$uid.$username}{'regdate'} < $mdate && $musername eq $username) || $iammod || $iamadmin || $iamgmod) {
           &fatal_error("change_not_allowed");            &fatal_error("change_not_allowed");
       }        }
   } else {    } else {
       &fatal_error("bad_postnumber","$postid");        &fatal_error("bad_postnumber","$postid");
   }    }
   
   ($tnum, $tsub, $tname, $temail, $tdate, $treplies, $tusername, $ticon, $tstate) = split(/\|/, $yyThreadLine);    ($tnum, $tsub, $tname, $temail, $tdate, $treplies, $tusername, $ticon, $tstate) = split(/\|/, $yyThreadLine);
   
   $postthread = 2 if $postid;    $postthread = 2 if $postid;
   
   # the post is to be modified...    # the post is to be modified...
   $name    = $FORM{'name'};    $name    = $FORM{'name'};
   $email   = $FORM{'email'};    $email   = $FORM{'email'};
   $subject = $FORM{'subject'};    $subject = $FORM{'subject'};
   $message = $FORM{'message'};    $message = $FORM{'message'};
   $icon    = $FORM{'icon'};    $icon    = $FORM{'icon'};
   $ns      = $FORM{'ns'};    $ns      = $FORM{'ns'};
   $notify  = $FORM{'notify'};    $notify  = $FORM{'notify'};
   $thestatus = $FORM{'topicstatus'};    $thestatus = $FORM{'topicstatus'};
   $thestatus =~ s/\, //g;    $thestatus =~ s/\, //g;
   &CheckIcon;    &CheckIcon;
   
   &fatal_error("no_message") unless ($message);    &fatal_error("no_message") unless ($message);
   
   $spamdetected = &spamcheck("$subject $message");    $spamdetected = &spamcheck("$subject $message");
   if (!${$uid.$FORM{$username}}{'spamcount'}) { ${$uid.$FORM{$username}}{'spamcount'} = 0; }    if (!${$uid.$FORM{$username}}{'spamcount'}) { ${$uid.$FORM{$username}}{'spamcount'} = 0; }
   $postspeed = $date - $posttime;    $postspeed = $date - $posttime;
   if (!$iamadmin && !$iamgmod && !$iammod){    if (!$iamadmin && !$iamgmod && !$iammod){
       if (($speedpostdetection && $postspeed < $min_post_speed) || $spamdetected == 1) {        if (($speedpostdetection && $postspeed < $min_post_speed) || $spamdetected == 1) {
           ${$uid.$username}{'spamcount'}++;            ${$uid.$username}{'spamcount'}++;
           ${$uid.$username}{'spamtime'} = $date;            ${$uid.$username}{'spamtime'} = $date;
           &UserAccount($username,"update");            &UserAccount($username,"update");
           $spam_hits_left_count = $post_speed_count - ${$uid.$username}{'spamcount'};            $spam_hits_left_count = $post_speed_count - ${$uid.$username}{'spamcount'};
           if ($spamdetected == 1){ &fatal_error("tsc_alert"); } else { &fatal_error("speed_alert"); }            if ($spamdetected == 1){ &fatal_error("tsc_alert"); } else { &fatal_error("speed_alert"); }
       }        }
   }    }
   
   my $mess_len = $message;    my $mess_len = $message;
   $mess_len =~ s/[\r\n ]//ig;    $mess_len =~ s/[\r\n ]//ig;
   $mess_len =~ s/&#\d{3,}?\;/X/ig;    $mess_len =~ s/&#\d{3,}?\;/X/ig;
   if (length($mess_len) > $MaxMessLen) {    if (length($mess_len) > $MaxMessLen) {
       require "$sourcedir/Post.pl";        require "$sourcedir/Post.pl";
       &Preview($post_txt{'536'} . " " . (length($mess_len) - $MaxMessLen) . " " . $post_txt{'537'});        &Preview($post_txt{'536'} . " " . (length($mess_len) - $MaxMessLen) . " " . $post_txt{'537'});
   }    }
   undef $mess_len;    undef $mess_len;
   
   &FromChars($subject);    &FromChars($subject);
   $convertstr = $subject;    $convertstr = $subject;
   $convertcut = $set_subjectMaxLength + ($subject =~ /^Re: / ? 4 : 0);    $convertcut = $set_subjectMaxLength + ($subject =~ /^Re: / ? 4 : 0);
    &CountChars;     &CountChars;
   $subject = $convertstr;    $subject = $convertstr;
   &ToHTML($subject);    &ToHTML($subject);
   
   &ToHTML($name);    &ToHTML($name);
   $email =~ s/\|//g;    $email =~ s/\|//g;
   &ToHTML($email);    &ToHTML($email);
   &fatal_error("no_subject") unless ($subject && $subject !~ m~\A[\s_.,]+\Z~);    &fatal_error("no_subject") unless ($subject && $subject !~ m~\A[\s_.,]+\Z~);
   my $testmessage = $message;    my $testmessage = $message;
   &ToChars($testmessage);    &ToChars($testmessage);
   $testmessage =~ s/[\r\n\ ]//g;    $testmessage =~ s/[\r\n\ ]//g;
   $testmessage =~ s/\&nbsp;//g;    $testmessage =~ s/\&nbsp;//g;
   $testmessage =~ s~\[table\].*?\[tr\].*?\[td\]~~g;    $testmessage =~ s~\[table\].*?\[tr\].*?\[td\]~~g;
   $testmessage =~ s~\[/td\].*?\[/tr\].*?\[/table\]~~g;    $testmessage =~ s~\[/td\].*?\[/tr\].*?\[/table\]~~g;
   $testmessage =~ s/\[.*?\]//g;    $testmessage =~ s/\[.*?\]//g;
   if ($testmessage eq "" && $message ne "" && $pollthread != 2) { fatal_error("useless_post","$testmessage"); }    if ($testmessage eq "" && $message ne "" && $pollthread != 2) { fatal_error("useless_post","$testmessage"); }
   
   if (!$minlinkpost){ $minlinkpost = 0 ;}    if (!$minlinkpost){ $minlinkpost = 0 ;}
   if (${$uid.$username}{'postcount'} < $minlinkpost && !$iamadmin && !$iamgmod && !$iammod && !$iamguest) {      if (${$uid.$username}{'postcount'} < $minlinkpost && !$iamadmin && !$iamgmod && !$iammod && !$iamguest) {  
       if ($message =~ m~http:\/\/~ || $message =~ m~https:\/\/~ || $message =~ m~ftp:\/\/~ || $message =~ m~www.~ || $message =~ m~ftp.~ =~ m~\[url~ || $message=~ m~\[link~ || $message=~ m~\[img~ || $message=~ m~\[ftp~) {        if ($message =~ m~http:\/\/~ || $message =~ m~https:\/\/~ || $message =~ m~ftp:\/\/~ || $message =~ m~www.~ || $message =~ m~ftp.~ =~ m~\[url~ || $message=~ m~\[link~ || $message=~ m~\[img~ || $message=~ m~\[ftp~) {
           &fatal_error("no_links_allowed");            &fatal_error("no_links_allowed");
       }        }
   }    }
   
   &FromChars($message);    &FromChars($message);
   $message =~ s/\cM//g;    $message =~ s/\cM//g;
   $message =~ s~\[([^\]]{0,30})\n([^\]]{0,30})\]~\[$1$2\]~g;    $message =~ s~\[([^\]]{0,30})\n([^\]]{0,30})\]~\[$1$2\]~g;
   $message =~ s~\[/([^\]]{0,30})\n([^\]]{0,30})\]~\[/$1$2\]~g;    $message =~ s~\[/([^\]]{0,30})\n([^\]]{0,30})\]~\[/$1$2\]~g;
   $message =~ s~(\w+://[^<>\s\n\"\]\[]+)\n([^<>\s\n\"\]\[]+)~$1\n$2~g;    $message =~ s~(\w+://[^<>\s\n\"\]\[]+)\n([^<>\s\n\"\]\[]+)~$1\n$2~g;
   &ToHTML($message);    &ToHTML($message);
   $message =~ s/\t/ \&nbsp; \&nbsp; \&nbsp;/g;    $message =~ s/\t/ \&nbsp; \&nbsp; \&nbsp;/g;
   $message =~ s~\n~<br />~g;    $message =~ s~\n~<br />~g;
   if ($postid == 0) {    if ($postid == 0) {
       $tsub  = $subject;        $tsub  = $subject;
       $ticon = $icon;        $ticon = $icon;
   }    }
   
   if ($tstate =~ /l/i) {    if ($tstate =~ /l/i) {
       my $icanbypass = &checkUserLockBypass if $bypass_lock_perm;        my $icanbypass = &checkUserLockBypass if $bypass_lock_perm;
       if (!$icanbypass) { &fatal_error('topic_locked');}        if (!$icanbypass) { &fatal_error('topic_locked');}
   }    }
   if ($iammod || $iamgmod || $iamadmin) {    if ($iammod || $iamgmod || $iamadmin) {
       $thestatus =~ s/0//g;        $thestatus =~ s/0//g;
       $tstate = $tstate =~ /a/i ? "0a$thestatus" : "0$thestatus";        $tstate = $tstate =~ /a/i ? "0a$thestatus" : "0$thestatus";
       &MessageTotals("load", $tnum);        &MessageTotals("load", $tnum);
       ${$tnum}{'threadstatus'} = $tstate;        ${$tnum}{'threadstatus'} = $tstate;
       &MessageTotals("update", $tnum);        &MessageTotals("update", $tnum);
   }    }
   
   $yyThreadLine = qq~$tnum|$tsub|$tname|$temail|$tdate|$treplies|$tusername|$ticon|$tstate~;    $yyThreadLine = qq~$tnum|$tsub|$tname|$temail|$tdate|$treplies|$tusername|$ticon|$tstate~;
   
   if ($mip =~ /$user_ip/) { $useredit_ip = $mip; }    if ($mip =~ /$user_ip/) { $useredit_ip = $mip; }
   else { $useredit_ip = "$mip $user_ip"; }    else { $useredit_ip = "$mip $user_ip"; }
   
   my (@attachments,%post_attach,%del_filename);    my (@attachments,%post_attach,%del_filename);
   fopen(ATM, "+<$vardir/attachments.txt");    fopen(ATM, "+<$vardir/attachments.txt");
   seek ATM, 0, 0;    seek ATM, 0, 0;
   while (<ATM>) {    while (<ATM>) {
       $_ =~ /^(\d+)\|(\d+)\|.+\|(.+)\|\d+\s+/;        $_ =~ /^(\d+)\|(\d+)\|.+\|(.+)\|\d+\s+/;
       $del_filename{$3}++;        $del_filename{$3}++;
       if ($threadid == $1 && $postid == $2) {        if ($threadid == $1 && $postid == $2) {
           $post_attach{$3} = $_;            $post_attach{$3} = $_;
       } else {        } else {
           push(@attachments, $_);            push(@attachments, $_);
       }        }
   }    }
   
   my ($file,$fixfile,@filelist,@newfilelist,@attachmentsfile);    my ($file,$fixfile,@filelist,@newfilelist,@attachmentsfile);
   for (my $y = 1; $y <= $allowattach; ++$y) {    for (my $y = 1; $y <= $allowattach; ++$y) {
       $file = $CGI_query->upload("file$y") if $CGI_query;        $file = $CGI_query->upload("file$y") if $CGI_query;
       if ($file && ($FORM{"w_file$y"} eq "attachnew" || !exists $FORM{"w_file$y"})) {        if ($file && ($FORM{"w_file$y"} eq "attachnew" || !exists $FORM{"w_file$y"})) {
           $fixfile = $file;            $fixfile = $file;
           $fixfile =~ s/.+\\([^\\]+)$|.+\/([^\/]+)$/$1/;            $fixfile =~ s/.+\\([^\\]+)$|.+\/([^\/]+)$/$1/;
           $fixfile =~ s/[^0-9A-Za-z\+\-\.:_]/_/g; # replace all inappropriate with the "_" character.            $fixfile =~ s/[^0-9A-Za-z\+\-\.:_]/_/g; # replace all inappropriate with the "_" character.
   
           # replace . with _ in the filename except for the extension            # replace . with _ in the filename except for the extension
           my $fixname = $fixfile;            my $fixname = $fixfile;
           $fixname =~ s/(.+)(\..+?)$/$1/;            $fixname =~ s/(.+)(\..+?)$/$1/;
           my $fixext = $2;            my $fixext = $2;
   
           my $spamdetected = &spamcheck("$fixname");            my $spamdetected = &spamcheck("$fixname");
           if (!$iamadmin && !$iamgmod && !$iammod){            if (!$iamadmin && !$iamgmod && !$iammod){
               if ($spamdetected == 1) {                if ($spamdetected == 1) {
                   ${$uid.$username}{'spamcount'}++;                    ${$uid.$username}{'spamcount'}++;
                   ${$uid.$username}{'spamtime'} = $date;                    ${$uid.$username}{'spamtime'} = $date;
                   &UserAccount($username,"update");                    &UserAccount($username,"update");
                   $spam_hits_left_count = $post_speed_count - ${$uid.$username}{'spamcount'};                    $spam_hits_left_count = $post_speed_count - ${$uid.$username}{'spamcount'};
                   foreach (@newfilelist) { unlink("$uploaddir/$_"); }                    foreach (@newfilelist) { unlink("$uploaddir/$_"); }
                   &fatal_error("tsc_alert");                    &fatal_error("tsc_alert");
               }                }
           }            }
                    if ($use_guardian && $string_on) {  
                         @bannedstrings = split(/\|/, $banned_strings);  
                         foreach (@bannedstrings) {  
                             chomp $_;  
                             if ($fixname =~ m/$_/i) { &fatal_error("attach_name_blocked","($_)"); }  
                         }  
                 }  
           $fixext  =~ s/\.(pl|pm|cgi|php)/._$1/i;            $fixext  =~ s/\.(pl|pm|cgi|php)/._$1/i;
           $fixname =~ s/\./_/g;            $fixname =~ s/\./_/g;
           $fixfile = qq~$fixname$fixext~;            $fixfile = qq~$fixname$fixext~;
   
           unlink(qq~$uploaddir/$FORM{"w_filename$y"}~) if $FORM{"w_filename$y"};            unlink(qq~$uploaddir/$FORM{"w_filename$y"}~) if $FORM{"w_filename$y"};
           if (!$overwrite) { $fixfile = &check_existence($uploaddir, $fixfile); }            if (!$overwrite) { $fixfile = &check_existence($uploaddir, $fixfile); }
           elsif ($overwrite == 2 && -e "$uploaddir/$fixfile") {            elsif ($overwrite == 2 && -e "$uploaddir/$fixfile") {
               foreach (@newfilelist) { unlink("$uploaddir/$_"); }                foreach (@newfilelist) { unlink("$uploaddir/$_"); }
               &fatal_error("file_overwrite");                &fatal_error("file_overwrite");
           }            }
   
           my $match = 0;            my $match = 0;
           if (!$checkext) { $match = 1; }            if (!$checkext) { $match = 1; }
           else {            else {
               foreach $ext (@ext) {                foreach $ext (@ext) {
                   if (grep /$ext$/i, $fixfile) { $match = 1; last; }                    if (grep /$ext$/i, $fixfile) { $match = 1; last; }
               }                }
           }            }
           if ($match) {            if ($match) {
               unless ($allowattach && (($allowguestattach == 0 && $username ne 'Guest') || $allowguestattach == 1)) {                unless ($allowattach && (($allowguestattach == 0 && $username ne 'Guest') || $allowguestattach == 1)) {
                   foreach (@newfilelist) { unlink("$uploaddir/$_"); }                    foreach (@newfilelist) { unlink("$uploaddir/$_"); }
                   &fatal_error("no_perm_att");                    &fatal_error("no_perm_att");
               }                }
           } else {            } else {
               foreach (@newfilelist) { unlink("$uploaddir/$_"); }                foreach (@newfilelist) { unlink("$uploaddir/$_"); }
               require "$sourcedir/Post.pl";                require "$sourcedir/Post.pl";
               &Preview("$fixfile $fatxt{'20'} @ext");                &Preview("$fixfile $fatxt{'20'} @ext");
           }            }
   
           my ($size,$buffer,$filesize,$file_buffer);            my ($size,$buffer,$filesize,$file_buffer);
           while ($size = read($file, $buffer, 512)) { $filesize += $size; $file_buffer .= $buffer; }            while ($size = read($file, $buffer, 512)) { $filesize += $size; $file_buffer .= $buffer; }
           if ($limit && $filesize > (1024 * $limit)) {            if ($limit && $filesize > (1024 * $limit)) {
               foreach (@newfilelist) { unlink("$uploaddir/$_"); }                foreach (@newfilelist) { unlink("$uploaddir/$_"); }
               require "$sourcedir/Post.pl";                require "$sourcedir/Post.pl";
               &Preview("$fatxt{'21'} $fixfile (" . int($filesize / 1024) . " KB) $fatxt{'21b'} " . $limit);                &Preview("$fatxt{'21'} $fixfile (" . int($filesize / 1024) . " KB) $fatxt{'21b'} " . $limit);
           }            }
           if ($dirlimit) {            if ($dirlimit) {
               my $dirsize = &dirsize($uploaddir);                my $dirsize = &dirsize($uploaddir);
               if ($filesize > ((1024 * $dirlimit) - $dirsize)) {                if ($filesize > ((1024 * $dirlimit) - $dirsize)) {
                   foreach (@newfilelist) { unlink("$uploaddir/$_"); }                    foreach (@newfilelist) { unlink("$uploaddir/$_"); }
                   require "$sourcedir/Post.pl";                    require "$sourcedir/Post.pl";
                   &Preview("$fatxt{'22'} $fixfile (" . (int($filesize / 1024) - $dirlimit + int($dirsize / 1024)) . " KB) $fatxt{'22b'}");                    &Preview("$fatxt{'22'} $fixfile (" . (int($filesize / 1024) - $dirlimit + int($dirsize / 1024)) . " KB) $fatxt{'22b'}");
               }                }
           }            }
   
           # create a new file on the server using the formatted ( new instance ) filename            # create a new file on the server using the formatted ( new instance ) filename
           if (fopen(NEWFILE, ">$uploaddir/$fixfile")) {            if (fopen(NEWFILE, ">$uploaddir/$fixfile")) {
               binmode NEWFILE; # needed for operating systems (OS) Windows, ignored by Linux                binmode NEWFILE; # needed for operating systems (OS) Windows, ignored by Linux
               print NEWFILE $file_buffer; # write new file on HD                print NEWFILE $file_buffer; # write new file on HD
               fclose(NEWFILE);                fclose(NEWFILE);
   
           } else { # return the server's error message if the new file could not be created            } else { # return the server's error message if the new file could not be created
               foreach (@newfilelist) { unlink("$uploaddir/$_"); }                foreach (@newfilelist) { unlink("$uploaddir/$_"); }
               &fatal_error("file_not_open","$uploaddir");                &fatal_error("file_not_open","$uploaddir");
           }            }
   
           # check if file has actually been uploaded, by checking the file has a size            # check if file has actually been uploaded, by checking the file has a size
           my $filesizekb = -s "$uploaddir/$fixfile";            my $filesizekb = -s "$uploaddir/$fixfile";
           unless ($filesizekb) {            unless ($filesizekb) {
               foreach (qw("@newfilelist" $fixfile)) { unlink("$uploaddir/$_"); }                foreach (qw("@newfilelist" $fixfile)) { unlink("$uploaddir/$_"); }
               &fatal_error("file_not_uploaded",$fixfile);                &fatal_error("file_not_uploaded",$fixfile);
           }            }
           $filesizekb = int($filesizekb / 1024);            $filesizekb = int($filesizekb / 1024);
   
           if ($fixfile =~ /\.(jpg|gif|png|jpeg)$/i) {            if ($fixfile =~ /\.(jpg|gif|png|jpeg)$/i) {
               my $okatt = 1;                my $okatt = 1;
               if ($fixfile =~ /gif$/i) {                if ($fixfile =~ /gif$/i) {
                   my $header;                    my $header;
                   fopen(ATTFILE, "$uploaddir/$fixfile");                    fopen(ATTFILE, "$uploaddir/$fixfile");
                   read(ATTFILE, $header, 10);                    read(ATTFILE, $header, 10);
                   my $giftest;                    my $giftest;
                   ($giftest, undef, undef, undef, undef, undef) = unpack("a3a3C4", $header);                    ($giftest, undef, undef, undef, undef, undef) = unpack("a3a3C4", $header);
                   fclose(ATTFILE);                    fclose(ATTFILE);
                   if ($giftest ne "GIF") { $okatt = 0; }                    if ($giftest ne "GIF") { $okatt = 0; }
               }                }
               fopen(ATTFILE, "$uploaddir/$fixfile");                fopen(ATTFILE, "$uploaddir/$fixfile");
               while ( read(ATTFILE, $buffer, 1024) ) {                while ( read(ATTFILE, $buffer, 1024) ) {
                   if ($buffer =~ /<(html|script|body)/ig) { $okatt = 0; last; }                    if ($buffer =~ /<(html|script|body)/ig) { $okatt = 0; last; }
               }                }
               fclose(ATTFILE);                fclose(ATTFILE);
               if(!$okatt) { # delete the file as it contains illegal code                if(!$okatt) { # delete the file as it contains illegal code
                   foreach (qw("@newfilelist" $fixfile)) { unlink("$uploaddir/$_"); }                    foreach (qw("@newfilelist" $fixfile)) { unlink("$uploaddir/$_"); }
                   &fatal_error("file_not_uploaded","$fixfile <= illegal code inside image file!");                    &fatal_error("file_not_uploaded","$fixfile <= illegal code inside image file!");
               }                }
           }            }
   
           push(@newfilelist, $fixfile);            push(@newfilelist, $fixfile);
           push(@filelist, $fixfile);            push(@filelist, $fixfile);
           push(@attachments, qq~$threadid|$postid|$subject|$mname|$currentboard|$filesizekb|$date|$fixfile|0\n~);            push(@attachments, qq~$threadid|$postid|$subject|$mname|$currentboard|$filesizekb|$date|$fixfile|0\n~);
   
       } elsif ($FORM{"w_filename$y"}) {        } elsif ($FORM{"w_filename$y"}) {
           if ($FORM{"w_file$y"} eq "attachdel") {            if ($FORM{"w_file$y"} eq "attachdel") {
               unlink(qq~$uploaddir/$FORM{"w_filename$y"}~) if $del_filename{$FORM{"w_filename$y"}} == 1;                unlink(qq~$uploaddir/$FORM{"w_filename$y"}~) if $del_filename{$FORM{"w_filename$y"}} == 1;
               $del_filename{$FORM{"w_filename$y"}}--;                $del_filename{$FORM{"w_filename$y"}}--;
           } elsif ($FORM{"w_file$y"} eq "attachold") {            } elsif ($FORM{"w_file$y"} eq "attachold") {
               push(@filelist, $FORM{"w_filename$y"});                push(@filelist, $FORM{"w_filename$y"});
               push(@attachments, $post_attach{$FORM{"w_filename$y"}});                push(@attachments, $post_attach{$FORM{"w_filename$y"}});
           }            }
       }        }
   }    }
   # Print attachments.txt    # Print attachments.txt
   truncate ATM, 0;    truncate ATM, 0;
   seek ATM, 0, 0;    seek ATM, 0, 0;
   print ATM sort { (split /\|/,$a)[6] <=> (split /\|/,$b)[6] } @attachments;    print ATM sort { (split /\|/,$a)[6] <=> (split /\|/,$b)[6] } @attachments;
   fclose(ATM);    fclose(ATM);
   
   # Create the list of files    # Create the list of files
   $fixfile = join(",", @filelist);    $fixfile = join(",", @filelist);
   
   ${$thread_arrayref{$threadid}}[$postid] = qq~$subject|$mname|$memail|$mdate|$musername|$icon|0|$useredit_ip|$message|$ns|$date|$username|$fixfile\n~;    ${$thread_arrayref{$threadid}}[$postid] = qq~$subject|$mname|$memail|$mdate|$musername|$icon|0|$useredit_ip|$message|$ns|$date|$username|$fixfile\n~;
   fopen(FILE, ">$datadir/$threadid.txt") || &fatal_error("cannot_open","$datadir/$threadid.txt",1);    fopen(FILE, ">$datadir/$threadid.txt") || &fatal_error("cannot_open","$datadir/$threadid.txt",1);
   print FILE @{$thread_arrayref{$threadid}};    print FILE @{$thread_arrayref{$threadid}};
   fclose(FILE);    fclose(FILE);
   
   if ($postid == 0 || $iammod || $iamgmod || $iamadmin) {    if ($postid == 0 || $iammod || $iamgmod || $iamadmin) {
       # Save the current board. icon, status or subject may have changed -> update board info        # Save the current board. icon, status or subject may have changed -> update board info
       fopen(BOARD, "+<$boardsdir/$currentboard.txt") || &fatal_error("cannot_open","$boardsdir/$currentboard.txt",1);        fopen(BOARD, "+<$boardsdir/$currentboard.txt") || &fatal_error("cannot_open","$boardsdir/$currentboard.txt",1);
       my @board = <BOARD>;        my @board = <BOARD>;
       for (my $a = 0; $a < @board; $a++) {        for (my $a = 0; $a < @board; $a++) {
           if ($board[$a] =~ m~\A$threadid\|~o) { $board[$a] = "$yyThreadLine\n"; last; }            if ($board[$a] =~ m~\A$threadid\|~o) { $board[$a] = "$yyThreadLine\n"; last; }
       }        }
       truncate BOARD, 0;        truncate BOARD, 0;
       seek BOARD, 0, 0;        seek BOARD, 0, 0;
       print BOARD @board;        print BOARD @board;
       fclose(BOARD);        fclose(BOARD);
   
       &BoardSetLastInfo($currentboard,\@board);        &BoardSetLastInfo($currentboard,\@board);
   
   } elsif ($postid == $#{$thread_arrayref{$threadid}}) {    } elsif ($postid == $#{$thread_arrayref{$threadid}}) {
       # maybe last message changed subject and/or icon -> update board info        # maybe last message changed subject and/or icon -> update board info
       fopen(BOARD, "$boardsdir/$currentboard.txt") || &fatal_error('cannot_open', "$boardsdir/$currentboard.txt", 1);        fopen(BOARD, "$boardsdir/$currentboard.txt") || &fatal_error('cannot_open', "$boardsdir/$currentboard.txt", 1);
       my @board = <BOARD>;        my @board = <BOARD>;
       fclose(BOARD);        fclose(BOARD);
       &BoardSetLastInfo($currentboard,\@board);        &BoardSetLastInfo($currentboard,\@board);
   }    }
   
   require "$sourcedir/Notify.pl";    require "$sourcedir/Notify.pl";
   if ($notify) {    if ($notify) {
       &ManageThreadNotify("add", $threadid, $username, ${$uid.$username}{'language'}, 1, 1);        &ManageThreadNotify("add", $threadid, $username, ${$uid.$username}{'language'}, 1, 1);
   } else {    } else {
       &ManageThreadNotify("delete", $threadid, $username);        &ManageThreadNotify("delete", $threadid, $username);
   }    }
   
   if (${$uid.$username}{'postlayout'} ne "$FORM{'messageheight'}|$FORM{'messagewidth'}|$FORM{'txtsize'}|$FORM{'col_row'}") {    if (${$uid.$username}{'postlayout'} ne "$FORM{'messageheight'}|$FORM{'messagewidth'}|$FORM{'txtsize'}|$FORM{'col_row'}") {
       ${$uid.$username}{'postlayout'} = "$FORM{'messageheight'}|$FORM{'messagewidth'}|$FORM{'txtsize'}|$FORM{'col_row'}";        ${$uid.$username}{'postlayout'} = "$FORM{'messageheight'}|$FORM{'messagewidth'}|$FORM{'txtsize'}|$FORM{'col_row'}";
       &UserAccount($username, "update");        &UserAccount($username, "update");
   }    }
   
   my $start = !$ttsreverse ? (int($postid / $maxmessagedisplay) * $maxmessagedisplay) : $treplies - (int(($treplies - $postid) / $maxmessagedisplay) * $maxmessagedisplay);    my $start = !$ttsreverse ? (int($postid / $maxmessagedisplay) * $maxmessagedisplay) : $treplies - (int(($treplies - $postid) / $maxmessagedisplay) * $maxmessagedisplay);
   $yySetLocation = qq~$scripturl?num=$threadid/$start#$postid~;    $yySetLocation = qq~$scripturl?num=$threadid/$start#$postid~;
   &redirectexit;    &redirectexit;
} }
   
sub MultiDel { # deletes singel- or multi-Posts sub MultiDel { # deletes singel- or multi-Posts
   $thread = $INFO{'thread'};    $thread = $INFO{'thread'};
   
   unless (ref($thread_arrayref{$thread})) {    unless (ref($thread_arrayref{$thread})) {
       fopen(FILE, "$datadir/$thread.txt") || &fatal_error("cannot_open","$datadir/$thread.txt",1);        fopen(FILE, "$datadir/$thread.txt") || &fatal_error("cannot_open","$datadir/$thread.txt",1);
       @{$thread_arrayref{$thread}} = <FILE>;        @{$thread_arrayref{$thread}} = <FILE>;
       fclose(FILE);        fclose(FILE);
   }    }
   my @messages = @{$thread_arrayref{$thread}};    my @messages = @{$thread_arrayref{$thread}};
   
   # check all checkboxes, delete posts if checkbox is ticked    # check all checkboxes, delete posts if checkbox is ticked
   my $kill = 0;    my $kill = 0;
   my $postid;    my $postid;
   for ($count = $#messages; $count >= 0; $count--) {    for ($count = $#messages; $count >= 0; $count--) {
       if ($FORM{"del$count"} ne '') {        if ($FORM{"del$count"} ne '') {
           chomp $messages[$count];            chomp $messages[$count];
           @message = split(/\|/, $messages[$count]);            @message = split(/\|/, $messages[$count]);
           $musername = $message[4];            $musername = $message[4];
   
           # Checks that the user is actually allowed to access multidel            # Checks that the user is actually allowed to access multidel
           if (${$uid.$username}{'regdate'} > $message[3] || (!$iamadmin && !$iamgmod && !$iammod && $musername ne $username) || !$sessionvalid) { &fatal_error("delete_not_allowed"); }            if (${$uid.$username}{'regdate'} > $message[3] || (!$iamadmin && !$iamgmod && !$iammod && $musername ne $username) || !$sessionvalid) { &fatal_error("delete_not_allowed"); }
           if (!$iamadmin && !$iamgmod && !$iammod && $tlnodelflag && $date > $message[3] + ($tlnodeltime * 3600 * 24)) { &fatal_error("time_locked","$tlnodeltime$timelocktxt{'02a'}"); }            if (!$iamadmin && !$iamgmod && !$iammod && $tlnodelflag && $date > $message[3] + ($tlnodeltime * 3600 * 24)) { &fatal_error("time_locked","$tlnodeltime$timelocktxt{'02a'}"); }
   
           if ($message[12]) { # delete post attachments            if ($message[12]) { # delete post attachments
               require "$admindir/Attachments.pl";                require "$admindir/Attachments.pl";
               my %remattach;                my %remattach;
               $message[12] =~ s/,/|/g;                $message[12] =~ s/,/|/g;
               $remattach{$thread} = $message[12];                $remattach{$thread} = $message[12];
               &RemoveAttachments(\%remattach);                &RemoveAttachments(\%remattach);
           }            }
   
           splice(@messages, $count, 1);            splice(@messages, $count, 1);
           $kill++;            $kill++;
           $postid = $count if $kill == 1;            $postid = $count if $kill == 1;
   
           # decrease members post count if not in a zero post count board            # decrease members post count if not in a zero post count board
           unless (${$uid.$currentboard}{'zero'} || $musername eq 'Guest' || $message[6] eq 'no_postcount') {            unless (${$uid.$currentboard}{'zero'} || $musername eq 'Guest' || $message[6] eq 'no_postcount') {
               if (!${$uid.$musername}{'password'}) {                if (!${$uid.$musername}{'password'}) {
                   &LoadUser($musername);                    &LoadUser($musername);
               }                }
               if (${$uid.$musername}{'postcount'} > 0) {                if (${$uid.$musername}{'postcount'} > 0) {
                   ${$uid.$musername}{'postcount'}--;                    ${$uid.$musername}{'postcount'}--;
                   &UserAccount($musername, "update");                    &UserAccount($musername, "update");
               }                }
               if (${$uid.$musername}{'position'}) {                if (${$uid.$musername}{'position'}) {
                   $grp_after = qq~${$uid.$musername}{'position'}~;                    $grp_after = qq~${$uid.$musername}{'position'}~;
               } else {                } else {
                   foreach $postamount (sort { $b <=> $a } keys %Post) {                    foreach $postamount (sort { $b <=> $a } keys %Post) {
                       if (${$uid.$musername}{'postcount'} > $postamount) {                        if (${$uid.$musername}{'postcount'} > $postamount) {
                           ($grp_after, undef) = split(/\|/, $Post{$postamount}, 2);                            ($grp_after, undef) = split(/\|/, $Post{$postamount}, 2);
                           last;                            last;
                       }                        }
                   }                    }
               }                }
               &ManageMemberinfo("update", $musername, '', '', $grp_after, ${$uid.$musername}{'postcount'});                &ManageMemberinfo("update", $musername, '', '', $grp_after, ${$uid.$musername}{'postcount'});
   
               my ($md,$mu,$mdmu);                my ($md,$mu,$mdmu);
               foreach (reverse @messages) {                foreach (reverse @messages) {
                   (undef, undef, undef, $md, $mu, undef) = split(/\|/, $_, 6);                    (undef, undef, undef, $md, $mu, undef) = split(/\|/, $_, 6);
                   if ($mu eq $musername) { $mdmu = $md; last; }                    if ($mu eq $musername) { $mdmu = $md; last; }
               }                }
               &Recent_Write("decr", $thread, $musername, $mdmu);                &Recent_Write("decr", $thread, $musername, $mdmu);
           }            }
       }        }
   }    }
   
   if (!@messages) {    if (!@messages) {
       # all post was deleted, call removethread        # all post was deleted, call removethread
       require "$sourcedir/Favorites.pl";        require "$sourcedir/Favorites.pl";
       $INFO{'ref'} = "delete";        $INFO{'ref'} = "delete";
       &RemFav($thread);        &RemFav($thread);
   
       require "$sourcedir/RemoveTopic.pl";        require "$sourcedir/RemoveTopic.pl";
       $iamposter = ($message[4] eq $username) ? 1 : 0;        $iamposter = ($message[4] eq $username) ? 1 : 0;
       &DeleteThread($thread);        &DeleteThread($thread);
   }    }
   @{$thread_arrayref{$thread}} = @messages;    @{$thread_arrayref{$thread}} = @messages;
   
   # if thread has not been deleted: update thread, update message index details ...    # if thread has not been deleted: update thread, update message index details ...
   fopen(FILE, ">$datadir/$thread.txt") || &fatal_error("cannot_open","$datadir/$thread.txt",1);    fopen(FILE, ">$datadir/$thread.txt") || &fatal_error("cannot_open","$datadir/$thread.txt",1);
   print FILE @{$thread_arrayref{$thread}};    print FILE @{$thread_arrayref{$thread}};
   fclose(FILE);    fclose(FILE);
   
   my @firstmessage = split(/\|/, ${$thread_arrayref{$thread}}[0]);    my @firstmessage = split(/\|/, ${$thread_arrayref{$thread}}[0]);
   my @lastmessage  = split(/\|/, ${$thread_arrayref{$thread}}[$#{$thread_arrayref{$thread}}]);    my @lastmessage  = split(/\|/, ${$thread_arrayref{$thread}}[$#{$thread_arrayref{$thread}}]);
   
   # update the current thread    # update the current thread
   &MessageTotals("load", $thread);    &MessageTotals("load", $thread);
   ${$thread}{'replies'} = $#{$thread_arrayref{$thread}};    ${$thread}{'replies'} = $#{$thread_arrayref{$thread}};
   ${$thread}{'lastposter'} = $lastmessage[4] eq "Guest" ? qq~Guest-$lastmessage[1]~ : $lastmessage[4];    ${$thread}{'lastposter'} = $lastmessage[4] eq "Guest" ? qq~Guest-$lastmessage[1]~ : $lastmessage[4];
   &MessageTotals("update", $thread);    &MessageTotals("update", $thread);
   
   # update the current board.    # update the current board.
   &BoardTotals("load", $currentboard);    &BoardTotals("load", $currentboard);
   ${$uid.$currentboard}{'messagecount'} -= $kill;    ${$uid.$currentboard}{'messagecount'} -= $kill;
    # &BoardTotals("update", ...) is done later in &BoardSetLastInfo     # &BoardTotals("update", ...) is done later in &BoardSetLastInfo
   
   my $threadline = '';    my $threadline = '';
   fopen(BOARDFILE, "+<$boardsdir/$currentboard.txt") || &fatal_error("cannot_open","$boardsdir/$currentboard.txt",1);    fopen(BOARDFILE, "+<$boardsdir/$currentboard.txt") || &fatal_error("cannot_open","$boardsdir/$currentboard.txt",1);
   my @buffer = <BOARDFILE>;    my @buffer = <BOARDFILE>;
   
   my $a;    my $a;
   for ($a = 0; $a < @buffer; $a++) {    for ($a = 0; $a < @buffer; $a++) {
       if ($buffer[$a] =~ /^$thread\|/) {        if ($buffer[$a] =~ /^$thread\|/) {
           $threadline = $buffer[$a];            $threadline = $buffer[$a];
           splice(@buffer, $a, 1);            splice(@buffer, $a, 1);
           last;            last;
       }        }
   }    }
   
   chomp $threadline;    chomp $threadline;
   my @newthreadline = split(/\|/, $threadline);    my @newthreadline = split(/\|/, $threadline);
   $newthreadline[1] = $firstmessage[0];         # subject of first message    $newthreadline[1] = $firstmessage[0];         # subject of first message
   $newthreadline[7] = $firstmessage[5];         # icon of first message    $newthreadline[7] = $firstmessage[5];         # icon of first message
   $newthreadline[4] = $lastmessage[3];          # date of last message    $newthreadline[4] = $lastmessage[3];          # date of last message
   $newthreadline[5] = ${$thread}{'replies'};    # replay number    $newthreadline[5] = ${$thread}{'replies'};    # replay number
   
   my $inserted = 0;    my $inserted = 0;
   for ($a = 0; $a < @buffer; $a++) {    for ($a = 0; $a < @buffer; $a++) {
       if ((split(/\|/, $buffer[$a], 6))[4] < $newthreadline[4]) {        if ((split(/\|/, $buffer[$a], 6))[4] < $newthreadline[4]) {
           splice(@buffer,$a,0,join("|", @newthreadline) . "\n");            splice(@buffer,$a,0,join("|", @newthreadline) . "\n");
           $inserted = 1;            $inserted = 1;
           last;            last;
       }        }
   }    }
   if (!$inserted) { push(@buffer, join("|", @newthreadline) . "\n"); }    if (!$inserted) { push(@buffer, join("|", @newthreadline) . "\n"); }
   
   truncate BOARDFILE, 0;    truncate BOARDFILE, 0;
   seek BOARDFILE, 0, 0;    seek BOARDFILE, 0, 0;
   print BOARDFILE @buffer;    print BOARDFILE @buffer;
   fclose(BOARDFILE);    fclose(BOARDFILE);
   
   &BoardSetLastInfo($currentboard,\@buffer);    &BoardSetLastInfo($currentboard,\@buffer);
   
   $postid = $postid > ${$thread}{'replies'} ? ${$thread}{'replies'} : ($postid - 1);    $postid = $postid > ${$thread}{'replies'} ? ${$thread}{'replies'} : ($postid - 1);
   my $start = !$ttsreverse ? (int($postid / $maxmessagedisplay) * $maxmessagedisplay) : ${$thread}{'replies'} - (int((${$thread}{'replies'} - $postid) / $maxmessagedisplay) * $maxmessagedisplay);    my $start = !$ttsreverse ? (int($postid / $maxmessagedisplay) * $maxmessagedisplay) : ${$thread}{'replies'} - (int((${$thread}{'replies'} - $postid) / $maxmessagedisplay) * $maxmessagedisplay);
   $yySetLocation = qq~$scripturl?num=$thread/$start#$postid~;    $yySetLocation = qq~$scripturl?num=$thread/$start#$postid~;
   
   &redirectexit;    &redirectexit;
} }
   
1; 1;