#!/usr/local/bin/perl #------------------------------------------------- # [BBS for i-mode] ver.0.00.1 # # Copyright (C) Minoru Miyajima # All rights reserved. # e-mail: maina_u@livedoor.com #------------------------------------------------- # # ver.0.00.1 #------------------------------------------------- require "surface.pl"; &init_form; if(!$form{"list_head"}){$form{"list_head"}=0;} if(!$form{"des_fname"}){$form{"des_fname"}="des.html";} if(!$form{"log_fname"}){$form{"log_fname"}="hist.dat";} if(!$form{"list_max"}){$form{"list_max"}=10;} &lock_open(TXT, $form{"log_fname"}); for($cnt=0;$cnt<$form{"list_head"};$cnt+=1){$tem = ;} for($cnt=0;$cnt<$form{"list_max"};$cnt+=1){$txt[$cnt] = ;} $next=; &unlock_close(TXT); ## 新規投稿 if($form{"mode"} eq "new"){ &dsp_head("NEW"); &dsp_form("mscbs.cgi",0,0,"","","","","",$form{'list_head'},"勘三郎/勘太郎/七之助"); } ##書き込み elsif($form{"mode"} eq "up"){ &dsp_head("BBS NEW"); $form{"text"}=~s/\r//g; $form{"text"}=~s/\n/
/g; $form{"remark"}=~s/\r//g; $form{"remark"}=~s/\n/
/g; &write_msg($form{"log_fname"},$form{'no'},$form{'name'},$form{'year'},$form{'month'},$form{'day'},$form{'text'},$form{'remark'}); print "書き込みが終了しました
"; print "一覧に戻る
"; } ##エディット elsif($form{"mode"} eq "ed"){ &dsp_head("修正"); for($cnt=0;$cnt<$form{"list_max"};$cnt+=1){ @out_txt = split(/,/, $txt[$cnt]); if($out_txt[0] eq $form{"list_no"}){ @out_temp = @out_txt; } } $out_temp[5]=~s/
/\n/g; $out_temp[6]=~s/
/\n/g; &dsp_form("mscbs.cgi",$out_temp[0],$out_temp[1],$out_temp[2],$out_temp[3],$out_temp[4],$out_temp[5],$out_temp[6],$form{'list_head'},"勘三郎/勘太郎/七之助"); } ## 読む elsif($form{"mode"} eq "view"){ &dsp_head("BBS READ"); for($cnt=0;$cnt<$form{"list_max"};$cnt+=1){ @out_txt = split(/,/, $txt[$cnt]); if($out_txt[0] eq $form{"list_no"}){ @out_temp = @out_txt; } } print "$out_temp[0]\:"; if(!$out_temp[4]){print "$out_temp[2]";} else {print "$out_temp[2]";} print "
title $out_temp[10]
"; print "$out_temp[11]

"; print "レスを書く
"; print "一覧に戻る
"; } elsif($form{"mode"} eq "list"){ &dsp_head("BBS LIST"); &dsp_list("mscbs.cgi","勘三郎/勘太郎/七之助"); } # 一覧 else { &dsp_head("BBS LIST"); &dsp_view("mscbs.cgi","勘三郎/勘太郎/七之助"); } &dsp_foot; exit; sub dsp_head{ local($title)=@_; print "Content-type: text/html\n\n"; print "$title"; } sub dsp_foot{ # local($title)=@_; print '
(c)MYPIXEL
'; } sub dsp_list{ local($cgi,$person_list)=@_; @person_list = split(/\//, $person_list); print "[書き込みリスト]
"; print "新規スケジュール
"; if($next){ print "次のページへ
"; } if($form{"list_head"}>0){ print "前のページへ
"; } print "
"; for($cnt=0;$cnt<$form{"list_max"};$cnt+=1){ @out_txt = split(/,/, $txt[$cnt]); if($out_txt[0] ne ""){ print "$out_txt[0]\:$person_list[$out_txt[1]]"; print "
$out_txt[2]年$out_txt[3]月$out_txt[4]日"; print "$out_txt[5]
"; } } if($next){ print "次のページへ
"; } if($form{"list_head"}>0){ print "前のページへ
"; } print "新規スケジュール
"; } sub dsp_form{ local($cgi,$no,$name,$year,$month,$day,$text,$remark,$list_head,$person_list) = @_; local($cnt,$person_max,@person_list); $person_max = split(/\//, $person_list); @person_list = split(/\//, $person_list); print "
"; print ""; print ""; print "俳優:
"; print "年:
"; print "月:
"; print "日:
"; print "内容:

"; print "備考:

"; print "
"; print "
"; print "
"; print "一覧に戻る
"; } sub dsp_view{ local($cgi,$person_list)=@_; local(@fmt,@txt); @person_list = split(/\//, $person_list); if($form{"name"}>=0){$person = 0;$person_prm="&name=$form{'name'}";} else {$person = 1;$person_prm="";} $list_next = "$cgi?mode=$form{'mode'}&des_fname=$form{'des_fname'}&list_head=" . ($form{'list_head'}+$form{'list_max'}) . $person_prm; $list_prev = "$cgi?mode=$form{'mode'}&des_fname=$form{'des_fname'}&list_head=" . ($form{'list_head'}-$form{'list_max'}) . $person_prm; &lock_open(FMT, $form{"des_fname"}); @fmt = ; &unlock_close(FMT); for( $cnt1=0,$_=$fmt[$cnt1];!m//g&&$fmt[$cnt1];$cnt1++,$_=$fmt[$cnt1] ){ $list_head = $list_head . $_; } s///g; for( $cnt2=0;!m//g&&$fmt[$cnt1];$cnt1++,$cnt2++,$_=$fmt[$cnt1] ){ $list_main = $list_main . $_; } s///g; for( $cnt2=0;$fmt[$cnt1] ;$cnt1++,$cnt2++,$_=$fmt[$cnt1] ){ $list_foot = $list_foot . $_; } &lock_open(TXT, $form{"log_fname"}); for( $cnt1=0,$cnt2=0,$tem = ; $cnt2<=$form{"list_max"} && $tem; ){ @out_txt = split(/,/, $tem); if(($out_txt[5] ne "")&&(($form{"name"} eq $out_txt[1])||($person == 1))){ if($cnt1>=$form{"list_head"}){ $txt[$cnt2] = $tem; ++$cnt2; } ++$cnt1; } $tem = ; } &unlock_close(TXT); if($form{'list_head'}<=0){ $list_head =~ s/.*//g; $list_foot =~ s/.*//g; } else{ $list_head =~ s/<:prevlist:>/$list_prev/g; $list_foot =~ s/<:prevlist:>/$list_prev/g; } if(!$txt[$form{"list_max"}]){ $list_head =~ s/.*//g; $list_foot =~ s/.*//g; } else{ $list_head =~ s/<:nextlist:>/$list_next/g; $list_foot =~ s/<:nextlist:>/$list_next/g; } print $list_head; for( $cnt1=0; $cnt1<$form{"list_max"}&&$cnt1<$cnt2; ++$cnt1 ){ @out_txt = split(/,/, $txt[$cnt1]); $list_fmt = $list_main; $list_fmt =~ s/<:no:>/$out_txt[0]/g; $list_fmt =~ s/<:name:>/$person_list[$out_txt[1]]/g; $list_fmt =~ s/<:year:>/$out_txt[2]/g; $list_fmt =~ s/<:month:>/$out_txt[3]/g; $list_fmt =~ s/<:day:>/$out_txt[4]/g; $list_fmt =~ s/<:txt:>/$out_txt[5]/g; $list_fmt =~ s/<:rem:>/$out_txt[6]/g; print $list_fmt; } if($cnt2 == 0){print "

スケジュールはありません


";} print $list_foot; } sub reload{ local($cginame) = @_; print "Location: $cginame\n\n"; } ########################## ##記事を書き込み## #書き込みデータフォーマット #"$no,$id,$usr_name,$usr_pass,$usr_mail,$usr_url,$usr_d1,$usr_d2,$usr_d3,$usr_date,$usr_sub,$usr_msg\n" ########################## sub write_msg { local($txtfile, $no, $name, $year, $month, $day, $msg, $rem)=@_; local($i,$txt_temp); &lock_open(TXT, "+<$txtfile"); local(@txt)=; seek(TXT,0,0); $date = &get_date; chomp($msg); local($old_no, $old_name, $old_year, $old_month, $old_day, $old_msg, $old_rem) = split(/,/, $txt[0]); # 新規書き込み if($no eq "0"){ # 多重書き込み排除 ----------------------------- chomp($old_msg); if ($old_msg eq $msg) { &unlock_close(TXT); &dsp_head("BBS LIST"); &dsp_list("mscbs.cgi"); } } # 再編集 else{ for($cnt=0;$cnt<$maxarticle;$cnt+=1){ @out_txt = split(/,/, $txt[$cnt]); if($out_txt[0] eq $no){ splice(@txt, $cnt,1); } } } $no = $old_no + 1; $line = "$no,$name,$year,$month,$day,$msg,$rem,$date\n"; unshift(@txt, $line); splice(@txt, $maxarticle); print TXT @txt; truncate(TXT, tell(TXT)); &unlock_close(TXT); } # OPEN & LOCK ---------------------------------------------------------------------------------------------- sub lock_open { local(*FILE, $name) = @_; if (!open(FILE, $name)) { print "$nameがオープンできません。"; } eval("flock(FILE, 2)"); seek(FILE, 0, 0); } # UNLOCK & CLOSE ------------------------------------------------------------------------------------------- sub unlock_close { local(*FILE) = @_; eval("flock(FILE, 8)"); close(FILE); } # INIT FORM ------------------------------------------------------------------------------------------- sub init_form{ require "jcode.pl"; $method = $ENV{'REQUEST_METHOD'}; $method =~ tr/A-Z/a-z/; if ($method eq 'post') { read(STDIN, $query, $ENV{'CONTENT_LENGTH'}); } else { $query = $ENV{'QUERY_STRING'}; } @assocarray = split(/&/, $query); foreach $assoc (@assocarray) { ($property, $value) = split(/=/, $assoc); $value =~ tr/+/ /; $value =~ s/%([A-Fa-f0-9][A-Fa-f0-9])/pack("C", hex($1))/eg; &jcode'convert(*value, 'sjis'); $form{$property} = $value; } } sub get_date { local(@week) = ("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"); local($sec, $min, $hour, $day, $mon, $year, $weekday) = localtime(time); $year += 1900; $mon++; if ($hour < 10) { $hour = "0$hour"; } if ($min < 10) { $min = "0$min"; } if ($sec < 10) { $sec = "0$sec"; } $weekstr = $week[$weekday]; return "$year:$mon:$day:$weekstr:$hour:$min"; }