#!/usr/bin/env ruby
# -*- coding: utf-8 -*-
require 'cgi'
require 'json'
#moare = "moare.js"
#bchu = "bchu.js"
c = CGI.new
s = c['shop']
name = c['name']
star = c['star']
comment = c['comment']
sjs = ''
inputs = {}
if s == "moare"
sjs = 'moare.json'
elsif s == "bchu"
sjs = 'bchu.json'
end
if star.to_i == 0
star = 3
elsif star.to_i > 5
star = 5
elsif star.to_i < 1
star = 1
end
#p sjs
data = File.open(sjs) do |io|
JSON.load(io)
end
inputs["name"] = name
inputs["star"] = star
inputs["comment"] = comment
if name != "" && star != "" && comment != ""
data.unshift(inputs)
end
poi = File.open(sjs, "w") do |file|
str = JSON.dump(data, file)
end
#sleep(3)
print "Content-type: text/plain; charset=UTF-8\n\n"
#puts "#{s},#{name},#{star},#{comment}"
puts JSON.pretty_generate(data)