Mercurial > hgrepos > hgweb.cgi > skipweb
changeset 649:55e59370aedc
add.html add.rb leaf.rb add
author | FUJIKAWA Kosuke <c111126@g.koeki-u.ac.jp> |
---|---|
date | Sun, 09 Nov 2014 16:56:30 +0900 |
parents | e01709e74c3a |
children | 8c17e8a77717 |
files | fujix/add.html fujix/add.rb fujix/leaf.rb fujix/redirect.html fujix/sql/dummy.txt |
diffstat | 5 files changed, 179 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/fujix/add.html Sun Nov 09 16:56:30 2014 +0900 @@ -0,0 +1,18 @@ +<html> +<head> +<title>add page</title> +<link rel="stylesheet" type="text/css" href="ほげ.css"> +</head> + +<body> +<h1>登録ぺーじ</h1> +<p>名前を入れて登録しよう</p> +<form method="POST" action="./add.rb"> +<p>お名前: <input name="name" type="text" maxlength="40"><br> +<input type="submit" value="OK"> +<input type="reset" value="reset"><br></p> +</form> +<address>c111126@g.koeki-u.ac.jp</address> + +</body> +</html>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/fujix/add.rb Sun Nov 09 16:56:30 2014 +0900 @@ -0,0 +1,48 @@ +#!/usr/bin/env ruby +#coding:utf-8 + +require'cgi' +require'sqlite3' + +cgi = CGI.new(:accept_charset => "UTF-8") +name = cgi["name"] + +db = SQLite3::Database.new("sql/test.sq3") + +begin + db.execute("insert into main(name,lon,lat) values('#{name}',0,0)"); +rescue + db.execute("create table main(id integer PRIMARY KEY AUTOINCREMENT,name,lon,lat)"); + db.execute("insert into main(name,lon,lat) values('#{name}',0,0)"); + data = db.execute("select * from main"); +end + +count = db.execute("select max(id) from main"); + +expires = (Time.now.gmtime+3600*24).strftime("%a, %d %b %Y %H:%M:%S GMT") + +print"Content-type: text/html charset=UTF-8\n" + +printf("Set-Cookie:id=%d; expires=%s\n",count[0][0],expires) +printf("Set-Cookie:name=%s; expires=%s\n\n",name,expires) + +printf"<!DOCTYPE html> +<html> +<head> +<title>add page's</title> +<script language=\"javascript\"> +time = 1; +url = \"http://skip.koeki-prj.org/fujix/redirect.html\"; +function jumpPage() { + location.href = url; +} +setTimeout(\"jumpPage()\",time*500) +</script> + +</head> +<body> +<p>勝手にページが飛びます。</p> +<p>移動しない場合は<a href=\"redirect.html\">こちら</a>から移動してください</p> +</body> +</html> +"
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/fujix/leaf.rb Sun Nov 09 16:56:30 2014 +0900 @@ -0,0 +1,107 @@ +#!/usr/bin/env ruby +#coding:utf-8 + +print"Content-type: text/html charset=UTF-8\n\n" + +require'sqlite3' +require 'cgi' +c = CGI.new(:accept_charaset => "UTF-8") +db = SQLite3::Database.new("sql/test.sq3") +db.results_as_hash = true + +lon = ARGV[0].to_f +lat = ARGV[1].to_f + +data = Hash.new +#data["fujix"] = [38.91026,139.84532] +#data["ほげ"] = [38.91526,139.84032] + +cookieuke = Hash.new # cookie値保存用のHash +if (c=ENV['HTTP_COOKIE']) # 環境変数 HTTP_COOKIE にcookieリストがある + c.split(/[;,]\s+/).each do |exp| # (セミコロンかカンマ)+空白 で分解 + if /(.*)=(.*)/ =~ exp # =の前後で分解 「変数=値;」 + key = CGI::unescape($1) # 変数も値もエスケープされているので + value = CGI::unescape($2) # 元に戻す + cookieuke[key] = CGI::unescape(value) + end + end +end +name = cookieuke["name"] +id = cookieuke["id"].to_i + +lon = 38.91326 +lat = 139.84032 + +begin + db.execute("select * from main"); +rescue + db.execute("create table main(id INTEGER PRIMARY KEY AUTOINCREMENT,name,lon,lat)"); + db.execute("insert into main(name,lon,lat) values('NAME','LON','LAT')"); +end + +sql = "update main set name=?,lon=?,lat=? where id=?" + +begin + db.execute(sql,name,lon,lat,id) +rescue + db.execute("insert into main(name,lon,lat) values('#{name}','#{lon}','#{lat}')"); +end + +db.execute("select * from main") do |load| + data[load['id']] = [load['name'],load['lon'],load['lat']] +end + +printf(<<_EOS_) +<!DOCTYPE html> +<html> +<head> +<link rel="stylesheet" type="text/css" href="leaflet/leaflet.css"/> +<script src="leaflet/leaflet.js"></script> +<style> + html,body,#map{ + height: 100% + } + body{ + padding: 0; + margin: 0; + } +</style> +<title>Getting Started with Leaflet</title> +<meta http-equiv="refresh" content="20;redirect.html"> +</head> +<body> +<div id="map"></div> +<script type="text/javascript"> + var hmap = L.map('map',{ + center: [38.91026,139.84532], + zoom: 14 //1~18 + }); + L.tileLayer('http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',{ + attribution: '© OpenStreetMap contributors' + }).addTo(hmap); +_EOS_ + +for id in data.keys + if data[id][1] == "LON" + next + else + printf(<<_EOS_,data[id][1].to_f,data[id][2].to_f,data[id][0]) + L.marker([%f,%f],{ + clickable:true, + draggable:true, + icon:L.icon({ + iconUrl: 'leaflet/images/face.png', + iconAnchor: [0,0], + popupAnchor: [10,5] + }) + }) + .bindPopup('%s') + .addTo(hmap); +_EOS_ + end +end + +print" +</script> +</body> +</html>\n"
--- a/fujix/redirect.html Thu Nov 06 15:51:21 2014 +0900 +++ b/fujix/redirect.html Sun Nov 09 16:56:30 2014 +0900 @@ -3,8 +3,9 @@ <title>たいとる</title> </head> <script language="javascript"> -time = 2; -url = "http://skip.koeki-prj.org/fujix/map.rb"; +time = 1; + +url = "http://skip.koeki-prj.org/fujix/leaf.rb"; if (navigator.geolocation) { navigator.geolocation.getCurrentPosition( @@ -42,9 +43,9 @@ function jumpPage() { location.href = url; } -setTimeout("jumpPage()",time*500) +setTimeout("jumpPage()",time*1000) </script> <body> -<p>位置情報を取得し直して地図に再表示します</p> +<p>位置情報を取得し直して再表示します</p> </body> </html>