#! /usr/bin/perl
#----------------------------------------------------------------------
# ヘッダー取り込み
#----------------------------------------------------------------------
use strict;
use IO::Socket;
use NKF;
require 'tyserv.pl';
#----------------------------------------------------------------------
# ワーク定義
#----------------------------------------------------------------------
my ($user, $passwd, $host, $port, $tran_status, $sts1, $sts2);
my (%input, $handle, $ret, $i, $cgipath);
my ($buf, @array, $key, $val);
#----------------------------------------------------------------------
# ワーク初期値設定
#----------------------------------------------------------------------
$tran_status = "OK";
#
# USER CODING START
#
$user = "user";
$passwd = "user";
$host = "localhost";
$port = 20000;
$cgipath = "http://myh.no-ip.org/~tyserv/cgi-bin/smp1.cgi";
#
# USER CODING END
#
#----------------------------------------------------------------------
# ソケットハンドル取得
#----------------------------------------------------------------------
$handle = IO::Socket::INET->new(Proto     => "tcp",
                                PeerAddr  => $host,
                                PeerPort  => $port);
if ($handle == 0){
    printf("can't connect to port $port on $host: $! \n");
    print "Content-type: text/html;charset=euc-jp\n\n";
    print "<html>\n";
    print "<head>\n";
    print "<title>ソケットハンドルの取得に失敗しました($!)。</title>\n";
    print "</head>\n";
    print "<body>\n";
    print "ソケットハンドルの取得に失敗しました($!)。\n";
    print "</body>\n";
    print "</head>\n";
    print "</html>\n";
    exit 1;
}
$handle->autoflush(1);              # so output gets there right away
#----------------------------------------------------------------------
# フォームの入力データ取得
#----------------------------------------------------------------------
$ENV{REQUEST_METHOD} =~ tr/a-z/A-Z/;
if ($ENV{REQUEST_METHOD} eq "POST"){
    read(STDIN, $buf, $ENV{CONTENT_LENGTH});
}else{
    $buf = $ENV{QUERY_STRING};
}
@array = split(/&/, $buf);
foreach $i (@array){
  ($key, $val) = split(/=/, $i);
  $val =~ tr/+/ /;
  $val =~ s/%([0-9a-zA-Z][0-9a-zA-Z])/pack("C",hex($1))/eg;
  $val =~ s/\n$//eg;
  $input{$key} = nkf('-e', $val);
  $input{$key} =~ s/&/&amp;/g;
  $input{$key} =~ s/</&lt;/g;
  $input{$key} =~ s/>/&gt;/g;
  $input{$key} =~ s/"/&quot;/g;
  $input{$key} =~ s/'/&#39;/g;
}
#----------------------------------------------------------------------
# トランザクション開始
#----------------------------------------------------------------------
if ($input{select} eq "init" ||
    $input{select} eq "get"){
    ($sts1, $sts2) = &ty_start_tranm($handle, $user, $passwd);
}else{
    ($sts1, $sts2) = &ty_start_tran($handle, $user, $passwd);
}
if ($sts1 eq "NG"){
    print "Content-type: text/html;charset=euc-jp\n\n";
    print "<html>\n";
    print "<head>\n";
    print "<title>トランザクション開始に失敗しました($sts1, $sts2)。</title>\n";
    print "</head>\n";
    print "<body>\n";
    print "トランザクション開始に失敗しました($sts1, $sts2)。\n";
    print "</body>\n";
    print "</head>\n";
    print "</html>\n";
    exit 1;
}
#----------------------------------------------------------------------
# 主処理開始
#----------------------------------------------------------------------
if ($input{select} eq "init"){
    sub_init(\%input);
}elsif ($input{select} eq "get"){
    sub_get(\%input, $handle);
}elsif ($input{select} eq "update"){
    $tran_status = sub_update(\%input, $handle);
}elsif ($input{select} eq "put"){
    $tran_status = sub_put(\%input, $handle);
}elsif ($input{select} eq "delete"){
    $tran_status = sub_delete(\%input, $handle);
}
#----------------------------------------------------------------------
# トランザクション終了
#----------------------------------------------------------------------
if ($tran_status eq "OK"){
    ($sts1, $sts2) = &ty_end_tran($handle);
}else{
    ($sts1, $sts2) = &ty_abort_tran($handle);
}
#----------------------------------------------------------------------
# 終了
#----------------------------------------------------------------------
exit 0;
#
#
#
#----------------------------------------------------------------------
# 検索条件入力画面
#----------------------------------------------------------------------
sub sub_init(){
    my ($input_ref) = @_;
#
# USER CODING START
#
    print "Content-type: text/html;charset=euc-jp\n\n";
    print "<html>\n";
    print "<head>\n";
    print "<title>検索条件入力</title>\n";
    print "</head>\n";
    print "<body>\n";
    print "検索条件入力\n";
    print "<form action=\"$cgipath\" method=\"POST\">\n";
    print "<input type=\"hidden\" name=\"from\" value=\"init\">\n";
    print "<input type=\"hidden\" name=\"current\" value=\"1\">\n";
    print "<input type=\"hidden\" name=\"bias\" value=\"0\">\n";
#
    print "<input type=\"radio\" name=\"select\" value=\"init\" disabled>条件\n";
    print "<input type=\"radio\" name=\"select\" value=\"get\" checked>検索\n";
    print "<input type=\"radio\" name=\"select\" value=\"put\">入力\n";
    print "<input type=\"radio\" name=\"select\" value=\"update\">更新\n";
    print "<input type=\"radio\" name=\"select\" value=\"delete\">削除\n";
    print "<br>\n";
    print "<input type=\"radio\" name=\"bias\" value=\"-1\" disabled>前\n";
    print "<input type=\"radio\" name=\"bias\" value=\"0\" disabled>現在\n";
    print "<input type=\"radio\" name=\"bias\" value=\"1\" disabled>次\n";
    print "<br>\n";
    print "<input type=\"submit\" name=\"enter\" value=\"enter\">\n";
    print "<input type=\"reset\" name=\"reset\" value=\"reset\">\n";
    print "<br>\n";
    print "<hr>\n";
#
# 検索キー項目選択&入力
#
    print "id: <input type=\"text\" name=\"cond_id\" size=\"4\" maxlength=\"4\" value=\"\">\n";
    print "<br>\n";
    print "name: <input type=\"text\" name=\"cond_name\" size=\"20\" maxlength=\"20\" value=\"\">\n";
    print "<br>\n";
#
    print "</form>\n";
    print "</body>\n";
    print "</html>\n";
#
# USER CODING END
#
}
#----------------------------------------------------------------------
# 検索画面
#----------------------------------------------------------------------
sub sub_get(){
    my ($input_ref, $handle) = @_;
#
# USER CODING START
#
    my ($sts1, $sts2, %rec, $i, $bias_prev, $bias_current, $bias_next);

#----------------------------------------------------------------------
# 読み取り
#----------------------------------------------------------------------
    if ($$input_ref{from} ne "get"){
        $$input_ref{bias} = 0;
    }
    $i = 0;
    %rec = ();
    if ($$input_ref{cond_name} gt ""){
        ($sts1, $sts2, %rec) = &ty_get($handle, "smp1", "skey1", "ge", [$$input_ref{cond_name}]);
    }else{
        ($sts1, $sts2, %rec) = &ty_get($handle, "smp1", "pkey", "ge", [$$input_ref{cond_id}]);
    }
    $i++;
    while ($i < ($$input_ref{current} + $$input_ref{bias}) && $sts1 eq "OK"){
        %rec = ();
        if ($$input_ref{cond_name} gt ""){
            ($sts1, $sts2, %rec) = &ty_getnext($handle, "smp1", "skey1");
        }else{
            ($sts1, $sts2, %rec) = &ty_getnext($handle, "smp1", "pkey");
        }
        $i++;
    }
#----------------------------------------------------------------------
# フォーム作成
#----------------------------------------------------------------------
#
    if ($$input_ref{bias} == -1){
        $bias_prev = "checked";
        $bias_current = "";
        $bias_next = "";
    }elsif ($$input_ref{bias} == 0){
        $bias_prev = "";
        $bias_current = "checked";
        $bias_next = "";
    }elsif ($$input_ref{bias} == 1){
        $bias_prev = "";
        $bias_current = "";
        $bias_next = "checked";
    }
#
    print "Content-type: text/html;charset=euc-jp\n\n";
    print "<html>\n";
    print "<head>\n";
    print "<title>検索処理</title>\n";
    print "</head>\n";
    print "<body>\n";
    print "検索処理\n";
    print "<form action=\"$cgipath\" method=\"POST\">\n";
    print "<input type=\"hidden\" name=\"from\" value=\"get\">\n";
    print "<input type=\"hidden\" name=\"current\" value=\"$i\">\n";
    print "<input type=\"hidden\" name=\"cond_id\" value=\"$$input_ref{cond_id}\">\n";
    print "<input type=\"hidden\" name=\"cond_name\" value=\"$$input_ref{cond_name}\">\n";
#
    print "<input type=\"radio\" name=\"select\" value=\"init\">条件\n";
    print "<input type=\"radio\" name=\"select\" value=\"get\" checked>検索\n";
    print "<input type=\"radio\" name=\"select\" value=\"put\">入力\n";
    print "<input type=\"radio\" name=\"select\" value=\"update\">更新\n";
    print "<input type=\"radio\" name=\"select\" value=\"delete\">削除\n";
    print "<br>\n";
    print "<input type=\"radio\" name=\"bias\" value=\"-1\" $bias_prev>前\n";
    print "<input type=\"radio\" name=\"bias\" value=\"0\" $bias_current>現在\n";
    print "<input type=\"radio\" name=\"bias\" value=\"1\" $bias_next>次\n";
    print "<br>\n";
    print "<input type=\"submit\" name=\"enter\" value=\"enter\">\n";
    print "<input type=\"reset\" name=\"reset\" value=\"reset\">\n";
    print "<br>\n";
    print "<hr>\n";
#
# 画面構成定義(全項目 readonly)
#
    print "id: <input type=\"text\" name=\"id\" size=\"4\" maxlength=\"4\" value=\"$rec{id}\" readonly>\n";
    print "<br>\n";
    print "name: <input type=\"text\" name=\"name\" size=\"20\" maxlength=\"20\" value=\"$rec{name}\" readonly>\n";
    print "<br>\n";
    print "salary: <input type=\"text\" name=\"salary\" size=\"8\" maxlength=\"8\" value=\"$rec{salary}\" readonly>\n";
    print "<br>\n";
#
    print "</form>\n";
    if ($sts1 eq "NG"){
        print "検索失敗しました($sts1, $sts2)。";
    }
    print "</body>\n";
    print "</html>\n";
#
# USER CODING END
#
}
#----------------------------------------------------------------------
# 入力画面
#----------------------------------------------------------------------
sub sub_put(){
    my ($input_ref, $handle) = @_;
#
# USER CODING START
#
    my ($sts1, $sts2, %rec, $i, $bias_prev, $bias_current, $bias_next, $tran_status1, $tran_status2);

    $tran_status1 = "OK";
    $tran_status2 = "";
#----------------------------------------------------------------------
# 更新
#----------------------------------------------------------------------
    if ($$input_ref{from} eq "put"){
        %rec = ();
        $rec{id} = $$input_ref{id};
        $rec{name} = $$input_ref{name};
        $rec{salary} = $$input_ref{salary};
        ($sts1, $sts2) = &ty_put($handle, "smp1", \%rec);
        $tran_status1 = $sts1;
        $tran_status2 = $sts2;
    }
#----------------------------------------------------------------------
# 読み取り
#----------------------------------------------------------------------
    if ($$input_ref{from} ne "put"){
        $$input_ref{bias} = 0;
    }
    $i = 0;
    %rec = ();
    if ($$input_ref{cond_name} gt ""){
        ($sts1, $sts2, %rec) = &ty_get($handle, "smp1", "skey1", "ge", [$$input_ref{cond_name}]);
    }else{
        ($sts1, $sts2, %rec) = &ty_get($handle, "smp1", "pkey", "ge", [$$input_ref{cond_id}]);
    }
    $i++;
    while ($i < ($$input_ref{current} + $$input_ref{bias}) && $sts1 eq "OK"){
        %rec = ();
        if ($$input_ref{cond_name} gt ""){
            ($sts1, $sts2, %rec) = &ty_getnext($handle, "smp1", "skey1");
        }else{
            ($sts1, $sts2, %rec) = &ty_getnext($handle, "smp1", "pkey");
        }
        $i++;
    }
#----------------------------------------------------------------------
# フォーム作成
#----------------------------------------------------------------------
#
    if ($$input_ref{bias} == -1){
        $bias_prev = "checked";
        $bias_current = "";
        $bias_next = "";
    }elsif ($$input_ref{bias} == 0){
        $bias_prev = "";
        $bias_current = "checked";
        $bias_next = "";
    }elsif ($$input_ref{bias} == 1){
        $bias_prev = "";
        $bias_current = "";
        $bias_next = "checked";
    }
#
    print "Content-type: text/html;charset=euc-jp\n\n";
    print "<html>\n";
    print "<head>\n";
    print "<title>入力処理</title>\n";
    print "</head>\n";
    print "<body>\n";
    print "入力処理\n";
    print "<form action=\"$cgipath\" method=\"POST\">\n";
    print "<input type=\"hidden\" name=\"from\" value=\"put\">\n";
    print "<input type=\"hidden\" name=\"current\" value=\"$i\">\n";
    print "<input type=\"hidden\" name=\"cond_id\" value=\"$$input_ref{cond_id}\">\n";
    print "<input type=\"hidden\" name=\"cond_name\" value=\"$$input_ref{cond_name}\">\n";
#
    print "<input type=\"radio\" name=\"select\" value=\"init\">条件\n";
    print "<input type=\"radio\" name=\"select\" value=\"get\">検索\n";
    print "<input type=\"radio\" name=\"select\" value=\"put\" checked>入力\n";
    print "<input type=\"radio\" name=\"select\" value=\"update\">更新\n";
    print "<input type=\"radio\" name=\"select\" value=\"delete\">削除\n";
    print "<br>\n";
    print "<input type=\"radio\" name=\"bias\" value=\"-1\" $bias_prev>前\n";
    print "<input type=\"radio\" name=\"bias\" value=\"0\" $bias_current>現在\n";
    print "<input type=\"radio\" name=\"bias\" value=\"1\" $bias_next>次\n";
    print "<br>\n";
    print "<input type=\"submit\" name=\"enter\" value=\"enter\">\n";
    print "<input type=\"reset\" name=\"reset\" value=\"reset\">\n";
    print "<br>\n";
    print "<hr>\n";
#
# 画面構成定義(全項目入力可)
#
    print "id: <input type=\"text\" name=\"id\" size=\"4\" maxlength=\"4\" value=\"$rec{id}\">\n";
    print "<br>\n";
    print "name: <input type=\"text\" name=\"name\" size=\"20\" maxlength=\"20\" value=\"$rec{name}\">\n";
    print "<br>\n";
    print "salary: <input type=\"text\" name=\"salary\" size=\"8\" maxlength=\"8\" value=\"$rec{salary}\">\n";
    print "<br>\n";
#
    print "</form>\n";
    if ($$input_ref{from} eq "put"){
        if ($tran_status1 eq "OK"){
            print "更新完了しました。";
        }else{
            print "更新失敗しました($tran_status1, $tran_status2)。";
        }
    }
    if ($sts1 eq "NG"){
        print "検索失敗しました($sts1, $sts2)。";
    }
    print "</body>\n";
    print "</html>\n";
#
# USER CODING END
#
    return $tran_status1;
}
#----------------------------------------------------------------------
# 更新画面
#----------------------------------------------------------------------
sub sub_update(){
    my ($input_ref, $handle) = @_;
#
# USER CODING START
#
    my ($sts1, $sts2, %rec, $i, $bias_prev, $bias_current, $bias_next, $bias_get, $tran_status1, $tran_status2);

    $tran_status1 = "OK";
    $tran_status2 = "";
#----------------------------------------------------------------------
# 更新
#----------------------------------------------------------------------
    if ($$input_ref{from} eq "update"){
        %rec = ();
        ($sts1, $sts2, %rec) = &ty_get($handle, "smp1", "pkey", "eq", [$$input_ref{id}]);
        if ($sts1 eq "OK"){
            $rec{id} = $$input_ref{id};
            $rec{name} = $$input_ref{name};
            $rec{salary} = $$input_ref{salary};
            ($sts1, $sts2) = &ty_update($handle, "smp1", [$rec{id}], \%rec);
        }
        $tran_status1 = $sts1;
        $tran_status2 = $sts2;
    }
#----------------------------------------------------------------------
# 読み取り
#----------------------------------------------------------------------
    if ($$input_ref{from} ne "update"){
        $$input_ref{bias} = 0;
    }
    $i = 0;
    %rec = ();
    if ($$input_ref{cond_name} gt ""){
        ($sts1, $sts2, %rec) = &ty_get($handle, "smp1", "skey1", "ge", [$$input_ref{cond_name}]);
    }else{
        ($sts1, $sts2, %rec) = &ty_get($handle, "smp1", "pkey", "ge", [$$input_ref{cond_id}]);
    }
    $i++;
    while ($i < ($$input_ref{current} + $$input_ref{bias}) && $sts1 eq "OK"){
        %rec = ();
        if ($$input_ref{cond_name} gt ""){
            ($sts1, $sts2, %rec) = &ty_getnext($handle, "smp1", "skey1");
        }else{
            ($sts1, $sts2, %rec) = &ty_getnext($handle, "smp1", "pkey");
        }
        $i++;
    }
#----------------------------------------------------------------------
# フォーム作成
#----------------------------------------------------------------------
#
    if ($$input_ref{bias} == -1){
        $bias_prev = "checked";
        $bias_current = "";
        $bias_next = "";
    }elsif ($$input_ref{bias} == 0){
        $bias_prev = "";
        $bias_current = "checked";
        $bias_next = "";
    }elsif ($$input_ref{bias} == 1){
        $bias_prev = "";
        $bias_current = "";
        $bias_next = "checked";
    }
#
    print "Content-type: text/html;charset=euc-jp\n\n";
    print "<html>\n";
    print "<head>\n";
    print "<title>更新処理</title>\n";
    print "</head>\n";
    print "<body>\n";
    print "更新処理\n";
    print "<form action=\"$cgipath\" method=\"POST\">\n";
    print "<input type=\"hidden\" name=\"from\" value=\"update\">\n";
    print "<input type=\"hidden\" name=\"current\" value=\"$i\">\n";
    print "<input type=\"hidden\" name=\"cond_id\" value=\"$$input_ref{cond_id}\">\n";
    print "<input type=\"hidden\" name=\"cond_name\" value=\"$$input_ref{cond_name}\">\n";
#
    print "<input type=\"radio\" name=\"select\" value=\"init\">条件\n";
    print "<input type=\"radio\" name=\"select\" value=\"get\">検索\n";
    print "<input type=\"radio\" name=\"select\" value=\"put\">入力\n";
    print "<input type=\"radio\" name=\"select\" value=\"update\" checked>更新\n";
    print "<input type=\"radio\" name=\"select\" value=\"delete\">削除\n";
    print "<br>\n";
    print "<input type=\"radio\" name=\"bias\" value=\"-1\" $bias_prev>前\n";
    print "<input type=\"radio\" name=\"bias\" value=\"0\" $bias_current>現在\n";
    print "<input type=\"radio\" name=\"bias\" value=\"1\" $bias_next>次\n";
    print "<br>\n";
    print "<input type=\"submit\" name=\"enter\" value=\"enter\">\n";
    print "<input type=\"reset\" name=\"reset\" value=\"reset\">\n";
    print "<br>\n";
    print "<hr>\n";
#
# 画面構成定義(主キー項目のみreadonly)
#
    print "id: <input type=\"text\" name=\"id\" size=\"4\" maxlength=\"4\" value=\"$rec{id}\" readonly>\n";
    print "<br>\n";
    print "name: <input type=\"text\" name=\"name\" size=\"20\" maxlength=\"20\" value=\"$rec{name}\">\n";
    print "<br>\n";
    print "salary: <input type=\"text\" name=\"salary\" size=\"8\" maxlength=\"8\" value=\"$rec{salary}\">\n";
    print "<br>\n";
#
    print "</form>\n";
    if ($$input_ref{from} eq "update"){
        if ($tran_status1 eq "OK"){
            print "更新完了しました。";
        }else{
            print "更新失敗しました($tran_status1, $tran_status2)。";
        }
    }
    if ($sts1 eq "NG"){
        print "検索失敗しました($sts1, $sts2)。";
    }
    print "</body>\n";
    print "</html>\n";
#
# USER CODING END
#
    return $tran_status1;
}
#----------------------------------------------------------------------
# 削除画面
#----------------------------------------------------------------------
sub sub_delete(){
    my ($input_ref, $handle) = @_;
#
# USER CODING START
#
    my ($sts1, $sts2, %rec, $i, $bias_prev, $bias_current, $bias_next, $tran_status1, $tran_status2);

    $tran_status1 = "OK";
    $tran_status2 = "";
#----------------------------------------------------------------------
# 更新
#----------------------------------------------------------------------
    if ($$input_ref{from} eq "delete"){
        ($sts1, $sts2) = &ty_delete($handle, "smp1", [$$input_ref{id}]);
        $tran_status1 = $sts1;
        $tran_status2 = $sts2;
    }
#----------------------------------------------------------------------
# 読み取り
#----------------------------------------------------------------------
    if ($$input_ref{from} ne "delete"){
        $$input_ref{bias} = 0;
    }
    $i = 0;
    %rec = ();
    if ($$input_ref{cond_name} gt ""){
        ($sts1, $sts2, %rec) = &ty_get($handle, "smp1", "skey1", "ge", [$$input_ref{cond_name}]);
    }else{
        ($sts1, $sts2, %rec) = &ty_get($handle, "smp1", "pkey", "ge", [$$input_ref{cond_id}]);
    }
    $i++;
    while ($i < ($$input_ref{current} + $$input_ref{bias}) && $sts1 eq "OK"){
        %rec = ();
        if ($$input_ref{cond_name} gt ""){
            ($sts1, $sts2, %rec) = &ty_getnext($handle, "smp1", "skey1");
        }else{
            ($sts1, $sts2, %rec) = &ty_getnext($handle, "smp1", "pkey");
        }
        $i++;
    }
#----------------------------------------------------------------------
# フォーム作成
#----------------------------------------------------------------------
#
    if ($$input_ref{bias} == -1){
        $bias_prev = "checked";
        $bias_current = "";
        $bias_next = "";
    }elsif ($$input_ref{bias} == 0){
        $bias_prev = "";
        $bias_current = "checked";
        $bias_next = "";
    }elsif ($$input_ref{bias} == 1){
        $bias_prev = "";
        $bias_current = "";
        $bias_next = "checked";
    }
#
    print "Content-type: text/html;charset=euc-jp\n\n";
    print "<html>\n";
    print "<head>\n";
    print "<title>削除処理</title>\n";
    print "</head>\n";
    print "<body>\n";
    print "削除処理\n";
    print "<form action=\"$cgipath\" method=\"POST\">\n";
    print "<input type=\"hidden\" name=\"from\" value=\"delete\">\n";
    print "<input type=\"hidden\" name=\"current\" value=\"$i\">\n";
    print "<input type=\"hidden\" name=\"cond_id\" value=\"$$input_ref{cond_id}\">\n";
    print "<input type=\"hidden\" name=\"cond_name\" value=\"$$input_ref{cond_name}\">\n";
#
    print "<input type=\"radio\" name=\"select\" value=\"init\">条件\n";
    print "<input type=\"radio\" name=\"select\" value=\"get\">検索\n";
    print "<input type=\"radio\" name=\"select\" value=\"put\">入力\n";
    print "<input type=\"radio\" name=\"select\" value=\"update\">更新\n";
    print "<input type=\"radio\" name=\"select\" value=\"delete\" checked>削除\n";
    print "<br>\n";
    print "<input type=\"radio\" name=\"bias\" value=\"-1\" $bias_prev>前\n";
    print "<input type=\"radio\" name=\"bias\" value=\"0\" $bias_current>現在\n";
    print "<input type=\"radio\" name=\"bias\" value=\"1\" $bias_next>次\n";
    print "<br>\n";
    print "<input type=\"submit\" name=\"enter\" value=\"enter\">\n";
    print "<input type=\"reset\" name=\"reset\" value=\"reset\">\n";
    print "<br>\n";
    print "<hr>\n";
#
# 画面構成定義(全項目readonly)
#
    print "id: <input type=\"text\" name=\"id\" size=\"4\" maxlength=\"4\" value=\"$rec{id}\" readonly>\n";
    print "<br>\n";
    print "name: <input type=\"text\" name=\"name\" size=\"20\" maxlength=\"20\" value=\"$rec{name}\" readonly>\n";
    print "<br>\n";
    print "salary: <input type=\"text\" name=\"salary\" size=\"8\" maxlength=\"8\" value=\"$rec{salary}\" readonly>\n";
    print "<br>\n";
#
    print "</form>\n";
    if ($$input_ref{from} eq "delete"){
        if ($tran_status1 eq "OK"){
            print "更新完了しました。";
        }else{
            print "更新失敗しました($tran_status1, $tran_status2)。";
        }
    }
    if ($sts1 eq "NG"){
        print "検索失敗しました($sts1, $sts2)。";
    }
    print "</body>\n";
    print "</html>\n";
#
# USER CODING END
#
    return $tran_status1;
}

#MEMO_#----------------------------------------------------------------------
#MEMO_# トランザクション(更新)開始
#MEMO_#----------------------------------------------------------------------
#MEMO_($sts1, $sts2) = &ty_start_tran($handle, $user, $passwd);
#MEMO_#----------------------------------------------------------------------
#MEMO_# 削除
#MEMO_#----------------------------------------------------------------------
#MEMO_($sts1, $sts2) = &ty_delete($handle, "smp1", ["0001"]);
#MEMO_#----------------------------------------------------------------------
#MEMO_# 挿入
#MEMO_#----------------------------------------------------------------------
#MEMO_%rec = ();
#MEMO_$rec{id} = "0001";
#MEMO_$rec{name} = "Masao Sato";
#MEMO_$rec{salary} = "0500000";
#MEMO_($sts1, $sts2) = &ty_put($handle, "smp1", \%rec);
#MEMO_#----------------------------------------------------------------------
#MEMO_# 読み取り
#MEMO_#----------------------------------------------------------------------
#MEMO_%rec = ();
#MEMO_($sts1, $sts2, %rec) = &ty_get($handle, "smp1", "pkey", "eq", ["0001"]);
#MEMO_#----------------------------------------------------------------------
#MEMO_# 次レコード読み取り
#MEMO_#----------------------------------------------------------------------
#MEMO_%rec = ();
#MEMO_($sts1, $sts2, %rec) = &ty_getnext($handle, "smp1", "pkey");
#MEMO_#----------------------------------------------------------------------
#MEMO_# 更新
#MEMO_#----------------------------------------------------------------------
#MEMO_%rec = ();
#MEMO_$rec{id} = "0001";
#MEMO_($sts1, $sts2, %rec) = &ty_get($handle, "smp1", "pkey", "eq", [$rec{id}]);
#MEMO_$rec{salary} *= 10;
#MEMO_($sts1, $sts2) = &ty_update($handle, "smp1", [$rec{id}], \%rec);
#MEMO_#----------------------------------------------------------------------
#MEMO_# コミット
#MEMO_#----------------------------------------------------------------------
#MEMO_($sts1, $sts2) = &ty_commit($handle);
#MEMO_#----------------------------------------------------------------------
#MEMO_# ロールバック
#MEMO_#----------------------------------------------------------------------
#MEMO_($sts1, $sts2) = &ty_rollback($handle);
#MEMO_#----------------------------------------------------------------------
#MEMO_# トランザクション(異常)終了
#MEMO_#----------------------------------------------------------------------
#MEMO_($sts1, $sts2) = &ty_abort_tran($handle);
#MEMO_#----------------------------------------------------------------------
#MEMO_# トランザクション(正常)終了
#MEMO_#----------------------------------------------------------------------
#MEMO_($sts1, $sts2) = &ty_end_tran($handle);