aboutsummaryrefslogtreecommitdiff
path: root/overview.rb
blob: 78225ae3f65132df262e36bfad2a5be4a9b5ed93 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#!/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>
	<td><label title="#{poll_name_tip = "the name equals the link under which you receive the poll"}" for="poll_name">Name:</label></td>
	<td><input title="#{poll_name_tip}" id="poll_name" size='16' type='text' name='create_poll' value='#{$cgi["create_poll"]}' /></td>
</tr>
<tr>
	<td><label for="poll_type">Type:</label></td>
	<td>
		<select id="poll_type" name="poll_type">
			<option value="Poll" selected="selected">normal</option>
			<option value="DatePoll">date</option>
		</select>
	</td>
</tr>
<tr>
	<td><label title="#{hidden_tip = "do not list the poll here (you have to remember the link)"}" for="hidden">Hidden?:</label></td>
	<td><input id="hidden" type="checkbox" name="hidden" value="true" title="#{hidden_tip}"></td>
</tr>
<tr>
	<td colspan='2'><input type='submit' value='create' /></td>
</tr>
</table>
</form>
</fieldset>
CREATE

puts "</body></html>"