#####################################################
#  LEO SuperCool BBS / LeoBBS X / 雷傲極酷超級論壇  #
#####################################################
# 基於山鷹(糊)、花無缺製作的 LB5000 XP 2.30 免費版  #
#   新版程式製作 & 版權所有: 雷傲科技 (C)(R)2004    #
#####################################################
#      主頁地址： http://www.LeoBBS.com/            #
#      論壇地址： http://bbs.LeoBBS.com/            #
#####################################################

my $lockfile = "$lbdir" . "lock/birthday.lck";
if (!(-e $lockfile)) {
    open (LOCKBIRTH, ">$lockfile");
    close (LOCKBIRTH);

    undef @birthdaytoday;
    open (MEMFILE, "${lbdir}data/lbmember3.cgi");
    my @memberdata = <MEMFILE>;
    close (MEMFILE);

    foreach (@memberdata) {
    	chomp $_;
    	(my $users, my $borns) = split(/\t/,$_);
    	(my $unowy, my $unowm, my $unowd) = split(/\//, $borns);
    	if (($nowm eq $unowm)&&($nowd eq $unowd)) {
            my $usersfilename = $users;
            $usersfilename =~ s/ /\_/g;
            $usersfilename =~ tr/A-Z/a-z/;
            $unowy = $nowy - $unowy;
            $unowy = $unowy - 1900 if ($unowy > 1900);
            push(@birthdaytoday, "$users\t$usersfilename\t$unowy\t\n");
            if ($sendtobirthday eq "yes") {
               	open (FILE, "${lbdir}$msgdir/in/${usersfilename}_msg.cgi");
		sysread(FILE, my $inboxmessages,(stat(FILE))[7]);
               	close (FILE);
	        $inboxmessages =~ s/\r//isg;
               	open (FILE, ">${lbdir}$msgdir/in/${usersfilename}_msg.cgi");
               	print FILE "＊＃！＆＊全體管理人員\tno\t$currenttime\t《$boardname》祝您生日快樂！\t今天是您 $unowy 歲生日,《$boardname》祝您生日快樂！\n$inboxmessages";
                close (FILE);
            }
    	}
    }
    
    chomp @birthdaytoday;
    foreach (@birthdaytoday) {
      	next if ($_ eq "");
	(my $users,my $usersfilename,my $unowy) = split(/\t/,$_);
	next if ($users eq "");
	$birthdayuser .= qq~<span style=cursor:hand onClick=javascript:O9('~ . uri_escape($usersfilename) . qq~') title=祝$unowy歲生日快樂！>$users</span>, ~;
    }
    chop $birthdayuser;
    chop $birthdayuser;
    $borncount = @birthdaytoday;
            
    open (BDILE, ">${lbdir}data/birthdaytoday.cgi");
    print BDILE "#$nowtime\n";
    print BDILE qq~$birthdayuser\n~;
    print BDILE qq~$borncount\n~;
    close (BDILE);
    unlink($lockfile);
} else {
    (my $sec,my $no) = localtime($currenttime);
    $sec = int($sec/15);
    unlink($lockfile) if ($sec == 2);
    $birthdayuser="";
    $borncount=0;
}
1;
