D:\my docs\My Received Files\Yabb\Yabb\YaBB_2.5_AEB\cgi-bin\yabb2_old\Sources\MyCenter.pl D:\WEBSITES\testbed\cgi-bin\yabb252\Sources\MyCenter.pl
############################################################################### ###############################################################################
# MyCenter.pl                                                                 # # MyCenter.pl                                                                 #
############################################################################### ###############################################################################
# YaBB: Yet another Bulletin Board                                            # # YaBB: Yet another Bulletin Board                                            #
# Open-Source Community Software for Webmasters                               # # Open-Source Community Software for Webmasters                               #
# Version:        YaBB 2.5 Anniversary Edition                                # # Version:        YaBB 2.5.2                                                  #
# Packaged:       July 04, 2010                                               # # Packaged:       September 30, 2012                                          #
# Distributed by: http://www.yabbforum.com                                    # # Distributed by: http://www.yabbforum.com                                    #
# =========================================================================== # # =========================================================================== #
# Copyright (c) 2000-2010 YaBB (www.yabbforum.com) - All Rights Reserved.     # # Copyright (c) 2000-2012 YaBB (www.yabbforum.com) - All Rights Reserved.     #
# Software by:  The YaBB Development Team                                     # # Software by:  The YaBB Development Team                                     #
#               with assistance from the YaBB community.                      # #               with assistance from the YaBB community.                      #
# Sponsored by: Xnull Internet Media, Inc. - http://www.ximinc.com            #    
#               Your source for web hosting, web design, and domains.         #    
############################################################################### ###############################################################################
   
$mycenterplver = 'YaBB 2.5 AE $Revision: 1.125 $'; $mycenterplver = 'YaBB 2.5.2 $Revision: 1.1 $';
if ($action eq 'detailedversion') { return 1; } if ($action eq 'detailedversion') { return 1; }
   
&LoadLanguage('InstantMessage'); &LoadLanguage('InstantMessage');
&LoadLanguage('MyCenter'); &LoadLanguage('MyCenter');
require "$templatesdir/$usemycenter/MyCenter.template"; require "$templatesdir/$usemycenter/MyCenter.template";
if (-e "$vardir/gmodsettings.txt" && $iamgmod) { require "$vardir/gmodsettings.txt"; } if (-e "$vardir/gmodsettings.txt" && $iamgmod) { require "$vardir/gmodsettings.txt"; }
$mycenter_txt{'welcometxt'} =~ s/USERLABEL/${$uid.$username}{'realname'}/g; $mycenter_txt{'welcometxt'} =~ s/USERLABEL/${$uid.$username}{'realname'}/g;
   
$showIM = ''; $showIM = '';
$IM_box = ''; $IM_box = '';
$showProfile = ''; $showProfile = '';
$PMfileToOpen = ''; $PMfileToOpen = '';
$sendBMess = ''; $sendBMess = '';
$isBMess = ''; $isBMess = '';
$showFavorites = ''; $showFavorites = '';
$showNotifications = ''; $showNotifications = '';
   
##  here begins the user centre, from the old IMIndex ##  here begins the user centre, from the old IMIndex
sub mycenter { sub mycenter {
   if ($iamguest) { &fatal_error('im_members_only'); }    if ($iamguest) { &fatal_error('members_only'); }
   
   &LoadBroadcastMessages($username); # get the BM infos    &LoadBroadcastMessages($username); # get the BM infos
   
   $IM_box = '';    $IM_box = '';
   my $PMfileToOpen = '';    my $PMfileToOpen = '';
   my @otherStoreFolders = ();    my @otherStoreFolders = ();
   my $otherStoreSelect = '';    my $otherStoreSelect = '';
   $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/ || $action eq 'deletemultimessages' || $action eq 'pmsearch') { $view = 'pm'; }
   elsif ($action eq 'mycenter') { $view = 'mycenter'; }    elsif ($action eq 'mycenter') { $view = 'mycenter'; }
   elsif ($action eq 'shownotify' || $action=~ /^notify/ || $action eq 'boardnotify2') { $view = 'notify'; $mctitle = $img_txt{'418'}; }    elsif ($action eq 'shownotify' || $action=~ /^notify/ || $action eq 'boardnotify2') { $view = 'notify'; $mctitle = $img_txt{'418'}; }
   elsif ($action eq 'myusersrecentposts') { $view = 'recentposts'; }    elsif ($action eq 'myusersrecentposts') { $view = 'recentposts'; }
   elsif ($action eq 'favorites') { $view = 'favorites'; $mctitle = $img_txt{'70'}; }    elsif ($action eq 'favorites') { $view = 'favorites'; $mctitle = $img_txt{'70'}; }
   elsif ($action =~ /^my/) { $view = 'profile'; }    elsif ($action =~ /^my/) { $view = 'profile'; }
   ## viewing PMs    ## viewing PMs
   if ($view eq 'pm') { # pm views    if ($view eq 'pm') { # pm views
       ## viewing a message box        ## viewing a message box
       require "$sourcedir/InstantMessage.pl";        require "$sourcedir/InstantMessage.pl";
       if ($action eq 'im' || $action eq 'imoutbox' || $action eq 'imstorage') {        if ($action eq 'im' || $action eq 'imoutbox' || $action eq 'imstorage') {
           my $foundextra = 0;            my $foundextra = 0;
           foreach my $storefolder (split(/\|/, ${$username}{'PMfolders'})) {            foreach my $storefolder (split(/\|/, ${$username}{'PMfolders'})) {
               if($storefolder ne $INFO{'viewfolder'}) {                if($storefolder ne $INFO{'viewfolder'}) {
                   push (@otherStoreFolders, $storefolder);                    push (@otherStoreFolders, $storefolder);
                   $foundextra = 1;                    $foundextra = 1;
               }                }
           }            }
           if ($foundextra > 0) {            if ($foundextra > 0) {
               $otherStoreSelect = qq~ $inmes_txt{'storein'} <select name="tostorefolder" id="tostorefolder">~;                $otherStoreSelect = qq~ $inmes_txt{'storein'} <select name="tostorefolder" id="tostorefolder">~;
               foreach my $otherFolder (@otherStoreFolders) {                foreach my $otherFolder (@otherStoreFolders) {
                   my $otherFolderName = $otherFolder;                    my $otherFolderName = $otherFolder;
                   if ($otherFolder eq 'in') { $otherFolderName = $im_folders_txt{'in'}; }                    if ($otherFolder eq 'in') { $otherFolderName = $im_folders_txt{'in'}; }
                   elsif ($otherFolder eq 'out') { $otherFolderName = $im_folders_txt{'out'}; }                    elsif ($otherFolder eq 'out') { $otherFolderName = $im_folders_txt{'out'}; }
                   $otherStoreSelect .= qq~<option value="$otherFolder">$otherFolderName</option>~;                    $otherStoreSelect .= qq~<option value="$otherFolder">$otherFolderName</option>~;
               }                }
               $otherStoreSelect .= qq~</select>~;                $otherStoreSelect .= qq~</select>~;
           }            }
       }        }
       ## inbox        ## inbox
       if ($action eq 'im' || ($action eq 'imshow' && $INFO{'caller'} == 1)) {        if ($action eq 'im' || ($action eq 'imshow' && $INFO{'caller'} == 1)) {
           $mctitle = $inmes_txt{'inbox'};            $mctitle = $inmes_txt{'inbox'};
           $status = $inmes_imtxt{'status'};            $status = $inmes_imtxt{'status'};
           $senderinfo = $inmes_txt{'318'};            $senderinfo = $inmes_txt{'318'};
           $callerid = 1;            $callerid = 1;
           $boxtxt = $inmes_txt{'316'};            $boxtxt = $inmes_txt{'316'};
           $movebutton  = qq~<input type="submit" name="imaction" value="$inmes_imtxt{'store'}" class="button" />$otherStoreSelect $inmes_txt{'storeor'}~;            $movebutton  = qq~<input type="submit" name="imaction" value="$inmes_imtxt{'store'}" class="button" />$otherStoreSelect $inmes_txt{'storeor'}~;
           $IM_box = $inmes_txt{'inbox'};            $IM_box = $inmes_txt{'inbox'};
           if($INFO{'focus'} eq 'bmess' || $INFO{'bmess'} eq 'yes') { $IM_box = $inmes_txt{'broadcast'}; $callerid = 5; }            if($INFO{'focus'} eq 'bmess' || $INFO{'bmess'} eq 'yes') { $IM_box = $inmes_txt{'broadcast'}; $callerid = 5; }
           $PMfileToOpen = 'msg';            $PMfileToOpen = 'msg';
       }        }
       ##  draft box        ##  draft box
       elsif ($action eq 'imdraft') {        elsif ($action eq 'imdraft') {
           $mctitle = $inmes_txt{'draft'};            $mctitle = $inmes_txt{'draft'};
           $status = $inmes_imtxt{'status'};            $status = $inmes_imtxt{'status'};
           $senderinfo = $inmes_txt{'324'};            $senderinfo = $inmes_txt{'324'};
           $callerid = 4;            $callerid = 4;
           $boxtxt = $inmes_txt{'draft'};            $boxtxt = $inmes_txt{'draft'};
           $movebutton = '';            $movebutton = '';
           $IM_box = $inmes_txt{'draft'};            $IM_box = $inmes_txt{'draft'};
           $PMfileToOpen = 'imdraft';            $PMfileToOpen = 'imdraft';
       }        }
       ## outbox        ## outbox
       elsif ($action eq 'imoutbox' || ($action eq 'imshow' && $INFO{'caller'} == 2)) {        elsif ($action eq 'imoutbox' || ($action eq 'imshow' && $INFO{'caller'} == 2)) {
           $mctitle = $inmes_txt{'773'};            $mctitle = $inmes_txt{'773'};
           $status = $inmes_imtxt{'status'};            $status = $inmes_imtxt{'status'};
           $senderinfo = $inmes_txt{'324'};            $senderinfo = $inmes_txt{'324'};
           $callerid = 2;            $callerid = 2;
           $boxtxt = $inmes_txt{'outbox'};            $boxtxt = $inmes_txt{'outbox'};
           $movebutton  = qq~<input type="submit" name="imaction" value="$inmes_imtxt{'store'}" class="button" />$otherStoreSelect $inmes_txt{'storeor'}~;            $movebutton  = qq~<input type="submit" name="imaction" value="$inmes_imtxt{'store'}" class="button" />$otherStoreSelect $inmes_txt{'storeor'}~;
           $IM_box = $inmes_txt{'outbox'};            $IM_box = $inmes_txt{'outbox'};
           $PMfileToOpen = 'outbox';            $PMfileToOpen = 'outbox';
       }        }
       # store        # store
       elsif ($action eq 'imstorage' || ($action eq 'imshow' && $INFO{'caller'} == 3)) {        elsif ($action eq 'imstorage' || ($action eq 'imshow' && $INFO{'caller'} == 3)) {
           $mctitle = $inmes_txt{'774'};            $mctitle = $inmes_txt{'774'};
           $status = '';            $status = '';
           $senderinfo = $inmes_txt{'318'};            $senderinfo = $inmes_txt{'318'};
           if ($INFO{'viewfolder'} eq 'out') { $senderinfo = $inmes_txt{'324'}; }            if ($INFO{'viewfolder'} eq 'out') { $senderinfo = $inmes_txt{'324'}; }
           elsif ($INFO{'viewfolder'} ne 'in') { $senderinfo = qq~$inmes_txt{'318'} / $inmes_txt{'324'}~; }            elsif ($INFO{'viewfolder'} ne 'in') { $senderinfo = qq~$inmes_txt{'318'} / $inmes_txt{'324'}~; }
           $callerid = 3;            $callerid = 3;
           $boxtxt = $inmes_txt{'storage'};            $boxtxt = $inmes_txt{'storage'};
           $movebutton  = qq~<input type="submit" name="imaction" value="$inmes_imtxt{'store'}" class="button" />$otherStoreSelect $inmes_txt{'storeor'}~;            $movebutton  = qq~<input type="submit" name="imaction" value="$inmes_imtxt{'store'}" class="button" />$otherStoreSelect $inmes_txt{'storeor'}~;
           $IM_box = $inmes_txt{'storage'};            $IM_box = $inmes_txt{'storage'};
           if ($INFO{'viewfolder'} eq 'in' || $INFO{'viewfolder'} eq 'out') { $IM_box .= qq~ &rsaquo; $im_folders_txt{"$INFO{'viewfolder'}"}~; }            if ($INFO{'viewfolder'} eq 'in' || $INFO{'viewfolder'} eq 'out') { $IM_box .= qq~ &rsaquo; $im_folders_txt{"$INFO{'viewfolder'}"}~; }
           elsif ($INFO{'viewfolder'}) { $IM_box .= qq~ &rsaquo; $INFO{'viewfolder'}~; }            elsif ($INFO{'viewfolder'}) { $IM_box .= qq~ &rsaquo; $INFO{'viewfolder'}~; }
           $PMfileToOpen = 'imstore';            $PMfileToOpen = 'imstore';
       }        }
       ## sending a message / previewing        ## sending a message / previewing
       elsif ($action eq 'imsend' || ($action eq 'imsend2' && $FORM{'previewim'})) {        elsif ($action eq 'imsend' || ($action eq 'imsend2' && $FORM{'previewim'})) {
           $IM_box = $inmes_txt{'148'};            $IM_box = $inmes_txt{'148'};
           if ($INFO{'forward'} == 1) { $IM_box = $inmes_txt{'forward'}; }            if ($INFO{'forward'} == 1) { $IM_box = $inmes_txt{'forward'}; }
           if ($INFO{'reply'}) { $IM_box = $inmes_txt{'replymess'}; }            if ($INFO{'reply'}) { $IM_box = $inmes_txt{'replymess'}; }
           &IMPost;            &IMPost;
           &buildIMsend;            &buildIMsend;
           &doshowims;            &doshowims;
       }        }
       ## posting the message or draft        ## posting the message or draft
       elsif ($action eq 'imsend2' || $FORM{'draft'}) {        elsif ($action eq 'imsend2' || $FORM{'draft'}) {
           $IM_box = $inmes_txt{'148'};            $IM_box = $inmes_txt{'148'};
           if($INFO{'forward'} == 1) { $IM_box = $inmes_txt{'forward'}; }            if($INFO{'forward'} == 1) { $IM_box = $inmes_txt{'forward'}; }
           if($INFO{'reply'}) { $IM_box = $inmes_txt{'replymess'}; }            if($INFO{'reply'}) { $IM_box = $inmes_txt{'replymess'}; }
           &IMsendMessage;            &IMsendMessage;
       }        }
       elsif ($action eq 'imshow' && $INFO{'caller'} == 5) {        elsif ($action eq 'imshow' && $INFO{'caller'} == 5) {
           $mctitle = $inmes_txt{'broadcast'};            $mctitle = $inmes_txt{'broadcast'};
           $status = $inmes_imtxt{'status'};            $status = $inmes_imtxt{'status'};
           $senderinfo = $inmes_txt{'318'};            $senderinfo = $inmes_txt{'318'};
           $callerid = 5;            $callerid = 5;
           $boxtxt = $inmes_txt{'316'};            $boxtxt = $inmes_txt{'316'};
           $movebutton = qq~<input type="submit" name="imaction" value="$inmes_imtxt{'store'}" class="button" />$otherStoreSelect $inmes_txt{'storeor'}~;            $movebutton = qq~<input type="submit" name="imaction" value="$inmes_imtxt{'store'}" class="button" />$otherStoreSelect $inmes_txt{'storeor'}~;
           $IM_box = $inmes_txt{'broadcast'};            $IM_box = $inmes_txt{'broadcast'};
           $PMfileToOpen = 'msg';            $PMfileToOpen = 'msg';
       }        }
   }    }
   ## viewing front page    ## viewing front page
   elsif ($view eq "mycenter") {    elsif ($view eq "mycenter") {
       $mctitle = "$inmes_txt{'mycenter'}";        $mctitle = "$inmes_txt{'mycenter'}";
   }    }
   ## viewing my profile    ## viewing my profile
   elsif ($view eq "profile") {    elsif ($view eq "profile") {
       $mctitle = "$mc_menus{'profile'}";        $mctitle = "$mc_menus{'profile'}";
   }    }
   ## viewing my recent posts    ## viewing my recent posts
   elsif ($view eq 'recentposts') {    elsif ($view eq 'recentposts') {
       $mctitle = "$inmes_txt{'viewrecentposts'} $inmes_txt{'viewrecentposts2'}";        $mctitle = "$inmes_txt{'viewrecentposts'} $inmes_txt{'viewrecentposts2'}";
   }    }
   
   ## draw the container    ## draw the container
   &drawPMbox($PMfileToOpen);    &drawPMbox($PMfileToOpen);
   &LoadIMs;    &LoadIMs;
   
   # navigation link    # navigation link
   $yynavigation = qq~&rsaquo; <a href="$scripturl?action=mycenter" class="nav">$img_txt{'mycenter'}</a> &rsaquo; $mctitle~;    $yynavigation = qq~&rsaquo; <a href="$scripturl?action=mycenter" class="nav">$img_txt{'mycenter'}</a> &rsaquo; $mctitle~;
   
   ## set template up    ## set template up
   $mycenter_template =~ s/({|<)yabb mcviewmenu(}|>)/$MCViewMenu/g;    $mycenter_template =~ s/({|<)yabb mcviewmenu(}|>)/$MCViewMenu/g;
   $mycenter_template =~ s/({|<)yabb mcmenu(}|>)/$yymcmenu/g;    $mycenter_template =~ s/({|<)yabb mcmenu(}|>)/$yymcmenu/g;
   $mycenter_template =~ s/({|<)yabb mcpmmenu(}|>)/$MCPmMenu/g;    $mycenter_template =~ s/({|<)yabb mcpmmenu(}|>)/$MCPmMenu/g;
   $mycenter_template =~ s/({|<)yabb mcprofmenu(}|>)/$MCProfMenu/g;    $mycenter_template =~ s/({|<)yabb mcprofmenu(}|>)/$MCProfMenu/g;
   $mycenter_template =~ s/({|<)yabb mcpostsmenu(}|>)/$MCPostsMenu/g;    $mycenter_template =~ s/({|<)yabb mcpostsmenu(}|>)/$MCPostsMenu/g;
   $mycenter_template =~ s/({|<)yabb mcglobformstart(}|>)/$MCGlobalFormStart/g;    $mycenter_template =~ s/({|<)yabb mcglobformstart(}|>)/$MCGlobalFormStart/g;
   $mycenter_template =~ s/({|<)yabb mcglobformend(}|>)/ ($MCGlobalFormStart ? "<\/form>" : "") /e;    $mycenter_template =~ s/({|<)yabb mcglobformend(}|>)/ ($MCGlobalFormStart ? "<\/form>" : "") /e;
   $mycenter_template =~ s/({|<)yabb mcextrasmilies(}|>)/$MCExtraSmilies/g;    $mycenter_template =~ s/({|<)yabb mcextrasmilies(}|>)/$MCExtraSmilies/g;
   $mycenter_template =~ s/({|<)yabb mccontent(}|>)/$MCContent/g;    $mycenter_template =~ s/({|<)yabb mccontent(}|>)/$MCContent/g;
   $mycenter_template =~ s/({|<)yabb mctitle(}|>)/$mctitle/g;    $mycenter_template =~ s/({|<)yabb mctitle(}|>)/$mctitle/g;
   $mycenter_template =~ s/({|<)yabb selecthtml(}|>)/$selecthtml/g;    $mycenter_template =~ s/({|<)yabb selecthtml(}|>)/$selecthtml/g;
   $mycenter_template =~ s/({|<)yabb forumjump(}|>)//g;    $mycenter_template =~ s/({|<)yabb forumjump(}|>)//g;
   
   ## end new style box    ## end new style box
   $yymain .= $mycenter_template;    $yymain .= $mycenter_template;
   if (%usernames_life_quote) { # for display names in Quotes in LivePreview    if (%usernames_life_quote) { # for display names in Quotes in LivePreview
       $yymain .= qq~        $yymain .= qq~
<script language="JavaScript" type="text/javascript"> <script language="JavaScript" type="text/javascript">
<!-- // <!-- //
   ~ . join(';', map { qq~LivePrevDisplayNames['$_'] = "$usernames_life_quote{$_}"~ } keys %usernames_life_quote) . qq~;    ~ . join(';', map { qq~LivePrevDisplayNames['$_'] = "$usernames_life_quote{$_}"~ } keys %usernames_life_quote) . qq~;
// --> // -->
</script>\n\n~; </script>\n\n~;
   }    }
   &template;    &template;
} }
   
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(/\|/, ${$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 \-_]/) { &fatal_error('invalid_character', $inmes_txt{'foldererror'}); }
           if ($FORM{'newfolder'} eq $currStoreFolder) { &fatal_error('im_folder_exists'); }            if ($FORM{'newfolder'} eq $currStoreFolder) { &fatal_error('im_folder_exists'); }
       } elsif ($FORM{'delfolders'}) {        } elsif ($FORM{'delfolders'}) {
           if ($currStoreFolder ne 'in' && $currStoreFolder ne 'out' && $FORM{"delfolder$x"} ne 'del') {            if ($currStoreFolder ne 'in' && $currStoreFolder ne 'out' && $FORM{"delfolder$x"} ne 'del') {
               $newStoreFolders .= qq~|$currStoreFolder~;                $newStoreFolders .= qq~|$currStoreFolder~;
           }            }
       }        }
       $x++;        $x++;
   }    }
   if ($FORM{'newfolder'}) { ${$username}{'PMfolders'} = qq~$storefolders|$FORM{'newfolder'}~; }    if ($FORM{'newfolder'}) { ${$username}{'PMfolders'} = qq~$storefolders|$FORM{'newfolder'}~; }
   elsif ($FORM{'delfolders'}) { ${$username}{'PMfolders'} = $newStoreFolders; }    elsif ($FORM{'delfolders'}) { ${$username}{'PMfolders'} = $newStoreFolders; }
   &buildIMS($username, 'update');    &buildIMS($username, 'update');
   $yySetLocation = qq~$scripturl?action=mycenter~;    $yySetLocation = qq~$scripturl?action=mycenter~;
   &redirectexit;    &redirectexit;
} }
   
##  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    my $receiver = $INFO{'receiver'}; # set variables from GET - localised
   
   if ($receiver && $receiver !~ /,/) {    if ($receiver && $receiver !~ /,/) {
       my $receiver = &decloak($receiver);        my $receiver = &decloak($receiver);
       if (&CallBackRec($receiver,$INFO{'rid'},1)) { &fatal_error("im_deleted"); }        if (&CallBackRec($receiver,$INFO{'rid'},1)) { &fatal_error("im_deleted"); }
       &updateIMS($receiver,$INFO{'rid'},'callback');        &updateIMS($receiver,$INFO{'rid'},'callback');
   } elsif ($receiver) {    } elsif ($receiver) {
       my $rec;        my $rec;
       foreach $rec (split(/,/, $receiver)) {        foreach $rec (split(/,/, $receiver)) {
           $rec = &decloak($rec);            $rec = &decloak($rec);
           if (&CallBackRec($rec,$INFO{'rid'},0)) { &fatal_error("im_deleted_multi"); }            if (&CallBackRec($rec,$INFO{'rid'},0)) { &fatal_error("im_deleted_multi"); }
       }        }
       foreach $rec (split(/,/, $receiver)) {        foreach $rec (split(/,/, $receiver)) {
           $rec = &decloak($rec);            $rec = &decloak($rec);
           &CallBackRec($rec,$INFO{'rid'},1);            &CallBackRec($rec,$INFO{'rid'},1);
           &updateIMS($rec,$INFO{'rid'},'callback');            &updateIMS($rec,$INFO{'rid'},'callback');
       }        }
   }    }
   
   &updateMessageFlag($username, $INFO{'rid'}, 'outbox', '', 'c');    &updateMessageFlag($username, $INFO{'rid'}, 'outbox', '', 'c');
   
   $yySetLocation = qq~$scripturl?action=imoutbox~;    $yySetLocation = qq~$scripturl?action=imoutbox~;
   &redirectexit;    &redirectexit;
} }
   
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;    fopen(REVMSG, ">$memberdir/$receiver.msg") if $do_it;
   ## 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);        ($rmessageid,$fromuser, undef, undef, undef, undef, undef, undef, undef, undef, undef, undef, $flags, undef) = split(/\|/, $_, 14);
       if (!$do_it) {        if (!$do_it) {
           if ($rmessageid == $rid && $fromuser eq $username) {            if ($rmessageid == $rid && $fromuser eq $username) {
               if ($flags !~ /u/i) { $nodel = 1; }                if ($flags !~ /u/i) { $nodel = 1; }
               last;                last;
           }            }
       } else {        } else {
           if ($rmessageid != $rid || $fromuser ne $username) { print REVMSG $_; }            if ($rmessageid != $rid || $fromuser ne $username) { print REVMSG $_; }
           elsif ($flags !~ /u/i) { print REVMSG $_; $nodel = 1;}            elsif ($flags !~ /u/i) { print REVMSG $_; $nodel = 1;}
       }        }
   }    }
   fclose(REVMSG) if $do_it;    fclose(REVMSG) if $do_it;
   $nodel;    $nodel;
} }
   
sub checkIMS { # lookup value in pm file sub checkIMS { # lookup value in pm file
   my $user = $_[0];    my $user = $_[0];
   my $id = $_[1];    my $id = $_[1];
   my $checkfor = $_[2];    my $checkfor = $_[2];
   
   ## has the message been opened by the receiver? 1 = yes 0 = no    ## has the message been opened by the receiver? 1 = yes 0 = no
   if ($checkfor eq 'messageopened') {    if ($checkfor eq 'messageopened') {
       my $messageFoundFlag = &checkMessageFlag($user, $id, 'msg', 'u');        my $messageFoundFlag = &checkMessageFlag($user, $id, 'msg', 'u');
       if ($messageFoundFlag == 1) { return 0; }        if ($messageFoundFlag == 1) { return 0; }
       else {$messageFoundFlag = &checkMessageFlag($user, $id, 'imstore', 'u'); }        else {$messageFoundFlag = &checkMessageFlag($user, $id, 'imstore', 'u'); }
       if ($messageFoundFlag == 1) { return 0; }        if ($messageFoundFlag == 1) { return 0; }
       else { return 1; }        else { return 1; }
   
   ## has the message been replied to? 1 = yes 0 = no    ## has the message been replied to? 1 = yes 0 = no
   } elsif ($checkfor eq 'messagereplied') {    } elsif ($checkfor eq 'messagereplied') {
       ## check in msg and imstore        ## check in msg and imstore
       my $messageFoundFlag = &checkMessageFlag($user, $id, 'msg', 'r');        my $messageFoundFlag = &checkMessageFlag($user, $id, 'msg', 'r');
       if ($messageFoundFlag == 1) { return 1; }        if ($messageFoundFlag == 1) { return 1; }
       else {$messageFoundFlag = &checkMessageFlag($user, $id, 'imstore', 'r'); }        else {$messageFoundFlag = &checkMessageFlag($user, $id, 'imstore', 'r'); }
       if ($messageFoundFlag == 1) { return 1; }        if ($messageFoundFlag == 1) { return 1; }
       else { return 0; }        else { return 0; }
   }    }
} }
   
sub checkMessageFlag { # look for $user.$pmFile, find $id message and check for $messageFlag sub checkMessageFlag { # look for $user.$pmFile, find $id message and check for $messageFlag
   my ($user, $id, $pmFile, $messageFlag) = @_;    my ($user, $id, $pmFile, $messageFlag) = @_;
   my $messageFoundFlag = 0;    my $messageFoundFlag = 0;
   if (%{'MF' . $user . $pmFile}) {    if (%{'MF' . $user . $pmFile}) {
       if (exists ${'MF' . $user . $pmFile}{$id} && ${'MF' . $user . $pmFile}{$id} =~ /$messageFlag/i) { $messageFoundFlag = 1; }        if (exists ${'MF' . $user . $pmFile}{$id} && ${'MF' . $user . $pmFile}{$id} =~ /$messageFlag/i) { $messageFoundFlag = 1; }
   } elsif (-e "$memberdir/$user.$pmFile") {    } elsif (-e "$memberdir/$user.$pmFile") {
       fopen ("USERMSG", "$memberdir/$user.$pmFile");        fopen ("USERMSG", "$memberdir/$user.$pmFile");
       my @userMessages = <USERMSG>;        my @userMessages = <USERMSG>;
       fclose ("USERMSG");        fclose ("USERMSG");
       my ($uMessageId,$uMessageFlags);        my ($uMessageId,$uMessageFlags);
       foreach (@userMessages) {        foreach (@userMessages) {
           ($uMessageId, undef, undef, undef, undef, undef, undef, undef, undef, undef, undef, undef, $uMessageFlags, undef) = split(/\|/, $_,  14);            ($uMessageId, undef, undef, undef, undef, undef, undef, undef, undef, undef, undef, undef, $uMessageFlags, undef) = split(/\|/, $_,  14);
           ${'MF' . $user . $pmFile}{$uMessageId} = $uMessageFlags;            ${'MF' . $user . $pmFile}{$uMessageId} = $uMessageFlags;
           if ($uMessageId == $id && $uMessageFlags =~ /$messageFlag/i) { $messageFoundFlag = 1; }            if ($uMessageId == $id && $uMessageFlags =~ /$messageFlag/i) { $messageFoundFlag = 1; }
       }        }
   }    }
   $messageFoundFlag;    $messageFoundFlag;
} }
   
sub updateMessageFlag { # look for $user.$pmFile, find $id message and check for $messageFlag. change to $newMessageFlag sub updateMessageFlag { # look for $user.$pmFile, find $id message and check for $messageFlag. change to $newMessageFlag
   my ($user, $id, $pmFile, $messageFlag, $newMessageFlag) = @_;    my ($user, $id, $pmFile, $messageFlag, $newMessageFlag) = @_;
   my $messageFoundFlag = 0;    my $messageFoundFlag = 0;
   if ((!exists ${'MF' . $user . $pmFile}{$id} || ($messageFlag ne '' && ${'MF' . $user . $pmFile}{$id} =~ /$messageFlag/) || ($messageFlag eq '' && !${'MF' . $user . $pmFile}{$id} =~ /$newMessageFlag/)) && -e "$memberdir/$user.$pmFile") {    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");        fopen ("USERFILE", "+<$memberdir/$user.$pmFile");
       my @userFile = <USERFILE>;        my @userFile = <USERFILE>;
       seek USERFILE, 0, 0;        seek USERFILE, 0, 0;
       truncate USERFILE, 0;        truncate USERFILE, 0;
       foreach my $userMessage (@userFile) {        foreach my $userMessage (@userFile) {
           my ($uMessageId, $uFrom, $uToUser, $uTocc, $uTobcc, $uSubject, $uDate, $uMessage, $uPid, $uReply , $uip, $uStatus, $uMessageFlags, $uStorefolder, $uAttach) = split(/\|/, $userMessage);            my ($uMessageId, $uFrom, $uToUser, $uTocc, $uTobcc, $uSubject, $uDate, $uMessage, $uPid, $uReply , $uip, $uStatus, $uMessageFlags, $uStorefolder, $uAttach) = split(/\|/, $userMessage);
           if ($uMessageId == $id) {            if ($uMessageId == $id) {
               $uMessageFlags =~ s/$newMessageFlag//gi if $newMessageFlag ne '';                $uMessageFlags =~ s/$newMessageFlag//gi if $newMessageFlag ne '';
               if ($uMessageFlags =~ s/$messageFlag/$newMessageFlag/i) {                if ($uMessageFlags =~ s/$messageFlag/$newMessageFlag/i) {
                   $messageFoundFlag = 1;                    $messageFoundFlag = 1;
               } else {                } else {
                   $uMessageFlags .= $newMessageFlag;                    $uMessageFlags .= $newMessageFlag;
               }                }
               $userMessage = "$uMessageId|$uFrom|$uToUser|$uTocc|$uTobcc|$uSubject|$uDate|$uMessage|$uPid|$uReply|$uip|$uStatus|$uMessageFlags|$uStorefolder|$uAttach";                $userMessage = "$uMessageId|$uFrom|$uToUser|$uTocc|$uTobcc|$uSubject|$uDate|$uMessage|$uPid|$uReply|$uip|$uStatus|$uMessageFlags|$uStorefolder|$uAttach";
           }            }
           ${'MF' . $user . $pmFile}{$uMessageId} = $uMessageFlags;            ${'MF' . $user . $pmFile}{$uMessageId} = $uMessageFlags;
           print USERFILE  $userMessage;            print USERFILE  $userMessage;
       }        }
       fclose("USERFILE");        fclose("USERFILE");
   }    }
   $messageFoundFlag;    $messageFoundFlag;
} }
   
sub updateIMS { # update .ims file for user: &updateIMS(<user>,<PM msgid>,[target/action]) sub updateIMS { # update .ims file for user: &updateIMS(<user>,<PM msgid>,[target/action])
   my ($user,$id,$target) = @_;    my ($user,$id,$target) = @_;
   
   # load the user who is processed here, if not allready loaded    # load the user who is processed here, if not allready loaded
   &buildIMS($user, 'load') unless exists ${$user}{'PMmnum'};    &buildIMS($user, 'load') unless exists ${$user}{'PMmnum'};
   
   # new msg received - add to the inbox lists and increment the counts    # new msg received - add to the inbox lists and increment the counts
   if ($target eq 'messagein') {    if ($target eq 'messagein') {
       # read the lines into temp variables        # read the lines into temp variables
       ${$user}{'PMmnum'}++;        ${$user}{'PMmnum'}++;
       ${$user}{'PMimnewcount'}++;        ${$user}{'PMimnewcount'}++;
   
   # message sent - add to the outbox list and increment count    # message sent - add to the outbox list and increment count
   } elsif ($target eq 'messageout') {    } elsif ($target eq 'messageout') {
       ${$user}{'PMmoutnum'}++;        ${$user}{'PMmoutnum'}++;
   
   # reading msg in inbox - newcount -1, remove from unread list    # reading msg in inbox - newcount -1, remove from unread list
   } elsif ($target eq 'inread') {    } elsif ($target eq 'inread') {
       if (&updateMessageFlag($user, $id, 'msg', 'u', '')) { ${$user}{'PMimnewcount'}--; }        if (&updateMessageFlag($user, $id, 'msg', 'u', '')) { ${$user}{'PMimnewcount'}--; }
       else { return; }        else { return; }
   
   # callback message - take off imnewcount, mnum    # callback message - take off imnewcount, mnum
   } elsif ($target eq 'callback') {    } elsif ($target eq 'callback') {
       ${$user}{'PMmnum'}--;        ${$user}{'PMmnum'}--;
       ${$user}{'PMimnewcount'}--;        ${$user}{'PMimnewcount'}--;
   
   # draft added    # draft added
   } elsif ($target eq 'draftadd') {    } elsif ($target eq 'draftadd') {
       ${$user}{'PMdraftnum'}++;        ${$user}{'PMdraftnum'}++;
   
   # draft send    # draft send
   } elsif ($target eq 'draftsend') {    } elsif ($target eq 'draftsend') {
       ${$user}{'PMdraftnum'}--;        ${$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
} }
   
# 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";    my $fileToOpen = "$username.msg";
   if ($INFO{'caller'} == 2)    { $fileToOpen = "$username.outbox"; }    if ($INFO{'caller'} == 2)    { $fileToOpen = "$username.outbox"; }
   elsif ($INFO{'caller'} == 3) { $fileToOpen = "$username.imstore"; }    elsif ($INFO{'caller'} == 3) { $fileToOpen = "$username.imstore"; }
   elsif ($INFO{'caller'} == 4) { $fileToOpen = "$username.imdraft"; }    elsif ($INFO{'caller'} == 4) { $fileToOpen = "$username.imdraft"; }
   elsif ($INFO{'caller'} == 5) { $fileToOpen = "broadcast.messages"; }    elsif ($INFO{'caller'} == 5) { $fileToOpen = "broadcast.messages"; }
   
   fopen(USRFILE, "+<$memberdir/$fileToOpen");    fopen(USRFILE, "+<$memberdir/$fileToOpen");
   seek USRFILE, 0, 0;    seek USRFILE, 0, 0;
   my @messages = <USRFILE>;    my @messages = <USRFILE>;
   seek USRFILE, 0, 0;    seek USRFILE, 0, 0;
   truncate USRFILE, 0;    truncate USRFILE, 0;
   
   # deleting    # deleting
   if ($FORM{'imaction'} eq $inmes_txt{'remove'} || $INFO{'action'} eq $inmes_txt{'remove'} || $INFO{'deleteid'}) {    if ($FORM{'imaction'} eq $inmes_txt{'remove'} || $INFO{'action'} eq $inmes_txt{'remove'} || $INFO{'deleteid'}) {
       my %CountStore;        my %CountStore;
       if ($INFO{'caller'} == 2)    { ${$username}{'PMmoutnum'} = 0; }        if ($INFO{'caller'} == 2)    { ${$username}{'PMmoutnum'} = 0; }
       elsif ($INFO{'caller'} == 4) { ${$username}{'PMdraftnum'} = 0; }        elsif ($INFO{'caller'} == 4) { ${$username}{'PMdraftnum'} = 0; }
       elsif ($INFO{'caller'} != 3 && $INFO{'caller'} != 5) { ${$username}{'PMmnum'} = 0; ${$username}{'PMimnewcount'} = 0; }        elsif ($INFO{'caller'} != 3 && $INFO{'caller'} != 5) { ${$username}{'PMmnum'} = 0; ${$username}{'PMimnewcount'} = 0; }
   
       if ($INFO{'deleteid'}) { $FORM{"message" . $INFO{'deleteid'}} = 1; } # singel delete        if ($INFO{'deleteid'}) { $FORM{"message" . $INFO{'deleteid'}} = 1; } # singel delete
   
       foreach (@messages) {        foreach (@messages) {
           my @m = split(/\|/, $_);            my @m = split(/\|/, $_);
           if (!exists $FORM{"message" . $m[0]}) {            if (!exists $FORM{"message" . $m[0]}) {
               print USRFILE $_;                print USRFILE $_;
   
               if ($INFO{'caller'} == 2)    { ${$username}{'PMmoutnum'}++; }                if ($INFO{'caller'} == 2)    { ${$username}{'PMmoutnum'}++; }
               elsif ($INFO{'caller'} == 3) { $CountStore{$m[13]}++; }                elsif ($INFO{'caller'} == 3) { $CountStore{$m[13]}++; }
               elsif ($INFO{'caller'} == 4) { ${$username}{'PMdraftnum'}++; }                elsif ($INFO{'caller'} == 4) { ${$username}{'PMdraftnum'}++; }
               elsif ($INFO{'caller'} != 5) { ${$username}{'PMmnum'}++; ${$username}{'PMimnewcount'}++ if $m[12] =~ /u/; }                elsif ($INFO{'caller'} != 5) { ${$username}{'PMmnum'}++; ${$username}{'PMimnewcount'}++ if $m[12] =~ /u/; }
           } else {            } else {
               if ($INFO{'caller'} == 3) {                if ($INFO{'caller'} == 3) {
                   $INFO{'viewfolder'} = $m[13];                    $INFO{'viewfolder'} = $m[13];
               } elsif ($INFO{'caller'} == 5) {                } elsif ($INFO{'caller'} == 5) {
                   ${$username}{'PMbcRead'} =~ s/$m[0]\b//g unless ${$username}{'PMbcRead'} =~ s/\b$m[0]$//;                    ${$username}{'PMbcRead'} =~ s/$m[0]\b//g unless ${$username}{'PMbcRead'} =~ s/\b$m[0]$//;
               }                }
           }            }
       }        }
       fclose(USRFILE);        fclose(USRFILE);
       if ($INFO{'caller'} == 3) {        if ($INFO{'caller'} == 3) {
           ${$username}{'PMfoldersCount'} = '';            ${$username}{'PMfoldersCount'} = '';
           ${$username}{'PMstorenum'} = 0;            ${$username}{'PMstorenum'} = 0;
           foreach (split(/\|/, ${$username}{'PMfolders'})) {            foreach (split(/\|/, ${$username}{'PMfolders'})) {
               $CountStore{$_} ||= 0;                $CountStore{$_} ||= 0;
               ${$username}{'PMfoldersCount'} .= ${$username}{'PMfoldersCount'} eq '' ? $CountStore{$_} : "|$CountStore{$_}";                ${$username}{'PMfoldersCount'} .= ${$username}{'PMfoldersCount'} eq '' ? $CountStore{$_} : "|$CountStore{$_}";
               ${$username}{'PMstorenum'} += $CountStore{$_};                ${$username}{'PMstorenum'} += $CountStore{$_};
           }            }
       }        }
       &buildIMS($username, 'update');        &buildIMS($username, 'update');
   
   #  moving messages    #  moving messages
   } elsif ($FORM{'imaction'} eq $inmes_imtxt{'store'} || $INFO{'imaction'} eq $inmes_imtxt{'store'}) {    } elsif ($FORM{'imaction'} eq $inmes_imtxt{'store'} || $INFO{'imaction'} eq $inmes_imtxt{'store'}) {
       my (@newmessages,%CountStore,$imstorefolder);        my (@newmessages,%CountStore,$imstorefolder);
       if ($FORM{'tostorefolder'}) { $imstorefolder = $FORM{'tostorefolder'}; }        if ($FORM{'tostorefolder'}) { $imstorefolder = $FORM{'tostorefolder'}; }
       elsif ($INFO{'caller'} == 1) { $imstorefolder = 'in'; }        elsif ($INFO{'caller'} == 1) { $imstorefolder = 'in'; }
       else { $imstorefolder = 'out'; }        else { $imstorefolder = 'out'; }
   
       foreach (@messages) {        foreach (@messages) {
           if (!$FORM{"message" . (split(/\|/, $_, 2))[0]}) {            if (!$FORM{"message" . (split(/\|/, $_, 2))[0]}) {
               if ($INFO{'caller'} != 3) {                if ($INFO{'caller'} != 3) {
                   print USRFILE $_;                    print USRFILE $_;
               } else {                } else {
                   my @m = split(/\|/, $_);                    my @m = split(/\|/, $_);
                   push(@newmessages, [@m]);                    push(@newmessages, [@m]);
                   $CountStore{$m[13]}++;                    $CountStore{$m[13]}++;
               }                }
           } else {            } else {
               my @m = split(/\|/, $_);                my @m = split(/\|/, $_);
               $m[13] = $imstorefolder;                $m[13] = $imstorefolder;
               push(@newmessages, [@m]);                push(@newmessages, [@m]);
               $CountStore{$imstorefolder}++;                $CountStore{$imstorefolder}++;
               if ($INFO{'caller'} != 3) {                if ($INFO{'caller'} != 3) {
                   ${$username}{'PMstorenum'}++;                    ${$username}{'PMstorenum'}++;
                   ${$username}{'PMmnum'}--;                      if ($INFO{'caller'} == 1) { ${$username}{'PMmnum'}--; }  
                     elsif ($INFO{'caller'} == 2) { ${$username}{'PMmoutnum'}--; }  
                   ${$username}{'PMimnewcount'}-- if $m[12] =~ /u/;                    ${$username}{'PMimnewcount'}-- if $m[12] =~ /u/;
               }                }
           }            }
       }        }
       fclose(USRFILE);        fclose(USRFILE);
   
       if (@newmessages) {        if (@newmessages) {
           if ($INFO{'caller'} != 3) {            if ($INFO{'caller'} != 3) {
               fopen(IUSRFILE, "$memberdir/$username.imstore");                fopen(IUSRFILE, "$memberdir/$username.imstore");
               foreach (<IUSRFILE>) {                foreach (<IUSRFILE>) {
                   my @m = split(/\|/, $_);                    my @m = split(/\|/, $_);
                   push(@newmessages, [@m]);                    push(@newmessages, [@m]);
                   $CountStore{$m[13]}++;                    $CountStore{$m[13]}++;
               }                }
               fclose(IUSRFILE);                fclose(IUSRFILE);
           }            }
           fopen(TRANSFER, ">$memberdir/$username.imstore");            fopen(TRANSFER, ">$memberdir/$username.imstore");
           print TRANSFER map({ join('|', @$_) } sort { $$b[6] <=> $$a[6] } @newmessages);            print TRANSFER map({ join('|', @$_) } sort { $$b[6] <=> $$a[6] } @newmessages);
           fclose(TRANSFER);            fclose(TRANSFER);
   
           ${$username}{'PMfoldersCount'} = '';            ${$username}{'PMfoldersCount'} = '';
           foreach (split(/\|/, ${$username}{'PMfolders'})) {            foreach (split(/\|/, ${$username}{'PMfolders'})) {
               $CountStore{$_} ||= 0;                $CountStore{$_} ||= 0;
               ${$username}{'PMfoldersCount'} .= ${$username}{'PMfoldersCount'} eq '' ? $CountStore{$_} : "|$CountStore{$_}";                ${$username}{'PMfoldersCount'} .= ${$username}{'PMfoldersCount'} eq '' ? $CountStore{$_} : "|$CountStore{$_}";
           }            }
           &buildIMS($username, 'update');            &buildIMS($username, 'update');
       }        }
   }    }
   
   my $redirect = 'im';    my $redirect = 'im';
   if ($INFO{'caller'} == 2)    { $redirect = 'imoutbox'; }    if ($INFO{'caller'} == 2)    { $redirect = 'imoutbox'; }
   elsif ($INFO{'caller'} == 3) { $redirect = "imstorage;viewfolder=$INFO{'viewfolder'}"; }    elsif ($INFO{'caller'} == 3) { $redirect = "imstorage;viewfolder=$INFO{'viewfolder'}"; }
   elsif ($INFO{'caller'} == 4) { $redirect = 'imdraft'; }    elsif ($INFO{'caller'} == 4) { $redirect = 'imdraft'; }
   elsif ($INFO{'caller'} == 5) { $redirectview = ';focus=bmess'; }    elsif ($INFO{'caller'} == 5) { $redirectview = ';focus=bmess'; }
   
   $yySetLocation = qq~$scripturl?action=$redirect~;    $yySetLocation = qq~$scripturl?action=$redirect~;
   &redirectexit;    &redirectexit;
} }
   
# if the user is valid.. # if the user is valid..
sub LoadValidUserDisplay { sub LoadValidUserDisplay {
   my $muser = $_[0];    my $muser = $_[0];
   if (!$yyUDLoaded{$muser} && -e "$memberdir/$muser.vars") { $sm = 1; &LoadUserDisplay($muser); }    if (!$yyUDLoaded{$muser} && -e "$memberdir/$muser.vars") { $sm = 1; &LoadUserDisplay($muser); }
} }
   
# 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];    $usrname = $_[0];
   my $usernamelink;    my $usernamelink;
   
   $sendPM = '';    $sendPM = '';
   $sendEmail = '';    $sendEmail = '';
   $membAdInfo = '';    $membAdInfo = '';
   
   if ($yyUDLoaded{$usrname}) {    if ($yyUDLoaded{$usrname}) {
       unless ($INFO{'caller'} == 2 && ($mstatus =~ /b/ || $mtousers =~ /,/ || $mccusers || $mbccusers)) {        unless ($INFO{'caller'} == 2 && ($mstatus =~ /b/ || $mtousers =~ /,/ || $mccusers || $mbccusers)) {
           $signature = ${$uid.$usrname}{'signature'};            $signature = ${$uid.$usrname}{'signature'};
           if ($INFO{'caller'} == 2 || $INFO{'caller'} == 3) { $signature = ''; }            if ($INFO{'caller'} == 2 || $INFO{'caller'} == 3) { $signature = ''; }
           unless($INFO{'caller'} == 5 && $mstatus eq 'g') { &userOnLineStatus($usrname); }            unless($INFO{'caller'} == 5 && $mstatus eq 'g') { &userOnLineStatus($usrname); }
   
           if (!$iamguest) {            if (!$iamguest) {
               # Allow instant message sending if current user is a member.                # 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>~;                $sendPM = qq~$menusep<a href="$scripturl?action=imsend;to=$useraccount{$usrname}">$img{'message_sm'}</a>~;
           }            }
           if (!${$uid.$usrname}{'hidemail'} || $iamadmin || $iamgmod || $allow_hide_email != 1) {            if (!${$uid.$usrname}{'hidemail'} || $iamadmin || $iamgmod || $allow_hide_email != 1) {
               $sendEmail = qq~$menusep<a href="mailto:${$uid.$usrname}{'email'}">$img{'email_sm'}</a>~;                $sendEmail = qq~$menusep<a href="mailto:${$uid.$usrname}{'email'}">$img{'email_sm'}</a>~;
           }            }
   
           my $wwwlink = ${$uid.$usrname}{'weburl'} ? qq~$menusep${$uid.$usrname}{'weburl'}~ : '';             if (!$minlinkweb) { $minlinkweb = 0; } 
             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'}~ : '';            my $aimad = ${$uid.$usrname}{'aim'} ? qq~$menusep${$uid.$usrname}{'aim'}~ : '';
           my $icqad = ${$uid.$usrname}{'icq'} ? qq~$menusep${$uid.$usrname}{'icq'}~ : '';            my $icqad = ${$uid.$usrname}{'icq'} ? qq~$menusep${$uid.$usrname}{'icq'}~ : '';
           my $yimad = ${$uid.$usrname}{'yim'} ? qq~$menusep${$uid.$usrname}{'yim'}~ : '';            my $yimad = ${$uid.$usrname}{'yim'} ? qq~$menusep${$uid.$usrname}{'yim'}~ : '';
           my $msnad = ${$uid.$usrname}{'msn'} ? qq~$menusep${$uid.$usrname}{'msn'}~ : '';            my $msnad = ${$uid.$usrname}{'msn'} ? qq~$menusep${$uid.$usrname}{'msn'}~ : '';
           my $gtalkad = ${$uid.$usrname}{'gtalk'} ? qq~$menusep${$uid.$usrname}{'gtalk'}~ : '';            my $gtalkad = ${$uid.$usrname}{'gtalk'} ? qq~$menusep${$uid.$usrname}{'gtalk'}~ : '';
           my $skypead = ${$uid.$usrname}{'skype'} ? qq~$menusep${$uid.$usrname}{'skype'}~ : '';            my $skypead = ${$uid.$usrname}{'skype'} ? qq~$menusep${$uid.$usrname}{'skype'}~ : '';
           my $myspacead = ${$uid.$usrname}{'myspace'} ? qq~$menusep${$uid.$usrname}{'myspace'}~ : '';            my $myspacead = ${$uid.$usrname}{'myspace'} ? qq~$menusep${$uid.$usrname}{'myspace'}~ : '';
           my $facebookad = ${$uid.$usrname}{'facebook'} ? qq~$menusep${$uid.$usrname}{'facebook'}~ : '';            my $facebookad = ${$uid.$usrname}{'facebook'} ? qq~$menusep${$uid.$usrname}{'facebook'}~ : '';
   
           $membAdInfo = $profbutton . $wwwlink . $msnad . $gtalkad . $icqad . $yimad . $aimad . $skypead . $myspacead . $facebookad;            $membAdInfo = $profbutton . $wwwlink . $msnad . $gtalkad . $icqad . $yimad . $aimad . $skypead . $myspacead . $facebookad;
       }        }
       $usernamelink = $link{$usrname};        $usernamelink = $link{$usrname};
       if ($musername eq $username) {        if ($musername eq $username) {
           $imOpened = &checkIMS($usrname, $messageid, 'messageopened');            $imOpened = &checkIMS($usrname, $messageid, 'messageopened');
           &LoadUser($usrname);            &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>~; }            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 {    } else {
       $usernamelink = qq~<b>$usrname</b>~;        $usernamelink = qq~<b>$usrname</b>~;
   }    }
   $usernamelink;    $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 isn't a FA/gmod and has a postcount below the threshold    ##  if user is not a FA/gmod and has a postcount below the threshold
   if (!$staff && ${$uid.$username}{'postcount'} < $numposts) {    if (!$staff && ${$uid.$username}{'postcount'} < $numposts) {
       &fatal_error('im_low_postcount');        &fatal_error('im_low_postcount');
   }    }
   ##  guests not allowed    ##  guests not allowed
   if ($iamguest) { &fatal_error('im_members_only'); }    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 '' && !$replyguest) {
       if ($INFO{'caller'} < 5) { &updateIMS($username, $INFO{'id'}, 'inread'); }        if ($INFO{'caller'} < 5) { &updateIMS($username, $INFO{'id'}, 'inread'); }
   
       my $pmFileType = "$username.msg";        my $pmFileType = "$username.msg";
       if ($INFO{'caller'} == 2) { $pmFileType = "$username.outbox"; }        if ($INFO{'caller'} == 2) { $pmFileType = "$username.outbox"; }
       elsif ($INFO{'caller'} == 3) { $pmFileType = "$username.imstore"; }        elsif ($INFO{'caller'} == 3) { $pmFileType = "$username.imstore"; }
       elsif ($INFO{'caller'} == 4) { $pmFileType = "$username.imdraft"; }        elsif ($INFO{'caller'} == 4) { $pmFileType = "$username.imdraft"; }
       elsif ($INFO{'caller'} == 5) { $pmFileType = "broadcast.messages"; }        elsif ($INFO{'caller'} == 5) { $pmFileType = "broadcast.messages"; }
   
   
       fopen(FILE, "$memberdir/$pmFileType");        fopen(FILE, "$memberdir/$pmFileType");
       @messages = <FILE>;        @messages = <FILE>;
       fclose(FILE);        fclose(FILE);
       ## split content of IM file up        ## split content of IM file up
       foreach my $checkTheMessage (@messages) {        foreach my $checkTheMessage (@messages) {
           ($qmessageid, $mfrom, $mto, $mtocc, $mtobcc, $msubject, $mdate, $message, $mparid, $mreplyno, $mip, $mstatus, $mflags, $mstore, $mattach) = split(/\|/, $checkTheMessage);            ($qmessageid, $mfrom, $mto, $mtocc, $mtobcc, $msubject, $mdate, $message, $mparid, $mreplyno, $mip, $mstatus, $mflags, $mstore, $mattach) = split(/\|/, $checkTheMessage);
           if ($qmessageid == $INFO{'id'}) { last; }            if ($qmessageid == $INFO{'id'}) { last; }
       }        }
       ## remove 're:' from subject (why?)        ## remove 're:' from subject (why?)
       $msubject =~ s/Re: //g;        $msubject =~ s/Re: //g;
       ## if replying/quoting, up the reply# by 1        ## if replying/quoting, up the reply# by 1
       if ($INFO{'quote'} || $INFO{'reply'}) { $mreplyno++; $INFO{'status'} = $mstatus; }        if ($INFO{'quote'} || $INFO{'reply'}) { $mreplyno++; $INFO{'status'} = $mstatus; }
       ##  if quote        ##  if quote
       if ($INFO{'reply'}) { $message = ''; }        if ($INFO{'reply'}) { $message = ''; }
       if ($INFO{'quote'}) {        if ($INFO{'quote'}) {
           # swap out brs and spaces            # swap out brs and spaces
           $message =~ s~<br.*?>~\n~gi;            $message =~ s~<br.*?>~\n~gi;
           $message =~ s/ \&nbsp; \&nbsp; \&nbsp;/\t/ig;            $message =~ s/ \&nbsp; \&nbsp; \&nbsp;/\t/ig;
           if (!$nestedquotes) {            if (!$nestedquotes) {
               $message =~ s~\n{0,1}\[quote([^\]]*)\](.*?)\[/quote([^\]]*)\]\n{0,1}~\n~isg;                $message =~ s~\n{0,1}\[quote([^\]]*)\](.*?)\[/quote([^\]]*)\]\n{0,1}~\n~isg;
           }            }
           if ($mfrom ne "" && $do_scramble_id) { $cloakedAuthor = &cloak($mfrom); }            if ($mfrom ne "" && $do_scramble_id) { $cloakedAuthor = &cloak($mfrom); }
           else { $cloakedAuthor = $mfrom; }            else { $cloakedAuthor = $mfrom; }
   
           # next 2 lines for display names in Quotes in LivePreview            # next 2 lines for display names in Quotes in LivePreview
           &LoadUser($mfrom);            &LoadUser($mfrom);
           $usernames_life_quote{$cloakedAuthor} = ${$uid.$mfrom}{'realname'};            $usernames_life_quote{$cloakedAuthor} = ${$uid.$mfrom}{'realname'};
   
           $quotestart = int($quotemsg / $maxmessagedisplay) * $maxmessagedisplay;            $quotestart = int($quotemsg / $maxmessagedisplay) * $maxmessagedisplay;
           if ($INFO{'forward'} || $INFO{'quote'}) {            if ($INFO{'forward'} || $INFO{'quote'}) {
               $message    = qq~[quote author=$cloakedAuthor link=impost date=$mdate\]$message\[/quote\]\n~;                $message    = qq~[quote author=$cloakedAuthor link=impost date=$mdate\]$message\[/quote\]\n~;
           }            }
           if ($message =~ /\#nosmileys/isg) { $message =~ s/\#nosmileys//isg; $nscheck = "checked"; }            if ($message =~ /\#nosmileys/isg) { $message =~ s/\#nosmileys//isg; $nscheck = "checked"; }
       }        }
       if ($INFO{'reply'} || $INFO{'forward'} || $INFO{'quote'}) { $msubject = "Re: $msubject"; }        if ($INFO{'reply'} || $INFO{'forward'} || $INFO{'quote'}) { $msubject = "Re: $msubject"; }
   } elsif ($replyguest) {    } elsif ($replyguest) {
       fopen(FILE, "$memberdir/broadcast.messages");        fopen(FILE, "$memberdir/broadcast.messages");
       my @messages = <FILE>;        my @messages = <FILE>;
       fclose(FILE);        fclose(FILE);
       ## split content of IM file up        ## split content of IM file up
       foreach my $checkTheMessage (@messages){        foreach my $checkTheMessage (@messages){
           ($qmessageid, $mfrom, $mto, $mtocc, $mtobcc, $msubject, $mdate, $message, $mparid, $mreplyno, $mip, $mstatus, $mflags, $mstore, $mattach) = split(/\|/, $checkTheMessage);            ($qmessageid, $mfrom, $mto, $mtocc, $mtobcc, $msubject, $mdate, $message, $mparid, $mreplyno, $mip, $mstatus, $mflags, $mstore, $mattach) = split(/\|/, $checkTheMessage);
           if ($qmessageid == $INFO{'id'}) { last; }            if ($qmessageid == $INFO{'id'}) { last; }
       }        }
       ($guestName, $guestEmail) = split(/\ /, $mfrom);        ($guestName, $guestEmail) = split(/\ /, $mfrom);
       $guestName =~ s/%20/ /g;        $guestName =~ s/%20/ /g;
       $message =~ s~<br.*?>~\n~gi;        $message =~ s~<br.*?>~\n~gi;
       $message =~ s/ \&nbsp; \&nbsp; \&nbsp;/\t/ig;        $message =~ s/ \&nbsp; \&nbsp; \&nbsp;/\t/ig;
       $message =~ s~\[b\](.*?)\[/b\]~*$1*~isg;        $message =~ s~\[b\](.*?)\[/b\]~*$1*~isg;
       $message =~ s~\[i\](.*?)\[/i\]~/$1/~isg;        $message =~ s~\[i\](.*?)\[/i\]~/$1/~isg;
       $message =~ s~\[u\](.*?)\[/u\]~_$1_~isg;        $message =~ s~\[u\](.*?)\[/u\]~_$1_~isg;
       $message =~ s~\[.*?\]~~g;        $message =~ s~\[.*?\]~~g;
       my $sendtouser = ${$uid.$username}{'realname'};        my $sendtouser = ${$uid.$username}{'realname'};
       my $mdate = &timeformat($mdate, 1);        my $mdate = &timeformat($mdate, 1);
       require "$sourcedir/Mailer.pl";        require "$sourcedir/Mailer.pl";
       &LoadLanguage('Email');        &LoadLanguage('Email');
       #sender email date subject message        #sender email date subject message
       $message = &template_email($replyguestmail, {'sender' => $guestName, 'email' => $guestEmail, 'sendto' => $sendtouser, 'date' => $mdate, 'subject' => $msubject, 'message' => $message});        $message = &template_email($replyguestmail, {'sender' => $guestName, 'email' => $guestEmail, 'sendto' => $sendtouser, 'date' => $mdate, 'subject' => $msubject, 'message' => $message});
       $msubject = qq~Re: $msubject~;        $msubject = qq~Re: $msubject~;
   }    }
   
   &FromHTML($message) if $INFO{'forward'} || $INFO{'quote'};    &FromHTML($message) if $INFO{'forward'} || $INFO{'quote'};
   &FromHTML($msubject);    &FromHTML($msubject);
   
   $submittxt = $inmes_txt{'sendmess'};    $submittxt = $inmes_txt{'sendmess'};
   if ($INFO{'forward'} == 1) { $submittxt = $inmes_txt{'forward'}; }    if ($INFO{'forward'} == 1) { $submittxt = $inmes_txt{'forward'}; }
   $destination = 'imsend2';    $destination = 'imsend2';
   $waction = 'imsend';    $waction = 'imsend';
   $is_preview = 0;    $is_preview = 0;
   $post = 'imsend';    $post = 'imsend';
   $previewtxt = $inmes_txt{'507'};    $previewtxt = $inmes_txt{'507'};
   $preview = 'previewim';    $preview = 'previewim';
   $icon = 'xx';    $icon = 'xx';
   $draft = 'draft';    $draft = 'draft';
   $mctitle = $inmes_txt{'sendmess'};    $mctitle = $inmes_txt{'sendmess'};
   if ($sendBMess) { $mctitle = $inmes_txt{'sendbroadmess'}; }    if ($sendBMess) { $mctitle = $inmes_txt{'sendbroadmess'}; }
} }
   
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;    seek FILE, 0, 0;
   my @messages = <FILE>;    my @messages = <FILE>;
   seek FILE, 0, 0;    seek FILE, 0, 0;
   truncate FILE, 0;    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 ($imessageid, $imusername, $imusernameto, $imusernametocc, $imusernametobcc, $imsub, $imdate, $mmessage, $imessagepid, $imreply, $mip, $imstatus, $imflags, $imstore, $imattach) = split(/\|/, $_);
       if ($imflags =~ s/u//i) {        if ($imflags =~ s/u//i) {
           print FILE "$imessageid|$imusername|$imusernameto|$imusernametocc|$imusernametobcc|$imsub|$imdate|$mmessage|$imessagepid|$imreply|$mip|$imstatus|$imflags|$imstore|$imattach";            print FILE "$imessageid|$imusername|$imusernameto|$imusernametocc|$imusernametobcc|$imsub|$imdate|$mmessage|$imessagepid|$imreply|$mip|$imstatus|$imflags|$imstore|$imattach";
       } else { print FILE $_; }        } else { print FILE $_; }
   }    }
   fclose(FILE);    fclose(FILE);
   
   ${$username}{'PMimnewcount'} = 0;    ${$username}{'PMimnewcount'} = 0;
   &buildIMS($username, 'update');    &buildIMS($username, 'update');
   
   if ($INFO{'oldmarkread'}) {    if ($INFO{'oldmarkread'}) {
       $yySetLocation = qq~$scripturl?action=im~;        $yySetLocation = qq~$scripturl?action=im~;
       &redirectexit;        &redirectexit;
   }    }
   $elenable = 0;    $elenable = 0;
   die ""; # This is here only to avoid server error log entries!    die ""; # 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) = split(/\|/, ${$uid.$username}{'pageindex'});
   if ($INFO{'action'} eq 'pmpagedrop') { ${$uid.$username}{'pageindex'} = qq~$msindx|$trindx|$mbindx|1~; }    if ($INFO{'action'} eq 'pmpagedrop') { ${$uid.$username}{'pageindex'} = qq~$msindx|$trindx|$mbindx|1~; }
   if ($INFO{'action'} eq 'pmpagetext') { ${$uid.$username}{'pageindex'} = qq~$msindx|$trindx|$mbindx|0~; }    if ($INFO{'action'} eq 'pmpagetext') { ${$uid.$username}{'pageindex'} = qq~$msindx|$trindx|$mbindx|0~; }
   &UserAccount($username, 'update');    &UserAccount($username, 'update');
   if ($INFO{'pmaction'} =~ /\//) {    if ($INFO{'pmaction'} =~ /\//) {
       my ($act, $val) = split(/\//, $INFO{'pmaction'});        my ($act, $val) = split(/\//, $INFO{'pmaction'});
       $INFO{'pmaction'} = $act . ';start=' . $val;        $INFO{'pmaction'} = $act . ';start=' . $val;
   }    }
   if ($INFO{'focus'} eq 'bmess') { $bmesslink = qq~;focus=bmess~;}    if ($INFO{'focus'} eq 'bmess') { $bmesslink = qq~;focus=bmess~;}
   $yySetLocation = qq~$scripturl?action=$INFO{'pmaction'}$bmesslink;start=$INFO{'start'}~ . ($INFO{'viewfolder'} ? ";viewfolder=$INFO{'viewfolder'}" : "");    $yySetLocation = qq~$scripturl?action=$INFO{'pmaction'}$bmesslink;start=$INFO{'start'}~ . ($INFO{'viewfolder'} ? ";viewfolder=$INFO{'viewfolder'}" : "");
   &redirectexit;    &redirectexit;
} }
   
# 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');    &LoadLanguage('InstantMessage');
   &LoadLanguage('Profile');    &LoadLanguage('Profile');
   $PMfileToOpen = $_[0];    $PMfileToOpen = $_[0];
   @dimmessages;    @dimmessages;
   @bmessages;    @bmessages;
   if ($view eq 'pm' && ($PM_level  == 1 || $PM_level  == 2 && ($iamadmin || $iamgmod || $iammod) || $PM_level  == 3 && ($iamadmin || $iamgmod) )) {    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);        ($qmessageid, $mfrom, $mto, $mtocc, $mtobcc, $msubject, $mdate, $message, $mparid, $mreplyno, $mip, $mstatus, $mflags, $mstore, $mattach);
   
       if (!$INFO{'focus'}) {        if (!$INFO{'focus'}) {
           if ($callerid < 5) {            if ($callerid < 5) {
               fopen(NFILE, "$memberdir/$username.$PMfileToOpen");                fopen(NFILE, "$memberdir/$username.$PMfileToOpen");
               @dimmessages = <NFILE>;                @dimmessages = <NFILE>;
               my ($mID,$mFlag);                my ($mID,$mFlag);
               foreach (reverse(@dimmessages)) {                foreach (reverse(@dimmessages)) {
                   ($mID, undef, undef, undef, undef, undef, undef, undef, undef, undef, undef, undef, $mFlag, undef) = split(/\|/, $_,  14);                    ($mID, undef, undef, undef, undef, undef, undef, undef, undef, undef, undef, undef, $mFlag, undef) = split(/\|/, $_,  14);
                   ${$username . $PMfileToOpen}{$mID} = $mFlag;                    ${$username . $PMfileToOpen}{$mID} = $mFlag;
                   if ($INFO{'id'} == -1 && $mFlag eq 'u') {                    if ($INFO{'id'} == -1 && $mFlag eq 'u') {
                       $INFO{'id'} = $mID;                        $INFO{'id'} = $mID;
                   }                    }
               }                }
           } else {            } else {
               fopen(NFILE, "$memberdir/broadcast.messages");                fopen(NFILE, "$memberdir/broadcast.messages");
               @bmessages = <NFILE>;                @bmessages = <NFILE>;
           }            }
           fclose(NFILE);            fclose(NFILE);
       }        }
       elsif ($INFO{'focus'} eq 'bmess' && $PMenableBm_level > 0) {        elsif ($INFO{'focus'} eq 'bmess' && $PMenableBm_level > 0) {
           fopen(BFILE, "$memberdir/broadcast.messages");            fopen(BFILE, "$memberdir/broadcast.messages");
           @bmessages = <BFILE>;            @bmessages = <BFILE>;
           fclose(BFILE);            fclose(BFILE);
       }        }
       $stkmess = 0;        $stkmess = 0;
       if (@bmessages > 0) {        if (@bmessages > 0) {
           foreach my $checkbcm (@bmessages) {            foreach my $checkbcm (@bmessages) {
               my (undef, $mfrom, $mto, undef, undef, undef, undef, undef, undef, undef, undef, $messStatus, undef) = split (/\|/, $checkbcm);                my (undef, $mfrom, $mto, undef, undef, undef, undef, undef, undef, undef, undef, $messStatus, undef) = split (/\|/, $checkbcm);
               if ($mfrom eq $username || &BroadMessageView($mto)) {                if ($mfrom eq $username || &BroadMessageView($mto)) {
                   if ($INFO{'sort'} ne 'gpdate' && ($messStatus =~ /g/ || $messStatus =~ /a/)) {                    if ($INFO{'sort'} ne 'gpdate' && ($messStatus =~ /g/ || $messStatus =~ /a/)) {
                       push (@stkbmessages, $checkbcm);                        push (@stkbmessages, $checkbcm);
                       $stkmess++;                        $stkmess++;
                   } else {                    } else {
                       push (@tmpbmessages, $checkbcm);                        push (@tmpbmessages, $checkbcm);
                   }                    }
               }                }
           }            }
           undef @bmessages;            undef @bmessages;
       }        }
       @stkbmessages = sort {$b <=> $a} @stkbmessages;        @stkbmessages = sort {$b <=> $a} @stkbmessages;
       @tmpbmessages = sort {$b <=> $a} @tmpbmessages;        @tmpbmessages = sort {$b <=> $a} @tmpbmessages;
       push (@dimmessages, @stkbmessages);        push (@dimmessages, @stkbmessages);
       push (@dimmessages, @tmpbmessages);        push (@dimmessages, @tmpbmessages);
       undef @stkbmessages;        undef @stkbmessages;
       undef @tmpbmessages;        undef @tmpbmessages;
   }    }
   
   $yyjavascript .= qq~    $yyjavascript .= qq~
       function changeBox(cbox) {        function changeBox(cbox) {
           box = eval(cbox);            box = eval(cbox);
           box.checked = !box.checked;            box.checked = !box.checked;
       }        }
   ~;    ~;
   
   
   ##  new style box ####    ##  new style box ####
   ## start with forum > my messages > inbox    ## start with forum > my messages > inbox
   $yymain .= qq~    $yymain .= qq~
<script language="JavaScript1.2" src="$yyhtml_root/ajax.js" type="text/javascript"></script> <script language="JavaScript1.2" src="$yyhtml_root/ajax.js" type="text/javascript"></script>
<script language="JavaScript1.2" type="text/javascript"> <script language="JavaScript1.2" 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 (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" ? qq~if (theForm.name.value == "" || theForm.name.value == "_" || theForm.name.value == " ") { alert("$post_txt{'75'}"); theForm.name.focus(); return false }
   if (theForm.name.value.length > 25)  { alert("$post_txt{'568'}"); theForm.name.focus(); return false }    if (theForm.name.value.length > 25)  { alert("$post_txt{'568'}"); theForm.name.focus(); return false }
   if (theForm.email.value == "") { alert("$post_txt{'76'}"); theForm.email.focus(); return false }    if (theForm.email.value == "") { alert("$post_txt{'76'}"); theForm.email.focus(); return false }
   if (! checkMailaddr(theForm.email.value)) { alert("$post_txt{'500'}"); theForm.email.focus(); return false }    if (! checkMailaddr(theForm.email.value)) { alert("$post_txt{'500'}"); theForm.email.focus(); return false }
~ : qq~if (postas == "imsend") { if (theForm.toshow.value == "") { alert("$post_txt{'752'}"); theForm.toshow.focus(); return false } }~) . qq~ ~ : 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 }    if (theForm.message.value == "") { alert("$post_txt{'78'}"); theForm.message.focus(); return false }
   return true    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/ && (!@dimmessages && $INFO{'focus'} ne 'bmess') && ($PM_level == 1 || $PM_level == 2 && ($iamadmin || $iamgmod || $iammod) || $PM_level == 3 && ($iamadmin || $iamgmod))) {
       if (!@dimmessages) {        if (!@dimmessages) {
           if ($action eq 'im') { unlink("$memberdir/$username.msg"); }            if ($action eq 'im') { unlink("$memberdir/$username.msg"); }
           elsif ($action eq 'imoutbox')  { unlink("$memberdir/$username.outbox"); }            elsif ($action eq 'imoutbox')  { unlink("$memberdir/$username.outbox"); }
           elsif ($action eq 'imstorage') { unlink("$memberdir/$username.imstore"); }            elsif ($action eq 'imstorage') { unlink("$memberdir/$username.imstore"); }
           elsif ($action eq 'imdraft') { unlink("$memberdir/$username.imdraft"); }            elsif ($action eq 'imdraft') { unlink("$memberdir/$username.imdraft"); }
       }        }
   }    }
   
   &LoadCensorList;    &LoadCensorList;
   
   # Fix moderator showing in info    # Fix moderator showing in info
   $sender = 'im';    $sender = 'im';
   $acount = 0;    $acount = 0;
   ## set browser title    ## set browser title
   $yytitle = $mycenter_txt{'welcometxt'};    $yytitle = $mycenter_txt{'welcometxt'};
   
   ## start new container - left side is menu, right side is content    ## start new container - left side is menu, right side is content
   my ($display_prof, $display_posts, $display_pm, $tabPMHighlighted, $tabProfHighlighted, $tabNotifyHighlighted);    my ($display_prof, $display_posts, $display_pm, $tabPMHighlighted, $tabProfHighlighted, $tabNotifyHighlighted);
   
   if ($mycenter_template =~ /({|<)yabb mcmenu(}|>)/g) {    if ($mycenter_template =~ /({|<)yabb mcmenu(}|>)/g) {
       &mcMenu;        &mcMenu;
       $newtemplate = 1;        $newtemplate = 1;
   }    }
   
   if ($view eq 'profile' || ($view eq 'mycenter' && ($PM_level == 0 || ($PM_level == 2 && !$iamadmin && !$iamgmod && !$iammod ) || ($PM_level == 3 && !$iamadmin && !$iamgmod)))) {    if ($view eq 'profile' || ($view eq 'mycenter' && ($PM_level == 0 || ($PM_level == 2 && !$iamadmin && !$iamgmod && !$iammod ) || ($PM_level == 3 && !$iamadmin && !$iamgmod)))) {
       $display_prof = 'inline';        $display_prof = 'inline';
       $tabProfHighlighted = 'windowbg2';        $tabProfHighlighted = 'windowbg2';
   } else {    } else {
       $display_prof = 'none';        $display_prof = 'none';
       $tabProfHighlighted = 'windowbg';        $tabProfHighlighted = 'windowbg';
   }    }
   
   if ($view eq 'notify' || $view eq 'favorites' || $view eq 'recentposts') {    if ($view eq 'notify' || $view eq 'favorites' || $view eq 'recentposts') {
       $display_posts = 'inline';        $display_posts = 'inline';
       $tabNotifyHighlighted = 'windowbg2';        $tabNotifyHighlighted = 'windowbg2';
   } else {    } else {
       $display_posts = 'none';        $display_posts = 'none';
       $tabNotifyHighlighted = 'windowbg';        $tabNotifyHighlighted = 'windowbg';
   }    }
   
   if ($view eq 'pm' || ($view eq 'mycenter' && ($PM_level == 1 || ($PM_level == 2 && ($iamadmin || $iamgmod || $iammod)) || ($PM_level == 3 && ($iamadmin || $iamgmod))))) {    if ($view eq 'pm' || ($view eq 'mycenter' && ($PM_level == 1 || ($PM_level == 2 && ($iamadmin || $iamgmod || $iammod)) || ($PM_level == 3 && ($iamadmin || $iamgmod))))) {
       $display_pm = 'inline';        $display_pm = 'inline';
   
       $tabPMHighlighted = 'windowbg2';        $tabPMHighlighted = 'windowbg2';
   } else {    } else {
       $display_pm = 'none';        $display_pm = 'none';
       $tabPMHighlighted = 'windowbg';        $tabPMHighlighted = 'windowbg';
   }    }
   
   my $tabWidth = '33%';    my $tabWidth = '33%';
   if ($PM_level == 0 || ($PM_level == 2 && !$iamadmin && !$iamgmod && !$iammod ) || ($PM_level == 3 && !$iamadmin && !$iamgmod)) { $tabWidth = '50%'; }    if ($PM_level == 0 || ($PM_level == 2 && !$iamadmin && !$iamgmod && !$iammod ) || ($PM_level == 3 && !$iamadmin && !$iamgmod)) { $tabWidth = '50%'; }
   $MCViewMenu = '';    $MCViewMenu = '';
   $MCPmMenu = '';    $MCPmMenu = '';
   $MCProfMenu = '';    $MCProfMenu = '';
   $MCPostsMenu = '';    $MCPostsMenu = '';
   $MCExtraSmilies = '';    $MCExtraSmilies = '';
   $MCContent = '';    $MCContent = '';
   
   if ($newtemplate) {    if ($newtemplate) {
       $MCViewMenu .= qq~        $MCViewMenu .= qq~
       <script language="JavaScript1.2" type="text/javascript">        <script language="JavaScript1.2" type="text/javascript">
       <!--        <!--
       function changeToTab(tab) {~;        function changeToTab(tab) {~;
       if ($PM_level == 1 || ($PM_level == 2 && ($iamadmin || $iamgmod || $iammod)) || ($PM_level == 3 && ($iamadmin || $iamgmod))) {        if ($PM_level == 1 || ($PM_level == 2 && ($iamadmin || $iamgmod || $iammod)) || ($PM_level == 3 && ($iamadmin || $iamgmod))) {
           $MCViewMenu .= qq~            $MCViewMenu .= qq~
           document.getElementById('cont_pm').style.display = 'none';            document.getElementById('cont_pm').style.display = 'none';
           document.getElementById('menu_pm').className = '';~;            document.getElementById('menu_pm').className = '';~;
       }        }
       $MCViewMenu .= qq~        $MCViewMenu .= qq~
           document.getElementById('cont_prof').style.display = 'none';            document.getElementById('cont_prof').style.display = 'none';
           document.getElementById('menu_prof').className = '';            document.getElementById('menu_prof').className = '';
           document.getElementById('cont_posts').style.display = 'none';            document.getElementById('cont_posts').style.display = 'none';
           document.getElementById('menu_posts').className = '';            document.getElementById('menu_posts').className = '';
           document.getElementById('cont_' + tab).style.display = 'inline';            document.getElementById('cont_' + tab).style.display = 'inline';
           document.getElementById('menu_' + tab).className = 'selected';            document.getElementById('menu_' + tab).className = 'selected';
       }        }
       //-->        //-->
       </script>~;        </script>~;
   } else {    } else {
       $MCViewMenu .= qq~        $MCViewMenu .= qq~
       <script language="JavaScript1.2" type="text/javascript">        <script language="JavaScript1.2" type="text/javascript">
       <!--        <!--
       function changeToTab(tab) {~;        function changeToTab(tab) {~;
       if ($PM_level == 1 || ($PM_level == 2 && ($iamadmin || $iamgmod || $iammod)) || ($PM_level == 3 && ($iamadmin || $iamgmod))) {        if ($PM_level == 1 || ($PM_level == 2 && ($iamadmin || $iamgmod || $iammod)) || ($PM_level == 3 && ($iamadmin || $iamgmod))) {
           $MCViewMenu .= qq~            $MCViewMenu .= qq~
           document.getElementById('cont_pm').style.display = 'none';            document.getElementById('cont_pm').style.display = 'none';
           document.getElementById('menu_pm').className = 'windowbg';~;            document.getElementById('menu_pm').className = 'windowbg';~;
       }        }
       $MCViewMenu .= qq~        $MCViewMenu .= qq~
           document.getElementById('cont_prof').style.display = 'none';            document.getElementById('cont_prof').style.display = 'none';
           document.getElementById('menu_prof').className = 'windowbg';            document.getElementById('menu_prof').className = 'windowbg';
           document.getElementById('cont_posts').style.display = 'none';            document.getElementById('cont_posts').style.display = 'none';
           document.getElementById('menu_posts').className = 'windowbg';            document.getElementById('menu_posts').className = 'windowbg';
           document.getElementById('cont_' + tab).style.display = 'inline';            document.getElementById('cont_' + tab).style.display = 'inline';
           document.getElementById('menu_' + tab).className = 'windowbg2';            document.getElementById('menu_' + tab).className = 'windowbg2';
       }        }
       //-->        //-->
       </script>\n~;        </script>\n~;
       $MCViewMenu .= qq~        $MCViewMenu .= qq~
       <table width="100%" border="0" cellspacing="0" cellpadding="0" align="center" >        <table width="100%" border="0" cellspacing="0" cellpadding="0" align="center" >
       <tr>~;        <tr>~;
       if ($PM_level == 0 || ($PM_level == 2 && !$iamadmin && !$iamgmod && !$iammod ) || ($PM_level == 3 && !$iamadmin && !$iamgmod)) {        if ($PM_level == 0 || ($PM_level == 2 && !$iamadmin && !$iamgmod && !$iammod ) || ($PM_level == 3 && !$iamadmin && !$iamgmod)) {
           $display_prof = 'inline';            $display_prof = 'inline';
           $tabProfHighlighted = 'windowbg2';            $tabProfHighlighted = 'windowbg2';
       }        }
       if ($PM_level == 1 || ($PM_level == 2 && ($iamadmin || $iamgmod || $iammod)) || ($PM_level == 3 && ($iamadmin || $iamgmod))   ) {        if ($PM_level == 1 || ($PM_level == 2 && ($iamadmin || $iamgmod || $iammod)) || ($PM_level == 3 && ($iamadmin || $iamgmod))   ) {
           $MCViewMenu .= qq~            $MCViewMenu .= qq~
           <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>~;            <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>~;
       }        }
       $MCViewMenu .= qq~        $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>            <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>
           <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>            <td width="$tabWidth" align=