F:\WEBSITES\testbed\zipped\yabb_svn_new\branches\2.5.2\cgi-bin\yabb2\Sources\Downloads.pl F:\WEBSITES\testbed\zipped\yabb_svn_new\trunk\cgi-bin\yabb2\Sources\Downloads.pm
############################################################################### ###############################################################################
# Downloads.pl                                                                # # Downloads.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';
   
$downloadsplver = 'YaBB 2.5.2 $Revision: 1.1 $'; $downloadspmver = 'YaBB 2.6.12 $Revision: 1710 $';
if ($action eq 'detailedversion') { return 1; } if ( $action eq 'detailedversion' ) { return 1; }
   
  get_template('Downloads');
  get_micon();
   
sub DownloadView { sub DownloadView {
   &fatal_error("members_only") if $guest_media_disallowed && $iamguest;     if ( $guest_media_disallowed && $iamguest ) { fatal_error('members_only'); } 
   &LoadLanguage('FA');     LoadLanguage('FA'); 
   &print_output_header;     print_output_header(); 
   
   $output = qq~<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">     $output = $downloads_top; 
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">     $output =~ s/{yabb fatxt39}/$fatxt{'39'}/sm; 
<head>  
<title>$fatxt{'39'}</title>     my $thread = $INFO{'thread'}; 
<meta http-equiv="Content-Type" content="text/html; charset=$yycharset" />     if ( !ref $thread_arrayref{$thread} ) { 
<link rel="stylesheet" href="$forumstylesurl/$usestyle.css" type="text/css" />         fopen( MSGTXT, "$datadir/$thread.txt" ) 
           or fatal_error( 'cannot_open', "$datadir/$thread.txt", 1 );
<script language="JavaScript1.2" type="text/javascript">         @{ $thread_arrayref{$thread} } = <MSGTXT>; 
<!--         fclose(MSGTXT); 
   function download_file(amfn) {     } 
       window.open('$scripturl?action=downloadfile;file=' + encodeURIComponent(amfn),'_blank');     my $threadname = ( split /\|/xsm, ${ $thread_arrayref{$thread} }[0], 2 )[0]; 
       self.setTimeout('location.reload()', 3000);     my @attachinput = 
   }      map { split /,/xsm, ( split /\|/xsm, $_ )[12] }
   function load_thread(amthreadid,amreplies) {       @{ $thread_arrayref{$thread} }; 
       try{     chomp @attachinput; 
           if (typeof(opener.document) == 'object') throw '1';  
           else throw '0';     my ( %attachinput, $viewattachments ); 
       } catch (e) {     map { $attachinput{$_} = 1; } @attachinput; 
           if (amreplies > 0 || ~ . ((($ttsureverse && ${$uid.$username}{'reversetopic'}) || $ttsreverse) ? 1 : 0) . qq~ == 1) amreplies = '/' + amreplies + '#' + amreplies;  
           else amreplies = '';     fopen( AML, "$vardir/attachments.txt" ) 
           if (e == 1) {       or fatal_error( 'cannot_open', "$vardir/attachments.txt", 1 ); 
               opener.location.href='$scripturl?num=' + amthreadid + amreplies;     @attachinput = 
               self.close();       grep { $_ =~ /$thread\|.+\|(.+)\|\d+\s+/xsm && exists $attachinput{$1} } 
           } else {       <AML>; 
               location.href='$scripturl?num=' + amthreadid + amreplies;     fclose(AML); 
           }  
       }     my $max = @attachinput; 
   }  
// -->     my $sort = $INFO{'sort'} 
</script>       || ( 
</head>         ( 
<body>             ( $ttsureverse && ${ $uid . $username }{'reversetopic'} ) 
<a name="pagetop">&nbsp;</a><br />             || $ttsreverse 
<div id="maincontainer">         ) ? -1 : 1 
<div id="container">       ); 
<br />     my $newstart = $INFO{'newstart'} || 0; 
<br />~;  
     my $colspan = ( $iamadmin || $iamgmod ) ? 8 : 7;
     if ( !$max ) {
   my $thread = $INFO{'thread'};         $viewattachments .= $downloads_att; 
   unless (ref($thread_arrayref{$thread})) {         $viewattachments =~ s/{yabb colspan}/$colspan/gsm; 
       fopen(MSGTXT, "$datadir/$thread.txt") || &fatal_error("cannot_open","$datadir/$thread.txt", 1);         $viewattachments =~ s/{yabb colspan}/$colspan/gsm; 
       @{$thread_arrayref{$thread}} = <MSGTXT>;         $viewattachments =~ s/{yabb threadname}/$threadname/gsm; 
       fclose(MSGTXT);         $viewattachments =~ s/{yabb fatxt48}/$fatxt{'38'}/gsm; 
   }         $viewattachments =~ s/{yabb fatxt70}/$fatxt{'70'}/gsm; 
   my $threadname = (split(/\|/, ${$thread_arrayref{$thread}}[0], 2))[0];         $viewattachments =~ s/{yabb fatxt71}/$fatxt{'71'}/gsm; 
   my @attachinput = map { split(/,/, (split(/\|/, $_))[12]) } @{$thread_arrayref{$thread}};     } 
   chomp(@attachinput);     else { 
         if ( $iamadmin || $iamgmod ) {
   my (%attachinput,$viewattachments);             LoadLanguage('Admin'); 
   map { $attachinput{$_} = 1; } @attachinput;  
             $output .= qq~
   fopen(AML, "$vardir/attachments.txt") || &fatal_error("cannot_open","$vardir/attachments.txt", 1);         <script type="text/javascript"> 
   @attachinput = grep { $_ =~ /$thread\|.+\|(.+)\|\d+\s+/ && exists $attachinput{$1} } <AML>;             function checkAll() { 
   fclose(AML);                 for (var i = 0; i < document.del_attachments.elements.length; i++) { 
                     document.del_attachments.elements[i].checked = true;
   my $max = @attachinput;                 } 
             }
   my $sort = $INFO{'sort'} || ((($ttsureverse && ${$uid.$username}{'reversetopic'}) || $ttsreverse) ? -1 : 1);             function uncheckAll() { 
   my $newstart = $INFO{'newstart'} || 0;                 for (var i = 0; i < document.del_attachments.elements.length; i++) { 
                     document.del_attachments.elements[i].checked = false;
   my $colspan = ($iamadmin || $iamgmod) ? 8 : 7;                 } 
   if (!$max) {             } 
       $viewattachments .= qq~<tr><td align="center" class="windowbg2" colspan="$colspan"><b><i>$fatxt{'48'}</i></b></td></tr>             function verify_delete() { 
   <tr><td align="center" class="catbg" colspan="$colspan"><a href="javascript:try{if(typeof(opener.document)=='object'){throw '1';}else{throw '0';}}catch (e){if(e==1) {opener.location.href='$scripturl?num=$thread';self.close();}else{location.href='$scripturl?num=$thread';}}">$fatxt{'70'} "<i>$threadname</i>"</a> &nbsp; | &nbsp; <a href="javascript:window.close();">$fatxt{'71'}</a></td></tr>~;                 for (var i = 0; i < document.del_attachments.elements.length; i++) { 
                     if (document.del_attachments.elements[i].checked === true) {
   } else {                         Check = confirm('$fatxt{'46a'}'); 
       if ($iamadmin || $iamgmod) {                         if (Check==true) document.del_attachments.action = '$adminurl?action=deleteattachment'; 
           &LoadLanguage('Admin');                         break; 
                     }
           $output .= qq~                 } 
       <script language="JavaScript1.2" type="text/javascript">             } 
       <!--         </script> 
           function checkAll() {         <form name="del_attachments" action="$scripturl?action=viewdownloads;thread=$thread" method="post" style="display: inline;" onsubmit="verify_delete();">~; 
                 for (var i = 0; i < document.del_attachments.elements.length; i++) {         } 
                   document.del_attachments.elements[i].checked = true;         else { 
                 }             $output .= qq~ 
           }         <form action="$scripturl?action=viewdownloads;thread=$thread" method="post" style="display: inline;">~; 
           function uncheckAll() {         } 
                 for (var i = 0; i < document.del_attachments.elements.length; i++) {         $output .= qq~ 
                   document.del_attachments.elements[i].checked = false;         <input type="hidden" name="oldsort" value="$sort" /> 
                 }         <input type="hidden" name="formsession" value="$formsession" />~; 
           }  
           function verify_delete() {         my @attachments; 
                 for (var i = 0; i < document.del_attachments.elements.length; i++) {         if ( $sort > 0 ) {    # sort ascending 
                   if (document.del_attachments.elements[i].checked == true) {            if ( $sort == 1 || $sort == 5 || $sort == 6 || $sort == 8 ) {
                       Check = confirm('$fatxt{'46a'}');                 @attachments = sort { 
                       if (Check==true) document.del_attachments.action = '$adminurl?action=deleteattachment';                     ( split /\|/xsm, $a )[$sort] 
                       break;                       <=> ( split /\|/xsm, $b )[$sort]; 
                   }                 } @attachinput;    # sort size, date, count numerically 
                 }            }
           }             elsif ( $sort == 100 ) { 
       //-->                 @attachments = sort { 
       </script>                     lc(   ( split /\./xsm, ( split /\|/xsm, $a )[7] )[1] ) cmp 
       <form name="del_attachments" action="$scripturl?action=viewdownloads;thread=$thread" method="post" style="display: inline;" onsubmit="verify_delete();">~;                       lc( ( split /\./xsm, ( split /\|/xsm, $b )[7] )[1] ); 
                 } @attachinput;    # sort extension lexically
       } else {             } 
           $output .= qq~             else { 
       <form action="$scripturl?action=viewdownloads;thread=$thread" method="post" style="display: inline;">~;                 @attachments = sort { 
       }                     lc(   ( split /\|/xsm, $a )[$sort] ) cmp 
       $output .= qq~                       lc( ( split /\|/xsm, $b )[$sort] ); 
       <input type="hidden" name="oldsort" value="$sort" />                 } @attachinput;    # sort lexically 
       <input type="hidden" name="formsession" value="$formsession" />~;             } 
         }
       my @attachments;         else {                     # sort descending 
       if ($sort > 0) { # sort ascending             if ( $sort == -1 || $sort == -5 || $sort == -6 || $sort == -8 ) { 
           if ($sort == 1 || $sort == 5 || $sort == 6 || $sort == 8) {                @attachments = reverse sort {
               @attachments = sort { (split(/\|/, $a))[$sort] <=> (split(/\|/, $b))[$sort]; } @attachinput; # sort size, date, count numerically                     ( split /\|/xsm, $a )[ -$sort ] 
           } elsif ($sort == 100) {                       <=> ( split /\|/xsm, $b )[ -$sort ]; 
               @attachments = sort { lc((split(/\./, (split(/\|/, $a))[7]))[1]) cmp lc((split(/\./, (split(/\|/, $b))[7]))[1]); } @attachinput; # sort extension lexically                 } @attachinput;    # sort size, date, count numerically 
           } else {             } 
               @attachments = sort { lc((split(/\|/, $a))[$sort]) cmp lc((split(/\|/, $b))[$sort]); } @attachinput; # sort lexically             elsif ( $sort == -100 ) { 
           }                 @attachments = reverse sort { 
       } else { # sort descending                     lc(   ( split /\./xsm, ( split /\|/xsm, $a )[7] )[1] ) cmp 
           if ($sort == -1 || $sort == -5 || $sort == -6 || $sort == -8) {                       lc( ( split /\./xsm, ( split /\|/xsm, $b )[7] )[1] ); 
               @attachments = sort { (split(/\|/, $b))[-$sort] <=> (split(/\|/, $a))[-$sort]; } @attachinput; # sort size, date, count numerically                 } @attachinput;    # sort extension lexically 
           } elsif ($sort == -100) {             } 
               @attachments = sort { lc((split(/\./, (split(/\|/, $b))[7]))[1]) cmp lc((split(/\./, (split(/\|/, $a))[7]))[1]); } @attachinput; # sort extension lexically             else { 
           } else {                @attachments = reverse sort {
               @attachments = sort { lc((split(/\|/, $b))[-$sort]) cmp lc((split(/\|/, $a))[-$sort]); } @attachinput; # sort lexically                     lc(   ( split /\|/xsm, $a )[ -$sort ] ) cmp 
           }                       lc( ( split /\|/xsm, $b )[ -$sort ] ); 
       }                 } @attachinput;    # sort lexically 
             }
       $postdisplaynum = 8;         } 
       $newstart = (int($newstart / 25)) * 25;  
       $tmpa = 1;         $postdisplaynum = 8; 
       if ($newstart >= (($postdisplaynum - 1) * 25)) { $startpage = $newstart - (($postdisplaynum - 1) * 25); $tmpa = int( $startpage / 25 ) + 1; }         $newstart       = ( int( $newstart / 25 ) ) * 25; 
       if ($max >= $newstart + ($postdisplaynum * 25)) { $endpage = $newstart + ($postdisplaynum * 25); } else { $endpage = $max; }         $tmpa           = 1; 
       if ($startpage > 0) { $pageindex = qq~<a href="$scripturl?action=viewdownloads;thread=$thread;newstart=0;sort=$sort" style="font-weight: normal;">1</a>&nbsp;...&nbsp;~; }         if ( $newstart >= ( ( $postdisplaynum - 1 ) * 25 ) ) { 
       if ($startpage == 25) { $pageindex = qq~<a href="$scripturl?action=viewdownloads;thread=$thread;newstart=0;sort=$sort" style="font-weight: normal;">1</a>&nbsp;~;}             $startpage = $newstart - ( ( $postdisplaynum - 1 ) * 25 ); 
       for ($counter = $startpage; $counter < $endpage; $counter += 25) {             $tmpa = int( $startpage / 25 ) + 1; 
           $pageindex .= $newstart == $counter ? qq~<b>$tmpa</b>&nbsp;~ : qq~<a href="$scripturl?action=viewdownloads;thread=$thread;newstart=$counter;sort=$sort" style="font-weight: normal;">$tmpa</a>&nbsp;~;         } 
           $tmpa++;         if ( $max >= $newstart + ( $postdisplaynum * 25 ) ) { 
       }             $endpage = $newstart + ( $postdisplaynum * 25 ); 
       $lastpn = int($max / 25) + 1;         } 
       $lastptn = ($lastpn - 1) * 25;         else { $endpage = $max; } 
       if ($endpage < $max - (25) ) { $pageindexadd = qq~...&nbsp;~; }         if ( $startpage > 0 ) { 
       if ($endpage != $max) { $pageindexadd .= qq~<a href="$scripturl?action=viewdownloads;thread=$thread;newstart=$lastptn;sort=$sort">$lastpn</a>~; }             $pageindex = 
       $pageindex .= $pageindexadd;  qq~<a href="$scripturl?action=viewdownloads;thread=$thread;newstart=0;sort=$sort" class="norm">1</a>&nbsp;...&nbsp;~; 
         }
       $pageindex = qq~<div class="small" style="text-align: right;">$fatxt{'64'}: $pageindex</div>~;         if ( $startpage == 25 ) { 
             $pageindex =
       $numbegin = ($newstart + 1);  qq~<a href="$scripturl?action=viewdownloads;thread=$thread;newstart=0;sort=$sort" class="norm">1</a>&nbsp;~; 
       $numend = ($newstart + 25);         } 
       if ($numend > $max) { $numend  = $max; }         foreach my $counter ( $startpage .. ( $endpage - 1 ) ) { 
       if ($max == 0) { $numshow = ''; }             if ( $counter % 25 == 0 ) { 
       else { $numshow = qq~($numbegin - $numend)~; }                 $pageindex .= 
                   $newstart == $counter
       my (%attach_gif,$ext);                   ? qq~<b>$tmpa</b>&nbsp;~ 
       foreach $row (splice(@attachments, $newstart, 25)) {                   : qq~<a href="$scripturl?action=viewdownloads;thread=$thread;newstart=$counter;sort=$sort" class="norm">$tmpa</a>&nbsp;~; 
           chomp $row;                 $tmpa++; 
           my ($amthreadid, $amreplies, $amthreadsub, $amposter, $amcurrentboard, $amkb, $amdate, $amfn, $amcount) = split(/\|/, $row);             } 
         }
           $amfn =~ /\.(.+?)$/;         $lastpn  = int( $max / 25 ) + 1; 
           $ext = $1;         $lastptn = ( $lastpn - 1 ) * 25; 
           unless (exists $attach_gif{$ext}) {         if ( $endpage < $max - (25) ) { $pageindexadd = q~...&nbsp;~; } 
               $attach_gif{$ext} = ($ext && -e "$forumstylesdir/$useimages/$ext.gif") ? "$ext.gif" : "paperclip.gif";         if ( $endpage != $max ) { 
           }             $pageindexadd .= 
  qq~<a href="$scripturl?action=viewdownloads;thread=$thread;newstart=$lastptn;sort=$sort">$lastpn</a>~;
           $amdate = &timeformat($amdate);         } 
           if (length($amthreadsub) > 20) { $amthreadsub = substr($amthreadsub, 0, 20) . "..."; }         $pageindex .= $pageindexadd; 
   
           $viewattachments .= qq~<tr>~ . (($iamadmin || $iamgmod) ? qq~         $pageindex = qq~$fatxt{'64'}: $pageindex~; 
       <td class="windowbg2" align="center" valign="middle"><input type="checkbox" name="del_$thread" value="$amfn" /></td>~ : '') . qq~  
       <td class="windowbg2" align="left" valign="middle"><a href="javascript:void(download_file('$amfn'));"> $amfn</a></td>         $numbegin = ( $newstart + 1 ); 
       <td class="windowbg2" align="center" valign="middle"><img src="$imagesdir/$attach_gif{$ext}" border="0" align="bottom" alt="" /></td>         $numend   = ( $newstart + 25 ); 
       <td class="windowbg2" align="right" valign="middle">$amkb KB</td>         if   ( $numend > $max ) { $numend  = $max; } 
       <td class="windowbg2" align="center" valign="middle">$amdate</td>         if   ( $max == 0 )      { $numshow = q{}; } 
       <td class="windowbg2" align="right" valign="middle">$amcount</td>         else                    { $numshow = qq~($numbegin - $numend)~; } 
       <td class="windowbg2" align="left" valign="middle"><a href="javascript:load_thread('$thread','$amreplies');">$amthreadsub</a></td>  
       <td class="windowbg2" align="center" valign="middle">$amposter</td>         my ( %attach_gif, $ext ); 
       </tr>         foreach my $row ( splice @attachments, $newstart, 25 ) { 
       ~;             chomp $row; 
       }             my ( 
                 $amthreadid, $amreplies,      $amthreadsub,
       $viewattachments .= qq~<tr>~ . (($iamadmin || $iamgmod) ? qq~                 $amposter,   $amcurrentboard, $amkb, 
       <td class="catbg" align="center">                 $amdate,     $amfn,           $amcount 
           <input type="checkbox" name="checkall" value="" onclick="if(this.checked){checkAll();}else{uncheckAll();}" />             ) = split /\|/xsm, $row; 
       </td>~ : '') . qq~  
       <td class="catbg" colspan="7">             if ( $amfn =~ /\.(.+?)$/xsm ) { 
           <table width="100%">                 $ext = $1; 
           <colgroup>             } 
               <col width="33%" />             if ( !exists $attach_gif{$ext} ) { 
               <col width="34%" />                 $attach_gif{$ext} = 
               <col width="33%" />                   ( $ext 
           </colgroup>                       && -e "$htmldir/Templates/Forum/$useimages/$att_img{$ext}" 
               <tr>                   ) 
                   <td align="left" valign="middle" class="small">~ . (($iamadmin || $iamgmod) ? qq~&lt;= $amv_txt{'38'} &nbsp; <input type="submit" value="$admin_txt{'32'}" class="button" />~ : '&nbsp;') . qq~</td>                   ? "$imagesdir/$att_img{$ext}" 
                   <td align="center" valign="middle" nowrap="nowrap"> &nbsp; <a href="javascript:load_thread('$thread',0);">$fatxt{'70'} "<i>$threadname</i>"</a> &nbsp; | &nbsp; <a href="javascript:window.close();">$fatxt{'71'}</a> &nbsp; </td>                   : "$micon_bg{'paperclip'}"; 
                   <td align="right" valign="middle" class="small">$pageindex</td>             } 
               </tr>  
           </table>             $amdate = timeformat($amdate); 
       </td>             if ( length($amthreadsub) > 20 ) { 
       </tr>~;                 $amthreadsub = substr( $amthreadsub, 0, 20 ) . q{...}; 
             }
       $output .= qq~  
       <input type="hidden" name="newstart" value="$newstart" />~;             if ( $iamadmin || $iamgmod ) { 
   }                 $att_admin = $my_att_admin; 
             }
   my $class_sortattach = $sort =~ /7/   ? 'windowbg2' : 'windowbg';             else { 
   my $class_sorttype   = $sort =~ /100/ ? 'windowbg2' : 'windowbg';                 $att_admin = q{}; 
   my $class_sortsize   = $sort =~ /5/   ? 'windowbg2' : 'windowbg';             } 
   my $class_sortdate   = $sort =~ /6/   ? 'windowbg2' : 'windowbg';             $viewattachments .= $downloads_att_b; 
   my $class_sorcount   = $sort =~ /8/   ? 'windowbg2' : 'windowbg';             $viewattachments =~ s/{yabb att_admin}/$att_admin/gsm; 
   my $class_sortsubj   = $sort =~ /1$/  ? 'windowbg2' : 'windowbg';             $viewattachments =~ s/{yabb amfn}/$amfn/gsm; 
   my $class_sortuser   = $sort =~ /3/   ? 'windowbg2' : 'windowbg';             $viewattachments =~ s/{yabb attach_gif}/$attach_gif{$ext}/gsm; 
             $viewattachments =~ s/{yabb thread}/$thread/gsm;
   $output .= qq~             $viewattachments =~ s/{yabb amkb}/$amkb/gsm; 
<table border="0" cellspacing="1" cellpadding="8" class="bordercolor" align="center" width="90%">             $viewattachments =~ s/{yabb amdate}/$amdate/gsm; 
   <tr>             $viewattachments =~ s/{yabb amcount}/$amcount/gsm; 
       <td class="titlebg" colspan="$colspan">             $viewattachments =~ s/{yabb amreplies}/$amreplies/gsm; 
       <img src="$imagesdir/xx.gif" alt="" border="0" />&nbsp;<b>$fatxt{'39'}</b>             $viewattachments =~ s/{yabb amthreadsub}/$amthreadsub/gsm; 
       </td>             $viewattachments =~ s/{yabb amposter}/$amposter/gsm; 
   </tr><tr>         } 
       <td class="windowbg" colspan="$colspan" align="center" width="100%">  
       <br />         if ( $iamadmin || $iamgmod ) { 
       $fatxt{'75'}:<br />             $att_admin_b = $my_att_admin_b; 
       "<i>$threadname</i>"<br />             $att_admin_c = $my_att_admin_c; 
       <br />         } 
       <span class="small">$fatxt{'76'}</span>         else { 
       <br />             $att_admin_b = q{}; 
       </td>             $att_admin_c = '&nbsp;'; 
   </tr><tr>         } 
       <td class="titlebg" colspan="$colspan" width="100%">         $viewattachments .= $downloads_att_c; 
       <div class="small" style="float: left; text-align: left;">$fatxt{'28'} $max $numshow</div>         $viewattachments =~ s/{yabb att_admin_b}/$att_admin_b/gsm; 
       $pageindex         $viewattachments =~ s/{yabb att_admin_c}/$att_admin_c/gsm; 
       </td>         $viewattachments =~ s/{yabb amv_txt38a}/$amv_txt{'38a'}/gsm; 
   </tr>         $viewattachments =~ s/{yabb admin_txt32}/$admin_txt{'32'}/gsm; 
   <tr>~ . (($iamadmin || $iamgmod) ? qq~         $viewattachments =~ s/{yabb thread}/$thread/gsm; 
       <td align="center" class="windowbg"><b>$fatxt{'45'}</b></td>~ : '') . qq~         $viewattachments =~ s/{yabb threadname}/$threadname/gsm; 
       <td onclick="location.href='$scripturl?action=viewdownloads;thread=$thread;sort=~ . ($sort == 7 ? -7 : 7) . qq~';" align="center" class="$class_sortattach" style="border: 0px; border-style: outset; cursor: pointer;"><a href="$scripturl?action=viewdownloads;thread=$thread;sort=~ . ($sort == 7 ? -7 : 7) . qq~"><b>$fatxt{'40'}</b></a></td>         $viewattachments =~ s/{yabb fatxt70}/$fatxt{'70'}/gsm; 
       <td onclick="location.href='$scripturl?action=viewdownloads;thread=$thread;sort=~ . ($sort == 100 ? -100 : 100) . qq~';" align="center" class="$class_sorttype" style="border: 0px; border-style: outset; cursor: pointer;"><a href="$scripturl?action=viewdownloads;thread=$thread;sort=~ . ($sort == 100 ? -100 : 100) . qq~"><b>$fatxt{'40a'}</b></a></td>         $viewattachments =~ s/{yabb fatxt71}/$fatxt{'71'}/gsm; 
       <td onclick="location.href='$scripturl?action=viewdownloads;thread=$thread;sort=~ . ($sort == -5 ? 5 : -5) . qq~';" align="center" class="$class_sortsize" style="border: 0px; border-style: outset; cursor: pointer;"><a href="$scripturl?action=viewdownloads;thread=$thread;sort=~ . ($sort == -5 ? 5 : -5) . qq~"><b>$fatxt{'41'}</b></a></td>         $viewattachments =~ s/{yabb pageindex}/$pageindex/gsm; 
       <td onclick="location.href='$scripturl?action=viewdownloads;thread=$thread;sort=~ . ($sort == -6 ? 6 : -6) . qq~';" align="center" class="$class_sortdate" style="border: 0px; border-style: outset; cursor: pointer;"><a href="$scripturl?action=viewdownloads;thread=$thread;sort=~ . ($sort == -6 ? 6 : -6) . qq~"><b>$fatxt{'43'}</b></a></td>  
       <td onclick="location.href='$scripturl?action=viewdownloads;thread=$thread;sort=~ . ($sort == -8 ? 8 : -8) . qq~';" align="center" class="$class_sorcount" style="border: 0px; border-style: outset; cursor: pointer;"><a href="$scripturl?action=viewdownloads;thread=$thread;sort=~ . ($sort == -8 ? 8 : -8) . qq~"><b>$fatxt{'41a'}</b></a></td>         $output .= qq~ 
       <td onclick="location.href='$scripturl?action=viewdownloads;thread=$thread;sort=~ . ($sort == 1 ? -1 : 1) . qq~';" align="center" class="$class_sortsubj" style="border: 0px; border-style: outset; cursor: pointer;"><a href="$scripturl?action=viewdownloads;thread=$thread;sort=~ . ($sort == 1 ? -1 : 1) . qq~"><b>$fatxt{'44'}</b></a></td>         <input type="hidden" name="newstart" value="$newstart" />~; 
       <td onclick="location.href='$scripturl?action=viewdownloads;thread=$thread;sort=~ . ($sort == 3 ? -3 : 3) . qq~';" align="center" class="$class_sortuser" style="border: 0px; border-style: outset; cursor: pointer;"><a href="$scripturl?action=viewdownloads;thread=$thread;sort=~ . ($sort == 3 ? -3 : 3) . qq~"><b>$fatxt{'42'}</b></a></td>     } 
   </tr>  
   $viewattachments     my $class_sortattach = $sort =~ /7/sm   ? 'windowbg2' : 'windowbg'; 
</table>~;     my $class_sorttype   = $sort =~ /100/sm ? 'windowbg2' : 'windowbg'; 
     my $class_sortsize   = $sort =~ /5/sm   ? 'windowbg2' : 'windowbg';
   $output .= '</form>' if $max && ($iamadmin || $iamgmod);     my $class_sortdate   = $sort =~ /6/sm   ? 'windowbg2' : 'windowbg'; 
     my $class_sorcount   = $sort =~ /8/sm   ? 'windowbg2' : 'windowbg';
   $output .= qq~     my $class_sortsubj   = $sort =~ /1$/sm  ? 'windowbg2' : 'windowbg'; 
<br />     my $class_sortuser   = $sort =~ /3/sm   ? 'windowbg2' : 'windowbg'; 
<br />  
</div>     if ( $iamadmin || $iamgmod ) { 
</div>         $att_out_admin_a = $my_out_att_admin_a; 
</body>     } 
</html>~;     else { 
         $att_out_admin_a = q{};
     }
   
     $output .= $downloads_att_out_a;
     $output =~ s/{yabb colspan}/$colspan/gsm;
     $output =~ s/{yabb threadname}/$threadname/gsm;
     $output =~ s/{yabb pageindex}/$pageindex/gsm;
     $output =~ s/{yabb max}/$max/gsm;
     $output =~ s/{yabb numshow}/$numshow/gsm;
     $output =~ s/{yabb fatxt39}/$fatxt{'39'}/gsm;
     $output =~ s/{yabb fatxt76}/$fatxt{'76'}/gsm;
     $output =~ s/{yabb fatxt75}/$fatxt{'75'}/gsm;
     $output =~ s/{yabb fatxt28}/$fatxt{'28'}/gsm;
   
     $output .= $att_out_admin_a;
     $output =~ s/{yabb fatxt45}/$fatxt{'45'}/gsm;
     my $att_text;
   
     $rsort = ( $sort == 7 ? -7 : 7 );
     $att_text = $my_att_sort;
     $att_text =~ s/{yabb attsort}/$rsort/gsm;
     $att_text =~ s/{yabb attclass}/$class_sortattach/gsm;
     $att_text =~ s/{yabb atttext}/$fatxt{'40'}/gsm;
     $output .= $att_text;
   
     $rsort = ( $sort == 100 ? -100 : 100 );
     $att_text = $my_att_sort;
     $att_text =~ s/{yabb attsort}/$rsort/gsm;
     $att_text =~ s/{yabb attclass}/$class_sorttype/gsm;
     $att_text =~ s/{yabb atttext}/$fatxt{'40a'}/gsm;
     $output .= $att_text;
   
     $rsort = ( $sort == 5 ? -5 : 5 );
     $att_text = $my_att_sort;
     $att_text =~ s/{yabb attsort}/$rsort/gsm;
     $att_text =~ s/{yabb attclass}/$class_sortsize/gsm;
     $att_text =~ s/{yabb atttext}/$fatxt{'41'}/gsm;
     $output .= $att_text;
   
     $rsort = ( $sort == -6 ? 6 : -6 );
     $att_text = $my_att_sort;
     $att_text =~ s/{yabb attsort}/$rsort/gsm;
     $att_text =~ s/{yabb attclass}/$class_sortdate/gsm;
     $att_text =~ s/{yabb atttext}/$fatxt{'43'}/gsm;
     $output .= $att_text;
   
     $rsort = ( $sort == -8 ? 8 : -8 );
     $att_text = $my_att_sort;
     $att_text =~ s/{yabb attsort}/$rsort/gsm;
     $att_text =~ s/{yabb attclass}/$class_sorcount/gsm;
     $att_text =~ s/{yabb atttext}/$fatxt{'41a'}/gsm;
     $output .= $att_text;
   
     $rsort = ( $sort == 1 ? -1 : 1 );
     $att_text = $my_att_sort;
     $att_text =~ s/{yabb attsort}/$rsort/gsm;
     $att_text =~ s/{yabb attclass}/$class_sortsubj/gsm;
     $att_text =~ s/{yabb atttext}/$fatxt{'44'}/gsm;
     $output .= $att_text;
   
     $rsort = ( $sort == 3 ? -3 : 3 );
     $att_text = $my_att_sort;
     $att_text =~ s/{yabb attsort}/$rsort/gsm;
     $att_text =~ s/{yabb attclass}/$class_sortuser/gsm;
     $att_text =~ s/{yabb atttext}/$fatxt{'42'}/gsm;
     $output .= $att_text;
   
     $output .= $downloads_tbl_end;
   
     $output =~ s/{yabb thread}/$thread/gsm;
     $output =~ s/{yabb viewattachments}/$viewattachments/gsm;
   
   &print_HTML_output_and_finish;     if ( $max && ( $iamadmin || $iamgmod ) ) { $output .= '</form>'; } 
}  
   
sub DownloadFileCouter {     $output .= $downloads_bottom; 
   $dfile = $INFO{'file'};  
   
   if ($guest_media_disallowed && $iamguest) { &fatal_error("",$maintxt{'40'}); }     print_HTML_output_and_finish(); 
     return;
  }
   
   if (!-e "$uploaddir/$dfile") { &fatal_error("","$dfile $maintxt{'23'}"); }  sub DownloadFileCouter { 
     $dfile = $INFO{'file'};
   
   fopen(ATM, "+<$vardir/attachments.txt", 1) || &fatal_error("cannot_open","$vardir/attachments.txt", 1);     if ( $guest_media_disallowed && $iamguest ) { 
   seek ATM, 0, 0;         fatal_error( q{}, $maintxt{'40'} ); 
   my @attachments = <ATM>;     } 
   truncate ATM, 0;  
   seek ATM, 0, 0;     if ( !-e "$uploaddir/$dfile" ) { 
   for (my $a = 0; $a < @attachments; $a++) {         fatal_error( q{}, "$maintxt{'23'} $dfile$maintxt{'23a'}" ); 
       $attachments[$a] =~ s/(.+\|)(.+)\|(\d+)(\s+)$/ $1 . ($dfile eq $2 ? "$2|" . ($3 + 1) : "$2|$3") . $4 /e;     } 
   }  
   print ATM @attachments;     fopen( ATM, "<$vardir/attachments.txt", 1 ) 
   fclose(ATM);       or fatal_error( 'cannot_open', "$vardir/attachments.txt", 1 ); 
     my @attachments = <ATM>;
     fclose( ATM );
   
     for my $i ( 0 .. $#attachments ) {
         $attachments[$i] =~
  s/(.+\|)(.+)\|(\d+)(\s+)$/ $1 . ($dfile eq $2 ? "$2|" . ($3 + 1) : "$2|$3") . $4 /exsm;
     }
     fopen( ATM, ">$vardir/attachments.txt", 1 )
       or fatal_error( 'cannot_open', "$vardir/attachments.txt", 1 );
     print {ATM} @attachments or croak "$croak{'print'} ATM";
     fclose(ATM);
   
   print "Location: $uploadurl/$dfile\n\r\n\r";     print "Location: $uploadurl/$dfile\n\r\n\r" 
       or croak "$croak{'print'} Location";
   
   exit;    exit;
} }
   
1; 1;