changeset 3441:05f1568dbb18

tamago.rb Êѹ¹
author OOTANI Hiroyuki <c115036@g.koeki-u.ac.jp>
date Fri, 28 Jul 2017 12:07:00 +0900
parents 97423bc9f575
children d629cbc46748
files event/oasis2017/ikusei/daizu.rb event/oasis2017/ikusei/tamago.rb
diffstat 2 files changed, 104 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/event/oasis2017/ikusei/daizu.rb	Fri Jul 28 11:21:38 2017 +0900
+++ b/event/oasis2017/ikusei/daizu.rb	Fri Jul 28 12:07:00 2017 +0900
@@ -140,7 +140,7 @@
 print(<<-EOF)
 <!DOCTYPE html>
 <html lang="ja">
-<head><title>花ç«</title>
+<head><title>大豆</title>
 <link rel="stylesheet" type="text/css" href="daizu.css" >
 <meta name="viewport" content="width=device-width">
 </head>
--- a/event/oasis2017/ikusei/tamago.rb	Fri Jul 28 11:21:38 2017 +0900
+++ b/event/oasis2017/ikusei/tamago.rb	Fri Jul 28 12:07:00 2017 +0900
@@ -5,13 +5,100 @@
 
 require 'cgi'
 require 'csv'
-
+require 'sqlite3'
 c = CGI.new(:accept_charset => "UTF-8")
-print "Content-type: text/html; charset=UTF-8\n\n"
+#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="IKD"
+
+
+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("tamago.csv") do |row|
   q_number = row.shift
@@ -48,11 +135,21 @@
 if number == ""  #åˆå›žèµ·å‹•æ™‚ã®ã¿
   number = "1"    #numberã«"1"を代入
 end
+print(<<-EOF)
+<!DOCTYPE html>
+<html lang="ja">
+<head><title>é³¥</title>
+<link rel="stylesheet" type="text/css" href="tamago.css" >
+<meta name="viewport" content="width=device-width">
+</head>
+<body>
+EOF
+printf("<h1>%sã•ã‚“ã®ãƒãƒ£ãƒ¬ãƒ³ã‚¸</h1>\n", playname)
 
 
-print"<html><head><title>é³¥</title>
-<meta name=\"viewport\" content=\"width=device-width,initial-scale=1\">
-<link rel=\"stylesheet\" type=\"text/css\" href=\"tamago.css\"></head><body>\n"
+#print"<html><head><title>é³¥</title>
+#<meta name=\"viewport\" content=\"width=device#-width,initial-scale=1\">
+#<link rel=\"stylesheet\" type=\"text/css\" hre#f=\"tamago.css\"></head><body>\n"
 
 print"<form method=\"POST\" action=\"./tamago.rb\">\n"
 
@@ -106,7 +203,7 @@
   end
   printf("<input type=\"submit\" value=\"次ã¸\">")
   
-
+db.execute("REPLACE INTO point VALUES(?, ?)", id, someValue)
 
 
 

yatex.org