diff --git a/docs/upgrades/upgrade_3.7.0-3.8.0.sql b/docs/upgrades/upgrade_3.7.0-3.8.0.sql index 0c0cc331b..dd3a01a15 100644 --- a/docs/upgrades/upgrade_3.7.0-3.8.0.sql +++ b/docs/upgrades/upgrade_3.7.0-3.8.0.sql @@ -46,6 +46,10 @@ insert into wobject (wobjectId, pageId, title, displayTitle, processMacros, desc delete from widget where namespace='SiteMap'; alter table SiteMap change widgetId wobjectId int not null; +insert into wobject (wobjectId, pageId, title, displayTitle, processMacros, description, dateAdded, addedBy, namespace, lastEdited, editedBy, templatePosition, sequenceNumber, startDate, endDate) select widgetId, pageId, title, displayTitle, processMacros, description, dateAdded, addedBy, namespace, lastEdited, editedBy, templatePosition, sequenceNumber, dateAdded, 1336444487 from widget where namespace='Poll'; +delete from widget where namespace='Poll'; +alter table Poll change widgetId wobjectId int not null; +alter table Poll_answer change widgetId wobjectId int not null; delete from international where language='Svenska'; diff --git a/lib/WebGUI/HTMLForm.pm b/lib/WebGUI/HTMLForm.pm index 098b0bf7d..291e547a4 100644 --- a/lib/WebGUI/HTMLForm.pm +++ b/lib/WebGUI/HTMLForm.pm @@ -134,7 +134,7 @@ sub checkbox { $extras = shift; $output = ''; $output .= _subtext($subtext); - $output = _tableFormRow($label,$output); + $output = _tableFormRow($label,$output) unless ($class->{_noTable}); $class->{_data} .= $output; } @@ -193,7 +193,7 @@ sub date { '/calendar.html\',\'cal\',\'WIDTH=200,HEIGHT=250\');return false" value="'. WebGUI::International::get(34).'">'; $output .= _subtext($subtext); - $output = _tableFormRow($label,$output); + $output = _tableFormRow($label,$output) unless ($class->{_noTable}); $class->{_data} .= $output; } @@ -256,7 +256,7 @@ sub email { $output .= ''; $output .= _subtext($subtext); - $output = _tableFormRow($label,$output); + $output = _tableFormRow($label,$output) unless ($class->{_noTable}); $class->{_data} .= $output; } @@ -305,7 +305,7 @@ sub file { $size = shift || $session{setting}{textBoxSize} || 30; $output = ''; $output .= _subtext($subtext); - $output = _tableFormRow($label,$output); + $output = _tableFormRow($label,$output) unless ($class->{_noTable}); $class->{_data} .= $output; } @@ -378,7 +378,7 @@ sub group { } $output .= ''; $output .= _subtext($subtext); - $output = _tableFormRow($label,$output); + $output = _tableFormRow($label,$output) unless ($class->{_noTable}); $class->{_data} .= $output; } @@ -501,7 +501,7 @@ sub HTMLArea { $output .= ''; $output .= _subtext($subtext); - $output = _tableFormRow($label,$output); + $output = _tableFormRow($label,$output) unless ($class->{_noTable}); $class->{_data} .= $output; } @@ -574,16 +574,21 @@ sub integer { $output .= ''; $output .= _subtext($subtext); - $output = _tableFormRow($label,$output); + $output = _tableFormRow($label,$output) unless ($class->{_noTable}); $class->{_data} .= $output; } #------------------------------------------------------------------- -=head2 new ( [ action, extras, method, enctype ] ) +=head2 new ( [ noTable, action, extras, method, enctype ] ) Constructor. +=item noTable + + If this is set to "1" then no table elements will be wrapped around + each form element. Defaults to "0". + =item action The Action URL for the form information to be submitted to. This @@ -610,15 +615,18 @@ sub integer { =cut sub new { - my ($header, $footer, $enctype, $class, $method, $action, $extras); + my ($header, $footer, $noTable, $enctype, $class, $method, $action, $extras); $class = shift; + $noTable = shift || 0; $action = shift || WebGUI::URL::page(); $method = shift || "POST"; $extras = shift; $enctype = shift || "multipart/form-data"; - $header = '
'; - bless {_header => $header, _footer => $footer, _data => ''}, $class; + $header = ''; + bless {_noTable => $noTable, _header => $header, _footer => $footer, _data => ''}, $class; } #------------------------------------------------------------------- @@ -679,7 +687,7 @@ sub password { $output = ''; $output .= _subtext($subtext); - $output = _tableFormRow($label,$output); + $output = _tableFormRow($label,$output) unless ($class->{_noTable}); $class->{_data} .= $output; } @@ -739,7 +747,7 @@ sub phone { $output .= ''; $output .= _subtext($subtext); - $output = _tableFormRow($label,$output); + $output = _tableFormRow($label,$output) unless ($class->{_noTable}); $class->{_data} .= $output; } @@ -817,8 +825,9 @@ sub readOnly { $value = shift; $label = shift; $subtext = shift; + $output = $value; $output .= _subtext($subtext); - $output = _tableFormRow($label,$value); + $output = _tableFormRow($label,$output) unless ($class->{_noTable}); $class->{_data} .= $output; } @@ -895,7 +904,7 @@ sub select { } $output .= ''; $output .= _subtext($subtext); - $output = _tableFormRow($label,$output); + $output = _tableFormRow($label,$output) unless ($class->{_noTable}); $class->{_data} .= $output; } @@ -939,7 +948,7 @@ sub submit { $wait = WebGUI::International::get(452); $output = ''; $output .= _subtext($subtext); - $output = _tableFormRow($label,$output); + $output = _tableFormRow($label,$output) unless ($class->{_noTable}); $class->{_data} .= $output; } @@ -999,7 +1008,7 @@ sub text { $output = ''; $output .= _subtext($subtext); - $output = _tableFormRow($label,$output); + $output = _tableFormRow($label,$output) unless ($class->{_noTable}); $class->{_data} .= $output; } @@ -1065,7 +1074,7 @@ sub textarea { $output .= ''; $output .= _subtext($subtext); - $output = _tableFormRow($label,$output); + $output = _tableFormRow($label,$output) unless ($class->{_noTable}); $class->{_data} .= $output; } @@ -1128,7 +1137,7 @@ sub url { $output .= ''; $output .= _subtext($subtext); - $output = _tableFormRow($label,$output); + $output = _tableFormRow($label,$output) unless ($class->{_noTable}); $class->{_data} .= $output; } @@ -1182,7 +1191,7 @@ sub yesNo { $output .= ' checked="1"' if ($value == 0); $output .= $extras.'>'.WebGUI::International::get(139); $output .= _subtext($subtext); - $output = _tableFormRow($label,$output); + $output = _tableFormRow($label,$output) unless ($class->{_noTable}); $class->{_data} .= $output; } @@ -1242,7 +1251,7 @@ sub zipcode { $output = ''; $output .= _subtext($subtext); - $output = _tableFormRow($label,$output); + $output = _tableFormRow($label,$output) unless ($class->{_noTable}); $class->{_data} .= $output; } diff --git a/lib/WebGUI/Widget/Poll.pm b/lib/WebGUI/Widget/Poll.pm deleted file mode 100644 index 8ec7f6ead..000000000 --- a/lib/WebGUI/Widget/Poll.pm +++ /dev/null @@ -1,259 +0,0 @@ -package WebGUI::Widget::Poll; - -our $namespace = "Poll"; - -#------------------------------------------------------------------- -# WebGUI is Copyright 2001-2002 Plain Black Software. -#------------------------------------------------------------------- -# Please read the legal notices (docs/legal.txt) and the license -# (docs/license.txt) that came with this distribution before using -# this software. -#------------------------------------------------------------------- -# http://www.plainblack.com info@plainblack.com -#------------------------------------------------------------------- - -use strict; -use Tie::CPHash; -use WebGUI::International; -use WebGUI::Privilege; -use WebGUI::Session; -use WebGUI::Shortcut; -use WebGUI::SQL; -use WebGUI::URL; -use WebGUI::Utility; -use WebGUI::Widget; - -#------------------------------------------------------------------- -sub _viewPoll { - my (%poll, $i, $output); - tie %poll, 'Tie::CPHash'; - %poll = getProperties($namespace,$_[0]); - if (defined %poll) { - $output = formHeader(); - $output .= WebGUI::Form::hidden('wid',$_[0]); - $output .= WebGUI::Form::hidden('func','vote'); - $output .= ''.$poll{question}.'| '.round(100*$data[0]/$totalResponses).'% |
'; - } - if ($data{active} eq "0") { - $output .= _viewResults($_[0]); - } elsif (WebGUI::Privilege::isInGroup($data{voteGroup},$session{user}{userId})) { - ($hasVoted) = WebGUI::SQL->quickArray("select count(*) from Poll_answer where widgetId=$_[0] and ((userId=$session{user}{userId} and userId<>1) or (userId=1 and ipAddress='$session{env}{REMOTE_ADDR}'))"); - if ($hasVoted) { - $output .= _viewResults($_[0]); - } else { - $output .= _viewPoll($_[0]); - } - } else { - $output .= _viewResults($_[0]); - } - return $output; -} - -#------------------------------------------------------------------- -sub www_vote { - my ($voteGroup,$hasVoted); - ($voteGroup) = WebGUI::SQL->quickArray("select voteGroup from Poll where widgetId='$session{form}{wid}'"); - ($hasVoted) = WebGUI::SQL->quickArray("select count(*) from Poll_answer where widgetId=$session{form}{wid} and ((userId=$session{user}{userId} and userId<>1) or (userId=1 and ipAddress='$session{env}{REMOTE_ADDR}'))"); - if (WebGUI::Privilege::isInGroup($voteGroup,$session{user}{userId}) && !($hasVoted)) { - WebGUI::SQL->write("insert into Poll_answer values ($session{form}{wid}, '$session{form}{answer}', $session{user}{userId}, '$session{env}{REMOTE_ADDR}')"); - } - return ""; -} - - - -1; - diff --git a/lib/WebGUI/Wobject.pm b/lib/WebGUI/Wobject.pm index def392388..68a82805d 100644 --- a/lib/WebGUI/Wobject.pm +++ b/lib/WebGUI/Wobject.pm @@ -393,7 +393,12 @@ sub www_deleteConfirm { =cut sub www_edit { - my ($f, $title, $templatePosition, $endDate); + my ($f, $displayTitle, $title, $templatePosition, $endDate); + if ($_[0]->get("wobjectId") eq "new") { + $displayTitle = 1; + } else { + $displayTitle = $_[0]->get("displayTitle"); + } $title = $_[0]->get("title") || $_[0]->get("namespace"); $templatePosition = $_[0]->get("templatePosition") || 'A'; $endDate = $_[0]->get("endDate") || (time()+315360000); @@ -403,7 +408,7 @@ sub www_edit { $f->hidden("func","editSave"); $f->readOnly($_[0]->get("wobjectId"),WebGUI::International::get(499)); $f->text("title",WebGUI::International::get(99),$title); - $f->yesNo("displayTitle",WebGUI::International::get(174),$_[0]->get("displayTitle")); + $f->yesNo("displayTitle",WebGUI::International::get(174),$displayTitle); $f->yesNo("processMacros",WebGUI::International::get(175),$_[0]->get("processMacros")); $f->select("templatePosition",_getPositions(),WebGUI::International::get(363),[$templatePosition]); $f->date("startDate",WebGUI::International::get(497),$_[0]->get("startDate")); diff --git a/lib/WebGUI/Wobject/Poll.pm b/lib/WebGUI/Wobject/Poll.pm new file mode 100644 index 000000000..077463b82 --- /dev/null +++ b/lib/WebGUI/Wobject/Poll.pm @@ -0,0 +1,229 @@ +package WebGUI::Wobject::Poll; + + +#------------------------------------------------------------------- +# WebGUI is Copyright 2001-2002 Plain Black Software. +#------------------------------------------------------------------- +# Please read the legal notices (docs/legal.txt) and the license +# (docs/license.txt) that came with this distribution before using +# this software. +#------------------------------------------------------------------- +# http://www.plainblack.com info@plainblack.com +#------------------------------------------------------------------- + +use strict; +use Tie::CPHash; +use WebGUI::HTMLForm; +use WebGUI::Icon; +use WebGUI::International; +use WebGUI::Privilege; +use WebGUI::Session; +use WebGUI::SQL; +use WebGUI::URL; +use WebGUI::Utility; +use WebGUI::Wobject; + +our @ISA = qw(WebGUI::Wobject); +our $namespace = "Poll"; +our $name = WebGUI::International::get(1,$namespace); + + +#------------------------------------------------------------------- +sub duplicate { + my ($w, $f, $sth, @row); + $w = $_[0]->SUPER::duplicate($_[1]); + $w = WebGUI::Wobject::Poll->new({wobjectId=>$w,namespace=>$namespace}); + $w->set({ + active=>$_[0]->get("active"), + graphWidth=>$_[0]->get("graphWidth"), + voteGroup=>$_[0]->get("voteGroup"), + question=>$_[0]->get("question"), + a1=>$_[0]->get("a1"), + a2=>$_[0]->get("a2"), + a3=>$_[0]->get("a3"), + a4=>$_[0]->get("a4"), + a5=>$_[0]->get("a5"), + a6=>$_[0]->get("a6"), + a7=>$_[0]->get("a7"), + a8=>$_[0]->get("a8"), + a9=>$_[0]->get("a9"), + a10=>$_[0]->get("a10"), + a11=>$_[0]->get("a11"), + a12=>$_[0]->get("a12"), + a13=>$_[0]->get("a13"), + a14=>$_[0]->get("a14"), + a15=>$_[0]->get("a15"), + a16=>$_[0]->get("a16"), + a17=>$_[0]->get("a17"), + a18=>$_[0]->get("a18"), + a19=>$_[0]->get("a19"), + a20=>$_[0]->get("a20") + }); + $sth = WebGUI::SQL->read("select * from Poll_answer where wobjectId=".$_[0]->get("wobjectId")); + while (@row = $sth->array) { + WebGUI::SQL->write("insert into Poll_answer values (".$w->get("wobjectId").", '$row[1]', $row[2], '$row[3]')"); + } + $sth->finish; +} + +#------------------------------------------------------------------- +sub new { + my ($self, $class, $property); + $class = shift; + $property = shift; + $self = WebGUI::Wobject->new($property); + bless $self, $class; +} + +#------------------------------------------------------------------- +sub purge { + WebGUI::SQL->write("delete from Poll_answer where wobjectId=".$_[0]->get("wobjectId")); + $_[0]->SUPER::purge(); +} + +#------------------------------------------------------------------- +sub set { + $_[0]->SUPER::set($_[1],[qw(active graphWidth voteGroup question a1 a2 a3 a4 a5 a6 a7 a8 a9 a10 a11 a12 a13 a14 a15 a16 a17 a18 a19 a20)]); +} + +#------------------------------------------------------------------- +sub www_copy { + if (WebGUI::Privilege::canEditPage()) { + $_[0]->duplicate; + return ""; + } else { + return WebGUI::Privilege::insufficient(); + } +} + +#------------------------------------------------------------------- +sub www_edit { + my ($f, $i, $output, $active, $voteGroup, $graphWidth, $answers); + if (WebGUI::Privilege::canEditPage()) { + if ($_[0]->get("wobjectId") eq "new") { + $active = 1; + } else { + $active = $_[0]->get("active"); + } + $voteGroup = $_[0]->get("voteGroup") || 7; + $graphWidth = $_[0]->get("graphWidth") || 150; + for ($i=1; $i<=20; $i++) { + if ($_[0]->get('a'.$i) =~ /\w/) { + $answers .= $_[0]->get("a".$i)."\n"; + } + } + $output = helpIcon(1,$namespace); + $output .= '
';
+ $output .= '')
+ .WebGUI::International::get(10,$namespace).'';
+ }
+ return $output;
+ } else {
+ return WebGUI::Privilege::insufficient();
+ }
+}
+
+#-------------------------------------------------------------------
+sub www_editSave {
+ my (@answer, $i, $property);
+ if (WebGUI::Privilege::canEditPage()) {
+ $_[0]->SUPER::www_editSave();
+ @answer = split("\n",$session{form}{answers});
+ for ($i=1; $i<=20; $i++) {
+ $property->{'a'.$i} = $answer[($i-1)];
+ }
+ $property->{voteGroup} = $session{form}{voteGroup};
+ $property->{graphWidth} = $session{form}{graphWidth};
+ $property->{active} = $session{form}{active};
+ $property->{question} = $session{form}{question};
+ $_[0]->set($property);
+ return "";
+ } else {
+ return WebGUI::Privilege::insufficient();
+ }
+}
+
+#-------------------------------------------------------------------
+sub www_resetVotes {
+ if (WebGUI::Privilege::canEditPage()) {
+ WebGUI::SQL->write("delete from Poll_answer where wobjectId=".$_[0]->get("wobjectId"));
+ }
+ return "";
+}
+
+#-------------------------------------------------------------------
+sub www_view {
+ my ($hasVoted, $output, $showPoll, $f, $i, $totalResponses, @data);
+ $output = $_[0]->displayTitle;
+ $output .= $_[0]->description;
+ if ($_[0]->get("active") eq "0") {
+ $showPoll = 0;
+ } elsif (WebGUI::Privilege::isInGroup($_[0]->get("voteGroup"),$session{user}{userId})) {
+ ($hasVoted) = WebGUI::SQL->quickArray("select count(*) from Poll_answer where wobjectId=".$_[0]->get("wobjectId")."
+ and ((userId=$session{user}{userId} and userId<>1) or (userId=1 and ipAddress='$session{env}{REMOTE_ADDR}'))");
+ if ($hasVoted) {
+ $showPoll = 0;
+ } else {
+ $showPoll = 1;
+ }
+ } else {
+ $showPoll = 0;
+ }
+ $output .= ''.$_[0]->get("question").'
';
+ if ($showPoll) {
+ $f = WebGUI::HTMLForm->new(1);
+ $f->hidden('wid',$_[0]->get("wobjectId"));
+ $f->hidden('func','vote');
+ for ($i=1; $i<=20; $i++) {
+ if ($_[0]->get('a'.$i) =~ /\w/) {
+ $f->raw(' '.$_[0]->get('a'.$i).'
');
+ }
+ }
+ $f->raw('
');
+ $f->submit(WebGUI::International::get(11,$namespace));
+ $output .= $f->print;
+ } else {
+ ($totalResponses) = WebGUI::SQL->quickArray("select count(*) from Poll_answer where wobjectId=".$_[0]->get("wobjectId"));
+ if ($totalResponses < 1) {
+ $totalResponses = 1;
+ }
+ for ($i=1; $i<=20; $i++) {
+ if ($_[0]->get('a'.$i) =~ /\w/) {
+ $output .= '
'.$_[0]->get('a'.$i).'
';
+ @data = WebGUI::SQL->quickArray("select count(*), answer from Poll_answer where answer='a$i' and wobjectId="
+ .$_[0]->get("wobjectId")." group by answer");
+ $output .= '
| '. + round(100*$data[0]/$totalResponses).'% ('.($data[0]+0).') |