#!/usr/bin/perl #┌──────────────────────── #│ mart.cgi - 2006/01/23 #│ Copyright (c) KentWeb #└──────────────────────── # 外部ファイル取り込み require './mart_init.cgi'; # 基本処理定義 &decode(0); if ($mode eq "change") { &change; } elsif ($mode eq "note") { ¬e; } elsif ($mode eq "check") { ✓ } &pickup; #------------------------------------------------- # カゴ入れ #------------------------------------------------- sub pickup { local($flag,$id,$code,$num,$size,$col,@new); $in{'num'} = &num_z2h($in{'num'}); $in{'size'} =~ s/:/:/g; $in{'size'} =~ s/;/;/g; $in{'color'} =~ s/:/:/g; $in{'color'} =~ s/;/;/g; # BACK属性がなければ、HTTP_REFERERで取得 if (!$in{'back'}) { $in{'back'} = $ENV{'HTTP_REFERER'}; } # 登録データ認識 &get_data; # コード & 個数が共に無しの場合は「中身確認」 if ($in{'code'} eq "" && $in{'num'} eq "") { # 在庫チェック if ($stock) { local($code,$zan); undef(%zan); open(IN,"$stkfile") || &error("Open Error: $stkfile"); while () { ($code,$zan) = split(/<>/); $zan{$code} = $zan; } close(IN); } @cook = &get_cookie($cookieID); &basket(@cook); # 商品コードのみ無しはエラー } elsif ($in{'code'} eq "" && $in{'num'}) { &error("商品コードが不正です"); # 商品個数のみ無しはエラー } elsif ($in{'code'} && $in{'num'} eq "") { &error("商品個数がありません"); } # 商品コードの登録チェック if (!defined($cart{"$in{'code'}"})) { &error("商品コード「$in{'code'}」は登録されていないデータです。
管理者へお問い合わせください。"); } # 在庫チェック if ($stock) { local($code,$zan); # ロック開始 &lock if ($lockkey); $flag=0; undef(%zan); open(IN,"$stkfile") || &error("Open Error: $stkfile"); while () { ($code,$zan) = split(/<>/); $zan{$code} = $zan; if ($code eq $in{'code'}) { $flag++; } } close(IN); # ロック解除 &unlock if ($lockkey); if (!$flag) { &error("この商品は在庫数が未定義です"); } if ($zan{$in{'code'}} - $in{'num'} < 0) { &error("誠に申\し訳ありません。
現在この商品は在庫切れです(現在の在庫数:$zan{$in{'code'}})"); } } # クッキー取得 @cook = &get_cookie($cookieID); # 重複チェック $flag=0; @new=(); foreach (@cook) { ($id,$code,$num,$size,$col) = split(/,/); # 要素が同じ場合は数量を足しこむ(重複する場合) if ($in{'code'} eq $code && $in{'size'} eq $size && $in{'color'} eq $col) { $flag++; $num += $in{'num'}; # 在庫チェック if ($stock) { if ($zan{$in{'code'}} - $num < 0) { &error("誠に申\し訳ありません。
現在この商品は在庫切れです(現在の在庫数:$zan{$in{'code'}})"); } } $_ = "$id,$code,$num,$size,$col"; } push(@new,$_); } @cook = @new; # 重複がなければ追加 if (!$flag) { # 識別番号を発行 ($id) = split(/,/, $cook[0]); $id++; # クッキー追加 @cook = ("$id,$in{'code'},$in{'num'},$in{'size'},$in{'color'}", @cook); } # クッキー格納 &set_cookie(@cook); # カゴ確認画面 &basket(@cook); } #------------------------------------------------- # カゴ画面表示 #------------------------------------------------- sub basket { local(@cook) = @_; &header; print <ホームに戻る | 特定商取引法の表\示 ]
  • 買物カゴの中身は以下のとおりです.
  • 消費税や送料が別途かかる場合には最終確認画面で表\示されます.
  • 数量を変更する場合はプルダウンから変更ボタンを押してください.

EOM # 買物カゴの中身 &cart_tbl('basket'); # 中身がない場合 if (@cook == 0) { print "

\n"; if ($in{'back'}) { print "\n"; } else { print "\n"; } print "
\n"; print "\n"; exit; } print <
EOM foreach (@cook) { s/;/;/g; ($id,$code,$num,$size,$col) = split(/,/); print "\n"; } print <

- WebMart -

EOM exit; } #------------------------------------------------- # カート内容変更 #------------------------------------------------- sub change { local($chg_num,$del_num); foreach ( keys(%in) ) { if (/^chg:(\d+)/) { $chg_num = $1; last; } elsif (/^del:(\d+)/) { $del_num = $1; last; } } # 在庫チェック if ($stock) { local($code,$zan); undef(%zan); open(IN,"$stkfile") || &error("Open Error: $stkfile"); while () { ($code,$zan) = split(/<>/); $zan{$code} = $zan; } close(IN); } # クッキー取得 local(@get) = &get_cookie($cookieID); @cook=(); foreach (@get) { ($id,$code,$num,$size,$col) = split(/,/); # 変更 if ($chg_num eq $id) { $_ = "$id,$code,$in{\"num:$id\"},$size,$col"; # 削除 } elsif ($del_num eq $id) { next; } push(@cook,$_); } # クッキー格納 &set_cookie(@cook); # 買物カゴ &get_data; &basket(@cook); } #------------------------------------------------- # 数字半角変換 #------------------------------------------------- sub num_z2h { local($_) = @_; s/0/0/g; s/1/1/g; s/2/2/g; s/3/3/g; s/4/4/g; s/5/5/g; s/6/6/g; s/7/7/g; s/8/8/g; s/9/9/g; $_; } #------------------------------------------------- # チェックモード #------------------------------------------------- sub check { &header; print <Check Mode
    EOM # ログ local(%log) = ('登録データ', $datfile, '在庫データ', $stkfile); while ( ($k,$v) = each(%log) ) { if (-e $v) { print "
  • $kパス: OK\n"; if (-r $v && -w $v) { print "
  • $kパーミッション: OK\n"; } else { print "
  • $kパーミッション: NG → $v\n"; } } else { print "
  • $kパス: NG → $v\n"; } } # sendmailパス if (-e $sendmail) { print "
  • sendmailパス: OK\n"; } else { print "
  • sendmailパス: NG → $sendmail\n"; } print <バージョン: $ver
EOM exit; } __END__