F:\WEBSITES\testbed\zipped\yabb_svn_new\branches\2.5.2\cgi-bin\yabb2\Sources\Subs.pl F:\WEBSITES\testbed\zipped\yabb_svn_new\trunk\cgi-bin\yabb2\Sources\Subs.pm
############################################################################### ###############################################################################
# Subs.pl                                                                     # # Subs.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 strict;
  # use warnings;
  no warnings qw(uninitialized once redefine);
  use CGI::Carp qw(fatalsToBrowser);
  use English qw(-no_match_vars);
  our $VERSION = '2.6.12';
   
$subsplver = 'YaBB 2.5.2 $Revision: 1.5 $'; $subspmver = 'YaBB 2.6.12 $Revision: 1717 $';
if ($debug) { &LoadLanguage('Debug'); }  
   
use subs 'exit'; use subs 'exit';
   
$yymain = '';  $yymain       = q{}; 
$yyjavascript = '';  $yyjavascript = q{}; 
$langopt = '';  $langopt      = q{}; 
   
# set line wrap limit in Display. # set line wrap limit in Display.
$linewrap = 80; $linewrap = 80;
$newswrap = 0; $newswrap = 0;
   
# get the current date/time # get the current date/time
$date = int(time() + $timecorrection);  
  $date = int( time() + $timecorrection );
   
# check if browser accepts encoded output # check if browser accepts encoded output
$gzaccept = $ENV{'HTTP_ACCEPT_ENCODING'} =~ /\bgzip\b/ || $gzforce; $gzaccept = $ENV{'HTTP_ACCEPT_ENCODING'} =~ /\bgzip\b/sm || $gzforce;
   
# parse the query string # parse the query string
&readform;  readform(); 
   
$uid = substr($date, length($date) - 3, 3);  $uid = substr $date, length($date) - 3, 3; 
$session_id = $cookiesession_name; $session_id = $cookiesession_name;
   
$randaction = substr($date,0,length($date)-2);  $randaction = substr $date, 0, length($date) - 2; 
   
$user_ip = $ENV{'REMOTE_ADDR'}; $user_ip = $ENV{'REMOTE_ADDR'};
if ($user_ip eq "127.0.0.1") { if ( $user_ip eq '127.0.0.1' ) {
   if    ($ENV{'HTTP_CLIENT_IP'}       && $ENV{'HTTP_CLIENT_IP'}       ne "127.0.0.1") { $user_ip = $ENV{'HTTP_CLIENT_IP'}; }     if ( $ENV{'HTTP_CLIENT_IP'} && $ENV{'HTTP_CLIENT_IP'} ne '127.0.0.1' ) { 
   elsif ($ENV{'X_CLIENT_IP'}          && $ENV{'X_CLIENT_IP'}          ne "127.0.0.1") { $user_ip = $ENV{'X_CLIENT_IP'}; }         $user_ip = $ENV{'HTTP_CLIENT_IP'}; 
   elsif ($ENV{'HTTP_X_FORWARDED_FOR'} && $ENV{'HTTP_X_FORWARDED_FOR'} ne "127.0.0.1") { $user_ip = $ENV{'HTTP_X_FORWARDED_FOR'}; }    }
}     elsif ( $ENV{'X_CLIENT_IP'} && $ENV{'X_CLIENT_IP'} ne '127.0.0.1' ) { 
         $user_ip = $ENV{'X_CLIENT_IP'};
if (-e "$yyexec.cgi") { $yyext = "cgi"; }    }
else { $yyext = "pl"; }     elsif ($ENV{'HTTP_X_FORWARDED_FOR'} 
if (-e "AdminIndex.cgi") { $yyaext = "cgi"; }         && $ENV{'HTTP_X_FORWARDED_FOR'} ne '127.0.0.1' ) 
else { $yyaext = "pl"; }     { 
         $user_ip = $ENV{'HTTP_X_FORWARDED_FOR'};
     }
  }
   
  if   ( -e "$yyexec.cgi" ) { $yyext = 'cgi'; }
  else                      { $yyext = 'pl'; }
  if   ( -e 'AdminIndex.cgi' ) { $yyaext = 'cgi'; }
  else                         { $yyaext = 'pl'; }
   
sub automaintenance { sub automaintenance {
   my $maction = $_[0];     my ( $maction, $mreason ) = @_; 
   my $mreason = $_[1];     if ( lc($maction) eq 'on' ) { 
   if (lc($maction) eq "on") {         fopen( MAINT, ">$vardir/maintenance.lock" ); 
       fopen (MAINT, ">$vardir/maintenance.lock");         print {MAINT} 
       print MAINT qq~Remove this file if your board is in maintenance for no reason\n~;           qq~$maintxt{'maint'}\n~ 
       fclose (MAINT);           or croak qq~$maintxt{'maint'}~; 
       if ($mreason eq "low_disk"){         fclose(MAINT); 
           &LoadLanguage('Error');         if ( $mreason eq 'low_disk' ) { 
           &alertbox($error_txt{'low_diskspace'});             LoadLanguage('Error'); 
       }             alertbox( $error_txt{'low_diskspace'} ); 
       $maintenance = 2 if !$maintenance;         } 
   } elsif (lc($maction) eq "off") {         if ( !$maintenance ) { $maintenance = 2; } 
       unlink "$vardir/maintenance.lock" || &admin_fatal_error("cannot_open_dir","$vardir/maintenance.lock");     } 
       $maintenance = 0 if $maintenance == 2;     elsif ( lc($maction) eq 'off' ) { 
   }         unlink "$vardir/maintenance.lock" 
           or fatal_error( 'cannot_open_dir', "$vardir/maintenance.lock" );
         if ( $maintenance == 2 ) { $maintenance = 0; }
     }
     return;
} }
   
sub getnewid { sub getnewid {
   my $newid = $date;    my $newid = $date;
   while (-e "$datadir/$newid.txt") { ++$newid; }    while ( -e "$datadir/$newid.txt" ) { ++$newid; }
   return $newid;    return $newid;
} }
   
sub undupe { sub undupe {
   my (@out,$duped,$check);     my (@indup) = @_; 
   foreach $check (@_) {     my ( @out, $duped, ); 
       $duped = 0;     foreach my $check (@indup) { 
       foreach (@out) { if ($_ eq $check) { $duped = 1; last; } }         $duped = 0; 
       if (!$duped) { push(@out, $check); }         foreach (@out) { 
   }            if ( $_ eq $check ) { $duped = 1; last; }
   return @out;         } 
         if ( !$duped ) { push @out, $check; }
     }
     return @out;
} }
   
sub exit { sub exit {
   local $| = 1;     my ($inexit)                = @_; 
   local $\ = '';     my $OUTPUT_AUTOFLUSH        = 1; 
   print '';     my $OUTPUT_RECORD_SEPARATOR = q{}; 
   wait if $child_pid;     print q{}; 
   CORE::exit($_[0] || 0);     if ($child_pid) { wait; } 
     CORE::exit( $inexit || 0 );
     return;
} }
   
sub print_output_header { sub print_output_header {
   $headerstatus ||= '200 OK';     if ($header_already_printed) { return; } 
   $contenttype  ||= 'text/html';     $yyxml_lang = $abbr_lang; 
     $header_already_printed = 1;
   my $ret = $yyIIS ? "HTTP/1.0 $headerstatus\n" : "Status: $headerstatus\n";     $headerstatus ||= '200 OK'; 
     $contenttype  ||= 'text/html';
   foreach ($yySetCookies1,$yySetCookies2,$yySetCookies3) { $ret .= "Set-Cookie: $_\n" if $_; }  
     my $ret = $yyIIS ? "HTTP/1.0 $headerstatus\n" : "Status: $headerstatus\n";
   if ($yySetLocation) {  
       $ret .= "Location: $yySetLocation";     foreach ( $yySetCookies1, $yySetCookies2, $yySetCookies3, @otherCookies ) { 
   } else {         if ($_) { $ret .= "Set-Cookie: $_\n"; } 
       $ret .= "Cache-Control: no-cache, must-revalidate\nPragma: no-cache\n" if !$cachebehaviour;     } 
       $ret .= "ETag: \"$ETag\"\n" if $ETag;  
       $ret .= "Last-Modified: $LastModified\n" if $LastModified;     if ( !$no_error_page ) { 
       $ret .= "Content-Encoding: gzip\n" if $gzcomp && $gzaccept;         if ($yySetLocation) { 
       $ret .= "Content-Type: $contenttype";             $ret .= "Location: $yySetLocation"; 
       $ret .= "; charset=$yycharset" if $yycharset;         } 
   }         else { 
   print $ret . "\r\n\r\n";             if ( !$cachebehaviour ) { 
                 $ret .=
  "Cache-Control: no-cache, must-revalidate\nPragma: no-cache\n";
             }
             if ($ETag)         { $ret .= "ETag: \"$ETag\"\n"; }
             if ($LastModified) { $ret .= "Last-Modified: $LastModified\n"; }
             if ( $gzcomp && $gzaccept ) { $ret .= "Content-Encoding: gzip\n"; }
             $ret .= "Content-Type: $contenttype";
             if ($yycharset) {$yymycharset = $yycharset;}
             if ($yymycharset) { $ret .= "; charset=$yymycharset"; }
        }
     }
     print $ret . "\r\n\r\n" or croak "$croak{'print'} ret";
     return;
} }
   
sub print_HTML_output_and_finish { sub print_HTML_output_and_finish {
   if ($gzcomp && $gzaccept) {    if ( $gzcomp && $gzaccept ) {
       my $filehandle_exists = fileno GZIP;        my $filehandle_exists = fileno GZIP;
       if ($gzcomp == 1 || $filehandle_exists) {        if ( $gzcomp == 1 || $filehandle_exists ) {
           $| = 1;            $OUTPUT_AUTOFLUSH = 1;
           open(GZIP, "| gzip -f") unless $filehandle_exists;             if ( !$filehandle_exists ) { 
           print GZIP $output;                 open GZIP, '| gzip -f' or croak "$croak{'open'} GZIP"; 
           close(GZIP);             } 
       } else {             print {GZIP} $output or croak "$croak{'print'} GZIP"; 
           require Compress::Zlib;             close GZIP or croak "$croak{'close'}"; 
           binmode STDOUT;         } 
           print Compress::Zlib::memGzip($output);         else { 
       }             require Compress::Zlib; 
   } else {             binmode STDOUT; 
       print $output;             print Compress::Zlib::memGzip($output) 
   }               or croak "$croak{'print'} ZLib"; 
   exit;         } 
     }
     else {
         print $output;    # or croak "$croak{'print'} output";
     }
     exit;
} }
   
sub write_cookie { sub write_cookie {
   my %params = @_;    my %params = @_;
   
   if ($params{'-expires'} =~ /\+(\d+)m/) {    if ( $params{'-expires'} =~ /\+(\d+)m/xsm ) {
       my ($sec, $min, $hour, $mday, $mon, $year, $wday) = gmtime($date + $1 * 60);         my ( $sec, $min, $hour, $mday, $mon, $year, $wday ) = 
           gmtime( $date + $1 * 60 );
   
         $year += 1900;
         my @mos = qw(
           Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec
         );
         my @dys = qw( Sun Mon Tue Wed Thu Fri Sat );
         $mon  = $mos[$mon];
         $wday = $dys[$wday];
   
         $params{'-expires'} = sprintf '%s, %02i-%s-%04i %02i:%02i:%02i GMT',
           $wday, $mday, $mon, $year, $hour, $min, $sec;
     }
   
     if ( $params{'-path'} ) { $params{'-path'} = " path=$params{'-path'};"; }
     if ( $params{'-expires'} ) {
         $params{'-expires'} = " expires=$params{'-expires'};";
     }
   
       $year += 1900;     return 
       my @mos = ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");       "$params{'-name'}=$params{'-value'};$params{'-path'}$params{'-expires'}"; 
       my @dys = ("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");  
       $mon  = $mos[$mon];  
       $wday = $dys[$wday];  
   
       $params{'-expires'} = sprintf("%s, %02i-%s-%04i %02i:%02i:%02i GMT", $wday, $mday, $mon, $year, $hour, $min, $sec);  
   }  
   
   $params{'-path'}    = " path=$params{'-path'};"       if $params{'-path'};  
   $params{'-expires'} = " expires=$params{'-expires'};" if $params{'-expires'};  
   
   "$params{'-name'}=$params{'-value'};$params{'-path'}$params{'-expires'}";  
} }
   
sub redirectexit { sub redirectexit {
   $headerstatus = '302 Moved Temporarily';    $headerstatus = '302 Moved Temporarily';
   &print_output_header;     print_output_header(); 
   exit;    exit;
  }
   
  sub redirectmove {
     require Sources::MessageIndex;
     MessageIndex();
     return;
} }
   
sub redirectinternal { sub redirectinternal {
   if ($currentboard) {    if ($currentboard) {
       if ($INFO{'num'}) { require "$sourcedir/Display.pl"; &Display; }        if   ( $INFO{'num'} ) { require Sources::Display;      Display(); }
       else { require "$sourcedir/MessageIndex.pl"; &MessageIndex; }        else                  { require Sources::MessageIndex; MessageIndex(); }
   } else {     } 
       require "$sourcedir/BoardIndex.pl";     else { 
       &BoardIndex;         require Sources::BoardIndex; 
   }         BoardIndex(); 
     }
     return;
} }
   
sub ImgLoc { sub ImgLoc {
   return (!-e "$forumstylesdir/$useimages/$_[0]" ? qq~$forumstylesurl/default/$_[0]~ : qq~$imagesdir/$_[0]~);     @img = @_; 
     if ( exists $img_locs{ $img[0] } ) {
         $img_locs{ $img[0] } = $img_locs{ $img[0] };
     }
     elsif ( -e "$htmldir/Templates/Forum/$useimages/$img[0]" ) {
         $img_locs{ $img[0] } = qq~$imagesdir/$img[0]~;
     }
     else {
         $img_locs{ $img[0] } = qq~$defaultimagesdir/$img[0]~;
     }
     return $img_locs{ $img[0] };
} }
   
sub template { sub template {
   &print_output_header;     print_output_header(); 
   
   if ($yytitle ne $maintxt{'error_description'}) {    if ( $yytitle ne $maintxt{'error_description'} ) {
       if ((!$iamguest || ($iamguest && $guestaccess == 1)) && !$maintenance ) { $yyforumjump = &jumpto; }         if ( ( !$iamguest || ( $iamguest && $guestaccess == 1 ) ) 
       else { $yyforumjump = ' '; }             && !$maintenance ) 
   }         { 
   $yyposition      = $yytitle;             $yyforumjump = jumpto(); 
   $yytitle         = "$mbname - $yytitle";         } 
   $yyimages        = $imagesdir;         else { $yyforumjump = ' '; } 
   $yydefaultimages = $defaultimagesdir;     } 
     $yyposition      = $yytitle;
   $yystyle  = qq~<link rel="stylesheet" href="$forumstylesurl/$usestyle.css" type="text/css" />\n~;     $yytitle         = "$mbname - $yytitle"; 
   $yystyle  =~ s~$usestyle\/~~g;     $yyimages        = $imagesdir; 
   $yystyle  .= qq~<link rel="stylesheet" href="$yyhtml_root/shjs/styles/sh_style.css" type="text/css" />\n~;     $yydefaultimages = $defaultimagesdir; 
   $yystyle .= $yyinlinestyle; # This is for the Help Center and anywhere else that wants to add inline CSS.     $yysyntax_js     = q{}; 
$yysyntax_js = qq~     $yygreyboxstyle  = q{}; 
<script language="JavaScript1.2" type="text/javascript" src="$yyhtml_root/shjs/sh_main.js"></script>     $yygrayscript    = q{}; 
<script language="JavaScript1.2" type="text/javascript" src="$yyhtml_root/shjs/sh_cpp.js"></script>  
<script language="JavaScript1.2" type="text/javascript" src="$yyhtml_root/shjs/sh_css.js"></script>     if ( 
<script language="JavaScript1.2" type="text/javascript" src="$yyhtml_root/shjs/sh_html.js"></script>            $INFO{'num'} 
<script language="JavaScript1.2" type="text/javascript" src="$yyhtml_root/shjs/sh_java.js"></script>         || $action eq 'post' 
<script language="JavaScript1.2" type="text/javascript" src="$yyhtml_root/shjs/sh_javascript.js"></script>         || $action eq 'modify' 
<script language="JavaScript1.2" type="text/javascript" src="$yyhtml_root/shjs/sh_pascal.js"></script>         || $action eq 'preview' 
<script language="JavaScript1.2" type="text/javascript" src="$yyhtml_root/shjs/sh_perl.js"></script>         || $action eq 'search2' 
<script language="JavaScript1.2" type="text/javascript" src="$yyhtml_root/shjs/sh_php.js"></script>         || $action eq 'imshow' 
<script language="JavaScript1.2" type="text/javascript" src="$yyhtml_root/shjs/sh_sql.js"></script>         || $action eq 'imsend' 
         || $action eq 'myviewprofile' 
         || $action eq 'eventcal' 
         || $action eq 'help' 
         || $action eq 'recenttopics' 
         || $action eq 'recent' 
         || $action eq 'usersrecentposts' 
         || $action eq 'myusersrecentposts' 
        )
     {
         $yysyntax_js = qq~
  <script type="text/javascript" src="$yyhtml_root/shjs/sh_main.js"></script>
  <script type="text/javascript" src="$yyhtml_root/shjs/sh_cpp.js"></script>
  <script type="text/javascript" src="$yyhtml_root/shjs/sh_css.js"></script>
  <script type="text/javascript" src="$yyhtml_root/shjs/sh_html.js"></script>
  <script type="text/javascript" src="$yyhtml_root/shjs/sh_java.js"></script>
  <script type="text/javascript" src="$yyhtml_root/shjs/sh_javascript.js"></script>
  <script type="text/javascript" src="$yyhtml_root/shjs/sh_pascal.js"></script>
  <script type="text/javascript" src="$yyhtml_root/shjs/sh_perl.js"></script>
  <script type="text/javascript" src="$yyhtml_root/shjs/sh_php.js"></script>
  <script type="text/javascript" src="$yyhtml_root/shjs/sh_sql.js"></script>
~; ~;
         $yyjsstyle =
  qq~<link rel="stylesheet" href="$yyhtml_root/shjs/styles/sh_style.css" type="text/css" />\n~;
         $yyhigh = q~<script type="text/javascript">
     sh_highlightDocument();
  </script>~;
   
   # add 'back to top' Button on the end of each page         if ($img_greybox) { 
   $yynavback .= qq~<img src="$imagesdir/tabsep211.png" border="0" alt="" style="vertical-align: middle;" />~ if !$yynavback;             $yygreyboxstyle = 
   $yynavback .= qq~ <a href="#pagetop" class="nav">$img_txt{'102'}</a> <img src="$imagesdir/tabsep211.png" border="0" alt="" style="vertical-align: middle;" />~;  qq~<link href="$yyhtml_root/greybox/gb_styles.css" rel="stylesheet" type="text/css" />\n~; 
   
   if (!$usehead) { $usehead = qq~default~; }             $yygrayscript = qq~ 
   $yytemplate = "$templatesdir/$usehead/$usehead.html";  <script type="text/javascript"> 
   fopen(TEMPLATE, $yytemplate) || die("$maintxt{'23'}: $yytemplate");     var GB_ROOT_DIR = "$yyhtml_root/greybox/"; 
   $output = join('', <TEMPLATE>);  </script> 
   fclose(TEMPLATE);  <script type="text/javascript" src="$yyhtml_root/AJS.js"></script> 
  <script type="text/javascript" src="$yyhtml_root/AJS_fx.js"></script>
   if ($iamadmin || $iamgmod) {  <script type="text/javascript" src="$yyhtml_root/greybox/gb_scripts.js"></script> 
       if ($maintenance) { $yyadmin_alert .= qq~<br /><span class="highlight"><b>$load_txt{'616'}</b></span>~; }  ~;
       if ($iamadmin && $rememberbackup) {         } 
           if ($lastbackup && $date > $rememberbackup + $lastbackup) {     } 
               $yyadmin_alert .= qq~<br /><span class="highlight"><b>$load_txt{'617'} ~ . &timeformat($lastbackup) . qq~</b></span>~;  
           }  
       }  
   }  
   
   $yyboardname = "$mbname";  
   $yyboardlink = qq~<a href="$scripturl">$mbname</a>~;  
   
   # static/dynamic clock  
   $yytime = &timeformat($date, 1);  
   if ($mytimeselected != 7 && (($iamguest && $dynamic_clock) || ${$uid.$username}{'dynamic_clock'})) {  
       $yytime =~ /(.*?)\d+:\d+((\w+)|:\d+)?/;  
       my ($a,$b) = ($1,$3);  
       $a =~ s/<.+?>//g;  
       $b = ' ' if $mytimeselected == 6;  
       $yytime = qq~&nbsp;<script language="javascript" type="text/javascript">\n<!--\nWriteClock('yabbclock','$a','$b');\n//-->\n</script>~;  
       $yyjavascript .= qq~\n\nvar OurTime = ~ . ($date + (3600 * $toffs)) . qq~000;\nvar YaBBTime = new Date();\nvar TimeDif = YaBBTime.getTime() - (YaBBTime.getTimezoneOffset() * 60000) - OurTime - 1000; // - 1000 compromise to transmission time~;  
   }  
   
   $yyjavascript .= qq~  
   
   function txtInFields(thefield, defaulttxt) {  
       if (thefield.value == defaulttxt) thefield.value = "";  
       else { if (thefield.value == "") thefield.value = defaulttxt; }  
   }  
   ~;  
   if ($output =~ /\{yabb tabmenu\}/) {  
       require "$sourcedir/TabMenu.pl";  
       &mainMenu;  
   
   } else {  
       $yymenu = qq~<a href="$scripturl">$img{'home'}</a>$menusep<a href="$scripturl?action=help" style="cursor:help;">$img{'help'}</a>~;  
       # remove search from menu if disabled by the admin  
       if ($maxsearchdisplay > -1) {  
           $yymenu .= qq~$menusep<a href="$scripturl?action=search">$img{'search'}</a>~;  
       }  
       if (!$ML_Allowed || ($ML_Allowed == 1 && !$iamguest) || ($ML_Allowed == 2 && $staff) || ($ML_Allowed == 3 && ($iamadmin || $iamgmod))) {  
           $yymenu .= qq~$menusep<a href="$scripturl?action=ml">$img{'memberlist'}</a>~;  
       }  
   
       if ($iamadmin) { $yymenu .= qq~$menusep<a href="$boardurl/AdminIndex.$yyaext">$img{'admin'}</a>~; }  
       if ($iamgmod) {  
           if (-e ("$vardir/gmodsettings.txt")) {  
               require "$vardir/gmodsettings.txt";  
           }  
           if ($allow_gmod_admin) { $yymenu .= qq~$menusep<a href="$boardurl/AdminIndex.$yyaext">$img{'admin'}</a>~; }  
       }  
       if ($sessionvalid == 0 && !$iamguest) {  
           my $sesredir;  
           unless (!$testenv || $action eq "revalidatesession" || $action eq "revalidatesession2") {  
               $sesredir = $testenv;  
               $sesredir =~ s/\=/\~/g;  
               $sesredir =~ s/;/x3B/g;  
               $sesredir = qq~;sesredir=$sesredir~;  
           }  
           $yymenu .= qq~$menusep<a href="$scripturl?action=revalidatesession$sesredir">$img{'sessreval'}</a>~;  
       }  
       if ($iamguest) {  
           my $sesredir;  
           if ($testenv) {  
               $sesredir = $testenv;  
               $sesredir =~ s/\=/\~/g;  
               $sesredir =~ s/;/x3B/g;  
               $sesredir = qq~;sesredir=$sesredir~;  
           }  
           $yymenu .= qq~$menusep<a href="~ . ($loginform ? "javascript:if(jumptologin>1)alert('$maintxt{'35'}');jumptologin++;window.scrollTo(0,10000);document.loginform.username.focus();" : "$scripturl?action=login$sesredir") . qq~">$img{'login'}</a>~;  
           if ($regtype != 0) { $yymenu .= qq~$menusep<a href="$scripturl?action=register">$img{'register'}</a>~; }  
           if ($PMenableGuestButton && $PM_level > 0 && $PMenableBm_level > 0) {  
               $yymenu .= qq~$menusep<a href="$scripturl?action=guestpm">$img{'pmadmin'}</a>~; }  
   
       } else {  
           ## pointing towards pm now  
           $yymenu .= qq~$menusep<a href="$scripturl?action=mycenter">$img{'mycenter'}</a>~;  
           $yymenu .= qq~$menusep<a href="$scripturl?action=logout">$img{'logout'}</a>~;  
       }  
   }  
   
   $yylangChooser = "";  
   if (($iamguest && !$guestLang) && $enable_guestlanguage && $guestaccess) {  
       if (!$langopt) {&guestLangSel;}  
       if ($morelang > 1) {  
           $yylangChooser = qq~$guest_txt{'sellanguage'}: <form action="$scripturl?action=guestlang" method="post" name="sellanguage">  
           <select name="guestlang" onchange="submit();">  
           $langopt  
           </select>  
           <noscript><input type="submit" value="$maintxt{'32'}" class="button" /></noscript>  
           </form>~;  
       }  
   
   } elsif (($iamguest && $guestLang) && $enable_guestlanguage && $guestaccess) {  
       if (!$langopt) {&guestLangSel;}  
       if ($morelang > 1) {  
           $yylangChooser = qq~$guest_txt{'changelanguage'}: <form action="$scripturl?action=guestlang" method="post" name="changelanguage">  
           <select name="guestlang" onchange="submit();">  
           $langopt  
           </select>  
           <noscript><input type="submit" value="$maintxt{'32'}" class="button" /></noscript>  
           </form>~;  
       }  
   }  
   
   my $wmessage;  
   if    ($hour >= 12 && $hour < 18) { $wmessage = $maintxt{'247a'}; } # Afternoon  
   elsif ($hour <  12 && $hour >= 0) { $wmessage = $maintxt{'247m'}; } # Morning  
   else                              { $wmessage = $maintxt{'247e'}; } # Evening  
   if ($iamguest) {  
       $yyuname = qq~$maintxt{'248'} $maintxt{'28'}. $maintxt{'249'} <a href="~ . ($loginform ? "javascript:if(jumptologin>1)alert('$maintxt{'35'}');jumptologin++;window.scrollTo(0,10000);document.loginform.username.focus();" : "$scripturl?action=login") . qq~">$maintxt{'34'}</a>~;  
       $yyuname .= qq~ $maintxt{'377'} <a href="$scripturl?action=register">$maintxt{'97'}</a>~ if $regtype;  
       $yyjavascript .= "\njumptologin = 1;";  
   } else {  
       if (${$uid.$username}{'bday'} ne '') {  
           my ($usermonth, $userday, $useryear) = split(/\//, ${$uid.$username}{'bday'});  
           if ($usermonth == $mon_num && $userday == $mday) { $wmessage = $maintxt{'247bday'}; }  
       }  
       $yyuname = ($PM_level == 0 || ($PM_level == 2 && !$iamadmin && !$iamgmod && !$iammod) || ($PM_level == 3 && !$iamadmin && !$iamgmod)) ? "$wmessage ${$uid.$username}{'realname'}" : "$wmessage ${$uid.$username}{'realname'}, ";  
   }  
   
   # Add new notifications if allowed  
   if (!$iamguest && $NewNotificationAlert) {  
       unless ($board_notify || $thread_notify) {  
           require "$sourcedir/Notify.pl";  
           ($board_notify,$thread_notify) = &NotificationAlert;  
       }  
       my ($bo_num,$th_num);  
       foreach (keys %$board_notify) { # boardname, boardnotifytype , new  
           $bo_num++ if ${$$board_notify{$_}}[2];  
       }  
       foreach (keys %$thread_notify) { # mythread, msub, new, username_link, catname_link, boardname_link, lastpostdate  
           $th_num++ if ${$$thread_notify{$_}}[2];  
       }  
       if ($bo_num || $th_num) {  
           my $noti_text = ($bo_num ? "$notify_txt{'201'} $notify_txt{'205'} ($bo_num)" : "") . ($th_num ? ($bo_num ? " $notify_txt{'202'} " : "") . "$notify_txt{'201'}  $notify_txt{'206'} ($th_num)" : "");  
           $yyadmin_alert = qq~<br />$notify_txt{'200'} <a href="$scripturl?action=shownotify">$noti_text</a>.$yyadmin_alert~;  
           $yymain .= qq~<script language="javascript" type="text/javascript">  
           <!--  
           window.setTimeout("Noti_Popup();", 1000);  
           function Noti_Popup() {  
               if (confirm('$notify_txt{'200'} $noti_text.\\n$notify_txt{'203'}'))  
                   window.location.href='$scripturl?action=shownotify';  
           }  
           //-->  
           </script>~ if ${$uid.$username}{'onlinealert'} and $boardindex_template;  
       }  
   }  
   
   # This next line fixes problems created when a fatal_error is called before Security.pl is loaded  
   # We don't want to require since it's an error and trying to do anything extra for an error could be bad  
   if ($output =~ m~<yabb copyright>~ || $output =~ m~{yabb copyright}~) { $yycopyin = 1; } ## new template style in also  
   $yysearchbox = '';  
   unless ($iamguest && $guestaccess == 0) {  
       if ($maxsearchdisplay > -1) {  
           $yysearchbox = qq~  
       <script language="JavaScript1.2" src="$yyhtml_root/ubbc.js" type="text/javascript"></script>  
       <form action="$scripturl?action=search2" method="post">  
       <input type="hidden" name="searchtype" value="allwords" />  
       <input type="hidden" name="userkind" value="any" />  
       <input type="hidden" name="subfield" value="on" />  
       <input type="hidden" name="msgfield" value="on" />  
       <input type="hidden" name="age" value="31" />  
       <input type="hidden" name="numberreturned" value="$maxsearchdisplay" />  
       <input type="hidden" name="oneperthread" value="1" />  
       <input type="hidden" name="searchboards" value="!all" />  
       <input type="text" name="search" size="16" id="search1" value="$img_txt{'182'}" style="font-size: 11px;" onfocus="txtInFields(this, '$img_txt{'182'}');" onblur="txtInFields(this, '$img_txt{'182'}')" />  
       <input type="image" src="$imagesdir/search.gif" style="border: 0; background-color: transparent; margin-right: 5px; vertical-align: middle;" />  
       </form>  
       ~;  
       }  
   }  
   if ($enable_news && -s "$vardir/news.txt" > 5) {  
       fopen(NEWS, "$vardir/news.txt");  
       my @newsmessages = <NEWS>;  
       fclose(NEWS);  
       chomp(@newsmessages);  
       my $startnews = int(rand(@newsmessages));  
       my $newstitle = qq~<b>$maintxt{'102'}:</b>~;  
       $newstitle =~ s/'/\\'/g;  
       $guest_media_disallowed = 0;  
       $newswrap = 40;  
       if ($shownewsfader) {  
           $fadedelay = $maxsteps * $stepdelay;  
           $yynews .= qq~  
           <script language="JavaScript1.2" type="text/javascript">  
               <!--  
                   var index = $startnews;  
                   var maxsteps = "$maxsteps";  
                   var stepdelay = "$stepdelay";  
                   var fadelinks = $fadelinks;  
                   var delay = "$fadedelay";  
                   function convProp(thecolor) {  
                       if(thecolor.charAt(0) == "#") {  
                           if(thecolor.length == 4) thecolor=thecolor.replace(/(\\#)([a-f A-F 0-10]{1,1})([a-f A-F 0-10]{1,1})([a-f A-F 0-10]{1,1})\/i, "\$1\$2\$2\$3\$3\$4\$4");  
                           var thiscolor = new Array(HexToR(thecolor), HexToG(thecolor), HexToB(thecolor));  
                           return thiscolor;  
                       }  
                       else if(thecolor.charAt(3) == "(") {  
                           thecolor=thecolor.replace(/rgb\\((\\d+?\\%*?)\\,(\\s*?)(\\d+?\\%*?)\\,(\\s*?)(\\d+?\\%*?)\\)/i, "\$1|\$3|\$5");  
                           var thiscolor = thecolor.split("|");  
                           return thiscolor;  
                       }  
                       else {  
                           thecolor=thecolor.replace(/\\"/g, "");  
                           thecolor=thecolor.replace(/maroon/ig, "128|0|0");  
                           thecolor=thecolor.replace(/red/i, "255|0|0");  
                           thecolor=thecolor.replace(/orange/i, "255|165|0");  
                           thecolor=thecolor.replace(/olive/i, "128|128|0");  
                           thecolor=thecolor.replace(/yellow/i, "255|255|0");  
                           thecolor=thecolor.replace(/purple/i, "128|0|128");  
                           thecolor=thecolor.replace(/fuchsia/i, "255|0|255");  
                           thecolor=thecolor.replace(/white/i, "255|255|255");  
                           thecolor=thecolor.replace(/lime/i, "00|255|00");  
                           thecolor=thecolor.replace(/green/i, "0|128|0");  
                           thecolor=thecolor.replace(/navy/i, "0|0|128");  
                           thecolor=thecolor.replace(/blue/i, "0|0|255");  
                           thecolor=thecolor.replace(/aqua/i, "0|255|255");  
                           thecolor=thecolor.replace(/teal/i, "0|128|128");  
                           thecolor=thecolor.replace(/black/i, "0|0|0");  
                           thecolor=thecolor.replace(/silver/i, "192|192|192");  
                           thecolor=thecolor.replace(/gray/i, "128|128|128");  
                           var thiscolor = thecolor.split("|");  
                           return thiscolor;  
                       }  
                   } //" make my syntax checker happy;  
   
                   if (ie4 || DOM2) document.write('$newstitle<div class="windowbg2" id="fadestylebak" style="display: none;"><div class="newsfader" id="fadestyle" style="display: none;"> </div></div>');  
   
                   if (document.getElementById('fadestyle').currentStyle) {  
                       tcolor = document.getElementById('fadestyle').currentStyle['color'];  
                       bcolor = document.getElementById('fadestyle').currentStyle['backgroundColor'];  
                       fntsize = document.getElementById('fadestyle').currentStyle['fontSize'];  
                       fntstyle = document.getElementById('fadestyle').currentStyle['fontStyle'];  
                       fntweight = document.getElementById('fadestyle').currentStyle['fontWeight'];  
                       fntfamily = document.getElementById('fadestyle').currentStyle['fontFamily'];  
                       txtdecoration = document.getElementById('fadestyle').currentStyle['textDecoration'];  
                   }  
                   else if (window.getComputedStyle) {  
                       tcolor = window.getComputedStyle(document.getElementById('fadestyle'), null).getPropertyValue('color');  
                       bcolor = window.getComputedStyle(document.getElementById('fadestyle'), null).getPropertyValue('background-color');  
                       fntsize = window.getComputedStyle(document.getElementById('fadestyle'), null).getPropertyValue('font-size');  
                       fntstyle = window.getComputedStyle(document.getElementById('fadestyle'), null).getPropertyValue('font-style');  
                       fntweight = window.getComputedStyle(document.getElementById('fadestyle'), null).getPropertyValue('font-weight');  
                       fntfamily = window.getComputedStyle(document.getElementById('fadestyle'), null).getPropertyValue('font-family');  
                       txtdecoration = window.getComputedStyle(document.getElementById('fadestyle'), null).getPropertyValue('text-decoration');  
                   }  
                   if (bcolor == "transparent" || bcolor == "rgba\\(0\\, 0\\, 0\\, 0\\)") {  
                       if (document.getElementById('fadestylebak').currentStyle) {  
                           tcolor = document.getElementById('fadestylebak').currentStyle['color'];  
                           bcolor = document.getElementById('fadestylebak').currentStyle['backgroundColor'];  
                       }  
                       else if (window.getComputedStyle) {  
                           tcolor = window.getComputedStyle(document.getElementById('fadestylebak'), null).getPropertyValue('color');  
                           bcolor = window.getComputedStyle(document.getElementById('fadestylebak'), null).getPropertyValue('background-color');  
                       }  
                   }  
                   txtdecoration = txtdecoration.replace(/\'/g, "");  
                   var endcolor = convProp(tcolor);  
                   var startcolor = convProp(bcolor);~;  
           my $greybox = $img_greybox;  
           $img_greybox = 0;  
           for (my $j = 0; $j < @newsmessages; $j++) {  
               $message = $newsmessages[$j];  
               &wrap;  
               if ($enable_ubbc) {  
                   if (!$yyYaBBCloaded) { require "$sourcedir/YaBBC.pl"; }  
                   $ns = "";  
                   &DoUBBC;  
                   $message =~ s/ style="display:none"/ style="display:block"/g;  
               }  
               &wrap2;  
               $message =~ s/"/\\"/g;  
               &ToChars($message);  
               $yynews .= qq~                    fcontent[$j] = "$message";\n~;  
           }  
           $img_greybox = $greybox;  
           $yynews .= qq~  
                   if (ie4 || DOM2) document.write('<div style="font-size: ' + fntsize + '\\; font-weight: ' + fntweight + '\\; font-style: ' + fntstyle + '\\; font-family: ' + fntfamily + '\\; text-decoration: ' + txtdecoration + '\\;" id="fscroller"></div>');  
   
                   if (window.addEventListener)  
                       window.addEventListener("load", changecontent, false);  
                   else if (window.attachEvent)  
                       window.attachEvent("onload", changecontent);  
                   else if (document.getElementById)  
                       window.onload = changecontent;  
               // -->  
           </script>  
       ~;  
       } else {  
           $message = $newsmessages[$startnews];  
           &wrap;  
           if ($enable_ubbc) {  
               if (!$yyYaBBCloaded) { require "$sourcedir/YaBBC.pl"; }  
               &DoUBBC;  
               $message =~ s/ style="display:none"/ style="display:block"/g;  
           }  
           &wrap2;  
           &ToChars($message);  
           $yynews = $message;  
       }  
       $newswrap = 0;  
   } else {  
       $yynews = '&nbsp;';  
   }  
   # Moved this down here so it shows more  
   ##  pushed to own file for flexibility  
   if ($debug == 1 or ($debug == 2 && $iamadmin)) { require "$sourcedir/Debug.pl"; &Debug; }  
   $yyurl      = $scripturl;  
   ## new and old tag template style decoding ##  
   while ($output =~ s~(<|{)yabb\s+(\w+)(}|>)~${"yy$2"}~g) {}  
   $output =~ s~(a href=\S+?action=viewprofile;username=.+?)>~$1 rel="nofollow">~isg;  
   if ($imagesdir ne $defaultimagesdir) {  
       $output =~ s~img src=(\\*"|')$imagesdir/(.+?)(\1)~ "img src=$1" . &ImgLoc($2) . $3 ~eisg;  
       $output =~ s~\.src='$imagesdir/(.+?)'~ ".src='" . &ImgLoc($1) . "'" ~eisg; # For Javascript generated images  
       $output =~ s~input type="image" src="$imagesdir/(.+?)"~ 'input type="image" src="' . &ImgLoc($1) . '"' ~eisg; # For input images  
       $output =~ s~option value="$imagesdir/(.+?)"~ 'option value="' . &ImgLoc($1) . '"' ~eisg; # For the post page  
   }  
   $output =~ s~</form>~<input type="hidden" name="formsession" value="$formsession" /></form>~g;  
   
   &image_resize;  
   
   # Start workaround to substitute all ';' by '&' in all URLs  
   # This workaround solves problems with servers that use mod_security  
   # in a very strict way. (error 406)  
   # Take the comments out of the following two lines if you had this problem.  
   # $output =~ s/($scripturl\?)([^'"]+)/ $1 . &URL_modify($2) /eg;  
   # sub URL_modify { my $x = shift; $x =~ s/;/&/g; $x; }  
   # End of workaround  
   
   if ($yycopyin == 0) {  
       $output = q~<center><h1><b>Sorry, the copyright tag <yabb copyright> must be in the template.<br />Please notify this forum's administrator that this site is using an ILLEGAL copy of YaBB!</b></h1></center>~;  
   }  
   
   &print_HTML_output_and_finish;     $yystyle = 
  qq~<link rel="stylesheet" href="$yyhtml_root/Templates/Forum/$usestyle.css" type="text/css" />\n~;
     $yystyle =~ s/$usestyle\///gxsm;
     $yystyle .= $yyjsstyle;
     $yystyle .= $yygreyboxstyle;
     $yystyle .= $yyinlinestyle;
   
     if ( $action eq 'register' || $action eq 'guestpm' || $action eq 'modalert' || $action eq 'post' || $action eq 'imsend' || ( $action eq 'eventcal' && $INFO{'addnew'} == 1 ) ) {
         $yystyle .= '<meta name ="robots" content="noindex, nofollow" />';
     }
   
     # Carsten's 'backtotop';
     if ( !$yynavback ) { $yynavback .= q~ ~; }
     $yynavback .=
  qq~$tabsep <span onclick="toTop(0)" class="cursor">$img_txt{'102'}</span> &nbsp; $tabsep~;
   
     if ( !$usehead ) { $usehead = q~default~; }
     $yytemplate = "$templatesdir/$usehead/$usehead.html";
     fopen( TEMPLATE, $yytemplate ) or croak("$maintxt{'23'}: $yytemplate");
     @whole_file = <TEMPLATE>;
     $output = join q{}, @whole_file;
     fclose(TEMPLATE);
   
     if ( $iamadmin || $iamgmod ) {
         if ($maintenance) {
             if   ($do_scramble_id) { $user = cloak($username); }
             else                   { $user = $username; }
             $yyadmin_alert .=
               qq~<br /><span class="highlight"><b>$load_txt{'616'}</b></span>~;
             $yyadmin_alert =~ s/USER/$user/sm;
         }
         $rememberbackup ||= 0;
         if ( $iamadmin && $rememberbackup > 0 ) {
             if ( $lastbackup && $date > $rememberbackup + $lastbackup ) {
                 $yyadmin_alert .=
                     qq~<br /><span class="highlight"><b>$load_txt{'617'} ~
                   . timeformat($lastbackup)
                   . q~</b></span>~;
             }
         }
     }
   
     # to top button for fixed menu
     $yyfixtop  = qq~$img_txt{'to_top'}~;
   
     $yyboardname = "$mbname";
     $yyboardlink = qq~<a href="$scripturl">$mbname</a>~;
   
     # static/dynamic clock
     $yytime = timeformat( $date, 1 );
     my $zone = q{};
     if ( ($iamguest && $default_tz eq 'UTC') || (${ $uid . $username }{'user_tz'} eq 'UTC') || ( !$default_tz  &&  !${ $uid . $username }{'user_tz'} ) ) {
         $zone = qq~ $maintxt{'UTC'}~;
     }
     my $toffs = 0;
     if ( $enabletz ) {
         $toffs = toffs($date);
     }
     if (
         $mytimeselected != 7
         && ( ( $iamguest && $dynamic_clock )
             || ${ $uid . $username }{'dynamic_clock'} )
       )
     {
         if ( $yytime =~ /(.*?)\d+:\d+((\w+)|:\d+)?/xsm ) {
             ( $aa, $bb ) = ( $1, $3 );
         }
         $aa =~ s/<.+?>//gxsm;
         if ( $mytimeselected == 6 ) { $bb = q{ }; }
         $yytime =
  qq~&nbsp;<script  type="text/javascript">\nWriteClock('yabbclock','$aa','$bb');\n</script>~;
         $yyjavascripta .=
             qq~
         var OurTime = ~
           . sprintf( '%d', ( $date + $toffs ) )
           . qq~000;\nvar YaBBTime = new Date();\nvar TimeDif = YaBBTime.getTime() - (YaBBTime.getTimezoneOffset() * 60000) - OurTime - 1000; // - 1000 compromise to transmission time~;
     }
     $yytime .= $zone;
   
     $yyjavascripta .= qq~
     var imagedir = "$imagesdir";
     function toTop(scrpoint) {
         window.scrollTo(0,scrpoint);
     }~;
   
     $yyjavascript .= q~
     function txtInFields(thefield, defaulttxt) {
         if (thefield.value == defaulttxt) thefield.value = "";
         else { if (thefield.value === "") thefield.value = defaulttxt; }
     }
     function selectAllCode(thefield) {
         var elem = document.getElementById('code' + thefield);
         if (document.selection) {
             document.selection.empty();
             var txt = document.body.createTextRange();
             txt.moveToElementText(elem);
             txt.select();
         }
         else {
             window.getSelection().removeAllRanges();
             txt = document.createRange();
             txt.setStartBefore(elem);
             txt.setEndAfter(elem);
             window.getSelection().addRange(txt);
         }
     }
     ~;
     require Sources::TabMenu;
     mainMenu();
   
   
     $yylangChooser = q{};
     if ( ( $iamguest && !$guestLang ) && $enable_guestlanguage && $guestaccess )
     {
         if ( !$langopt ) { guestLangSel(); }
         if ( $morelang > 1 ) {
             $yylangChooser =
  qq~$guest_txt{'sellanguage'}: <form action="$scripturl?action=guestlang" method="post" name="sellanguage">
             <select name="guestlang" onchange="submit();">
             $langopt
             </select>
             </form>~;
         }
     }
     elsif (( $iamguest && $guestLang )
         && $enable_guestlanguage
         && $guestaccess )
     {
         if ( !$langopt ) { guestLangSel(); }
         if ( $morelang > 1 ) {
             $yylangChooser =
  qq~$guest_txt{'changelanguage'}: <form action="$scripturl?action=guestlang" method="post" name="changelanguage">
             <select name="guestlang" onchange="submit();">
             $langopt
             </select>
             </form>~;
         }
     }
   
     my $wmessage;
     if ( $hour >= 12 && $hour < 18 ) {
         $wmessage = $maintxt{'247a'};
     }