#!/usr/local/bin/ruby
#  encoding: utf-8
#  daybook_comment.rb
#  
#  Created by midori on 2006-09-06.
#  Copyright (c) 2006. All rights reserved.
#  You can distribute/modify this program under the terms of the Ruby License.
#  Last change: 2006-10-23.
#________________________________________ 
require "daybook"
base = MainBase.load('base/daybook_base')
h_base =  base.make_base_hash
#________________________________________ 
require "newpost/d_check"
env = CheckURI.new(h_base)
res = env.daybook_comment_check
raise DaybookPrint.new.custom_print("_error... #{res['error']}")  if res.has_key?('error')

require "newpost/d_params"
cgipara = GetParams.new
para_data = cgipara.get_all_params
raise DaybookPrint.new.custom_print("inputdata_error... #{para_data['error']}")  if para_data.has_key?('error')

require "newpost/d_new"
require "newpost/d_commentmail"
require "index/d_index"
begin
  SAFE = 3
 #-------------------------------------
  mailpost = DaybookCommentMail.new(h_base)
  mailresult = mailpost.comment_sendmail(para_data)

  post = NewPost.new(h_base)
  result = post.post_child(para_data)
  if result.include?("Success")
    newindex = NewIndex.new(h_base)
    newindex.view_index
    newindex.view_archives
    #newindex.view_admin
  end
  
  DaybookPrint.new.custom_print("#{result}")
  #--------------------------------------
rescue
  DaybookPrint.new.error_out
end
#________________________________________ 

