diff options
author | Benjamin Kellermann <Benjamin.Kellermann@gmx.de> | 2009-11-20 10:31:24 +0100 |
---|---|---|
committer | Benjamin Kellermann <Benjamin.Kellermann@gmx.de> | 2009-11-20 10:31:24 +0100 |
commit | 47988b9d4bccb0b6145e1d2cf7462879576f6521 (patch) | |
tree | ecef7de7aaf995f544a3e711524c36ac1a2bfe46 | |
parent | c3d97c3944186d3ad08bcd50b496f3e64ebd8c3b (diff) |
changed interface to many tabs
-rwxr-xr-x | access_control.rb | 163 | ||||
-rw-r--r-- | charset.rb | 5 | ||||
-rwxr-xr-x | config_poll.rb | 225 | ||||
-rwxr-xr-x | customize.rb | 71 | ||||
-rwxr-xr-x | delete_poll.rb (renamed from remove_poll.rb) | 45 | ||||
-rw-r--r-- | dudle.css | 5 | ||||
-rwxr-xr-x | edit_columns.rb | 76 | ||||
-rwxr-xr-x | history.rb | 49 | ||||
-rw-r--r-- | html.rb | 7 | ||||
-rwxr-xr-x | index.cgi | 16 | ||||
-rwxr-xr-x | participate.rb | 41 | ||||
-rw-r--r-- | poll.rb | 50 | ||||
-rw-r--r-- | pollhead.rb | 9 | ||||
-rw-r--r-- | timepollhead.rb | 28 |
14 files changed, 446 insertions, 344 deletions
diff --git a/access_control.rb b/access_control.rb new file mode 100755 index 0000000..7251bdc --- /dev/null +++ b/access_control.rb @@ -0,0 +1,163 @@ +#!/usr/bin/env ruby + +################################ +# Author: Benjamin Kellermann # +# License: CC-by-sa 3.0 # +# see License # +################################ + +require "cgi" + +if __FILE__ == $0 + +$cgi = CGI.new + +load "../html.rb" + +acusers = {} + +File.open(".htdigest","r").each_line{|l| + user,realm = l.scan(/^(.*):(.*):.*$/).flatten + acusers[user] = realm +} + +def writehtaccess(acusers) + File.open(".htaccess","w"){|htaccess| + if acusers.values.include?("config") + htaccess << <<HTACCESS +<Files ~ "^(config|remove).cgi$"> +AuthType digest +AuthName "config" +AuthUserFile "#{File.expand_path(".").gsub('"','\\\\"')}/.htdigest" +Require valid-user +</Files> +HTACCESS + end + if acusers.values.include?("vote") + htaccess << <<HTACCESS +AuthType digest +AuthName "vote" +AuthUserFile "#{File.expand_path(".").gsub('"','\\\\"')}/.htdigest" +Require valid-user +HTACCESS + VCS.commit("Access Control changed") + end + } +end + +if $cgi.include?("ac_user") + user = $cgi["ac_user"] + type = $cgi["ac_type"] + if !(user =~ /^[\w]*$/) + # add user + + usercreatenotice = "<div class='error'>Only uppercase, lowercase, digits are allowed in the username.</div>" + elsif $cgi["ac_password1"] != $cgi["ac_password2"] + usercreatenotice = "<div class='error'>Passwords do not match.</div>" + else + if $cgi.include?("ac_create") + if type == "config" || type == "vote" + fork { + IO.popen("htdigest .htdigest #{type} #{user}","w+"){|htdigest| + htdigest.sync + htdigest.puts($cgi["ac_password1"]) + htdigest.puts($cgi["ac_password2"]) + } + } + acusers[user] = type + writehtaccess(acusers) + end + end + + # delete user + deleteuser = "" + deleteaction = "" + acusers.each{|user,action| + if $cgi.include?("ac_delete_#{user}_#{action}") + deleteuser = user + deleteaction = action + end + } + acusers.delete(deleteuser) + htdigest = [] + File.open(".htdigest","r"){|file| + htdigest = file.readlines + } + File.open(".htdigest","w"){|f| + htdigest.each{|line| + f << line unless line =~ /^#{deleteuser}:#{deleteaction}:/ + } + } + writehtaccess(acusers) + end +end + +$html = HTML.new("dudle - Access Control Settings") +$html.header["Cache-Control"] = "no-cache" +load "../charset.rb" +$html.add_css("../dudle.css") + +$html << "<body>" +$html << Dudle::tabs("Access Control") + +$html << <<TABLE + <div id='main'> +TABLE + +# ACCESS CONTROL +$accesslevels = { "vote" => "Vote Interface", "config" => "Config Interface" } +$html << <<ACL +<div id='access_control'> + <h1>Change Access Control Settings</h1> + <form method='post' action=''> + <table> + <tr> + <th>Access to</th><th>Username</th><th>Password</th><th>Password (repeat)</th> + </tr> +ACL +acusers.each{|user,action| + $html << <<USER +<tr> + <td>#{$accesslevels[action]}</td> + <td>#{user}</td> + <td>*****************</td> + <td>*****************</td> + <td> + <input type='submit' name='ac_delete_#{user}_#{action}' value='delete' /> + </td> +</tr> +USER +} + +$html << <<ACL +<tr> + <td> + <select name='ac_type'> +ACL + $accesslevels.each{|action,description| + $html << "<option value='#{action}'>#{description}</option>" + } + $html << <<ACL + </select> + </td> + <td><input size='6' value="" type='text' name='ac_user' /></td> + <td><input size='6' value="" type='password' name='ac_password1' /></td> + <td><input size='6' value="" type='password' name='ac_password2' /></td> + <td> + <input type='submit' name='ac_create' value='Add' /> + </td> +</tr> +ACL + +$html << <<ACL + </table> + </form> + #{usercreatenotice} +</div> +ACL + +$html << "</div></body>" + +$html.out($cgi) +end + @@ -6,7 +6,6 @@ if ($cgi.include?("utf") || $cgi.cookies["utf"][0]) && !$cgi.include?("ascii") expiretime = Time.now+1*60*60*24*365 - UTFASCII = "<a href='?ascii' style='text-decoration:none'>Change Charset to plain ASCII</a>" YES = CGI.escapeHTML('✔') NO = CGI.escapeHTML('✘') @@ -22,7 +21,6 @@ if ($cgi.include?("utf") || $cgi.cookies["utf"][0]) && !$cgi.include?("ascii") DELETE = CGI.escapeHTML("⌧") else expiretime = Time.now-1*60*60*24*36 - UTFASCII = "<a href='?utf' style='text-decoration:none'>If you see all these characters: #{CGI.escapeHTML('✔✘?–↞←→↠✍⌧')} you can safely change the charset to UTF-8</a>" YES = CGI.escapeHTML('OK') NO = CGI.escapeHTML('NO') @@ -37,4 +35,7 @@ else EDIT = CGI.escapeHTML("edit") DELETE = CGI.escapeHTML("delete") end + +UTFCHARS = [YES,NO,MAYBE,UNKNOWN,YEARBACK,MONTHBACK,MONTHFORWARD,YEARFORWARD,EDIT,DELETE] + $html.add_cookie("utf","true","/",expiretime) diff --git a/config_poll.rb b/config_poll.rb deleted file mode 100755 index 65484df..0000000 --- a/config_poll.rb +++ /dev/null @@ -1,225 +0,0 @@ -#!/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 - -olddir = File.expand_path(".") -Dir.chdir("..") -require "html" -load "config.rb" -require "poll" -Dir.chdir(olddir) -# BUGFIX for Time.parse, which handles the zone indeterministically -class << Time - alias_method :old_parse, :parse - def Time.parse(date, now=self.now) - Time.old_parse("2009-10-25 00:30") - Time.old_parse(date) - end -end - -acusers = {} - -if $cgi.include?("revision") - REVISION=$cgi["revision"].to_i - table = YAML::load(VCS.cat(REVISION, "data.yaml")) - VCS.cat(REVISION,".htdigest").each_line{|l| - v,k = l.scan(/^(.*):(.*):.*$/).flatten - acusers[k] = v - } -else - table = YAML::load_file("data.yaml") - File.open(".htdigest","r").each_line{|l| - user,realm = l.scan(/^(.*):(.*):.*$/).flatten - acusers[user] = realm - } - - if $cgi.include?("add_participant") - if $cgi.include?("delete_participant") - table.delete($cgi["olduser"]) - else - table.add_participant($cgi["olduser"],$cgi["add_participant"],{}) - end - end - table.edit_column($cgi["columnid"],$cgi["new_columnname"],$cgi) if $cgi.include?("new_columnname") - table.delete_column($cgi["deletecolumn"]) if $cgi.include?("deletecolumn") - - def writehtaccess(acusers) - File.open(".htaccess","w"){|htaccess| - if acusers.values.include?("config") - htaccess << <<HTACCESS -<Files ~ "^(config|remove).cgi$"> - AuthType digest - AuthName "config" - AuthUserFile "#{File.expand_path(".").gsub('"','\\\\"')}/.htdigest" - Require valid-user -</Files> -HTACCESS - end - if acusers.values.include?("vote") - htaccess << <<HTACCESS -AuthType digest -AuthName "vote" -AuthUserFile "#{File.expand_path(".").gsub('"','\\\\"')}/.htdigest" -Require valid-user -HTACCESS - VCS.commit("Access Control changed") - end - } - end - - if $cgi.include?("ac_user") - user = $cgi["ac_user"] - type = $cgi["ac_type"] - if !(user =~ /^[\w]*$/) - # add user - - usercreatenotice = "<div class='error'>Only uppercase, lowercase, digits are allowed in the username.</div>" - elsif $cgi["ac_password1"] != $cgi["ac_password2"] - usercreatenotice = "<div class='error'>Passwords do not match.</div>" - else - if $cgi.include?("ac_create") - if type == "config" || type == "vote" - fork { - IO.popen("htdigest .htdigest #{type} #{user}","w+"){|htdigest| - htdigest.sync - htdigest.puts($cgi["ac_password1"]) - htdigest.puts($cgi["ac_password2"]) - } - } - acusers[user] = type - writehtaccess(acusers) - end - end - - # delete user - deleteuser = "" - deleteaction = "" - acusers.each{|user,action| - if $cgi.include?("ac_delete_#{user}_#{action}") - deleteuser = user - deleteaction = action - end - } - acusers.delete(deleteuser) - htdigest = [] - File.open(".htdigest","r"){|file| - htdigest = file.readlines - } - File.open(".htdigest","w"){|f| - htdigest.each{|line| - f << line unless line =~ /^#{deleteuser}:#{deleteaction}:/ - } - } - writehtaccess(acusers) - end - end -end - -$html = HTML.new("dudle - Administration - #{table.name}") -$html.header["Cache-Control"] = "no-cache" -load "../charset.rb" -$html.add_css("../dudle.css") - -$html << "<body" -$html << Dudle::tabs("Admin") - -$html << <<TABLE - <div id='main'> - <h1>#{table.name}</h1> - <form method='post' action='config.cgi'> - #{table.to_html($cgi["edituser"],true,$cgi["editcolumn"])} - </form> -TABLE - -# ADD/REMOVE COLUMN -$html << <<ADD_EDIT -<div id='edit_column'> -#{table.edit_column_htmlform($cgi["editcolumn"])} -</div> -ADD_EDIT - -# ACCESS CONTROL -$accesslevels = { "vote" => "Vote Interface", "config" => "Config Interface" } -$html << <<ACL -<div id='access_control'> - <fieldset> - <legend>Change Access Control Settings</legend> - <form method='post' action=''> - <table> - <tr> - <th>Access to</th><th>Username</th><th>Password</th><th>Password (repeat)</th> - </tr> -ACL -acusers.each{|user,action| - $html << <<USER -<tr> - <td>#{$accesslevels[action]}</td> - <td>#{user}</td> - <td>*****************</td> - <td>*****************</td> - <td> - <input type='submit' name='ac_delete_#{user}_#{action}' value='delete' /> - </td> -</tr> -USER -} - -$html << <<ACL -<tr> - <td> - <select name='ac_type'> -ACL - $accesslevels.each{|action,description| - $html << "<option value='#{action}'>#{description}</option>" - } - $html << <<ACL - </select> - </td> - <td><input size='6' value="" type='text' name='ac_user' /></td> - <td><input size='6' value="" type='password' name='ac_password1' /></td> - <td><input size='6' value="" type='password' name='ac_password2' /></td> - <td> - <input type='submit' name='ac_create' value='Add' /> - </td> -</tr> -ACL - -$html << <<ACL - </table> - </form> - #{usercreatenotice} - </fieldset> -</div> -ACL - -$html << <<REMOVE -<div id='delete_poll'> - <fieldset> - <legend>Delete the Whole Poll</legend> - <form method='post' action='remove.cgi'> - <div> - Warning: This is an irreversible action!<br /> - <input type='submit' value='Delete' /> - </div> - </form> - </fieldset> -</div> -REMOVE - -$html << "</div></body>" - -$html.out($cgi) -end - diff --git a/customize.rb b/customize.rb new file mode 100755 index 0000000..0bd685d --- /dev/null +++ b/customize.rb @@ -0,0 +1,71 @@ +#!/usr/bin/env ruby + +################################ +# Author: Benjamin Kellermann # +# License: CC-by-sa 3.0 # +# see License # +################################ + +require "cgi" + +if __FILE__ == $0 + +$cgi = CGI.new +load "../html.rb" +$html = HTML.new("dudle - Customize") +load "../charset.rb" + +$html.header["Cache-Control"] = "no-cache" + +$html.add_css("../dudle.css") + +$html << "<body>" +$html << Dudle::tabs("Customize") +$html << "<div id='main'>" +$html << "<h1>Customize Personal Settings</h1>" + +$html << <<CHARSET +<div id='charset'> +<h2>Charset</h2> +<ul> +<li><a href='?utf' style='text-decoration:none'>If you see all these characters: #{UTFCHARS} you can safely change the charset to UTF-8</a></li> +<li><a href='?ascii' style='text-decoration:none'>Change Charset to plain ASCII</a></li> +</ul> +</div> +CHARSET + +$html << <<CHARSET +<div id='config_stylesheet'> +<h2>Stylesheet</h2> +<ul> +CHARSET +[["default","dudle.css"], + ["PrimeLife","primelife.css"], + ["TU Dresden","tud.css"]].each{|descr,cssfile| + $html << "<li><a href='?css=#{cssfile}'>#{descr}</a></li>" +} +$html << <<CHARSET +</ul> +</div> +CHARSET + +$html << <<CHARSET +<div id='config_user'> +<h2>Default Username</h2> +<form method='post' action=''> + <div> + <label for=''>Username: </label> + <input id='' size='16' type='text' value="" name='default_username' /> + <input type='submit' value='Save' /> + </div> +</form> +</div> +CHARSET + +$html << "</div>" +$html << "</body>" + +$html.out($cgi) +end + + diff --git a/remove_poll.rb b/delete_poll.rb index 542303d..cc472bf 100755 --- a/remove_poll.rb +++ b/delete_poll.rb @@ -18,34 +18,24 @@ require "ftools" if __FILE__ == $0 +POLL = File.basename(File.expand_path(".")) $cgi = CGI.new -$header = {} +load "../html.rb" +$html = HTML.new("dudle - Delete - #{POLL}") -$header["type"] = "text/html" -#$header["type"] = "application/xhtml+xml" -$header["charset"] = "utf-8" +$html.header["Cache-Control"] = "no-cache" -POLL = File.basename(File.expand_path(".")) +$html.add_css("../dudle.css") -$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="#{$header["type"]}; charset=#{$header["charset"]}" /> - <meta http-equiv="Content-Style-Type" content="text/css" /> - <title>dudle - delete - #{POLL}</title> - <link rel="stylesheet" type="text/css" href="../dudle.css" title="default"/> -</head> -<body id='main'> -HEAD +$html << "<body>" +$html << Dudle::tabs("Delete Poll") +$html << "<div id='main'>" if $cgi.include?("confirmnumber") if $cgi["confirm"] == QUESTIONS[$cgi["confirmnumber"].to_i] Dir.chdir("..") File.move(POLL, "/tmp/#{POLL}.#{rand(9999999)}") - $htmlout += <<SUCCESS -<div> + $html << <<SUCCESS The poll was deleted successfully! <br /> If this was done by accident, please contact the administrator of the system. @@ -54,21 +44,17 @@ if $cgi.include?("confirmnumber") </div> SUCCESS else - $htmlout += <<CANCEL -<div> + $html << <<CANCEL You canceld the deletion! - <br /> - <a href='config.cgi'>config</a> - <a href='remove.cgi'>delete</a> </div> CANCEL end else -$htmlout += <<TABLE +$html << <<TABLE <div> - <h1>Delete a Poll</h1> + <h1>Delete this Poll</h1> You want to delete 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]}” @@ -83,11 +69,8 @@ $htmlout += <<TABLE TABLE end -$htmlout += "</body>" - -$htmlout += "</html>" +$html << "</body>" -$header["Cache-Control"] = "no-cache" -$cgi.out($header){$htmlout} +$html.out($cgi) end @@ -174,9 +174,4 @@ h1 { div.comment { margin-top: 1ex; } -div#config{ - float: right; - margin-left:20px; - width:20ex; -} diff --git a/edit_columns.rb b/edit_columns.rb new file mode 100755 index 0000000..4f87269 --- /dev/null +++ b/edit_columns.rb @@ -0,0 +1,76 @@ +#!/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 + +olddir = File.expand_path(".") +Dir.chdir("..") +require "html" +load "config.rb" +require "poll" +Dir.chdir(olddir) +# BUGFIX for Time.parse, which handles the zone indeterministically +class << Time + alias_method :old_parse, :parse + def Time.parse(date, now=self.now) + Time.old_parse("2009-10-25 00:30") + Time.old_parse(date) + end +end + +acusers = {} + +if $cgi.include?("revision") + REVISION=$cgi["revision"].to_i + table = YAML::load(VCS.cat(REVISION, "data.yaml")) +else + table = YAML::load_file("data.yaml") + + if $cgi.include?("add_participant") + if $cgi.include?("delete_participant") + table.delete($cgi["olduser"]) + else + table.add_participant($cgi["olduser"],$cgi["add_participant"],{}) + end + end + table.edit_column($cgi["columnid"],$cgi["new_columnname"],$cgi) if $cgi.include?("new_columnname") + table.delete_column($cgi["deletecolumn"]) if $cgi.include?("deletecolumn") + +end + +$html = HTML.new("dudle - Edit Columns - #{table.name}") +$html.header["Cache-Control"] = "no-cache" +load "../charset.rb" +$html.add_css("../dudle.css") + +$html << "<body>" +$html << Dudle::tabs("Edit Columns") + +$html << <<TABLE + <div id='main'> + <h1>Add and Remove Columns</h1> +TABLE + +# ADD/REMOVE COLUMN +$html << <<ADD_EDIT + <div id='edit_column'> + #{table.edit_column_htmlform($cgi["editcolumn"])} + </div> +ADD_EDIT + +$html << "</body>" + +$html.out($cgi) +end + diff --git a/history.rb b/history.rb new file mode 100755 index 0000000..88fd0ee --- /dev/null +++ b/history.rb @@ -0,0 +1,49 @@ +#!/usr/bin/env ruby + +################################ +# Author: Benjamin Kellermann # +# License: CC-by-sa 3.0 # +# see License # +################################ + +require "cgi" +require "yaml" + +if __FILE__ == $0 + +$cgi = CGI.new + +olddir = File.expand_path(".") +Dir.chdir("..") +require "html" +require "poll" +load "config.rb" +Dir.chdir(olddir) + +if $cgi.include?("revision") + REVISION=$cgi["revision"].to_i + table = YAML::load(VCS.cat(REVISION, "data.yaml")) +else + table = YAML::load_file("data.yaml") +end + +$html = HTML.new("dudle - #{table.name} - History") +$html.header["Cache-Control"] = "no-cache" +load "../charset.rb" +$html.add_css("../dudle.css") + +$html << "<body>" +$html << Dudle::tabs("Access Control") + +$html << <<TABLE + <div id='main'> + <h1>History</h1> +TABLE + + +$html << "<p id='history'>history:#{table.history_to_html}</p>" +$html << table.to_html +$html << "</div></body>" + +$html.out($cgi) +end @@ -70,8 +70,13 @@ module Dudle def Dudle.tabs(active_tab) ret = "<div id='tabs'><ul>" [["Home",".."], + ["Customize","customize.cgi"], ["Poll","."], - ["Admin","config.cgi"]].each{|tab,file| + ["History","history.cgi"], + ["Edit Columns","edit_columns.cgi"], + ["Access Control","access_control.cgi"], + ["Delete Poll","delete_poll.cgi"] + ].each{|tab,file| if tab == active_tab ret += "<li id='active_tab' > #{tab} </li> " else @@ -40,11 +40,10 @@ if $cgi.include?("create_poll") Dir.chdir(SITE) VCS.init File.symlink("../participate.rb","index.cgi") - File.symlink("../atom.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) + VCS.add("index.cgi") + ["atom","customize", "history", "edit_columns","access_control", "delete_poll"].each{|f| + File.symlink("../#{f}.rb","#{f}.cgi") + VCS.add("#{f}.cgi") } ["data.yaml",".htaccess",".htdigest"].each{|f| File.open(f,"w").close @@ -61,13 +60,6 @@ if $cgi.include?("create_poll") end unless $html.header["status"] == "REDIRECT" - $html << <<CHARSET -<div id='config'> -<fieldset><legend>Config</legend> -#{UTFASCII} -</fieldset> -</div> -CHARSET $html << <<CREATE <fieldset><legend>Create New Poll</legend> diff --git a/participate.rb b/participate.rb index 1bafd30..1ba7c8d 100755 --- a/participate.rb +++ b/participate.rb @@ -21,30 +21,26 @@ require "poll" load "config.rb" Dir.chdir(olddir) -if $cgi.include?("revision") - REVISION=$cgi["revision"].to_i - table = YAML::load(VCS.cat(REVISION, "data.yaml")) -else - table = YAML::load_file("data.yaml") - - if $cgi.include?("add_participant") - if $cgi.include?("delete_participant") - table.delete($cgi["olduser"]) - else - agreed = {} - $cgi.params.each{|k,v| - if k =~ /^add_participant_checked_/ - agreed[k.gsub(/^add_participant_checked_/,"")] = v[0] - end - } - - table.add_participant($cgi["olduser"],$cgi["add_participant"],agreed) - end +table = YAML::load_file("data.yaml") + +if $cgi.include?("add_participant") + if $cgi.include?("delete_participant") + table.delete($cgi["olduser"]) + else + agreed = {} + $cgi.params.each{|k,v| + if k =~ /^add_participant_checked_/ + agreed[k.gsub(/^add_participant_checked_/,"")] = v[0] + end + } + + table.add_participant($cgi["olduser"],$cgi["add_participant"],agreed) end - - table.add_comment($cgi["commentname"],$cgi["comment"]) if $cgi["comment"] != "" - table.delete_comment($cgi["delete_comment"].to_i) if $cgi.include?("delete_comment") end + +table.add_comment($cgi["commentname"],$cgi["comment"]) if $cgi["comment"] != "" +table.delete_comment($cgi["delete_comment"].to_i) if $cgi.include?("delete_comment") + $html = HTML.new("dudle - #{table.name}") $html.header["Cache-Control"] = "no-cache" load "../charset.rb" @@ -86,7 +82,6 @@ if VCS.revno == 1 HINT else $html << <<TABLE -<p id='history'>history:#{table.history_to_html}</p> <h1>#{table.name}</h1> <div id='polltable'> <form method='post' action='.'> @@ -47,13 +47,13 @@ class Poll end end - def to_html(edituser = "", config = false,activecolumn = nil) + def to_html(edituser = "", activecolumn = nil) ret = "<table border='1'>\n" - ret += @head.to_html(config, activecolumn) + ret += @head.to_html(activecolumn) sort_data($cgi.include?("sort") ? $cgi.params["sort"] : ["timestamp"]).each{|participant,poll| if edituser == participant - ret += participate_to_html(edituser, config) + ret += participate_to_html(edituser) else ret += "<tr class='participantrow'>\n" ret += "<td class='name' #{edituser == participant ? "id='active'":""}>" @@ -81,7 +81,7 @@ class Poll } # PARTICIPATE - ret += participate_to_html(edituser, config) unless @data.keys.include?(edituser) + ret += participate_to_html(edituser) unless @data.keys.include?(edituser) # SUMMARY ret += "<tr id='summary'><td class='name'>total</td>\n" @@ -124,7 +124,7 @@ class Poll ret end - def participate_to_html(edituser, config) + def participate_to_html(edituser) checked = {} if @data.include?(edituser) @head.each_columnid{|k| checked[k] = @data[edituser][k]} @@ -139,29 +139,25 @@ class Poll name='add_participant' value=\"#{edituser}\"/>" ret += "</td>\n" - unless config - @head.each_column{|columnid,columntitle| - ret += "<td class='checkboxes'><table class='checkboxes'>" - [[YES, YESVAL],[NO, NOVAL],[MAYBE, MAYBEVAL]].each{|valhuman, valbinary| - ret += "<tr class='input-#{valbinary}'> - <td class='input-#{valbinary}'> - <input type='radio' - value='#{valbinary}' - id=\"add_participant_checked_#{CGI.escapeHTML(columnid.to_s.gsub(" ","_").gsub("+","_"))}_#{valbinary}\" - name=\"add_participant_checked_#{CGI.escapeHTML(columnid.to_s)}\" - title=\"#{CGI.escapeHTML(columntitle.to_s)}\" #{checked[columnid] == valbinary ? "checked='checked'":""}/> - </td> - <td class='input-#{valbinary}'> - <label for=\"add_participant_checked_#{CGI.escapeHTML(columnid.to_s.gsub(" ","_").gsub("+","_"))}_#{valbinary}\">#{valhuman}</label> - </td> - </tr>" - } - ret += "</table></td>" + @head.each_column{|columnid,columntitle| + ret += "<td class='checkboxes'><table class='checkboxes'>" + [[YES, YESVAL],[NO, NOVAL],[MAYBE, MAYBEVAL]].each{|valhuman, valbinary| + ret += "<tr class='input-#{valbinary}'> + <td class='input-#{valbinary}'> + <input type='radio' + value='#{valbinary}' + id=\"add_participant_checked_#{CGI.escapeHTML(columnid.to_s.gsub(" ","_").gsub("+","_"))}_#{valbinary}\" + name=\"add_participant_checked_#{CGI.escapeHTML(columnid.to_s)}\" + title=\"#{CGI.escapeHTML(columntitle.to_s)}\" #{checked[columnid] == valbinary ? "checked='checked'":""}/> + </td> + <td class='input-#{valbinary}'> + <label for=\"add_participant_checked_#{CGI.escapeHTML(columnid.to_s.gsub(" ","_").gsub("+","_"))}_#{valbinary}\">#{valhuman}</label> + </td> + </tr>" } - ret += "<td class='date'>" - else - ret += "<td class='date' colspan='#{@head.col_size + 1}'>" - end + ret += "</table></td>" + } + ret += "<td class='date'>" if @data.include?(edituser) ret += "<input type='submit' value='Save Changes' />" ret += "<br /><input style='margin-top:1ex' type='submit' name='delete_participant' value='Delete User' />" diff --git a/pollhead.rb b/pollhead.rb index 339498a..1a5fc8c 100644 --- a/pollhead.rb +++ b/pollhead.rb @@ -99,17 +99,20 @@ EDITDELETE hiddeninput = "<input type='hidden' name='columnid' value=\"#{get_id(title)}\" />" end return <<END -<fieldset><legend>Add/Edit Column</legend> -<form method='post' action='config.cgi'> +<form method='post' action=''> <div> <label for='columntitle'>Columntitle: </label> <input id='columntitle' size='16' type='text' value="#{title}" name='new_columnname' /> <label for='columndescription'>Description: </label> <input id='columndescription' size='30' type='text' value="#{description}" name='columndescription' /> #{hiddeninput} - <input type='submit' value='add/edit column' /> + <input type='submit' value='Add/Edit Column' /> </div> </form> +<fieldset><legend>Preview</legend> +<table> +#{to_html(true)} +</table> </fieldset> END end diff --git a/timepollhead.rb b/timepollhead.rb index 1641066..1ec5d60 100644 --- a/timepollhead.rb +++ b/timepollhead.rb @@ -123,20 +123,20 @@ class TimePollHead parsed_date.to_s end + # returns a sorted array, containing the big units and how often each small is in the big one + # small and big must be formated for strftime + # ex: head_count("%Y-%m") returns an array like [["2009-03",2],["2009-04",3]] + # if notime = true, the time field is stripped out before counting + def head_count(elem, notime) + data = @data.collect{|day| day.date} + data.uniq! if notime + ret = Hash.new(0) + data.each{|day| + ret[day.strftime(elem)] += 1 + } + ret.sort + end def to_html(config = false,activecolumn = nil) - # returns a sorted array, containing the big units and how often each small is in the big one - # small and big must be formated for strftime - # ex: head_count("%Y-%m") returns an array like [["2009-03",2],["2009-04",3]] - # if notime = true, the time field is stripped out before counting - def head_count(elem, notime) - data = @data.collect{|day| day.date} - data.uniq! if notime - ret = Hash.new(0) - data.each{|day| - ret[day.strftime(elem)] += 1 - } - ret.sort - end ret = "<tr><td></td>" head_count("%Y-%m",false).each{|title,count| year, month = title.split("-").collect{|e| e.to_i} @@ -179,7 +179,6 @@ class TimePollHead startdate = Date.parse("#{Date.today.year}-#{Date.today.month}-1") end ret = <<END -<fieldset><legend>Add/Remove Column</legend> <div style="float: left; margin-right: 20px"> <table><tr> END @@ -314,7 +313,6 @@ END ret += "</tr></table></div>" end - ret += "</fieldset>" ret end end |