PHP マスタメンテ


  control.php




  

<?
# *******************************************************************************
# 外部ファイル
# *******************************************************************************
require_once( 'common.php' );
require_once( 'db.php' );
require_once( 'model.php' );

# *******************************************************************************
# 定数
# *******************************************************************************
define( TXT_PROTECT, 'readonly style="background-color:silver"' );
define( BTN_PROTECT, 'disabled' );

# *******************************************************************************
# 初期値
# *******************************************************************************
$Title		= '住 所 登 録';
$Sel		= array('','','','');

# *******************************************************************************
# PASS グループ
# *******************************************************************************
$DisPass = 
array(
	'ad_id'		=> 1,
	'Check'		=> 1,
	'ad_name'	=> 2,
	'ad_zip'	=> 2,
	'ad_place'	=> 2,
	'ad_tel'	=> 2,
	'Update'	=> 2
);

# *******************************************************************************
# プロテクトタイプ
# *******************************************************************************
$DisType = 
array(
	'Check'		=> BTN_PROTECT,
	'Update'	=> BTN_PROTECT,
	'ad_id'		=> TXT_PROTECT,
	'ad_name'	=> TXT_PROTECT,
	'ad_zip'	=> TXT_PROTECT,
	'ad_place'	=> TXT_PROTECT,
	'ad_tel'	=> TXT_PROTECT
);

# *******************************************************************************
# 初期プロテクト
# *******************************************************************************
$Dis = array(
	'Check'		=> '',
	'ad_id'		=> '',
	'ad_name'	=> TXT_PROTECT,
	'ad_zip'	=> TXT_PROTECT,
	'ad_place'	=> TXT_PROTECT,
	'ad_tel'	=> TXT_PROTECT,
	'Update'	=> BTN_PROTECT
);

# *******************************************************************************
# DB インスタンス
# *******************************************************************************
	$SQL = new DB( );

# *******************************************************************************
# 処理コントロール
# *******************************************************************************
	switch ( $_ENV['REQUEST_METHOD'] ) {

		case 'GET':
			break;

		case 'POST':
			$Sel[$_POST['mode']] = 'selected';
			switch( $_POST['send'] ) {
				case 'チェック':
					if ( $_POST['mode'] == 1 ) {
						if ( CheckData( $SQL ) ) {
							$Option = "データは既に存在します";
							break;
						}
					}
					else {
						if ( !CheckData( $SQL ) ) {
							$Option = "該当データが存在しません";
							break;
						}
					}

					$ModeDisable = 'disabled';
					$Option = '<INPUT type=hidden name=mode value=';
					$Option .= Dd( $_POST['mode'] );
					$Option .= '>';

					if ( $_POST['mode'] != 3 ) {
						foreach( $DisPass as $Key => $Value ) {
							if ( $Value == 1 ) {
								$Dis[$Key] = $DisType[$Key];
							}
							if ( $Value == 2 ) {
								$Dis[$Key] = '';
							}
						}
					}
					else {
						foreach( $DisPass as $Key => $Value ) {
							if ( $Key == 'Update' ) {
								$Dis[$Key] = '';
							}
							else {
								$Dis[$Key] = $DisType[$Key];
							}
						}
					}
					break;

				case '更新':
					switch ( $_POST['mode'] ) {

						case 1:
							InsertData( $SQL );
							$Sel[1] = "selected";
							break;
		
						case 2:
							UpData( $SQL );
							$Sel[2] = "selected";
							break;
		
						case 3:
							DeleteData( $SQL );
							$Sel[3] = "selected";
							break;
					}
					#header( "Location: {$_ENV['HTTP_REFERER']}" );
					#$SQL->Close();
					#exit();
					break;

				default:
					$SqlDel = "delete from address where ad_id =" . $_POST['send'];
					$SQL->Query( $SqlDel );
					break;
			}
			break;

	}

# *******************************************************************************
# ビュー
# *******************************************************************************
	GetData( $SQL );
	require_once( 'view.php' );

# *******************************************************************************
# 接続解除
# *******************************************************************************
	$SQL->Close();


DispDebug( "POST" );
?>
  







  view.php




  

<SCRIPT language=JavaScript src="<?=COMMON_CLIENT_PATH?>common.js"></SCRIPT>
<SCRIPT language=JavaScript>

var Item = document.all;
var Bflg = 0;
// *****************************************************************************
// 画面チェック
// *****************************************************************************
function CheckData() {

	var Mode;

	switch( Bflg ) {
		case 1:
			Mode = eval( Item("mode").value );

			if ( Item("ad_id").value == "" ) {
				alert( "番号を入力して下さい" );
				Item("ad_id").focus();
				return false;
			}
			if ( !ChkNum( Item("ad_id").value ) ) {
				alert( "数字を入力して下さい" );
				Item("ad_id").focus();
				Item("ad_id").select();
				return false;
			}
			break;
		case 2:
			Mode = eval( Item("mode")(1).value );

			switch( Mode ) {
				case 1:
				case 2:
					if ( !ChkZip( Item("ad_zip").value ) ) {
						alert( "郵便番号が正しくありません" );
						Item("ad_zip").focus();
						Item("ad_zip").select();
						return false;
					}

					if ( !confirm( "更新してよろしいですか" ) ) {
						return false;
					}
					break;

				case 3:
					if ( !confirm( "削除してよろしいですか" ) ) {
						return false;
					}
			}
			break;
	}


	return true;

}

</SCRIPT>

<HTML>

<!-- ***************************************************************************
 ヘッダ
**************************************************************************** -->
<HEAD>
<META http-equiv="Content-type" content="text/html; charset=Shift_JIS">
<? require_once( 'style.php' ) ?>
</HEAD>

<!-- ***************************************************************************
 ボディ
**************************************************************************** -->
<BODY id=Body>
<? DispTitle( $Title ) ?>

<CENTER>
<!-- ***************************************************************************
 フォーム
**************************************************************************** -->
<FORM name="frm" method="POST" action="control.php" onSubmit='return CheckData();'>

<!-- ***************************************************************************
 処理区分
**************************************************************************** -->
	<SELECT name=mode <?=$ModeDisable?>>
		<OPTION value=1 <?=$Sel[1]?>>登録
		<OPTION value=2 <?=$Sel[2]?>>修正
		<OPTION value=3 <?=$Sel[3]?>>削除
	</SELECT>

	<BR>
	<?=$Option?>
	<BR>

	<TABLE border=5 cellpadding=5 style='border-style:ridge'>
<!-- ***************************************************************************
 番号
**************************************************************************** -->
		<TR>
			<TD>No.</TD>
			<TD>
				<INPUT
					type=text
					name=ad_id
					size=4
					maxlength=3
					value="<?=$_POST['ad_id']?>"
					<?=$Dis['ad_id']?>
				>
				<INPUT type=submit name=send value="チェック" <?=$Dis['Check']?> onClick='Bflg=1'>
			</TD>
		</TR>

<!-- ***************************************************************************
 氏名
**************************************************************************** -->
		<TR>
			<TD>氏名</TD>
			<TD>
				<INPUT
					type=text
					name=ad_name
					size=25
					maxlength=50
					value="<?=$_POST['ad_name']?>"
					<?=$Dis['ad_name']?>
				>
			</TD>
		</TR>

<!-- ***************************************************************************
 郵便番号
**************************************************************************** -->
		<TR>
			<TD>郵便番号</TD>
			<TD>
				<INPUT
					type=text
					name=ad_zip
					size=10
					maxlength=8
					value="<?=$_POST['ad_zip']?>"
					<?=$Dis['ad_zip']?>
				>
			</TD>
		</TR>

<!-- ***************************************************************************
 住所
**************************************************************************** -->
		<TR>
			<TD>住所</TD>
			<TD>
				<INPUT
					type=text
					name=ad_place
					size=50
					maxlength=50
					value="<?=$_POST['ad_place']?>"
					<?=$Dis['ad_place']?>
				>
			</TD>
		</TR>

<!-- ***************************************************************************
 電話番号
**************************************************************************** -->
		<TR>
			<TD>電話番号</TD>
			<TD>
				<INPUT
					type=text
					name=ad_tel
					size=16
					maxlength=14
					value="<?=$_POST['ad_tel']?>"
					<?=$Dis['ad_tel']?>
				>
			</TD>
		</TR>

	</TABLE>
	<BR>
	<INPUT type=submit name=send value="更新" <?=$Dis['Update']?> onClick='Bflg=2'>
	<INPUT type=button value="Cancel" onClick='location="control.php"'>

	<BR><BR>
	<HR>
	<?=$TDATA?>

</FORM>

</BODY>
</HTML>

<? MaxWindow() ?>
  

  model.php

  

<?

# *******************************************************************************
# インサート関数
# *******************************************************************************
function InsertData( &$SQL ){

	$IN = "insert into address (ad_id,ad_name,ad_zip,ad_place,ad_tel) values(";
	$IN = $IN. $_POST['ad_id'];
	$IN = $IN. "," . Ss( $_POST['ad_name'] );
	$IN = $IN. "," . Ss( $_POST['ad_zip'] );
	$IN = $IN. "," . Ss( $_POST['ad_place'] );
	$IN = $IN. "," . Ss( $_POST['ad_tel'] );
	$IN = $IN. ")";

	$SQL->Execute( $IN );

}

# *******************************************************************************
# チェック関数
# *******************************************************************************
function CheckData( &$SQL ){

	$column = $SQL->QueryEX( "select * from address where ad_id =" . $_POST['ad_id'] );

	if ( $column ) {
		$_POST['ad_name']	= $column['ad_name'];
		$_POST['ad_zip']	= $column['ad_zip'];
		$_POST['ad_place']	= $column['ad_place'];
		$_POST['ad_tel']	= $column['ad_tel'];
		return True;
	}
	else {
		return False;
	}

}

# *******************************************************************************
# データ表示関数
# *******************************************************************************
function GetData( &$SQL ){

	global $TDATA ;

	$column = $SQL->QueryEX( "select * from address" );

	$TDATA = $TDATA. "<TABLE border=5 cellpadding=5 style='border-style:ridge'>";

	while ( $column ) {

		$TDATA = $TDATA. "<TR>";
		$TDATA = $TDATA. "<TD>" . "<INPUT type=submit name='send' ";
		$TDATA = $TDATA. "onClick='Bflg=0' value='" . $column['ad_id'] . "'>" . "</TD>";
		$TDATA = $TDATA. "<TD>" . $column['ad_name'] . "</TD>";
		$TDATA = $TDATA. "<TD>" . $column['ad_zip'] . "</TD>";
		$TDATA = $TDATA. "<TD>" . $column['ad_place'] . "</TD>";
		$TDATA = $TDATA. "<TD>" . $column['ad_tel'] . "</TD>";
		$TDATA = $TDATA. "</TR>\n";

		$column = $SQL->QueryEX( "" );		

	}

	$TDATA = $TDATA. "</TABLE>";
}

# *******************************************************************************
# データ(アップデート)修正関数
# *******************************************************************************
function UpData( &$SQL ){

	$UP = "update address set ";
	$UP = $UP. " ad_name  = " . Ss( $_POST['ad_name'] );
	$UP = $UP. ",ad_zip   = " . Ss( $_POST['ad_zip'] );
	$UP = $UP. ",ad_place = " . Ss( $_POST['ad_place'] );
	$UP = $UP. ",ad_tel   = " . Ss( $_POST['ad_tel'] );
	$UP = $UP. " where ad_id = " . $_POST['ad_id'] ;

	$SQL->Execute( $UP );

}

# *******************************************************************************
# データ削除関数
# *******************************************************************************
function DeleteData( &$SQL ){

	$DEL = "delete from address where ad_id =" . $_POST['ad_id'];
	$SQL->Execute( $DEL );
}

?>
  




yahoo  google  MSDN  MSDN(us)  WinFAQ  Win Howto  tohoho  ie_DHTML  vector  wdic  辞書  天気 


[CommonSpec]
CCBot/2.0 (https://commoncrawl.org/faq/)
24/12/09 07:43:01
InfoBoard Version 1.00 : Language=Perl

1 BatchHelper COMprog CommonSpec Cprog CprogBase CprogSAMPLE CprogSTD CprogSTD2 CprogWinsock Cygwin GameScript HTML HTMLcss InstallShield InstallShieldFunc JScript JScriptSAMPLE Jsfuncs LLINK OldProg OracleGold OracleSilver PRO PRObrowser PROc PROconePOINT PROcontrol PROftpclient PROjscript PROmailer PROperl PROperlCHAT PROphp PROphpLesson PROphpLesson2 PROphpLesson3 PROphpfunction PROphpfunctionArray PROphpfunctionMisc PROphpfunctionString PROsql PROvb PROvbFunction PROvbString PROvbdbmtn PROvbonepoint PROwebapp PROwin1POINT PROwinSYSTEM PROwinYOROZU PROwindows ProjectBoard RealPHP ScriptAPP ScriptMaster VBRealtime Vsfuncs a1root access accreq adsi ajax amazon argus asp aspSample aspVarious aspdotnet aw2kinst cappvariety centura ckeyword classStyle cmaterial cmbin cmdbapp cmenum cmlang cmlistbox cmstd cmstdseed cmtxt cs daz3d db dbCommon dbaccess dnettool dos download flex2 flex3 flex4 framemtn framereq freeWorld freesoft gimp ginpro giodownload google hdml home hta htmlDom ie9svg install java javaSwing javascript jetsql jquery jsp jspTest jspVarious lightbox listasp listmsapi listmsie listmsiis listmsnt listmspatch listmsscript listmsvb listmsvc memo ms msde mysql netbeans oraPlsql oracle oracleWiper oraclehelper orafunc other panoramio pear perl personal pgdojo pgdojo_cal pgdojo_holiday pgdojo_idx pgdojo_ref pgdojo_req php phpVarious phpguide plsql postgres ps r205 realC realwebapp regex rgaki ruby rule sboard sc scprint scquest sdb sdbquest seesaa setup sh_Imagick sh_canvas sh_dotnet sh_google sh_tool sh_web shadowbox shgm shjquery shvbs shweb sjscript skadai skywalker smalltech sperl sqlq src systemdoc tcpip tegaki three toolbox twitter typeface usb useXML vb vbdb vbsfunc vbsguide vbsrc vpc wcsignup webanymind webappgen webclass webparts webtool webwsh win8 winofsql wmi work wp youtube