<commit_before>#!/usr/bin/env ruby
load "/home/ben/src/lib.rb/pphtml.rb"
require "pp"
require "yaml"
require "cgi"
require "date"
require "poll"

puts <<HEAD
<head>
<title>dudle</title>
<link rel="alternate"  type="application/atom+xml" href="atom.cgi" />
</head>
<body>
HEAD

if $cgi.include?("create_poll")
	SITE=$cgi["create_poll"]
	unless File.exist?(SITE)
		Dir.mkdir(SITE)
		Dir.chdir(SITE)
		`bzr init`
		File.symlink("../index.cgi","index.cgi")
		File.symlink("../atom.cgi","atom.cgi")
		File.open("data.yaml","w").close
		`bzr add data.yaml`
		hidden = ($cgi["hidden"] == "true")
		case $cgi["poll_type"]
		when "Poll"
			Poll.new SITE, hidden
		when "DatePoll"
			DatePoll.new SITE, hidden
		end
		Dir.chdir("..")
		if hidden
			puts <<HIDDENINFO
<fieldset>
<legend>Info</legend>
Poll #{SITE} created successfull!
<br />
Please remember the url (<a href="#{SITE}">#{$cgi.server_name}#{$cgi.script_name.gsub(/index.cgi$/,"")}#{SITE}</a>) while it will not be visible here.
</fieldset>
HIDDENINFO
		end
	else
		puts "<fieldset><legend>Error</legend>This poll already exists!</fieldset>"
	end
end

puts "<fieldset><legend>Available Polls</legend>"
puts "<table><tr><th>Poll</th><th>Last change</th></tr>"
Dir.glob("*/data.yaml").sort_by{|f|
	File.new(f).mtime
}.reverse.collect{|f| 
	f.gsub(/\/data\.yaml$/,'')
}.each{|site|
	unless YAML::load_file("#{site}/data.yaml" ).hidden
		puts "<tr>"
		puts "<td class='site'><a href='#{site}'>#{site}</a></td>"
		puts "<td class='mtime'>#{File.new(site + "/data.yaml").mtime.strftime('%d.%m, %H:%M')}</td>"
		puts "</tr>"
	end
}
puts "</table>"
puts "</fieldset>"

puts <<CHARSET
<fieldset><legend>change charset</legend>
#{UTFASCII}
</fieldset>
CHARSET

puts <<CREATE
<fieldset><legend>Create new Poll</legend>
<form method='post' action='.'>
<table>
<tr><commit_msg>bugfix: forgot to require datepoll<commit_after>#!/usr/bin/env ruby
load "/home/ben/src/lib.rb/pphtml.rb"
require "pp"
require "yaml"
require "cgi"
require "poll"
require "datepoll"

puts <<HEAD
<head>
<title>dudle</title>
<link rel="alternate"  type="application/atom+xml" href="atom.cgi" />
</head>
<body>
HEAD

if $cgi.include?("create_poll")
	SITE=$cgi["create_poll"]
	unless File.exist?(SITE)
		Dir.mkdir(SITE)
		Dir.chdir(SITE)
		`bzr init`
		File.symlink("../index.cgi","index.cgi")
		File.symlink("../atom.cgi","atom.cgi")
		File.open("data.yaml","w").close
		`bzr add data.yaml`
		hidden = ($cgi["hidden"] == "true")
		case $cgi["poll_type"]
		when "Poll"
			Poll.new SITE, hidden
		when "DatePoll"
			DatePoll.new SITE, hidden
		end
		Dir.chdir("..")
		if hidden
			puts <<HIDDENINFO
<fieldset>
<legend>Info</legend>
Poll #{SITE} created successfull!
<br />
Please remember the url (<a href="#{SITE}">#{$cgi.server_name}#{$cgi.script_name.gsub(/index.cgi$/,"")}#{SITE}</a>) while it will not be visible here.
</fieldset>
HIDDENINFO
		end
	else
		puts "<fieldset><legend>Error</legend>This poll already exists!</fieldset>"
	end
end

puts "<fieldset><legend>Available Polls</legend>"
puts "<table><tr><th>Poll</th><th>Last change</th></tr>"
Dir.glob("*/data.yaml").sort_by{|f|
	File.new(f).mtime
}.reverse.collect{|f| 
	f.gsub(/\/data\.yaml$/,'')
}.each{|site|
	unless YAML::load_file("#{site}/data.yaml").hidden
		puts "<tr>"
		puts "<td class='site'><a href='#{site}'>#{site}</a></td>"
		puts "<td class='mtime'>#{File.new(site + "/data.yaml").mtime.strftime('%d.%m, %H:%M')}</td>"
		puts "</tr>"
	end
}
puts "</table>"
puts "</fieldset>"

puts <<CHARSET
<fieldset><legend>change charset</legend>
#{UTFASCII}
</fieldset>
CHARSET

puts <<CREATE
<fieldset><legend>Create new Poll</legend>
<form method='post' action='.'>
<table>
<tr>
{'fraction_non_alphanumeric': 0.22772006560962274, 'fraction_numerical': 0.0, 'mean_word_length': 5.0180921052631575, 'pattern_counts': {'":': 0, '<': 113, '<?xml version=': 0, '>': 97, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5161888', 'n_tokens_mistral': 1591, 'n_tokens_neox': 1458, 'n_words': 284}