#!/usr/local/bin/ruby
#  encoding: utf-8
#  daybook_cont.rb
#
#  Created by midori on 2006-09-24.
#  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_params"
require "owner/d_remake"
require "index/d_index"
#________________________________________
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')

target = para_data['target']# hidden value of admin/daybook_admin.html
id = para_data['bid']
#--------------------------------------
begin
  SAFE = 3
  case target
    when "onlyremake"
     re = HTMLRemake.new(h_base)
     ans = re.remake_onlyfile(id)
    when "allremake"
     re = HTMLRemake.new(h_base)
     ans = re.remake_all
    when "delid"
      # Delete File
      if para_data['no'].to_i > 0
        del = HTMLRemake.new(h_base)
        ans = del.del_no(id, para_data['no'].to_i)
      else
        # Delete PostNO
        del = HTMLRemake.new(h_base)
        ans = del.del_id(id)
      end
    when "rss"
      rss = HTMLRemake.new(h_base)
      ans = rss.rss2
   else
     print "Content-Type: text/html\n\n"
     p target
  end
  
  # index archives admin page Review
  case ans
  when /Success/
    newindex = NewIndex.new(h_base)
    newindex.view_index
    newindex.view_archives
    newindex.view_admin
  end
  
  DaybookPrint.new.custom_print(ans)
rescue
  DaybookPrint.new.error_out
end
#________________________________________
#print "Content-Type: text/html\n\n"
#p ans
