############################################################################### # Notify.pl # ############################################################################### # YaBB: Yet another Bulletin Board # # Open-Source Community Software for Webmasters # # Version: YaBB 3.0 Beta # # Packaged: October 05, 2010 # # Distributed by: http://www.yabbforum.com # # =========================================================================== # # Copyright (c) 2000-2010 YaBB (www.yabbforum.com) - All Rights Reserved. # # Software by: The YaBB Development Team # # with assistance from the YaBB community. # ############################################################################### $notifyplver = 'YaBB 3.0 Beta $Revision: 338 $'; if ($action eq 'detailedversion') { return 1; } &LoadLanguage('Notify'); sub ManageBoardNotify { my $todo = $_[0]; my $theboard = $_[1]; my $user = $_[2]; my $userlang = $_[3]; my $notetype = $_[4]; my $noteview = $_[5]; if ($todo eq "load" || $todo eq "update" || $todo eq "delete" || $todo eq "add") { undef %theboard; ## open board mail file and build hash name / detail %theboard = map /(.*)\t(.*)/, &read_DBorFILE(1,'',$boardsdir,$theboard,'mail'); } if ($todo eq "add") { $theboard{$user} = "$userlang|$notetype|$noteview"; &LoadUser($user); my %b; foreach (split(/,/, ${$uid.$user}{'board_notifications'})) { $b{$_} = 1; } $b{$theboard} = 1; ${$uid.$user}{'board_notifications'} = join(',', keys %b); &UserAccount($user); } elsif ($todo eq "update") { if (exists $theboard{$user}) { my ($memlang, $memtype, $memview) = split(/\|/, $theboard{$user}); if ($userlang) { $memlang = $userlang; } if ($notetype) { $memtype = $notetype; } if ($noteview) { $memview = $noteview; } $theboard{$user} = "$memlang|$memtype|$memview"; } } elsif ($todo eq "delete") { my %b; foreach my $u (split(',', $user)) { delete $theboard{$u}; &LoadUser($u); foreach (split(/,/, ${$uid.$u}{'board_notifications'})) { $b{$_} = 1; } if (delete $b{$theboard}) { ${$uid.$u}{'board_notifications'} = join(',', keys %b); &UserAccount($u); } undef %b; } } if ($todo eq "save" || $todo eq "update" || $todo eq "delete" || $todo eq "add") { if (%theboard) { &write_DBorFILE(1,'',$boardsdir,$theboard,'mail',(map "$_\t$theboard{$_}\n", sort { $theboard{$a} cmp $theboard{$b} } keys %theboard)); undef %theboard; } else { &delete_DBorFILE("$boardsdir/$theboard.mail"); } } } sub BoardNotify { if (!$currentboard) { &fatal_error("no_access"); } if ($iamguest) { &fatal_error("members_only"); } my ($curuser, $curlang, $notifytype); $selected1 = ""; $selected2 = ""; $deloption = ""; my ($boardname, undef) = split(/\|/, $board{$currentboard}, 2); &ToChars($boardname); &ManageBoardNotify("load", $currentboard); $yymain .= qq~
~; undef %theboard; $yytitle = "$notify_txt{'125'}"; &template; } sub BoardNotify2 { if ($iamguest) { &fatal_error("members_only"); } foreach $variable (keys %FORM) { if ($variable eq 'formsession') { next; } $notify_type = $FORM{$variable}; if ($notify_type == 1 || $notify_type == 2) { &ManageBoardNotify("add", $variable, $username, ${$uid.$username}{'language'}, $notify_type, "1"); } elsif ($notify_type == 3) { &ManageBoardNotify("delete", $variable, $username); } } if ($action eq "boardnotify3") { $yySetLocation = qq~$scripturl?board=$INFO{'board'}~; } else { $yySetLocation = qq~$scripturl?action=shownotify~; } &redirectexit; } sub ManageThreadNotify { my $todo = $_[0]; my $thethread = $_[1]; my $user = $_[2]; my $userlang = $_[3]; my $notetype = $_[4]; my $noteview = $_[5]; if ($todo eq "load" || $todo eq "update" || $todo eq "delete" || $todo eq "add") { undef %thethread; ## open mail file and build hash %thethread = map /(.*)\t(.*)/, &read_DBorFILE(1,'',$datadir,$thethread,'mail'); } if ($todo eq "add") { $thethread{$user} = "$userlang|$notetype|$noteview"; &LoadUser($user); my %t; foreach (split(/,/, ${$uid.$user}{'thread_notifications'})) { $t{$_} = 1; } $t{$thethread} = 1; ${$uid.$user}{'thread_notifications'} = join(',', keys %t); &UserAccount($user); } elsif ($todo eq "update") { if (exists $thethread{$user}) { ($memlang, $memtype, $memview) = split(/\|/, $thethread{$user}); if ($userlang) { $memlang = $userlang; } if ($notetype) { $memtype = $notetype; } if ($noteview) { $memview = $noteview; } $thethread{$user} = "$memlang|$memtype|$memview"; } } elsif ($todo eq "delete") { my %t; foreach my $u (split(',', $user)) { delete $thethread{$u}; &LoadUser($u); foreach (split(/,/, ${$uid.$u}{'thread_notifications'})) { $t{$_} = 1; } if (delete $t{$thethread}) { ${$uid.$u}{'thread_notifications'} = join(',', keys %t); &UserAccount($u); } undef %t; } } if ($todo eq "save" || $todo eq "update" || $todo eq "delete" || $todo eq "add") { if (%thethread) { &write_DBorFILE(1,'',$datadir,$thethread,'mail',(map "$_\t$thethread{$_}\n", sort { $thethread{$a} cmp $thethread{$b} } keys %thethread)); undef %thethread; } else { &delete_DBorFILE("$datadir/$thethread.mail"); } } } # sub Notify { delted because not needed any more since YaBB 2.3 (deti) sub Notify2 { if ($iamguest) { &fatal_error("members_only"); } &ManageThreadNotify("add", $INFO{'num'}, $username, ${$uid.$username}{'language'}, 1, 1); if ($INFO{'oldnotify'}) { &redirectinternal; } $elenable = 0; die ""; # This is here only to avoid server error log entries! } sub Notify3 { if ($iamguest) { &fatal_error("members_only"); } &ManageThreadNotify("delete", $INFO{'num'}, $username); if ($INFO{'oldnotify'}) { &redirectinternal; } $elenable = 0; die ""; # This is here only to avoid server error log entries! } sub Notify4 { if ($iamguest) { &fatal_error("members_only"); } my ($variable, $notype, $threadno); foreach $variable (keys %FORM) { ($notype, $threadno) = split(/-/, $variable); if ($notype eq "thread") { &ManageThreadNotify("delete", $threadno, $username); } } $action = 'shownotify'; &ShowNotifications; } sub updateLanguage { my ($user,$newlang) = @_; &getMailFiles; foreach (@bmaildir) { &ManageBoardNotify("update", $_, $user, $newlang, "", ""); } foreach (@tmaildir) { &ManageThreadNotify("update", $_, $user, $newlang, "", ""); } } sub removeNotifications { my $user_s = shift; &getMailFiles; foreach (@bmaildir) { &ManageBoardNotify("delete", $_, $user_s); } foreach (@tmaildir) { &ManageThreadNotify("delete", $_, $user_s); } } sub getMailFiles { opendir(BOARDNOT, "$boardsdir"); @bmaildir = map { (split(/\./, $_))[0] } grep { /\.mail$/ } readdir(BOARDNOT); closedir(BOARDNOT); if ($use_MySQL) { @tmaildir = &get_mail_array(); } else { opendir(THREADNOT, "$datadir"); @tmaildir = map { (split(/\./, $_))[0] } grep { /\.mail$/ } readdir(THREADNOT); closedir(THREADNOT); } } sub ShowNotifications { ## bye bye guest.... if ($iamguest) { &fatal_error("members_only"); } $yynavigation = qq~› $img_txt{'mycenter'} › $img_txt{'418'}~; # Show Javascript for 'check all' notifications $showNotifications .= qq~
~;
}
}
$thread_notify{$mythread} = [$mythread, $msub, $new, $username_link, $catname_link, $boardname_link, ${$mythread}{'lastpostdate'}];
}
}
(\%board_notify,\%thread_notify);
}
1;