#+------------------------------------------------------+ #|≪BooShu2 ver.1.12≫ | #|Copyright : CGIブー | #|URL : http://boocgi.org/ | #|modified : 2011/02/08 | #+------------------------------------------------------+ #|★注意事項 | #|1.このスクリプトはフリー素材です。 | #|2.このスクリプトを使用したことによって生じる | #| いかなる損害に対して作者は一切の責任を負いません。| #+------------------------------------------------------+ #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ sub init{ #------------------------ $Cgi = 'booshu2.cgi'; $CgiName = 'booshu2'; $AdminCgi = 'admin.cgi'; $AdminCgiName = '出欠CGI'; $MoCgi = 'mo.cgi'; $AttendData = 'attend.txt'; $ActData = 'act.txt'; $PersonData = 'person.txt'; $SetteiData = 'settei.txt'; $ScheduleData = 'sche.txt'; $CsvData = 'booshu2.csv'; $MobileAgent = 'DoCoMo|KDDI|DDIPOKET|UP\.Browser|J-PHONE|Vodafone|SoftBank'; $DocomoAgent = 'DoCoMo'; $PerPage = 3;#PCで1ページに表示する件数 $MoPerPage = 5;#携帯で1ページに表示する件数 # $Copyright = "$CgiName by ブーCGI"; # #曜日 our@Week = ('日','月','火','水','木','金','土'); # open(DA,"<$ActData"); our@Act=; close(DA); # open(DA,"<$PersonData"); our@Person=; close(DA); # open(DA,"<$ScheduleData"); our@Sch=; close(DA); # open(DA,"<$AttendData"); our@Attend=; close(DA); # open(DA,"<$SetteiData"); our@Settei=; close(DA); chomp(@Settei); our$home_url = $Settei[0]; our$this_title = $Settei[1]; our$log_month = $Settei[2]; our$ana_authority = $Settei[3]; our$con_authority = $Settei[4]; our$image_color = $Settei[5]; our$sendmail_path = $Settei[6]; our$to_mail_admin = $Settei[7]; our$mobile_login = $Settei[8]; our$mobile_pass = $Settei[9]; our$mobile_eco = $Settei[10]; our$mobile_com_byte = $Settei[11]; our$admin_mailaddress = $Settei[12]; our$sche_sort = $Settei[13]||1; # our$minus_yea = 3; our$plus_yea = 3; # our@Sche; if($sche_sort == 2){ my$line1 = $Sch[0]; splice @Sch,0,1; @Sche = sort{ (split(/<>/,$b))[1]<=>(split(/<>/,$a))[1] or (split(/<>/,$b))[2]<=>(split(/<>/,$a))[2] or (split(/<>/,$b))[3]<=>(split(/<>/,$a))[3] }@Sch; unshift @Sche,$line1; }else{ @Sche = @Sch; } } #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ sub first{ our$ScheId = $qu->param('sche_id'); #------------------------ #現在の日時を取得 our($now_yea,$now_mon,$now_day) = &now_ymd; # our$yea = $yea || $qu->param('yea') || $now_yea; our$mon = $mon || $qu->param('mon') || $now_mon; #------------------------ our$who = $qu->param('who'); our$who_option = &who_option($who); #------------------------ our$title = $yea.'年'.$mon.'月のスケジュール'; #------------------------ our%Act; our$act_option = "\n"; for(my$m=1;$m<@Act;$m++){ my($act_rank,$act_id,$act) = split(/<>/,$Act[$m]); $Act{$act_id} = $act; $act_option .= "\n"; } #------------------------ our(%AttendAct,%AttendCom,%AttendCou,%AttendAct2); for(my$d=0;$d<@Attend;$d++){ my($sche_id,$person,$act,$ymdhm,$com) = split(/<>/,$Attend[$d]); $AttendAct{"$sche_id-$person"} = $act; $AttendCom{"$sche_id-$person"} = $com; $AttendCou{"$person-$act"}++; $AttendAct2{"$sche_id-$act"}++; } #------------------------ our(%ScheduleId,%ScheduleYea,%ScheduleMon,%ScheduleDay,%ScheduleHou,%ScheduleMin,%ScheduleTitle,%ScheduleDetail); our(%StaTime,%EndTime,%HowPerson,%LimitAct); our(%cap,%go_flag,%aco,$List); our($se,$mi,$ho,$da,$mo,$ye,$we) = localtime(time); our$n_time = sprintf("%04d%02d%02d%02d%02d",$ye+1900,$mo+1,$da,$ho,$mi,$se); our$d_time = sprintf("%04d%02d%02d",$ye+1900,$mo+1,$da); our($yea_op1,$yea_op2); for(my$s=1;$s<@Sche;$s++){ my($sche_id,$ye,$mo,$da,$ho,$mi,$title,$sche,$sta_time,$end_time,$how_person,$limit_act) = split(/<>/,$Sche[$s]); $ScheduleId{"$ye-$mo-$da"} = $sche_id; $ScheduleYea{$sche_id} = $ye; $ScheduleMon{$sche_id} = $mo; $ScheduleDay{$sche_id} = $da; $ScheduleHou{$sche_id} = $ho; $ScheduleMin{$sche_id} = $mi; $ScheduleTitle{$sche_id} = $title; $ScheduleDetail{$sche_id} = $sche; $StaTime{$sche_id} = $sta_time; $EndTime{$sche_id} = $end_time; $HowPerson{$sche_id} = $how_person; foreach my$lim(split(/-/,$limit_act)){ $LimitAct{"$sche_id-$lim"} = 1; } # my%flag; if($sta_time !~/^(0+)$/ && $end_time !~/^(0+)$/){ if($n_time < $sta_time){ $cap{$sche_id} = "出欠開始前"; $flag{1}++; }elsif($n_time > $end_time){ $cap{$sche_id} = "締め切り"; $flag{1}++; }else{ $cap{$sche_id} = "出欠受付中"; } } foreach(split(/-/,$limit_act)){ $aco{$sche_id} += $AttendAct2{"$sche_id-$_"}; } if($how_person && $aco{$sche_id} >= $how_person && $flag{1} < 1){ $flag{2}++; $cap{$sche_id} = "締め切り"; } $cap{$sche_id} = "○出欠受付中" if(!$cap{$sche_id} && sprintf("%04d%02d%02d%02d%02d",$ye,$mo,$da,$ho,$mi) > $n_time); if($flag{1} == 0){ if($flag{2} == 0){ $go_flag{$sche_id}++; }else{ $limit_act =~s/\-/\|/g; if($AttendAct{"$sche_id-$who"} =~/^($limit_act)$/){ $go_flag{$sche_id}++; } } } $yea_op1 = $ye if(!$yea_op1 || $ye < $yea_op1); } $yea_op2 = $now_yea+2; # our$yea_option = &yea_option($yea); our$mon_option = &mon_option($mon); } #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ sub mail_go{ # my$Mode = $qu->param('mode'); my$ScheId = $qu->param('sche_id'); # my%Act; for(my$m=1;$m<@Act;$m++){ my($act_rank,$act_id,$act) = split(/<>/,$Act[$m]); $Act{$act_id} = $act; } $Act{'mi'} = '未回答'; my%MailGoAct; my$act_list; foreach my$act($qu->param('to_mail')){ $act =~s/\r\n|\r|\n//g; $MailGoAct{$act}= 1; $act_list .= "$Act{$act}/"; } $act_list =~s/\/$//g; my%PersonAct; for(my$d=0;$d<@Attend;$d++){ my($sche_id,$person,$act,$ymdhm,$com) = split(/<>/,$Attend[$d]); $PersonAct{"$sche_id-$person"} = $act; } my($mailbcc,%Who,$admin_mail); for(my$p=1;$p<@Person;$p++){ my($person_rank,$person_id,$person,$pass,$mail,$authority) = split(/<>/,$Person[$p]); $Who{$person_id} = $person; $mail_from = $mail if($person_id == $who); $admin_mail = $mail if($authority == 1 && $mail); if($mail){ if($Mode eq 'each_edit'){ #管理者に送信 $mailbcc .= "$mail," if($authority == 1); }elsif($Mode eq 'new' || $Mode eq ''){ #全員に送信 $mailbcc .= "$mail,"; }elsif($MailGoAct{'mi'} == 1){ #未回答者に送信 $mailbcc .= "$mail," if(!$PersonAct{"$ScheId-$person_id"}); }else{ $mailbcc .= "$mail," if($MailGoAct{$PersonAct{"$ScheId-$person_id"}} == 1); } } } $mailbcc =~s/\,$//g; # my$mail_subject = $qu->param('mail_subject'); my$mail_message = $qu->param('mail_message'); $mail_from = $admin_mail if(!$mail_from); $mail_from = $admin_mailaddress if($admin_mailaddress); # if($Mode eq 'new'){ #スケジュール登録からの送信の場合 $Schedule =~s/
/\n/g; $mail_subject .= "$Title"; $mail_message .= "【日時】\n".sprintf("%04d/%02d/%02d(%s) %02d:%02d",$Yea,$Mon,$Day,$Week[&week_judge($Yea,$Mon,$Day)],$Hou,$Min)."\n\n"; $mail_message .= "【$Title】\n"."$Schedule\n\n"; $mail_message .= "【締め切り人数】$HowPerson人\n\n" if($HowPerson); if($ye1&&$mo1&&$da1&&$ho1&&$mi1&&$ye2&&$mo2&&$da2&&$ho2&&$mi2){ $mail_message .= "【出欠期間】\n"; $mail_message .= sprintf("%04d/%02d/%02d(%s) %02d:%02d",$ye1,$mo1,$da1,$Week[&week_judge($ye1,$mo1,$da1)],$ho1,$mi1)."から\n"; $mail_message .= sprintf("%04d/%02d/%02d(%s) %02d:%02d",$ye2,$mo2,$da2,$Week[&week_judge($ye2,$mo2,$da2)],$ho2,$mi2)."まで"; } }elsif($ScheId > 0){ #各スケジュールからの送信の場合 my($Title,$Sche,$Date); for(my$s=1;$s<@Sche;$s++){ my($sche_id,$ye,$mo,$da,$ho,$mi,$title,$sche,$sta_time,$end_time,$how_person,$limit_act) = split(/<>/,$Sche[$s]); if($ScheId == $sche_id){ $sche =~s/
/\n/g; $Title = $title; $Sche = $sche; $Date = sprintf("%04d/%02d/%02d(%s) %02d:%02d",$ye,$mo,$da,$Week[&week_judge($ye,$mo,$da)],$ho,$mi); last; } } if($Mode eq 'each_edit'){ #出欠更新を管理者に送信 my($se,$mi,$ho,$da,$mo,$ye,$we) = localtime(time); $ye += 1900; $mo += 1; $mail_subject = "出欠更新あり"; $mail_message = "出欠の更新を受け付けました。\n"; $mail_message .= "【ユーザ名】$Who{$who}\n"; $mail_message .= "【スケジュール】$Title $Date\n"; if($Act){ $mail_message .= "【出欠状況】".$Act{$Act}."\n"; }else{ $mail_message .= "【出欠状況】".$Act{$PersonAct{"$ScheId-$who"}}."\n"; } $mail_message .= "【更新日時】$ye/$mo/$da($Week[$we]) $ho:$mi:$se\n"; }else{ #スケジュール毎のメール送信 $mail_message .= "\n\n\n"; $mail_message .= "このメッセージは以下のスケジュールで出欠登録が($act_list)の方に送信しています。\n\n"; $mail_message .= "【日時】\n$Date\n\n"; $mail_message .= "【$Title】\n"."$Sche"; } } #------------------------ my$cgi_path = $ENV{'HTTP_HOST'}.$ENV{'SCRIPT_NAME'}; $mail_message .= "\n\n【出欠登録】\n"; if($ENV{'SERVER_PORT'} == 443){ $mail_message .= "https://$cgi_path\n\n"; }else{ $mail_message .= "http://$cgi_path\n\n"; } $mail_message .= "\nby $this_title\n"; #------------------------ if(!$mail_subject){ return(2,"件名が未記入です。"); }elsif(!$mail_message){ return(2,"メッセージが未記入です。"); }elsif($Mode ne 'each_edit' && !$mail_from){ return(2,"送信者メールアドレスが不明です。"); }elsif(!$mailbcc){ return(2,"送信先が不明です。"); }else{ eval "use Encode;"; eval "use Jcode;"; if(eval "\${Encode::VERSION}"){ #Encodeが使える環境 eval "Encode::from_to(\$mail_subject,'shiftjis','MIME-Header-ISO_2022_JP');"; eval "Encode::from_to(\$mail_message,'shiftjis','7bit-jis');"; }elsif(eval "\${Jcode::VERSION}"){ #Jcodeが使える環境 eval "\$mail_subject = Jcode->new(\$mail_subject,'sjis')->mime_encode();"; eval "\$mail_message = Jcode->new(\$mail_message,'sjis')->jis;"; } #メール送信 if(!open(MAIL,"| $sendmail_path -t")){ return(2,"Sendmailにアクセスできません。"); } print MAIL "From: $mail_from\n"; print MAIL "Bcc: $mailbcc\n"; print MAIL "Subject: $mail_subject\n"; print MAIL "MIME-Version: 1.0\n"; print MAIL "Content-Type: text/plain; charset=iso-2022-jp\n"; print MAIL "Content-Transfer-Encoding: 7bit\n\n"; print MAIL "$mail_message\n"; close(MAIL); } return(1); } #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ sub yea_option{ my($yea) = @_; my($yea) = &now_ymd; my$option = "\n"; for(my$y=$yea_op1;$y<=$yea_op2;$y++){ my$sel = ' selected="selected"' if($y == $yea && $yea); $option .= "\n"; } return $option; } #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ sub mon_option{ my($mon) = @_; my$option = "\n"; for(my$m=1;$m<=12;$m++){ my$sel = ' selected="selected"' if($m == $mon && $mon); $option .= "\n"; } return $option; } #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ sub day_option{ my($day) = @_; my$option = "\n"; for(my$d=1;$d<=31;$d++){ my$sel = ' selected="selected"' if($d == $day && $day); $option .= "\n"; } return $option; } #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ sub hou_option{ my($hou) = @_; my$option = "\n"; for(my$h=0;$h<=23;$h++){ my$hh = sprintf("%02d",$h); my$sel = ' selected="selected"' if($hh eq $hou); $option .= "\n"; } return $option; } #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ sub min_option{ my($min) = @_; my@minutes = ('00','15','30','45'); my$option = "\n"; for(my$m=0;$m<@minutes;$m++){ my$sel = ' selected="selected"' if($minutes[$m] eq $min); $option .= "\n"; } return $option; } #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ sub who_option{ my($who_id) = @_; my$option = "\n"; for(my$p=1;$p<@Person;$p++){ my($person_rank,$person_id,$person,$pass,$mail,$authority) = split(/<>/,$Person[$p]); my$sel; if($who_id == $person_id){$sel = ' selected="selected"';} $option .= "\n"; } return $option; } #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ sub without{ my($str) = @_; $str =~s//>/g; return $str; } #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ sub now_ymd{ #現在の日時を取得 my($s,$m,$h,$d,$mo,$ye,$w) = localtime(time); my$now_year = $ye + 1900; my$now_month = $mo + 1; return($now_year,$now_month,$d); } #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ sub week_judge{ my($yea,$mon,$day) = @_; if($mon < 3){ $mon += 12; $yea--; } my$wn = ($yea + int($yea / 4) - int($yea / 100) + int($yea / 400) + int((13 * $mon + 8) / 5) + $day) % 7; return $wn; } #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ sub each_person_pass_get{ our(%EachPerson,%EachPassword,%EachAuthority); for(my$p=1;$p<@Person;$p++){ my($person_rank,$person_id,$person,$pass,$mail,$authority) = split(/<>/,$Person[$p]); $EachPassword{$person_id} = $pass; $EachPerson{$person_id} = $person; $EachAuthority{$person_id} = $authority; } } #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ sub each_login_check{ my$num = 0; if($mission eq 'each_login'){ if(!$each_pass || !$who || crypt($each_pass,$EachPassword{$who}) ne $EachPassword{$who}){ $num = 1; } }else{ if(!$each_pass || !$who || $each_pass ne $EachPassword{$who}){ $num = 1; } } return $num; } #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ sub enkey{ my($val) = @_; my($sec,$min,$hou,$day,$mon,$ye,$we) = localtime(time); my(@token) = ('0'..'9','A'..'Z','a'..'z'); my$salt = $token[(time | $$) % scalar(@token)]; $salt .= $token[($sec+$min*60+$hou*60*60) % scalar(@token)]; return crypt($val,$salt); } #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ sub old_data_sakujo{ my%Del; my($yea,$mon,$day) = &now_ymd; $mon -= $log_month; while($mon <= 0){ $mon+=12; $yea--; } my$keep_ym = sprintf("%04d%02d",$yea,$mon); #------------------------ open(DA,"+<$ScheduleData"); flock(DA,2); my@sche=; truncate(DA,0); seek(DA,0,0); my@new_sche; my$last_id = $sche[0]; $last_id =~s/\r\n|\r|\n//g; for(my$s=1;$s<@sche;$s++){ my($sche_id,$ye,$mo,$da,$ho,$mi,$title,$sche,$sta_time,$end_time,$how_person,$limit_act) = split(/<>/,$sche[$s]); if(sprintf("%04d%02d",$ye,$mo) >= $keep_ym){ push @new_sche,"$sche_id<>$ye<>$mo<>$da<>$ho<>$mi<>$title<>$sche<>$sta_time<>$end_time<>$how_person<>$limit_act<>\n"; }else{ $Del{$sche_id} = 1; } } my@Sches = sort{ (split(/<>/,$a))[1]<=>(split(/<>/,$b))[1] or (split(/<>/,$a))[2]<=>(split(/<>/,$b))[2] or (split(/<>/,$a))[3]<=>(split(/<>/,$b))[3] or (split(/<>/,$a))[4]<=>(split(/<>/,$b))[4] or (split(/<>/,$a))[5]<=>(split(/<>/,$b))[5] }@new_sche; unshift @Sches,"$last_id\n"; print DA @Sches; close(DA); #------------------------ open(DA,"+<$AttendData"); flock(DA,2); my@att=; truncate(DA,0); seek(DA,0,0); my@new_att; for(my$d=0;$d<@att;$d++){ my($sche_id,$person,$act,$ymdhm,$com) = split(/<>/,$att[$d]); if($Del{$sche_id} != 1){ push@new_att,"$sche_id<>$person<>$act<>$ymdhm<>$com<>\n"; } } my@new_atts = sort(@new_att); print DA @new_atts; close(DA); } #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1;