#!/usr/bin/perl #┌──────────────────────── #│ mart_admin.cgi - 2004/01/14 #│ Copyright (c) KentWeb #└──────────────────────── # 外部ファイル取り込み require './jcode.pl'; require './mart_init.cgi'; # 基本処理定義 &decode(1); if ($in{'pass'} eq "") { &enter; } elsif ($in{'pass'} ne $pass) { &error("パスワードが違います"); } &admin; #------------------------------------------------- # 管理モード #------------------------------------------------- sub admin { local($i,$next,$back,$code,$name,$price,$intax,$plus1,$plus2,@tax); # 新規フォーム if ($in{'job'} eq "new") { &new_form; # 新規登録 } elsif ($in{'job'} eq "new2") { $in{'code'} =~ s/:/:/g; $in{'code'} =~ s/;/;/g; $in{'name'} =~ s/:/:/g; $in{'name'} =~ s/;/;/g; if ($in{'code'} eq "") { &error("商品コードが未入力です"); } if ($in{'name'} eq "") { &error("商品名が未入力です"); } if ($in{'price'} eq "") { &error("商品単価が未入力です"); } if ($in{'price'} =~ /\D/) { &error("商品単価は半角数字のみで入力してください"); } if ($in{'plus2'} ne "" && $in{'plus2'} =~ /\D/) { &error("付加金額は半角数字のみで入力してください"); } if (($in{'plus1'} eq "" && $in{'plus2'} ne "") || ($in{'plus1'} ne "" && $in{'plus2'} eq "")) { &error("名称と金額は双方共に入力してください"); } if ($stock) { if ($in{'stock'} eq "") { &error("在庫数を指定してください"); } if ($in{'stock'} =~ /\D/) { &error("在庫数に半角数字以外の文字が入力されています"); } } $f=0; open(IN,"$datfile") || &error("Open Error: $datfile"); while (<IN>) { ($code) = split(/<>/); if ($in{'code'} eq $code) { $f++; last; } } close(IN); if ($f) { &error("商品コード $in{'code'} は登録済です"); } # 登録データ更新 open(OUT,">>$datfile") || &error("Write Error: $datfile"); print OUT "$in{'code'}<>$in{'name'}<>$in{'price'}<>$in{'intax'}<>$in{'plus1'}<>$in{'plus2'}<>\n"; close(OUT); # ロック開始 &lock if ($lockkey); # 在庫更新 if ($stock) { open(OUT,">>$stkfile") || &error("Write Error: $stkfile"); print OUT "$in{'code'}<>$in{'stock'}<>\n"; close(OUT); } # ロック解除 &unlock if ($lockkey); # 編集フォーム } elsif ($in{'job'} eq "edit" && $in{'code'} ne "") { open(IN,"$datfile") || &error("Open Error: $datfile"); while (<IN>) { ($code,$name,$price,$intax,$plus1,$plus2) = split(/<>/); if ($in{'code'} eq $code) { last; } } close(IN); &edit_form($code,$name,$price,$intax,$plus1,$plus2); # 編集実行 } elsif ($in{'job'} eq "edit2" && $in{'code'} ne "") { $in{'code'} =~ s/:/:/g; $in{'code'} =~ s/;/;/g; $in{'name'} =~ s/:/:/g; $in{'name'} =~ s/;/;/g; if ($in{'code'} eq "") { &error("商品コードが未入力です"); } if ($in{'name'} eq "") { &error("商品名が未入力です"); } if ($in{'price'} eq "") { &error("商品単価が未入力です"); } if ($in{'price'} =~ /\D/) { &error("商品単価は半角数字のみで入力してください"); } if ($in{'plus2'} ne "" && $in{'plus2'} =~ /\D/) { &error("付加金額は半角数字のみで入力してください"); } if (($in{'plus1'} eq "" && $in{'plus2'} ne "") || ($in{'plus1'} ne "" && $in{'plus2'} eq "")) { &error("名称と金額は双方共に入力してください"); } if ($stock) { if ($in{'stock'} eq "") { &error("在庫数を指定してください"); } if ($in{'stock'} =~ /\D/) { &error("在庫数に半角数字以外の文字が入力されています"); } } @data=(); open(IN,"$datfile") || &error("Open Error: $datfile"); while (<IN>) { ($code,$name,$price,$intax,$plus1,$plus2) = split(/<>/); if ($in{'code'} eq $code) { $_="$in{'code'}<>$in{'name'}<>$in{'price'}<>$in{'intax'}<>$in{'plus1'}<>$in{'plus2'}<>\n"; } push(@data,$_); } close(IN); # 登録データ更新 open(OUT,">$datfile") || &error("Write Error: $datfile"); print OUT @data; close(OUT); # 在庫更新 if ($stock && $in{'now'} != $in{'stock'}) { local($flag,@file); # ロック開始 &lock if ($lockkey); @file=(); $flag=0; open(IN,"$stkfile") || &error("Open Error: $stkfile"); while (<IN>) { ($code,$zan) = split(/<>/); if ($in{'code'} eq $code) { $flag++; $_="$code<>$in{'stock'}<>\n"; } push(@file,$_); } close(IN); if (!$flag) { push(@file,"$in{'code'}<>$in{'stock'}<>\n"); } open(OUT,">$stkfile") || &error("Write Error: $stkfile"); print OUT @file; close(OUT); # ロック解除 &unlock if ($lockkey); } # 削除実行 } elsif ($in{'job'} eq "dele" && $in{'code'} ne "") { @data=(); open(IN,"$datfile") || &error("Open Error: $datfile"); while (<IN>) { ($code,$name,$price,$intax,$plus1,$plus2) = split(/<>/); $f=0; foreach $del ( split(/\0/, $in{'code'}) ) { if ($code eq $del) { $f++; last; } } if (!$f) { push(@data,$_); } } close(IN); # 登録データ更新 open(OUT,">$datfile") || &error("Write Error: $datfile"); print OUT @data; close(OUT); # 在庫更新 if ($stock) { # ロック開始 &lock if ($lockkey); @file=(); open(IN,"$stkfile") || &error("Open Error: $stkfile"); while (<IN>) { ($code,$zan) = split(/<>/); next if ($in{'code'} eq $code); push(@file,$_); } close(IN); open(OUT,">$stkfile") || &error("Write Error: $stkfile"); print OUT @file; close(OUT); # ロック解除 &unlock if ($lockkey); } } &header; print <<EOM; <form> <input type="button" value="TOPに戻る" onClick=window.open("$home","_self")> </form> <ul> <li>処理を選択して送信ボタンを押してください。 </ul> <form action="$admin" method="POST"> <input type=hidden name=pass value="$in{'pass'}"> 処理: <select name=job> <option value="new">新規登録 <option value="edit">データ修正 <option value="dele">データ削除 </select> <input type=submit value="送信する"> <p> <table border=0 cellspacing=2 cellpadding=4> <tr> <th class=l>選択</th> <th class=l>商品コード</th> <th class=l>商品名</th> <th class=l>単価</th> EOM # 在庫データ if ($stock) { local($code,$zan); %stock=(); open(IN,"$stkfile") || &error("Open Error: $stkfile"); while (<IN>) { ($code,$zan) = split(/<>/); $stock{$code} = $zan; } close(IN); print "<th class=l>在庫</th>"; } print "</tr>\n"; @tax = ('税別','税込み'); $i=0; open(IN,"$datfile") || &error("Open Error: $datfile"); while (<IN>) { $i++; next if ($i < $page + 1); next if ($i > $page + $pageLog); ($code,$name,$price,$intax,$plus1,$plus2) = split(/<>/); $price = &comma($price); print "<tr><th class=r> <input type=checkbox name=code value=\"$code\"></th> <td class=r>$code</td><td class=r><b>$name</b></td> <td align=right class=r>\\$price ($tax[$intax])</td>\n"; # 在庫 if ($stock) { if (!defined($stock{$code})) { $stock{$code}=0; } print "<td align=right class=r>$stock{$code}</td>"; } print "</tr>\n"; } close(IN); $next = $page + $pageLog; $back = $page - $pageLog; print "</table></form><p><table><tr>\n"; if ($back >= 0) { print "<td><form action=\"$admin\" method=post>\n"; print "<input type=hidden name=pass value=\"$in{'pass'}\">\n"; print "<input type=hidden name=page value=\"$back\">\n"; print "<input type=submit value=\"前の$pageLog件\"></form></td>\n"; } if ($next < $i) { print "<td><form action=\"$admin\" method=post>\n"; print "<input type=hidden name=pass value=\"$in{'pass'}\">\n"; print "<input type=hidden name=page value=\"$next\">\n"; print "<input type=submit value=\"次の$pageLog件\"></form></td>\n"; } print <<EOM; </tr></table> </body> </html> EOM exit; } #------------------------------------------------- # 新規登録フォーム #------------------------------------------------- sub new_form { &header; print <<EOM; <form action="$admin" method="POST"> <input type=hidden name=pass value="$in{'pass'}"> <input type=submit value="前画面に戻る"> </form> <ul> <li>所定の内容を入力してください。 </ul> <form action="$admin" method="POST"> <input type=hidden name=job value="new2"> <input type=hidden name=pass value="$in{'pass'}"> EOM &form(); } #------------------------------------------------- # 編集フォーム #------------------------------------------------- sub edit_form { local($code,$name,$price,$intax,$plus1,$plus2) = @_; local($id,$zan); # 在庫 if ($stock) { %stock=(); open(IN,"$stkfile") || &error("Open Error: $stkfile"); while (<IN>) { ($id,$zan) = split(/<>/); $stock{$id} = $zan; } close(IN); } &header; print <<EOM; <form action="$admin" method="POST"> <input type=hidden name=pass value="$in{'pass'}"> <input type=submit value="前画面に戻る"> </form> <ul> <li>修正する部分のみ変更してください。 </ul> <form action="$admin" method="POST"> <input type=hidden name=job value="edit2"> <input type=hidden name=pass value="$in{'pass'}"> EOM &form($code,$name,$price,$intax,$plus1,$plus2); } #------------------------------------------------- # フォーム #------------------------------------------------- sub form { local($code,$name,$price,$intax,$plus1,$plus2) = @_; print <<EOM; <table cellpadding=4> <tr> <th class=l>商品コード</th> <td class=r><input type=text name=code size=20 value="$code"> (任意の英数字で指定)</td> </tr> <tr> <th class=l>商品名</th> <td class=r><input type=text name=name size=30 value="$name"></td> </tr> <tr> <th class=l>商品単価</th> <td class=r><input type=text name=price size=20 value="$price" style="ime-mode:inactive"> 円</td> </tr> <tr> <th class=l>消費税</th> <td class=r> EOM if ($intax eq "") { $intax = 1; } @tax = ('税別','税込み'); foreach (0,1) { if ($intax == $_) { print "<input type=radio name=intax value=\"$_\" checked>$tax[$_]\n"; } else { print "<input type=radio name=intax value=\"$_\">$tax[$_]\n"; } } print "</td></tr>\n"; # 在庫 if ($stock) { if (!defined($stock{$code})) { $stock{$code}=0; } print "<tr><th class=l>在庫数</th><td class=r> <input type=text name=stock size=5 style=\"ime-mode:inactive\" value=\"$stock{$code}\"> <input type=hidden name=now value=\"$stock{$code}\"> </td></tr>\n"; } print <<EOM; </table> <p> <input type=submit value=" 送信する "> </form> </body> </html> EOM exit; } #------------------------------------------------- # 入室画面 #------------------------------------------------- sub enter { &header; print <<EOM; <div align="center"> <h4>パスワードを入力してください</h4> <form action="$admin" method="POST"> <input type=password name=pass size=8> <input type=submit value="ログイン"> </form> </div> </body> </html> EOM exit; } __END__ |
←#!/usr/bin/perl又は#!/usr/local/bin/perl サーバー会社に確認して下さい。(アット・ワイエムシー社は#!/usr/bin/perlです) |
次へ |