#!/usr/bin/perl

#******************************************************************************
#atlink.cgi - Automatic Link Ver.2.03
#
#Version   	:2.03
#modified  	:2001/02/25
#Copyright 	:The Room
#E-Mail		:dream@lib.net
#URL		:http://dream.lib.net/room/
#
#これはフリー素材です。
#転載・商用目的の利用の際には、メールをお願いします。
#
#******************************************************************************
#1行目のperlのディレクトリ指定は、サーバによって異なります。
#詳しくは、管理者にお聞きください。
#******************************************************************************

#jcode.pl のパス
$jcode = './jcode.pl';

#データ保存ファイルのパス
$datafile = 'data.dat';

#管理用パスワード
$adminpass = 'mk6256';

#ホームページURL
$homeurl = 'http://www.kassai.co.jp/limeheart/index.html';

#******************************************************************************

#登録を管理人しかできないようにする場合は 1 を設定。
# サイト登録時には上で設定した管理用パスワードを設定してください。
$adminonly = 1;

#上で 1 を設定した場合に表示するコメント
$adminmsg = '管理人しか実行できません。';

#******************************************************************************

#カテゴリー表示方法
# 0-羅列 / 1-セレクトボックス
$catinditype = 0;

#バナーの登録・表示を行うなら 1 を設定。
$banner = 1;

#コメントの入力を必須にするなら 1 を設定。
$commentent = 0;

#メールアドレスの入力を必須にするなら 1 を設定。
$mailent = 0;

#上で 1 を設定した場合のバナー表示サイズ（縦,横)
# (0,0)の設定をすると、サイズは固定されません。
@bannersize = (88,31);

#1ページに表示するサイト数
$pagein = 30;

#コメント文字数制限（半角）
$commentlimit = 300;

#******************************************************************************

#タイトル
$title = 'ライムハート特選リンク';

#ページ上部に表示するタイトル
$pagetop = '<table border=0 bgcolor=#CCFFCC width=700><tr><td><div align=left><font color=#6060ff size=3><a href=../../index.html target=_top>ホーム</a>>リンク</font></div></td></tr></table>';

#BODYタグ
$bodytag = '<body text=#000000 bgcolor=#ffffff link=#6060ff vlink=#6060ff alink=#0000ff>';

#スタイルシート設定
# 必要の無い方は削除してください。
$stylesheet = <<EOD;
<style type="text/css">
<!--
BODY,TR,TD,TH{
	font-size: 10pt;
	}
HR{
	color:#d0d0ff;
	}
a:hover{
	color: #000060;
	} 
.input {
	border-color:#a0a0ff;
	border-style:solid solid solid solid;
	background-color: #f0f0ff;
	}
.button{
	border-color:#a0a0ff;
	border-style:solid solid solid solid;
	background-color: #f0f0ff;
	}
.select {
	border-color:#a0a0ff;
	border-style:solid solid solid solid;
	background-color: #f0f0ff;
	}
-->
</style>
EOD

#リンク表示のバナー・題名の背景色
$linkcolor1 = '#ffffff';

#リンク表示のコメント部の背景色
$linkcolor2 = '#ffffff';

#リンク表示の枠の色
$linkcolor3 ='#ffffff';

#タイトル・バナーを表示する、テーブル横幅の割合
# 100までの数値で指定してください。
$tablecols = 30;

#リンクのターゲット
$linktarget = '_blank';

#******************************************************************************

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]);
	$esearchkey = $text if $key eq 'searchkey';
	$text =~ s/\+/ /g;
	$text =~ s/%(..)/pack("c",hex($1))/ge;
	$text =~ s/\r\n/\n/g; 
	$text =~ s/\n//g; 
	&jcode'convert(*text,'sjis');
	$text =~ s/</&lt;/g;
	$text =~ s/>/&gt;/g;
	$act = $text if $key eq 'act';
	$cat = $text if $key eq 'cat';
	$page = $text if $key eq 'page';

	$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';
	$sitemail = $text if $key eq 'sitemail';
	$sitepass = $text if $key eq 'sitepass';

	$burl = $text if $key eq 'burl';
	$bpass = $text if $key eq 'bpass';

	$searchkey = $text if $key eq 'searchkey';
	$cond = $text if $key eq 'cond';

	$act2 = $text if $key eq 'act2';
	$newcat = $text if $key eq 'newcat';
	$chgcat = $text if $key eq 'chgcat';
	push(@selcatd,$text) if $key eq 'selcat';
}

$cat ||= 0;
$page ||= 0;
if ($act eq "srh1"){&srh1;}
elsif ($act eq "reg1"){&reg1;}
elsif ($act eq "reg2"){&reg2;}
elsif ($act eq "chg1"){&chg1("変更");}
elsif ($act eq "chg2"){&chg2;}
elsif ($act eq "chg3"){&chg3;}
elsif ($act eq "del1"){&chg1("削除");}
elsif ($act eq "del2"){&del2;}
elsif ($act eq "del3"){&del3;}
elsif ($act eq "adm1"){&adm1;}
elsif ($act eq "adm2"){&adm2;}

&indicate;
#*****************************************************************************
sub adm2{
#管理
my ($a1,$a2,@temp1,@temp2,@temp3);

if ($sitepass ne $adminpass){&error("パスワードが間違っています。");}
if (($act2 eq "カテゴリーを作成") && ($newcat eq "")){
	&error("新しいカテゴリー名を入力してください。");
	}
elsif ($act2 eq "チェックしたカテゴリーを変更"){
	&error("変更後のカテゴリー名を入力してください。") if $chgcat eq "";
	&error("変更するカテゴリーを選択してください。") if $selcatd[0] eq "";
	&error("カテゴリーは１つしか選択できません。") if $selcatd[1];
	}
elsif ($act2 eq "チェックしたカテゴリーを削除"){
	&error("削除するカテゴリーを選択してください。") if $selcatd[0] eq "";
	}

if ($act2 eq ""){
	open(IN,$datafile);
	eval{flock(IN,1)};
	$a1=<IN>;
	close(IN);
	chop($a1);@temp1=split(/<>/,$a1);
	}else{
	open(IO,"+<$datafile");
	eval{flock(IO,2)};
	$a1=<IO>;chomp($a1);
	@temp1=split(/<>/,$a1);$a1="";
	if ($act2 eq "カテゴリーを作成"){
		push(@temp1,$newcat);
		@log=<IO>;
		foreach(@temp1){$a1.=$_."<>";}
		$msg = "カテゴリーを作成しました。";
		}
	elsif ($act2 eq "チェックしたカテゴリーを変更"){
		$temp1[$selcatd[0]]=$chgcat;
		@log=<IO>;
		foreach(@temp1){$a1.=$_."<>";}
		$msg = "カテゴリーを変更しました。";
		}else{
		$a2=0;
		foreach(@selcatd){$temp2[$_]=1;}
		for(0 .. $#temp1){
			if ($temp2[$_] == 0){
				$a1.="$temp1[$_]<>";
				$temp3[$_]=$a2;
				$a2++;
				}
			}
		while(<IO>){
			@temp2=split(/<>/,$_);
			if ($temp3[$temp2[0]] ne ""){
				push(@log,$temp3[$temp2[0]]."<>$temp2[1]<>$temp2[2]<>$temp2[3]<>$temp2[4]<>$temp2[5]<>$temp2[6]<>\n");
				}
			}
		@temp1=split(/<>/,$a1);
		$msg = "カテゴリーを削除しました。";
		}
	truncate(IO,0);
	seek(IO,0,0);
	print IO $a1."\n";
	print IO @log;
	close(IO);
	}
$msg="<font color=red><b>$msg</b></font><br><Br>" if $msg;
&hphead;

print <<EOD;
<div align=center>
$msg
<form method="post" action="./atlink.cgi">
<input type="hidden" name="sitepass" value="$sitepass">
<input type="hidden" name="act" value="adm2">
<table border=0 bgcolor=$linkcolor3 cellspacing=0 cellpadding=1>
<tr><td>
<table border=0 cellspacing=0 cellpadding=5 bgcolor=$linkcolor2>
<tr><td>
<div align=center>現在のカテゴリー</div><br>
EOD
for(0 .. $#temp1){
	print "<input type=\"checkbox\" name=\"selcat\" value=\"$_\">$temp1[$_]<br>";
	}
print <<EOD;
</td></tr></table>
</td></tr></table>
<br>
<table border=0 bgcolor=$linkcolor3 cellspacing=0 cellpadding=1 width=50%>
<tr><td>
<table border=0 cellspacing=0 cellpadding=5 bgcolor=$linkcolor2 width=100%>
<tr><td>
<div align=center>
<input type="submit" name="act2" value="チェックしたカテゴリーを削除">
</div>
<br>
＊複数のカテゴリーを同時に削除できます。<br>
＊削除したカテゴリーに属していたリンクも全て削除されます。<br>
</td></tr></table>
</td></tr></table>
<br>
<table border=0 bgcolor=$linkcolor3 cellspacing=0 cellpadding=1 width=50%>
<tr><td>
<table border=0 cellspacing=0 cellpadding=5 bgcolor=$linkcolor2 width=100%>
<tr><td>
<div align=center>
<input type="submit" name="act2" value="チェックしたカテゴリーを変更">
</div><br>
カテゴリー名 <input type="text" name="chgcat" size=30><br>
<br>
＊選択した１つのカテゴリーの名前を変更します。<br>
</td></tr></table>
</td></tr></table>
<br>
<table border=0 bgcolor=$linkcolor3 cellspacing=0 cellpadding=1 width=50%>
<tr><td>
<table border=0 cellspacing=0 cellpadding=5 bgcolor=$linkcolor2 width=100%>
<tr><td>
<div align=center>
<input type="submit" name="act2" value="カテゴリーを作成">
</div><br>
新しいカテゴリー名 <input type="text" name="newcat" size=30><br>
<br>
＊新たにカテゴリーを作成します。<br>
</td></tr></table>
</td></tr></table>

</form>
</div>
EOD
&hpfoot;
}
#*****************************************************************************
sub adm1{
#管理
&hphead;
print <<EOD;
<div align=center>
<form method="get" action="./atlink.cgi">
<input type="hidden" name="act" value="adm2">
パスワードを入力してください。<br>
<br>
<table border=0 bgcolor=#a0a0ff cellspacing=0>
<tr><td>
<table border=0 cellpadding=5 cellspacing=0 bgcolor=#e0e0ff>
<tr>
<th>パスワード</th>
<td><input type="password" name="sitepass" value="" size=8 maxlength=8 class="input"></td>
</tr>
<tr><td colspan=2 align=center>
<input type="submit" value="認証" class="button">
</td></tr>
</table>
</td></tr></table>
</form>
</div>
EOD
&hpfoot;
}
#*****************************************************************************
sub del3{
#削除
my (@temp1,@log);
&error("パスワードが間違っています。") if ($adminonly) && ($sitepass ne $adminpass);

open(IO,"+<$datafile");
eval{flock(IO,2)};
while(<IO>){
	@temp1 = split(/<>/,$_);
	unless (($temp1[2] eq $siteurl) && (($temp1[6] eq $sitepass) || ($adminpass eq $sitepass))){
		push(@log,$_);
		}
	}
truncate(IO,0);
seek(IO,0,0);
print IO @log;
close(IO);

&hphead;
print <<EOD;
<div align=center>
<br>
削除が完了しました。<br>
<br>
ご利用ありがとうございました。<br>
<br>
<br>
<a href="./atlink.cgi">戻る</a><br>
<br>
</div>
EOD
&hpfoot;
}
#*****************************************************************************
sub del2{
#削除
my (@temp1,@temp2);

$siteurl =~ s/ //g;
&error("登録したサイトURLを入力してください。") if !$siteurl;
&error("パスワードを入力してください。") if !$sitepass;
&error("パスワードが間違っています。") if ($adminonly) && ($sitepass ne $adminpass);

open(IN,$datafile);
eval{flock(IN,1)};
my $a1=<IN>;
while(<IN>){
	@temp1=split(/<>/,$_);
	if (($temp1[2] eq $siteurl) && (($temp1[6] eq $sitepass) || ($adminpass eq $sitepass))){
		@temp2 = @temp1;
		last;
		}
	}
close(IN);
&error("サイトURLかパスワードが間違っています。") if !$temp2[1];
@temp1=split(/<>/,$a1);

&hphead;
print "<div align=center><br>";
print <<EOD;
<form method="post" action="./atlink.cgi">
以下のサイトを削除します。よろしければ削除ボタンを押してください。<br><br>
<table border=0 bgcolor=$linkcolor3 cellspacing=0 cellpadding=1>
<tr><td>
<table border=0 cellspacing=0 cellpadding=5 bgcolor=$linkcolor2>
<tr><th>カテゴリー</th>
<td nowrap>$temp1[$temp2[0]]</td>
</tr>
<tr>
<th nowrap>サイト名</th>
<td nowrap>$temp2[1]</td>
</tr>
<tr>
<th nowrap>URL</th>
<td nowrap>$temp2[2]</td>
</tr>
<tr><th colspan=2><input type="submit" value="削除" class="button"></th></tr>
</table>
</td></tr>
</table>
<input type="hidden" name="act" value="del3">
<input type="hidden" name="siteurl" value="$siteurl">
<input type="hidden" name="sitepass" value="$sitepass">
</form>
</div>
<br>
EOD
&hpfoot;
}
#*****************************************************************************
sub chg3{
#変更
&error("パスワードが間違っています。") if ($adminonly) && ($bpass ne $adminpass);
&datacheck;

my (@temp1,@log);

open(IO,"+<$datafile");
eval{flock(IO,2)};
while(<IO>){
	@temp1 = split(/<>/,$_);
	unless (($temp1[2] eq $burl) && (($temp1[6] eq $bpass) || ($adminpass eq $bpass))){
		push(@log,$_);
		}
	}
splice(@log,1,0,"$sitecat<>$sitename<>$siteurl<>$sitebanner<>$sitecomment<>$sitemail<>$sitepass<>\n");
truncate(IO,0);
seek(IO,0,0);
print IO @log;
close(IO);

@temp1 = split(/<>/,$log[0]);
&hphead;
print <<EOD;
<div align=center>
<br>
変更が完了しました。<br>
<br>
<table border=0 bgcolor=$linkcolor1 cellspacing=0 cellpadding=1>
<tr><td>
<table border=0 cellspacing=0 cellpadding=5 bgcolor=$linkcolor2>
<tr>
<th nowrap width=30%>カテゴリー </th>
<td nowrap>$temp1[$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>$sitebanner</td>
</tr>
<tr>
<th nowrap>コメント</th>
<td nowrap>$sitecomment</td>
</tr>
<tr>
<th nowrap>メールアドレス</th>
<td nowrap>$sitemail</td>
</tr>
<tr>
<th nowrap>パスワード</th>
<td nowrap>$sitepass</td>
</tr>
</table>
</td></tr></table>
<br>
<a href="./atlink.cgi">戻る</a><br>
<br>
</div>
EOD
&hpfoot;
}
#*****************************************************************************
sub chg2{
#変更
my (@temp1,@temp2);

$siteurl =~ s/ //g;
&error("登録したサイトURLを入力してください。") if !$siteurl;
&error("パスワードを入力してください。") if !$sitepass;
&error("パスワードが間違っています。") if ($adminonly) && ($sitepass ne $adminpass);

open(IN,$datafile);
eval{flock(IN,1)};
my $a1=<IN>;
while(<IN>){
	@temp1=split(/<>/,$_);
	if (($temp1[2] eq $siteurl) && (($temp1[6] eq $sitepass) || ($adminpass eq $sitepass))){
		@temp2 = @temp1;
		last;
		}
	}
close(IN);
&error("サイトURLかパスワードが間違っています。") if !$temp2[1];
@temp1=split(/<>/,$a1);

&hphead;
print "<div align=center><br>";
print <<EOD;
<form method="post" action="./atlink.cgi">
以下のフォームに必要事項を入力し、変更ボタンを押してください。<br><br>
<table border=0 bgcolor=$linkcolor3 cellspacing=0 cellpadding=1>
<tr><td>
<table border=0 cellspacing=0 cellpadding=5 bgcolor=$linkcolor2>
<tr><th>カテゴリー</th>
<td nowrap><select name="sitecat" class="input">
EOD
for(0 .. $#temp1-1){
	if ($_ == $temp2[0]){$a2 = " selected";}else{$a2="";}
	print "<option value=\"$_\"$a2>$temp1[$_]\n";
	}
print <<EOD;
</select>
</td></tr>
<tr>
<th nowrap>サイト名</th>
<td nowrap><input type="text" name="sitename" size=30 class="input" value="$temp2[1]"></td>
</tr>
<tr>
<th nowrap>URL</th>
<td nowrap><input type="text" name="siteurl" size=30 class="input" value="$temp2[2]"></td>
</tr>
EOD
if ($banner){
print <<EOD;
<tr>
<th nowrap>バナー<br>（無い場合は無記入）</th>
<td nowrap><input type="text" name="sitebanner" size=30 class="input" value="$temp2[3]"></td>
</tr>
EOD
}
print <<EOD;
<tr>
<th nowrap>コメント<br>（半角$commentlimit字以内）</th>
<td nowrap><input type="text" name="sitecomment" size=30 class="input" value="$temp2[4]"></td>
</tr>

<tr>
<th nowrap>メールアドレス</th>
<td nowrap><input type="text" name="sitemail" size=30 class="input" value="$temp2[5]"></td>
</tr>

<tr>
<th nowrap>パスワード<br>（半角英数字8字以内）</th>
<td nowrap><input type="text" name="sitepass" size=9 maxlength=8 class="input" value="$temp2[6]"></td>
</tr>
<tr><th colspan=2><input type="submit" value="変更" class="button"></th></tr>
</table>
</td></tr>
</table>
<input type="hidden" name="act" value="chg3">
<input type="hidden" name="burl" value="$siteurl">
<input type="hidden" name="bpass" value="$sitepass">
</form>
</div>
<br>
EOD
&hpfoot;

}
#*****************************************************************************
sub chg1{
#変更
$act=substr($act,0,3)."2";

&hphead;
print "<div align=center><br>";
print "<b>".$adminmsg."</b><br><br>" if $adminonly;
print <<EOD;
<form method="get" action="./atlink.cgi">
<input type="hidden" name="act" value="$act">
登録されているサイトの$_[0]を行います。<br><br>
<table border=0 bgcolor=#a0a0ff cellspacing=0>
<tr><td>
<table border=0 cellpadding=5 cellspacing=0 bgcolor=#e0e0ff>
<tr>
<th>登録したURL</th>
<td><input type="text" name="siteurl" size=30 class="input" value=""></td>
</tr>
<tr>
<th>パスワード</th>
<td><input type="password" name="sitepass" value="" size=8 maxlength=8 class="input"></td>
</tr>
<tr><td colspan=2 align=center>
<input type="submit" value="認証" class="button">
</td></tr>
</table>
</td></tr></table>
</form>
</div>
EOD
&hpfoot;
}
#*****************************************************************************
sub reg2{
#登録
&error("パスワードが間違っています。") if ($adminonly) && ($sitepass ne $adminpass);
&datacheck;
my (@log,@temp1);
open(IO,"+<$datafile");
eval{flock(IO,2)};
while(<IO>){
	@temp1=split(/<>/,$_);
	if ($temp1[2] eq $siteurl){
		close(IO);
		&error("このURLは既に登録されています。");
		}
	push(@log,$_);
	}
splice(@log,1,0,"$sitecat<>$sitename<>$siteurl<>$sitebanner<>$sitecomment<>$sitemail<>$sitepass<>\n");
truncate(IO,0);
seek(IO,0,0);
print IO @log;
close(IO);

@temp1 = split(/<>/,$log[0]);
&hphead;
print <<EOD;
<div align=center>
<br>
登録が完了しました。<br>
以下の情報は、忘れないようにメモしておいてください。<br><br>
<table border=0 bgcolor=$linkcolor1 cellspacing=0 cellpadding=1>
<tr><td>
<table border=0 cellspacing=0 cellpadding=5 bgcolor=$linkcolor2>
<tr>
<th nowrap width=30%>カテゴリー </th>
<td nowrap>$temp1[$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>$sitebanner</td>
</tr>
<tr>
<th nowrap>コメント</th>
<td nowrap>$sitecomment</td>
</tr>
<tr>
<th nowrap>メールアドレス</th>
<td nowrap>$sitemail</td>
</tr>
<tr>
<th nowrap>パスワード</th>
<td nowrap>$sitepass</td>
</tr>
</table>
</td></tr></table>
<br>
<a href="./atlink.cgi">戻る</a><br>
<br>
</div>
EOD
&hpfoot;
}
#*****************************************************************************
sub reg1{
#登録

&hphead;
print "<div align=center><br>";
print "<b>".$adminmsg."</b><br><br>" if $adminonly;
print <<EOD;
<form method="post" action="./atlink.cgi">
以下のフォームに必要事項を入力し、決定ボタンを押してください。<br><br>
<table border=0 bgcolor=$linkcolor3 cellspacing=0 cellpadding=1>
<tr><td>
<table border=0 cellspacing=0 cellpadding=5 bgcolor=$linkcolor2>
<tr><th>カテゴリー</th>
<td nowrap><select name="sitecat" class="input">
EOD
open(IN,$datafile);
eval{flock(IN,1)};
my @temp1=split(/<>/,<IN>);
close(IN);
my $a2 = " selected";
for(0 .. $#temp1-1){
	print "<option value=\"$_\"$a2>$temp1[$_]\n";
	$a2 = "";
	}
print <<EOD;
</select>
</td></tr>
<tr>
<th nowrap>サイト名</th>
<td nowrap><input type="text" name="sitename" size=30 class="input"></td>
</tr>
<tr>
<th nowrap>URL</th>
<td nowrap><input type="text" name="siteurl" size=30 class="input"></td>
</tr>
EOD
if ($banner){
print <<EOD;
<tr>
<th nowrap>バナー<br>（無い場合は無記入）</th>
<td nowrap><input type="text" name="sitebanner" size=30 class="input"></td>
</tr>
EOD
}
print <<EOD;
<tr>
<th nowrap>コメント<br>（半角$commentlimit字以内）</th>
<td nowrap><input type="text" name="sitecomment" size=30 class="input"></td>
</tr>

<tr>
<th nowrap>メールアドレス</th>
<td nowrap><input type="text" name="sitemail" size=30 class="input"></td>
</tr>

<tr>
<th nowrap>パスワード<br>（半角英数字8字以内）</th>
<td nowrap><input type="text" name="sitepass" size=9 maxlength=8 class="input"></td>
</tr>
<tr><th colspan=2><input type="submit" value="決定" class="button"></th></tr>
</table>
</td></tr>
</table>
<input type="hidden" name="act" value="reg2">
</form>
</div>
<br>
EOD
&hpfoot;
}
#******************************************************************************
sub srh1{
#検索

&hphead;
print <<EOD;
<div align=center>
<form method="get" action="./atlink.cgi">
<input type="hidden" name="act" value="srh2">
登録されているサイトの検索を行います。<br><br>
<table border=0 bgcolor=#a0a0ff cellspacing=0>
<tr><td>
<table border=0 cellpadding=5 cellspacing=0 bgcolor=#e0e0ff>
<tr>
<th>検索文字</th>
<td><input type="text" name="searchkey" size=20 class="input" value=""></td>
</tr>
<tr>
<th>条件</th>
<td><input type="radio" name="cond" value="0" checked>AND <input type="radio" name="condition" value="1">OR</td>
</tr>
<tr><td colspan=2 align=center>
<input type="submit" value="検索" class="button">
</td></tr>
</table>
</td></tr></table>
</form>
</div>
EOD
&hpfoot;

}
#******************************************************************************
sub indicate{
#リンク表示

my (@log,@temp1,$flag,$msg,$ct,$navibuf);
open(IN,$datafile);
eval{flock(IN,1)};
$a1=<IN>;chomp($a1);
@catdata = split(/<>/,$a1);
if ($act eq "srh2"){
	$searchkey =~ s/　/ /g;
	@temp1 = split(/ /,lc($searchkey));
	while(<IN>){
		$flag = 0;
		foreach $i(@temp1){
			if (index($_,$i) != -1){
				$flag = 1;
				last if $cond;
				}
			elsif ($cond == 0){
				$flag = 0;
				last;
				}
			}
		push(@log,$_) if $flag;
		}
	}else{
	while(<IN>){push(@log,$_) if $_ =~ /^$cat</;}
	}
close(IN);
$ct = $#log+1;
$navibuf = &navi2;

&hphead;
if ($act eq "srh2"){
	$cat = 99;
	$catdata[99]="「$searchkey」で検索";
	}

if (($page != 0) || ($log[($page+1)*$pagein] ne "")){
	$msg = "<div align=center>";
	if ($act eq "srh2"){
		$msg .= "<a href=\"./atlink.cgi?act=srh2&searchkey=$esearchkey&cond=$cond&page=".($page-1)."\">&lt;&lt;前のページ</a> " if $page != 0;
		$msg .= "<a href=\"./atlink.cgi?act=srh2&searchkey=$esearchkey&cond=$cond&page=".($page+1)."\">次のページ&gt;&gt;</a> " if $log[($page+1)*$pagein] ne "";
		}else{
		$msg .= "<a href=\"./atlink.cgi?cat=$cat&page=".($page-1)."\">&lt;&lt;前のページ</a> " if $page != 0;
		$msg .= "<a href=\"./atlink.cgi?cat=$cat&page=".($page+1)."\">次のページ&gt;&gt;</a> " if $log[($page+1)*$pagein] ne "";
		}
	$msg.="</div>";
	}
$a1 = ($page+1)*$pagein;

print <<EOD;
<table boader=0 align=left bgcolor=ccffcc width=700><tr><td><div align=center>$navibuf</div></td></tr></table><br clear=all>
EOD

print $msg."<br>" if $msg;
print <<EOD;
<table border=0 bgcolor=$linkcolor3 width=80% cellpadding=0 cellspacing=0 align=left>
<tr><td>
<table border=1 cellpadding=2 cellspacing=0 width=700 bordercolor="#66CCCC">
<tr><th bgcolor=$linkcolor1 colspan=3 width=700>$catdata[$cat] - $ct件</th></tr>
EOD

for($page*$pagein .. ($page+1)*$pagein-1){
	last if $log[$_] eq "";
	@temp1 = split(/<>/,$log[$_]);
	if (($banner) && ($temp1[3])){
		if ($bannersize[0]){
			$bnr = "<img src=\"$temp1[3]\" width=$bannersize[0] height=$bannersize[1] border=0><br>";
			}else{
			$bnr = "<img src=\"$temp1[3]\" border=0><br>";
			}
		}else{
		$bnr="";
		}
	print "<tr><td  width=130>\n<a href=\"$temp1[2]\" target=\"$linktarget\">$bnr</a></td><td width=130><a href=\"$temp1[2]\" target=\"$linktarget\">$temp1[1]</a>";
	print "</td><td width=400>$temp1[4]</td></tr>\n";
	}
print <<EOD;
</table>
</td></tr></table><br clear=all>
EOD
print "<br clear=all>".$msg if $msg;
#print $navibuf;

&navi2;
&hpfoot;
}
#******************************************************************************
sub navi2{
#カテゴリー表示
my $buffer;
$buffer .= "<br><div align=center>";
if ($catinditype == 0){
	for(0 .. $#catdata){
		if ($_ == $cat){
			$buffer .= "<b>▼$catdata[$_]</b>\n"
			}else{
			$buffer .= "<a href=\"./atlink.cgi?cat=$_\"><font style=\"text-decoration:none;\">▼</font>$catdata[$_]</a>\n";
			}
		}
	}else{
	$buffer .= "<table><tr><form method=\"get\" action=\"./atlink.cgi\"><td>\n<select name=\"cat\" class=\"select\">\n";
	for(0 .. $#catdata){
		if ($_ == $cat){
			$buffer .= "<option value=\"$_\" selected>$catdata[$_]\n";
			}else{
			$buffer .= "<option value=\"$_\">$catdata[$_]\n";
			}
		}
	$buffer .= "</select>\n<input type=\"submit\" value=\"GO!\" class=\"button\">\n</td></form></tr></table>\n";
	}
$buffer .= "</div><br>\n";
return $buffer;
}
#******************************************************************************
sub navi1{
#メニュー表示
print <<EOD;
<hr>
<div align=center>
<a href="$homeurl">HOME</a> 
&nbsp;&nbsp;<a href="./atlink.cgi">表\示</a>
&nbsp;&nbsp;<a href="./atlink.cgi?act=reg1">登録</a>
&nbsp;&nbsp;<a href="./atlink.cgi?act=chg1">変更</a>
&nbsp;&nbsp;<a href="./atlink.cgi?act=del1">削除</a>
&nbsp;&nbsp;<a href="./atlink.cgi?act=srh1">検索</a>
&nbsp;&nbsp;<a href="./atlink.cgi?act=adm1">管理</a>
</div>
<hr>
EOD
}
#******************************************************************************
sub hphead{
#ヘッダ表示

print "Content-type:text/html; charset=shift_jis\n\n";
print <<EOD;
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=Shift_JIS">
<title>ライムハート☆リンク</title>
<link href="../../style2004.css" rel="stylesheet" type="text/css">
</head>

<body>
<!-- #BeginLibraryItem "/limeheart/lbi/top.lbi" --><table border="0" cellpadding="0" cellspacing="0" width="700">
<!-- fwtable fwsrc="lime2004-3.png" fwbase="top3.gif" fwstyle="Dreamweaver" fwdocid = "742308039" fwnested="0" -->
  <tr>
   <td><img src="../../image/top2004/spacer.gif" width="198" height="1" border="0" alt=""></td><td><img src="../../image/top2004/spacer.gif" width="45" height="1" border="0" alt=""></td><td><img src="../../image/top2004/spacer.gif" width="26" height="1" border="0" alt=""></td><td><img src="../../image/top2004/spacer.gif" width="44" height="1" border="0" alt=""></td><td><img src="../../image/top2004/spacer.gif" width="27" height="1" border="0" alt=""></td><td><img src="../../image/top2004/spacer.gif" width="43" height="1" border="0" alt=""></td><td><img src="../../image/top2004/spacer.gif" width="28" height="1" border="0" alt=""></td><td><img src="../../image/top2004/spacer.gif" width="42" height="1" border="0" alt=""></td><td><img src="../../image/top2004/spacer.gif" width="27" height="1" border="0" alt=""></td><td><img src="../../image/top2004/spacer.gif" width="43" height="1" border="0" alt=""></td><td><img src="../../image/top2004/spacer.gif" width="27" height="1" border="0" alt=""></td><td><img src="../../image/top2004/spacer.gif" width="43" height="1" border="0" alt=""></td><td><img src="../../image/top2004/spacer.gif" width="27" height="1" border="0" alt=""></td><td><img src="../../image/top2004/spacer.gif" width="44" height="1" border="0" alt=""></td><td><img src="../../image/top2004/spacer.gif" width="26" height="1" border="0" alt=""></td><td><img src="../../image/top2004/spacer.gif" width="10" height="1" border="0" alt=""></td><td><img src="../../image/top2004/spacer.gif" width="1" height="1" border="0" alt=""></td></tr>

  <tr>
   <td rowspan="2"><img name="top3_r1_c1" src="../../image/top2004/top3_r1_c1.gif" width="198" height="95" border="0" alt=""></td><td colspan="15"><table width="502" height="71" border="0" cellpadding="0" cellspacing="0" bgcolor="#CCCC99">
        <tr>
          <td width="255" height="38"><font size="1">&lt;&lt;リラックスグッズと癒しアイテム&gt;&gt;</font></td><td width="247"><a href="../../first.html" target="_self"><font size="1">お買い物案内</font></a><font size="1">/<a href="../../terms.html" target="_self">関連法規の表示</a></font></td></tr>
        <tr>
          <td>　</td><td>　</td></tr>
      </table></td><td><img src="../../image/top2004/spacer.gif" width="1" height="71" border="0" alt=""></td></tr>
  <tr>
    <td colspan="2"><img name="top3_r2_c2" src="../../image/top2004/top3_r2_c2.gif" width="71" height="24" border="0" usemap="#m_top3_r2_c2" alt=""></td><td colspan="2"><img name="top3_r2_c4" src="../../image/top2004/top3_r2_c4.gif" width="71" height="24" border="0" usemap="#m_top3_r2_c4" alt=""></td><td colspan="2"><img name="top3_r2_c6" src="../../image/top2004/top3_r2_c6.gif" width="71" height="24" border="0" usemap="#m_top3_r2_c6" alt=""></td><td colspan="2"><img name="top3_r2_c8" src="../../image/top2004/top3_r2_c8.gif" width="69" height="24" border="0" usemap="#m_top3_r2_c8" alt=""></td><td colspan="2"><img name="top3_r2_c10" src="../../image/top2004/top3_r2_c10.gif" width="70" height="24" border="0" usemap="#m_top3_r2_c10" alt=""></td><td colspan="2"><img name="top3_r2_c12" src="../../image/top2004/top3_r2_c12.gif" width="70" height="24" border="0" usemap="#m_top3_r2_c12" alt=""></td><td colspan="2"><img name="top3_r2_c14" src="../../image/top2004/top3_r2_c14.gif" width="70" height="24" border="0" usemap="#m_top3_r2_c14" alt=""></td><td rowspan="3"><img name="top3_r2_c16" src="../../image/top2004/top3_r2_c16.gif" width="10" height="59" border="0" usemap="#m_top3_r2_c16" alt=""></td><td><img src="../../image/top2004/spacer.gif" width="1" height="24" border="0" alt=""></td></tr>
  <tr>
   <td rowspan="2" colspan="2"><img name="top3_r3_c1" src="../../image/top2004/top3_r3_c1.gif" width="243" height="35" border="0" usemap="#m_top3_r3_c1" alt=""></td><td colspan="2"><img name="top3_r3_c3" src="../../image/top2004/top3_r3_c3.gif" width="70" height="31" border="0" usemap="#m_top3_r3_c3" alt=""></td><td colspan="2"><img name="top3_r3_c5" src="../../image/top2004/top3_r3_c5.gif" width="70" height="31" border="0" usemap="#m_top3_r3_c5" alt=""></td><td colspan="2"><img name="top3_r3_c7" src="../../image/top2004/top3_r3_c7.gif" width="70" height="31" border="0" usemap="#m_top3_r3_c7" alt=""></td><td colspan="2"><img name="top3_r3_c9" src="../../image/top2004/top3_r3_c9.gif" width="70" height="31" border="0" usemap="#m_top3_r3_c9" alt=""></td><td colspan="2"><img name="top3_r3_c11" src="../../image/top2004/top3_r3_c11.gif" width="70" height="31" border="0" usemap="#m_top3_r3_c11" alt=""></td><td colspan="2"><img name="top3_r3_c13" src="../../image/top2004/top3_r3_c13.gif" width="71" height="31" border="0" usemap="#m_top3_r3_c13" alt=""></td><td rowspan="2"><img name="top3_r3_c15" src="../../image/top2004/top3_r3_c15.gif" width="26" height="35" border="0" usemap="#m_top3_r3_c15" alt=""></td><td><img src="../../image/top2004/spacer.gif" width="1" height="31" border="0" alt=""></td></tr>
  <tr>
   <td colspan="12"><img name="top3_r4_c3" src="../../image/top2004/top3_r4_c3.gif" width="421" height="4" border="0" alt=""></td><td><img src="../../image/top2004/spacer.gif" width="1" height="4" border="0" alt=""></td></tr>
<map name="m_top3_r2_c2">
    <area shape="poly" coords="10,1,0,25,71,25,62,1,10,1" href="../../index.html" target="_top" alt="" >
</map>
<map name="m_top3_r2_c4">
    <area shape="poly" coords="10,1,0,25,71,25,62,1,10,1" href="../../1_kaori.htm" target="_self" alt="香り" >
</map>
<map name="m_top3_r2_c6">
<area shape="poly" coords="79,1,69,25,140,25,131,1,79,1" href="#" alt="" >
    <area shape="poly" coords="10,1,0,25,71,25,62,1,10,1" href="../../2_akari.htm" target="_self" alt="灯り" >
</map>
  <map name="m_top3_r2_c8">
    <area shape="poly" coords="78,1,68,25,139,25,130,1,78,1" href="#" alt="" >
    <area shape="poly" coords="8,0,-2,24,69,24,60,0,8,0" href="../../3_hureai.htm" target="_self" alt="触れ合い" >
</map>
<map name="m_top3_r2_c10">
    <area shape="poly" coords="9,1,-1,25,70,25,61,1,9,1" href="../../4_sound.htm" target="_self" alt="サウンド" >
</map>
<map name="m_top3_r2_c12">
    <area shape="poly" coords="10,1,0,25,71,25,62,1,10,1" href="../../5_nyuyoku.htm" target="_self" alt="入浴" >
</map>
<map name="m_top3_r2_c14">
    <area shape="poly" coords="10,1,0,25,71,25,62,1,10,1" href="../../6_anmin.htm" target="_self" alt="安眠休息" >
<area shape="poly" coords="-60,1,-70,25,1,25,-8,1,-60,1" href="#" alt="" >
</map>
<map name="m_top3_r2_c16">
<area shape="poly" coords="-60,1,-70,25,1,25,-8,1,-60,1" href="#" alt="" >
</map>
<map name="m_top3_r3_c1">
<area shape="poly" coords="252,5,242,29,313,29,304,5,252,5" href="#" alt="" >
<area shape="poly" coords="208,-23,198,1,269,1,260,-23,208,-23" href="#" alt="" >
</map>
<map name="m_top3_r3_c3">
<area shape="poly" coords="79,5,69,29,140,29,131,5,79,5" href="#" alt="" >
    <area shape="poly" coords="9,5,-1,29,70,29,61,5,9,5" href="../../7_wahu.htm" target="_self" alt="和風" >
<area shape="poly" coords="36,-23,26,1,97,1,88,-23,36,-23" href="#" alt="" >
<area shape="poly" coords="-35,-23,-45,1,26,1,17,-23,-35,-23" href="#" alt="" >
</map>
<map name="m_top3_r3_c5">
<area shape="poly" coords="79,5,69,29,140,29,131,5,79,5" href="#" alt="" >
    <area shape="poly" coords="9,5,-1,29,70,29,61,5,9,5" href="../../8_azian.htm" target="_self" alt="アジアン" >
<area shape="poly" coords="37,-23,27,1,98,1,89,-23,37,-23" href="#" alt="" >
<area shape="poly" coords="-34,-23,-44,1,27,1,18,-23,-34,-23" href="#" alt="" >
</map>
<map name="m_top3_r3_c7">
<area shape="poly" coords="79,5,69,29,140,29,131,5,79,5" href="#" alt="" >
    <area shape="poly" coords="9,5,-1,29,70,29,61,5,9,5" href="../../9_teien.htm" target="_self" alt="庭園" >
<area shape="poly" coords="36,-23,26,1,97,1,88,-23,36,-23" href="#" alt="" >
<area shape="poly" coords="-33,-23,-43,1,28,1,19,-23,-33,-23" href="#" alt="" >
</map>
<map name="m_top3_r3_c9">
<area shape="poly" coords="79,6,69,30,140,30,131,6,79,6" href="#" alt="" >
    <area shape="poly" coords="9,5,-1,29,70,29,61,5,9,5" href="../../10_bizyutu.htm" target="_self" alt="美術" >
<area shape="poly" coords="36,-23,26,1,97,1,88,-23,36,-23" href="#" alt="" >
<area shape="poly" coords="-34,-23,-44,1,27,1,18,-23,-34,-23" href="#" alt="" >
</map>
<map name="m_top3_r3_c11">
<area shape="poly" coords="79,5,69,29,140,29,131,5,79,5" href="#" alt="" >
    <area shape="poly" coords="9,6,-1,30,70,30,61,6,9,6" href="../../11_suisyo.htm" target="_self" alt="水晶・鉱石" >
<area shape="poly" coords="37,-23,27,1,98,1,89,-23,37,-23" href="#" alt="" >
<area shape="poly" coords="-34,-23,-44,1,27,1,18,-23,-34,-23" href="#" alt="" >
</map>
<map name="m_top3_r3_c13">
    <area shape="poly" coords="9,5,-1,29,70,29,61,5,9,5" href="../../12_mainasuion.htm" target="_self" alt="マイナスイオン" >
<area shape="poly" coords="37,-23,27,1,98,1,89,-23,37,-23" href="#" alt="" >
<area shape="poly" coords="-33,-23,-43,1,28,1,19,-23,-33,-23" href="#" alt="" >
</map>
<map name="m_top3_r3_c15">
<area shape="poly" coords="-34,-23,-44,1,27,1,18,-23,-34,-23" href="#" alt="" >
</map>
</table><!-- #EndLibraryItem --> 

$pagetop<br>
EOD
#&navi1;
}
#******************************************************************************
sub hpfoot{
#フッタ表示
#
#著作権を消すことを禁じます。
print <<EOD;
<hr>
<div align="center"><a href="http://dream.lib.net/room/" target="_blank">Automatic Link by The Room</a></div>
</body></html>
EOD
exit;
}
#******************************************************************************
sub error{
#エラー表示
&hphead;
print <<EOD;
<br><br>
<div align=center>
$_[0]
</div>
<br><br>
EOD
&hpfoot;
}
#******************************************************************************
sub datacheck{
#データチェック
if ($sitecat eq ""){&error("カテゴリーを選択してください。");}
elsif ($sitename eq ""){&error("サイト名を入力してください。");}
elsif ($siteurl eq ""){&error("サイトURLを入力してください。");}
elsif (($commentent) && ($sitecomment eq "")){&error("コメントを入力してください。");}
elsif (($mailent) && ($sitemail eq "")){&error("メールアドレスを入力してください。");}
elsif ($sitepass eq ""){&error("パスワードを設定してください。");}

elsif (length($sitepass) > 8){&error("パスワードが長すぎます。");}
elsif (length($sitecomment) > $commentlimit){&error("コメントが長すぎます。");}
elsif ($sitepass =~ /[^0-9a-zA-Z]/){&error("パスワードは半角英数字のみで設定してください。");}
elsif ($siteurl !~ /^https?:\/\/[\w|\:\@\-]+\.[\w|\:\!\#\%\=\&\-\|\@\~\+\.\?\/]+$/i){&error("サイトURLが間違っています。");}
elsif (($sitebanner ne "") && ($sitebanner !~ /^https?:\/\/[\w|\:\@\-]+\.[\w|\:\!\#\%\=\&\-\|\@\~\+\.\?\/]+$/i)){&error("バナーURLが間違っています。");}
elsif (($mailent) && ($sitemail) && ($sitemail !~ /[\w\.\-\&]+\@[\w\.\-\&]+\.[\w\.\-\&]/)){&error("メールアドレスが間違っています。");}
}
#******************************************************************************
