changeset 1704:a9bea01bfceb

me.rb Êѹ¹
author OOTANI Hiroyuki <c115036@g.koeki-u.ac.jp>
date Fri, 28 Jul 2017 11:03:36 +0900
parents 23202ac3e859
children 5b6d6717d315
files event/oasis2017/ikusei/kayaku4.rb event/oasis2017/ikusei/me.rb
diffstat 2 files changed, 107 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/event/oasis2017/ikusei/kayaku4.rb	Thu Jul 27 22:00:47 2017 +0900
+++ b/event/oasis2017/ikusei/kayaku4.rb	Fri Jul 28 11:03:36 2017 +0900
@@ -12,7 +12,7 @@
 number = c["rd"]
 img = c["img"]
 
-file = "../quiz/db/point.sq3"
+file = "../db/point.sq3"
 
 
 #cookie関係
--- a/event/oasis2017/ikusei/me.rb	Thu Jul 27 22:00:47 2017 +0900
+++ b/event/oasis2017/ikusei/me.rb	Fri Jul 28 11:03:36 2017 +0900
@@ -5,13 +5,102 @@
 
 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="IKB"
+
+
+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("me.csv") do |row|
   q_number = row.shift
@@ -49,10 +138,21 @@
   number = "1"    #numberã«"1"を代入
 end
 
+print(<<-EOF)
+<!DOCTYPE html>
+<html lang="ja">
+<head><title>芽</title>
+<link rel="stylesheet" type="text/css" href="me.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=\"me.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=\"me.css\"></head><body>\n"
 
 print"<form method=\"POST\" action=\"./me.rb\">\n"
 
@@ -108,7 +208,7 @@
   
 
 
-
+db.execute("REPLACE INTO point VALUES(?, ?)", id, someValue)
 
 
 elsif number == "2" || number == "6" || number == "11"          #ä¸æ­£è§£1

yatex.org