F:\WEBSITES\testbed\zipped\yabb_svn_new\branches\2.5.2\cgi-bin\yabb2\Sources\MyCenter.pl F:\WEBSITES\testbed\zipped\yabb_svn_new\trunk\cgi-bin\yabb2\Sources\MyCenter.pm
############################################################################### ###############################################################################
# MyCenter.pl                                                                 # # MyCenter.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);
  use CGI::Carp qw(fatalsToBrowser);
  our $VERSION = '2.6.12';
   
  $mycenterpmver = 'YaBB 2.6.12 $Revision: 1710 $';
  if ( $action eq 'detailedversion' ) { return 1; }
   
  LoadLanguage('InstantMessage');
  LoadLanguage('MyCenter');
  LoadLanguage('Profile');
  get_micon();
  get_template('MyCenter');
  get_gmod();
  $pm_lev = PMlev();
   
  $mycenter_txt{'welcometxt'} =~ s/USERLABEL/${$uid.$username}{'realname'}/gxsm;
   
  $showIM            = q{};
  $IM_box            = q{};
  $showProfile       = q{};
  $PMfileToOpen      = q{};
  $sendBMess         = q{};
  $isBMess           = q{};
  $showFavorites     = q{};
  $showNotifications = q{};
   
$mycenterplver = 'YaBB 2.5.2 $Revision: 1.1 $';  
if ($action eq 'detailedversion') { return 1; }  
   
&LoadLanguage('InstantMessage');  
&LoadLanguage('MyCenter');  
require "$templatesdir/$usemycenter/MyCenter.template";  
if (-e "$vardir/gmodsettings.txt" && $iamgmod) { require "$vardir/gmodsettings.txt"; }  
$mycenter_txt{'welcometxt'} =~ s/USERLABEL/${$uid.$username}{'realname'}/g;  
   
$showIM = '';  
$IM_box = '';  
$showProfile = '';  
$PMfileToOpen = '';  
$sendBMess = '';  
$isBMess = '';  
$showFavorites = '';  
$showNotifications = '';  
   
##  here begins the user centre, from the old IMIndex  
sub mycenter { sub mycenter {
   if ($iamguest) { &fatal_error('members_only'); }    if ($iamguest) { fatal_error('im_members_only'); }
   
   &LoadBroadcastMessages($username); # get the BM infos    LoadBroadcastMessages($username);    # get the BM infos
   
   $IM_box = '';     $IM_box = q{}; 
   my $PMfileToOpen = '';     my $PMfileToOpen      = q{}; 
   my @otherStoreFolders = ();    my @otherStoreFolders = ();
   my $otherStoreSelect = '';     my $otherStoreSelect  = q{}; 
   $replyguest = $INFO{'replyguest'} || $FORM{'replyguest'};    $replyguest = $INFO{'replyguest'} || $FORM{'replyguest'};
   ## select view by action    ## select view by action
   if ($action =~ /^im/ || $action eq 'deletemultimessages' || $action eq 'pmsearch') { $view = 'pm'; }     if (   $action =~ /^im/sm 
   elsif ($action eq 'mycenter') { $view = 'mycenter'; }         || $action eq 'deletemultimessages' 
   elsif ($action eq 'shownotify' || $action=~ /^notify/ || $action eq 'boardnotify2') { $view = 'notify'; $mctitle = $img_txt{'418'}; }         || $action eq 'pmsearch' ) 
   elsif ($action eq 'myusersrecentposts') { $view = 'recentposts'; }     { 
   elsif ($action eq 'favorites') { $view = 'favorites'; $mctitle = $img_txt{'70'}; }         $view = 'pm'; 
   elsif ($action =~ /^my/) { $view = 'profile'; }    }
   ## viewing PMs     elsif ( $action eq 'mycenter' ) { $view = 'mycenter'; } 
   if ($view eq 'pm') { # pm views     elsif ($action eq 'shownotify' 
       ## viewing a message box         || $action =~ /^notify/xsm 
       require "$sourcedir/InstantMessage.pl";         || $action eq 'boardnotify2' ) 
       if ($action eq 'im' || $action eq 'imoutbox' || $action eq 'imstorage') {    {
           my $foundextra = 0;         $view    = 'notify'; 
           foreach my $storefolder (split(/\|/, ${$username}{'PMfolders'})) {         $mctitle = $img_txt{'418'}; 
               if($storefolder ne $INFO{'viewfolder'}) {     } 
                   push (@otherStoreFolders, $storefolder);     elsif ( $action eq 'myusersrecentposts' ) { $view = 'recentposts'; } 
                   $foundextra = 1;     elsif ( $action eq 'favorites' ) { 
               }         $view    = 'favorites'; 
           }         $mctitle = $img_txt{'70'}; 
           if ($foundextra > 0) {     } 
               $otherStoreSelect = qq~ $inmes_txt{'storein'} <select name="tostorefolder" id="tostorefolder">~;     elsif ( $action =~ /^my/xsm ) { $view = 'profile'; } 
               foreach my $otherFolder (@otherStoreFolders) {     ## viewing PMs 
                   my $otherFolderName = $otherFolder;     if ( $view eq 'pm' ) {    # pm views 
                   if ($otherFolder eq 'in') { $otherFolderName = $im_folders_txt{'in'}; }         ## viewing a message box 
                   elsif ($otherFolder eq 'out') { $otherFolderName = $im_folders_txt{'out'}; }         require Sources::InstantMessage; 
                   $otherStoreSelect .= qq~<option value="$otherFolder">$otherFolderName</option>~;         if (   $action eq 'im' 
               }             || $action eq 'imoutbox' 
               $otherStoreSelect .= qq~</select>~;             || $action eq 'imstorage' ) 
           }         { 
       }             my $foundextra = 0; 
       ## inbox             foreach my $storefolder ( split /\|/xsm, ${$username}{'PMfolders'} ) 
       if ($action eq 'im' || ($action eq 'imshow' && $INFO{'caller'} == 1)) {            {
           $mctitle = $inmes_txt{'inbox'};                 if ( $storefolder ne $INFO{'viewfolder'} ) { 
           $status = $inmes_imtxt{'status'};                     push @otherStoreFolders, $storefolder; 
           $senderinfo = $inmes_txt{'318'};                     $foundextra = 1; 
           $callerid = 1;                 } 
           $boxtxt = $inmes_txt{'316'};             } 
           $movebutton  = qq~<input type="submit" name="imaction" value="$inmes_imtxt{'store'}" class="button" />$otherStoreSelect $inmes_txt{'storeor'}~;             if ( $foundextra > 0 ) { 
           $IM_box = $inmes_txt{'inbox'};                 $otherStoreSelect = 
           if($INFO{'focus'} eq 'bmess' || $INFO{'bmess'} eq 'yes') { $IM_box = $inmes_txt{'broadcast'}; $callerid = 5; }  qq~ $inmes_txt{'storein'} <select name="tostorefolder" id="tostorefolder">~; 
           $PMfileToOpen = 'msg';                 foreach my $otherFolder (@otherStoreFolders) { 
       }                     my $otherFolderName = $otherFolder; 
       ##  draft box                     if ( $otherFolder eq 'in' ) { 
       elsif ($action eq 'imdraft') {                         $otherFolderName = $im_folders_txt{'in'}; 
           $mctitle = $inmes_txt{'draft'};                     } 
           $status = $inmes_imtxt{'status'};                     elsif ( $otherFolder eq 'out' ) { 
           $senderinfo = $inmes_txt{'324'};                         $otherFolderName = $im_folders_txt{'out'}; 
           $callerid = 4;                     } 
           $boxtxt = $inmes_txt{'draft'};                     $otherStoreSelect .= 
           $movebutton = '';  qq~<option value="$otherFolder">$otherFolderName</option>~; 
           $IM_box = $inmes_txt{'draft'};                 } 
           $PMfileToOpen = 'imdraft';                 $otherStoreSelect .= q~</select>~; 
       }            }
       ## outbox         } 
       elsif ($action eq 'imoutbox' || ($action eq 'imshow' && $INFO{'caller'} == 2)) {         ## inbox 
           $mctitle = $inmes_txt{'773'};         if ( $action eq 'im' 
           $status = $inmes_imtxt{'status'};             || ( $action eq 'imshow' && $INFO{'caller'} == 1 ) ) 
           $senderinfo = $inmes_txt{'324'};         { 
           $callerid = 2;             $mctitle    = $inmes_txt{'inbox'}; 
           $boxtxt = $inmes_txt{'outbox'};             $status     = $inmes_imtxt{'status'}; 
           $movebutton  = qq~<input type="submit" name="imaction" value="$inmes_imtxt{'store'}" class="button" />$otherStoreSelect $inmes_txt{'storeor'}~;             $senderinfo = $inmes_txt{'318'}; 
           $IM_box = $inmes_txt{'outbox'};             $callerid   = 1; 
           $PMfileToOpen = 'outbox';             $boxtxt     = $inmes_txt{'316'}; 
       }             $movebutton = 
       # store  qq~<input type="submit" name="imaction" value="$inmes_imtxt{'store'}" class="button" />$otherStoreSelect $inmes_txt{'storeor'}~; 
       elsif ($action eq 'imstorage' || ($action eq 'imshow' && $INFO{'caller'} == 3)) {             $IM_box = $inmes_txt{'inbox'}; 
           $mctitle = $inmes_txt{'774'};             if ( $INFO{'focus'} eq 'bmess' || $INFO{'bmess'} eq 'yes' ) { 
           $status = '';                 $IM_box   = $inmes_txt{'broadcast'}; 
           $senderinfo = $inmes_txt{'318'};                 $callerid = 5; 
           if ($INFO{'viewfolder'} eq 'out') { $senderinfo = $inmes_txt{'324'}; }            }
           elsif ($INFO{'viewfolder'} ne 'in') { $senderinfo = qq~$inmes_txt{'318'} / $inmes_txt{'324'}~; }             $PMfileToOpen = 'msg'; 
           $callerid = 3;         } 
           $boxtxt = $inmes_txt{'storage'};         ##  draft box 
           $movebutton  = qq~<input type="submit" name="imaction" value="$inmes_imtxt{'store'}" class="button" />$otherStoreSelect $inmes_txt{'storeor'}~;         elsif ( $action eq 'imdraft' ) { 
           $IM_box = $inmes_txt{'storage'};             $mctitle      = $inmes_txt{'draft'}; 
           if ($INFO{'viewfolder'} eq 'in' || $INFO{'viewfolder'} eq 'out') { $IM_box .= qq~ &rsaquo; $im_folders_txt{"$INFO{'viewfolder'}"}~; }             $status       = $inmes_imtxt{'status'}; 
           elsif ($INFO{'viewfolder'}) { $IM_box .= qq~ &rsaquo; $INFO{'viewfolder'}~; }             $senderinfo   = $inmes_txt{'324'}; 
           $PMfileToOpen = 'imstore';             $callerid     = 4; 
       }             $boxtxt       = $inmes_txt{'draft'}; 
       ## sending a message / previewing             $movebutton   = q{}; 
       elsif ($action eq 'imsend' || ($action eq 'imsend2' && $FORM{'previewim'})) {             $IM_box       = $inmes_txt{'draft'}; 
           $IM_box = $inmes_txt{'148'};             $PMfileToOpen = 'imdraft'; 
           if ($INFO{'forward'} == 1) { $IM_box = $inmes_txt{'forward'}; }        }
           if ($INFO{'reply'}) { $IM_box = $inmes_txt{'replymess'}; }         ## outbox 
           &IMPost;         elsif ( $action eq 'imoutbox' 
           &buildIMsend;             || ( $action eq 'imshow' && $INFO{'caller'} == 2 ) ) 
           &doshowims;         { 
       }             $mctitle    = $inmes_txt{'773'}; 
       ## posting the message or draft             $status     = $inmes_imtxt{'status'}; 
       elsif ($action eq 'imsend2' || $FORM{'draft'}) {             $senderinfo = $inmes_txt{'324'}; 
           $IM_box = $inmes_txt{'148'};             $callerid   = 2; 
           if($INFO{'forward'} == 1) { $IM_box = $inmes_txt{'forward'}; }             $boxtxt     = $inmes_txt{'outbox'}; 
           if($INFO{'reply'}) { $IM_box = $inmes_txt{'replymess'}; }             $movebutton = 
           &IMsendMessage;  qq~<input type="submit" name="imaction" value="$inmes_imtxt{'store'}" class="button" />$otherStoreSelect $inmes_txt{'storeor'}~; 
       }             $IM_box       = $inmes_txt{'outbox'}; 
       elsif ($action eq 'imshow' && $INFO{'caller'} == 5) {             $PMfileToOpen = 'outbox'; 
           $mctitle = $inmes_txt{'broadcast'};         } 
           $status = $inmes_imtxt{'status'};  
           $senderinfo = $inmes_txt{'318'};         # store 
           $callerid = 5;         elsif ( $action eq 'imstorage' 
           $boxtxt = $inmes_txt{'316'};             || ( $action eq 'imshow' && $INFO{'caller'} == 3 ) ) 
           $movebutton = qq~<input type="submit" name="imaction" value="$inmes_imtxt{'store'}" class="button" />$otherStoreSelect $inmes_txt{'storeor'}~;         { 
           $IM_box = $inmes_txt{'broadcast'};             $mctitle    = $inmes_txt{'storage'}; 
           $PMfileToOpen = 'msg';             $status     = q{}; 
       }             $senderinfo = $inmes_txt{'318'}; 
   }             if ( $INFO{'viewfolder'} eq 'out' ) { 
   ## viewing front page                 $senderinfo = $inmes_txt{'324'}; 
   elsif ($view eq "mycenter") {             } 
       $mctitle = "$inmes_txt{'mycenter'}";             elsif ( $INFO{'viewfolder'} ne 'in' ) { 
   }                 $senderinfo = qq~$inmes_txt{'318'} / $inmes_txt{'324'}~; 
   ## viewing my profile             } 
   elsif ($view eq "profile") {             $callerid = 3; 
       $mctitle = "$mc_menus{'profile'}";  
   }             $boxtxt = $inmes_txt{'storage'}; 
   ## viewing my recent posts             $movebutton = 
   elsif ($view eq 'recentposts') {  qq~<input type="submit" name="imaction" value="$inmes_imtxt{'store'}" class="button" />$otherStoreSelect $inmes_txt{'storeor'}~; 
       $mctitle = "$inmes_txt{'viewrecentposts'} $inmes_txt{'viewrecentposts2'}";             $IM_box = $inmes_txt{'storage'}; 
   }  
             fopen( THREADS, "$memberdir/$username.imstore" );
   ## draw the container             @threads = <THREADS>; 
   &drawPMbox($PMfileToOpen);             fclose(THREADS); 
   &LoadIMs;             $threadid = $INFO{'id'}; 
             foreach my $thread (@threads) {
   # navigation link                 chomp $thread; 
   $yynavigation = qq~&rsaquo; <a href="$scripturl?action=mycenter" class="nav">$img_txt{'mycenter'}</a> &rsaquo; $mctitle~;                 if ( $thread =~ /$threadid/xsm ) { 
                     @fold = split /\|/xsm, $thread;
   ## set template up                     if ( $fold[13] eq 'in' || $fold[13] eq 'out' ) { 
   $mycenter_template =~ s/({|<)yabb mcviewmenu(}|>)/$MCViewMenu/g;                         $folder = qq~$im_folders_txt{$fold[13]}~; 
   $mycenter_template =~ s/({|<)yabb mcmenu(}|>)/$yymcmenu/g;                     } 
   $mycenter_template =~ s/({|<)yabb mcpmmenu(}|>)/$MCPmMenu/g;                     else { $folder = $fold[13]; } 
   $mycenter_template =~ s/({|<)yabb mcprofmenu(}|>)/$MCProfMenu/g;                 } 
   $mycenter_template =~ s/({|<)yabb mcpostsmenu(}|>)/$MCPostsMenu/g;             } 
   $mycenter_template =~ s/({|<)yabb mcglobformstart(}|>)/$MCGlobalFormStart/g;             if ( $INFO{'viewfolder'} eq 'in' || $INFO{'viewfolder'} eq 'out' ) { 
   $mycenter_template =~ s/({|<)yabb mcglobformend(}|>)/ ($MCGlobalFormStart ? "<\/form>" : "") /e;                 $IM_box .= qq~ &rsaquo; $im_folders_txt{"$INFO{'viewfolder'}"}~; 
   $mycenter_template =~ s/({|<)yabb mcextrasmilies(}|>)/$MCExtraSmilies/g;             } 
   $mycenter_template =~ s/({|<)yabb mccontent(}|>)/$MCContent/g;             elsif ( $INFO{'viewfolder'} ) { 
   $mycenter_template =~ s/({|<)yabb mctitle(}|>)/$mctitle/g;                 $IM_box .= qq~ &rsaquo; $INFO{'viewfolder'}~; 
   $mycenter_template =~ s/({|<)yabb selecthtml(}|>)/$selecthtml/g;             } 
   $mycenter_template =~ s/({|<)yabb forumjump(}|>)//g;             $mctitle .= qq~ &rsaquo; $folder~; 
             $PMfileToOpen = 'imstore';
   ## end new style box         } 
   $yymain .= $mycenter_template;         ## sending a message / previewing 
   if (%usernames_life_quote) { # for display names in Quotes in LivePreview         elsif ( $action eq 'imsend' ) 
       $yymain .= qq~         { 
<script language="JavaScript" type="text/javascript">             $IM_box = $inmes_txt{'148'}; 
<!-- //             if ( $INFO{'forward'} == 1 ) { $IM_box = $inmes_txt{'forward'}; } 
   ~ . join(';', map { qq~LivePrevDisplayNames['$_'] = "$usernames_life_quote{$_}"~ } keys %usernames_life_quote) . qq~;             if ( $INFO{'reply'} )        { $IM_box = $inmes_txt{'replymess'}; } 
// -->             IMPost(); 
</script>\n\n~;             buildIMsend(); 
   }             doshowims(); 
   &template;         } 
         ## posting the message or draft
         elsif ( $action eq 'imsend2' || $FORM{'draft'} ) {
             $IM_box = $inmes_txt{'148'};
             if ( $INFO{'forward'} == 1 ) { $IM_box = $inmes_txt{'forward'}; }
             if ( $INFO{'reply'} )        { $IM_box = $inmes_txt{'replymess'}; }
             IMsendMessage();
         }
         elsif ( $action eq 'imshow' && $INFO{'caller'} == 5 ) {
             $mctitle    = $inmes_txt{'broadcast'};
             $status     = $inmes_imtxt{'status'};
             $senderinfo = $inmes_txt{'318'};
             $callerid   = 5;
             $boxtxt     = $inmes_txt{'316'};
             $movebutton =
  qq~<input type="submit" name="imaction" value="$inmes_imtxt{'store'}" class="button" />$otherStoreSelect $inmes_txt{'storeor'}~;
             $IM_box       = $inmes_txt{'broadcast'};
             $PMfileToOpen = 'msg';
         }
     }
     ## viewing front page
     elsif ( $view eq 'mycenter' ) {
         $mctitle = "$inmes_txt{'mycenter'}";
     }
     ## viewing my profile
     elsif ( $view eq 'profile' ) {
         $mctitle = "$mc_menus{'profile'}";
     }
     ## viewing my recent posts
     elsif ( $view eq 'recentposts' ) {
         $mctitle =
           "$inmes_txt{'viewrecentposts'} $inmes_txt{'viewrecentposts2'}";
     }
   
     ## draw the container
     drawPMbox($PMfileToOpen);
     LoadIMs();
   
     # navigation link
     $yynavigation =
  qq~&rsaquo; <a href="$scripturl?action=mycenter" class="nav">$img_txt{'mycenter'}</a> &rsaquo; $mctitle~;
   
     ## set template up
     $mycenter_template =~ s/{yabb mcviewmenu}/$MCViewMenu/gsm;
     $mycenter_template =~ s/{yabb mcmenu}/$yymcmenu/gsm;
     $mycenter_template =~ s/{yabb mcpmmenu}/$MCPmMenu/gsm;
     $mycenter_template =~ s/{yabb mcprofmenu}/$MCProfMenu/gsm;
     $mycenter_template =~ s/{yabb mcpostsmenu}/$MCPostsMenu/gsm;
     $mycenter_template =~
       s/{yabb mcglobformstart}/$MCGlobalFormStart/gsm;
     $mycenter_template =~
  s/{yabb mcglobformend}/ ($MCGlobalFormStart ? "<\/form>" : q{}) /esm;
   
     $mycenter_template =~ s/{yabb mccontent}/$MCContent/gsm;
     $mycenter_template =~ s/{yabb mctitle}/$mctitle/gsm;
     $mycenter_template =~ s/{yabb selecthtml}/$selecthtml/gsm;
     $mycenter_template =~ s/{yabb forumjump}//gsm;
   
     ## end new style box
     $yymain .= $mycenter_template;
     template();
     return;
} }
   
sub AddFolder { sub AddFolder {
   if ($iamguest) { &fatal_error("im_members_only"); }    if ($iamguest) { fatal_error('im_members_only'); }
   my $storefolders = ${$username}{'PMfolders'};    my $storefolders     = ${$username}{'PMfolders'};
   my @currStoreFolders = split(/\|/, ${$username}{'PMfolders'});     my @currStoreFolders = split /\|/xsm, ${$username}{'PMfolders'}; 
   my $newStoreFolders = "in|out";     my $newStoreFolders  = 'in|out'; 
   
   my $newFolderName = $FORM{'newfolder'};    my $newFolderName = $FORM{'newfolder'};
   chomp $newFolderName;    chomp $newFolderName;
   
   my $x = 0;    my $x = 0;
   nxtfdr: foreach my $currStoreFolder (@currStoreFolders) {  NXTFDR: foreach my $currStoreFolder (@currStoreFolders) {
       if ($FORM{'newfolder'}) {        if ( $FORM{'newfolder'} ) {
           if ($newFolderName =~ /[^0-9A-Za-z \-_]/) { &fatal_error('invalid_character', $inmes_txt{'foldererror'}); }             if ( $newFolderName =~ /[^0-9A-Za-z \-_]/xsm ) { 
           if ($FORM{'newfolder'} eq $currStoreFolder) { &fatal_error('im_folder_exists'); }                 fatal_error( 'invalid_character', $inmes_txt{'foldererror'} ); 
       } elsif ($FORM{'delfolders'}) {             } 
           if ($currStoreFolder ne 'in' && $currStoreFolder ne 'out' && $FORM{"delfolder$x"} ne 'del') {            if ( $FORM{'newfolder'} eq $currStoreFolder ) {
               $newStoreFolders .= qq~|$currStoreFolder~;                 fatal_error('im_folder_exists'); 
           }            }
       }        }
       $x++;         elsif ( $FORM{'delfolders'} ) { 
   }             if (   $currStoreFolder ne 'in' 
   if ($FORM{'newfolder'}) { ${$username}{'PMfolders'} = qq~$storefolders|$FORM{'newfolder'}~; }                 && $currStoreFolder ne 'out' 
   elsif ($FORM{'delfolders'}) { ${$username}{'PMfolders'} = $newStoreFolders; }                 && $FORM{"delfolder$x"} ne 'del' ) 
   &buildIMS($username, 'update');             { 
   $yySetLocation = qq~$scripturl?action=mycenter~;                 $newStoreFolders .= qq~|$currStoreFolder~; 
   &redirectexit;             } 
         }
         $x++;
     }
     if ( $FORM{'newfolder'} ) {
         ${$username}{'PMfolders'} = qq~$storefolders|$FORM{'newfolder'}~;
     }
     elsif ( $FORM{'delfolders'} ) {
         ${$username}{'PMfolders'} = $newStoreFolders;
     }
     buildIMS( $username, 'update' );
     $yySetLocation = qq~$scripturl?action=mycenter~;
     redirectexit();
     return;
} }
   
##  call an unopened message back ##  call an unopened message back
sub CallBack { sub CallBack {
   if ($iamguest) { &fatal_error("im_members_only"); }    if ($iamguest) { fatal_error('im_members_only'); }
   
   my $receiver = $INFO{'receiver'}; # set variables from GET - localised  
   
   if ($receiver && $receiver !~ /,/) {     my $receiver = $INFO{'receiver'};    # set variables from GET - localised 
       my $receiver = &decloak($receiver);  
       if (&CallBackRec($receiver,$INFO{'rid'},1)) { &fatal_error("im_deleted"); }  
       &updateIMS($receiver,$INFO{'rid'},'callback');  
   } elsif ($receiver) {  
       my $rec;  
       foreach $rec (split(/,/, $receiver)) {  
           $rec = &decloak($rec);  
           if (&CallBackRec($rec,$INFO{'rid'},0)) { &fatal_error("im_deleted_multi"); }  
       }  
       foreach $rec (split(/,/, $receiver)) {  
           $rec = &decloak($rec);  
           &CallBackRec($rec,$INFO{'rid'},1);  
           &updateIMS($rec,$INFO{'rid'},'callback');  
       }  
   }  
   
   &updateMessageFlag($username, $INFO{'rid'}, 'outbox', '', 'c');     if ( $receiver && $receiver !~ /,/xsm ) { 
         $receiver = decloak($receiver);
   $yySetLocation = qq~$scripturl?action=imoutbox~;         if ( CallBackRec( $receiver, $INFO{'rid'}, 1 ) ) { 
   &redirectexit;             fatal_error('im_deleted'); 
         }
         updateIMS( $receiver, $INFO{'rid'}, 'callback' );
     }
     elsif ($receiver) {
         foreach my $rec ( split /,/xsm, $receiver ) {
             $rec = decloak($rec);
             if ( CallBackRec( $rec, $INFO{'rid'}, 0 ) ) {
                 fatal_error('im_deleted_multi');
             }
         }
         foreach my $rec ( split /,/xsm, $receiver ) {
             $rec = decloak($rec);
             CallBackRec( $rec, $INFO{'rid'}, 1 );
             updateIMS( $rec, $INFO{'rid'}, 'callback' );
         }
     }
   
     updateMessageFlag( $username, $INFO{'rid'}, 'outbox', q{}, 'c' );
   
     $yySetLocation = qq~$scripturl?action=imoutbox~;
     redirectexit();
     return;
} }
   
sub CallBackRec { sub CallBackRec {
   my ($receiver,$rid,$do_it) = @_;    my ( $receiver, $rid, $do_it ) = @_;
   
   fopen(RECMSG, "$memberdir/$receiver.msg");     fopen( RECMSG, "$memberdir/$receiver.msg" ); 
   my @rims = <RECMSG>;    my @rims = <RECMSG>;
   fclose(RECMSG);    fclose(RECMSG);
   
   my ($nodel,$rmessageid,$fromuser,$flags);     my ( $nodel, $rmessageid, $fromuser, $flags ); 
   fopen(REVMSG, ">$memberdir/$receiver.msg") if $do_it;     if ($do_it) { fopen( REVMSG, ">$memberdir/$receiver.msg" ); } 
   ## run through and drop the message line    ## run through and drop the message line
   foreach (@rims) {    foreach (@rims) {
       ($rmessageid,$fromuser, undef, undef, undef, undef, undef, undef, undef, undef, undef, undef, $flags, undef) = split(/\|/, $_, 14);         ( 
       if (!$do_it) {             $rmessageid, $fromuser, undef,  undef, undef, 
           if ($rmessageid == $rid && $fromuser eq $username) {             undef,       undef,     undef,  undef, undef, 
               if ($flags !~ /u/i) { $nodel = 1; }             undef,       undef,     $flags, undef 
               last;         ) = split /\|/xsm, $_, 14; 
           }         if ( !$do_it ) { 
       } else {            if ( $rmessageid == $rid && $fromuser eq $username ) {
           if ($rmessageid != $rid || $fromuser ne $username) { print REVMSG $_; }                if ( $flags !~ /u/ism ) { $nodel = 1; }
           elsif ($flags !~ /u/i) { print REVMSG $_; $nodel = 1;}                 last; 
       }            }
   }        }
   fclose(REVMSG) if $do_it;         else { 
   $nodel;             if ( $rmessageid != $rid || $fromuser ne $username ) { 
}                 print {REVMSG} $_ or croak "$croak{'print'} REVMSG"; 
             }
sub checkIMS { # lookup value in pm file             elsif ( $flags !~ /u/ism ) { 
   my $user = $_[0];                 print {REVMSG} $_ or croak "$croak{'print'} REVMSG"; 
   my $id = $_[1];                 $nodel = 1; 
   my $checkfor = $_[2];             } 
         }
   ## has the message been opened by the receiver? 1 = yes 0 = no     } 
   if ($checkfor eq 'messageopened') {     if ($do_it) { fclose(REVMSG); } 
       my $messageFoundFlag = &checkMessageFlag($user, $id, 'msg', 'u');     return $nodel; 
       if ($messageFoundFlag == 1) { return 0; } }
       else {$messageFoundFlag = &checkMessageFlag($user, $id, 'imstore', 'u'); }  
       if ($messageFoundFlag == 1) { return 0; }  sub checkIMS {    # lookup value in pm file 
       else { return 1; }     my ( $user, $id, $checkfor ) = @_; 
   
   ## has the message been replied to? 1 = yes 0 = no    ## has the message been opened by the receiver? 1 = yes 0 = no
   } elsif ($checkfor eq 'messagereplied') {    if ( $checkfor eq 'messageopened' ) {
       ## check in msg and imstore         my $messageFoundFlag = checkMessageFlag( $user, $id, 'msg', 'u' ); 
       my $messageFoundFlag = &checkMessageFlag($user, $id, 'msg', 'r');         if ( $messageFoundFlag == 1 ) { return 0; } 
       if ($messageFoundFlag == 1) { return 1; }         else { 
       else {$messageFoundFlag = &checkMessageFlag($user, $id, 'imstore', 'r'); }             $messageFoundFlag = checkMessageFlag( $user, $id, 'imstore', 'u' ); 
       if ($messageFoundFlag == 1) { return 1; }        }
       else { return 0; }        if   ( $messageFoundFlag == 1 ) { return 0; }
   }        else                            { return 1; }
}  
         ## has the message been replied to? 1 = yes 0 = no
sub checkMessageFlag { # look for $user.$pmFile, find $id message and check for $messageFlag     } 
   my ($user, $id, $pmFile, $messageFlag) = @_;     elsif ( $checkfor eq 'messagereplied' ) { 
   my $messageFoundFlag = 0;         ## check in msg and imstore 
   if (%{'MF' . $user . $pmFile}) {         my $messageFoundFlag = checkMessageFlag( $user, $id, 'msg', 'r' ); 
       if (exists ${'MF' . $user . $pmFile}{$id} && ${'MF' . $user . $pmFile}{$id} =~ /$messageFlag/i) { $messageFoundFlag = 1; }        if ( $messageFoundFlag == 1 ) { return 1; }
   } elsif (-e "$memberdir/$user.$pmFile") {        else {
       fopen ("USERMSG", "$memberdir/$user.$pmFile");             $messageFoundFlag = checkMessageFlag( $user, $id, 'imstore', 'r' ); 
       my @userMessages = <USERMSG>;         } 
       fclose ("USERMSG");         if   ( $messageFoundFlag == 1 ) { return 1; } 
       my ($uMessageId,$uMessageFlags);         else                            { return 0; } 
       foreach (@userMessages) {     } 
           ($uMessageId, undef, undef, undef, undef, undef, undef, undef, undef, undef, undef, undef, $uMessageFlags, undef) = split(/\|/, $_,  14);     return; 
           ${'MF' . $user . $pmFile}{$uMessageId} = $uMessageFlags;  } 
           if ($uMessageId == $id && $uMessageFlags =~ /$messageFlag/i) { $messageFoundFlag = 1; }  
       }  sub checkMessageFlag { 
   }  
   $messageFoundFlag;     # look for $user.$pmFile, find $id message and check for $messageFlag 
}     my ( $user, $id, $pmFile, $messageFlag ) = @_; 
     my $messageFoundFlag = 0;
sub updateMessageFlag { # look for $user.$pmFile, find $id message and check for $messageFlag. change to $newMessageFlag     if ( %{ 'MF' . $user . $pmFile } ) { 
   my ($user, $id, $pmFile, $messageFlag, $newMessageFlag) = @_;         if ( exists ${ 'MF' . $user . $pmFile }{$id} 
   my $messageFoundFlag = 0;             && ${ 'MF' . $user . $pmFile }{$id} =~ /$messageFlag/ism ) 
   if ((!exists ${'MF' . $user . $pmFile}{$id} || ($messageFlag ne '' && ${'MF' . $user . $pmFile}{$id} =~ /$messageFlag/) || ($messageFlag eq '' && !${'MF' . $user . $pmFile}{$id} =~ /$newMessageFlag/)) && -e "$memberdir/$user.$pmFile") {        {
       fopen ("USERFILE", "+<$memberdir/$user.$pmFile");             $messageFoundFlag = 1; 
       my @userFile = <USERFILE>;         } 
       seek USERFILE, 0, 0;     } 
       truncate USERFILE, 0;     elsif ( -e "$memberdir/$user.$pmFile" ) { 
       foreach my $userMessage (@userFile) {         fopen( USERMSG, "$memberdir/$user.$pmFile" ); 
           my ($uMessageId, $uFrom, $uToUser, $uTocc, $uTobcc, $uSubject, $uDate, $uMessage, $uPid, $uReply , $uip, $uStatus, $uMessageFlags, $uStorefolder, $uAttach) = split(/\|/, $userMessage);         my @userMessages = <USERMSG>; 
           if ($uMessageId == $id) {         fclose(USERMSG); 
               $uMessageFlags =~ s/$newMessageFlag//gi if $newMessageFlag ne '';         my ( $uMessageId, $uMessageFlags ); 
               if ($uMessageFlags =~ s/$messageFlag/$newMessageFlag/i) {        foreach (@userMessages) {
                   $messageFoundFlag = 1;             ( 
               } else {                 $uMessageId, undef, undef,          undef, undef, 
                   $uMessageFlags .= $newMessageFlag;                 undef,       undef, undef,          undef, undef, 
               }                 undef,       undef, $uMessageFlags, undef 
               $userMessage = "$uMessageId|$uFrom|$uToUser|$uTocc|$uTobcc|$uSubject|$uDate|$uMessage|$uPid|$uReply|$uip|$uStatus|$uMessageFlags|$uStorefolder|$uAttach";             ) = split /\|/xsm, $_, 14; 
           }             ${ 'MF' . $user . $pmFile }{$uMessageId} = $uMessageFlags; 
           ${'MF' . $user . $pmFile}{$uMessageId} = $uMessageFlags;             if ( $uMessageId == $id && $uMessageFlags =~ /$messageFlag/ism ) { 
           print USERFILE  $userMessage;                 $messageFoundFlag = 1; 
       }            }
       fclose("USERFILE");         } 
   }    }
   $messageFoundFlag;    return $messageFoundFlag;
} }
   
sub updateIMS { # update .ims file for user: &updateIMS(<user>,<PM msgid>,[target/action])  sub updateMessageFlag { 
   my ($user,$id,$target) = @_;  
  # look for $user.$pmFile, find $id message and check for $messageFlag. change to $newMessageFlag
   # load the user who is processed here, if not allready loaded     my ( $user, $id, $pmFile, $messageFlag, $newMessageFlag ) = @_; 
   &buildIMS($user, 'load') unless exists ${$user}{'PMmnum'};     my $messageFoundFlag = 0; 
     if (
   # new msg received - add to the inbox lists and increment the counts         ( 
   if ($target eq 'messagein') {             !exists ${ 'MF' . $user . $pmFile }{$id} 
       # read the lines into temp variables             || ( $messageFlag ne q{} 
       ${$user}{'PMmnum'}++;                 && ${ 'MF' . $user . $pmFile }{$id} =~ /$messageFlag/xsm ) 
       ${$user}{'PMimnewcount'}++;             || ( $messageFlag eq q{} 
                 && !${ 'MF' . $user . $pmFile }{$id} =~ /$newMessageFlag/xsm )
   # message sent - add to the outbox list and increment count         ) 
   } elsif ($target eq 'messageout') {         && -e "$memberdir/$user.$pmFile" 
       ${$user}{'PMmoutnum'}++;       ) 
     {
   # reading msg in inbox - newcount -1, remove from unread list         fopen( USERFILE, "<$memberdir/$user.$pmFile" ); 
   } elsif ($target eq 'inread') {         my @userFile = <USERFILE>; 
       if (&updateMessageFlag($user, $id, 'msg', 'u', '')) { ${$user}{'PMimnewcount'}--; }         fclose( USERFILE ); 
       else { return; }         my @newpmfile = (); 
         foreach my $userMessage (@userFile) {
   # callback message - take off imnewcount, mnum             my ( 
   } elsif ($target eq 'callback') {                 $uMessageId,    $uFrom,        $uToUser, $uTocc, 
       ${$user}{'PMmnum'}--;                 $uTobcc,        $uSubject,     $uDate,   $uMessage, 
       ${$user}{'PMimnewcount'}--;                 $uPid,          $uReply,       $uip,     $uStatus, 
                 $uMessageFlags, $uStorefolder, $uAttach
   # draft added             ) = split /\|/xsm, $userMessage; 
   } elsif ($target eq 'draftadd') {            if ( $uMessageId == $id ) {
       ${$user}{'PMdraftnum'}++;                 if ( $newMessageFlag ne q{} ) { 
                     $uMessageFlags =~ s/$newMessageFlag//gism;
   # draft send                 } 
   } elsif ($target eq 'draftsend') {                if ( $uMessageFlags =~ s/$messageFlag/$newMessageFlag/ixsm ) {
       ${$user}{'PMdraftnum'}--;                     $messageFoundFlag = 1; 
   }                }
                 else {
                     $uMessageFlags .= $newMessageFlag;
                 }
                 $userMessage =
  "$uMessageId|$uFrom|$uToUser|$uTocc|$uTobcc|$uSubject|$uDate|$uMessage|$uPid|$uReply|$uip|$uStatus|$uMessageFlags|$uStorefolder|$uAttach";
             }
             ${ 'MF' . $user . $pmFile }{$uMessageId} = $uMessageFlags;
             push @newpmfile, $userMessage;
   
         }
         fopen( USERFILE, ">$memberdir/$user.$pmFile" );
         print {USERFILE} @newpmfile or croak "$croak{'print'} USERFILE";
         fclose(USERFILE);
     }
     return $messageFoundFlag;
  }
   
  sub updateIMS {
   
     # update .ims file for user: &updateIMS(<user>,<PM msgid>,[target/action])
     my ( $user, $id, $target ) = @_;
   
     # load the user who is processed here, if not already loaded
     if ( !exists ${$user}{'PMmnum'} ) { buildIMS( $user, 'load' ); }
   
     # new msg received - add to the inbox lists and increment the counts
     if ( $target eq 'messagein' ) {
   
         # read the lines into temp variables
         ${$user}{'PMmnum'}++;
         ${$user}{'PMimnewcount'}++;
   
         # message sent - add to the outbox list and increment count
     }
     elsif ( $target eq 'messageout' ) {
         ${$user}{'PMmoutnum'}++;
   
         # reading msg in inbox - newcount -1, remove from unread list
     }
     elsif ( $target eq 'inread' ) {
         if ( updateMessageFlag( $user, $id, 'msg', 'u', q{} ) ) {
             ${$user}{'PMimnewcount'}--;
         }
         else { return; }
   
         # callback message - take off imnewcount, mnum
     }
     elsif ( $target eq 'callback' ) {
         ${$user}{'PMmnum'}--;
         ${$user}{'PMimnewcount'}--;
   
         # draft added
     }
     elsif ( $target eq 'draftadd' ) {
         ${$user}{'PMdraftnum'}++;
   
         # draft send
     }
     elsif ( $target eq 'draftsend' ) {
         ${$user}{'PMdraftnum'}--;
     }
   
   &buildIMS($user, 'update'); # rebuild the .ims file it with the new values    buildIMS( $user, 'update' );  # rebuild the .ims file it with the new values
     return;
} }
   
# delete|move IMs # delete|move IMs
sub Del_Some_IM { sub Del_Some_IM {
   &LoadLanguage('InstantMessage');     LoadLanguage('InstantMessage'); 
   if ($iamguest) { &fatal_error('im_members_only'); }    if ($iamguest) { fatal_error('im_members_only'); }
   
   my $fileToOpen = "$username.msg";  
   if ($INFO{'caller'} == 2)    { $fileToOpen = "$username.outbox"; }  
   elsif ($INFO{'caller'} == 3) { $fileToOpen = "$username.imstore"; }  
   elsif ($INFO{'caller'} == 4) { $fileToOpen = "$username.imdraft"; }  
   elsif ($INFO{'caller'} == 5) { $fileToOpen = "broadcast.messages"; }  
   
   fopen(USRFILE, "+<$memberdir/$fileToOpen");  
   seek USRFILE, 0, 0;  
   my @messages = <USRFILE>;  
   seek USRFILE, 0, 0;  
   truncate USRFILE, 0;  
   
   # deleting  
   if ($FORM{'imaction'} eq $inmes_txt{'remove'} || $INFO{'action'} eq $inmes_txt{'remove'} || $INFO{'deleteid'}) {  
       my %CountStore;  
       if ($INFO{'caller'} == 2)    { ${$username}{'PMmoutnum'} = 0; }  
       elsif ($INFO{'caller'} == 4) { ${$username}{'PMdraftnum'} = 0; }  
       elsif ($INFO{'caller'} != 3 && $INFO{'caller'} != 5) { ${$username}{'PMmnum'} = 0; ${$username}{'PMimnewcount'} = 0; }  
   
       if ($INFO{'deleteid'}) { $FORM{"message" . $INFO{'deleteid'}} = 1; } # singel delete  
   
       foreach (@messages) {  
           my @m = split(/\|/, $_);  
           if (!exists $FORM{"message" . $m[0]}) {  
               print USRFILE $_;  
   
               if ($INFO{'caller'} == 2)    { ${$username}{'PMmoutnum'}++; }  
               elsif ($INFO{'caller'} == 3) { $CountStore{$m[13]}++; }  
               elsif ($INFO{'caller'} == 4) { ${$username}{'PMdraftnum'}++; }  
               elsif ($INFO{'caller'} != 5) { ${$username}{'PMmnum'}++; ${$username}{'PMimnewcount'}++ if $m[12] =~ /u/; }  
           } else {  
               if ($INFO{'caller'} == 3) {  
                   $INFO{'viewfolder'} = $m[13];  
               } elsif ($INFO{'caller'} == 5) {  
                   ${$username}{'PMbcRead'} =~ s/$m[0]\b//g unless ${$username}{'PMbcRead'} =~ s/\b$m[0]$//;  
               }  
           }  
       }  
       fclose(USRFILE);  
       if ($INFO{'caller'} == 3) {  
           ${$username}{'PMfoldersCount'} = '';  
           ${$username}{'PMstorenum'} = 0;  
           foreach (split(/\|/, ${$username}{'PMfolders'})) {  
               $CountStore{$_} ||= 0;  
               ${$username}{'PMfoldersCount'} .= ${$username}{'PMfoldersCount'} eq '' ? $CountStore{$_} : "|$CountStore{$_}";  
               ${$username}{'PMstorenum'} += $CountStore{$_};  
           }  
       }  
       &buildIMS($username, 'update');  
   
   #  moving messages  
   } elsif ($FORM{'imaction'} eq $inmes_imtxt{'store'} || $INFO{'imaction'} eq $inmes_imtxt{'store'}) {  
       my (@newmessages,%CountStore,$imstorefolder);  
       if ($FORM{'tostorefolder'}) { $imstorefolder = $FORM{'tostorefolder'}; }  
       elsif ($INFO{'caller'} == 1) { $imstorefolder = 'in'; }  
       else { $imstorefolder = 'out'; }  
   
       foreach (@messages) {  
           if (!$FORM{"message" . (split(/\|/, $_, 2))[0]}) {  
               if ($INFO{'caller'} != 3) {  
                   print USRFILE $_;  
               } else {  
                   my @m = split(/\|/, $_);  
                   push(@newmessages, [@m]);  
                   $CountStore{$m[13]}++;  
               }  
           } else {  
               my @m = split(/\|/, $_);  
               $m[13] = $imstorefolder;  
               push(@newmessages, [@m]);  
               $CountStore{$imstorefolder}++;  
               if ($INFO{'caller'} != 3) {  
                   ${$username}{'PMstorenum'}++;  
                   if ($INFO{'caller'} == 1) { ${$username}{'PMmnum'}--; }  
                   elsif ($INFO{'caller'} == 2) { ${$username}{'PMmoutnum'}--; }  
                   ${$username}{'PMimnewcount'}-- if $m[12] =~ /u/;  
               }  
           }  
       }  
       fclose(USRFILE);  
   
       if (@newmessages) {  
           if ($INFO{'caller'} != 3) {  
               fopen(IUSRFILE, "$memberdir/$username.imstore");  
               foreach (<IUSRFILE>) {  
                   my @m = split(/\|/, $_);  
                   push(@newmessages, [@m]);  
                   $CountStore{$m[13]}++;  
               }  
               fclose(IUSRFILE);  
           }  
           fopen(TRANSFER, ">$memberdir/$username.imstore");  
           print TRANSFER map({ join('|', @$_) } sort { $$b[6] <=> $$a[6] } @newmessages);  
           fclose(TRANSFER);  
   
           ${$username}{'PMfoldersCount'} = '';  
           foreach (split(/\|/, ${$username}{'PMfolders'})) {  
               $CountStore{$_} ||= 0;  
               ${$username}{'PMfoldersCount'} .= ${$username}{'PMfoldersCount'} eq '' ? $CountStore{$_} : "|$CountStore{$_}";  
           }  
           &buildIMS($username, 'update');  
       }  
   }  
   
   my $redirect = 'im';  
   if ($INFO{'caller'} == 2)    { $redirect = 'imoutbox'; }  
   elsif ($INFO{'caller'} == 3) { $redirect = "imstorage;viewfolder=$INFO{'viewfolder'}"; }  
   elsif ($INFO{'caller'} == 4) { $redirect = 'imdraft'; }  
   elsif ($INFO{'caller'} == 5) { $redirectview = ';focus=bmess'; }  
   
   $yySetLocation = qq~$scripturl?action=$redirect~;     my $fileToOpen = "$username.msg"; 
   &redirectexit;     if    ( $INFO{'caller'} == 2 ) { $fileToOpen = "$username.outbox"; } 
     elsif ( $INFO{'caller'} == 3 ) { $fileToOpen = "$username.imstore"; }
     elsif ( $INFO{'caller'} == 4 ) { $fileToOpen = "$username.imdraft"; }
     elsif ( $INFO{'caller'} == 5 ) { $fileToOpen = 'broadcast.messages'; }
   
     fopen( USRFILE, "<$memberdir/$fileToOpen" );
     my @messages = <USRFILE>;
     fclose( USRFILE );
     my @delpost = ();
     # deleting
     if (   $FORM{'imaction'} eq $inmes_txt{'remove'}
         || $INFO{'action'} eq $inmes_txt{'remove'}
         || $INFO{'deleteid'} )
     {
         my %CountStore;
         if    ( $INFO{'caller'} == 2 ) { ${$username}{'PMmoutnum'}  = 0; }
         elsif ( $INFO{'caller'} == 4 ) { ${$username}{'PMdraftnum'} = 0; }
         elsif ( $INFO{'caller'} != 3 && $INFO{'caller'} != 5 ) {
             ${$username}{'PMmnum'}       = 0;
             ${$username}{'PMimnewcount'} = 0;
         }
   
         if ( $INFO{'deleteid'} ) {
             $FORM{ 'message' . $INFO{'deleteid'} } = 1;
         }    # single delete
         @delpost = ();
         foreach (@messages) {
             my @m = split /\|/xsm, $_;
             chomp @m;
             if ( $INFO{'caller'} != 1 && $m[14] ne q{} ) {
                 foreach ( split /,/xsm, $m[14] ) {
                     my ( $pmAttachFile, $pmAttachUser ) = split /~/xsm, $_;
                     if ( $username eq $pmAttachUser ) {
                         unlink "$pmuploaddir/$pmAttachFile";
                     }
                 }
             }
             if ( !exists $FORM{ 'message' . $m[0] } ) {
                 push @delpost, $_;
   
                 if    ( $INFO{'caller'} == 2 ) { ${$username}{'PMmoutnum'}++; }
                 elsif ( $INFO{'caller'} == 3 ) { $CountStore{ $m[13] }++; }
                 elsif ( $INFO{'caller'} == 4 ) { ${$username}{'PMdraftnum'}++; }
                 elsif ( $INFO{'caller'} != 5 ) {
                     ${$username}{'PMmnum'}++;
                     if ( $m[12] =~ /u/sm ) { ${$username}{'PMimnewcount'}++; }
                 }
             }
             else {
                 if ( $INFO{'caller'} == 3 ) {
                     $INFO{'viewfolder'} = $m[13];
                 }
                 elsif ( $INFO{'caller'} == 5 ) {
                     if ( ${$username}{'PMbcRead'} !~ s/\b$m[0]$//gsm ) {
                         ${$username}{'PMbcRead'} =~ s/$m[0]\b//gsm;
                     }
                 }
             }
         }
         fopen( USRFILE, ">$memberdir/$fileToOpen" );
         print {USRFILE} @delpost or croak "$croak{'print'} USRFILE";
         fclose(USRFILE);
   
         if ( $INFO{'caller'} == 3 ) {
             ${$username}{'PMfoldersCount'} = q{};
             ${$username}{'PMstorenum'}     = 0;
             foreach ( split /\|/xsm, ${$username}{'PMfolders'} ) {
                 $CountStore{$_} ||= 0;
                 ${$username}{'PMfoldersCount'} .=
                   ${$username}{'PMfoldersCount'} eq q{}
                   ? $CountStore{$_}
                   : "|$CountStore{$_}";
                 ${$username}{'PMstorenum'} += $CountStore{$_};
             }
         }
         buildIMS( $username, 'update' );
   
         #  moving messages
     }
     elsif ($FORM{'imaction'} eq $inmes_imtxt{'store'}
         || $INFO{'imaction'} eq $inmes_imtxt{'store'} )
     {
         my ( @newmessages, %CountStore, $imstorefolder );
         if ( $FORM{'tostorefolder'} ) {
             $imstorefolder = $FORM{'tostorefolder'};
         }
         elsif ( $INFO{'caller'} == 1 ) { $imstorefolder = 'in'; }
         else                           { $imstorefolder = 'out'; }
         @delpost = ();
         foreach (@messages) {
             if ( !$FORM{ 'message' . ( split /\|/xsm, $_, 2 )[0] } ) {
                 if ( $INFO{'caller'} != 3 ) {
                     push @delpost, $_;
                 }
                 else {
                     my @m = split /\|/xsm, $_;
                     push @newmessages, [@m];
                     $CountStore{ $m[13] }++;
                 }
             }
             else {
                 my @m = split /\|/xsm, $_;
                 $m[13] = $imstorefolder;
                 push @newmessages, [@m];
                 $CountStore{$imstorefolder}++;
                 if ( $INFO{'caller'} != 3 ) {
                     ${$username}{'PMstorenum'}++;
                     if ( $INFO{'caller'} == 1 ) { ${$username}{'PMmnum'}--; }
                     elsif ( $INFO{'caller'} == 2 ) {
                         ${$username}{'PMmoutnum'}--;
                     }
                     if ( $m[12] =~ /u/sm ) { ${$username}{'PMimnewcount'}--; }
                 }
             }
         }
         fopen( USRFILE, ">$memberdir/$fileToOpen" );
         print {USRFILE} @delpost or croak "$croak{'print'} USRFILE";
         fclose(USRFILE);
   
         if (@newmessages) {
             if ( $INFO{'caller'} != 3 ) {
                 fopen( IUSRFILE, "$memberdir/$username.imstore" );
                 while ( my $line = <IUSRFILE> ) {
                     my @m = split /\|/xsm, $line;
                     push @newmessages, [@m];
                     $CountStore{ $m[13] }++;
                 }
                 fclose(IUSRFILE);
             }
             fopen( TRANSFER, ">$memberdir/$username.imstore" );
             print {TRANSFER}
               map( { join q{|}, @{$_} }
                 reverse sort { ${$a}[6] <=> ${$b}[6] } @newmessages )
               or croak "$croak{'print'} TRANSFER";
             fclose(TRANSFER);
   
             ${$username}{'PMfoldersCount'} = q{};
             foreach ( split /\|/xsm, ${$username}{'PMfolders'} ) {
                 $CountStore{$_} ||= 0;
                 ${$username}{'PMfoldersCount'} .=
                   ${$username}{'PMfoldersCount'} eq q{}
                   ? $CountStore{$_}
                   : "|$CountStore{$_}";
             }
             buildIMS( $username, 'update' );
         }
     }
   
     my $redirect = 'im';
     if ( $INFO{'caller'} == 2 ) { $redirect = 'imoutbox'; }
     elsif ( $INFO{'caller'} == 3 ) {
         $redirect = "imstorage;viewfolder=$INFO{'viewfolder'}";
     }
     elsif ( $INFO{'caller'} == 4 ) { $redirect     = 'imdraft'; }
     elsif ( $INFO{'caller'} == 5 ) { $redirectview = ';focus=bmess'; }
   
     $yySetLocation = qq~$scripturl?action=$redirect~;
     redirectexit();
     return;
} }
   
# if the user is valid..  # if the user is valid. 
sub LoadValidUserDisplay { sub LoadValidUserDisplay {
   my $muser = $_[0];     my ($muser) = @_; 
   if (!$yyUDLoaded{$muser} && -e "$memberdir/$muser.vars") { $sm = 1; &LoadUserDisplay($muser); }     if ( !$yyUDLoaded{$muser} && -e "$memberdir/$muser.vars" ) { 
         $sm = 1;
         LoadUserDisplay($muser);
     }
     return;
} }
   
# create either a full link or just a name for the IM display # create either a full link or just a name for the IM display
sub CreateUserDisplayLine { sub CreateUserDisplayLine {
   $usrname = $_[0];     my ($usrname) = @_; 
   my $usernamelink;    my $usernamelink;
   
   $sendPM = '';     $sendPM     = q{}; 
   $sendEmail = '';     $sendEmail  = q{}; 
   $membAdInfo = '';     $membAdInfo = q{}; 
   
   if ($yyUDLoaded{$usrname}) {    if ( $yyUDLoaded{$usrname} ) {
       unless ($INFO{'caller'} == 2 && ($mstatus =~ /b/ || $mtousers =~ /,/ || $mccusers || $mbccusers)) {         if ( 
           $signature = ${$uid.$usrname}{'signature'};             $INFO{'caller'} != 2 
           if ($INFO{'caller'} == 2 || $INFO{'caller'} == 3) { $signature = ''; }             || (   $mstatus !~ /b/sm 
           unless($INFO{'caller'} == 5 && $mstatus eq 'g') { &userOnLineStatus($usrname); }                 && $mtousers !~ /,/xsm 
                 && !$mccusers
           if (!$iamguest) {                 && !$mbccusers ) 
               # Allow instant message sending if current user is a member.           ) 
               $sendPM = qq~$menusep<a href="$scripturl?action=imsend;to=$useraccount{$usrname}">$img{'message_sm'}</a>~;         { 
           }             $signature = ${ $uid . $usrname }{'signature'}; 
           if (!${$uid.$usrname}{'hidemail'} || $iamadmin || $iamgmod || $allow_hide_email != 1) {            if ( $INFO{'caller'} == 2 || $INFO{'caller'} == 3 ) {
               $sendEmail = qq~$menusep<a href="mailto:${$uid.$usrname}{'email'}">$img{'email_sm'}</a>~;                 $signature = q{}; 
           }            }
             if ( $INFO{'caller'} != 5
           if (!$minlinkweb) { $minlinkweb = 0; }                 || ( $mstatus ne 'g' && $mstatus ne 'ga' ) ) 
           my $wwwlink = (${$uid.$user}{'weburl'} && (${$uid.$user}{'postcount'} >= $minlinkweb || ${$uid.$user}{'position'} eq 'Administrator' || ${$uid.$user}{'position'} eq 'Global Moderator')) ? qq~$menusep${$uid.$usrname}{'weburl'}~ : '';             { 
           my $aimad = ${$uid.$usrname}{'aim'} ? qq~$menusep${$uid.$usrname}{'aim'}~ : '';                 userOnLineStatus($usrname); 
           my $icqad = ${$uid.$usrname}{'icq'} ? qq~$menusep${$uid.$usrname}{'icq'}~ : '';             } 
           my $yimad = ${$uid.$usrname}{'yim'} ? qq~$menusep${$uid.$usrname}{'yim'}~ : '';  
           my $msnad = ${$uid.$usrname}{'msn'} ? qq~$menusep${$uid.$usrname}{'msn'}~ : '';             if ( !$iamguest ) { 
           my $gtalkad = ${$uid.$usrname}{'gtalk'} ? qq~$menusep${$uid.$usrname}{'gtalk'}~ : '';  
           my $skypead = ${$uid.$usrname}{'skype'} ? qq~$menusep${$uid.$usrname}{'skype'}~ : '';                 # Allow instant message sending if current user is a member. 
           my $myspacead = ${$uid.$usrname}{'myspace'} ? qq~$menusep${$uid.$usrname}{'myspace'}~ : '';                 $sendPM = 
           my $facebookad = ${$uid.$usrname}{'facebook'} ? qq~$menusep${$uid.$usrname}{'facebook'}~ : '';  qq~$menusep<a href="$scripturl?action=imsend;to=$useraccount{$usrname}">$img{'message_sm'}</a>~; 
             }
           $membAdInfo = $profbutton . $wwwlink . $msnad . $gtalkad . $icqad . $yimad . $aimad . $skypead . $myspacead . $facebookad;             if (   !${ $uid . $usrname }{'hidemail'} 
       }                 || $iamadmin 
       $usernamelink = $link{$usrname};                 || $iamgmod 
       if ($musername eq $username) {                 || $allow_hide_email != 1 ) 
           $imOpened = &checkIMS($usrname, $messageid, 'messageopened');             { 
           &LoadUser($usrname);                 $sendEmail = 
           if (!$imOpened && (${$uid.$usrname}{'notify_me'} < 2 || $enable_notifications < 2)) { $usernamelink .= qq~ <span class="small">(<a href="$scripturl?action=imcb;rid=$messageid;receiver=$useraccount{$usrname}" onclick="return confirm('$inmes_imtxt{'73'}')">$inmes_imtxt{'83'}</a>)</span>~; }  qq~$menusep<a href="mailto:${$uid.$usrname}{'email'}">$img{'email_sm'}</a>~; 
       }            }
   } else {  
       $usernamelink = qq~<b>$usrname</b>~;             if ( !$minlinkweb ) { $minlinkweb = 0; } 
   }             $membAdInfo .= 
   $usernamelink;               ${ $uid . $usrname }{'weburl'} 
               ? $menusep . ${ $uid . $usrname }{'weburl'}
               : q{};
             $membAdInfo .=
               ${ $uid . $usrname }{'gtalk'}
               ? $menusep . ${ $uid . $usrname }{'gtalk'}
               : q{};
             $membAdInfo .=
               ${ $uid . $usrname }{'skype'}
               ? $menusep . ${ $uid . $usrname }{'skype'}
               : q{};
             $membAdInfo .=
               ${ $uid . $usrname }{'myspace'}
               ? $menusep . ${ $uid . $usrname }{'myspace'}
               : q{};
             $membAdInfo .=
               ${ $uid . $usrname }{'facebook'}
               ? $menusep . ${ $uid . $usrname }{'facebook'}
               : q{};
             $membAdInfo .=
               ${ $uid . $usrname }{'twitter'}
               ? $menusep . ${ $uid . $usrname }{'twitter'}
               : q{};
             $membAdInfo .=
               ${ $uid . $usrname }{'youtube'}
               ? $menusep . ${ $uid . $usrname }{'youtube'}
               : q{};
             $membAdInfo .=
               ${ $uid . $usrname }{'icq'}
               ? $menusep . ${ $uid . $usrname }{'icq'}
               : q{};
             $membAdInfo .=
               ${ $uid . $usrname }{'yim'}
               ? $menusep . ${ $uid . $usrname }{'yim'}
               : q{};
             $membAdInfo .=
               ${ $uid . $usrname }{'aim'}
               ? $menusep . ${ $uid . $usrname }{'aim'}
               : q{};
         }
         $usernamelink = $link{$usrname};
         if ( $musername eq $username ) {
             $imOpened = checkIMS( $usrname, $messageid, 'messageopened' );
             LoadUser($usrname);
             if (
                 !$imOpened
                 && ( ${ $uid . $usrname }{'notify_me'} < 2
                     || $enable_notifications < 2 )
               )
             {
                 $usernamelink .=
  qq~ <span class="small">(<a href="$scripturl?action=imcb;rid=$messageid;receiver=$useraccount{$usrname}" onclick="return confirm('$inmes_imtxt{'73'}')">$inmes_imtxt{'83'}</a>)</span>~;
             }
         }
     }
     else {
         $usernamelink = qq~<b>$usrname</b>~;
     }
     return $usernamelink;
} }
   
#  posting the IM #  posting the IM
sub IMPost { sub IMPost {
   if (($INFO{'bmess'} || $FORM{'isBMess'}) eq 'yes') { $sendBMess = 1; }    if ( ( $INFO{'bmess'} || $FORM{'isBMess'} ) eq 'yes' ) { $sendBMess = 1; }
   ##  if user is not a FA/gmod and has a postcount below the threshold     ##  guests not allowed 
   if (!$staff && ${$uid.$username}{'postcount'} < $numposts) {     if ($iamguest) { fatal_error('im_members_only'); } 
       &fatal_error('im_low_postcount');     ##  if user is not a FA/gmod and has a postcount below the threshold 
   }     if ( !$staff && ${ $uid . $username }{'postcount'} < $numposts ) { 
   ##  guests not allowed         fatal_error('im_low_postcount'); 
   if ($iamguest) { &fatal_error('im_members_only'); }    }
   my ($mdate, $mip, $mmessage);     my ( $mdate, $mip, $mmessage ); 
   ##  if the IM has a number assigned already, open the right IM file    ##  if the IM has a number assigned already, open the right IM file
   if ($INFO{'id'} ne '' && !$replyguest) {    if ( $INFO{'id'} ne q{} ) {
       if ($INFO{'caller'} < 5) { &updateIMS($username, $INFO{'id'}, 'inread'); }         if ( $INFO{'caller'} < 5 ) { 
             updateIMS( $username, $INFO{'id'}, 'inread' );
       my $pmFileType = "$username.msg";         } 
       if ($INFO{'caller'} == 2) { $pmFileType = "$username.outbox"; }  
       elsif ($INFO{'caller'} == 3) { $pmFileType = "$username.imstore"; }         my $pmFileType = "$username.msg"; 
       elsif ($INFO{'caller'} == 4) { $pmFileType = "$username.imdraft"; }        if ( $INFO{'caller'} == 2 ) { $pmFileType = "$username.outbox"; }
       elsif ($INFO{'caller'} == 5) { $pmFileType = "broadcast.messages"; }         elsif ( $INFO{'caller'} == 3 ) { 
             $pmFileType = "$username.imstore";
         }
       fopen(FILE, "$memberdir/$pmFileType");         elsif ( $INFO{'caller'} == 4 ) { 
       @messages = <FILE>;             $pmFileType = "$username.imdraft"; 
       fclose(FILE);         } 
       ## split content of IM file up         elsif ( $INFO{'caller'} == 5 ) { 
       foreach my $checkTheMessage (@messages) {             $pmFileType = 'broadcast.messages'; 
           ($qmessageid, $mfrom, $mto, $mtocc, $mtobcc, $msubject, $mdate, $message, $mparid, $mreplyno, $mip, $mstatus, $mflags, $mstore, $mattach) = split(/\|/, $checkTheMessage);         } 
           if ($qmessageid == $INFO{'id'}) { last; }  
       }         if ( !$replyguest ) { 
       ## remove 're:' from subject (why?)             fopen( FILE, "$memberdir/$pmFileType" ); 
       $msubject =~ s/Re: //g;             @messages = <FILE>; 
       ## if replying/quoting, up the reply# by 1             fclose(FILE); 
       if ($INFO{'quote'} || $INFO{'reply'}) { $mreplyno++; $INFO{'status'} = $mstatus; }             ## split content of IM file up 
       ##  if quote             foreach my $checkTheMessage (@messages) { 
       if ($INFO{'reply'}) { $message = ''; }                 ( 
       if ($INFO{'quote'}) {                     $qmessageid, $mfrom,    $mto,   $mtocc, 
           # swap out brs and spaces                     $mtobcc,     $msubject, $mdate, $message, 
           $message =~ s~<br.*?>~\n~gi;                     $mparid,     $mreplyno, $mip,   $mstatus, 
           $message =~ s/ \&nbsp; \&nbsp; \&nbsp;/\t/ig;                     $mflags,     $mstore,   $mattach 
           if (!$nestedquotes) {                 ) = split /\|/xsm, $checkTheMessage; 
               $message =~ s~\n{0,1}\[quote([^\]]*)\](.*?)\[/quote([^\]]*)\]\n{0,1}~\n~isg;                 if ( $qmessageid == $INFO{'id'} ) { last; } 
           }            }
           if ($mfrom ne "" && $do_scramble_id) { $cloakedAuthor = &cloak($mfrom); }             ## remove 're:' from subject (why?) 
           else { $cloakedAuthor = $mfrom; }             $msubject =~ s/Re: //gsm; 
             $msubject =~ s/Fwd: //gsm;
           # next 2 lines for display names in Quotes in LivePreview             ## if replying/quoting, up the reply# by 1 
           &LoadUser($mfrom);             if ( $INFO{'quote'} || $INFO{'reply'} ) { 
           $usernames_life_quote{$cloakedAuthor} = ${$uid.$mfrom}{'realname'};                 $mreplyno++; 
                 $INFO{'status'} = $mstatus;
           $quotestart = int($quotemsg / $maxmessagedisplay) * $maxmessagedisplay;             } 
           if ($INFO{'forward'} || $INFO{'quote'}) {             ##  if quote 
               $message    = qq~[quote author=$cloakedAuthor link=impost date=$mdate\]$message\[/quote\]\n~;             if ( $INFO{'reply'} ) { $message = q{}; } 
           }             if ( $INFO{'quote'} ) { 
           if ($message =~ /\#nosmileys/isg) { $message =~ s/\#nosmileys//isg; $nscheck = "checked"; }  
       }                 # swap out brs and spaces 
       if ($INFO{'reply'} || $INFO{'forward'} || $INFO{'quote'}) { $msubject = "Re: $msubject"; }                 $message =~ s/<br.*?>/\n/igsm; 
   } elsif ($replyguest) {                 $message =~ s/ \&nbsp; \&nbsp; \&nbsp;/\t/igsm; 
       fopen(FILE, "$memberdir/broadcast.messages");                 if ( !$nestedquotes ) { 
       my @messages = <FILE>;                     $message =~ 
       fclose(FILE);  s/\n{0,1}\[quote([^\]]*)\](.*?)\[\/quote([^\]]*)\]\n{0,1}/\n/isgm; 
       ## split content of IM file up                 } 
       foreach my $checkTheMessage (@messages){                 if ( $mfrom ne q{} && $do_scramble_id ) { 
           ($qmessageid, $mfrom, $mto, $mtocc, $mtobcc, $msubject, $mdate, $message, $mparid, $mreplyno, $mip, $mstatus, $mflags, $mstore, $mattach) = split(/\|/, $checkTheMessage);                     $cloakedAuthor = cloak($mfrom); 
           if ($qmessageid == $INFO{'id'}) { last; }                }
       }                else { $cloakedAuthor = $mfrom; }
       ($guestName, $guestEmail) = split(/\ /, $mfrom);  
       $guestName =~ s/%20/ /g;                 # next 2 lines for display names in Quotes in LivePreview 
       $message =~ s~<br.*?>~\n~gi;                 LoadUser($mfrom); 
       $message =~ s/ \&nbsp; \&nbsp; \&nbsp;/\t/ig;                 $usernames_life_quote{$cloakedAuthor} = 
       $message =~ s~\[b\](.*?)\[/b\]~*$1*~isg;                   ${ $uid . $mfrom }{'realname'}; 
       $message =~ s~\[i\](.*?)\[/i\]~/$1/~isg;  
       $message =~ s~\[u\](.*?)\[/u\]~_$1_~isg;                 $maxmessagedisplay ||= 10; 
       $message =~ s~\[.*?\]~~g;                 $quotestart = 
       my $sendtouser = ${$uid.$username}{'realname'};                   int( $quotemsg / $maxmessagedisplay ) * $maxmessagedisplay; 
       my $mdate = &timeformat($mdate, 1);                 if ( $INFO{'forward'} || $INFO{'quote'} ) { 
       require "$sourcedir/Mailer.pl";                     $message = 
       &LoadLanguage('Email');  qq~[quote author=$cloakedAuthor link=impost date=$mdate\]$message\[/quote\]\n~; 
       #sender email date subject message                 } 
       $message = &template_email($replyguestmail, {'sender' => $guestName, 'email' => $guestEmail, 'sendto' => $sendtouser, 'date' => $mdate, 'subject' => $msubject, 'message' => $message});                 if ( $message =~ /\#nosmileys/isgm ) { 
       $msubject = qq~Re: $msubject~;                     $message =~ s/\#nosmileys//isgm; 
   }                     $nscheck = 'checked'; 
                 }
   &FromHTML($message) if $INFO{'forward'} || $INFO{'quote'};             } 
   &FromHTML($msubject);             if ( $INFO{'reply'} || $INFO{'quote'} ) { 
                 $msubject = "Re: $msubject";
   $submittxt = $inmes_txt{'sendmess'};             } 
   if ($INFO{'forward'} == 1) { $submittxt = $inmes_txt{'forward'}; }             if ( $INFO{'forward'} ) { 
   $destination = 'imsend2';                 $msubject =~ s/Re: //gsm; 
   $waction = 'imsend';                 $msubject = "Fwd: $msubject"; 
   $is_preview = 0;             } 
   $post = 'imsend';         } 
   $previewtxt = $inmes_txt{'507'};         elsif ($replyguest) { 
   $preview = 'previewim';             fopen( FILE, "$memberdir/$pmFileType" ); 
   $icon = 'xx';             @messages = <FILE>; 
   $draft = 'draft';             fclose(FILE); 
   $mctitle = $inmes_txt{'sendmess'};             ## split content of IM file up 
   if ($sendBMess) { $mctitle = $inmes_txt{'sendbroadmess'}; }             foreach my $checkTheMessage (@messages) { 
                 (
                     $qmessageid, $mfrom,    $mto,   $mtocc,
                     $mtobcc,     $msubject, $mdate, $message,
                     $mparid,     $mreplyno, $mip,   $mstatus,
                     $mflags,     $mstore,   $mattach
                 ) = split /\|/xsm, $checkTheMessage;
                 if ( $qmessageid == $INFO{'id'} ) { last; }
             }
             ( $guestName, $guestEmail ) = split /\ /sm, $mfrom;
             $guestName =~ s/%20/ /gsm;
             $message   =~ s/<br.*?>/\n/gism;
             $message   =~ s/ \&nbsp; \&nbsp; \&nbsp;/\t/igsm;
             $message   =~ s/\[b\](.*?)\[\/b\]/*$1*/isgm;
             $message   =~ s/\[i\](.*?)\[\/i\]/\/$1\//isgm;
             $message   =~ s/\[u\](.*?)\[\/u\]/_$1_/isgm;
             $message   =~ s/\[.*?\]//gsm;
             my $sendtouser = ${ $uid . $username }{'realname'};
             $mdate = timeformat( $mdate, 1 );
             require Sources::Mailer;
             LoadLanguage('Email');
   
             #sender email date subject message
             $message = template_email(
                 $replyguestmail,
                 {
                     'sender'  => $guestName,
                     'email'   => $guestEmail,
                     'sendto'  => $sendtouser,
                     'date'    => $mdate,
                     'subject' => $msubject,
                     'message' => $message
                 }
             );
             $msubject = qq~Re: $msubject~;
         }
     }
   
     if ( $INFO{'forward'} || $INFO{'quote'} ) { FromHTML($message); }
     FromHTML($msubject);
   
     $submittxt = $inmes_txt{'sendmess'};
     if ( $INFO{'forward'} == 1 ) { $submittxt = $inmes_txt{'forward'}; }
     $destination = 'imsend2';
     $waction     = 'imsend';
     $post        = 'imsend';
     $icon        = 'xx';
     $draft       = 'draft';
     $mctitle     = $inmes_txt{'sendmess'};
     if ($sendBMess) { $mctitle = $inmes_txt{'sendbroadmess'}; }
     return;
} }
   
sub MarkAll { sub MarkAll {
   if ($iamguest) { &fatal_error('im_members_only'); }    if ($iamguest) { fatal_error('im_members_only'); }
   
   fopen(FILE, "+<$memberdir/$username.msg");     fopen( FILE, "<$memberdir/$username.msg" ); 
   seek FILE, 0, 0;     my @messages = <FILE>; 
   my @messages = <FILE>;     fclose( FILE ); 
   seek FILE, 0, 0;     my @mymessages = (); 
   truncate FILE, 0;  
   foreach (@messages) {    foreach (@messages) {
       my ($imessageid, $imusername, $imusernameto, $imusernametocc, $imusernametobcc, $imsub, $imdate, $mmessage, $imessagepid, $imreply, $mip, $imstatus, $imflags, $imstore, $imattach) = split(/\|/, $_);         my ( 
       if ($imflags =~ s/u//i) {             $imessageid,     $imusername,      $imusernameto, 
           print FILE "$imessageid|$imusername|$imusernameto|$imusernametocc|$imusernametobcc|$imsub|$imdate|$mmessage|$imessagepid|$imreply|$mip|$imstatus|$imflags|$imstore|$imattach";             $imusernametocc, $imusernametobcc, $imsub, 
       } else { print FILE $_; }             $imdate,         $mmessage,        $imessagepid, 
   }             $imreply,        $mip,             $imstatus, 
   fclose(FILE);             $imflags,        $imstore,         $imattach 
         ) = split /\|/xsm, $_;
   ${$username}{'PMimnewcount'} = 0;         if ( $imflags =~ s/u//ism ) { 
   &buildIMS($username, 'update');             push @mymessages, 
  "$imessageid|$imusername|$imusernameto|$imusernametocc|$imusernametobcc|$imsub|$imdate|$mmessage|$imessagepid|$imreply|$mip|$imstatus|$imflags|$imstore|$imattach";
   if ($INFO{'oldmarkread'}) {         } 
       $yySetLocation = qq~$scripturl?action=im~;         else { push @mymessages, $_; } 
       &redirectexit;     } 
   }     fopen( FILE, ">$memberdir/$username.msg" ); 
   $elenable = 0;     print {FILE} @mymessages or croak "$croak{'print'} FILE"; 
   die ""; # This is here only to avoid server error log entries!     fclose(FILE); 
   
     ${$username}{'PMimnewcount'} = 0;
     buildIMS( $username, 'update' );
   
     if ( $INFO{'oldmarkread'} ) {
         $yySetLocation = qq~$scripturl?action=im~;
         redirectexit();
     }
     $elenable = 0;
     croak q{};    # This is here only to avoid server error log entries!
} }
   
# change type of page index for PM # change type of page index for PM
sub PmPageindex { sub PmPageindex {
   my ($msindx, $trindx, $mbindx, undef) = split(/\|/, ${$uid.$username}{'pageindex'});     my ( $msindx, $trindx, $mbindx, undef ) = 
   if ($INFO{'action'} eq 'pmpagedrop') { ${$uid.$username}{'pageindex'} = qq~$msindx|$trindx|$mbindx|1~; }       split /\|/xsm, ${ $uid . $username }{'pageindex'}; 
   if ($INFO{'action'} eq 'pmpagetext') { ${$uid.$username}{'pageindex'} = qq~$msindx|$trindx|$mbindx|0~; }     if ( $INFO{'action'} eq 'pmpagedrop' ) { 
   &UserAccount($username, 'update');         ${ $uid . $username }{'pageindex'} = qq~$msindx|$trindx|$mbindx|1~; 
   if ($INFO{'pmaction'} =~ /\//) {     } 
       my ($act, $val) = split(/\//, $INFO{'pmaction'});     if ( $INFO{'action'} eq 'pmpagetext' ) { 
       $INFO{'pmaction'} = $act . ';start=' . $val;         ${ $uid . $username }{'pageindex'} = qq~$msindx|$trindx|$mbindx|0~; 
   }    }
   if ($INFO{'focus'} eq 'bmess') { $bmesslink = qq~;focus=bmess~;}     UserAccount( $username, 'update' ); 
   $yySetLocation = qq~$scripturl?action=$INFO{'pmaction'}$bmesslink;start=$INFO{'start'}~ . ($INFO{'viewfolder'} ? ";viewfolder=$INFO{'viewfolder'}" : "");     if ( $INFO{'pmaction'} =~ /\//xsm ) { 
   &redirectexit;         my ( $act, $val ) = split /\//xsm, $INFO{'pmaction'}; 
         $INFO{'pmaction'} = $act . ';start=' . $val;
     }
     if ( $INFO{'focus'} eq 'bmess' ) { $bmesslink = q~;focus=bmess~; }
     $yySetLocation =
       qq~$scripturl?action=$INFO{'pmaction'}$bmesslink;start=$INFO{'start'}~
       . ( $INFO{'viewfolder'} ? ";viewfolder=$INFO{'viewfolder'}" : q{} );
     redirectexit();
     return;
} }
   
# draw the whole block , with the menu, and the various PM views. # draw the whole block , with the menu, and the various PM views.
sub drawPMbox { sub drawPMbox {
   &LoadLanguage('InstantMessage');     my ($PMfileToOpen) = @_; 
   &LoadLanguage('Profile');     LoadLanguage('InstantMessage'); 
   $PMfileToOpen = $_[0];     if (   ( $PMfileToOpen || $INFO{'focus'} ) 
   @dimmessages;         && $view eq 'pm' 
   @bmessages;         && $pm_lev == 1 ) 
   if ($view eq 'pm' && ($PM_level  == 1 || $PM_level  == 2 && ($iamadmin || $iamgmod || $iammod) || $PM_level  == 3 && ($iamadmin || $iamgmod) )) {    {
       ($qmessageid, $mfrom, $mto, $mtocc, $mtobcc, $msubject, $mdate, $message, $mparid, $mreplyno, $mip, $mstatus, $mflags, $mstore, $mattach);         if ( !$INFO{'focus'} ) { 
             if ( $callerid < 5 ) {
       if (!$INFO{'focus'}) {                 fopen( NFILE, "$memberdir/$username.$PMfileToOpen" ); 
           if ($callerid < 5) {                 @dimmessages = <NFILE>; 
               fopen(NFILE, "$memberdir/$username.$PMfileToOpen");                 my ( $mID, $mFlag ); 
               @dimmessages = <NFILE>;                 foreach ( reverse @dimmessages ) { 
               my ($mID,$mFlag);                     ( 
               foreach (reverse(@dimmessages)) {                         $mID,  undef, undef, undef, undef, undef,  undef, 
                   ($mID, undef, undef, undef, undef, undef, undef, undef, undef, undef, undef, undef, $mFlag, undef) = split(/\|/, $_,  14);                         undef, undef, undef, undef, undef, $mFlag, undef 
                   ${$username . $PMfileToOpen}{$mID} = $mFlag;                     ) = split /\|/xsm, $_, 14; 
                   if ($INFO{'id'} == -1 && $mFlag eq 'u') {                     ${ $username . $PMfileToOpen }{$mID} = $mFlag; 
                       $INFO{'id'} = $mID;                     if ( $INFO{'id'} == -1 && $mFlag eq 'u' ) { 
                   }                         $INFO{'id'} = $mID; 
               }                    }
           } else {                 } 
               fopen(NFILE, "$memberdir/broadcast.messages");             } 
               @bmessages = <NFILE>;             else { 
           }                 fopen( NFILE, "$memberdir/broadcast.messages" ); 
           fclose(NFILE);                 @bmessages = <NFILE>; 
       }            }
       elsif ($INFO{'focus'} eq 'bmess' && $PMenableBm_level > 0) {             fclose(NFILE); 
           fopen(BFILE, "$memberdir/broadcast.messages");         } 
           @bmessages = <BFILE>;         elsif ( $INFO{'focus'} eq 'bmess' && $PMenableBm_level > 0 ) { 
           fclose(BFILE);             fopen( BFILE, "$memberdir/broadcast.messages" ); 
       }             @bmessages = <BFILE>; 
       $stkmess = 0;             fclose(BFILE); 
       if (@bmessages > 0) {         } 
           foreach my $checkbcm (@bmessages) {         $stkmess = 0; 
               my (undef, $mfrom, $mto, undef, undef, undef, undef, undef, undef, undef, undef, $messStatus, undef) = split (/\|/, $checkbcm);         if ( @bmessages > 0 ) { 
               if ($mfrom eq $username || &BroadMessageView($mto)) {            foreach my $checkbcm (@bmessages) {
                   if ($INFO{'sort'} ne 'gpdate' && ($messStatus =~ /g/ || $messStatus =~ /a/)) {                 my ( 
                       push (@stkbmessages, $checkbcm);                     undef, $mfrom,      $mto,  undef, undef, 
                       $stkmess++;                     undef, undef,       undef, undef, undef, 
                   } else {                     undef, $messStatus, undef, 
                       push (@tmpbmessages, $checkbcm);                 ) = split /\|/xsm, $checkbcm; 
                   }                 if ( $mfrom eq $username || BroadMessageView($mto) ) { 
               }                     if ( $INFO{'sort'} ne 'gpdate' 
           }                         && ( $messStatus =~ m/g/sm || $messStatus =~ m/a/sm ) ) 
           undef @bmessages;                     { 
       }                         push @stkbmessages, $checkbcm; 
       @stkbmessages = sort {$b <=> $a} @stkbmessages;                         $stkmess++; 
       @tmpbmessages = sort {$b <=> $a} @tmpbmessages;                     } 
       push (@dimmessages, @stkbmessages);                     else { 
       push (@dimmessages, @tmpbmessages);                         push @tmpbmessages, $checkbcm; 
       undef @stkbmessages;                     } 
       undef @tmpbmessages;                 } 
   }            }
             undef @bmessages;
   $yyjavascript .= qq~         } 
       function changeBox(cbox) {         @stkbmessages = reverse sort { $a <=> $b } @stkbmessages; 
           box = eval(cbox);         @tmpbmessages = reverse sort { $a <=> $b } @tmpbmessages; 
           box.checked = !box.checked;         push @dimmessages, @stkbmessages; 
       }         push @dimmessages, @tmpbmessages; 
   ~;         undef @stkbmessages; 
         undef @tmpbmessages;
     }
   ##  new style box ####  
   ## start with forum > my messages > inbox     $yyjavascript .= q~ 
   $yymain .= qq~         function changeBox(cbox) { 
<script language="JavaScript1.2" src="$yyhtml_root/ajax.js" type="text/javascript"></script>             box = eval(cbox); 
<script language="JavaScript1.2" type="text/javascript">             box.checked = !box.checked; 
<!--         } 
     ~;
   
     ##  new style box ####
     ## start with forum > my messages > inbox
     $yymain .= qq~
  <script src="$yyhtml_root/ajax.js" type="text/javascript"></script>
  <script type="text/javascript">
var postas = '$post'; var postas = '$post';
function checkForm(theForm) { function checkForm(theForm) {
   if (navigator.appName == "Microsoft Internet Explorer" && document.getElementById('iecopy').checked == true) { theForm.message.createTextRange().execCommand("Copy"); }    if (theForm.subject.value === "") { alert("$post_txt{'77'}"); theForm.subject.focus(); return false; }
   if (theForm.subject.value == "") { alert("$post_txt{'77'}"); theForm.subject.focus(); return false }     ~ . ( 
   ~ . ($iamguest && $post ne "imsend" ? qq~if (theForm.name.value == "" || theForm.name.value == "_" || theForm.name.value == " ") { alert("$post_txt{'75'}"); theForm.name.focus(); return false }         $iamguest && $post ne 'imsend' 
   if (theForm.name.value.length > 25)  { alert("$post_txt{'568'}"); theForm.name.focus(); return false }        ? qq~if (theForm.name.value === "" || theForm.name.value == "_" || theForm.name.value == " ") { alert("$post_txt{'75'}"); theForm.name.focus(); return false; }
   if (theForm.email.value == "") { alert("$post_txt{'76'}"); theForm.email.focus(); return false }    if (theForm.name.value.length > 25)  { alert("$post_txt{'568'}"); theForm.name.focus(); return false; }
   if (! checkMailaddr(theForm.email.value)) { alert("$post_txt{'500'}"); theForm.email.focus(); return false }    if (theForm.email.value === "") { alert("$post_txt{'76'}"); theForm.email.focus(); return false; }
~ : qq~if (postas == "imsend") { if (theForm.toshow.value == "") { alert("$post_txt{'752'}"); theForm.toshow.focus(); return false } }~) . qq~     if (! checkMailaddr(theForm.email.value)) { alert("$post_txt{'500'}"); theForm.email.focus(); return false; } 
   if (theForm.message.value == "") { alert("$post_txt{'78'}"); theForm.message.focus(); return false }  ~
   return true         : qq~if (postas == "imsend") { if (theForm.toshow.value === "") { alert("$post_txt{'752'}"); theForm.toshow.focus(); return false; } }~ 
       )
       . qq~
     if (theForm.message.value === "") { alert("$post_txt{'78'}"); theForm.message.focus(); return false; }
     return true;
} }
function NewWindow(mypage, myname, w, h, scroll) { function NewWindow(mypage, myname, w, h, scroll) {
   var new_win;    var new_win;
   new_win = window.open (mypage, myname, 'status=yes,height='+h+',width='+w+',top=100,left=100,scrollbars=yes');    new_win = window.open (mypage, myname, 'status=yes,height='+h+',width='+w+',top=100,left=100,scrollbars=yes');
   new_win.window.focus();    new_win.window.focus();
} }
   
// copy user // copy user
function copyUser (oElement) { function copyUser (oElement) {
   var indexToCopyId = oElement.options.selectedIndex;    var indexToCopyId = oElement.options.selectedIndex;
   var indexToCopy = oElement.options[indexToCopyId];    var indexToCopy = oElement.options[indexToCopyId];
   var username = indexToCopy.text;    var username = indexToCopy.text;
   var userid = indexToCopy.value;    var userid = indexToCopy.value;
   insert_user ('toshow',username,userid);    insert_user ('toshow',username,userid);
} }
   
// insert user name to list // insert user name to list
function insert_user (oElement,username,userid) { function insert_user (oElement,username,userid) {
   var exists = false;    var exists = false;
   var oDoc = window.document;    var oDoc = window.document;
   var oList = oDoc.getElementById('toshow').options;    var oList = oDoc.getElementById('toshow').options;
   for (var i = 0; i < oList.length; i++) {    for (var i = 0; i < oList.length; i++) {
       if (oList[i].text == username) {        if (oList[i].text == username) {
           exists = true;            exists = true;
           alert("$usersel_txt{'memfound'}");            alert("$usersel_txt{'memfound'}");
       }        }
   }    }
   if (!exists) {    if (!exists) {
       if (oList.length == 1 && oList[0].value == '0' ) {        if (oList.length == 1 && oList[0].value == '0' ) {
           oList[0].value = userid;            oList[0].value = userid;
           oList[0].text = username;            oList[0].text = username;
       } else {        } else {
           var newOption = oDoc.createElement("option");            var newOption = oDoc.createElement("option");
           oDoc.getElementById(oElement).appendChild(newOption);            oDoc.getElementById(oElement).appendChild(newOption);
           newOption.text = username;            newOption.text = username;
           newOption.value = userid;            newOption.value = userid;
       }        }
   }    }
} }
//-->  
</script> </script>
   ~; ~;
   
   if ($action =~ /^im/ && (!@dimmessages && $INFO{'focus'} ne 'bmess') && ($PM_level == 1 || $PM_level == 2 && ($iamadmin || $iamgmod || $iammod) || $PM_level == 3 && ($iamadmin || $iamgmod))) {     if (   $action =~ /^im/sm 
       if (!@dimmessages) {         && ( !@dimmessages && $INFO{'focus'} ne 'bmess' ) 
           if ($action eq 'im') { unlink("$memberdir/$username.msg"); }         && $pm_lev == 1 ) 
           elsif ($action eq 'imoutbox')  { unlink("$memberdir/$username.outbox"); }     { 
           elsif ($action eq 'imstorage') { unlink("$memberdir/$username.imstore"); }         if ( !@dimmessages ) { 
           elsif ($action eq 'imdraft') { unlink("$memberdir/$username.imdraft"); }             if ( $action eq 'im' ) { 
       }                 unlink "$memberdir/$username.msg"; 
   }            }
             elsif ( $action eq 'imoutbox' ) {
   &LoadCensorList;                 unlink "$memberdir/$username.outbox"; 
             }
   # Fix moderator showing in info             elsif ( $action eq 'imstorage' ) { 
   $sender = 'im';                 unlink "$memberdir/$username.imstore"; 
   $acount = 0;             } 
   ## set browser title             elsif ( $action eq 'imdraft' ) { 
   $yytitle = $mycenter_txt{'welcometxt'};                 unlink "$memberdir/$username.imdraft"; 
             }
   ## start new container - left side is menu, right side is content         } 
   my ($display_prof, $display_posts, $display_pm, $tabPMHighlighted, $tabProfHighlighted, $tabNotifyHighlighted);     } 
   
   if ($mycenter_template =~ /({|<)yabb mcmenu(}|>)/g) {     LoadCensorList(); 
       &mcMenu;  
       $newtemplate = 1;     # Fix moderator showing in info 
   }     $sender = 'im'; 
     $acount = 0;
   if ($view eq 'profile' || ($view eq 'mycenter' && ($PM_level == 0 || ($PM_level == 2 && !$iamadmin && !$iamgmod && !$iammod ) || ($PM_level == 3 && !$iamadmin && !$iamgmod)))) {     ## set browser title 
       $display_prof = 'inline';     $yytitle = $mycenter_txt{'welcometxt'}; 
       $tabProfHighlighted = 'windowbg2';  
   } else {     ## start new container - left side is menu, right side is content 
       $display_prof = 'none';     my ( $display_prof, $display_posts, $display_pm, $tabPMHighlighted, 
       $tabProfHighlighted = 'windowbg';         $tabProfHighlighted, $tabNotifyHighlighted ); 
   }  
     if ( $mycenter_template =~ /{yabb mcmenu}/gsm ) {
   if ($view eq 'notify' || $view eq 'favorites' || $view eq 'recentposts') {         mcMenu(); 
       $display_posts = 'inline';         $newtemplate = 1; 
       $tabNotifyHighlighted = 'windowbg2';     } 
   } else {  
       $display_posts = 'none';     if ( 
       $tabNotifyHighlighted = 'windowbg';         $view eq 'profile' 
   }         || ( 
             $view eq 'mycenter' 
   if ($view eq 'pm' || ($view eq 'mycenter' && ($PM_level == 1 || ($PM_level == 2 && ($iamadmin || $iamgmod || $iammod)) || ($PM_level == 3 && ($iamadmin || $iamgmod))))) {             && (   $PM_level == 0 
       $display_pm = 'inline';                 || ( $PM_level == 2 && !$staff ) 
                 || ( $PM_level == 3 && !$iamadmin && !$iamgmod )
       $tabPMHighlighted = 'windowbg2';                 || ( $PM_level == 4 && !$iamadmin && !$iamgmod && !$iamfmod ) ) 
   } else {         ) 
       $display_pm = 'none';       ) 
       $tabPMHighlighted = 'windowbg';     { 
   }         $display_prof       = 'inline'; 
         $tabProfHighlighted = 'windowbg2';
   my $tabWidth = '33%';     } 
   if ($PM_level == 0 || ($PM_level == 2 && !$iamadmin && !$iamgmod && !$iammod ) || ($PM_level == 3 && !$iamadmin && !$iamgmod)) { $tabWidth = '50%'; }     else { 
   $MCViewMenu = '';         $display_prof       = 'none'; 
   $MCPmMenu = '';         $tabProfHighlighted = 'windowbg'; 
   $MCProfMenu = '';     } 
   $MCPostsMenu = '';  
   $MCExtraSmilies = '';     if ( $view eq 'notify' || $view eq 'favorites' || $view eq 'recentposts' ) { 
   $MCContent = '';         $display_posts        = 'inline'; 
         $tabNotifyHighlighted = 'windowbg2';
   if ($newtemplate) {     } 
       $MCViewMenu .= qq~     else { 
       <script language="JavaScript1.2" type="text/javascript">         $display_posts        = 'none'; 
       <!--         $tabNotifyHighlighted = 'windowbg'; 
       function changeToTab(tab) {~;     } 
       if ($PM_level == 1 || ($PM_level == 2 && ($iamadmin || $iamgmod || $iammod)) || ($PM_level == 3 && ($iamadmin || $iamgmod))) {  
           $MCViewMenu .= qq~     if ( 
           document.getElementById('cont_pm').style.display = 'none';         $view eq 'pm' 
           document.getElementById('menu_pm').className = '';~;         || (   $view eq 'mycenter' 
       }             && $pm_lev == 1 ) 
       $MCViewMenu .= qq~       ) 
           document.getElementById('cont_prof').style.display = 'none';     { 
           document.getElementById('menu_prof').className = '';         $display_pm       = 'inline'; 
           document.getElementById('cont_posts').style.display = 'none';         $tabPMHighlighted = 'windowbg2'; 
           document.getElementById('menu_posts').className = '';     } 
           document.getElementById('cont_' + tab).style.display = 'inline';     else { 
           document.getElementById('menu_' + tab).className = 'selected';         $display_pm       = 'none'; 
       }         $tabPMHighlighted = 'windowbg'; 
       //-->     } 
       </script>~;  
   } else {     my $tabWidth = '33%'; 
       $MCViewMenu .= qq~     if (   $PM_level == 0 
       <script language="JavaScript1.2" type="text/javascript">         || ( $PM_level == 2 && !$staff ) 
       <!--         || ( $PM_level == 3 && !$iamadmin && !$iamgmod ) 
       function changeToTab(tab) {~;         || ( $PM_level == 4 && !$iamadmin && !$iamgmod && !$iamfmod ) ) 
       if ($PM_level == 1 || ($PM_level == 2 && ($iamadmin || $iamgmod || $iammod)) || ($PM_level == 3 && ($iamadmin || $iamgmod))) {    {
           $MCViewMenu .= qq~         $tabWidth = '50%'; 
           document.getElementById('cont_pm').style.display = 'none';     } 
           document.getElementById('menu_pm').className = 'windowbg';~;     $MCViewMenu     = q{}; 
       }     $MCPmMenu       = q{}; 
       $MCViewMenu .= qq~     $MCProfMenu     = q{}; 
           document.getElementById('cont_prof').style.display = 'none';     $MCPostsMenu    = q{}; 
           document.getElementById('menu_prof').className = 'windowbg';     $MCExtraSmilies = q{}; 
           document.getElementById('cont_posts').style.display = 'none';     $MCContent      = q{}; 
           document.getElementById('menu_posts').className = 'windowbg';  
           document.getElementById('cont_' + tab).style.display = 'inline';     if ($newtemplate) { 
           document.getElementById('menu_' + tab).className = 'windowbg2';         $MCView_tab = q~ 
       }         <script type="text/javascript"> 
       //-->         function changeToTab(tab) {~; 
       </script>\n~;         if ( $pm_lev == 1 ) { 
       $MCViewMenu .= qq~             $MCView_tab .= q~ 
       <table width="100%" border="0" cellspacing="0" cellpadding="0" align="center" >             document.getElementById('cont_pm').style.display = 'none'; 
       <tr>~;             document.getElementById('menu_pm').className = '';~; 
       if ($PM_level == 0 || ($PM_level == 2 && !$iamadmin && !$iamgmod && !$iammod ) || ($PM_level == 3 && !$iamadmin && !$iamgmod)) {         } 
           $display_prof = 'inline';         $MCView_tab .= q~ 
           $tabProfHighlighted = 'windowbg2';             document.getElementById('cont_prof').style.display = 'none'; 
       }             document.getElementById('menu_prof').className = ''; 
       if ($PM_level == 1 || ($PM_level == 2 && ($iamadmin || $iamgmod || $iammod)) || ($PM_level == 3 && ($iamadmin || $iamgmod))   ) {             document.getElementById('cont_posts').style.display = 'none'; 
           $MCViewMenu .= qq~             document.getElementById('menu_posts').className = ''; 
           <td width="$tabWidth" align="center" valign="middle" class="$tabPMHighlighted" id="menu_pm"><a href="javascript:void(0);" onclick="changeToTab('pm'); return false;">$mc_menus{'messages'}</a></td>~;             document.getElementById('cont_' + tab).style.display = 'inline'; 
       }             document.getElementById('menu_' + tab).className = 'selected'; 
       $MCViewMenu .= qq~         } 
           <td width="$tabWidth" align="center" valign="middle" class="$tabProfHighlighted" id="menu_prof"><a href="javascript:void(0);" onclick="changeToTab('prof'); return false;">$mc_menus{'profile'}</a></td>         </script>~; 
           <td width="$tabWidth" align="center" valign="middle" class="$tabNotifyHighlighted" id="menu_posts"><a href="javascript:void(0);" onclick="changeToTab('posts'); return false;">$mc_menus{'posts'}</a></td>     } 
       </tr>     else { 
       </table>\n~;         $MCView_tab = q~ 
   }         <script type="text/javascript"> 
         function changeToTab(tab) {~;
         if ( $pm_lev == 1 ) {
             $MCView_tab .= q~
             document.getElementById('cont_pm').style.display = 'none';
             document.getElementById('menu_pm').className = 'windowbg';~;
         }
         $MCView_tab .= qq~
             document.getElementById('cont_prof').style.display = 'none';
             document.getElementById('menu_prof').className = 'windowbg';
             document.getElementById('cont_posts').style.display = 'none';
             document.getElementById('menu_posts').className = 'windowbg';
             document.getElementById('cont_' + tab).style.display = 'inline';
             document.getElementById('menu_' + tab).className = 'windowbg2';
         }
         </script>\n~;
         if (   $PM_level == 0
             || ( $PM_level == 2 && !$staff )
             || ( $PM_level == 3 && !$iamadmin && !$iamgmod )
             || ( $PM_level == 4 && !$iamadmin && !$iamgmod && !$iamfmod ) )
         {
             $display_prof       = 'inline';
             $tabProfHighlighted = 'windowbg2';
         }
         if ( $pm_lev == 1 ) {
             $MCViewMenu_mess = $my_MCViewMenu_mess;
             $MCViewMenu_mess =~ s/{yabb tabPMHighlighted}/$tabPMHighlighted/sm;
             $MCViewMenu_mess =~
               s/{yabb mc_menus_messages}/$mc_menus{'messages'}/sm;
         }
         $MCViewMenu .= $my_MCViewMenu;
         $MCViewMenu =~ s/{yabb MCView_tab}/$MCView_tab/sm;
         $MCViewMenu =~ s/{yabb MCViewMenu_mess}/$MCViewMenu_mess/sm;
         $MCViewMenu =~ s/{yabb tabWidth}/$tabWidth/gsm;
         $MCViewMenu =~ s/{yabb tabProfHighlighted}/$tabProfHighlighted/sm;
         $MCViewMenu =~ s/{yabb tabNotifyHighlighted}/$tabNotifyHighlighted/sm;
         $MCViewMenu =~ s/{yabb mc_menus_profile}/$mc_menus{'profile'}/sm;
         $MCViewMenu =~ s/{yabb mc_menus_posts}/$mc_menus{'posts'}/sm;
     }
   
     $MCViewMenu .= $MCView_tab;
   
## start Profile div ## start Profile div
   $MCProfMenu = qq~  
   <div id="cont_prof" style="display: $display_prof">     ## links for profile pages. SID is now cloaked and controls whether or not 
   <table id="prof"  width="100%" align="center" class="windowbg2" cellpadding="4">     ## the action goes to authenticate or straight to the page. 
       <tr>     ## The trick is to use $page to pass the intended page through and switch over on 
           <td style="text-align: left;">~;     ## positive id. 
     if ( $page && $page ne $action ) { $action = $page; }
   ## links for profile pages. SID is now cloaked and controls whether or not     my $profileLink; 
   ## the action goes to authenticate or straight to the page.     my $sid      = $INFO{'sid'}; 
   ## The trick is to use $page to pass the intended page through and switch over on     my $thisLink = q{}; 
   ## positive id.     my $sidLink  = q{}; 
   if ($page && $page ne $action)  { $action = $page; }    if ( !$sid ) { $sid     = $FORM{'sid'}; }
   my $profileLink;     if ($sid)    { $sidLink = ";sid=$sid"; } 
   my $sid = $INFO{'sid'};  
   my $thisLink = '';     if   ( !$sid ) { $profileLink = 'action=profileCheck;page='; } 
   my $sidLink = '';     else           { $profileLink = 'action='; } 
   if (!$sid) {$sid = $FORM{'sid'}; }  
   if ($sid) { $sidLink = ";sid=$sid"; }     $thisLink_a = 'action=myviewprofile;username=' . $useraccount{$username}; 
   
   if (!$sid) { $profileLink = 'action=profileCheck;page='; }     $thisLink_b = 
   else {$profileLink = 'action=';}       $profileLink . 'myprofile;username=' . $useraccount{$username} . $sidLink; 
   $thisLink = 'action=myviewprofile;username=' . $useraccount{$username};  
   $MCProfMenu .= qq~     $thisLink_c = 
   <span class="nav"><b><a href="$scripturl?$thisLink">$inmes_txt{'viewprofile'}</a></b></span><br /><br />~;         $profileLink 
       . 'myprofileContacts;username=' 
   $thisLink = $profileLink . 'myprofile;username=' . $useraccount{$username} . $sidLink;       . $useraccount{$username} 
   $MCProfMenu .= qq~       . $sidLink; 
   <span class="nav"><b><a href="$scripturl?$thisLink">$profile_txt{'79'}</a></b></span><br />~;  
     $thisLink_d =
   $thisLink = $profileLink . 'myprofileContacts;username=' . $useraccount{$username} . $sidLink;         $profileLink 
   $MCProfMenu .= qq~       . 'myprofileOptions;username=' 
   <span class="nav"><b><a href="$scripturl?$thisLink">$profile_txt{'819'}</a></b></span><br />~;       . $useraccount{$username} 
       . $sidLink;
   $thisLink = $profileLink . 'myprofileOptions;username=' . $useraccount{$username} . $sidLink;  
   $MCProfMenu .= qq~     if ($buddyListEnabled) { 
   <span class="nav"><b><a href="$scripturl?$thisLink">$profile_txt{'818'}</a></b></span><br />~;         $thisLink_e = 
             $profileLink
   if ($buddyListEnabled) {           . 'myprofileBuddy;username=' 
       $thisLink = $profileLink . 'myprofileBuddy;username=' . $useraccount{$username} . $sidLink;           . $useraccount{$username} 
       $MCProfMenu .= qq~           . $sidLink; 
       <span class="nav"><b><a href="$scripturl?$thisLink">$profile_buddy_list{'buddylist'}</a></b></span><br />~;         $my_buddylink = $my_thislink_buddy; 
   }         $my_buddylink =~ s/{yabb thisLink_e}/$thisLink_e/sm; 
     }
   if ($PM_level == 1 || ($PM_level == 2 && ($iamadmin || $iamgmod || $iammod)) || ($PM_level == 3 && ($iamadmin || $iamgmod))) {  
       $thisLink = $profileLink . 'myprofileIM;username=' . $useraccount{$username} . $sidLink;     if ( $pm_lev == 1 ) { 
       $MCProfMenu .= qq~         $thisLink_f = 
       <span class="nav"><b><a href="$scripturl?$thisLink">$inmes_txt{'765'}</a></b></span>             $profileLink 
       <br />           . 'myprofileIM;username=' 
       ~;           . $useraccount{$username} 
   }           . $sidLink; 
         $my_IMpref = $my_thislink_impref;
   if ($iamadmin || ($iamgmod && $allow_gmod_profile && $gmod_access2{'profileAdmin'} eq 'on')) {         $my_IMpref =~ s/{yabb thisLink_f}/$thisLink_f/sm; 
       $thisLink = $profileLink . 'myprofileAdmin;username=' . $useraccount{$username} . $sidLink;     } 
       $MCProfMenu .= qq~  
           <span class="nav"><b><a href="$scripturl?$thisLink">$profile_txt{'820'}</a></b></span>     if ( 
           <br />         $iamadmin 
       ~;         || (   $iamgmod 
   }             && $allow_gmod_profile 
             && $gmod_access2{'profileAdmin'} eq 'on' )
   $MCProfMenu .= qq~       ) 
       </td></tr>     { 
   </table>         $thisLink_g = 
   </div>             $profileLink 
   ~;           . 'myprofileAdmin;username=' 
           . $useraccount{$username}
           . $sidLink;
         $my_adminlink = $my_thisLink_admin;
         $my_adminlink =~ s/{yabb thisLink_g}/$thisLink_g/sm;
     }
   
     $MCProfMenu = $my_MCProfMenu;
     $MCProfMenu =~ s/{yabb display_prof}/$display_prof/sm;
     $MCProfMenu =~ s/{yabb thisLink_a}/$thisLink_a/sm;
     $MCProfMenu =~ s/{yabb thisLink_b}/$thisLink_b/sm;
     $MCProfMenu =~ s/{yabb thisLink_c}/$thisLink_c/sm;
     $MCProfMenu =~ s/{yabb thisLink_d}/$thisLink_d/sm;
     $MCProfMenu =~ s/{yabb my_buddylink}/$my_buddylink/sm;
     $MCProfMenu =~ s/{yabb my_IMpref}/$my_IMpref/sm;
     $MCProfMenu =~ s/{yabb my_adminlink}/$my_adminlink/sm;
## end Profile div ## end Profile div
   
## start Posts div ## start Posts div
   $MCPostsMenu = qq~     if ( ${ $uid . $username }{'postcount'} > 0 && $maxrecentdisplay > 0 ) { 
   <div id="cont_posts" style="display: $display_posts">         $MCPost_count = $my_MCPost_count; 
   <table id="posts" width="100%" align="center" class="windowbg2" cellpadding="4">         $MCPost_count =~ s/{yabb username}/$useraccount{$username}/sm; 
       <tr><td class="windowbg2">         my ( $x, $y ) = ( int( $maxrecentdisplay / 5 ), 0 ); 
           <span class="nav"><b><a href="$scripturl?action=shownotify">$inmes_txt{'viewnotify'}</a></b></span><br />         if ($x) { 
           <span class="nav"><b><a href="$scripturl?action=favorites">$inmes_txt{'viewfavs'}</a></b></span><br />             foreach my $i ( 1 .. 5 ) { 
   ~;                 $y = $i * $x; 
   if (${$uid.$username}{'postcount'} > 0 && $maxrecentdisplay > 0) {                 $MCPost_recent .= qq~ 
       $MCPostsMenu .= qq~             <option value="$y">$y</option>~; 
       <br /><br />             } 
       <form action="$scripturl?action=myusersrecentposts;username=$useraccount{$username}" method="post" style="display: inline;">         } 
       <span class="small">$inmes_txt{'viewrecentposts'} <select name="viewscount" size="1">~;         if ( $maxrecentdisplay > $y ) { 
             $MCPost_recent .= qq~
       my ($x,$y) = (int($maxrecentdisplay/5),0);         <option value="$maxrecentdisplay">$maxrecentdisplay</option>~; 
       if ($x) {         } 
           for (my $i = 1; $i <= 5; $i++) {  
               $y = $i * $x;         $MCPost_recent .= qq~ 
               $MCPostsMenu .= qq~         </select> $inmes_txt{'viewrecentposts2'} 
           <option value="$y">$y</option>~;         <input type="submit" value="$inmes_txt{'goviewrecent'}" class="button" /></span> 
           }         </form> 
       }     ~; 
       $MCPostsMenu .= qq~     } 
       <option value="$maxrecentdisplay">$maxrecentdisplay</option>~ if $maxrecentdisplay > $y;     $MCPostsMenu = $my_MCPostsMenu; 
     $MCPostsMenu =~ s/{yabb display_posts}/$display_posts/sm;
       $MCPostsMenu .= qq~     $MCPostsMenu =~ s/{yabb MCPost_count}/$MCPost_count/sm; 
       </select> $inmes_txt{'viewrecentposts2'}     $MCPostsMenu =~ s/{yabb MCPost_recent}/$MCPost_recent/sm; 
       <input type="submit" value="$inmes_txt{'goviewrecent'}" class="button" /></span>  
       </form>  
   ~;  
   }  
   $MCPostsMenu .= qq~  
       </td></tr>  
   </table>  
   </div>  
   ~;  
## end Posts div ## end Posts div
   
   if (!$replyguest) {    if ( !$replyguest ) {
       if ($view eq 'pm' && $action ne 'imsend' && $action ne 'imsend2') {        if ( $view eq 'pm' && $action ne 'imsend' && $action ne 'imsend2' ) {
           my $imstoreFolder;            my $imstoreFolder;
           if ($action eq 'imstorage') { $imstoreFolder = ";viewfolder=$INFO{'viewfolder'}"; }             if ( $action eq 'imstorage' ) { 
           $MCGlobalFormStart .= qq~                 $imstoreFolder = ";viewfolder=$INFO{'viewfolder'}"; 
           <form action="$scripturl?action=deletemultimessages;caller=$callerid$imstoreFolder" method="post" name="searchform" enctype="application/x-www-form-urlencoded">             } 
           ~;             $MCGlobalFormStart .= qq~ 
             <form action="$scripturl?action=deletemultimessages;caller=$callerid$imstoreFolder" method="post" name="searchform" enctype="application/x-www-form-urlencoded" accept-charset="$yymycharset">
       } elsif ($view eq 'pm') {             ~; 
           $MCGlobalFormStart .= qq~<form action="$scripturl?action=$destination" method="post" name="postmodify" id="postmodify" enctype="application/x-www-form-urlencoded" onsubmit="~;         } 
           if (!${$uid.$toshow}{'realname'}) { $MCGlobalFormStart .= qq~selectNames(); ~; }         elsif ( $view eq 'pm' ) { 
           $MCGlobalFormStart .= qq~if(!checkForm(this)) { return false; } else { return submitproc(); }">~;             my $entype = q{}; 
             my $snames = q{};
           ## add smilies box  
           ## smilies             $allowAttachIM ||= 0; 
           $MCPmMenu .= qq~             $allowGroups = GroupPerms( $allowAttachIM, $pmAttachGroups ); 
       <script language="JavaScript1.2" src="$yyhtml_root/ubbc.js" type="text/javascript"></script>             if ( $allowAttachIM && $allowGroups ) { 
       <script language="JavaScript1.2" type="text/javascript">                 $entype = "multipart/form-data"; 
       <!--~;             } 
             else {
           if ($smiliestyle == 1) { $smiliewinlink = qq~$scripturl?action=smilieput~; }                 $entype = "application/x-www-form-urlencoded"; 
           else { $smiliewinlink = qq~$scripturl?action=smilieindex~; }            }
             if ( !${ $uid . $toshow }{'realname'} ) {
           $MCPmMenu .= qq~                 $snames = q~selectNames(); ~; 
       function smiliewin() {             } 
           window.open("$smiliewinlink", 'list', 'width=$winwidth, height=$winheight, scrollbars=yes');             $MCGlobalFormStart .= qq~<form action="$scripturl?action=$destination" method="post" name="postmodify" id="postmodify" enctype="multipart/form-data" onsubmit="${snames}if(!checkForm(this)) { return false; } else { return submitproc(); }">~; 
       }        }
       //-->     } 
       </script>\n~;     else { 
         $MCGlobalFormStart .=
           if ($showadded == 2 || $showsmdir == 2) {  qq~<form action="$scripturl?action=$destination" method="post" name="postmodify" id="postmodify" enctype="application/x-www-form-urlencoded">~; 
               $MCExtraSmilies .= qq~     } 
               <br />  
               <script language="JavaScript1.2" type="text/javascript">     ################################################### 
               <!--     ########  right side container starts here 
               function Smiliextra() {     ################################################### 
                   AddTxt=smiliecode[document.getElementById('smiliextra_list').value];     if ( $view eq 'mycenter' ) { 
                   AddText(AddTxt);         LoadUserDisplay($username); 
               }  
               ~;         my $onOffStatus = 
               $smilieslist = '';           ${ $uid . $username }{'offlinestatus'} eq 'away' 
               $smilie_url_array = '';           ? $mycenter_txt{'onoffstatusaway'} 
               $smilie_code_array = '';           : $mycenter_txt{'onoffstatuson'}; 
               $i = 0;  
               if ($showadded == 2) {         my $stealthstatus = q{}; 
                   while ($SmilieURL[$i]) {        if ( ( $iamadmin || $iamgmod ) && $enable_MCstatusStealth ) {
                       $smilieslist .= qq~    document.write('<option value="$i"~ . ($SmilieDescription[$i] eq $showinbox ? ' selected="selected"' : '') . qq~>$SmilieDescription[$i]</option>');\n~;             $stealthstatus_on = $mycenter_txt{'stealth_off'}; 
                       if ($SmilieURL[$i] =~ /\//i) { $tmpurl = $SmilieURL[$i]; }             if ( ${ $uid . $username }{'stealth'} ) { 
                       else { $tmpurl = qq~$defaultimagesdir/$SmilieURL[$i]~; }                 $stealthstatus_on = $mycenter_txt{'stealth_on'}; 
                       $smilie_url_array .= qq~"$tmpurl", ~;             } 
                       $tmpcode = $SmilieCode[$i];             $stealthstatus = $my_stealthstatus; 
                       $tmpcode =~ s/\&quot;/"+'"'+"/g;    # "'             $stealthstatus =~ s/{yabb stealthstatus}/$stealthstatus_on/sm; 
                       &FromHTML($tmpcode);         } 
                       $tmpcode =~ s/&#36;/\$/g;  
                       $tmpcode =~ s/&#64;/\@/g;         my $memberinfo = "$memberinfo{$username}$addmembergroup{$username}"; 
                       $smilie_code_array .= qq~" $tmpcode", ~;         my $userOnline = userOnLineStatus($username) . q~<br />~; 
                       $i++;         my $template_postinfo = 
                   }  qq~$mycenter_txt{'posts'}: <a href="$scripturl?action=myusersrecentposts;username=$useraccount{$username}" title="$mycenter_txt{'mylastposts'}">~ 
               }           . NumberFormat( ${ $uid . $username }{'postcount'} ) 
               if ($showsmdir == 2) {           . q~</a><br />~; 
                   opendir(DIR, "$smiliesdir");         my $template_age; 
                   @contents = readdir(DIR);         if (   ${ $uid . $username }{'bday'} 
                   closedir(DIR);             && $showuserage 
             && ( !$showage || !${ $uid . $username }{'hideage'} ) )
                   foreach $line (sort { uc($a) cmp uc($b) } @contents) {         { 
                       ($name, $extension) = split(/\./, $line);             CalcAge( $username, 'calc' ); 
                       if ($extension =~ /gif/i || $extension =~ /jpg/i || $extension =~ /jpeg/i || $extension =~ /png/i) {             $template_age = qq~$profile_txt{'420'}: $age<br />~; 
                           if ($line !~ /banner/i) {         } 
                               $smilieslist .= qq~    document.write('<option value="$i"~ . ($name eq $showinbox ? ' selected="selected"' : '') . qq~>$name</option>');\n~;         my $template_regdate; 
                               $smilie_url_array .= qq~"$smiliesurl/$line", ~;         if ( $showregdate && ${ $uid . $username }{'regtime'} ) { 
                               $smilie_code_array .= qq~" [smiley=$line]", ~;             $dr_regdate = timeformat( ${ $uid . $username }{'regtime'}, 1 ); 
                               $i++;             $dr_regdate = dtonly($dr_regdate); 
                           }             $dr_regdate =~ s/(.*)(, 1?[0-9]):[0-9][0-9].*/$1/xsm; 
                       }             $template_regdate = qq~$profile_txt{'regdate'} $dr_regdate<br />~; 
                   }        }
               }         my $userlocation; 
               $smilie_url_array  .= qq~""~;         if ( ${ $uid . $username }{'location'} ) { 
               $smilie_code_array .= qq~""~;             $userlocation = 
                 qq~$mycenter_txt{'location'}: ~
               $MCExtraSmilies .= qq~               . ${ $uid . $username }{'location'} 
               smilieurl = new Array($smilie_url_array);               . q~<br />~; 
               smiliecode = new Array($smilie_code_array);         } 
               document.write('<table class="bordercolor" height="90" width="120" border="0" cellpadding="2" cellspacing="1" align="center"><tr>');  
               document.write('<td height="15" align="center" valign="middle" class="titlebg"><span class="small"><b>$post_smiltxt{'1'}</b></span></td>');         $mctitle = $mycenter_txt{'welcometxt'}; 
               document.write('</tr><tr>');  
               document.write('<td height="20" align="center" valign="top" class="windowbg2"><select name="smiliextra_list" id="smiliextra_list" onchange="document.images.smiliextra_image.src=smilieurl[document.getElementById(\\'smiliextra_list\\').value]" style="width:114px; font-size:7pt;">');         $myprofileblock =~ s/{yabb userlink}/$link{$username}/gsm; 
               $smilieslist         $myprofileblock =~ s/{yabb memberinfo}/$memberinfo/gsm; 
               document.write('</select></td>');         $myprofileblock =~ s/{yabb stars}/$memberstar{$username}/gsm; 
               document.write('</tr><tr>');         $myprofileblock =~ s/{yabb useronline}/$userOnline/gsm; 
               document.write('<td height="70" align="center" valign="middle" class="windowbg2"><img name="smiliextra_image" src="'+smilieurl[0]+'" alt="" border="0" onclick="javascript: Smiliextra();" style="cursor: pointer;"></td>');         $myprofileblock =~ 
               document.write('</tr><tr>');           s/{yabb userpic}/${$uid.$username}{'userpic'}/gsm; 
               document.write('<td height="15" align="center" valign="middle" class="windowbg2"><span class="small"><a href="javascript: smiliewin();">$post_smiltxt{'17'}</a></span></td>');         $myprofileblock =~ 
               document.write('</tr></table>');           s/{yabb usertext}/${$uid.$username}{'usertext'}/gsm; 
               document.images.smiliextra_image.src = smilieurl[document.getElementById('smiliextra_list').value];         $myprofileblock =~ s/{yabb postinfo}/$template_postinfo/gsm; 
               //-->         $myprofileblock =~ s/{yabb location}/$userlocation/gsm; 
               </script>         $myprofileblock =~ 
               <br />           s/{yabb gender}/${$uid.$username}{'gender'}/gsm; 
               ~;         $myprofileblock =~ s/{yabb zodiac}/${$uid.$username}{'zodiac'}/gsm; 
           }         $myprofileblock =~ s/{yabb age}/$template_age/gsm; 
       }         $myprofileblock =~ s/{yabb regdate}/$template_regdate/gsm; 
   
   } else {  ## Mod Hook myprofileblock ## 
       $MCGlobalFormStart .= qq~<form action="$scripturl?action=$destination" method="post" name="postmodify" id="postmodify" enctype="application/x-www-form-urlencoded">~;         $myprofileblock =~ s/{yabb .+?}//gsm; 
   }  
         if ($buddyListEnabled) {
   ###################################################             if ( ${ $uid . $username }{'buddylist'} ) { 
   ########  right side container starts here                 LoadBuddyList(); 
   ###################################################                 $buddiesCurrentStatus = 
   if ($view eq 'mycenter') {  qq~$mycenter_txt{'buddylisttitle'}:<br />$buddiesCurrentStatus~; 
       &LoadUserDisplay($username);             } 
             else {
       my $onOffStatus = ${$uid.$username}{'offlinestatus'} eq "away" ? $mycenter_txt{'onoffstatusaway'} : $mycenter_txt{'onoffstatuson'};                 $buddiesCurrentStatus = $mycenter_txt{'buddylistnone'}; 
             }
       my $stealthstatus = '';         } 
       if (($iamadmin || $iamgmod) && $enable_MCstatusStealth) {        else {
           $stealthstatus = $mycenter_txt{'stealth_off'};             $buddiesCurrentStatus = q~&nbsp;~; 
           if (${$uid.$username}{'stealth'}) { $stealthstatus = $mycenter_txt{'stealth_on'}; }        }
           $stealthstatus = qq~        <tr>  
                   <td class="windowbg2">$mycenter_txt{'stealth'}</td>         $MCContent .= $my_MCContent; 
                   <td class="windowbg2">'$stealthstatus'</td>         $MCContent =~ s/{yabb myprofileblock}/$myprofileblock/sm; 
               </tr>~;         $MCContent =~ s/{yabb buddiesCurrentStatus}/$buddiesCurrentStatus/sm; 
       }         $MCContent =~ s/{yabb onOffStatus}/$onOffStatus/sm; 
         $MCContent =~ s/{yabb stealthstatus}/$stealthstatus/sm;
       my $memberinfo = "$memberinfo{$username}$addmembergroup{$username}";  
       my $userOnline = &userOnLineStatus($username) . "<br />";         ############### sending pm ####################### 
       my $template_postinfo = qq~$mycenter_txt{'posts'}: ~ . &NumberFormat(${$uid.$username}{'postcount'}) . qq~<br />~;     } 
       my $userlocation;     elsif ( $view eq 'pm' && ( $action eq 'imsend' || $action eq 'imsend2' ) ) { 
       if (${$uid.$username}{'location'}) {         my $sendTitle = $inmes_txt{'sendmess'}; 
           $userlocation = ${$uid.$username}{'location'} . "<br />";         if ($sendBMess) { $sendTitle = $inmes_txt{'sendbroadmess'}; } 
       }         $MCContent .= $my_MCContent_PM; 
         $MCContent =~ s/{yabb MCGlobalFormStart}/$MCGlobalFormStart/sm;
       $mctitle = $mycenter_txt{'welcometxt'};         $MCContent =~ s/{yabb imsend}/$imsend/sm; 
       #################################         $MCGlobalFormStart = q{}; 
       $myprofileblock =~ s/({|<)yabb userlink(}|>)/$link{$username}/g;  
       $myprofileblock =~ s/({|<)yabb memberinfo(}|>)/$memberinfo/g;         # inbox/outbox/ storage/draft  viewing 
       $myprofileblock =~ s/({|<)yabb stars(}|>)/$memberstar{$username}/g;     } 
       $myprofileblock =~ s/({|<)yabb useronline(}|>)/$userOnline/g;     elsif ( 
       $myprofileblock =~ s/({|<)yabb userpic(}|>)/${$uid.$username}{'userpic'}/g;         $view eq 'pm' 
       $myprofileblock =~ s/({|<)yabb usertext(}|>)/${$uid.$username}{'usertext'}/g;         && (   $action eq 'im' 
       $myprofileblock =~ s/({|<)yabb postinfo(}|>)/$template_postinfo/g;             || $action eq 'imoutbox' 
       $myprofileblock =~ s/({|<)yabb location(}|>)/$userlocation/g;             || $action eq 'imstorage' 
       $myprofileblock =~ s/({|<)yabb gender(}|>)/${$uid.$username}{'gender'}/g;             || $action eq 'imdraft' ) 
       ################################       ) 
       $myprofileblock =~ s/({|<)yabb .+?(}|>)//g;     { 
         drawPMView();
       if ($buddyListEnabled) {  
           $buddiesCurrentStatus;     } 
           if (${$uid.$username}{'buddylist'}) {    elsif ( $view eq 'pm' && $action eq 'imshow' ) {
               &LoadBuddyList;         $showIM = q{}; 
               $buddiesCurrentStatus = qq~$mycenter_txt{'buddylisttitle'}:<br />$buddiesCurrentStatus~;         if ( $INFO{'id'} eq 'all' ) { 
           } else {             my $BC; 
               $buddiesCurrentStatus = $mycenter_txt{'buddylistnone'};             foreach (@dimmessages) { 
           }                 $showmessid = ( split /\|/xsm, $_ )[0]; 
       } else {                 $showIM .= DoShowIM($showmessid); 
           $buddiesCurrentStatus = qq~&nbsp;~;                 if ( $INFO{'caller'} == 5 
       }                     && !${$username}{ 'PMbcRead' . $showmessid } ) 
                 {
       $MCContent .= qq~                     ${$username}{'PMbcRead'} .= 
       <table width="100%" border="0" cellspacing="1" cellpadding="5" align="right">                       ${$username}{'PMbcRead'} ? ",$showmessid" : $showmessid; 
               <tr>                     $BCnewMessage--; 
                   <td width="33%" class="windowbg2" valign="top">                     $BC = 1; 
                       $myprofileblock                 } 
                   </td>             } 
                   <td width="67%" class="windowbg2" valign="top">             if ($BC) { buildIMS( $username, 'update' ); } 
                       $buddiesCurrentStatus         } 
                   </td>         else { 
               </tr>             $showIM = DoShowIM( $INFO{'id'} ); 
               <tr>             if ( $INFO{'caller'} == 5 
                   <td colspan="2" class="windowbg">                 && !${$username}{ 'PMbcRead' . $INFO{'id'} } ) 
                       $mycenter_txt{'currentsettings'}             { 
                   </td>                 ${$username}{'PMbcRead'} .= 
               </tr>                   ${$username}{'PMbcRead'} ? ",$INFO{'id'}" : $INFO{'id'}; 
               <tr>                 buildIMS( $username, 'update' ); 
                   <td class="windowbg2">                 $BCnewMessage--; 
                       $mycenter_txt{'onoffstatus'}<br />             } 
                   </td>         } 
                   <td class="windowbg2">         $MCContent .= $showIM; 
     }
       '$onOffStatus'</td>     elsif ( $view eq 'pm' && $action eq 'pmsearch' ) { 
               </tr>         spam_protection(); 
       $stealthstatus         $yysearchmain = q{}; 
       </table>         require Sources::Search; 
       ~;         pmsearch(); 
         $MCContent .= $yysearchmain;
   ############### sending pm #######################         $mctitle = "$pm_search{'desc'}"; 
   } elsif ($view eq 'pm' && ($action eq 'imsend' || $action eq 'imsend2')) {     } 
       my $sendTitle = $inmes_txt{'sendmess'};     elsif ( $view eq 'profile' ) { 
       if ($sendBMess) { $sendTitle = $inmes_txt{'sendbroadmess'}; }         ## if user has had to go via id check, this restores their intended page 
       $MCContent .= qq~         $page = $INFO{'page'}; 
       $MCGlobalFormStart         if ( $page && $action ne $page ) { $action = $page; } 
       <table width="100%" border="0" cellspacing="0" cellpadding="5">         require Sources::Profile; 
           $imsend         if    ( $action eq 'myprofileIM' )        { ModifyProfileIM(); } 
       </table>         elsif ( $action eq 'myprofileIM2' )       { ModifyProfileIM2(); } 
       </form>~;         elsif ( $action eq 'myprofile' )          { ModifyProfile(); } 
       $MCGlobalFormStart = '';         elsif ( $action eq 'myprofile2' )         { ModifyProfile2(); } 
         elsif ( $action eq 'myprofileContacts' )  { ModifyProfileContacts(); }
   # inbox/outbox/ storage/draft  viewing         elsif ( $action eq 'myprofileContacts2' ) { ModifyProfileContacts2(); } 
   } elsif ($view eq 'pm' && ($action eq 'im' || $action eq 'imoutbox' || $action eq 'imstorage' || $action eq 'imdraft')) {         elsif ( $action eq 'myprofileOptions' )   { ModifyProfileOptions(); } 
       &drawPMView;         elsif ( $action eq 'myprofileOptions2' )  { ModifyProfileOptions2(); } 
         elsif ( $action eq 'myprofileBuddy' )     { ModifyProfileBuddy(); }
   } elsif ($view eq 'pm' && $action eq 'imshow') {         elsif ( $action eq 'myprofileBuddy2' )    { ModifyProfileBuddy2(); } 
       $showIM = '';         elsif ( $action eq 'myviewprofile' )      { ViewProfile(); } 
       if ($INFO{'id'} eq 'all') {         elsif ( $action eq 'myprofileAdmin' )     { ModifyProfileAdmin(); } 
           my $BC;         elsif ( $action eq 'myprofileAdmin2' )    { ModifyProfileAdmin2(); } 
           foreach (@dimmessages) {         $MCContent .= $showProfile; 
               $showmessid = (split /\|/, $_)[0];     } 
               $showIM .= &DoShowIM($showmessid);     elsif ( $view eq 'notify' ) { 
               if ($INFO{'caller'} == 5 && !${$username}{'PMbcRead' . $showmessid}) {         require Sources::Notify; 
                   ${$username}{'PMbcRead'} .= ${$username}{'PMbcRead'} ? ",$showmessid" : $showmessid;         if ( $action eq 'shownotify' ) { ShowNotifications(); } 
                   $BCnewMessage--; $BC = 1;         elsif ( $action eq 'boardnotify2' ) { 
               }             BoardNotify2(); 
           }             ShowNotifications(); 
           if ($BC) { &buildIMS($username, 'update'); }        }
       } else {         elsif ( $action eq 'notify4' ) { Notify4(); } 
           $showIM = &DoShowIM($INFO{'id'});         $MCContent .= $showNotifications; 
           if ($INFO{'caller'} == 5 && !${$username}{'PMbcRead' . $INFO{'id'}}) {     } 
               ${$username}{'PMbcRead'} .= ${$username}{'PMbcRead'} ? ",$INFO{'id'}" : $INFO{'id'};     elsif ( $view eq 'recentposts' ) { 
               &buildIMS($username, 'update');         require Sources::Profile; 
               $BCnewMessage--;         usersrecentposts(); 
           }         $MCContent .= $showProfile; 
       }    }
     elsif ( $view eq 'favorites' ) {
       $MCContent .= qq~         require Sources::Favorites; 
           $showIM         Favorites(); 
       <br />         $MCContent .= $showFavorites; 
       ~;     } 
   
   } elsif ($view eq 'pm' && $action eq 'pmsearch') {     ## start PM div 
       &spam_protection;     if ( $pm_lev == 1 ) { 
       $yysearchmain = '';         if ( 
       require "$sourcedir/Search.pl";                ( $PMenableBm_level == 1 && $staff ) 
       &pmsearch;             || ( $PMenableBm_level == 2 && ( $iamadmin || $iamgmod ) ) 
       $MCContent .= qq~             || ( $PMenableBm_level == 4 
           $yysearchmain                 && ( $iamadmin || $iamgmod || $iamfmod ) ) 
       <br />             || ( $PMenableBm_level == 3 && $iamadmin ) 
       ~;           ) 
       $mctitle = "$pm_search{'desc'}";         { 
             $MCPmMenu_bm = $my_MCPmMenu_bm;
   } elsif ($view eq 'profile') {         } 
       ## if user has had to go via id check, this restores their intended page  
       $page = $INFO{'page'};         my $inboxNewCount = 
       if($page && $action ne $page) { $action = $page; }           ${$username}{'PMimnewcount'} 
       require "$sourcedir/Profile.pl";           ? qq~<span class="NewLinks">, <a href="$scripturl?action=imshow;caller=1;id=-1">${$username}{'PMimnewcount'} $inmes_txt{'new'}</a></span>~ 
       if ($action eq 'myprofileIM') { &ModifyProfileIM; }           : q{}; 
       elsif ($action eq 'myprofileIM2') { &ModifyProfileIM2; }  
       elsif ($action eq 'myprofile') { &ModifyProfile; }         if ( $PMenableBm_level > 0 
       elsif ($action eq 'myprofile2') { &ModifyProfile2; }             || ( $PMenableGuestButton == 1 && ( $iamadmin || $iamgmod ) ) ) 
       elsif ($action eq 'myprofileContacts') { &ModifyProfileContacts; }         { 
       elsif ($action eq 'myprofileContacts2') { &ModifyProfileContacts2; }             $inboxNewCount_bm = 
       elsif ($action eq 'myprofileOptions') { &ModifyProfileOptions; }               $BCnewMessage 
       elsif ($action eq 'myprofileOptions2') { &ModifyProfileOptions2; }               ? qq~ <span class='NewLinks'>, <a href="$scripturl?action=im;focus=bmess">$BCnewMessage $inmes_txt{'new'}</a></span>~ 
       elsif ($action eq 'myprofileBuddy') { &ModifyProfileBuddy; }               : q{}; 
       elsif ($action eq 'myprofileBuddy2') { &ModifyProfileBuddy2; }             $MCPmMenu_bmbox = $mypmmenu_bmbox; 
       elsif ($action eq 'myviewprofile') { &ViewProfile; }             $MCPmMenu_bmbox =~ s/{yabb BCCount}/$BCCount/sm; 
       elsif ($action eq 'myprofileAdmin') { &ModifyProfileAdmin; }             $MCPmMenu_bmbox =~ s/{yabb inboxNewCount_bm}/$inboxNewCount_bm/sm; 
       elsif ($action eq 'myprofileAdmin2') { &ModifyProfileAdmin2; }        }
       $MCContent .= qq~  
           $showProfile         my @folderCount = split /\|/xsm, ${$username}{'PMfoldersCount'}; 
       <br />         $foldercount0 = $folderCount[0] || 0; 
       ~;         $foldercount1 = $folderCount[1] || 0; 
   
   } elsif ($view eq 'notify') {         ## if there are some folders to show under storage 
       require "$sourcedir/Notify.pl";         ## split the list down and show it with link to each folder 
       if ($action eq 'shownotify') { &ShowNotifications; }         $enable_storefolders ||= 0; 
       elsif ($action eq 'boardnotify2') { &BoardNotify2; &ShowNotifications; }         if ( $enable_storefolders > 0 ) { 
       elsif ($action eq 'notify4') { &Notify4; }             my $storeFoldersTotal = 0; 
       $MCContent .= qq~$showNotifications             my $DelAdFolder       = 0; 
       <br />             if ( ${$username}{'PMfolders'} ) { 
       ~;                 my $x = 2; 
                 foreach
   } elsif ($view eq 'recentposts') {                   my $storefolder ( split /\|/xsm, ${$username}{'PMfolders'} ) 
       require "$sourcedir/Profile.pl";                 { 
       &usersrecentposts;                     if ( $storefolder ne 'in' && $storefolder ne 'out' ) { 
       $MCContent .= qq~$showProfile                         $storeFoldersTotal++; 
       <br />                         if ( $storeFoldersTotal > 0 && $folderCount[$x] == 0 ) { 
       ~;                             $DelAdFolder      = 1; 
                             $MCPmMenuTemp_chk = qq~
   } elsif ($view eq 'favorites'){                                 <input type="checkbox" name="delfolder$x" id="delfolder$x" value="del" />~; 
       require "$sourcedir/Favorites.pl";                         } 
       &Favorites;                         else { 
       $MCContent .= qq~$showFavorites                             $MCPmMenuTemp_chk = q~&nbsp;~; 
       <br />                         } 
       ~;                         $storefolderl = $storefolder; 
   }                         $storefolderl =~ s/ /%20/gsm; 
   
   ## start PM div                         $foldercount = $folderCount[$x] || 0; 
   if ($PM_level == 1 || ($PM_level == 2 && ($iamadmin || $iamgmod || $iammod)) || ($PM_level == 3 && ($iamadmin || $iamgmod))) {                         $MCPmMenuTemp .= $my_MCPmMenuTemp; 
       $MCPmMenu .= qq~                         $MCPmMenuTemp =~ s/{yabb storefolder}/$storefolder/gsm; 
   <div id="cont_pm" style="display: $display_pm">                         $MCPmMenuTemp =~ s/{yabb storefolderl}/$storefolderl/gsm; 
       <table id="pms" width="100%" align="center" class="windowbg2" cellpadding="1">                         $MCPmMenuTemp =~ 
       ~;                           s/{yabb MCPmMenuTemp_chk}/$MCPmMenuTemp_chk/gsm; 
                         $MCPmMenuTemp =~ s/{yabb foldercount}/$foldercount/gsm;
       if (($PMenableBm_level == 1 && ($iamadmin || $iamgmod || $iammod)) || ($PMenableBm_level == 2 && ($iamadmin || $iamgmod)) || ($PMenableBm_level == 3 && $iamadmin)) {                         $x++; 
           $MCPmMenu .= qq~                     } 
           <tr>                 } 
               <td style="text-align: left;" colspan="3">  
                   <span class="nav"><b><a href="$scripturl?action=imsend;bmess=yes">$img{'sendbmess'}</a></b></span>                 if ($DelAdFolder) { 
               </td>                     $MCPmMenuTemp .= $my_MCPmMenudeladd; 
           </tr>~;                 } 
       }            }
   
       my $inboxNewCount = qq~<span class="NewLinks">, <a href="$scripturl?action=imshow;caller=1;id=-1">${$username}{'PMimnewcount'} $inmes_txt{'new'}</a></span>~;             if ($storeFoldersTotal) { 
       if (${$username}{'PMimnewcount'} == 0) { $inboxNewCount = ''; }                 $MCPmMenu_strtot = $my_storetotals; 
                 $MCPmMenu_strtot =~ s/{yabb MCPmMenuTemp}/$MCPmMenuTemp/sm;
       $MCPmMenu .= qq~             } 
            <tr>  
                <td style="text-align: left;" colspan="3"><span class="nav"><b><a href="$scripturl?action=imsend">$img{'im_send'}</a></b></span></td>             $MCPmMenu_markall = $my_markall; 
           </tr>             $MCPmMenu_markall =~ s/{yabb MCPmMenu_strtot}/$MCPmMenu_strtot/sm; 
           <tr>             $MCPmMenu_markall =~ s/{yabb new_load}/$newload/sm; 
               <td width="15%" class="windowbg2"><img src="$imagesdir/im_inbox.gif" alt="$inmes_txt{'inbox'}" title="$inmes_txt{'inbox'}" border="0" /></td>  
               <td width="60%" class="windowbg2"><span class="nav"><b><a href="$scripturl?action=im">$inmes_txt{'inbox'}</a></b></span></td>             $yyjavascript .= 
               <td width="25%" class="windowbg2"><span class="nav">${$username}{'PMmnum'}$inboxNewCount</span></td>  qq~\nvar markallreadlang = '$inmes_txt{'500'}';\nvar markfinishedlang = '$inmes_txt{'500a'}';~; 
           </tr>~;  
             ## this allows user to add a new folder on the fly
       if ($PMenableBm_level > 0 || ($PMenableGuestButton == 1 && ($iamadmin || $iamgmod))) {            if ( $storeFoldersTotal < $enable_storefolders ) {
           $inboxNewCount = $BCnewMessage ? " <span class='NewLinks'>($inmes_txt{'new'})</span>" : "";                 $MCPmMenu_newfolder = $my_newfolder; 
           $MCPmMenu .= qq~             } 
           <tr>         } 
               <td width="15%" class="windowbg2"><img src="$imagesdir/im_inbox.gif" alt="$inmes_txt{'broadcast'}" title="$inmes_txt{'broadcast'}" border="0" /></td>  
               <td width="60%" class="windowbg2"><span class="nav"><b><a href="$scripturl?action=im;focus=bmess">$inmes_txt{'broadcast'}</a></b></span></td>         $enable_PMsearch ||= 0; 
               <td width="25%" class="windowbg2"><span class="nav">$BCCount$inboxNewCount</span></td>         if ( $enable_PMsearch > 0 ) { 
           </tr>~;             if ( $view eq 'pm' && $action ne 'pmsearch' ) { 
       }                 $MCPmMenu_pmsearch_b = $my_pmsearch_b; 
             }
       my @folderCount = split(/\|/, ${$username}{'PMfoldersCount'});             $MCPmMenu_pmsearch = $my_pmsearch; 
       $MCPmMenu .= qq~             $MCPmMenu_pmsearch =~ 
           <tr>               s/{yabb MCPmMenu_pmsearch_b}/$MCPmMenu_pmsearch_b/sm; 
               <td width="15%" class="windowbg2"><img src="$imagesdir/im_outbox.gif" alt="$inmes_txt{'draft'}" title="$inmes_txt{'draft'}" border="0" /></td>         } 
               <td width="60%" class="windowbg2"><span class="nav"><b><a href="$scripturl?action=imdraft">$inmes_txt{'draft'}</a></b></span>    </td>  
               <td width="25%" class="windowbg2"><span class="nav">${$username}{'PMdraftnum'}</span></td>         $MCPmMenu .= $my_MCPmMenu; 
           </tr>         $MCPmMenu =~ s/{yabb display_pm}/$display_pm/sm; 
           <tr>         $MCPmMenu =~ s/{yabb MCPmMenu_bm}/$MCPmMenu_bm/sm; 
               <td width="15%" class="windowbg2"><img src="$imagesdir/im_outbox.gif" alt="$inmes_txt{'outbox'}" title="$inmes_txt{'outbox'}" border="0" /></td>         $MCPmMenu =~ s/{yabb mypmmenu_inbox}/$mypmmenu_inbox/sm; 
               <td width="60%" class="windowbg2"><span class="nav"><b><a href="$scripturl?action=imoutbox">$inmes_txt{'outbox'}</a></b></span>    </td>         $MCPmMenu =~ s/{yabb username_PMmnum}/${$username}{'PMmnum'}/sm; 
               <td width="25%" class="windowbg2"><span class="nav">${$username}{'PMmoutnum'}</span></td>         $MCPmMenu =~ s/{yabb inboxNewCount}/$inboxNewCount/sm; 
           </tr>         $MCPmMenu =~ s/{yabb MCPmMenu_bmbox}/$MCPmMenu_bmbox/sm; 
           <tr>         $MCPmMenu =~ s/{yabb foldercount0}/$foldercount0/sm; 
               <td colspan="3"><hr width="100%" class="hr" /></td>         $MCPmMenu =~ s/{yabb foldercount1}/$foldercount1/sm; 
           </tr>         $MCPmMenu =~ s/{yabb PMdraftnum}/${$username}{'PMdraftnum'}/sm; 
           <tr>         $MCPmMenu =~ s/{yabb PMmoutnum}/${$username}{'PMmoutnum'}/sm; 
               <td width="15%" class="windowbg2"><img src="$imagesdir/imstore.gif" alt="$inmes_txt{'storage'}" title="$inmes_txt{'storage'}" border="0" /></td>         $MCPmMenu =~ s/{yabb PMstorenum}/${$username}{'PMstorenum'}/sm; 
               <td width="60%" class="windowbg2"><span class="small">$inmes_txt{'storage'}</span></td>         $MCPmMenu =~ s/{yabb MCPmMenu_markall}/$MCPmMenu_markall/sm; 
               <td width="25%" class="windowbg2"><span class="nav">${$username}{'PMstorenum'}</span></td>         $MCPmMenu =~ s/{yabb MCPmMenu_newfolder}/$MCPmMenu_newfolder/sm; 
           </tr>         $MCPmMenu =~ s/{yabb MCPmMenu_pmsearch}/$MCPmMenu_pmsearch/sm; 
           <tr>     } 
               <td width="15%" class="windowbg2">&nbsp;</td>     ## end PM div 
               <td width="60%" class="windowbg2"><span class="nav">&nbsp; &nbsp;<b><a href="$scripturl?action=imstorage;viewfolder=in">$im_folders_txt{'in'}</a></b></span></td>     return; 
               <td width="25%" class="windowbg2"><span class="nav">~; $MCPmMenu .= $folderCount[0] || 0; $MCPmMenu .= qq~</span></td>  
           </tr>  
           <tr>  
               <td width="15%" class="windowbg2">&nbsp;</td>  
               <td width="60%" class="windowbg2"><span class="nav">&nbsp; &nbsp;<b><a href="$scripturl?action=imstorage;viewfolder=out">$im_folders_txt{'out'}</a></b> </span></td>  
               <td width="25%" class="windowbg2"><span class="nav">~; $MCPmMenu .= $folderCount[1] || 0; $MCPmMenu .= qq~</span></td>  
           </tr>  
       ~;  
   
       ## if there are some folders to show under storage  
       ## split the list down and show it with link to each folder  
       if ($enable_storefolders > 0) {  
           my $storeFoldersTotal = 0;  
           my $DelAdFolder = 0;  
           if (${$username}{'PMfolders'}) {  
               my $x = 2;  
               foreach my $storefolder (split(/\|/, ${$username}{'PMfolders'})) {  
                   if ($storefolder ne 'in' && $storefolder ne 'out') {  
                       $storeFoldersTotal++;  
                       $MCPmMenuTemp .= qq~  
                       <tr>  
                           <td width="15%" class="windowbg2">~;  
                       if ($storeFoldersTotal > 0 && $folderCount[$x] == 0) {  
                           $DelAdFolder = 1;  
                           $MCPmMenuTemp .= qq~  
                               <input type="checkbox" name="delfolder$x" id="delfolder$x" value="del" />~;  
                       } else {  
                           $MCPmMenuTemp .= qq~&nbsp;~;  
                       }  
   
                       $MCPmMenuTemp .= qq~  
                           </td>  
                           <td width="60%" class="windowbg2"><span class="nav">&nbsp; &nbsp;<b><a href="$scripturl?action=imstorage;viewfolder=$storefolder">$storefolder</a></b></span></td>  
                           <td width="25%" class="windowbg2"><span class="nav">~;  
                       $MCPmMenuTemp .= $folderCount[$x] || 0;  
                       $MCPmMenuTemp .= qq~</span></td>  
                       </tr>~;  
                   $x++;  
                   }  
               }  
   
               if ($DelAdFolder) {  
                   $MCPmMenuTemp .= qq~  
                       <tr>  
                           <td class="windowbg2" colspan="3">  
                           <input type="submit" name="deladdfolder" id="deladdfolder" value="$inmes_txt{'delete'}" class="button" />  
                           <input type="hidden" name="delfolders" id="delfolders" value="yes" />  
                           </td>  
                       </tr>  
                   ~;  
               }  
           }  
   
           if ($storeFoldersTotal) {  
               $MCPmMenu .= qq~  
                   <tr>  
                       <td class="windowbg2" colspan="3">  
                       <form action="$scripturl?action=delpmfolder" method="post" name="delpmfolder" id="delpmfolder" enctype="application/x-www-form-urlencoded" style="display:inline;"  onsubmit="return submitproc()">  
                       <table width="100%" border="0" cellspacing="0" cellpadding="2">  
                       $MCPmMenuTemp  
                       </table>  
                       </form>  
                       </td>  
                   </tr>  
               ~;  
           }  
   
           $MCPmMenu .= qq~  
           <tr>  
               <td colspan="3"><hr width="100%" class="hr" /></td>  
           </tr>  
           <tr>  
               <td colspan="3"><span class="nav"><b><a href="javascript:MarkAllAsRead('$scripturl?action=markims','$imagesdir')">$inmes_txt{'764'}</a></b></span></td>  
           </tr>~;  
           $yyjavascript .= qq~\nvar markallreadlang = '$inmes_txt{'500'}';\nvar markfinishedlang = '$inmes_txt{'500a'}';~;  
   
           ## this allows user to add a new folder on the fly  
           if ($storeFoldersTotal < $enable_storefolders ) {  
               $MCPmMenu .= qq~  
           <tr>  
               <td colspan="3">  
               <hr width="100%" class="hr" />  
                   <form action="$scripturl?action=newpmfolder" method="post" name="newpmfolder" id="newpmfolder" enctype="application/x-www-form-urlencoded" style="display:inline;"  onsubmit="return submitproc()">  
                   <label for="newfolder">$inmes_imtxt{'newstorefolder'}</label><br />  
                   <input type="text" name="newfolder" id="newfolder" size="15" value="$mc_folders{'foldername'}" onfocus="txtInFields(this, '$mc_folders{'foldername'}');" onblur="txtInFields(this, '$mc_folders{'foldername'}')" />  
                   <input type="submit" name="addimfolder" id="addimfolder" value="$inmes_txt{'addfolder'}" class="button" />  
                   </form>  
               </td>  
           </tr>~;  
           }  
       }  
   
       unless ($enable_PMsearch == 0) {  
           $MCPmMenu .= qq~  
           <tr>  
               <td colspan="3">  
               <hr width="100%" class="hr" />  
               <script language="JavaScript1.2" src="$yyhtml_root/ubbc.js" type="text/javascript"></script>  
               <label for="search">$pm_search{'desc'}</label><br />  
               <form action="$scripturl?action=pmsearch" method="post" onsubmit="return submitproc()" style="display: inline">~;  
   
           if ($view eq 'pm' && $action ne 'pmsearch') {  
               $MCPmMenu .= qq~  
               - <input type="radio" name="pmbox" id="pmboxall" value="" checked="checked" /> <label for="pmboxall">$pm_search{'all'}</label>  
               <input type="radio" name="pmbox" id="pmboxthis" value="$callerid" /> <label for="pmboxthis">$pm_search{'justthis'}</label><br />~;  
           }  
   
           $MCPmMenu .= qq~  
               - <input type="checkbox" name="searchtype" id="searchtype" value="user" /> <label for="searchtype">$pm_search{'byuser'}</label><br />  
               <input type="text" name="search" id="search" size="16" style="font-size: 11px; vertical-align: middle;" />  
   
               <input type="image" src="$imagesdir/search.gif" style="border: 0; background-color: transparent; margin-right: 5px; vertical-align: middle;" />  
               </form>  
               </td>  
           </tr>  
           ~;  
       }  
   
       $MCPmMenu .= qq~  
       </table>  
   </div>  
       ~;  
   
   }  
   ## end PM div  
} }
   
sub drawPMView { sub drawPMView {
   ## column headers    ## column headers
   ## note - if broadcast messages not enabled but guest pm is, admin/gmod still    ## note - if broadcast messages not enabled but guest pm is, admin/gmod still
   ##  see the broadcast split    ##  see the broadcast split
   if (($enable_PMcontrols && ${$uid.$username}{'pmviewMess'}) || (!$enable_PMcontrols && !$enable_PMviewMess) ) {    if ( ${ $uid . $username }{'pmviewMess'} ) {
       if (!$yyYaBBCloaded) { require "$sourcedir/YaBBC.pl"; }         enable_yabbc(); 
   }    }
   if ($INFO{'sort'} ne 'gpdate' && $INFO{'sort'} ne 'thread') { &pageLinksList; }     if ( $INFO{'sort'} ne 'gpdate' && $INFO{'sort'} ne 'thread' ) { 
   my $dateColhead = "$inmes_txt{'317'}";         pageLinksList(); 
   if ($action eq 'imdraft') { $dateColhead = $inmes_txt{'datesave'}; }    }
     my $dateColhead = "$inmes_txt{'317'}";
   $mctitle = $IM_box;     if ( $action eq 'imdraft' ) { $dateColhead = $inmes_txt{'datesave'}; } 
   $MCContent .= qq~  
   <table border="0" width="100%" cellspacing="1" cellpadding="3" class="bordercolor">     $maxmessagedisplay ||= 10; 
   ~;     if ( ( $#dimmessages >= $maxmessagedisplay || $INFO{'start'} =~ /all/sm ) 
         && $action ne 'imstorage' )
   if (($#dimmessages >= $maxmessagedisplay || $INFO{'start'} =~ /all/) && $action ne 'imstorage') {    {
       $MCContent .= qq~         $MCContent_page = $my_PMview_top; 
       <tr><td colspan="3" class="titlebg">$pageindex1$pageindexjs</td></tr>         $MCContent_page =~ s/{yabb pageindex1}/$pageindex1/sm; 
       ~;         $MCContent_page =~ s/{yabb pageindexjs}/$pageindexjs/sm; 
   }    }
   
   if ($INFO{'viewfolder'} ne '') { $vfolder = qq~;viewfolder=$INFO{'viewfolder'}~; }     if ( $INFO{'viewfolder'} ne q{} ) { 
   if ($INFO{'focus'} eq 'bmess') { $vbmess = qq~;focus=bmess~; }         $vfolder = qq~;viewfolder=$INFO{'viewfolder'}~; 
   if ($INFO{'sort'} ne 'gpdate') { $sbgpdate = qq~;sort=gpdate~; }    }
     if ( $INFO{'focus'} eq 'bmess' ) { $vbmess = q~;focus=bmess~; }
   unless ($action eq 'imstorage' && $INFO{'viewfolder'} eq '') {     if ( $INFO{'sort'} ne 'gpdate' ) { $sbgpdate = q~;sort=gpdate~; } 
       $MCContent .= qq~  
     <tr>     if ( $action ne 'imstorage' || $INFO{'viewfolder'} ne q{} ) { 
       <td class="titlebg"  width="65%"><b>$inmes_txt{'70'}</b></td>         $MCContent_view .= $my_PMview; 
       <td class="titlebg"  width="15%"><b>$senderinfo</b></td>         $MCContent_view =~ s/{yabb senderinfo}/$senderinfo/sm; 
       <td class="titlebg"  width="20%"><b><a href="$scripturl?action=$action$sbgpdate$vfolder$vbmess">$dateColhead</a></b></td>         $MCContent_view =~ s/{yabb action}/$action/sm; 
     </tr>         $MCContent_view =~ s/{yabb sbgpdate}/$sbgpdate/sm; 
       ~;         $MCContent_view =~ s/{yabb vfolder}/$vfolder/sm; 
   }         $MCContent_view =~ s/{yabb vbmess}/$vbmess/sm; 
         $MCContent_view =~ s/{yabb dateColhead}/$dateColhead/sm;
   ## if no messages found in file, say so     } 
   my $storeContentFound = 0;  
   if ($INFO{'viewfolder'} && @dimmessages) {     ## if no messages found in file, say so 
       foreach my $checkPost (@dimmessages) {     my $storeContentFound = 0; 
           my $thisStorefolder= (split /\|/, $checkPost)[13];     if ( $INFO{'viewfolder'} && @dimmessages ) { 
           if ($thisStorefolder eq $INFO{'viewfolder'}) { $storeContentFound = 1; last; }         foreach my $checkPost (@dimmessages) { 
       }             my $thisStorefolder = ( split /\|/xsm, $checkPost )[13]; 
   }             if ( $thisStorefolder eq $INFO{'viewfolder'} ) { 
                 $storeContentFound = 1;
   if (!@dimmessages || ($storeContentFound == 0 && $INFO{'viewfolder'})) {                 last; 
       ## drop in the 'no messages' text             } 
       $MCContent .= qq~         } 
     <tr>     } 
       <td class="windowbg" colspan="3" height="21">$inmes_txt{'151'}</td>     $MCContent_no_mess = q{}; 
     </tr>     if ( !@dimmessages || ( $storeContentFound == 0 && $INFO{'viewfolder'} ) ) { 
   </table>         ## drop in the 'no messages' text 
   <br clear="all" /><br />         $MCContent_no_mess = $my_nomesssages; 
   ~;     } 
   } else {    else {
       ## set colours for display        ## set colours for display
       $acount++;        $acount++;
       my $sortBy = $INFO{'sort'};        my $sortBy = $INFO{'sort'};
       my $maxcounter;        my $maxcounter;
       $start = $start || 0;        $start = $start || 0;
       ## if on last page, adjust the maxcounter down        ## if on last page, adjust the maxcounter down
       if ((($#dimmessages + 1) - $start) < $maxmessagedisplay || $sortBy eq 'gpdate' || $action eq 'imstorage') {         if (   ( ( $#dimmessages + 1 ) - $start ) < $maxmessagedisplay 
           $maxcounter = @dimmessages;             || $sortBy eq 'gpdate' 
       } else {             || $action eq 'imstorage' ) 
           $maxcounter = ($start + $maxmessagedisplay);         { 
       }             $maxcounter = @dimmessages; 
       my $viewBMess;         } 
       my $groupByDate = 0;         else { 
       my $dateSpan = 0;             $maxcounter = ( $start + $maxmessagedisplay ); 
       my $latestPM = 0;         } 
       if ($INFO{'focus'} eq 'bmess') { $viewBMess = 1; }         my $viewBMess; 
       if ($sortBy eq 'gpdate') {         my $groupByDate = 0; 
           my $topMDate = (split /\|/, $dimmessages[0])[6];         my $dateSpan    = 0; 
           my $oldestDate = (split /\|/, $dimmessages[$#dimmessages])[6];         my $latestPM    = 0; 
           $groupByDate = 1;         if ( $INFO{'focus'} eq 'bmess' ) { $viewBMess = 1; } 
           ## work out the span of days - today less oldest message, in days         if ( $sortBy eq 'gpdate' ) { 
           $dateSpan = int(($date - $oldestDate) / 86400); # in days             my $topMDate   = ( split /\|/xsm, $dimmessages[0] )[6]; 
           $latestPM = (($date - $topMDate) / 3600); # in hours             my $oldestDate = ( split /\|/xsm, $dimmessages[-1] )[6]; 
       }             $groupByDate = 1; 
       ## if sort is grouped, extra block is added per group             ## work out the span of days - today less oldest message, in days 
       ## pull date of newest pm             $dateSpan = int( ( $date - $oldestDate ) / 86400 );    # in days 
             $latestPM = ( ( $date - $topMDate ) / 3600 );           # in hours
       my $latestDateSet = 0;         } 
       my $lastWeekSet = 0;         ## if sort is grouped, extra block is added per group 
       my $twoWeeksSet = 0;         ## pull date of newest pm 
       my $threeWeeksSet = 0;  
       my $monthSet = 0;        my $latestDateSet = 0;
       my $gtMonthSet = 0;        my $lastWeekSet   = 0;
       my $uselegend = "";         my $twoWeeksSet   = 0; 
         my $threeWeeksSet = 0;
       # work out the newest pm date soa s to put the right first block in         my $monthSet      = 0; 
       if ($dateSpan > 31) { $gtMonthSet = 1; $uselegend = 'older'; }         my $gtMonthSet    = 0; 
       if ($dateSpan > 21 && ($latestPM / 24) < 32 ) { $monthSet = 1; $uselegend = 'fourweeks';}         my $uselegend     = q{}; 
       if ($dateSpan > 14 && ($latestPM / 24) < 22 ) { $threeWeeksSet = 1; $uselegend = 'threeweeks';}         my ( $mAttachDeleteWarn, $mAttachDeleteSet ); 
       if ($dateSpan > 7  && ($latestPM / 24) < 15 ) { $twoWeeksSet = 1; $uselegend = 'twoweeks';}  
       if ($dateSpan > 1 && ($latestPM / 24) < 8 ) { $lastWeekSet = 1; $uselegend = 'oneweek';}         # work out the newest pm date soa s to put the right first block in 
       if ($latestPM < 24) { $latestDateSet = 1; $uselegend = 'latest'; }        if ( $dateSpan > 31 ) { $gtMonthSet = 1; $uselegend = 'older'; }
         if ( $dateSpan > 21 && ( $latestPM / 24 ) < 32 ) {
       if ($sortBy eq 'gpdate') {             $monthSet  = 1; 
           $MCContent .= qq~             $uselegend = 'fourweeks'; 
     <tr>         } 
       <td class="titlebg"  width="100%" colspan="3"><span class="imgtitlebg">$im_sorted{$uselegend}</span>    </td>         if ( $dateSpan > 14 && ( $latestPM / 24 ) < 22 ) { 
     </tr>             $threeWeeksSet = 1; 
           ~;             $uselegend     = 'threeweeks'; 
         }
           $counterCheck = $start;         if ( $dateSpan > 7 && ( $latestPM / 24 ) < 15 ) { 
       }             $twoWeeksSet = 1; 
       if ($viewBMess) { $stkDateSet = 1; }             $uselegend   = 'twoweeks'; 
         }
         if ( $dateSpan > 1 && ( $latestPM / 24 ) < 8 ) {
             $lastWeekSet = 1;
             $uselegend   = 'oneweek';
         }
         if ( $latestPM < 24 ) { $latestDateSet = 1; $uselegend = 'latest'; }
   
         $MCContent_sort = q{};
         if ( $sortBy eq 'gpdate' ) {
             $MCContent_sort .= $my_uselegend;
             $MCContent_sort =~ s/{yabb sorted_legend}/$im_sorted{$uselegend}/sm;
             $mytopdisp = q~display:none;~;
   
             $counterCheck = $start;
         }
         if ($viewBMess) { $stkDateSet = 1; }
   
       for ($counter = $start; $counter < $maxcounter; $counter++) {        foreach my $counter ( $start .. ( $maxcounter - 1 ) ) {
##########  top of messages list ########## ##########  top of messages list ##########
# $messageid, $musername, $musernameto, $musernamecc, $musernamebcc            # $messageid, $musername, $musernameto, $musernamecc, $musernamebcc
           $class_PM_list = $class_PM_list eq 'windowbg2' ? 'windowbg' : 'windowbg2';             $class_PM_list = 
           chomp $dimmessages[$counter];               $class_PM_list eq 'windowbg2' ? 'windowbg' : 'windowbg2'; 
           my ($messageid, $musername, $musernameto, $musernamecc, $musernamebcc, $msub, $mdate, $immessage, $mpmessageid, $mreplyno, $mips, $messageStatus, $messageFlags, $storeFolder, $messageAttachment) = split(/\|/, $dimmessages[$counter]);             chomp $dimmessages[$counter]; 
           ## if we are viewing  one of the storage folders, filter out the             my ( 
           ##  PMs that don't match                 $messageid,    $musername,    $musernameto, 
           if ($action eq 'imstorage' && $INFO{'viewfolder'} ne $storeFolder) {                 $musernamecc,  $musernamebcc, $msub, 
               $class_PM_list = $class_PM_list eq 'windowbg2' ? 'windowbg' : 'windowbg2';                 $mdate,        $immessage,    $mpmessageid, 
               next;                 $mreplyno,     $mips,         $messStatus, 
           }                 $messageFlags, $storeFolder,  $messageAttachment, 
           ## set the status icon             ) = split /\|/xsm, $dimmessages[$counter]; 
           my $messIconName = 'standard';             ## if we are viewing  one of the storage folders, filter out the 
           if ($messageStatus =~ /c/) { $messIconName = 'confidential'; }             ##  PMs that do not match 
           elsif ($messageStatus =~ /u/) { $messIconName = 'urgent'; }             if ( $action eq 'imstorage' && $INFO{'viewfolder'} ne $storeFolder ) 
           elsif ($messageStatus =~ /a/) { $messIconName = 'alertmod'; }             { 
           elsif ($messageStatus =~ /gr/) { $messIconName = 'guestpmreply'; }                 $class_PM_list = 
           elsif ($messageStatus =~ /g/) { $messIconName = 'guestpm'; }                   $class_PM_list eq 'windowbg2' ? 'windowbg' : 'windowbg2'; 
           my $messIcon = qq~<img src="$imagesdir/$messIconName.gif" name="icons" border="0" hspace="15" alt="$im_message_status{$messIconName}" title="$im_message_status{$messIconName}" style="vertical-align: middle;" />~;                 next; 
             }
           my ($hasMultiRecs,$multiRecs);             chomp $messageAttachment; 
           if ($musernameto =~ /,/ || $musernamecc || $musernamebcc ) { $hasMultiRecs = 1; }             if ( $messageAttachment ne q{} ) { 
                 foreach ( split /,/xsm, $messageAttachment ) {
           ## if store, set the from/to                     my ( $pmAttachFile, $pmAttachUser ) = split /~/xsm, $_; 
                     if ( $username eq $pmAttachUser
           # check for multiple recs (outbox/store/draft only)                         && -e "$pmuploaddir/$pmAttachFile" ) 
           ## and build the to/rec string for individual callback                     { 
           my %usersRec;                         $mAttachDeleteSet = 1; 
                     }
           my $usernameto = '';                 } 
           if ($action eq 'imoutbox' || $action eq 'imstorage' || $action eq 'imdraft') {             } 
               if ($hasMultiRecs) {             ## set the status icon 
                   my $switchComma = 0;             my @staticon = (); 
                   $usernameto = '';             if    ( $messStatus =~ m/c/sm ) { $messIconName = 'confidential'; } 
                   if ($messageStatus !~ /b/) {             elsif ( $messStatus =~ m/u/sm ) { $messIconName = 'urgent'; } 
                       ## check each to see if they read the message             elsif ( $messStatus =~ m/a/sm || $messStatus =~ m/ga/sm ) { 
                       foreach my $muser (split(/\,/, $musernameto)) {                 $messIconName = 'alertmod'; 
                           $userToMessRead = &checkIMS($muser, $messageid, 'messageopened');             } 
                           %usersRec = {%usersRec , $muser => $userToMessRead};             elsif ( $messStatus =~ m/gr/sm ) { 
                           if (!$yyUDLoaded{$muser}) { &LoadUser($muser); }                 $messIconName = 'guestpmreply'; 
                           if ($usernameto && $switchComma == 0) { $usernameto .= qq~ ...~; $switchComma = 1; }            }
                           elsif (!$usernameto) {             elsif ( $messStatus =~ m/g/sm ) { $messIconName = 'guestpm'; } 
                               $usernameto = qq~<a href="$scripturl?action=viewprofile;username=$useraccount{$muser}">${$uid.$muser}{'realname'}</a>~;             else                            { $messIconName = 'standard'; } 
                           }             my $messIcon = $micon{$messIconName}; 
                       }  
                       if ($musernamecc) {             my ($hasMultiRecs); 
                       ## check each to see if they read the message             if ( $musernameto =~ /,/xsm || $musernamecc || $musernamebcc ) { 
                           foreach my $muser (split(/\,/, $musernamecc)) {                 $hasMultiRecs = 1; 
                               $userToMessRead = &checkIMS($muser, $messageid, 'messageopened');             } 
                               %usersRec = {%usersRec , $muser => $userToMessRead};  
                               if (!$yyUDLoaded{$muser}) { &LoadUser($muser); }             ## if store, set the from/to 
                               if ($usernameto && $switchComma == 0) { $usernameto .= qq~ ...~; $switchComma = 1; }  
                           }             # check for multiple recs (outbox/store/draft only) 
                       }             ## and build the to/rec string for individual callback 
                       if ($musernamebcc) {             my %usersRec; 
                           ## check each to see if they read the message  
                           foreach my $muser (split(/\,/, $musernamebcc)) {             my $usernameto = q{}; 
                               $userToMessRead = &checkIMS($muser, $messageid, 'messageopened');             if (   $action eq 'imoutbox' 
                               %usersRec = {%usersRec , $muser => $userToMessRead};                 || $action eq 'imstorage' 
                               if (!$yyUDLoaded{$muser}) { &LoadUser($muser); }                 || $action eq 'imdraft' ) 
                               if($usernameto && $switchComma == 0) {$usernameto .= qq~ ...~; $switchComma = 1; }             { 
                           }                 if ($hasMultiRecs) { 
                       }                     my $switchComma = 0; 
                   } else {                     $usernameto = q{}; 
                       foreach my $muser (split(/\,/, $musernameto)) {                    if ( $messStatus !~ /b/sm ) {
                           if ($muser eq 'all') { $usernameto = $inmes_txt{'bmallmembers'}; }                         ## check each to see if they read the message 
                           elsif ($muser eq 'mods') { $usernameto = $inmes_txt{'bmmods'}; }                         foreach my $muser ( split /\,/xsm, $musernameto ) { 
                           elsif ($muser eq 'gmods') { $usernameto = $inmes_txt{'bmgmods'}; }                             $userToMessRead = 
                           elsif ($muser eq 'admins') { $usernameto = $inmes_txt{'bmadmins'}; }                               checkIMS( $muser, $messageid, 'messageopened' ); 
                           else {                             %usersRec = 
                               my $title = (split /\|/, $NoPost{$muser})[0];                               { %usersRec, $muser => $userToMessRead }; 
                               $usernameto = $title;                             if ( !$yyUDLoaded{$muser} ) { LoadUser($muser); } 
                           }                             if ( $usernameto && $switchComma == 0 ) { 
                           if ($usernameto && $switchComma == 0) { $usernameto .= qq~ ...~; $switchComma = 1; last; }                                 $usernameto .= q~ ...~; 
                       }                                 $switchComma = 1; 
                   }                            }
               } else {                            elsif ( !$usernameto ) {
                   if ($messageStatus !~ /b/) {                                 $usernameto = 
                       $userToMessRead = &checkIMS($musernameto, $messageid, 'messageopened');  qq~<a href="$scripturl?action=viewprofile;username=$useraccount{$muser}" rel="nofollow">$format_unbold{$muser}</a>~; 
                       if (!$yyUDLoaded{$musernameto}) { &LoadUser($musernameto); }                            }
                       $usernameto = qq~<a href="$scripturl?action=viewprofile;username=$useraccount{$musernameto}">${$uid.$musernameto}{'realname'}</a>~;                         } 
                   } else {                        if ($musernamecc) {
                       if ($musernameto eq 'all') { $usernameto = $inmes_txt{'bmallmembers'}; }                             ## check each to see if they read the message 
                       elsif ($musernameto eq 'mods') { $usernameto = $inmes_txt{'bmmods'}; }                             foreach my $muser ( split /\,/xsm, $musernamecc ) { 
                       elsif ($musernameto eq 'gmods') { $usernameto = $inmes_txt{'bmgmods'}; }                                 $userToMessRead = checkIMS( $muser, $messageid, 
                       elsif ($musernameto eq 'admins') { $usernameto = $inmes_txt{'bmadmins'}; }                                     'messageopened' ); 
                       else {                                 %usersRec = 
                           my $title = (split /\|/, $NoPost{$musernameto})[0];                                   { %usersRec, $muser => $userToMessRead }; 
                           $usernameto = $title;                                 if ( !$yyUDLoaded{$muser} ) { 
                       }                                     LoadUser($muser); 
                   }                                }
               }                                 if ( $usernameto && $switchComma == 0 ) { 
           }                                     $usernameto .= q~ ...~; 
           ## done multi                                     $switchComma = 1; 
           ## kill if not needed                                 } 
           if (!$hasMultiRecs) { undef %usersRec; }                            }
                         }
           ## time to output name                         if ($musernamebcc) { 
           # for multi recs, have to split it down and test per user                             ## check each to see if they read the message 
           ## happens for any message sent with cc or bcc                             foreach my $muser ( split /\,/xsm, $musernamebcc ) { 
           my $checkz = 0;                                 $userToMessRead = checkIMS( $muser, $messageid, 
           my $allChecked = 0;                                     'messageopened' ); 
                                 %usersRec =
           $msub = &Censor($msub);                                   { %usersRec, $muser => $userToMessRead }; 
           &ToChars($msub);                                 if ( !$yyUDLoaded{$muser} ) { 
                                     LoadUser($muser);
           $mydate = &timeformat($mdate);                                 } 
           ## start of message row 1                                 if ( $usernameto && $switchComma == 0 ) { 
           ## for inbox or store, check from                                     $usernameto .= q~ ...~; 
           my ($fromToName, $messageIcon, $callBack, $messageAction);                                     $switchComma = 1; 
           if ($action ne 'imstorage' && $action ne 'imdraft' && !$viewBMess) {                                 } 
               ## detect multi-rec                             } 
               my ($imnew, $imRepliedTo, $imOpened);                         } 
               ## outbox - has the recp opened the message? (allow for multi)                     } 
               if ($action eq 'imoutbox' && !$hasMultiRecs ) {                    else {
                   $imOpened = &checkIMS($musernameto, $messageid, 'messageopened');                         foreach my $muser ( split /\,/xsm, $musernameto ) { 
               } elsif ($action eq 'im') { ## inbox - has user opened ?                             @grps = qw(all mods fmods gmods admins); 
                   $imOpened = &checkIMS($username, $messageid, 'messageopened');                             @grps2 = 
               }                               qw(bmallmembers bmmods bmfmods bmgmods bmadmins); 
               if ($action eq 'im') { $imRepliedTo = &checkIMS($username, $messageid, 'messagereplied'); }                             for my $grp ( 0 .. $#grps ) { 
                                 if ( $muser eq $grps[$grp] ) {
               ## viewing inbox                                     $usernameto = $inmes_txt{ $grps2[$grp] }; 
               if ($action eq 'im') {                                 } 
                   ## not opened                             } 
                   if (!$imOpened && !$hasMultiRecs) {                             if (   $uname ne 'all' 
                       $messageIcon = qq~<img src="$imagesdir/imclose.gif" border="0" alt="$inmes_imtxt{'innotread'}" title="$inmes_imtxt{'innotread'}" style="vertical-align: middle;" />~;                                 && $uname ne 'mods' 
                   }                                 && $uname ne 'fmods' 
                   ## replied to                                 && $uname ne 'gmods' 
                   elsif ($imRepliedTo && !$hasMultiRecs) {                                 && $uname ne 'admins' ) 
                       $messageIcon = qq~<img src="$imagesdir/answered.gif" border="0" alt="$inmes_imtxt{'08'}" title="$inmes_imtxt{'08'}" style="vertical-align: middle;" />~;                             { 
                   }                                 my ( $title, undef ) = 
                   ## opened                                   split /\|/xsm, $NoPost{$uname}, 2; 
                   elsif ($imOpened && !$hasMultiRecs) {                                 $usernameto = $title; 
                       $messageIcon = qq~<img src="$imagesdir/imopen.gif" border="0" alt="$inmes_imtxt{'inread'}" title="$inmes_imtxt{'inread'}" style="vertical-align: middle;" />~;                             } 
                   }                             if ( $usernameto && $switchComma == 0 ) { 
                   ## not opened multi                                 $usernameto .= q~ ...~; 
                   elsif (!$imOpened && $hasMultiRecs) {                                 $switchComma = 1; 
                       $messageIcon = qq~<img src="$imagesdir/imclose2.gif" border="0" alt="$inmes_imtxt{'inread'}" title="$inmes_imtxt{'inread'}" style="vertical-align: middle;" />~;                                 last; 
                   }                            }
                   ## opened multi                         } 
                   elsif ($imOpened && $hasMultiRecs) {                     } 
                       $messageIcon = qq~<img src="$imagesdir/imopen2.gif" border="0" alt="$inmes_imtxt{'inread'}" title="$inmes_imtxt{'inread'}" style="vertical-align: middle;" />~;                 } 
                   }                 else { 
               }                     if ( $messStatus !~ /b/sm ) { 
                         $userToMessRead =
               ##  outbox                           checkIMS( $musernameto, $messageid, 'messageopened' ); 
               elsif ($action eq 'imoutbox') {                        if ( !$yyUDLoaded{$musernameto} ) {
                   ## not opened                             LoadUser($musernameto); 
                   if (!$imOpened && !$hasMultiRecs) {                         } 
                       &LoadUser($musernameto);                         $usernameto = 
                       if (${$uid.$musernameto}{'notify_me'} < 2 || $enable_notifications < 2) {  qq~<a href="$scripturl?action=viewprofile;username=$useraccount{$musernameto}" rel="nofollow">$format_unbold{$musernameto}</a>~; 
                           $messageIcon = qq~<img src="$imagesdir/imclose.gif" border="0" alt="$inmes_imtxt{'outnotread'}" title="$inmes_imtxt{'outnotread'}" style="vertical-align: middle;" />~;                     } 
                           $callBack = qq~<span class="small"><a href="$scripturl?action=imcb;rid=$messageid;receiver=$useraccount{$musernameto}" onclick="return confirm('$inmes_imtxt{'73'}')">$inmes_imtxt{'83'}</a> | </span>~;                     else { 
                       } else {                         @grps = qw(all mods fmods gmods admins); 
                           $messageIcon = qq~<img src="$imagesdir/imclose.gif" border="0" alt="$inmes_imtxt{'outnotread'}" title="$inmes_imtxt{'outnotread'}" style="vertical-align: middle;" />~;                         @grps2 = 
                       }                           qw(bmallmembers bmmods bmfmods bmgmods bmadmins); 
                   }                         for my $grp ( 0 .. $#grps ) { 
                   ## opened                             if ( $musernameto eq $grps[$grp] ) { 
                   elsif ($imOpened && !$hasMultiRecs) {                                 $usernameto = $inmes_txt{ $grps2[$grp] }; 
                       $messageIcon = $messageFlags =~ /c/i ? qq~<img src="$imagesdir/imcallback.gif" border="0" alt="$inmes_imtxt{'callback'}" title="$inmes_imtxt{'callback'}" style="vertical-align: middle;" />~ : qq~<img src="$imagesdir/imopen.gif" border="0" alt="$inmes_imtxt{'outread'}" title="$inmes_imtxt{'outread'}" style="vertical-align: middle;" />~;                             } 
                   }                        }
                         if (   $uname ne 'all' 
                   ## for multi rec, and none opened                             && $uname ne 'mods' 
                   if ($hasMultiRecs) {                             && $uname ne 'fmods' 
                       my ($countrecepients,$countread,@receivers);                             && $uname ne 'gmods' 
                       my $tousers = $musernameto;                             && $uname ne 'admins' ) 
                       $tousers .= ",$musernamecc" if $musernamecc;                         { 
                       $tousers .= ",$musernamebcc" if $musernamebcc;                             my ( $title, undef ) = 
                       foreach my $recname (split(/,/, $tousers)) {                               split /\|/xsm, $NoPost{$uname}, 2; 
                           $countrecepients++;                             $usernameto = $title; 
                           &LoadUser($recname);                         } 
                           if (&checkIMS($recname, $messageid, 'messageopened') || (${$uid.$recname}{'notify_me'} > 1 && $enable_notifications > 1)) { $countread++; } else { push(@receivers, $useraccount{$recname}); }                     } 
                       }                }
                       if (!$countread) {             } 
                           $messageIcon = qq~<img src="$imagesdir/imclose2.gif" border="0" alt="$inmes_imtxt{'outmultinotread'}" title="$inmes_imtxt{'outmultinotread'}" style="vertical-align: middle;" />~;             ## done multi 
                           $callBack = qq~<span class="small"><a href="$scripturl?action=imcb;rid=$messageid;receiver=~ . join(',', @receivers) . qq~" onclick="return confirm('$inmes_imtxt{'73'}')">$inmes_imtxt{'83'}</a> | </span>~;             ## kill if not needed 
                       } elsif ($countrecepients == $countread) {             if ( !$hasMultiRecs ) { undef %usersRec; } 
                           $messageIcon = $messageFlags =~ /c/i ? qq~<img src="$imagesdir/imcallback2.gif" border="0" alt="$inmes_imtxt{'outmulticallback'}" title="$inmes_imtxt{'outmulticallback'}" style="vertical-align: middle;" />~ : qq~<img src="$imagesdir/imopen2.gif" border="0" alt="$inmes_imtxt{'outmultiread'}" title="$inmes_imtxt{'outmultiread'}" style="vertical-align: middle;" />~;  
                       } else {             ## time to output name 
                           $messageIcon = $messageFlags =~ /c/i ? qq~<img src="$imagesdir/imcallback3.gif" border="0" alt="$inmes_imtxt{'outsomemulticallback'}" title="$inmes_imtxt{'outsomemulticallback'}" style="vertical-align: middle;" />~ : qq~<img src="$imagesdir/imopen3.gif" border="0" alt="$inmes_imtxt{'outmultisomeread'}" title="$inmes_imtxt{'outmultisomeread'}" style="vertical-align: middle;" />~;             # for multi recs, have to split it down and test per user 
                           $callBack = qq~<span class="small"><a href="$scripturl?action=imshow;id=$messageid;caller=2">$inmes_imtxt{'multicallback'}</a> | </span>~;             ## happens for any message sent with cc or bcc 
                       }             my $checkz     = 0; 
                   }             my $allChecked = 0; 
               }  
           }             $msub = Censor($msub); 
             ToChars($msub);
           ## switch action if opening a draft - want this sending to the 'send' screen  
           my $actString = 'imshow';             $mydate = timeformat($mdate); 
           if ($action eq 'imdraft') { $actString = 'imsend'; }             ## start of message row 1 
             ## for inbox or store, check from
           ## if grouping, check bar here             my ( $messageIcon, $callBack ); 
           if ($stkmess && $sortBy ne 'gpdate' && $normDateSet && $viewBMess) {             if ( $action ne 'imstorage' && $action ne 'imdraft' && !$viewBMess ) 
               ## sticky messages             { 
               $normDateSet = 0;                 ## detect multi-rec 
               $MCContent .= qq~                 my ( $imRepliedTo, $imOpened ); 
     <tr>                 ## outbox - has the recp opened the message? (allow for multi) 
       <td class="titlebg"  width="100%" colspan="3"><span class="imgtitlebg">$im_sorted{'standart'}</span></td>                 if ( $action eq 'imoutbox' && !$hasMultiRecs ) { 
     </tr>                     $imOpened = 
               ~;                       checkIMS( $musernameto, $messageid, 'messageopened' ); 
           }                }
                 elsif ( $action eq 'im' ) {    ## inbox - has user opened ?
           if ($stkmess && $sortBy ne 'gpdate' && $stkDateSet && $viewBMess && ($messageStatus =~ /g/ || $messageStatus =~ /a/)) {                     $imOpened = 
               ## sticky messages                       checkIMS( $username, $messageid, 'messageopened' ); 
               $stkDateSet = 0;                 } 
               $MCContent .= qq~                 if ( $action eq 'im' ) { 
     <tr>                     $imRepliedTo = 
       <td class="titlebg"  width="100%" colspan="3"><span class="imgtitlebg">$im_sorted{'important'}</span></td>                       checkIMS( $username, $messageid, 'messagereplied' ); 
     </tr>                 } 
               ~;  
           }                 ## viewing inbox 
                 if ( $action eq 'im' ) {
           if ($sortBy eq 'gpdate') {                     ## not opened 
               $uselegend = '';                     if ( !$imOpened && !$hasMultiRecs ) { 
               if ($latestDateSet && ($date - $mdate)/86400 > 1 && $counter > $counterCheck) {                         $messageIcon = 
                       $latestDateSet = 0;  qq~<img src="$imagesdir/$newload{'imclose'}" alt="$inmes_imtxt{'innotread'}" title="$inmes_imtxt{'innotread'}" />~; 
                       if ($lastWeekSet) {                     } 
                           $counterCheck = $counter if ($date - $mdate)/86400 <= 7;                     ## replied to 
                           $uselegend = 'oneweek';                     elsif ( $imRepliedTo && !$hasMultiRecs ) { 
                       }                         $messageIcon = 
               }  qq~<img src="$imagesdir/$IM_answered" alt="$inmes_imtxt{'08'}" title="$inmes_imtxt{'08'}" />~; 
                     }
               if ($lastWeekSet && ($date - $mdate)/86400 > 7 && $counter > $counterCheck) {                     ## opened 
                       $lastWeekSet = 0;                     elsif ( $imOpened && !$hasMultiRecs ) { 
                       if ($twoWeeksSet) {                         $messageIcon = 
                           $counterCheck = $counter if ($date - $mdate)/86400 <= 14;  qq~<img src="$imagesdir/$newload{'imopen'}" alt="$inmes_imtxt{'inread'}" title="$inmes_imtxt{'inread'}" />~; 
                           $uselegend = 'twoweeks';                     } 
                       }                     ## not opened multi 
               }                     elsif ( !$imOpened && $hasMultiRecs ) { 
                         $messageIcon =
               if ($twoWeeksSet && ($date - $mdate)/86400 > 14 && $counter > $counterCheck) {  qq~<img src="$imagesdir/$newload{'imclose2'}" alt="$inmes_imtxt{'inread'}" title="$inmes_imtxt{'inread'}" />~; 
                       $twoWeeksSet = 0;                     } 
                       if ($threeWeeksSet) {                     ## opened multi 
                           $counterCheck = $counter if ($date - $mdate)/86400 <= 21;                     elsif ( $imOpened && $hasMultiRecs ) { 
                           $uselegend = 'threeweeks';                         $messageIcon = 
                       }  qq~<img src="$imagesdir/$newload{'imopen2'}" alt="$inmes_imtxt{'inread'}" title="$inmes_imtxt{'inread'}" />~; 
               }                    }
                 }
               if ($threeWeeksSet && ($date - $mdate)/86400 > 21 && $counter > $counterCheck) {  
                       $threeWeeksSet = 0;                 ##  outbox 
                       if ($monthSet) {                elsif ( $action eq 'imoutbox' ) {
                           $counterCheck = $counter if ($date - $mdate)/86400 <= 31;                     ## not opened 
                           $uselegend = 'fourweeks';                     if ( !$imOpened && !$hasMultiRecs ) { 
                       }                         LoadUser($musernameto); 
               }                         if ( ${ $uid . $musernameto }{'notify_me'} < 2 
                             || $enable_notifications < 2 )
               if ($monthSet && ($date - $mdate)/86400 > 31 && $counter > $counterCheck) {                        {
                       $monthSet = 0;                             $messageIcon = 
                       if ($gtMonthSet) { $uselegend = 'older'; }  qq~<img src="$imagesdir/$newload{'imclose'}" alt="$inmes_imtxt{'outnotread'}" title="$inmes_imtxt{'outnotread'}" />~; 
               }                             $callBack = 
               $MCContent .= qq~  qq~<span class="small"><a href="$scripturl?action=imcb;rid=$messageid;receiver=$useraccount{$musernameto}" onclick="return confirm('$inmes_imtxt{'73'}')">$inmes_imtxt{'83'}</a> | </span>~; 
     <tr>                         } 
       <td class="titlebg"  width="100%" colspan="3"><span class="imgtitlebg">$im_sorted{$uselegend}</span></td>                         else { 
     </tr>                             $messageIcon = 
               ~ if $uselegend;  qq~<img src="$imagesdir/$newload{'imclose'}" alt="$inmes_imtxt{'outnotread'}" title="$inmes_imtxt{'outnotread'}" />~; 
           }                        }
                     }
           my $BCnew;                     ## opened 
           if ($action eq 'im' && $viewBMess && !${$username}{'PMbcRead' . $messageid}) {                    elsif ( $imOpened && !$hasMultiRecs ) {
               $BCnew = qq~&nbsp;<img src="$imagesdir/new.gif" alt="" border="0" style="vertical-align: middle;" />~;                         $messageIcon = 
           }                           $messageFlags =~ /c/ism 
                           ? qq~<img src="$imagesdir/$IM_callback"  alt="$inmes_imtxt{'callback'}" title="$inmes_imtxt{'callback'}" />~
           $MCContent .= qq~                           : qq~<img src="$imagesdir/$newload{'imopen'}"  alt="$inmes_imtxt{'outread'}" title="$inmes_imtxt{'outread'}" />~; 
     <tr>                     } 
       <td class="$class_PM_list" align="left">$BCnew$messageIcon$messIcon<a href="$scripturl?action=$actString;caller=$callerid;id=$messageid">$msub</a></td>  
       <td class="$class_PM_list">~;                     ## for multi rec, and none opened 
                     if ($hasMultiRecs) {
           if ($action eq 'im' || ($action eq 'imstorage' && $INFO{'viewfolder'} eq 'in')) {                         my ( $countrecepients, $countread, @receivers ); 
               if ($messageStatus eq 'g') {                         my $tousers = $musernameto; 
                   my ($guestName, $guestEmail) = split(/ /, $musername);                         if ($musernamecc)  { $tousers .= ",$musernamecc"; } 
                   $guestName =~ s/%20/ /g;                         if ($musernamebcc) { $tousers .= ",$musernamebcc"; } 
                   $usernamefrom = qq~$guestName<br />(<a href="mailto:$guestEmail">$guestEmail</a>)~;                         foreach my $recname ( split /,/xsm, $tousers ) { 
               } else {                             $countrecepients++; 
                   &LoadUser($musername); # is from user                             LoadUser($recname); 
                   $usernamefrom = ${$uid.$musername}{'realname'} ? qq~<a href="$scripturl?action=viewprofile;username=$useraccount{$musername}">${$uid.$musername}{'realname'}</a>~ : ($musername ? qq~$musername ($maintxt{'470a'})~ : $maintxt{'470a'}); # 470a == Ex-Member                             if ( 
               }                                 checkIMS( $recname, $messageid, 
               $MCContent .= $usernamefrom; # [inbox / broadcast / storage in]                                     'messageopened' ) 
                                 || ( ${ $uid . $recname }{'notify_me'} > 1
           } elsif ($action eq 'imoutbox' || ($action eq 'imstorage' && $INFO{'viewfolder'} eq 'out')) {                                     && $enable_notifications > 1 ) 
               my @usernameto;                               ) 
               if ($messageStatus eq 'gr') {                            {
                   my ($guestName, $guestEmail) = split(/ /, $musernameto);                                 $countread++; 
                   $guestName =~ s/%20/ /g;                             } 
                   $usernameto[0] = qq~$guestName<br />(<a href="mailto:$guestEmail">$guestEmail</a>)~;                             else { push @receivers, $useraccount{$recname}; } 
               } elsif ($messageStatus =~ /b/) {                         } 
                   foreach my $uname (split(/,/, $musernameto)) {                        if ( !$countread ) {
                       if ($uname eq 'all') { push(@usernameto, $inmes_txt{'bmallmembers'});                             $messageIcon = 
                       } elsif ($uname eq 'mods') { push(@usernameto, $inmes_txt{'bmmods'});  qq~<img src="$imagesdir/$newload{'imclose2'}" alt="$inmes_imtxt{'outmultinotread'}" title="$inmes_imtxt{'outmultinotread'}" />~; 
                       } elsif ($uname eq 'gmods') { push(@usernameto, $inmes_txt{'bmgmods'});                             $callBack = 
                       } elsif ($uname eq 'admins') { push(@usernameto, $inmes_txt{'bmadmins'});  qq~<span class="small"><a href="$scripturl?action=imcb;rid=$messageid;receiver=~ 
                       } else {                               . join( q{,}, @receivers ) 
                           my ($title, undef) = split(/\|/, $NoPost{$uname}, 2);                               . qq~" onclick="return confirm('$inmes_imtxt{'73'}')">$inmes_imtxt{'83'}</a> | </span>~; 
                           push(@usernameto, $title);                         } 
                       }                         elsif ( $countrecepients == $countread ) { 
                   }                             $messageIcon = 
               } else {                               $messageFlags =~ /c/ism 
                   my $uname = $musernameto; # is to user                               ? qq~<img src="$imagesdir/$IM_imcallback2" alt="$inmes_imtxt{'outmulticallback'}" title="$inmes_imtxt{'outmulticallback'}" />~ 
                   $uname .= ",$musernamecc" if $musernamecc;                               : qq~<img src="$imagesdir/$newload{'imopen2'}" alt="$inmes_imtxt{'outmultiread'}" title="$inmes_imtxt{'outmultiread'}" />~; 
                   if ($musernamebcc) {                         } 
                       if ($musername eq $username) {                        else {
                           $uname .= ",$musernamebcc";                             $messageIcon = 
                       } else {                               $messageFlags =~ /c/ism 
                           foreach (split(/,/, $musernamebcc)) {                               ? qq~<img src="$imagesdir/$IM_imcallback3" alt="$inmes_imtxt{'outsomemulticallback'}" title="$inmes_imtxt{'outsomemulticallback'}" />~ 
                               if ($_ eq $username) { $uname .= ",$username"; last; }                               : qq~<img src="$imagesdir/$IM_imopen3" alt="$inmes_imtxt{'outmultisomeread'}" title="$inmes_imtxt{'outmultisomeread'}" />~; 
                           }                             $callBack = 
                       }  qq~<span class="small"><a href="$scripturl?action=imshow;id=$messageid;caller=2">$inmes_imtxt{'multicallback'}</a> | </span>~; 
                   }                        }
                   foreach $uname (split(/,/, $uname)) {                     } 
                       &LoadUser($uname);                 } 
                       push(@usernameto, (${$uid.$uname}{'realname'} ? qq~<a href="$scripturl?action=viewprofile;username=$useraccount{$uname}">${$uid.$uname}{'realname'}</a>~ : ($uname ? qq~$uname ($maintxt{'470a'})~ : $maintxt{'470a'}))); # 470a == Ex-Member             } 
                   }  
               }             ## switch action if opening a draft - want this sending to the 'send' screen 
               $MCContent .= join(', ', @usernameto); # [outbox / storage out]             my $actString = 'imshow'; 
             if ( $action eq 'imdraft' ) { $actString = 'imsend'; }
           } elsif ($action eq 'imdraft') {  
               my @usernameto;             ## if grouping, check bar here 
               if ($messageStatus =~ /b/) {             $MCContent_stk   = q{}; 
                   foreach my $uname (split(/,/, $musernameto)) {             $MCContent_stk_i = q{}; 
                       if ($uname eq 'all') { push(@usernameto, $inmes_txt{'bmallmembers'});             if ( $stkmess && $sortBy ne 'gpdate' && $normDateSet && $viewBMess ) 
                       } elsif ($uname eq 'mods') { push(@usernameto, $inmes_txt{'bmmods'});             { 
                       } elsif ($uname eq 'gmods') { push(@usernameto, $inmes_txt{'bmgmods'});                 ## sticky messages 
                       } elsif ($uname eq 'admins') { push(@usernameto, $inmes_txt{'bmadmins'});                 $normDateSet   = 0; 
                       } else {                 $MCContent_stk = $my_sticky_mess; 
                           my ($title, undef) = split(/\|/, $NoPost{$uname}, 2);             } 
                           push(@usernameto, $title);  
                       }             if (   $stkmess 
                   }                 && $sortBy ne 'gpdate' 
               } else {                 && $stkDateSet 
                   my $uname = $musernameto; # is to user                 && $viewBMess 
                   $uname .= ",$musernamecc" if $musernamecc;                 && ( $messStatus =~ m/g/sm || $messStatus =~ m/a/sm ) ) 
                   if ($musernamebcc) {            {
                       if ($musername eq $username) {                 ## sticky messages 
                           $uname .= ",$musernamebcc";                 $stkDateSet      = 0; 
                       } else {                 $MCContent_stk_i = $my_sticky_mess_i; 
                           foreach (split(/,/, $musernamebcc)) {             } 
                               if ($_ eq $username) { $uname .= ",$username"; last; }  
                           }             if ( $sortBy eq 'gpdate' ) { 
                       }                 $uselegend = q{}; 
                   }                 if (   $latestDateSet 
                   foreach $uname (split(/,/, $uname)) {                     && ( $date - $mdate ) / 86400 > 1 
                       &LoadUser($uname);                     && $counter > $counterCheck ) 
                       push(@usernameto, (${$uid.$uname}{'realname'} ? qq~<a href="$scripturl?action=viewprofile;username=$useraccount{$uname}">${$uid.$uname}{'realname'}</a>~ : ($uname ? qq~$uname ($maintxt{'470a'})~ : $maintxt{'470a'}))); # 470a == Ex-Member                 { 
                   }                     $latestDateSet = 0; 
               }                     if ($lastWeekSet) { 
               $MCContent .= join(', ', @usernameto); # [draft]                         if ( ( $date - $mdate ) / 86400 <= 7 ) { 
                             $counterCheck = $counter;
           } else {                         } 
               my @usernameto;                         $uselegend = 'oneweek'; 
               if ($messageStatus eq 'g') {                     } 
                   my ($guestName, $guestEmail) = split(/ /, $musername);                 } 
                   $guestName =~ s/%20/ /g;  
                   $usernamefrom = qq~$guestName<br />(<a href="mailto:$guestEmail">$guestEmail</a>)~;                 if (   $lastWeekSet 
                     && ( $date - $mdate ) / 86400 > 7
                   my $uname = $musernameto; # is to user                     && $counter > $counterCheck ) 
                   $uname .= ",$musernamecc" if $musernamecc;                 { 
                   if ($musernamebcc) {                     $lastWeekSet = 0; 
                       if ($musername eq $username) {                    if ($twoWeeksSet) {
                           $uname .= ",$musernamebcc";                         if ( ( $date - $mdate ) / 86400 <= 14 ) { 
                       } else {                             $counterCheck = $counter; 
                           foreach (split(/,/, $musernamebcc)) {                         } 
                               if ($_ eq $username) { $uname .= ",$username"; last; }                         $uselegend = 'twoweeks'; 
                           }                    }
                       }                }
                   }  
                   foreach $uname (split(/,/, $uname)) {                 if (   $twoWeeksSet 
                       &LoadUser($uname);                     && ( $date - $mdate ) / 86400 > 14 
                       push(@usernameto, (${$uid.$uname}{'realname'} ? qq~<a href="$scripturl?action=viewprofile;username=$useraccount{$uname}">${$uid.$uname}{'realname'}</a>~ : ($uname ? qq~$uname ($maintxt{'470a'})~ : $maintxt{'470a'}))); # 470a == Ex-Member                     && $counter > $counterCheck ) 
                   }                 { 
                   $usernameto = join(', ', @usernameto);                     $twoWeeksSet = 0; 
                     if ($threeWeeksSet) {
               } elsif ($messageStatus eq 'gr') {                        if ( ( $date - $mdate ) / 86400 <= 21 ) {
                   my ($guestName, $guestEmail) = split(/ /, $musernameto);                             $counterCheck = $counter; 
                   $guestName =~ s/%20/ /g;                         } 
                   $usernameto = qq~$guestName<br />(<a href="mailto:$guestEmail">$guestEmail</a>)~;                         $uselegend = 'threeweeks'; 
                     }
                   &LoadUser($musername); # is from user                 } 
                   $usernamefrom = ${$uid.$musername}{'realname'} ? qq~<a href="$scripturl?action=viewprofile;username=$useraccount{$musername}">${$uid.$musername}{'realname'}</a>~ : ($musername ? qq~$musername ($maintxt{'470a'})~ : $maintxt{'470a'}); # 470a == Ex-Member  
                 if (   $threeWeeksSet
               } elsif ($messageStatus =~ /b/) {                     && ( $date - $mdate ) / 86400 > 21 
                   foreach my $uname (split(/,/, $musernameto)) {                     && $counter > $counterCheck ) 
                       if ($uname eq 'all') { push(@usernameto, $inmes_txt{'bmallmembers'});                 { 
                       } elsif ($uname eq 'mods') { push(@usernameto, $inmes_txt{'bmmods'});                     $threeWeeksSet = 0; 
                       } elsif ($uname eq 'gmods') { push(@usernameto, $inmes_txt{'bmgmods'});                     if ($monthSet) { 
                       } elsif ($uname eq 'admins') { push(@usernameto, $inmes_txt{'bmadmins'});                         if ( ( $date - $mdate ) / 86400 <= 31 ) { 
                       } else {                             $counterCheck = $counter; 
                           my ($title, undef) = split(/\|/, $NoPost{$uname}, 2);                         } 
                           push(@usernameto, $title);                         $uselegend = 'fourweeks'; 
                       }                    }
                   }                }
                   $usernameto = join(', ', @usernameto);  
                 if (   $monthSet
                   &LoadUser($musername); # is from user                     && ( $date - $mdate ) / 86400 > 31 
                   $usernamefrom = ${$uid.$musername}{'realname'} ? qq~<a href="$scripturl?action=viewprofile;username=$useraccount{$musername}">${$uid.$musername}{'realname'}</a>~ : ($musername ? qq~$musername ($maintxt{'470a'})~ : $maintxt{'470a'}); # 470a == Ex-Member                     && $counter > $counterCheck ) 
                 {
               } else {                     $monthSet = 0; 
                   my $uname = $musernameto; # is to user                     if ($gtMonthSet) { $uselegend = 'older'; } 
                   $uname .= ",$musernamecc" if $musernamecc;                 } 
                   if ($musernamebcc) {                 $MCContent_lgnd = q{}; 
                       if ($musername eq $username) {                if ($uselegend) {
                           $uname .= ",$musernamebcc";                     $MCContent_lgnd = $my_uselegend; 
                       } else {                     $MCContent_lgnd =~ 
                           foreach (split(/,/, $musernamebcc)) {                       s/{yabb sorted_legend}/$im_sorted{$uselegend}/sm; 
                               if ($_ eq $username) { $uname .= ",$username"; last; }                }
                           }            }
                       }  
                   }             my $BCnew; 
                   foreach $uname (split(/,/, $uname)) {             if (   $action eq 'im' 
                       &LoadUser($uname);                 && $viewBMess 
                       push(@usernameto, (${$uid.$uname}{'realname'} ? qq~<a href="$scripturl?action=viewprofile;username=$useraccount{$uname}">${$uid.$uname}{'realname'}</a>~ : ($uname ? qq~$uname ($maintxt{'470a'})~ : $maintxt{'470a'}))); # 470a == Ex-Member                 && !${$username}{ 'PMbcRead' . $messageid } ) 
                   }             { 
                   $usernameto = join(', ', @usernameto);                 $BCnew = qq~&nbsp;$micon{'new'}~; 
             }
                   &LoadUser($musername); # is from user             my $attachIcon; 
                   $usernamefrom = ${$uid.$musername}{'realname'} ? qq~<a href="$scripturl?action=viewprofile;username=$useraccount{$musername}">${$uid.$musername}{'realname'}</a>~ : ($musername ? qq~$musername ($maintxt{'470a'})~ : $maintxt{'470a'}); # 470a == Ex-Member             if ( $messageAttachment ne q{} ) { 
               }                 @im_attach_count = split /\,/xsm, $messageAttachment; 
               $MCContent .= qq~$usernamefrom / $usernameto~; #[store other]                 $imAttachCount = @im_attach_count; 
           }                 my $alt = 
           $MCContent .= qq~</td>                     $imAttachCount == 1 
       <td class="$class_PM_list">$mydate</td>                   ? $inmes_txt{'attach_3'} 
           ~;                   : $inmes_txt{'attach_2'}; 
                 $attachIcon =
           undef $quotecount;  qq~<img src="$micon_bg{'paperclip'}" alt="$inmes_txt{'attach_1'} $imAttachCount $alt" title="$inmes_txt{'attach_1'} $imAttachCount $alt" class="mc_clip" />~; 
           undef $codecount;             } 
           $quoteimg = '';  
           $codeimg = '';             $MCContent_BM = $my_BM_mess; 
             $MCContent_BM =~ s/{yabb class_PM_list}/$class_PM_list/gsm;
           if ($UseMenuType != 1) { $sepa = '&nbsp;|&nbsp;'; }             $MCContent_BM =~ s/{yabb MCContent_stk}/$MCContent_stk/sm; 
           else { $sepa = $menusep; }             $MCContent_BM =~ s/{yabb MCContent_stk_i}/$MCContent_stk_i/sm; 
           ## inline list for msg             $MCContent_BM =~ s/{yabb MCContent_lgnd}/$MCContent_lgnd/sm; 
           my ($actionsMenu, $actionsMenuselect, $storefolderView);             $MCContent_BM =~ s/{yabb BCnew}/$BCnew/sm; 
           $mreplyno++;             $MCContent_BM =~ s/{yabb messageIcon}/$messageIcon/sm; 
           ## build actionsMenu for output             $MCContent_BM =~ s/{yabb messIcon}/$messIcon/sm; 
           if ($action eq 'im' && !$viewBMess) {             $MCContent_BM =~ s/{yabb actString}/$actString/sm; 
               $actionsMenu = qq~<a href="$scripturl?action=imsend;caller=$callerid;quote=$mreplyno;to=$useraccount{$musername};id=$messageid">$inmes_txt{'145'}</a>$sepa<a href="$scripturl?action=imsend;caller=$callerid;reply=$mreplyno;to=$useraccount{$musername};id=$messageid">$inmes_txt{'146'}</a>$sepa<a href="$scripturl?action=imsend;caller=$callerid;forward=1;quote=$mreplyno;id=$messageid">$inmes_txt{'147'}</a>$sepa<a href="$scripturl?action=deletemultimessages;caller=$callerid;deleteid=$messageid" onclick="return confirm('$inmes_txt{'770'}')">$inmes_txt{'remove'}</a>~;             $MCContent_BM =~ s/{yabb callerid}/$callerid/sm; 
             $MCContent_BM =~ s/{yabb messageid}/$messageid/sm;
           ## broadcast messages can only be quoted on!             $MCContent_BM =~ s/{yabb msub}/$msub/sm; 
           } elsif ($action eq 'im' && $viewBMess) {             $MCContent_BM =~ s/{yabb attachIcon}/$attachIcon/sm; 
               if ($messageStatus eq 'g') {  
                   $actionsMenu = qq~<a href="$scripturl?action=imsend;caller=$callerid;quote=$mreplyno;replyguest=1;id=$messageid">$inmes_txt{'146'}</a>~;             if ( $action eq 'im' 
               } else {                 || ( $action eq 'imstorage' && $INFO{'viewfolder'} eq 'in' ) ) 
             {
                   $actionsMenu = qq~<a href="$scripturl?action=imsend;caller=$callerid;quote=$mreplyno;id=$messageid">$inmes_txt{'145'}</a>$sepa<a href="$scripturl?action=imsend;caller=$callerid;reply=$mreplyno;to=$useraccount{$musername};id=$messageid">$inmes_txt{'146'}</a>~;                 if ( $messStatus eq 'g' || $messStatus eq 'ga' ) { 
               }                     my ( $guestName, $guestEmail ) = split / /sm, $musername; 
               if ($iamadmin || $username eq $musername) {                     $guestName =~ s/%20/ /gsm; 
                   $actionsMenu .= qq~$sepa<a href="$scripturl?action=deletemultimessages;caller=$callerid;deleteid=$messageid" onclick="return confirm('$inmes_txt{'770'}')">$inmes_txt{'remove'}</a>~; $deleteButton = 1;                     $usernamefrom = 
               }  qq~$guestName<br />(<a href="mailto:$guestEmail">$guestEmail</a>)~; 
                 }
           ## for others                 else { 
           } elsif ($action eq 'imdraft') {                     LoadUser($musername);    # is from user 
               $actionsMenu = qq~<a href="$scripturl?action=deletemultimessages;caller=$callerid;deleteid=$messageid" onclick="return confirm('$inmes_txt{'770'}')">$inmes_txt{'remove'}</a>~;                     $usernamefrom = 
           } elsif ($action eq 'imoutbox') {                       ${ $uid . $musername }{'realname'} 
               $actionsMenu = qq~$callBack<a href="$scripturl?action=deletemultimessages;caller=$callerid;deleteid=$messageid" onclick="return confirm('$inmes_txt{'770'}')">$inmes_txt{'remove'}</a>~;                       ? qq~<a href="$scripturl?action=viewprofile;username=$useraccount{$musername}" rel="nofollow">$format_unbold{$musername}</a>~ 
           } else {                       : ( 
               if ($action eq 'imstorage') { $storefolderView = ";viewfolder=$INFO{'viewfolder'}"; }                           $musername ? qq~$musername ($maintxt{'470a'})~ 
               if ($messageStatus =~ /gr/) {                         : $maintxt{'470a'} 
                   $actionsMenu = qq~<a href="$scripturl?action=deletemultimessages;caller=$callerid;deleteid=$messageid$storefolderView" onclick="return confirm('$inmes_txt{'770'}')">$inmes_txt{'remove'}</a>~;                       );                     # 470a == Ex-Member 
               } else {                 } 
                   $actionsMenu = qq~$callBack<a href="$scripturl?action=imsend;caller=$callerid;quote=$mreplyno;to=$useraccount{$musername};id=$messageid">$inmes_txt{'145'}</a>$sepa<a href="$scripturl?action=imsend;caller=$callerid;reply=$mreplyno;to=$useraccount{$musername};id=$messageid">$inmes_txt{'146'}</a>$sepa<a href="$scripturl?action=imsend;caller=$callerid;forward=1;id=$messageid">$inmes_txt{'147'}</a>$sepa<a href="$scripturl?action=deletemultimessages;caller=$callerid;deleteid=$messageid$storefolderView" onclick="return confirm('$inmes_txt{'770'}')">$inmes_txt{'remove'}</a>~;                 $MCContent_from = 
               }                   $usernamefrom;             # [inbox / broadcast / storage in] 
           }  
           if (!$viewBMess || ($viewBMess && ($iamadmin || $username eq $musername))) {             } 
               $actionsMenuselect = qq~<input type="checkbox" name="message$messageid" id="message$messageid" class="$class_PM_list" value="1" style="cursor: hand;" /> <label for="message$messageid">$inmes_txt{'delete'}</label>~;             elsif ( $action eq 'imoutbox' 
               if ($action ne 'imdraft' && !$viewBMess) { $actionsMenuselect .= qq~/<label for="message$messageid">$inmes_imtxt{'store'}</label>~; }                 || ( $action eq 'imstorage' && $INFO{'viewfolder'} eq 'out' ) ) 
           }             { 
           $MCContent .= qq~                 my @usernameto; 
     </tr>                 if ( $messStatus eq 'gr' ) { 
                     my ( $guestName, $guestEmail ) = split / /sm, $musernameto;
     <tr>                     $guestName =~ s/%20/ /gsm; 
       <td colspan="3" height="21" class="$class_PM_list">                     $usernameto[0] = 
           ~;  qq~$guestName<br />(<a href="mailto:$guestEmail">$guestEmail</a>)~; 
                 }
           if (($enable_PMcontrols && ${$uid.$username}{'pmviewMess'}) || (!$enable_PMcontrols && $enable_PMviewMess && ${$uid.$username}{'pmviewMess'})) {                elsif ( $messStatus =~ /b/sm ) {
               if ($immessage =~ /\[quote(.*?)\]/isg) {  
                   $quoteimg = qq~<img src="$imagesdir\/quote.gif" alt="$inmes_imtxt{'69'}" title="$inmes_imtxt{'69'}" \/>&nbsp;~;                     @grps  = qw(all mods fmods gmods admins); 
                   $immessage =~ s/\[quote(.*?)\](.+?)\[\/quote\]//ig;                     @grps2 = qw(bmallmembers bmmods bmfmods bmgmods bmadmins); 
               }                     foreach my $uname ( split /,/xsm, $musernameto ) { 
               if ($immessage =~ /\[code\s*(.*?)\]/isg) {                        for my $grp ( 0 .. $#grps ) {
                   $codeimg = qq~<img src="$imagesdir\/code1.gif" alt="$inmes_imtxt{'84'}" title="$inmes_imtxt{'84'}" \/>&nbsp;~;                             if ( $uname eq $grps[$grp] ) { 
                   $immessage =~ s/\[code\s*(.*?)\](.+?)\[\/code\]//ig;                                 push @usernameto, $inmes_txt{ $grps2[$grp] }; 
               }                            }
               $immessage =~ s~<br.*?>~&nbsp;~gi;                         } 
               $immessage =~ s~&nbsp;&nbsp;~ ~g;                         if (   $uname ne 'all' 
               &ToChars($immessage);                             && $uname ne 'mods' 
               $immessage =~ s~\[.*?\]~~g;                             && $uname ne 'fmods' 
               &FromChars($immessage);                             && $uname ne 'gmods' 
               $convertstr = $immessage;                             && $uname ne 'admins' ) 
               $convertcut = 100;                         { 
               &CountChars;                             my ( $title, undef ) = 
               my $immessage = $convertstr;                               split /\|/xsm, $NoPost{$uname}, 2; 
               &ToChars($immessage);                             push @usernameto, $title; 
               if ($cliped) { $immessage .= "..."; }                        }
               $immessage = qq~$quoteimg$codeimg $immessage~;                     } 
               $immessage = &Censor($immessage);                 } 
               unless ($immessage =~ s/#nosmileys//isg) {                else {
                   $message = $immessage;                     my $uname = $musernameto;    # is to user 
                   if (!$yyYaBBCloaded) { require "$sourcedir/YaBBC.pl"; }                    if ($musernamecc) { $uname .= ",$musernamecc"; }
                   &MakeSmileys;                     if ($musernamebcc) { 
                   $immessage = $message;                         if ( $musername eq $username ) { 
               }                             $uname .= ",$musernamebcc"; 
               $MCContent .= qq~                         } 
       $immessage<br /><br />                         else { 
       <hr width="100%" class="hr" />                             foreach ( split /,/xsm, $musernamebcc ) { 
               ~;                                 if ( $_ eq $username ) { 
           }                                     $uname .= ",$username"; 
           $MCContent .= qq~                                     last; 
       <div style="float: left; text-align: left; width: 65%;"><span class="small">$actionsMenu</span></div>                                 } 
       <div style="float: right; text-align: right; width: 35%;"><span class="small">$actionsMenuselect</span></div>                             } 
       </td>                         } 
     </tr>~;                     } 
           $acount++;                     foreach my $uname ( split /,/xsm, $uname ) { 
           if ($acount == $stkmess +1) { $normDateSet = 1; }                         LoadUser($uname); 
       }                         push 
                           @usernameto,
                           (
                             ${ $uid . $uname }{'realname'}
                             ? qq~<a href="$scripturl?action=viewprofile;username=$useraccount{$uname}" rel="nofollow">$format_unbold{$uname}</a>~
                             : (
                                   $uname ? qq~$uname ($maintxt{'470a'})~
                                 : $maintxt{'470a'}
                             )
                           );    # 470a == Ex-Member
                     }
                 }
                 $MCContent_to_out = join q{, },
                   @usernameto;    # [outbox / storage out]
   
             }
             elsif ( $action eq 'imdraft' ) {
                 my @usernameto;
                 if ( $messStatus =~ /b/sm ) {
                     @grps  = qw(all mods fmods gmods admins);
                     @grps2 = qw(bmallmembers bmmods bmfmods bmgmods bmadmins);
                     foreach my $uname ( split /,/xsm, $musernameto ) {
                         for my $grp ( 0 .. $#grps ) {
                             if ( $uname eq $grps[$grp] ) {
                                 push @usernameto, $inmes_txt{ $grps2[$grp] };
                             }
                         }
                         if (   $uname ne 'all' 
                             && $uname ne 'mods' 
                             && $uname ne 'fmods' 
                             && $uname ne 'gmods' 
                             && $uname ne 'admins' )
                         {
                             my ( $title, undef ) =
                               split /\|/xsm, $NoPost{$uname}, 2;
                             push @usernameto, $title;
                         }
                     }
                 }
                 else {
                     my $uname = $musernameto;    # is to user
                     if ($musernamecc) { $uname .= ",$musernamecc"; }
                     if ($musernamebcc) {
                         if ( $musername eq $username ) {
                             $uname .= ",$musernamebcc";
                         }
                         else {
                             foreach ( split /,/xsm, $musernamebcc ) {
                                 if ( $_ eq $username ) {
                                     $uname .= ",$username";
                                     last;
                                 }
                             }
                         }
                     }
                     foreach my $uname ( split /,/xsm, $uname ) {
                         LoadUser($uname);
                         push
                           @usernameto,
                           (
                             ${ $uid . $uname }{'realname'}
                             ? qq~<a href="$scripturl?action=viewprofile;username=$useraccount{$uname}" rel="nofollow">$format_unbold{$uname}</a>~
                             : (
                                   $uname ? qq~$uname ($maintxt{'470a'})~
                                 : $maintxt{'470a'}
                             )
                           );    # 470a == Ex-Member
                     }
                 }
                 $MCContent_to_out = join q{, }, @usernameto;    # [draft]
   
             }
             else {
                 my @usernameto;
                 if ( $messStatus eq 'g' || $messStatus eq 'ga' ) {
                     my ( $guestName, $guestEmail ) = split / /sm, $musername;
                     $guestName =~ s/%20/ /gsm;
                     $usernamefrom =
  qq~$guestName<br />(<a href="mailto:$guestEmail">$guestEmail</a>)~;
   
                     my $uname = $musernameto;                   # is to user
                     if ($musernamecc) { $uname .= ",$musernamecc"; }
                     if ($musernamebcc) {
                         if ( $musername eq $username ) {
                             $uname .= ",$musernamebcc";
                         }
                         else {
                             foreach ( split /,/xsm, $musernamebcc ) {
                                 if ( $_ eq $username ) {
                                     $uname .= ",$username";
                                     last;
                                 }
                             }
                         }
                     }
                     foreach my $uname ( split /,/xsm, $uname ) {
                         LoadUser($uname);
                         push
                           @usernameto,
                           (
                             ${ $uid . $uname }{'realname'}
                             ? qq~<a href="$scripturl?action=viewprofile;username=$useraccount{$uname}" rel="nofollow">$format_unbold{$uname}</a>~
                             : (
                                   $uname ? qq~$uname ($maintxt{'470a'})~
                                 : $maintxt{'470a'}
                             )
                           );    # 470a == Ex-Member
                     }
                     $usernameto = join q{, }, @usernameto;
   
                 }
                 elsif ( $messStatus eq 'gr' ) {
                     my ( $guestName, $guestEmail ) = split / /sm, $musernameto;
                     $guestName =~ s/%20/ /gsm;
                     $usernameto =
  qq~$guestName<br />(<a href="mailto:$guestEmail">$guestEmail</a>)~;
   
                     LoadUser($musername);    # is from user
                     $usernamefrom =
                       ${ $uid . $musername }{'realname'}
                       ? qq~<a href="$scripturl?action=viewprofile;username=$useraccount{$musername}" rel="nofollow">$format_unbold{$musername}</a>~
                       : (
                           $musername ? qq~$musername ($maintxt{'470a'})~
                         : $maintxt{'470a'}
                       );                     # 470a == Ex-Member
   
                 }
                 elsif ( $messStatus =~ /b/sm ) {
                     @grps  = qw(all mods fmods gmods admins);
                     @grps2 = qw(bmallmembers bmmods bmfmods bmgmods bmadmins);
                     foreach my $uname ( split /,/xsm, $musernameto ) {
                         for my $grp ( 0 .. $#grps ) {
                             if ( $uname eq $grps[$grp] ) {
                                 push @usernameto, $inmes_txt{ $grps2[$grp] };
                             }
                         }
                         if (   $uname ne 'all' 
                             && $uname ne 'mods' 
                             && $uname ne 'fmods' 
                             && $uname ne 'gmods' 
                             && $uname ne 'admins' )
                         {
                             my ( $title, undef ) =
                               split /\|/xsm, $NoPost{$uname}, 2;
                             push @usernameto, $title;
                         }
                     }
                     $usernameto = join q{, }, @usernameto;
   
                     LoadUser($musername);    # is from user
                     $usernamefrom =
                       ${ $uid . $musername }{'realname'}
                       ? qq~<a href="$scripturl?action=viewprofile;username=$useraccount{$musername}" rel="nofollow">$format_unbold{$musername}</a>~
                       : (
                           $musername ? qq~$musername ($maintxt{'470a'})~
                         : $maintxt{'470a'}
                       );                     # 470a == Ex-Member
                 }
                 else {
                     my $uname = $musernameto;    # is to user
                     if ($musernamecc) { $uname .= ",$musernamecc"; }
                     if ($musernamebcc) {
                         if ( $musername eq $username ) {
                             $uname .= ",$musernamebcc";
                         }
                         else {
                             foreach ( split /,/xsm, $musernamebcc ) {
                                 if ( $_ eq $username ) {
                                     $uname .= ",$username";
                                     last;
                                 }
                             }
                         }
                     }
                     foreach my $uname ( split /,/xsm, $uname ) {
                         LoadUser($uname);
                         push
                           @usernameto,
                           (
                             ${ $uid . $uname }{'realname'}
                             ? qq~<a href="$scripturl?action=viewprofile;username=$useraccount{$uname}" rel="nofollow">$format_unbold{$uname}</a>~
                             : (
                                   $uname ? qq~$uname ($maintxt{'470a'})~
                                 : $maintxt{'470a'}
                             )
                           );    # 470a == Ex-Member
                     }
                     $usernameto = join q{, }, @usernameto;
   
                     LoadUser($musername);    # is from user
                     $usernamefrom =
                       ${ $uid . $musername }{'realname'}
                       ? qq~<a href="$scripturl?action=viewprofile;username=$useraccount{$musername}" rel="nofollow">$format_unbold{$musername}</a>~
                       : (
                           $musername ? qq~$musername ($maintxt{'470a'})~
                         : $maintxt{'470a'}
                       );                     # 470a == Ex-Member
                 }
                 $MCContent_to .= qq~$usernamefrom / $usernameto~; #[store other]
             }
   
             undef $quotecount;
             undef $codecount;
             $quoteimg = q{};
             $codeimg  = q{};
   
             my $attachDeleteWarn;
             chomp $messageAttachment;
             if (
                 (
                        $action eq 'imdraft' 
                     || $action eq 'imoutbox' 
                     || $action eq 'imstorage' 
                 )
                 && $messageAttachment ne q{}
               )
             {
   
                 foreach ( split /,/xsm, $messageAttachment ) {
                     my ( $pmAttachFile, $pmAttachUser ) = split /~/xsm, $_;
                     if ( $username eq $pmAttachUser
                         && -e "$pmuploaddir/$pmAttachFile" )
                     {
                         $attachDeleteWarn = $inmes_txt{'770a'};
                     }
                 }
             }
   
             if   ( $UseMenuType != 1 ) { $sepa = '&nbsp;|&nbsp;'; }
             else                       { $sepa = $menusep; }
             ## inline list for msg
             my ( $actionsMenu, $actionsMenuselect, $storefolderView );
             $mreplyno++;
             ## build actionsMenu for output
             if ( $action eq 'im' && !$viewBMess ) {
                 if ( $messStatus eq 'g' || $messStatus eq 'ga' ) {
                     $actionsMenu =
  qq~<a href="$scripturl?action=imsend;caller=$callerid;reply=$mreplyno;replyguest=1;id=$messageid">$inmes_txt{'146'}</a>
  $sepa<a href="$scripturl?action=imsend;caller=$callerid;forward=1;quote=$mreplyno;id=$messageid">$inmes_txt{'147'}</a>
  $sepa<a href="$scripturl?action=deletemultimessages;caller=$callerid;deleteid=$messageid" onclick="return confirm('$inmes_txt{'770'}')">$inmes_txt{'remove'}</a>~;
                 }
                 else {
                     $actionsMenu =
  qq~<a href="$scripturl?action=imsend;caller=$callerid;quote=$mreplyno;to=$useraccount{$musername};id=$messageid">$inmes_txt{'145'}</a>$sepa<a href="$scripturl?action=imsend;caller=$callerid;reply=$mreplyno;to=$useraccount{$musername};id=$messageid">$inmes_txt{'146'}</a>$sepa<a href="$scripturl?action=imsend;caller=$callerid;forward=1;quote=$mreplyno;id=$messageid">$inmes_txt{'147'}</a>$sepa<a href="$scripturl?action=deletemultimessages;caller=$callerid;deleteid=$messageid" onclick="return confirm('$inmes_txt{'770'}')">$inmes_txt{'remove'}</a>~;
   
                     ## broadcast messages can only be quoted on!
                 }
             }
             elsif ( $action eq 'im' && $viewBMess ) {
                 if ( $messStatus eq 'g' || $messStatus eq 'ga' ) {
                     $actionsMenu =
  qq~<a href="$scripturl?action=imsend;caller=$callerid;quote=$mreplyno;replyguest=1;id=$messageid">$inmes_txt{'146'}</a>~;
                 }
                 else {
                     $actionsMenu =
  qq~<a href="$scripturl?action=imsend;caller=$callerid;quote=$mreplyno;id=$messageid">$inmes_txt{'145'}</a>$sepa<a href="$scripturl?action=imsend;caller=$callerid;reply=$mreplyno;to=$useraccount{$musername};id=$messageid">$inmes_txt{'146'}</a>~;
                 }
                 if ( $iamadmin || $username eq $musername ) {
                     $actionsMenu .=
  qq~$sepa<a href="$scripturl?action=deletemultimessages;caller=$callerid;deleteid=$messageid" onclick="return confirm('$inmes_txt{'770'}')">$inmes_txt{'remove'}</a>~;
                     $deleteButton = 1;
                 }
   
                 ## for others
             }
             elsif ( $action eq 'imdraft' ) {
                 $actionsMenu =
  qq~<a href="$scripturl?action=deletemultimessages;caller=$callerid;deleteid=$messageid" onclick="return confirm('$inmes_txt{'770'}$attachDeleteWarn')">$inmes_txt{'remove'}</a>~;
             }
             elsif ( $action eq 'imoutbox' ) {
                 $actionsMenu =
  qq~$callBack<a href="$scripturl?action=deletemultimessages;caller=$callerid;deleteid=$messageid" onclick="return confirm('$inmes_txt{'770'}$attachDeleteWarn')">$inmes_txt{'remove'}</a>~;
             }
             else {
                 if ( $action eq 'imstorage' ) {
                     $storefolderView = ";viewfolder=$INFO{'viewfolder'}";
                 }
                 if ( $messStatus =~ /gr/sm ) {
                     $actionsMenu =
  qq~<a href="$scripturl?action=deletemultimessages;caller=$callerid;deleteid=$messageid$storefolderView" onclick="return confirm('$inmes_txt{'770'}')">$inmes_txt{'remove'}</a>~;
                 }
                 elsif ( $messStatus eq 'g' || $messStatus eq 'ga' ) {
                     $actionsMenu =
  qq~<a href="$scripturl?action=imsend;caller=$callerid;quote=$mreplyno;replyguest=1;id=$messageid">$inmes_txt{'146'}</a>~;
                 }
                 else {
                     $actionsMenu =
  qq~$callBack<a href="$scripturl?action=imsend;caller=$callerid;quote=$mreplyno;to=$useraccount{$musername};id=$messageid">$inmes_txt{'145'}</a>$sepa<a href="$scripturl?action=imsend;caller=$callerid;reply=$mreplyno;to=$useraccount{$musername};id=$messageid">$inmes_txt{'146'}</a>$sepa<a href="$scripturl?action=imsend;caller=$callerid;forward=1;id=$messageid">$inmes_txt{'147'}</a>$sepa<a href="$scripturl?action=deletemultimessages;caller=$callerid;deleteid=$messageid$storefolderView" onclick="return confirm('$inmes_txt{'770'}$attachDeleteWarn')">$inmes_txt{'remove'}</a>~;
                 }
             }
             if ( !$viewBMess
                 || ( $viewBMess && ( $iamadmin || $username eq $musername ) ) )
             {
                 $actionsMenuselect =
  qq~<input type="checkbox" name="message$messageid" id="message$messageid" class="cursor $class_PM_list" value="1" /> <label for="message$messageid">$inmes_txt{'delete'}</label>~;
                 if ( $action ne 'imdraft' && !$viewBMess ) {
                     $actionsMenuselect .=
  qq~/<label for="message$messageid">$inmes_imtxt{'store'}</label>~;
                 }
             }
             if ( ${ $uid . $username }{'pmviewMess'} ) {
                 if ( $immessage =~ /\[quote(.*?)\]/isgm ) {
                     $quoteimg =
  qq~<img src="$imagesdir/$IM_quote" alt="$inmes_imtxt{'69'}" title="$inmes_imtxt{'69'}" />&nbsp;~;
                     $immessage =~ s/\[quote(.*?)\](.+?)\[\/quote\]//igsm;
                 }
                 if ( $immessage =~ /\[code\s*(.*?)\]/isgm ) {
                     $codeimg =
  qq~<img src="$imagesdir/$IM_code1" alt="$inmes_imtxt{'84'}" title="$inmes_imtxt{'84'}" />&nbsp;~;
                     $immessage =~ s/\[code\s*(.*?)\](.+?)\[\/code\]//igsm;
                 }
                 $immessage =~ s/<br.*?>/&nbsp;/gism;
                 $immessage =~ s/&nbsp;&nbsp;/ /gsm;
                 ToChars($immessage);
                 $immessage =~ s/\[.*?\]//gsm;
                 FromChars($immessage);
                 $convertstr = $immessage;
                 $convertcut = 100;
                 CountChars();
                 $immessage = $convertstr;
                 ToChars($immessage);
                 if ($cliped) { $immessage .= q{...}; }
                 $immessage = qq~$quoteimg$codeimg $immessage~;
                 $immessage = Censor($immessage);
   
                 if ( $immessage !~ s/\x23nosmileys//isgm ) {
                     $message = $immessage;
                     enable_yabbc();
                     MakeSmileys();
                     $immessage = $message;
                 }
                 $MCContent_mymess = $my_immessage;
                 $MCContent_mymess =~ s/{yabb immessage}/$immessage/sm;
             }
             $MCContent_im .= $my_IM_show;
             $MCContent_im =~ s/{yabb MCContent_BM}/$MCContent_BM/sm;
             $MCContent_im =~ s/{yabb class_PM_list}/$class_PM_list/gsm;
             $MCContent_im =~ s/{yabb MCContent_to}/$MCContent_to/sm;
             $MCContent_im =~ s/{yabb MCContent_from}/$MCContent_from/sm;
             $MCContent_im =~ s/{yabb MCContent_to_out}/$MCContent_to_out/sm;
             $MCContent_im =~ s/{yabb mydate}/$mydate/sm;
             $MCContent_im =~ s/{yabb class_PM_list}/$class_PM_list/gsm;
             $MCContent_im =~ s/{yabb MCContent_mymess}/$MCContent_mymess/sm;
             $MCContent_im =~ s/{yabb actionsMenu}/$actionsMenu/sm;
             $MCContent_im =~ s/{yabb actionsMenuselect}/$actionsMenuselect/sm;
   
             $acount++;
             if ( $acount == $stkmess + 1 ) { $normDateSet = 1; }
         }
################ end of message loop ################### ################ end of message loop ###################
   
       ## limiter bar        ## limiter bar
       if ($enable_imlimit == 1 && !$viewBMess) {        if ( $enable_imlimit == 1 && !$viewBMess ) {
           my $impercent = 0;            my $impercent      = 0;
           my $imbar = 0;            my $imbar          = 0;
           my $imrest = 0;            my $imrest         = 0;
           my $messageCounter = @dimmessages;            my $messageCounter = @dimmessages;
           if ($action eq 'im' && !$viewBMess) {            if ( $action eq 'im' && !$viewBMess ) {
               if ($messageCounter != 0 && $numibox != 0) {                if ( $messageCounter != 0 && $numibox != 0 ) {
                   $impercent = int(100 / $numibox * $messageCounter);                     $impercent = int( 100 / $numibox * $messageCounter ); 
                   $imbar = int(200 / $numibox * $messageCounter);                     $imbar     = int( 200 / $numibox * $messageCounter ); 
               }                }
   
               $intext = qq~($inmes_imtxt{'13'} $messageCounter $inmes_imtxt{'01'} $numibox $inmes_imtxt{'19'} $inmes_txt{'inbox'} $inmes_txt{'folder'})~;                 $intext = 
           }  qq~($inmes_imtxt{'13'} $messageCounter $inmes_imtxt{'01'} $numibox $inmes_imtxt{'19'} $inmes_txt{'inbox'} $inmes_txt{'folder'})~; 
             }
           elsif ($action eq 'imoutbox') {  
               if ($messageCounter != 0 && $numobox != 0) {            elsif ( $action eq 'imoutbox' ) {
                   $impercent = int(100 / $numobox * $messageCounter);                 if ( $messageCounter != 0 && $numobox != 0 ) { 
                   $imbar = int(200 / $numobox * $messageCounter);                     $impercent = int( 100 / $numobox * $messageCounter ); 
               }                     $imbar     = int( 200 / $numobox * $messageCounter ); 
               $intext = qq~($inmes_imtxt{'13'} $messageCounter $inmes_imtxt{'01'} $numobox $inmes_imtxt{'19'} $inmes_txt{'outbox'} $inmes_txt{'folder'})~;                 } 
           }                 $intext = 
  qq~($inmes_imtxt{'13'} $messageCounter $inmes_imtxt{'01'} $numobox $inmes_imtxt{'19'} $inmes_txt{'outbox'} $inmes_txt{'folder'})~;
           elsif ($action eq 'imdraft') {             } 
               if ($messageCounter != 0 && $numdraft != 0) {  
                   $impercent = int(100 / $numdraft * $messageCounter);             elsif ( $action eq 'imdraft' ) { 
                   $imbar = int(200 / $numdraft * $messageCounter);                 if ( $messageCounter != 0 && $numdraft != 0 ) { 
               }                     $impercent = int( 100 / $numdraft * $messageCounter ); 
               $intext = qq~($inmes_imtxt{'13'} $messageCounter $inmes_imtxt{'01'} $numdraft $inmes_imtxt{'19'} $inmes_txt{'draft'} $inmes_txt{'folder'})~;                     $imbar     = int( 200 / $numdraft * $messageCounter ); 
           }                }
           elsif ($action eq 'imstorage') {                 $intext = 
               if ($messageCounter != 0 && $numstore != 0) {  qq~($inmes_imtxt{'13'} $messageCounter $inmes_imtxt{'01'} $numdraft $inmes_imtxt{'19'} $inmes_txt{'draft'} $inmes_txt{'folder'})~; 
                   $impercent = int(100 / $numstore * $messageCounter);             } 
                   $imbar = int(200 / $numstore * $messageCounter);             elsif ( $action eq 'imstorage' ) { 
               }                 if ( $messageCounter != 0 && $numstore != 0 ) { 
               $intext = qq~($inmes_imtxt{'13'} $messageCounter $inmes_imtxt{'01'} $numstore $inmes_imtxt{'19'} $inmes_txt{'storage'} $inmes_txt{'folder'})~;                     $impercent = int( 100 / $numstore * $messageCounter ); 
           }                     $imbar     = int( 200 / $numstore * $messageCounter ); 
           $imrest = 200 - $imbar;                 } 
           if ($imbar > 200) { $imbar  = 200; }                 $intext = 
           if ($imrest <= 0) { $dorest = ''; }  qq~($inmes_imtxt{'13'} $messageCounter $inmes_imtxt{'01'} $numstore $inmes_imtxt{'19'} $inmes_txt{'storage'} $inmes_txt{'folder'})~; 
           else { $dorest = qq~<img src="$imagesdir/usageempty.gif" height="8" width="$imrest" align="middle" alt="" />~; }            }
           $imbargfx = qq~$inmes_imtxt{'67'}:&nbsp;<img src="$imagesdir/usage.gif" align="middle" alt="" /><img src="$imagesdir/usagebar.gif" height="8" width="$imbar" align="middle" alt="" />$dorest<img src="$imagesdir/usage.gif" align="middle" alt="" />&nbsp;$impercent&nbsp;%&nbsp;<br />~;             $imrest = 200 - $imbar; 
       } else {             if ( $imbar > 200 ) { $imbar  = 200; } 
           $intext = qq~&nbsp;~;             if ( $imrest <= 0 ) { $dorest = q{}; } 
           $imbargfx = qq~&nbsp;~;             else { 
       }                 $dorest = 
       unless ($action eq 'imstorage' && $INFO{'viewfolder'} eq '') {  qq~<img src="$imagesdir/$IM_usageempty" height="8" width="$imrest" alt="" />~; 
           $removeButton = qq~<input type="submit" name="imaction" value="$inmes_txt{'remove'}" class="button" onclick="return confirm('$inmes_txt{'delmultipms'}');" />~;             } 
           $inmes_txt{'777'} =~ s/REMOVE/$removeButton/;             $imbargfx = 
           $removeButton = $inmes_txt{'777'};  qq~$inmes_imtxt{'67'}:&nbsp;<img src="$imagesdir/$IM_usage" alt="" /><img src="$imagesdir/$IM_usagebar" height="8" width="$imbar" alt="" />$dorest<img src="$imagesdir/$IM_usage" alt="" />&nbsp;$impercent&nbsp;%&nbsp;<br />~; 
       }        }
       if (@dimmessages) {        else {
           $MCContent .= qq~             $intext   = q~&nbsp;~; 
     <tr>             $imbargfx = q~&nbsp;~; 
       <td class="titlebg" colspan="3" align="right" height="21" >         } 
           ~;         if ( $action ne 'imstorage' || $INFO{'viewfolder'} ne q{} ) { 
           if (!$viewBMess) {            if ( $mAttachDeleteSet == 1 && $action ne 'im' ) {
               $MCContent .= qq~                 $mAttachDeleteWarn = $inmes_txt{'770b'}; 
       <span  class="small"><b>$imbargfx&nbsp;$intext<br /><br /></b></span>~;             } 
               unless ($action eq 'imstorage' && $INFO{'viewfolder'} eq '') { $MCContent .= $movebutton; }             $removeButton = 
           }  qq~<input type="submit" name="imaction" value="$inmes_txt{'remove'}" class="button" onclick="return confirm('$inmes_txt{'delmultipms'}$mAttachDeleteWarn');" />~; 
           if (!$viewBMess || ($viewBMess && ($iamadmin|| $deleteButton))) {             $inmes_txt{'777'} =~ s/REMOVE/$removeButton/sm; 
               $MCContent .= qq~ $removeButton~;             $removeButton = $inmes_txt{'777'}; 
           }        }
           $MCContent .= qq~         if (@dimmessages) { 
       </td>             if ( !$viewBMess ) { 
     </tr>                 if ( $imbargfx || $intext ) { 
           ~;                     $MCContent_dima = qq~ 
         <span class="small"><b>$imbargfx&nbsp;$intext</b><br /><br /></span>~;
           if ((!$viewBMess || ($viewBMess && ($iamadmin || $deleteButton))) && !($action eq 'imstorage' && $INFO{'viewfolder'} eq '')) {                 } 
               $MCContent .= qq~                 if ( $action ne 'imstorage' || $INFO{'viewfolder'} ne q{} ) { 
     <tr>                     $MCContent_dima .= $movebutton; 
       <td class="windowbg" colspan="3" align="right">                 } 
       <div style="float: right;">             } 
         <label for="delete_store"><i>$inmes_txt{'737'}</i></label>&nbsp;<input type="checkbox" id="delete_store" name="delete_store" onclick="if (this.checked) checkAll(); else uncheckAll();" />             if ( !$viewBMess 
       </div>                 || ( $viewBMess && ( $iamadmin || $deleteButton ) ) ) 
       <br />             { 
       <script language="JavaScript1.2" type="text/javascript">                 $MCContent_dima .= qq~ $removeButton<br /><br />~; 
           <!--             } 
           function checkAll() {             $MCContent_dim = $my_dimmessages; 
               for (var i = 0; i < document.searchform.elements.length; i++) {             $MCContent_dim =~ s/{yabb MCContent_dima}/$MCContent_dima/sm; 
                   document.searchform.elements[i].checked = true;  
               }             if ( 
           }                 ( 
           function uncheckAll() {                     !$viewBMess 
                     || ( $viewBMess && ( $iamadmin || $deleteButton ) )
               for (var i = 0; i < document.searchform.elements.length; i++) {                 ) 
               document.searchform.elements[i].checked = false;                 && !( $action eq 'imstorage' && $INFO{'viewfolder'} eq q{} ) 
               }               ) 
           }             { 
           // -->                 $MCContent_del = $my_delstore; 
       </script>             } 
       </td>         } 
     </tr>~;     } 
           }     $mctitle = $IM_box; 
       }     $MCContent .= $my_IMblock_top; 
       $MCContent .= qq~     $MCContent =~ s/{yabb MCContent_page}/$MCContent_page/sm; 
       </table>     $MCContent =~ s/{yabb MCContent_view}/$MCContent_view/sm; 
       ~;     $MCContent =~ s/{yabb MCContent_no_mess}/$MCContent_no_mess/sm; 
   }     $MCContent =~ s/{yabb MCContent_sort}/$MCContent_sort/sm; 
     $MCContent =~ s/{yabb MCContent_im}/$MCContent_im/sm;
     $MCContent =~ s/{yabb mytopdisp}/$mytopdisp/sm;
     $MCContent =~ s/{yabb MCContent_selmen}/$MCContent_selmen/gsm;
     $MCContent =~ s/{yabb MCContent_del}/$MCContent_del/sm;
     $MCContent =~ s/{yabb MCContent_dim}/$MCContent_dim/sm;
     return $MCContent;
} }
   
# load user's buddylist and show status of said members # load user's buddylist and show status of said members
sub LoadBuddyList { sub LoadBuddyList {
   # Load background color list  
   my @cssvalues = ('windowbg2', 'windowbg');     # Load background color list 
   my $cssnum = @cssvalues;     my @cssvalues = qw ( windowbg2 windowbg ); 
   my $counter = 0;     my $cssnum    = @cssvalues; 
     my $counter   = 0;
   my @buddies = split('\|',${$uid.$username}{'buddylist'});  
   chomp @buddies;     my @buddies = split /\|/xsm, ${ $uid . $username }{'buddylist'}; 
   $buddiesCurrentStatus = qq~     chomp @buddies; 
       <table cellspacing="1" cellpadding="1" width="100%" align="center" border="0">     $buddiesCurrentStatus = $my_buddiesCurrentStatus; 
       <tr class="catbg"><td align="center">$profile_txt{'68a'}</td><td align="center">$profile_txt{'68b'}</td><td align="center"><img src="$imagesdir/imclose.gif" border="0" alt="$profile_txt{'69a'}" title="$profile_txt{'69a'}" /></td><td align="center"><img src="$imagesdir/email.gif" border="0" alt="$profile_txt{'69'}" title="$profile_txt{'69'}" /></td><td align="center"><img src="$imagesdir/www.gif" border="0" alt="$profile_txt{'96'}" title="$profile_txt{'96'}" /></td></tr>  
   ~;     foreach my $buddyname (@buddies) { 
   foreach my $buddyname (@buddies) {         $css = $cssvalues[ ( $counter % $cssnum ) ]; 
       $css = $cssvalues[($counter % $cssnum)];         my ($buddyrealname); 
       my ($buddyrealname);         my ( $online, $buddyemail, $buddypm, $buddywww ) = '&nbsp;'; 
       my ($online, $buddyemail, $buddypm, $buddywww) = '&nbsp;';         if ( -e "$memberdir/$buddyname.vars" ) { 
       if (-e "$memberdir/$buddyname.vars") {             LoadUser($buddyname); 
           &LoadUser($buddyname);             $online        = userOnLineStatus($buddyname); 
           $online = &userOnLineStatus($buddyname);             $buddyrealname = ${ $uid . $buddyname }{'realname'}; 
           $buddyrealname = ${$uid.$buddyname}{'realname'};             $usernamelink  = $link{$buddyname}; 
           $usernamelink = $link{$buddyname};  
             if (   ${ $uid . $buddyname }{'hidemail'}
           if (${$uid.$buddyname}{'hidemail'} && !$iamadmin && $allow_hide_email == 1) {                 && !$iamadmin 
               $buddyemail = qq~<img src="$imagesdir/lockmail.gif" alt="$mycenter_txt{'hiddenemail'}" title="$mycenter_txt{'hiddenemail'}" />~;                 && $allow_hide_email == 1 ) 
           } else {            {
               $buddyemail = qq~<a href="mailto:${$uid.$buddyname}{'email'}"><img src="$imagesdir/email.gif" border="0" alt="$profile_txt{'889'} ${$uid.$buddyname}{'email'}" title="$profile_txt{'889'} ${$uid.$buddyname}{'email'}" /></a>~;                 $buddyemail = 
           }  qq~<img src="$micon_bg{'lockmail'}" alt="$mycenter_txt{'hiddenemail'}" title="$mycenter_txt{'hiddenemail'}" />~; 
             }
           &CheckUserPM_Level($buddyname);             else { 
           if ($PM_level == 1 || ($PM_level == 2 && $UserPM_Level{$buddyname} > 1 && ($iamadmin || $iamgmod || $iammod)) || ($PM_level == 3 && $UserPM_Level{$buddyname} == 3 && ($iamadmin || $iamgmod))) {                 $buddyemail = 
               $buddypm = qq~<a href="$scripturl?action=imsend;to=$useraccount{$buddyname}"><img src="$imagesdir/imclose.gif" border="0" alt="$profile_txt{'688'} $buddyrealname" title="$profile_txt{'688'} $buddyrealname" /></a>~; qq~<a href="mailto:${$uid.$buddyname}{'email'}"><img src="$micon_bg{'email'}" alt="$profile_txt{'889'} ${$uid.$buddyname}{'email'}" title="$profile_txt{'889'} ${$uid.$buddyname}{'email'}" /></a>~;
           }            }
   
           if (${$uid.$buddyname}{'weburl'}) {             CheckUserPM_Level($buddyname); 
               $buddywww = qq~<a href="${$uid.$buddyname}{'weburl'}" target="_blank"><img src="$imagesdir/www.gif" border="0" alt="${$uid.$buddyname}{'webtitle'}" title="${$uid.$buddyname}{'webtitle'}" /></a>~;             if ( 
           }                    $PM_level == 1 
                 || ( $PM_level == 2 && $UserPM_Level{$buddyname} > 1 && $staff )
       } else {                 || (   $PM_level == 3 
           $usernamelink = $mycenter_txt{'buddydeleted'}; # Ex-Member                     && $UserPM_Level{$buddyname} == 3 
       }                     && ( $iamadmin || $iamgmod ) ) 
       $buddiesCurrentStatus .= qq~<tr class="$css"><td align="left">$usernamelink</td><td align="center">$online</td><td align="center">$buddypm</td><td align="center">$buddyemail</td><td align="center">$buddywww</td></tr>~;                 || (   $PM_level == 4 
       $counter++;                     && $UserPM_Level{$buddyname} == 4 
   }                     && ( $iamadmin || $iamgmod || $iamfmod ) ) 
   undef %UserPM_Level;               ) 
   $buddiesCurrentStatus .= "</table>";             { 
   return $buddiesCurrentStatus;                 $buddypm = 
  qq~<a href="$scripturl?action=imsend;to=$useraccount{$buddyname}"><img src="$imagesdir/$newload{'imclose'}"  alt="$profile_txt{'688'} $buddyrealname" title="$profile_txt{'688'} $buddyrealname" /></a>~;
             }
   
             if ( !$minlinkweb ) { $minlinkweb = 0; }
             if (
                 ${ $uid . $buddyname }{'weburl'}
                 && (   ${ $uid . $buddyname }{'postcount'} >= $minlinkweb
                     || ${ $uid . $buddyname }{'position'} eq 'Administrator' 
                     || ${ $uid . $buddyname }{'position'} eq 'Global Moderator' 
                     || ${ $uid . $buddyname }{'position'} eq 'Mid Moderator' )
               )
             {
                 $buddywww =
  qq~<a href="${$uid.$buddyname}{'weburl'}" target="_blank"><img src="$micon_bg{'www'}" alt="${$uid.$buddyname}{'webtitle'}" title="${$uid.$buddyname}{'webtitle'}" /></a>~;
             }
         }
         else {
             $usernamelink = $mycenter_txt{'buddydeleted'};    # Ex-Member
         }
         $buddiesCurrentStatus_a .= $my_buddiesCurrentStatus_a;
         $buddiesCurrentStatus_a =~ s/{yabb css}/$css/sm;
         $buddiesCurrentStatus_a =~ s/{yabb usernamelink}/$usernamelink/sm;
         $buddiesCurrentStatus_a =~ s/{yabb online}/$online/sm;
         $buddiesCurrentStatus_a =~ s/{yabb buddypm}/$buddypm/sm;
         $buddiesCurrentStatus_a =~ s/{yabb buddyemail}/$buddyemail/sm;
         $buddiesCurrentStatus_a =~ s/{yabb buddywww}/$buddywww/sm;
   
         $counter++;
     }
     $buddiesCurrentStatus = $my_buddiesCurrentStatus;
     $buddiesCurrentStatus =~
       s/{yabb buddiesCurrentStatus_a}/$buddiesCurrentStatus_a/sm;
     undef %UserPM_Level;
     return $buddiesCurrentStatus;
} }
   
sub mcMenu { sub mcMenu {
   my ($pmclass, $profclass, $postclass);     my ( $pmclass, $profclass, $postclass ); 
   if ($action eq "mycenter" || $action eq "im" || $action eq "imdraft" || $action eq "imoutbox" || $action eq "imstorage" || $action eq "imsend" || $action eq "imsend2" || $action eq "imshow") {     if (   $action eq 'mycenter' 
       $pmclass = qq~ class="selected"~;         || $action eq 'im' 
       if ($PM_level == 0 || ($PM_level == 2 && !$iamadmin && !$iamgmod && !$iammod ) || ($PM_level == 3 && !$iamadmin && !$iamgmod)) {         || $action eq 'imdraft' 
           $profclass = qq~ class="selected"~;         || $action eq 'imoutbox' 
       }         || $action eq 'imstorage' 
   }         || $action eq 'imsend' 
         || $action eq 'imsend2' 
   if ($action eq "profileCheck" || $action eq "myviewprofile" || $action eq "myprofile" || $action eq "myprofileContacts" || $action eq "myprofileOptions" || $action eq "myprofileBuddy" || $action eq "myprofileIM" || $action eq "myprofileAdmin") {         || $action eq 'imshow' ) 
       $profclass = qq~ class="selected"~;     { 
   }         $pmclass = q~ class="selected"~; 
         if (   $PM_level == 0
   if ($action eq "favorites" || $action eq "shownotify" || $action eq "myusersrecentposts") {             || ( $PM_level == 2 && !$staff ) 
       $postclass = qq~ class="selected"~;             || ( $PM_level == 3 && !$iamadmin && !$iamgmod ) 
   }             || ( $PM_level == 4 && !$iamadmin && !$iamgmod && !$iamfmod ) ) 
         {
   my $tabsep = qq~<img src="$imagesdir/tabsep211.png" border="0" alt="" style="float: left; vertical-align: middle;" />~;             $profclass = q~ class="selected"~; 
   my $tabfill = qq~<img src="$imagesdir/tabfill.gif" border="0" alt="" style="vertical-align: middle;" />~;         } 
     }
   # pm link  
   if ($PM_level == 1 || ($PM_level == 2 && ($iamadmin || $iamgmod || $iammod)) || ($PM_level == 3 && ($iamadmin || $iamgmod))) {     if (   $action eq 'profileCheck' 
       $yymcmenu .= qq~<span onclick="changeToTab('pm'); return false;"$pmclass id="menu_pm"><a href="$scripturl?action=mycenter" onclick="changeToTab('pm'); return false;" style="padding: 3px 0 4px 0; ">$tabfill$mc_menus{'messages'}$tabfill</a></span>$tabsep         || $action eq 'myviewprofile' 
       ~;         || $action eq 'myprofile' 
   }         || $action eq 'myprofileContacts' 
   # profile link         || $action eq 'myprofileOptions' 
   $yymcmenu .= qq~<span onclick="changeToTab('prof'); return false;"$profclass id="menu_prof"><a href="$scripturl?action=myviewprofile;username=$useraccount{$username}" onclick="changeToTab('prof'); return false;" style="padding: 3px 0 4px 0; ">$tabfill$mc_menus{'profile'}$tabfill</a></span>         || $action eq 'myprofileBuddy' 
   ~;         || $action eq 'myprofileIM' 
         || $action eq 'myprofileAdmin' )
   # posts link     { 
   $yymcmenu .= qq~$tabsep<span onclick="changeToTab('posts'); return false;"$postclass  id="menu_posts"><a href="$scripturl?action=favorites" onclick="changeToTab('posts'); return false;" style="padding: 3px 0 4px 0; ">$tabfill$mc_menus{'posts'}$tabfill</a></span>         $profclass = q~ class="selected"~; 
   ~;     } 
   
     if (   $action eq 'favorites' 
         || $action eq 'shownotify' 
         || $action eq 'myusersrecentposts' )
     {
         $postclass = q~ class="selected"~;
     }
   
     if ( $pm_lev == 1 ) {
         $yymcmenu .=
  qq~<li><span onclick="changeToTab('pm'); return false;"$pmclass id="menu_pm"><a href="$scripturl?action=mycenter" onclick="changeToTab('pm'); return false;">$mc_menus{'messages'}</a></span></li>
         ~;
     }
   
     # profile link
     $yymcmenu .=
  qq~<li><span onclick="changeToTab('prof'); return false;"$profclass id="menu_prof"><a href="$scripturl?action=myviewprofile;username=$useraccount{$username}" onclick="changeToTab('prof'); return false;">$mc_menus{'profile'}</a></span></li>
     ~;
   
     # posts link
     $yymcmenu .=
  qq~<li><span onclick="changeToTab('posts'); return false;"$postclass  id="menu_posts"><a href="$scripturl?action=favorites" onclick="changeToTab('posts'); return false;">$mc_menus{'posts'}</a></span></li>
     ~;
   
   $yymcmenu .= qq~$tabsep~;     $yymcmenu .= q{}; 
     return;
} }
   
1; 1;