コメント |
@DIV
PHP 基本部分
@LINE
[[HTML META]] 部分
@LINE
[[HTML STYLE]] 部分
@LINE
[[クライアント スクリプト]]
@LINE
HTML 画面定義
@END
[[テスト用変更ID フィールドは本来非表示なので入力しないように]]
[[未チェックですが、シングルクオート、ダブルクォート、バックスラッシュ(\) は、入力不可とする]]
※ どうしても入力必要な場合は、特別な処理が多く付加される )
※ シングルクオートに関してのみ、SQL 文字列作成直前に入力値の ' -> '' 変換を実施してもよい
( 但し、INPUT の VALUE 属性に HTMLとして 文字列セットする場合は HTML 側で必ず ダブルクォートを使う事 )
例 : <INPUT type=text value="<?= $data ?>">
STYLE は、外部定義と内部定義があり、STYLE 内の構文からも外部ファイルを定義できる
JavaScript(クライアント スクリプト) も、外部定義と内部定義がある
@DIV
<?
# **********************************************************
# 基本定義部分
# **********************************************************
ini_set( 'display_errors', "1" );
function inc( $path ) {
$inc = @file( $path );
array_shift($inc);
array_pop($inc);
$GLOBALS['inc_eval_txt'] = implode( "", $inc );
eval($GLOBALS['inc_eval_txt']);
}
$conf_client_charset = "euc-jp";
$conf_db_type = 1;
#$conf_db_connect_action = "set names 'ujis'";
header( "Expires: Wed, 31 May 2000 14:59:58 GMT" );
header( "Content-Type: text/html; Charset=$conf_client_charset" );
# **********************************************************
# 外部ファイル
# **********************************************************
inc( "http://lightbox.in.coocan.jp/gen/db.txt" );
?>
<HTML>
<HEAD>
<!-- *************************************************** -->
<!-- ドキュメント定義部分 -->
<!-- *************************************************** -->
<META http-equiv="Content-type" content="text/html; charset=<?= $conf_client_charset ?>">
<TITLE>シンプル掲示板</TITLE>
<!-- =================================================== -->
<!-- スタイルシート -->
<!-- =================================================== -->
<STYLE type="text/css">
* {
font-family: "MS Pゴシック";
font-size: 12px;
}
BODY {
background-color: white;
color: black;
}
.honbun {
padding:10px;
width:100%;
height:100%;
border-color:black;
border-style:solid;
border-width:1px;
}
</STYLE>
<!-- =================================================== -->
<!-- 外部クライアントスクリプト -->
<!-- =================================================== -->
<SCRIPT
language="javascript"
type="text/javascript"
src="http://lightbox.in.coocan.jp/prototype.js">
</SCRIPT>
<!-- =================================================== -->
<!-- クライアントスクリプト -->
<!-- =================================================== -->
<SCRIPT language="javascript" type="text/javascript">
// *********************************************************
// フォームのチェック
// *********************************************************
function CheckData() {
if ( Trim( $("title").value ) == "" ) {
Error( $("title"), "タイトルを入力して下さい" );
return false;
}
if ( Trim($("body").value) == "" ) {
Error( $("body"), "本文を入力して下さい" );
return false;
}
if ( Trim($("password").value) == "" ) {
Error( $("password"), "パスワードを入力して下さい" );
return false;
}
return true;
}
// *********************************************************
// エラーメッセージ
// *********************************************************
function Error( field, str ) {
alert( str + " " );
field.focus();
field.select();
}
// *********************************************************
// 削除パスワードチェック
// *********************************************************
function CheckDelete( no ) {
if ( Trim($2("password",no).value) == "" ) {
Error( $2("password",no), "パスワードを入力して下さい" );
return false;
}
return true;
}
// *********************************************************
// 投稿データより投稿エリアへデータ転送
// *********************************************************
function TransferData( no ) {
$("update").value = $2("board_id",no-1).value;
$("title").value = $2("board_title",no-1).value;
$("name").value = $2("board_name",no-1).value;
$("body").value = $2("board_body",no-1).value;
$3("BODY").scrollTop = 0;
$("entry").style.backgroundColor = 'skyblue';
$("name").style.backgroundColor = 'silver';
$("name").disabled = true;
}
// *********************************************************
// 変更モードから通常モードへ移行する
// *********************************************************
function ResetForm( ) {
$("update").value = '';
$("name").value = '';
$("entry").style.backgroundColor = 'white';
$("name").style.backgroundColor = 'white';
$("name").disabled = false;
}
// *********************************************************
// 漢字スペースを含む空白削除
// *********************************************************
function Trim( strValue ) {
// 以下[]内の空白に見えるのは漢字スペース
var regL = /^[ \s]+/;
var regR = /[ \s]+$/;
strValue = strValue.replace(regL,"");
strValue = strValue.replace(regR,"");
return strValue;
}
</SCRIPT>
<!-- *************************************************** -->
<!-- 画面定義部分 -->
<!-- *************************************************** -->
<BODY style='text-align:center'>
<FORM
method=post
onSubmit='return CheckData()'
>
<TABLE id=entry border=1>
<TR>
<TD>タイトル</TD>
<TD>
<INPUT
type=text
name=title
value="<?= $_POST['title'] ?>"
>
テスト用変更ID
<INPUT type=text name=update>
</TD>
</TR>
<TR>
<TD>名前</TD>
<TD>
<INPUT
type=text
name=name
value="<?= $_POST['name'] ?>"
>
パスワード
<INPUT type=password name=password>
</TD>
</TR>
<TR>
<TD>本文</TD>
<TD>
<TEXTAREA
name=body
cols=80
rows=10
><?= $_POST['body'] ?></TEXTAREA>
</TD>
</TR>
<TR>
<TD colspan=2>
<!-- 変更モードキャンセルボタン -->
<INPUT
type=button
value="リセット"
onClick='ResetForm()'
style='float:right;'
>
<!-- 通常投稿送信ボタン -->
<INPUT
type=submit
name=send
value="送信"
>
</TD>
</TR>
</TABLE>
</FORM>
<HR>
<?
# **********************************************************
# デバッグ用
# **********************************************************
print "<PRE style='text-align:left;width:100%'>";
print_r($_POST);
print "</PRE>";
# **********************************************************
# 接続
# **********************************************************
$SQL = new DB( "localhost", "lightbox", "root", "" );
# **********************************************************
# 更新
# **********************************************************
if ( $_POST['update'] != '' ) {
$Query = "select * from board ";
$Query .= " where board_id = '{$_POST['update']}'";
$Query .= " and board_pass = '" . sha1($_POST['password']) . "'";
$Column = $SQL->QueryEx( $Query );
if ( !$Column ) {
print "<SPAN style='font-weight:bold;font-size:16px;color:red'>バスワードが一致しません</SPAN><br><br>";
print "<INPUT type=button value='戻る' onClick='location=\"board.php\"'>";
exit();
}
$Query = "select * from board ";
$Query .= " where board_body = '{$_POST['body']}'";
$Query .= " and board_delflg is NULL";
$Column = $SQL->QueryEx( $Query );
if ( $Column ) {
print "<SPAN style='font-weight:bold;font-size:16px;color:red'>二重投稿です。</SPAN><br><br>";
print "<INPUT type=button value='戻る' onClick='location=\"board.php\"'>";
exit();
}
$Query = "update board set ";
$Query .= " board_title = '{$_POST['title']}'";
$Query .= " ,board_body = '{$_POST['body']}'";
$Query .= " ,board_update = now()";
$Query .= " where board_id = {$_POST['update']}";
$SQL->Execute( $Query );
print "<SPAN style='font-weight:bold;font-size:16px;color:blue'>投稿が更新されました</SPAN><br><br>";
print "<INPUT type=button value='戻る' onClick='location=\"board.php\"'>";
exit();
}
# **********************************************************
# 削除
# **********************************************************
if ( $_POST['send'] == '削除' ) {
$Query = "select * from board ";
$Query .= " where board_id = '{$_POST['board_id']}'";
$Query .= " and board_pass = '" . sha1($_POST['password']) . "'";
$Column = $SQL->QueryEx( $Query );
if ( !$Column ) {
print "<SPAN style='font-weight:bold;font-size:16px;color:red'>バスワードが一致しません</SPAN><br><br>";
}
else {
$Query = "update board ";
$Query .= " set board_delflg = 'D'";
$Query .= " ,board_update = now()";
$Query .= " where board_id = {$_POST['board_id']}";
$SQL->Execute( $Query );
print "<SPAN style='font-weight:bold;font-size:16px;color:blue'>投稿が削除されました</SPAN><br><br>";
}
print "<INPUT type=button value='戻る' onClick='location=\"board.php\"'>";
exit();
}
# **********************************************************
# 新規追加
# **********************************************************
if ( $_POST['send'] != '' ) {
$Query = "select * from board ";
$Query .= " where board_body = '{$_POST['body']}'";
$Query .= " and board_delflg is NULL";
$Column = $SQL->QueryEx( $Query );
if ( $Column ) {
print "<SPAN style='font-weight:bold;font-size:16px;color:red'>二重投稿です。</SPAN><br><br>";
}
else {
$Query = " insert into board (board_title,board_name,board_pass,board_body,board_create,board_update) ";
$pass = sha1($_POST['password']);
$Query .= " values('{$_POST['title']}','{$_POST['name']}','$pass','{$_POST['body']}',now(),now()) ";
$SQL->Execute( $Query );
}
}
$Query = "select * from board where board_delflg is NULL order by `board_update` desc";
$Column = $SQL->QueryEx( $Query );
# **********************************************************
# 発言一覧表示部分
# **********************************************************
$row = 1;
print "<TABLE border=0 style='table-layout:fixed;width:80%'>\n";
while( $Column ) {
?>
<TR>
<TD style='line-height:20px;'>
【<?= $Column['board_title'] ?>】: <?= $Column['board_create'] ?>
<br>
発言者 : <?= $Column['board_name'] ?>
</TD>
</TR>
<TR>
<TD valign=top><PRE class=honbun><?= $Column['board_body'] ?></PRE></TD>
</TR>
<TR>
<TD valign=top>
<FORM
method=post
onSubmit='return CheckDelete( <?= $row ?> )'
>
<!-- 削除用送信ボタン -->
<INPUT
type=submit
name=send
value='削除'
>
パスワード
<INPUT type=password name=password>
<!-- データ転送用隠しフィールド -->
<INPUT
type=hidden
name=board_id
value='<?= $Column['board_id'] ?>'
>
<INPUT
type=hidden
name=board_title
value='<?= $Column['board_title'] ?>'
>
<INPUT
type=hidden
name=board_name
value='<?= $Column['board_name'] ?>'
>
<TEXTAREA
name=board_body
style='display:none'
><?= $Column['board_body'] ?></TEXTAREA>
<!-- 変更データ転送ボタン -->
<INPUT
type=button
value='変更'
onClick='TransferData( <?= $row ?> )'
>
</FORM>
<br>
</TD>
</TR>
<?
$Column = $SQL->QueryEx( );
$row++;
}
print "</TABLE>\n";
# **********************************************************
# 接続解除
# **********************************************************
$SQL->Close();
?>
<br>
</BODY>
</HTML>
@END
|