################################
# Author: Benjamin Kellermann #
# License: CC-by-sa 3.0 #
# see License #
################################
require "date"
require "poll"
class DatePoll < Poll
def sort_data fields
datefields = fields.collect{|field|
field == "timestamp" || field == "name" ? field : Date.parse(field)
}
super datefields
end
def head_to_html(config = false, activecolumn = nil)
ret = "
| \n"
monthhead = Hash.new(0)
@head.sort.each{|curdate,curdescription|
monthhead["#{curdate.year}-#{curdate.mon.to_s.rjust(2,"0")} "] += 1
}
monthhead.sort.each{|title,count|
year, month = title.split("-").collect{|e| e.to_i}
ret += "#{Date::ABBR_MONTHNAMES[month]} #{year} | \n"
}
ret += "
---|
Name | \n"
@head.sort.each{|curdate,curdescription|
ret += "#{Date::ABBR_DAYNAMES[curdate.wday]}, #{curdate.day} | \n"
}
ret += "Last Edit | \n
\n"
ret
end
def edit_column_htmlform(activecolumn)
if $cgi.include?("add_remove_column_month")
if $cgi.params["add_remove_column_month"].size == 1
startdate = Date.parse("#{$cgi["add_remove_column_month"]}-1")
else
olddate = $cgi.params["add_remove_column_month"][1]
case $cgi["add_remove_column_month"]
when CGI.unescapeHTML(YEARBACK)
startdate = Date.parse("#{olddate}-1")-365
when CGI.unescapeHTML(MONTHBACK)
startdate = Date.parse("#{olddate}-1")-1
when CGI.unescapeHTML(MONTHFORWARD)
startdate = Date.parse("#{olddate}-1")+31
when CGI.unescapeHTML(YEARFORWARD)
startdate = Date.parse("#{olddate}-1")+366
else
exit
end
startdate = Date.parse("#{startdate.year}-#{startdate.month}-1")
end
else
startdate = Date.parse("#{Date.today.year}-#{Date.today.month}-1")
end
ret = <
END
ret
end
def parsecolumntitle(title)
Date.parse("#{$cgi["add_remove_column_month"]}-#{title}")
end
def edit_column(newtitle, description, oldtitle = nil)
parsed_date = parsecolumntitle(newtitle)
if @head.include?(parsed_date)
delete_column(newtitle)
else
@head[parsed_date] = ""
store "Column #{parsed_date} added"
end
true
end
end