#!/usr/bin/env ruby
#coding:utf-8

require'cgi'
require'sqlite3'

db = SQLite3::Database.new("../sql/stamp.sq3")

c = CGI.new(:accept_charaset => "UTF-8")

flag = 0
text = "<p>登録者一覧を表示します</p>\n"
begin
  result = db.execute("select * from main;")
rescue
  flag = 1
  text = "<p>データがありません</p>\n"
end

printf("Content-type: text/html; charset=UTF-8\n\n")

printf'<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/h
tml4/strict.dtd">
<html>
<head>
<title>Delete table</title>
<link rel="stylesheet" type="text/css" href="design.css">
</head>
</body>
<h1>データ閲覧ページ</h1>'
puts text
if flag == 1
else
  print"<table border = 1>\n"
  result.each do |line|
    printf("<tr><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td></tr>\n",line[0],line[1],line[2],line[3],line[4],line[8],line[9])
  end
 print"</table>"
end

print'</body></html>'
