#!/usr/bin/perl

#******************************************************************************
#atlink.cgi - Automatic Link Ver.2.01
#
#Version   	:2.01
#modified  	:2000/05/30
#Copyright 	:The Room
#E-Mail		:kmorita@allnet.ne.jp
#URL		:http://starlight.ci.nu/home/dream/room/index.shtml
#
#これはフリー素材です。
#転載・商用目的の利用の際には、メールをお願いします。
#
#******************************************************************************
#1行目のperlのディレクトリ指定は、サーバによって異なります。
#詳しくは、管理者にお聞きください。
#******************************************************************************
#
#画面設定
#
#タイトル
$title = "九度山町商工会リンク集";
#
#ページ上部に表示する題名
$pagetop ='<img src="../img/link/title-link.gif" width="616" height="194">';
#
#ホームページURL(HOMEのリンクで戻るところ)
$backhome = "../index.htm";
#
#******************************************************************************
#
#リンク設定
#
#カテゴリー名
#	５つ以上のカテゴリーを作りたいときは、
#	$catname[5]="ラーメン屋";
#	このように、[]内の数値を増やしてください。
$catname[0]="九度山町関連";
$catname[1]="商工会関連";
$catname[2]="和歌山県関連";
$catname[3]="その他";
#
#******************************************************************************
#
#画面全体
#
#BODYタグ
$bodytag='<body text="black" bgcolor="white" link="6060ff" vlink="6060ff" alink="0000ff" topmargin="0">';
#
$tdcl1 = "#c0c0ff";	#リンク表示のバナー・題名の背景色
$tdcl2 = "#e0e0ff";	#リンク表示のコメント部の背景色
$bordercolor="#a0a0ff";	#リンク表示の枠の色
#
$bannerfit = 1;		#バナー表示の大きさを固定する場合は1を設定。
@bannersize=(88,31);	#上で1を設定したときの大きさ（縦,横）
#
$hrcolor="#d0d0ff";	#HRタグの色（IEでしか効果はありません）
#
#******************************************************************************
#
#内部設定
#
$datafile="./data.dat";	#データファイル名
#
$adminpass="kudoyama";	#管理用パスワード
#
#******************************************************************************
#
#その他の設定
#
$jcode="./jcode.pl";	#jcode.plの位置
#
#******************************************************************************
#
#スタイルシート設定
#
$style = 1;		#スタイルシートを使用するなら1を。
#
#使用するスタイルシート
#	「$sheet = <<EOD;」の次の行から「EOD」の前の行までスタイルシートを書きます
#
$sheet = <<EOD;	
BODY,TD,TH{font-size: 10pt;}
a:hover { color: #000060 } 
EOD
#
#******************************************************************************
#
#メール設定
#
#登録・変更時にメールを送るなら1を。
$mailsend = 0;
#
$sendmail = '/usr/sbin/sendmail';#sendmailのパス
#
$from = '九度山町商工会 <kudoyama@w-shokokai.or.jp>';#送信者名前
#
$subject[0] = "九度山町商工会リンク集 登録完了のお知らせ";	#登録時のメールの題名
$subject[1] = "九度山町商工会リンク集 変更完了のお知らせ";	#変更時のメールの題名
#
sub mailbody1{
#登録時のメール文章
$buffer .= <<EOD;
 九度山町商工会リンク集 登録完了のお知らせ


あなたのサイトは、以下のデータで登録されました。

カテゴリー	：$catname[$sitecat]
サイト名	：$sitename
サイトURL	：$siteurl
バナーURL	：$sitebanner
コメント	：$sitecomment
メールアドレス	：$siteemail
パスワード	：$sitepass

このメールは保存しておく事をお勧めします。

御利用ありがとうございました。

なお、利用された覚えの無い方は、このメールは削除してください。

------------------------------------------------------------------------------
運営：九度山町商工会
Automatic Link Ver.2.01
------------------------------------------------------------------------------
EOD
}
#******************************************************************************
sub mailbody2{
#変更時のメール文章
$buffer .= <<EOD;
 九度山町商工会リンク集 変更完了のお知らせ


あなたのサイトは、以下のデータで変更されました。

カテゴリー	：$catname[$sitecat]
サイト名	：$sitename
サイトURL	：$siteurl
バナーURL	：$sitebanner
コメント	：$sitecomment
メールアドレス	：$siteemail
パスワード	：$sitepass

このメールは保存しておく事をお勧めします。

御利用ありがとうございました。

なお、利用された覚えの無い方は、このメールは削除してください。

------------------------------------------------------------------------------
運営：九度山町商工会
Automatic Link Ver.2.01
------------------------------------------------------------------------------
EOD
}
#
#******************************************************************************

if ($style == 0){
	$sheet = "";
	}else{
	$sheet = "<style = \"text/css\"><!--$sheet--></style>\n";
	}
#jcode.plの読みこみ
require $jcode;

#データ受け取り
$cl = $ENV{"CONTENT_LENGTH"};
if( $cl > 0 ){
	read(STDIN, $qs, $cl );
}else{
	$qs = $ENV{"QUERY_STRING"};
}

@contents = split(/&/,$qs);
foreach $i (0 .. $#contents) {
	local($key,$text)= split(/=/,$contents[$i]);
	$text =~ s/\+/ /g;
	$text =~ s/%(..)/pack("c",hex($1))/ge;
	$text =~ s/\r\n/\n/g; 
	$text =~ s/\n//g; 
	&jcode'convert(*text,"sjis");

	if ($key ne 'sitedata'){
		$text =~ s/<\s*\b[^>]*>//g;
		}

	$action = $text if $key eq 'action';
	$cat = $text if $key eq 'cat';

	$sitecat = $text if $key eq 'sitecat';
	$sitename = $text if $key eq 'sitename';
	$siteurl = $text if $key eq 'siteurl';
	$sitebanner = $text if $key eq 'sitebanner';
	$sitecomment = $text if $key eq 'sitecomment';
	$siteemail = $text if $key eq 'siteemail';
	$sitepass = $text if $key eq 'sitepass';

	$sitedata = $text if $key eq 'sitedata';
	$sitedata2 = $text if $key eq 'sitedata2';
	$condition = $text if $key eq 'condition';
}

#データチェック
if ($action eq ""){$action = "indicate";}
if ($cat eq ""){$cat = 0;}
if ($sitecat eq ""){$sitecat = 0;}

#actionの値で命令分岐

&hphead;
if ($action eq "indicate"){&indicate;}
elsif ($action eq "regist1"){&regist1;}
elsif ($action eq "regist2"){&regist2;}
elsif ($action eq "change1"){&change1;}
elsif ($action eq "change2"){&change2;}
elsif ($action eq "change3"){&change3;}
elsif ($action eq "delete1"){&delete1;}
elsif ($action eq "delete2"){&delete2;}
elsif ($action eq "delete3"){&delete3;}
elsif ($action eq "search1"){&search1;}
elsif ($action eq "search2"){&search1;&search2;}
&hpfoot;
exit;

#*********************************検索ルーチン*********************************

sub search1{
#
#検索フォーム表示
#
print <<EOD;
<br>
<center>
<form method="post" action="atlink.cgi">
登録されているサイトの検索を行います。<br><br>
<table border=0 bgcolor=$bordercolor cellspacing=0>
<tr><td>
<table border=0 cellpadding=5 cellspacing=0 bgcolor=$tdcl2>
<tr>
<th> 検索文字 </th>
<td> <input type="text" name="sitedata" size=20> </td>
</tr>
<tr>
<th> 条件 </th>
<td> <input type="radio" name="condition" value="0" checked>AND <input type="radio" name="condition" value="1">OR </td>
</tr>
</table>
</td></tr></table>
<input type="submit" value="検索">
<input type="hidden" name="action" value="search2">
</form>
</center>
EOD
}
#******************************************************************************
sub search2{
#
#検索
#
open (IN,"$datafile");
flock(IN,1);
@y1=<IN>;
close (IN);

@terms=split(/ /,$sitedata);

print "<hr color=$hrcolor>\n<center>";

if ($sitedata eq ""){
	print "<br><b>検索文字を入力してください。</b><br><br><br>\n";
	}else{
	$buffer = "";
	$flag = 0;

	#検索開始
	for ($i=$#y1;$i>=0;$i--){
		@y2 = split(/<>/,$y1[$i]);
		$ct = -1;

		#検索文字の照合チェック
		for ($j=0;$j<=$#terms;$j++){
			if ($y1[$i] =~ /$terms[$j]/i){$ct++;}
			}
		if ((($condition == 0) && ($ct == $#terms)) || (($condition == 1) && ($ct >= 0))){
			$flag++;

			if ($y2[3] eq ""){
				$a1 = "<br>$y2[1]<br><br>";
				}else{
				if ($bannerfit == 0){
					$a1 = "<img src=\"$y2[3]\" border=0><br>$y2[1]<br>";
					}else{
					$a1 = "<img src=\"$y2[3]\" width=\"$bannersize[0]\" height=\"$bannersize[1]\" border=0><br>$y2[1]<br>";
					}
				}
			#リンク表示
			$buffer .="<tr><th width=30% bgcolor=$tdcl1 nowrap valign=center>";
			$buffer .="<a href=\"$y2[2]\" target=\"_blank\">$a1</a></th><td bgcolor=$tdcl2><br>&nbsp;$y2[4]<br><br></td></tr>";
			}
		}
	
	#表示
	if ($flag == 0){
		print "<br><b>「$sitedata」は見つかりませんでした。</b><br><br><br>";
		}else{
		print "<br><b>「$sitedata」$flag件のリンクが見つかりました。</b><br><br>";
		print "<table border=0 bgcolor=$bordercolor width=80% cellpadding=0 cellspacing=0><tr><td>";
		print "<table border=0 width=100% cellpadding=5 cellspacing=1>";		print $buffer;
		print "</table></td></tr></table><br><br>";
		}
	}

print "</center>";
}
#******************************************************************************
sub delete1{
#
#削除・認証フォーム表示
#
print <<EOD;
<br>
<center>
<form method="post">
サイトの削除を行います。よろしければ、決定ボタンを押してください。<br><br>

<table border=0 bgcolor=$bordercolor cellspacing=0>
<tr><td>
<table border=0 cellpadding=5 cellspacing=0>
<tr>
<th bgcolor=$tdcl2> サイト名 </th>
<td bgcolor=$tdcl2> <input type="text" name="sitename" size=30> </td>
</tr>
<tr>
<th bgcolor=$tdcl2> パスワード </th>
<td bgcolor=$tdcl2> <input type="password" name="sitepass" size=9 maxlength=8> </td>
</tr>
<tr>
<th bgcolor=$tdcl2 colspan=2><input type="submit" value="決定"></th>
</tr>
</table>
</td></tr></table>
<input type="hidden" name="action" value="delete2">
</form>
<br>
EOD
}
#******************************************************************************
sub delete2{
#
#削除フォームor認証エラー表示
#
$flag = 0;

open (IN,"$datafile");
flock(IN,1);
@y1 = <IN>;
close (IN);

for ($i=0;$i<=$#y1;$i++){
	@y2 = split(/<>/,$y1[$i]);
	if ((($sitename eq $y2[1]) && ($sitepass eq $y2[6])) || (($sitename eq $y2[1]) && ($sitepass eq $adminpass))){
		$flag = 1;
		last;
		}
	}

if ($flag == 0){
#認証エラー
print <<EOD;
<center>
<br><br>
<b>サイト名またはパスワードが違います。<br>
<br><br>
<br>
<form method="post" action="atlink.cgi">
<input type="submit" value="再入力">
<input type="hidden" name="action" value="delete1">
</form>
<br><br>
</center>
EOD
	}else{

$sitecat=$y2[0];
$sitename=$y2[1];
$siteurl=$y2[2];
$sitebanner=$y2[3];
$sitecomment=$y2[4];
$siteemail=$y2[5];
$sitepass=$y2[6];

if ($sitebanner eq ""){
	$b1 = "（無し）";
	}else{
	if ($bannerfit == 0){
		$b1 = "<img src=\"$sitebanner\" border=0>";
		}else{
		$b1 = "<img src=\"$sitebanner\" border=0 width=$bannersize[0] height=$bannersize[1]>";
		}
	}

#削除確認表示
print <<EOD;
<center>
<br>
以下のサイトを削除します。よろしければ削除ボタンを押してください。<br><br>
<table border=0 bgcolor=$bordercolor cellspacing=0>
<tr><td>
<table border=0 cellpadding=5 cellspacing=0 bgcolor=$tdcl2>
<tr>
<th nowrap> カテゴリー </th>
<td nowrap> $catname[$sitecat] </td>
</tr>
<tr>
<th nowrap> サイト名 </th>
<td nowrap> $sitename </td>
</tr>
<tr>
<th nowrap> URL </th>
<td nowrap> $siteurl </td>
</tr>
<tr>
<th nowrap> バナー </th>
<td nowrap> $b1 </td>
</tr>
<tr>
<th nowrap> コメント </th>
<td nowrap> $sitecomment </td>
</tr>
<tr>
<th nowrap> メールアドレス </th>
<td nowrap> $siteemail </td>
</tr>
<tr>
<th nowrap> パスワード </th>
<td nowrap> $sitepass </td>
</tr>
</table>
</td></tr></table>

<table>
<tr><td>
<form method="post" action="atlink.cgi">
<input type="submit" value="削除">
<input type="hidden" name="siteurl" value="$siteurl">
<input type="hidden" name="action" value="delete3">
</form>
</td>
<td>
<form method="post" action="atlink.cgi">
<input type="submit" value="中止">
<input type="hidden" name="action" value="indicate">
</form>
</td>
</tr>
</table>
<br>
</center>
EOD
	}
}
#******************************************************************************
sub delete3{
#
#削除完了表示
#
open (IO,"+<$datafile");
flock(IO,2);
@y1=<IO>;

for ($i=0;$i<=$#y1;$i++){
	@y2=split(/<>/,$y1[$i]);
	if ($y2[2] eq $siteurl){
		splice(@y1,$i,1);
		last;
		}
	}

truncate(IO,0);
seek(IO,0,0);
print IO @y1;
close (IO);

#完了表示
print <<EOD;
<center>
<br>
削除が完了しました。<br>
<br>
御利用ありがとうございました。<br>
<br>
<br>
<a href="atlink.cgi">戻る</a>
<br>
<br>
EOD
}
#******************************************************************************
sub change1{
#
#変更・認証フォーム表示
#
print <<EOD;
<br>
<center>
<form method="post">
サイトの変更を行います。必要事項を入力して、決定ボタンを押してください。<br><br><table border=0 bgcolor=$bordercolor cellspacing=0>
<tr><td>
<table border=0 cellpadding=5 cellspacing=0 bgcolor=$tdcl2>
<tr>
<th nowrap> サイト名 </th>
<td nowrap> <input type="text" name="sitename" size=30> </td>
</tr>
<tr>
<th nowrap> パスワード </th>
<td nowrap> <input type="password" name="sitepass" size=9 maxlength=8> </td>
</tr>
<tr>
<th colspan=2><input type="submit" value="決定"></th>
</tr>
</table>
</td></tr>
</table>
<input type="hidden" name="action" value="change2">
</form>
<br>

EOD
}
#******************************************************************************
sub change2{
#
#変更フォームor認証エラー表示
#
$flag = 0;

open (IN,"$datafile");
flock(IN,1);
@y1 = <IN>;
close (IN);

for ($i=0;$i<=$#y1;$i++){
	@y2 = split(/<>/,$y1[$i]);
	if ((($sitename eq $y2[1]) && ($sitepass eq $y2[6])) || (($sitename eq $y2[1]) && ($sitepass eq $adminpass))){
		$flag = 1;
		last;
		}
	}

if ($flag == 0){
#認証エラー
print <<EOD;
<center>
<br><br>
<b>サイト名またはパスワードが違います。<br>
<br><br>
<br>
<form method="post" action="atlink.cgi">
<input type="submit" value="再入力">
<input type="hidden" name="action" value="change1">
</form>
<br><br>
</center>
EOD
	}else{
$sitecat=$y2[0];
$sitename=$y2[1];
$siteurl=$y2[2];
$sitebanner=$y2[3];
$sitecomment=$y2[4];
$siteemail=$y2[5];
$sitepass=$y2[6];

if ($sitebanner eq ""){$sitebanner="http://";}
#変更フォーム表示
print <<EOD;
<center>
<form method="post" action="atlink.cgi">
以下のフォームに必要事項を入力し、変更ボタンを押してください。<br><br>

<table border=0 bgcolor=$tdcl1 cellspacing=0 cellpadding=1>
<tr><td>
<table border=0 cellspacing=0 cellpadding=5 bgcolor=$tdcl2>
<tr><th nowrap> カテゴリー </th>
<td nowrap> $catname[$sitecat] （変更不可） </td></tr>
<tr>
<th nowrap> サイト名 </th>
<td nowrap> <input type="text" name="sitename" value="$sitename" size=30></td>
</tr>
<tr>
<th nowrap> URL </th>
<td nowrap> <input type="text" name="siteurl" value="$siteurl" size=30></td>
</tr>

<tr>
<th nowrap> バナー <br>（無い場合は無記入）</th>
<td nowrap> <input type="text" name="sitebanner" value="$sitebanner" size=30></td>
</tr>

<tr>
<th nowrap> コメント <br>（簡単な紹介・タグ不可）</th>
<td nowrap> <input type="text" name="sitecomment" value="$sitecomment\" size=30></td>
</tr>

<tr>
<th nowrap> メールアドレス </th>
<td nowrap> <input type="text" name="siteemail" value="$siteemail" size=30></td>
</tr>

<tr>
<th nowrap> パスワード <br>（半角英数字8字以内）</th>
<td nowrap> <input type="text" name="sitepass" value="$sitepass" size=9 maxlength=8></td>
</tr>
<tr><th colspan=2><input type="submit" value="変更"></th></tr>
</table>
</td></tr></table>
<input type="hidden" name="sitecat" value="$sitecat">
<input type="hidden" name="sitedata" value="$sitename">
<input type="hidden" name="sitedata2" value="$siteurl">
<input type="hidden" name="action" value="change3">
</form>
</center>
EOD
	}
}
#******************************************************************************
sub change3{
#
#変更完了or入力エラー表示
#
open (IO,"+<$datafile");
flock(IO,2);
@y1=<IO>;
$emsg = "";

for ($i=0;$i<=$#y1;$i++){
	@y2=split(/<>/,$y1[$i]);
	if (($y2[1] eq $sitedata) && ($y2[2] eq $sitedata2)){
		$bpt = $i;
		}
	elsif ($y2[2] eq $siteurl){
		$emsg = "そのURLは既に登録されています。";
		}
	}

if ($emsg eq ""){
	if ($sitename eq ""){$emsg = "サイト名を入力してください。";}
	elsif (($siteurl eq "") || ($siteurl eq "http://")){$emsg = "URL名を入力してください。";}
	elsif ($sitecomment eq ""){$emsg = "コメントを入力してください。";}
	elsif ($siteemail eq ""){$emsg = "メールアドレスを入力してください。";}
	elsif ($sitepass eq ""){$emsg = "パスワードを設定してください。";}
	elsif ($siteurl !~ /http:\/\//i){$emsg = "URLが不正です。";}
	elsif ($sitepass =~ /[^0-9a-zA-Z]/){$emsg = "パスワードが不正です。";}
	elsif ($siteemail !~ /@/){$emsg = "メールアドレスが不正です";}
	elsif (($sitebanner eq "http://") || ($sitebanner eq "")){$sitebanner ="";}
	elsif ($sitebanner !~ /http:\/\//i){$emsg = "バナーのアドレスが不正です。";}	}
if ($emsg ne ""){
close (IO);
#入力エラー表示
print <<EOD;
<center>
<br><br>
<b>入力内容にエラーがありました。<br>
<br><br>
$emsg<br>
<br>
<form method="post" action="atlink.cgi">
<input type="submit" value="再入力">
<input type="hidden" name="sitename" value="$sitename">
<input type="hidden" name="siteurl" value="$siteurl">
<input type="hidden" name="sitebanner" value="$sitebanner">
<input type="hidden" name="sitecat" value="$sitecat">
<input type="hidden" name="sitecomment" value="$sitecomment">
<input type="hidden" name="siteemail" value="$siteemail">
<input type="hidden" name="sitepass" value="$sitepass">
<input type="hidden" name="action" value="change2">
</form>
<br><br>
</center>
EOD
	}else{

	$a1 = "$sitecat<>$sitename<>$siteurl<>$sitebanner<>$sitecomment<>$siteemail<>$sitepass<>\n";
	splice(@y1,$bpt,1,$a1);
	truncate(IO,0);
	seek(IO,0,0);
	print IO @y1;
	close (IO);

	if ($sitebanner eq ""){
		$b1="（無し）";
		}else{

		if ($bannerfit == 0){
			$b1 = "<img src=\"$sitebanner\" border=0>";
			}else{
			$b1 = "<img src=\"$sitebanner\" border=0 width=$bannersize[0] height=$bannersize[1]>";
			}
		}

if ($mailsend == 1){&mailsending(1);}

#変更完了表示
print <<EOD;
<center>
<br>
以下の内容で変更を行いました。<br><br>
<table border=0 bgcolor=$tdcl1 cellspacing=0 cellpadding=1>
<tr><td>
<table border=0 cellspacing=0 cellpadding=5 bgcolor=$tdcl2>
<tr>
<th width=30% nowrap> カテゴリー </th>
<td nowrap> $catname[$sitecat] </td>
</tr>
<tr>
<th nowrap> サイト名 </th>
<td nowrap> $sitename </td>
</tr>
<tr>
<th nowrap> URL </th>
<td nowrap> $siteurl </td>
</tr>

<tr>
<th nowrap> バナー </th>
<td nowrap> $b1 </td>
</tr>

<tr>
<th nowrap> コメント </th>
<td nowrap> $sitecomment </td>
</tr>

<tr>
<th nowrap> メールアドレス </th>
<td nowrap> $siteemail </td>
</tr>

<tr>
<th nowrap> パスワード </th>
<td nowrap> $sitepass </td>
</tr>
</table>
</td></tr></table>
<br>
<a href="atlink.cgi">戻る</a><br>
<br>
</center>
EOD
	}
}
#******************************************************************************
sub regist1{
#
#登録フォーム表示
#
if ($siteurl eq ""){$siteurl = "http://";}
if ($sitebanner eq ""){$sitebanner = "http://";}

print <<EOD;
<center>
<form method="post" action="atlink.cgi">
以下のフォームに必要事項を入力し、決定ボタンを押してください。<br><br>
<table border=0 bgcolor=$tdcl1 cellspacing=0 cellpadding=1>
<tr><td>
<table border=0 cellspacing=0 cellpadding=5 bgcolor=$tdcl2>
<tr><th> カテゴリー </th>
<td nowrap> <select name="sitecat">
EOD
for ($i=0;$i<=$#catname;$i++){
	if ($sitecat == $i){
		$a1=" selected";
		}else{
		$a1 = "";
		}
	print "<option value=\"$i\"$a1>$catname[$i]</option>\n";
	}
print <<EOD;
</select>
 </td></tr>
<tr>
<th nowrap> サイト名 </th>
<td nowrap> <input type="text" name="sitename" value="$sitename" size=30></td>
</tr>
<tr>
<th nowrap> URL </th>
<td nowrap> <input type="text" name="siteurl" value="$siteurl" size=30></td>
</tr>

<tr>
<th nowrap> バナー <br>（無い場合は無記入）</th>
<td nowrap> <input type="text" name="sitebanner" value="$sitebanner" size=30></td>
</tr>

<tr>
<th nowrap> コメント <br>（簡単な紹介・タグ不可）</th>
<td nowrap> <input type="text" name="sitecomment" value="$sitecomment\" size=30></td>
</tr>

<tr>
<th nowrap> メールアドレス </th>
<td nowrap> <input type="text" name="siteemail" value="$siteemail" size=30></td>
</tr>

<tr>
<th nowrap> パスワード <br>（半角英数字8字以内）</th>
<td nowrap> <input type="text" name="sitepass" value="$sitepass" size=9 maxlength=8></td>
</tr>
<tr><th colspan=2><input type="submit" value="決定"></th></tr>
</table>
</td></tr>
</table>
<input type="hidden" name="action" value="regist2">
</form>
</center>
EOD

}
#******************************************************************************
sub regist2{
#
#登録完了表示orエラー表示
#
open (IO,"+<$datafile");
flock(IO,2);
@y1=<IO>;

$emsg = "";
$bflag = 0;
for ($i=0;$i<=$#y1;$i++){
	@y2=split(/<>/,$y1[$i]);
	if ($y2[2] eq $siteurl){
		$emsg = "そのURLは既に登録されています。";
		last;
		}
	}
if ($emsg eq ""){
	if ($sitename eq ""){$emsg = "サイト名を入力してください。";}
	elsif (($siteurl eq "") || ($siteurl eq "http://")){$emsg = "URL名を入力してください。";}
	elsif ($sitecomment eq ""){$emsg = "コメントを入力してください。";}
	elsif ($siteemail eq ""){$emsg = "メールアドレスを入力してください。";}
	elsif ($sitepass eq ""){$emsg = "パスワードを設定してください。";}
	elsif ($siteurl !~ /^https?:\/\/[\w|\:\@\-]+\.[\w|\:\!\#\%\=\&\-\|\@\~\+\.\?\/]+$/i){$emsg = "URLが不正です。";}
	elsif ($sitepass =~ /[^0-9a-zA-Z]/){$emsg = "パスワードが不正です。";}
	elsif ($siteemail !~ /[\w\.\-\&]+\@[\w\.\-\&]+\.[\w\.\-\&]/){$emsg = "メールアドレスが不正です";}
	elsif (($sitebanner eq "http://") || ($sitebanner eq "")){$sitebanner="";}
	elsif ($sitebanner !~ /^https?:\/\/[\w|\:\@\-]+\.[\w|\:\!\#\%\=\&\-\|\@\~\+\.\?\/]+$/i){$emsg = "バナーのアドレスが不正です。";}	}

if ($emsg ne ""){
#入力エラー表示
close (IO);
print <<EOD;
<center>
<br><br>
<b>入力内容にエラーがありました。<br>
<br><br>
$emsg<br>
<br>
<form method="post" action="atlink.cgi">
<input type="submit" value="再入力">
<input type="hidden" name="sitename" value="$sitename">
<input type="hidden" name="siteurl" value="$siteurl">
<input type="hidden" name="sitebanner" value="$sitebanner">
<input type="hidden" name="sitecat" value="$sitecat">
<input type="hidden" name="sitecomment" value="$sitecomment">
<input type="hidden" name="siteemail" value="$siteemail">
<input type="hidden" name="sitepass" value="$sitepass">
<input type="hidden" name="action" value="regist1">
</form>
</center>
<br><br>
EOD
	}else{
	$a1 = "$sitecat<>$sitename<>$siteurl<>$sitebanner<>$sitecomment<>$siteemail<>$sitepass<>\n";
	truncate(IO,0);
	seek(IO,0,0);
	print IO @y1;
	print IO $a1;
	close (IO);

	if ($sitebanner eq ""){
		$b1="（無し）";
		}else{
		if ($bannerfit == 0){
			$b1 = "<img src=\"$sitebanner\" border=0>";
			}else{
			$b1 = "<img src=\"$sitebanner\" border=0 width=$bannersize[0] height=$bannersize[1]>";
			}
		}

if ($mailsend == 1){&mailsending(0);}
#登録完了表示
print <<EOD;
<center>
<br>
登録が完了しました。<br>
以下の情報は、忘れないようにメモしておいてください。<br><br>
<table border=0 bgcolor=$tdcl1 cellspacing=0 cellpadding=1>
<tr><td>

<table border=0 cellspacing=0 cellpadding=5 bgcolor=$tdcl2>
<tr>
<th nowrap width=30%> カテゴリー </th>
<td nowrap> $catname[$sitecat] </td>
</tr>
<tr>
<th nowrap> サイト名 </th>
<td nowrap> $sitename </td>
</tr>
<tr>
<th nowrap> URL </th>
<td nowrap> $siteurl </td>
</tr>
<tr>
<th nowrap> バナー </th>
<td nowrap> $b1 </td>
</tr>
<tr>
<th nowrap> コメント </th>
<td nowrap> $sitecomment </td>
</tr>
<tr>
<th nowrap> メールアドレス </th>
<td nowrap> $siteemail </td>
</tr>
<tr>
<th nowrap> パスワード </th>
<td nowrap> $sitepass </td>
</tr>
</table>
</td></tr></table>
<br>
<div align=center><a href="atlink.cgi">戻る</a></div><br><br>
</center>
EOD
	}
}
#******************************************************************************
sub indicate{
#
#リンク表示
#

open (IN,"$datafile");
flock(IN,1);
@y1=<IN>;
close (IN);

print "<br>";
&navi2;

$flag = 0;

for ($i=$#y1;$i>=0;$i--){
	@y2 = split(/<>/,$y1[$i]);
	if ($y2[0] == $cat){
		if ($flag == 0 ){
			$flag =1;
			print "<center>\n";

			#テーブルタグ表示
			print "<table border=0 bgcolor=$bordercolor width=80% cellpadding=0 cellspacing=0><tr><td>";
			print "<table border=0 width=100% cellpadding=5 cellspacing=1>";
			print "<tr><th bgcolor=$tdcl1 colspan=2>$catname[$cat]</th></tr>\n";			}
			
		if ($y2[3] eq ""){
			$a1 = "<br>$y2[1]<br><br>";
			}else{
			if ($bannerfit == 0){
				$a1 = "<img src=\"$y2[3]\" border=0><br>$y2[1]<br>";
				}else{
				$a1 = "<img src=\"$y2[3]\" width=\"$bannersize[0]\" height=\"$bannersize[1]\" border=0><br>$y2[1]<br>";
				}
			}

		#リンク表示
		print "<tr><th width=30% bgcolor=$tdcl1 nowrap valign=center>";
		print "<a href=\"$y2[2]\" target=\"_blank\">$a1</a></th><td bgcolor=$tdcl2 width=70%><br>&nbsp;$y2[4]<br><br></td></tr>";

		
		}
	}
if ($flag == 1){
	print "</table></td></tr></table>\n";
	}else{
	#リンクが無い場合
	print "<center><br><br><b>「$catname[$cat]」に登録されているリンクはありません。</b><br><br><br></center>";
	}
print "<br>";
&navi2;
}
#******************************************************************************
sub navi1{
#
#設定用ナビゲーションバー表示
#
print "<center><hr color=\"$hrcolor\">";
print "<a href=\"$backhome\" TARGET=\"_top\"><font style=\"text-decoration:none;\"> </font>HOME</a>　";
if ($action =~ /indicate/){
	print "<b> 表\示</b>　";
	}else{
	print "<a href=\"atlink.cgi?action=indicate\"><font style=\"text-decoration:none;\"> </font>表\示</a>　";
	}

if ($action =~ /regist/){
	print "<b> 登録</b>　";
	}else{
	print "<a href=\"atlink.cgi?action=regist1\"><font style=\"text-decoration:none;\"> </font>登録</a>　";
	}

if ($action =~ /change/){
	print "<b> 変更</b>　";
	}else{
	print "<a href=\"atlink.cgi?action=change1\"><font style=\"text-decoration:none;\"> </font>変更</a>　";
	}

if ($action =~ /delete/){
	print "<b> 削除</b>　";
	}else{
	print "<a href=\"atlink.cgi?action=delete1\"><font style=\"text-decoration:none;\"> </font>削除</a>　";
	}

if ($action =~ /search/){
	print "<b> 検索</b>　";
	}else{
	print "<a href=\"atlink.cgi?action=search1\"><font style=\"text-decoration:none;\"> </font>検索</a>　";
	}
print "</center><hr color=$hrcolor>";
}
#******************************************************************************
sub navi2{
#
#カテゴリー選択用ナビゲーションバー
#
print "<center>\n";
for ($i=0;$i<=$#catname;$i++){
	if ($i == $cat){
		print "<b>▼$catname[$i]</b>　";
		}else{
		print "<a href=\"atlink.cgi?action=indicate&cat=$i\"><font style=\"text-decoration:none;\">▼</font>$catname[$i]</a>　";
		}
	}
print "</center><br>\n";
}
#******************************************************************************
sub mailsending{
#
#メール送信
#
$buffer = "To: $siteemail\n";
$buffer .= "From: $from\n";
$buffer .= "Subject: $subject[$_[0]]\n";
$buffer .= "Content-Transfer-Encoding: 7bit\n";
$buffer .= "Content-Type: text/plain\; charset=\"ISO-2022-JP\"\n\n\n";
if ($_[0] == 0){&mailbody1;}else{&mailbody2;}

&jcode'convert(*buffer,"jis");
open(OUT,"| $sendmail -t");
print OUT $buffer;
close (OUT);
}
#******************************************************************************
sub hphead{
#
#ヘッダ表示
#
print "Content-type: text/html\n\n";
print <<EOD;
<html><head>
<META HTTP-EQUIV="Pragma" CONTENT="no-cache">
<title>$title</title>
</head>
$bodytag
$sheet
$pagetop<br>
EOD
&navi1;
}
#******************************************************************************
sub hpfoot{
#
#フッタ表示
#
print <<EOD;
<hr color=$hrcolor>
<div align="center"><a href="http://starlight.ci.nu/home/dream/room/index.shtml" target="_blank">The Room</a></div>
<hr color=$hrcolor>
</body></html>
EOD
}
#******************************************************************************
