#!/usr/bin/ruby1.8 require "cgi" # ---- form class class EntryForm def initialize(params) # - page if (params['Page'].empty?) then @page = 0 else @page = params['Page'][0].to_i end # - mail address if (params['MADR'].empty?) then @mail_addrss = '' else @mail_address = params['MADR'][0] end # - name if (params['NAME'].empty?) then @name = '' else @name = params['NAME'][0] end # - build service if (params['BUILD'].empty?) then @build = '' else @build = params['BUILD'][0] end # - select package if (params['PACK'].empty?) then @pack = '' else @pack = params['PACK'][0] end # - send area if (params['AREA'].empty?) then @area = '' else @area = params['AREA'][0] end # - payment if (params['PAYMENT'].empty?) then @payment = '' else @payment = params['PAYMENT'][0] end end # -- page def GetPage @page end # -- send mail def SendMail message = "" message << "Mail Address:\n" message << @mail_address message << "\n\n" message << "Name:\n" message << @name message << "\n\n" message << "Build:\n" message << @build message << "\n\n" message << "Pack:\n" message << @pack message << "\n\n" message << "Area:\n" message << @area message << "\n\n" message << "Payment:\n" message << @payment message << "\n\n" # open("| /usr/sbin/sendmail rero2@yuumu.org", "w") do |mail| mail.print("From: kanade_entry@yuumu.org\n") mail.print("To: rero2@yuumu.org\n") mail.print("Subject: To Kanade Entry\n") mail.print("\n") mail.print message end end # -- invisible form def InvisibleForm printf("\n", @mail_address) printf("\n", @name) printf("\n", @build) printf("\n", @pack) printf("\n", @area) printf("\n", @payment) end # -- confirm def Confirm printf("
連絡先メールアドレス : %s
\n", @mail_address) printf("お名前 : %s
\n", @name) if (@build =~ /NO/) then disp_build = "希望しません(キットで送る)" else disp_build = "希望します(+1,000円)" end printf("組み立て希望 : %s
\n", disp_build) if (@pack =~ /OK/) then disp_pack = "良いです(送料 500円)" else disp_pack = "箱にしてください(送り先で送料が決まります)" end printf("EXPACK500で良いか : %s
\n", disp_pack) printf("宛先都道府県 : %s
\n", @area) printf("支払い方法 : %s
\n", @payment) end end # ---- stock class class Stock def initialize(stock_file) @stock = 0 fp = open("stock.dat", "r") fp.each do |line| if line =~ /[0-9]+/ then @stock = line.to_i elsif line =~ /\*/ @stock -= 1 end end fp.close end def GetStock @stock end def PutStock fp = open("stock.dat", "a") fp << "*\n" fp.close end end # ---- page subroutine def goto_next print'' end def soldout print '申込数が予定数量に達したため受付を終了します。
ありがとうございました。
%d 個
\n", rest.GetStock); elsif line =~ /\%\%confirm\%\%/ then form.InvisibleForm form.Confirm elsif line =~ /\%\%next\%\%/ then if rest.GetStock > 0 then goto_next else soldout end else print line end end fp.close end # ---- main routine cgi = CGI.new params = cgi.params get_form = EntryForm::new(params) rest = Stock::new('stock.dat') # ---- generate html print "Content-type: text/html\n\n" fp = open("base.html", "r") fp.each do |line| if line =~ /\%\%body\%\%/ then output_body(get_form, rest) else print line end end fp.close