user_insertExec.php 8.6 KB
<?PHP 
//*****************************************************************************
//* 
//* プログラム名:ユーザー情報登録
//* プログラムID:user_insertExec.php
//* 機能        :ユーザー情報データを登録する
//* 作成者      :t.sugiyama(MTC)
//* 
//*****************************************************************************
header("Content-type: text/html; charset=EUC-JP");
//***************************
//* インクルードファイル
//***************************
include("../../include/session_start.inc");
include("../../include/SessionChk2.inc");
include("../../include/dbcon.inc");
include("../../include/jcode.phps");
//***************************
//* 内部変数
//***************************
$objConn			= null;	//接続オブジェクト
$strSQL				= "";	//SQL文

$strUser_id		    = "";	//ユーザーID
$strUser_Pass	    = "";	//パスワード
$strSei_Kj	    	= "";	//氏名(姓)
$strMei_Kj		    = "";	//氏名(名)
$strSei_Kn		    = "";	//氏名(フリガナ姓)
$strMei_Kn			= "";	//氏名(フリガナ名)
$strSex				= "";	//性別
$strDepartment_Id	= "";	//上位グループID
$strSubject_Id		= "";	//下位グループID
$strYubin_No		= "";	//郵便番号
$strTel_no			= "";	//自宅電話番号
$strKeitai_no		= "";	//携帯電話番号
$strMailAddress		= "";	//携帯メールアドレス
$strPcMailAddress	= "";	//PCメールアドレス
$strAdmin			= false;
$intDataCount		= 0;

//***************************
//* メイン処理
//***************************

$Max_cd	= 0;

//個人情報を取得
$strSQL = "SELECT Max(syain_cd) as Max_cd " .
          "FROM syain_tbl ";
          
$objRecSet = pg_exec($strSQL);
$Max_cd = pg_result($objRecSet,0,"Max_cd");
if($objRecSet==false){
    echo("SQL実行に失敗しました(SELECT)");
    exit;
}

$Max_cd = "'" . ($Max_cd + 1) . "'";

//----------ランダム暗号----------------
$num = 1;
while ($num >= 1){
    $strArray = array(0,1,2,3,4,5,6,7,8,9,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z);

    for ($i = 0; $i < 5; $i++){
      $tmp_num = rand(0, 51);
      $strTmp = $strTmp . $strArray[$tmp_num];
    }
	
    $angou = $strTmp;
    $sql = "SELECT * FROM syain_tbl";
    $sql .= " WHERE angou_cd = '$angou'";
    $rtn = pg_exec($pg_con, $sql);
    if($rtn == false){
    	echo "SQLの実行に失敗しました。(#1)";
        exit;
  	}
  	$num = pg_numrows($rtn);
}

$angou_cd = "'" . $angou . "'";
//ユーザーID
$strUser_id = $user_id;
if ($strUser_id == ""){
	$strUser_id = "NULL";
	$strD_id = " ";
}else{
	$strD_id = $strUser_id;
	$strUser_id = "'" . $strUser_id . "'";
}
//パスワード
$strUser_Pass = $user_pass;
if ($strUser_Pass == ""){
	$strUser_Pass = "NULL";
}else{
	$strUser_Pass = "'" . $strUser_Pass . "'";
}

$strSei_Kj = "'" . JcodeConvert($sei_kj, 1, 1) . "'";
$strMei_Kj = "'" . JcodeConvert($mei_kj, 1, 1) . "'";
$strSei_Kn = "'" . JcodeConvert($sei_kn, 1, 1) . "'";
$strMei_Kn = "'" . JcodeConvert($mei_kn, 1, 1) . "'";

if ($sex == "t"){
	$strSex = "'true'";
}else{
	$strSex = "'false'";
}


//郵便1
if (($yubin_no1 == "")&&($yubin_no2 == "")){
	$strYubin_No = "NULL";
}else{
	$strYubin_No = "'" . $yubin_no1 . $yubin_no2 . "'";
}

//住所1
$strAddrPref = $address1;
if ($strAddrPref == ""){
	$strAddrPref = "NULL";
}else{
	$strAddrPref = "'" . JcodeConvert($strAddrPref, 1, 1) . "'";
}

//住所2
$strAddrCity = $address2;
if ($strAddrCity == ""){
	$strAddrCity = "NULL";
}else{
	$strAddrCity = "'" . JcodeConvert($strAddrCity, 1, 1) . "'";
}

//住所3
$strAddrBanti = $address3;
if ($strAddrBanti == ""){
	$strAddrBanti = "NULL";
}else{
	$strAddrBanti = "'" . JcodeConvert($strAddrBanti, 1, 1) . "'";
}

//住所4
$strAddrApart = $address4;
if ($strAddrApart == ""){
	$strAddrApart = "NULL";
}else{
	$strAddrApart = "'" . JcodeConvert($strAddrApart, 1, 1) . "'";
}

//グループID
$strGroup2_Id = $group2_id;
if ($strGroup2_Id == "Null"){
	$strGroup2_Id = "000";
}else{
	$strGroup2_Id = "'" . $strGroup2_Id . "'";
}

//自宅電話番号
$strTel_no = $tel_no1 . $tel_no2 . $tel_no3;
if ($strTel_no == ""){
	$strTel_no = "NULL";
}else{
	$strTel_no = "'" . $tel_no1 . "-" . $tel_no2 . "-" .$tel_no3 . "'";
}

//携帯電話番号
$strKeitai_no = $keitai_no1 . $keitai_no2 . $keitai_no3;
if ($strKeitai_no == ""){
	$strKeitai_no = "NULL";
}else{
	$strKeitai_no = "'" . $keitai_no1 . "-" . $keitai_no2 . "-" .$keitai_no3 . "'";
}

//携帯メールアドレス
$strMailAddress = $mail_address;
if ($strMailAddress == ""){
	$strMailAddress = "NULL";
}else{
	$strMailAddress = "'" . $strMailAddress . "'";
}

//PCメールアドレス
$strPcMailAddress = $pcmail_address;
if ($strPcMailAddress == ""){
	$strPcMailAddress = "NULL";
}else{
	$strPcMailAddress = "'" . $strPcMailAddress . "'";
}

$strSQL = "SELECT * FROM syain_tbl WHERE syain_id = " . $strUser_id;

$objRecSet = pg_exec($strSQL);
if($objRecSet==false){
    echo("SQL実行に失敗しました(INSERT)");
    exit;
}

$intDataCount = pg_numrows($objRecSet);

if ($intDataCount == 0){

	$strSQL = "INSERT INTO syain_tbl (" .
	          "syain_cd," .
	          "angou_cd," .
	          "syain_id," .
	          "password," .
	          "name_kj_sei," .
	          "name_kj_mei," .
	          "name_kn_sei," .
	          "name_kn_mei," .
	          "syugyo_type," .
	          "sex," .
	          "birthday," .
	          "nyusya_date," .
	          "mail_addr," .
	          "pc_mail_addr," .
	          "extension_no," .
	          "yubin_no," .
	          "addr_pref," .
	          "addr_city," .
	          "addr_banti," .
	          "addr_apart," .
	          "tel_no," .
	          "keitai_no," .
	          "del_flg," .
	          "disp_rank)" .
	          "VALUES (" .
	          $Max_cd . "," .
	          $angou_cd . ", " .
	          $strUser_id . ", " .
	          $strUser_Pass . ", " .
	          $strSei_Kj . ", " .
	          $strMei_Kj . ", " .
	          $strSei_Kn . ", " .
	          $strMei_Kn . ", " .
	          0 . ", " .
	          $strSex . ", " .
	          "''" . ", " .
	          "''" . ", " .
	          $strMailAddress . ", " .
	          $strPcMailAddress . ", " .
	          "''" . ", " .
	          $strYubin_No . ", " .
	          $strAddrPref . ", " .
	          $strAddrCity . ", " .
	          $strAddrBanti . ", " .
	          $strAddrApart . ", " .
	          $strTel_no . ", " .
	          $strKeitai_no . ", " .
	          "'true'" . ", " .
	          0 . ")";

	$objRecSet = pg_exec($strSQL);
 	if($objRecSet==false){
	    echo("SQL実行に失敗しました(INSERT)");
	    exit;
	}
	
//GROUP_INFO書込み
	if ($bumon_num==0){
		$strSQL = "INSERT INTO group_info (" .
    	          "syain_cd," .
    	          "group_id )" .
    			  "VALUES (" .
    	          $Max_cd . "," .
    	          "'" . $strpras . "')";
    	
    	$objRecSet = pg_exec($strSQL);
    	if($objRecSet==false){
    	    echo("SQL実行に失敗しました(INSERT)");
    	    exit;
    	}
	}else{
    	$strBumonArray=split("/",$strpras);
    	for ($i = 0 ; $i <= $bumon_num-1 ; $i++) {
    	
        	$strSQL = "INSERT INTO group_info (" .
        	          "syain_cd," .
        	          "group_id )" .
        			  "VALUES (" .
        	          $Max_cd . "," .
        	          "'" . $strBumonArray[$i] . "')";
        	
        	$objRecSet = pg_exec($strSQL);
        	if($objRecSet==false){
        	    echo("SQL実行に失敗しました(INSERT)");
        	    exit;
        	}
    	}
	}
}

	//メモ欄書き込み
	$strSQL="INSERT INTO syain_biko_tbl ( syain_cd,biko ) VALUES ".
			"(".$Max_cd . ","."'".$biko."')";
	$objRecSet = pg_exec($strSQL);
	if($objRecSet==false){
	    echo("SQL実行に失敗しました(INSERT)");
	    exit;
	}

?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML>
<HEAD>
<META http-equiv="Content-Type" content="text/html; charset=EUC-JP">
<META http-equiv="Content-Style-Type" content="text/css">
<CENTER>
<TITLE>登録結果</TITLE>
</HEAD>
<BODY bgcolor="White">
<TABLE border=1 bordercolor="#008080" width="544">
<TBODY>
  <!--<TR>
    <TD bgcolor="#FFCC99" Width="50%"><B><FONT size="2">ユーザーID</FONT></B></TD>
    <TD><FONT size="2"><?PHP  echo $strD_id ?></FONT></TD>
  </TR>-->
  <TR>
    <TD bgcolor="#FFCC99"><B><FONT size="2">氏名</FONT></B></TD>
    <TD><FONT size="2"><?PHP  echo $sei_kj ?> <?PHP  echo $mei_kj ?></FONT></TD>
  </TR>
<?PHP 
if ($intDataCount > 0){
?>
  <TR>
    <TD bgcolor="#FFCC99" ALIGN="CENTER" COLSPAN="2"><B><FONT color=#FF0000 size="2" >入力されたユーザーIDが既に存在しています</FONT></B></TD>
  </TR>
<?PHP 
}
else{
?>
  <TR>
    <TD bgcolor="#FFCC99" ALIGN="CENTER" COLSPAN="2"><B><FONT size="2">上記のユーザー情報を登録しました</FONT></B></TD>
  </TR>
<?PHP 
}
?>
</TBODY>
</TABLE>
<BR>
<BR>
<BR>
<TABLE border=0 cellspacing="0" cellpadding="3" width="544">
<TBODY>
  <TR>
    <TD ALIGN="CENTER">
    <FONT size="2"><A href="./user_ichiran.php">ユーザー情報一覧に戻る</A></FONT>
    </TD>
  </TR>
</TBODY>
</TABLE>
</BODY>
</CENTER>
</HTML>