#!/usr/local/bin/perl # ================================================================== # ==== NPO団体掲示板 # ==== 団体登録プログラム # ==== 作成:MTEC # ================================================================== # ============================================== # ファイル一覧 # ============================================== $program1 = 'admin.cgi'; # 管理者プログラム $program2 = 'touroku.cgi'; # 団体登録プログラム $program3 = 'syokai.cgi'; # 団体紹介プログラム $program4 = 'login.cgi'; # 団体ログインプログラム $program5 = 'calendar.cgi'; # カレンダープログラム $program6 = 'event.cgi'; # イベント詳細表示 $file_hyoshi = 'db/hyoshi.dat'; # 表紙データファイル $file_data = 'db/touroku.dat'; # 登録データファイル $file_syokai = 'db/syokai.dat'; # 団体紹介データファイル $file_pass = 'db/pass.dat'; # パスワードファイル $file_temp = 'db/temp.dat'; # テンポラリファイル $file_num = 'db/num.dat'; # ID番号ファイル $file_tiiki = 'db/t_tiiki.dat'; # 活動地域テーブル $file_katudo = 'db/t_katudo.dat'; # 活動内容テーブル # ############################################## # 以下サブルーチン # ############################################## # ============================================ # 戻るボタン # ============================================ sub go_prev { my ($url, $mode) = ($_[0], $_[1]); if ($mode){ $img = "b_back.gif"; $alt = "もどる"; } else { $img = "b_top.gif"; $alt = "TOP"; } print < $alt EOF } # ============================================ # フッダー表示 # ============================================ sub print_bottom { my $flg = $_[0]; if ($flg){ print < 環境創造活動支援グループ EOF } print < EOF } # ============================================== # ID番号取得 # ============================================== sub get_num { open(FILE, $file_num); @data = ; close(FILE); foreach $line(@data){ chomp $line; $id_no = @data[0]; } if ($id_no eq ""){ $id_no = 1; } } # ============================================ # 日付取得 # ============================================ sub get_date { $ENV{'TZ'} = "JST-9"; @dat = localtime(time); $dat[5] += 1900; $dat[4] = sprintf("%02d",$dat[4]); $dat[3] = sprintf("%02d",$dat[3]); $dat[2] = sprintf("%02d",$dat[2]); $dat[1] = sprintf("%02d",$dat[1]); $dat[0] = sprintf("%.2d",$dat[0]); $dat[6] = ('日','月','火','水','木','金','土') [$dat[6]]; $thismonth = $dat[4] + 1; $thisyear = $dat[5]; $today = $dat[3]; } # ============================================ # カレンダー日計算 # ============================================ sub day { my $disp_month = $_[0]; if(($disp_year % 4) != 0 || ($disp_year % 100) == 0 && ($disp_year % 400) !=0){ $month2 = '28'; } else { $month2 = '29'; } # うるう年 @endday = (31,$month2,31,30,31,30,31,31,30,31,30,31); # 月末 $hairetu_month = $disp_month - 1; my $dayend = $endday[$hairetu_month]; # 更新月末 return $dayend; } # ============================================ # カレンダー曜日計算 # ============================================ sub youbi { my ($disp_year, $disp_month, $disp_day) = @_; if ($disp_month == 1 || $disp_month == 2){ $disp_year--; $disp_month += 12; } $num_youbi = ($disp_year + int($disp_year / 4) - int($disp_year / 100) + int($disp_year / 400) + int(2.6 * $disp_month + 1.6) + $disp_day) % 7; # ====曜日計算はZeller(ツェラー)の公式 return $num_youbi; } # ============================================== # 入力データタグチェック # ============================================== sub syori_tag { $dantaimei = &tag_check($dantaimei); $dantaimei_k = &tag_check($dantaimei_k); $yubin_1 = &tag_check($yubin_1); $yubin_2 = &tag_check($yubin_2); $jyusyo = &tag_check($jyusyo); $daihyomei = &tag_check($daihyomei); $daihyomei_k = &tag_check($daihyomei_k); $tel = &tag_check($tel); $fax = &tag_check($fax); $mail = &tag_check($mail); $kaisi_y = &tag_check($kaisi_y); $kaisi_m = &tag_check($kaisi_m); $kaisi_d = &tag_check($kaisi_d); $aisatsu = &tag_check($aisatsu); $comment = &tag_check($comment); } # ============================================== # 活動地域コード変換処理 # ============================================== sub syori_tiiki { open(FILE, $file_tiiki); @data = ; close(FILE); foreach $line(@data){ chomp $line; my ($dat_code, $dat_tiiki) = split(/\t/, $line); if ($tiiki == $dat_code){ $hyoji_tiiki = $dat_tiiki; last; } } } # ============================================== # 会員数コード変換処理 # ============================================== sub syori_kaiinsu { if ($kaiinsu == 1){ $hyoji_kaiinsu = "1〜5人"; } elsif ($kaiinsu == 2){ $hyoji_kaiinsu = "6〜10人"; } elsif ($kaiinsu == 3){ $hyoji_kaiinsu = "11人以上"; } } # ============================================== # 元号コード変換処理 # ============================================== sub syori_gengou { if ($kaisi_g == 1){ $hyoji_kaisi_g = "昭和"; } elsif ($kaisi_g == 2){ $hyoji_kaisi_g = "平成"; } } # ============================================== # 活動内容コード変換処理 # ============================================== sub syori_katudo { open(FILE, $file_katudo); @data = ; close(FILE); @in_katudo = split('\0', $katudo); foreach $in_katudo(@in_katudo){ foreach $line(@data){ chomp $line; my ($dat_code, $dat_katudo) = split(/\t/, $line); if ($in_katudo == $dat_code){ $hyoji_katudo .= "$dat_katudo "; $out_katudo .= "$dat_code:"; last; } } } chop $out_katudo; } # ============================================== # 通知の可否コード変換処理 # ============================================== sub syori_tuti { if ($tuti == 1){ $hyoji_tuti = "可"; } elsif ($tuti == 0){ $hyoji_tuti = "不可"; } } # ============================================== # 表示用文字処理 # ============================================== sub syori_moji { #全角カナ→半角カナ #jcode::h2z_euc(\$dantaimei); #jcode::h2z_euc(\$dantaimei_k); #jcode::h2z_euc(\$jyusho); #jcode::h2z_euc(\$daihyomei); #jcode::h2z_euc(\$daihyomei_k); #全角ローマ英数字→半角ローマ英数字 #$from = '0-9A-Za-z @.”“’−'; #$to = '0-9A-Za-z @.""\'-'; #jcode::tr(\$yubin_1, $from, $to); #jcode::tr(\$yubin_2, $from, $to); #jcode::tr(\$tel, $from, $to); #jcode::tr(\$fax, $from, $to); #jcode::tr(\$mail, $from, $to); #jcode::tr(\$kaisi_y, $from, $to); #jcode::tr(\$kaisi_m, $from, $to); #jcode::tr(\$kaisi_d, $from, $to); #jcode::tr(\$password, $from, $to); #表示用にデータのない項目には空白スペースを入れる if ($kaisi_d eq ''){ $hyoji_kaisi_d = ' '; } else { $hyoji_kaisi_d = $kaisi_d; } } # ============================================== # '"文字処理(入力時) # ============================================== sub syori_moji_in { my $in_word = $_[0]; #"'記号 $in_word =~ s/"/”/g; $in_word =~ s/'/’/g; #タグをとる $in_word =~ s//>/ig; $in_word =~ s///ig; # 改行コードを\nに統一する $in_word =~ s/\015\012/\n/g; #Windowsから $in_word =~ s/\015/\n/g; #Macから # \nを
に変換 $in_word =~ s/\n/
/g; return $in_word; } # ============================================== # '"文字処理(出力時) # ============================================== sub syori_moji_out { my $in_word = $_[0]; $in_word =~ s/”/"/g; $in_word =~ s/’/'/g; return $in_word; } # ============================================== # 改行コード処理(\n→
) # ============================================== sub syori_kaigyo { my $in_word = $_[0]; # 改行コードを\nに統一する $in_word =~ s/\015\012/\n/g; #Windowsから $in_word =~ s/\015/\n/g; #Macから # \nを
に変換 $in_word =~ s/\n/
/g; return $in_word; } # ============================================== # 改行コード処理(
→\n) # ============================================== sub syori_br { my $in_word = $_[0]; #
を\nに変換 $in_word =~ s/
/\n/g; return $in_word; } # ============================================ # ロック処理 # ============================================ sub my_flock { my %lfh = (dir => './db/lockdir/', basename => 'lockfile',timeout => 60, trytime => 10, @_); $lfh{path} = $lfh{dir} . $lfh{basename}; for (my $i = 0; $i < $lfh{trytime}; $i++, sleep 1) { return \%lfh if (rename($lfh{path}, $lfh{current} = $lfh{path} . "-" . time)); } opendir(LOCKDIR, $lfh{dir}); my @filelist = readdir(LOCKDIR); closedir(LOCKDIR); foreach (@filelist) { if (/^$lfh{basename}(\d+)/) { return \%lfh if (time - $1 > $lfh{timeout} and rename($lfh{dir} . $_, $lfh{current} = $lfh{path} . time)); last; } } undef; } # ============================================ # ロック解除 # ============================================ sub my_funlock { rename($_[0]->{current}, $_[0]->{path}); } # ============================================ # タグの無効化 # ============================================ sub tag_check { $ckdt = $_[0]; $ckdt =~ s//>/ig; $ckdt =~ s///ig; $ckdt =~ s/"/”/g; $ckdt =~ s/'/’/g; return $ckdt; } # ============================================ # 使用可能なタグのみ戻す # ============================================ sub tag_change { local($_) = $_[0]; 1 while s/(.*)(<(sup)>(.*)<\/sup>)/$1$4<\/sup>/i; 1 while s/(.*)(<(sub)>(.*)<\/sub>)/$1$4<\/sub>/i; 1 while s/(.*)(<(i)>(.*)<\/i>)/$1$4<\/i>/i; 1 while s/(.*)(<(b)>(.*)<\/b>)/$1$4<\/b>/i; 1 while s/(.*)(<(u)>(.*)<\/u>)/$1$4<\/u>/i; 1 while s/(.*)(<(br)>)/$1
/i; $_; } # ============================================ # 文字数を数える # ============================================ sub cnt_moji { $chk = $_[0]; $chk =~ s/<[^>]*>//g; #タグを除去する $chk =~ s/\015\012//g; #改行コード除去(Windowsから) $chk =~ s/\015//g; #改行コード除去(Macから) $zen = $chk =~ tr/\xa1-\xfe/\xa1-\xfe/; #全角文字数 $han = $chk =~ tr/\x00-\x7f/\x00-\x7f/; #半角文字数 $num = $zen/2 + $han; return $num; } # ============================================ # GIF画像のサイズ取得(get_size.pl by IKCN(http://azazel.oc.to/ikcn/)を参考) # ============================================ sub get_gif_size { my ($file) = @_; my $buf; my ($x,$y) = undef,undef; open(FILE,"grf_dantai/$file") or &error('un_open',$file); binmode(FILE); read(FILE,$buf,10); close(FILE); ($x,$y) = unpack("x6 vv",$buf); return($x,$y); } # ============================================ # JPG画像のサイズ取得(get_size.pl by IKCN(http://azazel.oc.to/ikcn/)を参考) # ============================================ sub get_jpg_size { my ($file) = @_; my $tmp; my ($marker,$code,$len); my ($x,$y) = undef,undef; open(FILE,"grf_dantai/$file") or &error('un_open',$file); binmode(FILE); read(FILE,$tmp,2); while (1) { my $tmp_marker; $len = 4; read(FILE,$tmp_marker,$len); ($marker,$code,$len) = unpack("a a n",$tmp_marker); if($marker ne "\xFF"){ last; } elsif(ord($code) >= 0xC0 && ord($code) <= 0xC3){ my $buf; $len = 5; read(FILE,$buf,$len); ($y,$x) = unpack("xnn",$buf); last; } else{ my $tmp; read(FILE,$tmp,$len - 2); } } close(FILE); return($x,$y); } # ============================================ # PNG画像のサイズ取得(get_size.pl by IKCN(http://azazel.oc.to/ikcn/)を参考) # ============================================ sub get_png_size { my ($file) = @_; my $tmp; my $buf; my ($x,$y) = undef,undef; open(FILE,"grf_dantai/$file") or &error('un_open',$file); binmode(FILE); read(FILE,$buf,24); ($x,$y) = unpack("x16 NN",$buf); close(FILE); return($x,$y); } # ============================================ # 画像のサイズをきめる # ============================================ sub get_size { $wid = ''; $hei = ''; my ($f_ext) = @_[0]; my ($file) = @_[1]; if ($f_ext eq "gif") {($wid, $hei) = &get_gif_size ($file);} if (($f_ext eq "jpg") || ($f_ext eq "jpeg")) {($wid, $hei) = &get_jpg_size ($file);} if ($f_ext eq "png") {($wid, $hei) = &get_png_size ($file);} if ($hei > $max_height){ $width[$cnt] = ""; $height[$cnt] = " height=$max_height"; } elsif ($wid > $max_width){ $width[$cnt] = " width=$max_width"; $height[$cnt] = ""; } else { $width[$cnt] = " width=$wid"; $height[$cnt] = " height=$hei"; } } # ============================================ # エラールーチン # ============================================ #sub error { # $error = $_[0]; # if ($error eq 'bad_login' ) {$msg = '不正なログインです。';} # if ($error eq 'no_pass' ) {$msg = 'パスワードとIDが違います。';} # if ($error eq 'no_match_id'){$msg = '登録データが見つかりません。';} # if ($error eq 'no_name' ){$msg = '名前を入力して下さい。';} # if ($error eq 'bad_save'){$msg = '混雑していて送信に失敗しました。
時間をおいて再度送信して下さい。';} # if ($error eq 'big_img') {$msg = '画像のファイルサイズを50KB以下にして下さい。';} # if ($error eq 'bad_filetype') {$msg = '画像ファイルは jpg 又は gif しか登録できません。';} # if ($error eq 'logout'){ # print "ログアウトしています。再度ログインしてください。\n"; # die; # } # print "
\n"; # print "

$msg

\n"; # print "エラー\n"; # if ($error ne 'bad_login'){ # print "

もどって もう一度お願いします。

\n"; # } # print "
\n"; # &print_bottom(1); # exit; #} # #1; #return true # ==========================おしまい(^-^)y==========================