aboutsummaryrefslogtreecommitdiff
path: root/remove_poll.rb
diff options
context:
space:
mode:
authorBenjamin Kellermann <Benjamin.Kellermann@gmx.de>2009-10-05 23:31:19 +0200
committerBenjamin Kellermann <Benjamin.Kellermann@gmx.de>2009-10-05 23:31:19 +0200
commit9b3a44f070b1355a516849a33d23424416605cf1 (patch)
tree59f0641ccd3e6a3ec267a623860350fa1fef91a5 /remove_poll.rb
parent9349a9182285b4f208143d2c915645e9dcbb06aa (diff)
added feature to remove a poll
Diffstat (limited to 'remove_poll.rb')
-rwxr-xr-xremove_poll.rb90
1 files changed, 90 insertions, 0 deletions
diff --git a/remove_poll.rb b/remove_poll.rb
new file mode 100755
index 0000000..ea0b6ee
--- /dev/null
+++ b/remove_poll.rb
@@ -0,0 +1,90 @@
+#!/usr/bin/env ruby
+
+################################
+# Author: Benjamin Kellermann #
+# License: CC-by-sa 3.0 #
+# see License #
+################################
+
+QUESTIONS = ["Yes, I know what I am doing!",
+ "I hate these stupid entry fields.",
+ "I am aware of the consequences.",
+ "Please delete this poll."]
+
+CONFIRM = rand(QUESTIONS.size)
+
+require "cgi"
+
+if __FILE__ == $0
+
+$cgi = CGI.new
+
+TYPE = "text/html"
+#TYPE = "application/xhtml+xml"
+CHARSET = "utf-8"
+
+POLL = File.basename(File.expand_path("."))
+
+$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>
+ <meta http-equiv="Content-Type" content="#{TYPE}; charset=#{CHARSET}" />
+ <meta http-equiv="Content-Style-Type" content="text/css" />
+ <title>dudle - remove - #{POLL}</title>
+ <link rel="stylesheet" type="text/css" href="../dudle.css" title="default"/>
+</head>
+<body>
+HEAD
+
+if $cgi.include?("confirmnumber")
+ if $cgi["confirm"] == QUESTIONS[$cgi["confirmnumber"].to_i]
+ Dir.chdir("..")
+ `mv #{POLL} /tmp/#{POLL}.#{rand(9999999)}`
+ $htmlout += <<SUCCESS
+<div>
+ The poll was deleted successfully!
+ <br />
+ If this was done by accident, please contact the administrator of the system.
+ The poll can be recovered for an indeterministic amount of time, maybe it is already to late. <br />
+ <a href='../'>home</a>
+</div>
+SUCCESS
+ else
+ $htmlout += <<CANCEL
+<div>
+ You canceld the deletion!
+ <br />
+ <a href='config.cgi'>config</a>
+ <a href='remove.cgi'>remove</a>
+</div>
+CANCEL
+ end
+
+else
+
+$htmlout += <<TABLE
+<div>
+ <h1>Remove a Poll</h1>
+ You want to remove the poll named <b>#{POLL}</b>.<br />
+ This is an irreversible action!<br />
+ If you are sure in what you are doing, please type into the form “#{QUESTIONS[CONFIRM]}”
+ <form method='post' action=''>
+ <div>
+ <input type='hidden' name='confirmnumber' value='#{CONFIRM}' />
+ <input size='30' type='text' name='confirm' />
+ <input type='submit' value='remove' />
+ </div>
+ </form>
+</div>
+TABLE
+end
+
+$htmlout += "</body>"
+
+$htmlout += "</html>"
+
+$cgi.out("type" => TYPE ,"charset" => CHARSET, "Cache-Control" => "no-cache"){$htmlout}
+end
+