aboutsummaryrefslogtreecommitdiff
path: root/index.cgi
blob: 59044787dc7812a136838dc77dfa379d705ec875 (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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#!/usr/bin/env ruby

################################
# Author:  Benjamin Kellermann #
# License: CC-by-sa 3.0        #
#          see License         #
################################

require "yaml"
require "cgi"


if __FILE__ == $0

$cgi = CGI.new

TYPE = "text/html"
#TYPE = "application/xhtml+xml"
CHARSET = "utf-8"

$htmlout = <<HEAD
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
  "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
HEAD

load "charset.rb"
if File.exists?("config.rb")
	load "config.rb"
else
	puts "\nPlease configure me in the file config.rb"
	exit
end

require "poll"
require "datepoll"
require "timepoll"

$htmlout += <<HEAD
<head>
	<title>dudle</title>
	<meta http-equiv="Content-Type" content="#{TYPE}; charset=#{CHARSET}" /> 
	<meta http-equiv="Content-Style-Type" content="text/css" />
	<link rel="stylesheet" type="text/css" href="dudle.css" title="default"/>
HEAD
	
	$htmlout += '<link rel="alternate"  type="application/atom+xml" href="atom.cgi" />' if File.exists?("atom.cgi")

	$htmlout += "</head><body id='main'><h1>dudle</h1>"

if $cgi.include?("create_poll")
	SITE=$cgi["create_poll"].gsub(/^\//,"")
	unless File.exist?(SITE)
		Dir.mkdir(SITE)
		Dir.chdir(SITE)
		VCS.init
		File.symlink("../participate.rb","index.cgi")
		File.symlink("../atom_single.rb","atom.cgi")
		File.symlink("../config_poll.rb","config.cgi")
		File.symlink("../remove_poll.rb","remove.cgi")
		["index.cgi","atom.cgi","config.cgi","remove.cgi"].each{|f|
			VCS.add(f)
		}
		["data.yaml",".htaccess",".htdigest"].each{|f|
			File.open(f,"w").close
			VCS.add(f)
		}
		case $cgi["poll_type"]
		when "normal"
			Poll.new SITE
		when "time"
			TimePoll.new SITE
		end
		Dir.chdir("..")
		$cgi.out("status" => "REDIRECT",
		         "Location" => "#{SITEURL}#{SITE}/",
		         "type" => TYPE,
		         "charset" => CHARSET,
		         "cookie" => $utfcookie,
		         "Cache-Control" => "no-cache"){ 
			"The poll was created successfully. The link to your new poll is:<br /><a href='#{SITEURL}#{SITE}'>#{SITEURL}#{SITE}</a>"
		}
		exit
	else
		createnotice = "<div class='error'>Error: This poll already exists!</div>"
	end
end

$htmlout += <<CHARSET
<div id='config'>
<fieldset><legend>Config</legend>
#{UTFASCII}
</fieldset>
</div>
CHARSET

$htmlout += <<CREATE
<fieldset><legend>Create New Poll</legend>
<form method='post' action='.'>
<table>
<tr>
	<td class='create_poll'><label title="#{poll_name_tip = "the name equals the link under which you receive the poll"}" for="poll_name">Name:</label></td>
	<td class='create_poll'><input title="#{poll_name_tip}" id="poll_name" size='16' type='text' name='create_poll' /></td>
</tr>
<tr>
	<td>Type:</td>
	<td class='create_poll'>
		<input id='chooseTime' type='radio' value='time' name='poll_type' checked='checked' />
		<label for='chooseTime'>Event Schedule Poll (e.g. schedule a meeting)</label>
		<br />
		<input id='chooseNormal' type='radio' value='normal' name='poll_type' />
		<label for='chooseNormal'>Normal Poll (e.g. vote for what is the best coffee)</label>
	</td>
</tr>
<tr>
	<td></td>
	<td class='create_poll'><input type='submit' value='create' /></td>
</tr>
</table>
</form>
#{createnotice}
</fieldset>
CREATE

$htmlout += NOTICE
$htmlout += "</body>"

$htmlout += "</html>"

$cgi.out("type" => TYPE ,"charset" => CHARSET,"cookie" => $utfcookie, "Cache-Control" => "no-cache"){$htmlout}
end