From e910cb33e1d1c6d60c08379ca3c41fa0d615cc0c Mon Sep 17 00:00:00 2001 From: Benjamin Kellermann Date: Mon, 5 Oct 2009 16:31:06 +0200 Subject: added feature to modify name after participating --- poll.rb | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) (limited to 'poll.rb') diff --git a/poll.rb b/poll.rb index 081513e..ac58ae6 100644 --- a/poll.rb +++ b/poll.rb @@ -54,9 +54,9 @@ class Poll ret += head_to_html(config) sort_data($cgi.include?("sort") ? $cgi.params["sort"] : ["timestamp"]).each{|participant,poll| ret += "\n" - ret += "" + ret += "" ret += participant - ret += " #{EDIT}" unless config + ret += " #{EDIT}" unless config ret += "\n" @head.sort.each{|columntitle,columndescription| klasse = poll[columntitle] @@ -122,8 +122,8 @@ class Poll end def participate_to_html checked = {} - if $cgi.include?("edit") - participant = $cgi["edit"] + if $edituser && @data.include?($edituser) + participant = $edituser @head.each_key{|k| checked[k] = @data[participant][k]} else participant = "" @@ -131,10 +131,11 @@ class Poll end ret = "\n" ret += " + \n" @head.sort.each{|columntitle,columndescription| @@ -246,18 +247,20 @@ ADDCOMMENT END end def add_participant(name, agreed) - htmlname = CGI.escapeHTML(name.strip) - if htmlname == "" + name.strip! + if name == "" maximum = @data.keys.collect{|e| e.scan(/^Anonymous #(\d*)/).flatten[0]}.compact.collect{|i| i.to_i}.max maximum ||= 0 - htmlname = "Anonymous ##{maximum + 1}" - name = htmlname + name = "Anonymous ##{maximum + 1}" end - @data[htmlname] = {"timestamp" => Time.now } - @head.each_key{|columntitle| - @data[htmlname][columntitle] = agreed[columntitle.to_s] - } - store "Participant #{name.strip} edited" + htmlname = CGI.escapeHTML(name) + @data.delete(CGI.escapeHTML($edituser)) + $edituser = htmlname + @data[htmlname] = {"timestamp" => Time.now } + @head.each_key{|columntitle| + @data[htmlname][columntitle] = agreed[columntitle.to_s] + } + store "Participant #{name.strip} edited" end def invite_delete(name) htmlname = CGI.escapeHTML(name.strip) -- cgit v1.2.3