Mercurial > hgrepos > hgweb.cgi > skipweb
view event/oasis2017/ikusei/daizu.rb @ 3440:97423bc9f575
daizu.rb Êѹ¹2
author | OOTANI Hiroyuki <c115036@g.koeki-u.ac.jp> |
---|---|
date | Fri, 28 Jul 2017 11:21:38 +0900 |
parents | f047cb0b8798 |
children | 8d9f55c5c619 |
line wrap: on
line source
#!/usr/bin/env ruby # -*- coding: utf-8 -*- Encoding.default_internal = "UTF-8" Encoding.default_external = "UTF-8" require 'cgi' require 'csv' require 'sqlite3' c = CGI.new(:accept_charset => "UTF-8") #print "Content-type: text/html; charset=UTF-8\n\n" number = c["rd"] img = c["img"] file = "../db/point.sq3" #cookie関係 cookie_id=c.cookies["id"][0] form_seikai=c["seikai"] #ã‚‚ã—æ£è§£ã—ãŸã‚‰?ã¨ã‹ã˜ã‚ƒãªã„? form_name=c["playname"] #åå‰å…¥åŠ› someValue="IKC" if cookie_id == nil newid = Time.now.to_i.to_s + "/" + rand(99999).to_s id = newid else id = cookie_id end # idã‚’ã™ãcookieã§ç›¸æ‰‹ãƒ–ラウザã«é€ã‚‹ # 変数ã®æœŸé™ã‚’24時間ã«è¨å®šã—ã€expire変数ã«å…¥ã‚Œã‚‹ expire = (Time.now+24*3600).gmtime.strftime("%a, %d %b %Y %H:%M:%S GMT") printf("Content-type: text/html; charset=UTF-8\n") printf("Set-Cookie: id=%s; expires=%s\n\n", id, expire) db = SQLite3::Database.new(file) db.execute("PRAGMA foreign_keys=on") db.execute("CREATE TABLE IF NOT EXISTS " + "users(id text primary key, name text, creation text)") db.execute("CREATE TABLE IF NOT EXISTS " + "point(id, keyword text, FOREIGN KEY(id) REFERENCES users(id))") if form_seikai > "" && id > ''# ã‚‚ã—æ£è§£ã—ãŸã‚‰ db.execute("DELETE FROM point WHERE id=?", id) end # cookie関連ã¯ã“ã“ã¾ã§ã ã¨æ€ã£ã¦ã„ã‚‹ ################################################################## ユーザ登録 playname = form_name if form_name > "" # フォームã§nameãŒé€ã‚‰ã‚ŒãŸãªã‚‰ãれ優先 now = Time.now.strftime("%F %T") db.execute("REPLACE INTO users VALUES(?, ?, ?)", id, form_name, now); else # フォームã§nameãªã‘ã‚Œã°dbã‹ã‚‰ # dbname = db.execute("SELECT name from users WHERE id=?", id)[0][0] #if dbname != nil # playname = dbname # データベースã‹ã‚‰ã®ã®åå‰ã‚’プレイåã¨ã™ã‚‹ #end #end dbname = db.execute("SELECT name from users WHERE id=?", id)[0] if dbname != nil && dbname[0] playname = dbname[0] end end if playname == "" print(<<-EOF) <form action="#{File.basename($0)}" method="POST"> <p>プレイåを入れã¦ãã ã•ã„: <input type="text" name="playname"> <input type="submit" value="é€ä¿¡"> <input type="reset" value="リセット"> </form> EOF exit end #printf("<h1>%sã•ã‚“ã®ãƒãƒ£ãƒ¬ãƒ³ã‚¸</h1>\n", playname) ################################################################## åˆå›žå‡¦ç† number = c["rd"] img = c["img"] def outinput(value, name) printf("<label><input type=\"radio\" name=\"rd\" value=\"%s\">%s</label>", value, name) end def imgsrc(img) printf("<img src=\"%s\">", img) end if number == "" #åˆå›žèµ·å‹•æ™‚ã®ã¿ number = "1" #numberã«"1"を代入 end x = Hash.new CSV.foreach("daizu.csv") do |row| q_number = row.shift question = row.shift x[q_number] = [question, Hash[*row]] ##x[number] = {"Q" => question, "A" => Hash[*row]} end #p x #encoding:"SJIS:UTF-8" gazou1="07.png"#1ページ目ã®ç”»åƒ link1 ="07.png"#1ページ目ã®ãƒªãƒ³ã‚¯ç”»åƒ alt1 ="daizu"#1ページ目ã®altç”»åƒ gazou2="08.png"#2ページ目ã®ç”»åƒ link2 ="08.png"#2ページ目ã®ãƒªãƒ³ã‚¯ç”»åƒ alt2 ="tounyu"#2ページ目ã®altç”»åƒ gazou3="09.png"#3ページ目ã®ç”»åƒ link3 ="09.png"#3ページ目ã®ãƒªãƒ³ã‚¯ç”»åƒ alt3 ="toufu"#3ページ目ã®altç”»åƒ ongaku1="daizu1.mp3" ongaku2="daizu2.mp3" ongaku3="daizu3.mp3" ongaku4="daizu.ogg" def outinput(value, name) printf("<label><input type=\"radio\" name=\"rd\" value=\"%s\">%s</label>", value, name) end def imgsrc(img) printf("<img src=\"%s\">", img) end if number == "" #åˆå›žèµ·å‹•æ™‚ã®ã¿ number = "1" #numberã«"1"を代入 end print(<<-EOF) <!DOCTYPE html> <html lang="ja"> <head><title>花ç«</title> <link rel="stylesheet" type="text/css" href="daizu.css" > <meta name="viewport" content="width=device-width"> </head> <body> EOF printf("<h1>%sã•ã‚“ã®ãƒãƒ£ãƒ¬ãƒ³ã‚¸</h1>\n", playname) #print"<!DOCTYPE html> #<html><head><title>大豆</title> #<meta name=\"viewport\" content=\"width=device#-width,initial-scale=1\"> #<link rel=\"stylesheet\" type=\"text/css\" hre#f=\"daizu.css\"> #</head><body>\n" print"<form method=\"POST\" action=\"./daizu.rb\">\n" q = x[number] #ifã§å ´åˆåˆ†ã‘åˆã‚ã¦ãã®å•é¡Œã«è¡Œãã€æ£è§£ã€ä¸æ£è§£ï¼‘ã€ä¸æ£è§£ï¼’,ã®ï¼”通り if number == "1" || number == "5" || number == "9" #åˆã‚ã¦æŒ‘戦 printf("<p>%s</p>", q[0]) if number == "1" printf("<p><a href=\"%s\"><img src=\"%s\" alt=\"%s\" height=\"300px\" width=\"300px\"></a></p>",link1,gazou1,alt1) elsif number == "5" printf("<p><a href=\"%s\"><img src=\"%s\" alt=\"%s\" height=\"300px\" width=\"300px\"></a></p>",link2,gazou2,alt2) elsif number == "9" printf("<p><a href=\"%s\"><img src=\"%s\" alt=\"%s\" height=\"300px\" width=\"300px\"></a></p>",link3,gazou3,alt3) end for v, sel in q[1] outinput(v, sel) end print"<input name=\"ok\" type=\"submit\" value=\"é€ä¿¡\">\n" print"<input name=\"ng\" type=\"reset\" value=\"リセット\">\n" elsif number == "3" || number == "8" || number == "10" #æ£è§£ printf("%s", q[0]) #printf("%s", q[1]) if number == "3" print("<p>") printf("<audio controls autoplay loop false preload=\"auto\"><source src=\"%s\"></audio>",ongaku1) print("<\p>") printf("<label><input type=\"radio\" name=\"rd\" value=\"5\">次ã¸é€²ã‚‚ã†<br></label>") # printf("<input type=\"submit\" value=\"次ã¸\">") elsif number =="8" print("<p>") printf("<audio controls autoplay loop false preload=\"auto\"><source src=\"%s\"></audio>",ongaku2) print("</p>") printf("<label><input type=\"radio\" name=\"rd\" value=\"9\">次ã¸é€²ã‚‚ã†<br></label>") elsif number == "10" print("<p>") printf("<audio controls autoplay loop false preload=\"auto\"><source src=\"%s\"></audio>",ongaku3) print("<\p>") printf("<label><input type=\"radio\" name=\"rd\" value=\"13\">次ã¸é€²ã‚‚ã†<br></label>") end printf("<input type=\"submit\" value=\"次ã¸\">") db.execute("REPLACE INTO point VALUES(?, ?)", id, someValue) elsif number == "2" || number == "6" || number == "11" #ä¸æ£è§£1 print("<h1>残念ï¼ã‚‚ã†ä¸€åº¦æŒ‘戦ã ーー</h1>") printf("<p>%s</p>", q[0]) if number == "2" printf("<p><a href=\"%s\"><img src=\"%s\" alt=\"%s\" height=\"300px\" width=\"300px\"></a></p>",link1,gazou1,alt1) elsif number == "6" printf("<p><a href=\"%s\"><img src=\"%s\" alt=\"%s\" height=\"300px\" width=\"300px\"></a></p>",link2,gazou2,alt2) elsif number == "11" printf("<p><a href=\"%s\"><img src=\"%s\" alt=\"%s\" height=\"300px\" width=\"300px\"></a></p>",link3,gazou3,alt3) end for v, sel in q[1] outinput(v, sel) end print"<input name=\"ok\" type=\"submit\" value=\"é€ä¿¡\">\n" print"<input name=\"ng\" type=\"reset\" value=\"リセット\">\n" elsif number == "4" || number == "7" || number == "12" #ä¸æ£è§£2 print("<h1>惜ã—ã„ï¼ã‚‚ã†ä¸€åº¦ã‚„ã£ã¦ã¿ã‚ˆãƒ¼ãƒ¼</h1>") printf("<p>%s</p>", q[0]) if number == "4" printf("<p><a href=\"%s\"><img src=\"%s\" alt=\"%s\" height=\"300px\" width=\"300px\"></a></p>",link1,gazou1,alt1) elsif number == "7" printf("<p><a href=\"%s\"><img src=\"%s\" alt=\"%s\" height=\"300px\" width=\"300px\"></a></p>",link2,gazou2,alt2) elsif number == "12" printf("<p><a href=\"%s\"><img src=\"%s\" alt=\"%s\" height=\"300px\" width=\"300px\"></a></p>",link3,gazou3,alt3) end for v, sel in q[1] outinput(v, sel) end print"<input name=\"ok\" type=\"submit\" value=\"é€ä¿¡\">\n" print"<input name=\"ng\" type=\"reset\" value=\"リセット\">\n" elsif number == "13" print("<p>音楽ã®èžåˆ</p>\n") printf("<audio controls autoplay loop false preload=\"auto\"><source src=\"%s\"></audio>\n",ongaku4) #printf("<p><a href=\"http://roy.e.koeki-u.ac.jp/~c115036/ikusei2017/ikusei.html\">topページã«æˆ»ã‚‹</a></p>\n") end print"</form>\n" print "</body>\n" print "</html>\n"