<?php
// クッキーの取得
if (isset($HTTP_POST_VARS[name]))
{
/* フォームのデータ代入 */
$name = $HTTP_POST_VARS[name];
$com = $HTTP_POST_VARS[com];
$email = $HTTP_POST_VARS[email];
$title = $HTTP_POST_VARS[title];
$fcolor = $HTTP_POST_VARS[fcolor];
$ryokanphp = "$name<>$email<>$fcolor<>";
setcookie('ryokanphp', $ryokanphp, time() + 60 * 86400);
$cname = $name;
$cemail= $email;
$cfcolor = $fcolor;
}
else
{
$a = 2;
list($cname, $cemail, $cfcolor) = split("<>", $_COOKIE[ryokanphp]);
}
/* 設定 */
$script = "test42.php"; //このスクリプトの名前
$logfile = "test42.log"; //ログファイル名
$viewmax = 10; //表示行数
$logmax = 500; //保存最大行数
$master_email = 'ryokan@po.minc.ne.jp'; //管理人メールアドレス
$master_name = '良寛'; //管理人名前
?>
<html>
<head>
<META http-equiv="Expires" content="0">
<META http-equiv="Cache-Control" content="no-cache">
<META Http-equiv="Content-Type" Content="text/html;charset=Shift_JIS">
<title>PHP簡易掲示板</title>
</head>
<body bgcolor="#FFFFFF">
<p align="center"><font face="MS ゴシック" size="6"><b>PHP簡易掲示板</b></font></p>
<p align="center"><font face="MS ゴシック" size="2">何でも書いて結構です</font></p>
<p align="center"><font face="MS ゴシック" size="2">現段階の</font><a href="test42.txt" target="_blank">ソース<img src="sosu.gif" border="0"></a></p>
<blockquote>
<?php
print "<form method=\"post\" action=\"$script\">\n";
?>
<input type="hidden" name="start_log" value="0">
<div align="left">
<table border="0">
<tr>
<td>
<p align="right">お名前:</td>
<center><td>
<?php
print ("<input type=\"text\" name=\"name\" size=\"30\" value=\"$cname\">\n");
?>
</td></tr>
</center>
<tr>
<td>
<p align="right">メール:</td>
<center><td>
<?php
print ("<input type=\"text\" name=\"email\" size=\"30\" value=\"$cemail\">\n");
?>
</td></tr>
<tr>
<td>
タイトル:</td>
<td><input type="text" name="title" size="30"></td>
</tr>
</center>
<tr>
<td>
<p align="right">文字色:</td>
<center><td>
<?php
if ($cfcolor == "")
{
print ("<input type=\"radio\" value=\"\" checked name=\"fcolor\">■ <input type=\"radio\" name=\"fcolor\" value=\"#008000\"><font color=\"#008000\">■</font> <input type=\"radio\" name=\"fcolor\" value=\"#800000\"><font color=\"#800000\">■</font> <input type=\"radio\" name=\"fcolor\" value=\"#000080\"><font color=\"#000080\">■</font> <input type=\"radio\" name=\"fcolor\" value=\"#FF0000\"><font color=\"#FF0000\">■</font>\n");
}
if ($cfcolor == "#008000")
{
print ("<input type=\"radio\" value=\"\" name=\"fcolor\">■ <input type=\"radio\" checked name=\"fcolor\" value=\"#008000\"><font color=\"#008000\">■</font> <input type=\"radio\" name=\"fcolor\" value=\"#800000\"><font color=\"#800000\">■</font> <input type=\"radio\" name=\"fcolor\" value=\"#000080\"><font color=\"#000080\">■</font> <input type=\"radio\" name=\"fcolor\" value=\"#FF0000\"><font color=\"#FF0000\">■</font>\n");
}
if ($cfcolor == "#800000")
{
print ("<input type=\"radio\" value=\"\" name=\"fcolor\">■ <input type=\"radio\" name=\"fcolor\" value=\"#008000\"><font color=\"#008000\">■</font> <input type=\"radio\" checked name=\"fcolor\" value=\"#800000\"><font color=\"#800000\">■</font> <input type=\"radio\" name=\"fcolor\" value=\"#000080\"><font color=\"#000080\">■</font> <input type=\"radio\" name=\"fcolor\" value=\"#FF0000\"><font color=\"#FF0000\">■</font>\n");
}
if ($cfcolor == "#000080")
{
print ("<input type=\"radio\" value=\"\" name=\"fcolor\">■ <input type=\"radio\" name=\"fcolor\" value=\"#008000\"><font color=\"#008000\">■</font> <input type=\"radio\" name=\"fcolor\" value=\"#800000\"><font color=\"#800000\">■</font> <input type=\"radio\" checked name=\"fcolor\" value=\"#000080\"><font color=\"#000080\">■</font> <input type=\"radio\" name=\"fcolor\" value=\"#FF0000\"><font color=\"#FF0000\">■</font>\n");
}
if ($cfcolor == "#FF0000")
{
print ("<input type=\"radio\" value=\"\" name=\"fcolor\">■ <input type=\"radio\" name=\"fcolor\" value=\"#008000\"><font color=\"#008000\">■</font> <input type=\"radio\" name=\"fcolor\" value=\"#800000\"><font color=\"#800000\">■</font> <input type=\"radio\" name=\"fcolor\" value=\"#000080\"><font color=\"#000080\">■</font> <input type=\"radio\" checked name=\"fcolor\" value=\"#FF0000\"><font color=\"#FF0000\">■</font>\n");
}
?>
</td></tr>
<tr>
<td></td>
<td><textarea rows="6" name="com" cols="60"></textarea></td>
</tr>
<tr>
<td></td>
<td><input type="submit" value="送信"> <input type="reset" value="リセット"></td>
</tr>
</table>
</center>
</div>
</form>
<hr>
<?php
if($name && $com)
{
/* 特殊文字をHTMLエンティティに変換 */
$com = htmlspecialchars ($com);
$name = htmlspecialchars ($name);
$title = htmlspecialchars ($title);
/* Shift-JISの場合バッククォートを除去 */
if(get_magic_quotes_gpc())
{
$com = stripslashes($com);
$name = stripslashes($name);
$title = stripslashes($title);
}
$com = str_replace("\r\n", "\r", $com); //Win系は\r\n
$com = str_replace("\r", "\n", $com); //Mac系は\r
$com = nl2br($com); //改行文字の前にHTMLの改行指定文字<br />を挿入する
$com = str_replace("\n", "", $com); //\n除去
/* 日付けのフォーマット */
$youbi = array("日", "月", "火", "水", "木", "金", "土");
$gmt = time() + 9*3600; //GMTとの時差9時間を足す
$now = gmdate("Y年m月d日", $gmt) . "(" . $youbi[gmdate("w",$gmt)] . ")" . gmdate(" H:i:s", $gmt);
/* ログを配列に読み込む */
$lines = file($logfile); //いままでのログを配列に読み込む
/* 旧ログの先頭レコードを取得 */
list($count1, $name1, $email1, $title1, $now1, $com1, $fcolor1, $time1) = split("<>", $lines[0]);
if ( $com1 != $com )
{
$count1++;
/* レコードの成型 */
$time = time();
$dat = "$count1<>$name<>$email<>$title<>$now<>$com<>$fcolor<>$time<>\n";
$fp = fopen($logfile, "w"); //ログをオープン(空になる)
fputs($fp,$dat); //データを書き込む(先頭に)
for($i = 0; $i < $logmax-1; $i++) //いままでの分を追記
{
fputs($fp, $lines[$i]); //(配列0-98→現ログ1-99行目)
}
fclose ($fp);
}
}
/* 表示処理 */
$lines = file($logfile); // ログを読込む
$n = count($lines) - 1; // 要素数カウント
$start_log = $HTTP_POST_VARS[start_log]; // 表示の開始番号
$end_log = $start_log + $viewmax - 1; // 終了番号
if ($start_log == "")
{
$start_log = 0;
}
if ($start_log > $n)
{
$start_log = $n;
}
if ($start_log < 0)
{
$start_log = 0;
}
if ($end_log > $n)
{
$end_log = $n;
}
$before = $start_log - $viewmax; // 前ページの表示番号
if ($before < 0)
{
$before = 0;
}
$next = $end_log + 1; // 次ページの表示番号
if ($next > $n)
{
$next = $n;
}
for($i = $start_log; $i <= $end_log; $i++)
{
list($count, $name, $email, $title, $now, $com, $fcolor, $time) = split("<>", $lines[$i]);
/* ログの表示 */
if ($count != 0)
{
if ($email)
{
if ($email == $master_email)
{
print ("$count <font size=3 color=blue><b><a href=\"mailto:$email\">$name</a></b></font> <small>$now</small><font color=$fcolor><b> $title</b><br><blockquote> $com </blockquote></font><hr>\n");
}
else
{
print ("$count <font size=3 color=blue><b><a href=\"mailto:$email\">$name</a></b></font>さん <small>$now</small><font color=$fcolor><b> $title</b><br><blockquote> $com </blockquote></font><hr>\n");
}
}
else
{
if ($name == $master_name)
{
print ("$count <font size=3 color=blue><b>$name</b></font> <small>$now</small><font color=$fcolor><b> $title</b><br><blockquote> $com </blockquote></font><hr>\n");
}
else
{
print ("$count <font size=3 color=blue><b>$name</b></font>さん <small>$now</small><font color=$fcolor><b> $title</b><br><blockquote> $com </blockquote></font><hr>\n");
}
}
}
}
?>
</blockquote>
<div align="center">
<center>
<table border="0" width="350">
<tr>
<td width="175" align="right">
<?php
print "<form method=\"POST\" action=\"$script\">\n";
if ($start_log > 0)
{
print <<< HERE
<input type="submit" value="前の $viewmax 件">
<input type="hidden" name="start_log" value="$before">
HERE;
}
print <<< HERE
</form>
</td>
<td width="175" align="left">
HERE;
print "<form method=\"POST\" action=\"$script\">\n";
if ($end_log < $n)
{
print <<< HERE
<input type="submit" value="次の $viewmax 件">
<input type="hidden" name="start_log" value="$next">
HERE;
}
?>
</form>
</td>
</tr>
</table>
</center>
</div>
</body></html>