CGI プログラム10

戻る

# mscenq1_c.pl==>(mscenq1.plのテストプログラム) use strict; use DBI; use CGI qw/:standard/; use HTML::Template; my(%t,$n,$n1,@loop1,@loop2); # データベースに連結 $t{dsn} = "DBI:mysql:host=localhost;database=cookbook"; $t{dbh} = DBI->connect($t{dsn}, "cbuser", "cbpass") or die "Cannot connect to server\n"; $t{dbh}->do("SET NAMES utf8"); if(!$t{dbh}){ print "SQL read ERROR!\n"; exit; } # enq1テーブルのourrefを読む #@loop = (); # initialize an array to hold your loop $t{enq1_maxid} = $t{dbh}->selectrow_array("select max(id) from enq1"); @{ $t{list} } = $t{dbh}->selectrow_array("select time,ourref,owner,ownerno,hullnoid,name1id, type1id, maker1id, dwg1id,partsid,NUid,memo from enq1 where id = $t{enq1_maxid}"); $t{dbh}->disconnect; $t{owner1_id} = $t{list}[2]; $t{owner1} = $t{dbh}->selectrow_array("select company from owners where id = $t{owner1_id}"); $t{hullnoid1} = $t{list}[4]; $t{hullno1} = $t{dbh}->selectrow_array("select HULL_NO from hull_no where id = $t{hullnoid1}"); $t{template} = HTML::Template->new(filename => 'mscenq1_c.htm'); $t{template}->param(pro => "mscenq1_c.pl"); $t{template}->param(enq1_id => $t{enq1_maxid}); $t{template}->param(time1 => $t{list}[0]); $t{template}->param(ourref1 => $t{list}[1]); $t{template}->param(owner1 => $t{owner1}); $t{template}->param(ownerno1 => $t{list}[3]); $t{template}->param(hullno1 => $t{hullno1}); $t{name1id} = $t{list}[5]; # name1id $t{type1id} = $t{list}[6]; # type1id $t{maker1id} = $t{list}[7]; # maker1id $t{dwg1id} = $t{list}[8]; # dwg1id @loop1 = (); if ( $t{name1id} != 0 ) { @{ $t{name1id_list} } = split(/==/,$t{name1id}); @{ $t{type1id_list} } = split(/==/,$t{type1id}); @{ $t{maker1id_list} } = split(/==/,$t{maker1id}); @{ $t{dwg1id_list} } = split(/==/,$t{dwg1id}); for $n ( 0 .. $#{ $t{name1id_list} } ) { $t{name1id1} = $t{name1id_list}[$n]; $t{type1id1} = $t{type1id_list}[$n]; $t{maker1id1} = $t{maker1id_list}[$n]; $t{dwg1id1} = $t{dwg1id_list}[$n]; $t{name1} = $t{dbh}->selectrow_array("select name from main_name1 where id = $t{name1id1}"); $t{type1} = $t{dbh}->selectrow_array("select name from main_type1 where id = $t{type1id1}"); $t{maker1} = $t{dbh}->selectrow_array("select name from main_maker1 where id = $t{maker1id1}"); $t{dwg1} = $t{dbh}->selectrow_array("select name from main_dwg1 where id = $t{dwg1id1}"); my %row = ( name1 => $t{name1}, type1 => $t{type1}, maker1 => $t{maker1}, dwg1 => $t{dwg1} ); # put this row into the loop by reference push(@loop1, \%row); } } $t{template}->param(LOOP1 => \@loop1); $t{partsid} = $t{list}[9]; # partsid $t{NUid} = $t{list}[10]; # NUid @loop2 = (); @{ $t{partsid_list0} } = split(/==/,$t{partsid}); @{ $t{NUid_list0} } = split(/==/,$t{NUid}); for $n (0 .. $#{ $t{partsid_list0} } ) { $t{p_list1} = $t{partsid_list0}[$n]; $t{N_list1} = $t{NUid_list0}[$n]; @{ $t{partsid_list} } = split(/=/,$t{p_list1}); @{ $t{NUid_list} } = split(/=/,$t{N_list1}); for $n1 ( 0 .. $#{ $t{partsid_list} } ) { $t{partsid1} = $t{partsid_list}[$n1]; $t{NUid1} = $t{NUid_list}[$n1]; @{ $t{parts} } = $t{dbh}->selectrow_array("select name, code from parts1 where id = $t{partsid1}"); $t{NU1} = $t{dbh}->selectrow_array("select parts_Unit from parts_nu where id = $t{NUid1}"); my %row = ( parts_list => $t{p_list1}, parts_name => $t{parts}[0], parts_code => $t{parts}[1], NU1 => $t{NU1} ); # put this row into the loop by reference push(@loop2, \%row); } } $t{template}->param(LOOP2 => \@loop2); $t{memo} = $t{list}[11]; # memo $t{template}->param(memo => $t{memo}); print $t{template}->output; 1; ------------------------------------------------------------------------------ <center><h2>enq1(From 船主)</h2></center> <a href="http://localhost/index.html">http://localhost/index.html</a><br> <hr color="#003366"> 目的:船主からのENQ情報をデータベースに入力する。<br> mode:mscenq1;table:enq1;Perl:<TMPL_VAR NAME="pro"> <hr color="#003366"> <h3>ENQ_ID==><TMPL_VAR NAME="enq1_id"></h3> <hr color="#003366"> <h3>TIME==><TMPL_VAR NAME="time1"></h3> <hr color="#003366"> <h3>OURREF==><TMPL_VAR NAME="ourref1"></h3> <hr color="#003366"> <h3>船主==><TMPL_VAR NAME="owner1"></h3> <form action="" method="post"> <input type=text size=50 name=word1 value=""> <input type="submit" value="船主を検索"><p> <input type="hidden" name="table" value="owners"> <input type="hidden" name="tmpl" value="mscsearch"> <input type="hidden" name="enq1_id" value="<TMPL_VAR NAME="enq1_id">"> <input type="hidden" name="rm" value="modesearch"> </form> 船主データが存在しない場合,データベース管理=>船主データ(owners)=>船主テーブルの項目を追加 <hr color="#003366"> <h3>船主ENQ番号==><TMPL_VAR NAME="ownerno1"></h3> <form action="" method="post"> <input type=text size=50 name="owner_enq" value=""> <input type="submit" value="船主ENQ番号を入力"><p> <input type="hidden" name="table" value="enq1"> <input type="hidden" name="tmpl" value="mscread"> <input type="hidden" name="tables" value="owners==hull_no==enq1"> <input type="hidden" name="enq1" value=<TMPL_VAR NAME="enq1">> <input type="hidden" name="owners" value=<TMPL_VAR NAME="owners">> <input type="hidden" name="hull_no" value=<TMPL_VAR NAME="hull_no">> <input type="hidden" name="rm" value="moderead"> </form> <hr color="#003366"> <h3>HULL_NO==><TMPL_VAR NAME="hullno1"></h3> <form action="" method="post"> <input type=text size=50 name=word1 value=""> <input type="submit" value="HULLNOを検索"><p> <input type="hidden" name="table" value="hull_no"> <input type="hidden" name="tmpl" value="mscsearch"> <input type="hidden" name="tables" value="owners==hull_no"> <input type="hidden" name="owners" value=<TMPL_VAR NAME="owners">> <input type="hidden" name="hull_no" value=<TMPL_VAR NAME="hull_no">> <input type="hidden" name="rm" value="modesearch"> </form> <hr color="#003366"> <h3>主機名(main_name1),主機タイプ(main_type1),主機メーカー(main_maker1),図面番号(main_dwg1)</h3> <TMPL_LOOP NAME="LOOP1"> <h3><TMPL_VAR NAME="name1">,<TMPL_VAR NAME="type1">,<TMPL_VAR NAME="maker1">,<TMPL_VAR NAME="dwg1"></h3> </TMPL_LOOP> <hr color="#003366"> <h3>パーツ<br> name,code,unit</h3> <TMPL_LOOP NAME="LOOP2"> <h4><TMPL_VAR NAME="parts_list">,<TMPL_VAR NAME="parts_name">,<TMPL_VAR NAME="parts_code">,<TMPL_VAR NAME="NU1"></h4> </TMPL_LOOP> <hr color="#003366"> <h3>メモ(memo)==><TMPL_VAR NAME="memo"></h3> <hr color="#003366"> <form action="" method="post"> <input type="submit" value="enq1(From 船主)作成開始へ戻る"><p> <input type="hidden" name="rm" value="modeenq1_start"> </form> </form>
戻る