<HTML>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=x-euc-jp">
<HEAD>
<TITLE>PHP LINKS MAKER</TITLE>
</HEAD>
<?
mysql_connect("localhost","root","");
mysql_select_db("test_link");
if($button == "書き込み"){ //書き込み処理
//ごく簡単なチェック
$error = false;
if($parent_number==0 && $type=="link") {
$error_message="最上階にはフォルダしか作れません";
$error = true;
}
if($type=="link" && (empty($title) || empty($link))) {
$error_message="タイトルとURLは必須です";
$error = true;
}
if($type=="folder" && empty($title)) {
$error_message="タイトルは必須です";
$error = true;
}
if($error){
print "</head></html>";//いちおうタグを閉じてみる
print "エラーがあります<br>";
print $error_message;
exit();
}
$result = mysql_query("insert into links set parent_number=$parent_number, type='$type', title='$title', link='$link', comment='$comment', banner='$banner'");
print $result ? "書き込みました<BR>": "書き込みに失敗しました<BR>";
$parent_number=0;
include("write1.php");
Show_Items();
}
else if(isset($print_number)){ //内容表示処理
include("show_contents1.php");
$parent_number=$print_number;
if($type=="folder")include("write1.php");
}
else { //通常
$parent_number=0;
include("write1.php");
Show_Items();
}
function Show_Items(){
print ("<B>一覧</B><BR><BR>");
Show_Itself_And_Call_Children(0,-1);
}
function Show_Itself_And_Call_Children($number, $indent){
//表示
if ($number != 0){
$result = mysql_query("select * from links where number=$number");
$row = mysql_fetch_assoc($result);
foreach($row as $key => $value){
$$key = $value;
}
//print("親:[$row[parent_number]]");
print str_repeat("-",$indent);
if($type=="folder"){ //フォルダの場合
print"○";
print "$number: <a href=\"create_link.php?print_number=$number\">$title</a>";
print ": $comment<BR>\n";
}
else { //リンクの場合
print "$number: <a href=\"create_link.php?print_number=$number\">$title</a>";
if(!empty($banner)) print "<img src=\"$banner\" width=\"30\" height=\"15\">";
print ": $comment<BR>\n";
}
}
//子供呼び出し
$result = mysql_query("select * from links where parent_number=$number ORDER BY type DESC");
while ($row=mysql_fetch_assoc($result)) Show_Itself_And_Call_Children($row[number], $indent+1);
}
?>
</HTML>