# daily_theme.rb $Revision: 1.2 $
#
# Copyright (c) 2005 SHIBATA Hiroshi <h-sbt@nifty.com>
# Distributed under the GPL
#

def css_tag
   if @mode =~ /conf$/ then
      css = "#{theme_url}/conf.css"
   elsif @conf.options.include?('daily_theme.list')
      if @conf.options['daily_theme.list'].size > 0
         theme_list = @conf.options['daily_theme.list'].split(/\n/)
         
         index = Time.now.yday % theme_list.size
         theme_name = theme_list[index].strip
         
         css = "#{theme_url}/#{theme_name}/#{theme_name}.css"
      else
         css = @css
      end
   else
      css = @css
   end
      
   title = CGI::escapeHTML( File::basename( css, '.css' ) )
   <<-CSS
   <link rel="stylesheet" href="#{theme_url}/base.css" type="text/css" media="all">
   <link rel="stylesheet" href="#{css}" title="#{title}" type="text/css" media="all">
   CSS
   
end

add_conf_proc( 'daily_theme', @daily_theme_label, 'theme' ) do
   daily_theme_conf_proc
end
def daily_theme_conf_proc
   if @mode == 'saveconf' then
      if @cgi.params['daily_theme.list'] && @cgi.params['daily_theme.list'][0]
         @conf['daily_theme.list'] = @cgi.params['daily_theme.list'][0]
      else
         @conf['daily_theme.list'] = nil
      end
      
	end
   
   # initialize Theme list
   @conf['daily_theme.list'] = "default" unless @conf['daily_theme.list']
   
	result = <<-HTML
   <h3>#{@daily_theme_label}</h3>
   <p>#{@daily_theme_label_desc}</p>
   <p><textarea name="daily_theme.list" cols="70" rows="20">#{CGI::escapeHTML( @conf['daily_theme.list'] )}</textarea></p>
	HTML
end
