Added Poll wobject.
This commit is contained in:
parent
1d7dcd6e9e
commit
f656d00c20
6 changed files with 272 additions and 284 deletions
|
|
@ -134,7 +134,7 @@ sub checkbox {
|
|||
$extras = shift;
|
||||
$output = '<input type="checkbox" name="'.$name.'" value="'.$value.'"'.$checked.' '.$extras.'>';
|
||||
$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 .= '<input type="text" name="'.$name.'" value="'.$value.'" size="'.
|
||||
$size.'" maxlength="'.$maxLength.'" onBlur="emailCheck(this.value)" '.$extras.'>';
|
||||
$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 = '<input type="file" name="'.$name.'" size="'.$size.'" '.$extras.'>';
|
||||
$output .= _subtext($subtext);
|
||||
$output = _tableFormRow($label,$output);
|
||||
$output = _tableFormRow($label,$output) unless ($class->{_noTable});
|
||||
$class->{_data} .= $output;
|
||||
}
|
||||
|
||||
|
|
@ -378,7 +378,7 @@ sub group {
|
|||
}
|
||||
$output .= '</select>';
|
||||
$output .= _subtext($subtext);
|
||||
$output = _tableFormRow($label,$output);
|
||||
$output = _tableFormRow($label,$output) unless ($class->{_noTable});
|
||||
$class->{_data} .= $output;
|
||||
}
|
||||
|
||||
|
|
@ -501,7 +501,7 @@ sub HTMLArea {
|
|||
$output .= '<textarea name="'.$name.'" cols="'.$columns.'" rows="'.$rows.'" wrap="'.$wrap.
|
||||
'" onBlur="fixChars(this.form.'.$name.')" '.$extras.'>'.$value.'</textarea>';
|
||||
$output .= _subtext($subtext);
|
||||
$output = _tableFormRow($label,$output);
|
||||
$output = _tableFormRow($label,$output) unless ($class->{_noTable});
|
||||
$class->{_data} .= $output;
|
||||
}
|
||||
|
||||
|
|
@ -574,16 +574,21 @@ sub integer {
|
|||
$output .= '<input type="text" name="'.$name.'" value="'.$value.'" size="'.
|
||||
$size.'" maxlength="'.$maxLength.'" onKeyUp="doNumCheck(this.form.'.$name.')" '.$extras.'>';
|
||||
$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 = '<form action="'.$action.'" enctype="'.$enctype.'" method="'.$method.'" '.$extras.'><table>';
|
||||
$footer = '</table></form>';
|
||||
bless {_header => $header, _footer => $footer, _data => ''}, $class;
|
||||
$header = '<form action="'.$action.'" enctype="'.$enctype.'" method="'.$method.'" '.$extras.'>';
|
||||
$header .= '<table>' unless ($noTable);
|
||||
$footer = '</table>' unless ($noTable);
|
||||
$footer .= '</form>';
|
||||
bless {_noTable => $noTable, _header => $header, _footer => $footer, _data => ''}, $class;
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
|
@ -679,7 +687,7 @@ sub password {
|
|||
$output = '<input type="password" name="'.$name.'" value="'.$value.'" size="'.
|
||||
$size.'" maxlength="'.$maxLength.'" '.$extras.'>';
|
||||
$output .= _subtext($subtext);
|
||||
$output = _tableFormRow($label,$output);
|
||||
$output = _tableFormRow($label,$output) unless ($class->{_noTable});
|
||||
$class->{_data} .= $output;
|
||||
}
|
||||
|
||||
|
|
@ -739,7 +747,7 @@ sub phone {
|
|||
$output .= '<input type="text" name="'.$name.'" value="'.$value.'" size="'.
|
||||
$size.'" maxlength="'.$maxLength.'" '.$extras.'>';
|
||||
$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 .= '</select>';
|
||||
$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 = '<input type="submit" value="'.$value.'" onClick="this.value=\''.$wait.'\'" '.$extras.'>';
|
||||
$output .= _subtext($subtext);
|
||||
$output = _tableFormRow($label,$output);
|
||||
$output = _tableFormRow($label,$output) unless ($class->{_noTable});
|
||||
$class->{_data} .= $output;
|
||||
}
|
||||
|
||||
|
|
@ -999,7 +1008,7 @@ sub text {
|
|||
$output = '<input type="text" name="'.$name.'" value="'.$value.'" size="'.
|
||||
$size.'" maxlength="'.$maxLength.'" '.$extras.'>';
|
||||
$output .= _subtext($subtext);
|
||||
$output = _tableFormRow($label,$output);
|
||||
$output = _tableFormRow($label,$output) unless ($class->{_noTable});
|
||||
$class->{_data} .= $output;
|
||||
}
|
||||
|
||||
|
|
@ -1065,7 +1074,7 @@ sub textarea {
|
|||
$output .= '<textarea name="'.$name.'" cols="'.$columns.'" rows="'.$rows.'" wrap="'.
|
||||
$wrap.'" '.$extras.'>'.$value.'</textarea>';
|
||||
$output .= _subtext($subtext);
|
||||
$output = _tableFormRow($label,$output);
|
||||
$output = _tableFormRow($label,$output) unless ($class->{_noTable});
|
||||
$class->{_data} .= $output;
|
||||
}
|
||||
|
||||
|
|
@ -1128,7 +1137,7 @@ sub url {
|
|||
$output .= '<input type="text" name="'.$name.'" value="'.$value.'" size="'.
|
||||
$size.'" maxlength="'.$maxLength.'" onBlur="addHTTP(this.form.'.$name.')" '.$extras.'>';
|
||||
$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 = '<input type="text" name="'.$name.'" value="'.$value.'" size="'.
|
||||
$size.'" maxlength="'.$maxLength.'" '.$extras.'>';
|
||||
$output .= _subtext($subtext);
|
||||
$output = _tableFormRow($label,$output);
|
||||
$output = _tableFormRow($label,$output) unless ($class->{_noTable});
|
||||
$class->{_data} .= $output;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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 .= '<span class="pollQuestion">'.$poll{question}.'</span><br>';
|
||||
for ($i=1; $i<=20; $i++) {
|
||||
if ($poll{'a'.$i} =~ /\w/) {
|
||||
$output .= WebGUI::Form::radio("answer",'a'.$i).' <span class="pollAnswer">'.$poll{'a'.$i}.'</span><br>';
|
||||
}
|
||||
}
|
||||
$output .= '<br>'.WebGUI::Form::submit(WebGUI::International::get(11,$namespace));
|
||||
$output .= '</form>';
|
||||
}
|
||||
return $output;
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub _viewResults {
|
||||
my (%poll, @data, $i, $output, $totalResponses);
|
||||
tie %poll, 'Tie::CPHash';
|
||||
%poll = getProperties($namespace,$_[0]);
|
||||
if (defined %poll) {
|
||||
$output = '<span class="pollQuestion">'.$poll{question}.'</span>';
|
||||
($totalResponses) = WebGUI::SQL->quickArray("select count(*) from Poll_answer where widgetId=$_[0]");
|
||||
if ($totalResponses < 1) {
|
||||
$totalResponses = 1;
|
||||
}
|
||||
for ($i=1; $i<=20; $i++) {
|
||||
if ($poll{'a'.$i} =~ /\w/) {
|
||||
$output .= '<span class="pollAnswer"><hr size=1>'.$poll{'a'.$i}.'<br></span>';
|
||||
@data = WebGUI::SQL->quickArray("select count(*), answer from Poll_answer where answer='a$i' and widgetId=$_[0] group by answer");
|
||||
$output .= '<table cellpadding=0 cellspacing=0 border=0><tr><td width="'.round($poll{graphWidth}*$data[0]/$totalResponses).'" class="pollColor"><img src="'.$session{setting}{lib}.'/spacer.gif" height="1" width="1"></td><td class="pollAnswer"> '.round(100*$data[0]/$totalResponses).'%</td></tr></table>';
|
||||
}
|
||||
}
|
||||
$output .= '<span class="pollAnswer"><hr size=1><b>Total Votes:</b> '.$totalResponses.'</span>';
|
||||
}
|
||||
return $output;
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub duplicate {
|
||||
my ($sth, %data, $newWidgetId, $pageId, @row);
|
||||
tie %data, 'Tie::CPHash';
|
||||
%data = getProperties($namespace,$_[0]);
|
||||
$pageId = $_[1] || $data{pageId};
|
||||
$newWidgetId = create($pageId,$namespace,$data{title},$data{displayTitle},$data{description},$data{processMacros},$data{templatePosition});
|
||||
WebGUI::SQL->write("insert into Poll values ($newWidgetId, '$data{active}', '$data{graphWidth}', '$data{voteGroup}', ".quote($data{question}).", ".quote($data{a1}).", ".quote($data{a2}).", ".quote($data{a3}).", ".quote($data{a4}).", ".quote($data{a5}).", ".quote($data{a6}).", ".quote($data{a7}).", ".quote($data{a8}).", ".quote($data{a9}).", ".quote($data{a10}).", ".quote($data{a11}).", ".quote($data{a12}).", ".quote($data{a13}).", ".quote($data{a14}).", ".quote($data{a15}).", ".quote($data{a16}).", ".quote($data{a17}).", ".quote($data{a18}).", ".quote($data{a19}).", ".quote($data{a20}).")");
|
||||
$sth = WebGUI::SQL->read("select * from Poll_answer where widgetId=$_[0]");
|
||||
while (@row = $sth->array) {
|
||||
WebGUI::SQL->write("insert into Poll_answer values ($newWidgetId, '$row[1]', $row[2], '$row[3]')");
|
||||
}
|
||||
$sth->finish;
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub purge {
|
||||
WebGUI::SQL->write("delete from Poll_answer where widgetId=$_[0]",$_[1]);
|
||||
purgeWidget($_[0],$_[1],$namespace);
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub widgetName {
|
||||
return WebGUI::International::get(1,$namespace);
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub www_add {
|
||||
my ($output, %hash);
|
||||
tie %hash, 'Tie::IxHash';
|
||||
if (WebGUI::Privilege::canEditPage()) {
|
||||
$output = helpLink(1,$namespace);
|
||||
$output .= '<h1>'.WebGUI::International::get(2,$namespace).'</h1>';
|
||||
$output .= formHeader();
|
||||
$output .= WebGUI::Form::hidden("widget",$namespace);
|
||||
$output .= WebGUI::Form::hidden("func","addSave");
|
||||
$output .= '<table>';
|
||||
$output .= tableFormRow(WebGUI::International::get(99),WebGUI::Form::text("title",20,128,'Poll'));
|
||||
$output .= tableFormRow(WebGUI::International::get(174),WebGUI::Form::checkbox("displayTitle",1));
|
||||
$output .= tableFormRow(WebGUI::International::get(175),WebGUI::Form::checkbox("processMacros",1));
|
||||
%hash = WebGUI::Widget::getPositions();
|
||||
$output .= tableFormRow(WebGUI::International::get(363),
|
||||
WebGUI::Form::selectList("templatePosition",\%hash));
|
||||
$output .= tableFormRow(WebGUI::International::get(85),WebGUI::Form::textArea("description",'',50,5,1));
|
||||
$output .= tableFormRow(WebGUI::International::get(3,$namespace),WebGUI::Form::checkbox("active",1,1));
|
||||
$output .= tableFormRow(WebGUI::International::get(4,$namespace),
|
||||
WebGUI::Form::groupList("voteGroup",7)); # Group "Everyone"
|
||||
$output .= tableFormRow(WebGUI::International::get(5,$namespace),
|
||||
WebGUI::Form::text("graphWidth",20,3,150));
|
||||
$output .= tableFormRow(WebGUI::International::get(6,$namespace),WebGUI::Form::text("question",50,255));
|
||||
$output .= tableFormRow(WebGUI::International::get(7,$namespace).'<span><br>'.WebGUI::International::get(8,$namespace).'</span>',
|
||||
WebGUI::Form::textArea("answers",'',50,8,0,'on'));
|
||||
$output .= formSave();
|
||||
$output .= '</table></form>';
|
||||
return $output;
|
||||
} else {
|
||||
return WebGUI::Privilege::insufficient();
|
||||
}
|
||||
return $output;
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub www_addSave {
|
||||
my ($widgetId, @answer);
|
||||
if (WebGUI::Privilege::canEditPage()) {
|
||||
$widgetId = create($session{page}{pageId},$session{form}{widget},$session{form}{title},$session{form}{displayTitle},$session{form}{description},$session{form}{processMacros},$session{form}{templatePosition});
|
||||
@answer = split("\n",$session{form}{answers});
|
||||
WebGUI::SQL->write("insert into Poll values ($widgetId, '$session{form}{active}', '$session{form}{graphWidth}', '$session{form}{voteGroup}', ".quote($session{form}{question}).", ".quote($answer[0]).", ".quote($answer[1]).", ".quote($answer[2]).", ".quote($answer[3]).", ".quote($answer[4]).", ".quote($answer[5]).", ".quote($answer[6]).", ".quote($answer[7]).", ".quote($answer[8]).", ".quote($answer[9]).", ".quote($answer[10]).", ".quote($answer[11]).", ".quote($answer[12]).", ".quote($answer[13]).", ".quote($answer[14]).", ".quote($answer[15]).", ".quote($answer[16]).", ".quote($answer[17]).", ".quote($answer[18]).", ".quote($answer[19]).")");
|
||||
return "";
|
||||
} else {
|
||||
return WebGUI::Privilege::insufficient();
|
||||
}
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub www_copy {
|
||||
if (WebGUI::Privilege::canEditPage()) {
|
||||
duplicate($session{form}{wid});
|
||||
return "";
|
||||
} else {
|
||||
return WebGUI::Privilege::insufficient();
|
||||
}
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub www_edit {
|
||||
my ($output, %data, %hash, @array);
|
||||
tie %hash, "Tie::IxHash";
|
||||
tie %data, 'Tie::CPHash';
|
||||
if (WebGUI::Privilege::canEditPage()) {
|
||||
%data = getProperties($namespace,$session{form}{wid});
|
||||
$output = helpLink(1,$namespace);
|
||||
$output .= '<h1>'.WebGUI::International::get(9,$namespace).'</h1>';
|
||||
$output .= formHeader();
|
||||
$output .= WebGUI::Form::hidden("wid",$session{form}{wid});
|
||||
$output .= WebGUI::Form::hidden("func","editSave");
|
||||
$output .= '<table>';
|
||||
$output .= tableFormRow(WebGUI::International::get(99),WebGUI::Form::text("title",20,128,$data{title}));
|
||||
$output .= tableFormRow(WebGUI::International::get(174),
|
||||
WebGUI::Form::checkbox("displayTitle",1,$data{displayTitle}));
|
||||
$output .= tableFormRow(WebGUI::International::get(175),
|
||||
WebGUI::Form::checkbox("processMacros",1,$data{processMacros}));
|
||||
%hash = WebGUI::Widget::getPositions();
|
||||
$array[0] = $data{templatePosition};
|
||||
$output .= tableFormRow(WebGUI::International::get(363),
|
||||
WebGUI::Form::selectList("templatePosition",\%hash,\@array));
|
||||
$output .= tableFormRow(WebGUI::International::get(85),
|
||||
WebGUI::Form::textArea("description",$data{description},50,5,1));
|
||||
$output .= tableFormRow(WebGUI::International::get(3,$namespace),
|
||||
WebGUI::Form::checkbox("active",1,$data{active}));
|
||||
$output .= tableFormRow(WebGUI::International::get(4,$namespace),
|
||||
WebGUI::Form::groupList("voteGroup",$data{voteGroup}));
|
||||
$output .= tableFormRow(WebGUI::International::get(5,$namespace),
|
||||
WebGUI::Form::text("graphWidth",20,3,$data{graphWidth}));
|
||||
$output .= tableFormRow(WebGUI::International::get(6,$namespace),
|
||||
WebGUI::Form::text("question",50,255,$data{question}));
|
||||
$output .= tableFormRow(WebGUI::International::get(7,$namespace).'<span><br>'.WebGUI::International::get(8,$namespace).'</span>',
|
||||
WebGUI::Form::textArea("answers",$data{a1}."\n".$data{a2}."\n".$data{a3}."\n".$data{a4}."\n".$data{a5}."\n".$data{a6}."\n".$data{a7}."\n".$data{a8}."\n".$data{a9}."\n".$data{a10}."\n".$data{a11}."\n".$data{a12}."\n".$data{a13}."\n".$data{a14}."\n".$data{a15}."\n".$data{a16}."\n".$data{a17}."\n".$data{a18}."\n".$data{a19}."\n".$data{a20}."\n",50,8,0,'on'));
|
||||
$output .= formSave();
|
||||
$output .= tableFormRow("",'<a href="'.WebGUI::URL::page('func=resetVotes&wid='.$session{form}{wid})
|
||||
.'">'.WebGUI::International::get(10,$namespace).'</a>');
|
||||
$output .= '</table></form>';
|
||||
return $output;
|
||||
} else {
|
||||
return WebGUI::Privilege::insufficient();
|
||||
}
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub www_editSave {
|
||||
my (@answer);
|
||||
if (WebGUI::Privilege::canEditPage()) {
|
||||
update();
|
||||
@answer = split("\n",$session{form}{answers});
|
||||
WebGUI::SQL->write("update Poll set active='$session{form}{active}', voteGroup='$session{form}{voteGroup}', graphWidth=$session{form}{graphWidth}, question=".quote($session{form}{question}).", a1=".quote($answer[0]).", a2=".quote($answer[1]).", a3=".quote($answer[2]).", a4=".quote($answer[3]).", a5=".quote($answer[4]).", a6=".quote($answer[5]).", a7=".quote($answer[6]).", a8=".quote($answer[7]).", a9=".quote($answer[8]).", a10=".quote($answer[9]).", a11=".quote($answer[10]).", a12=".quote($answer[11]).", a13=".quote($answer[12]).", a14=".quote($answer[13]).", a15=".quote($answer[14]).", a16=".quote($answer[15]).", a17=".quote($answer[16]).", a18=".quote($answer[17]).", a19=".quote($answer[18]).", a20=".quote($answer[19])." where widgetId=$session{form}{wid}");
|
||||
return "";
|
||||
} else {
|
||||
return WebGUI::Privilege::insufficient();
|
||||
}
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub www_resetVotes {
|
||||
if (WebGUI::Privilege::canEditPage()) {
|
||||
WebGUI::SQL->write("delete from Poll_answer where widgetId='$session{form}{wid}'");
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub www_view {
|
||||
my ($hasVoted, %data, $output);
|
||||
tie %data, 'Tie::CPHash';
|
||||
%data = getProperties($namespace,$_[0]);
|
||||
if ($data{displayTitle} == 1) {
|
||||
$output = "<h1>".$data{title}."</h1>";
|
||||
}
|
||||
if ($data{description} ne "") {
|
||||
$output .= $data{description}.'<p>';
|
||||
}
|
||||
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;
|
||||
|
||||
|
|
@ -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"));
|
||||
|
|
|
|||
229
lib/WebGUI/Wobject/Poll.pm
Normal file
229
lib/WebGUI/Wobject/Poll.pm
Normal file
|
|
@ -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 .= '<h1>'.WebGUI::International::get(9,$namespace).'</h1>';
|
||||
$f = WebGUI::HTMLForm->new;
|
||||
$f->yesNo("active",WebGUI::International::get(3,$namespace),$active);
|
||||
$f->group("voteGroup",WebGUI::International::get(4,$namespace),[$voteGroup]);
|
||||
$f->integer("graphWidth",WebGUI::International::get(5,$namespace),$graphWidth);
|
||||
$f->text("question",WebGUI::International::get(6,$namespace),$_[0]->get("question"));
|
||||
$f->textarea("answers",WebGUI::International::get(7,$namespace).'<span class="formSubtext"><br>'.WebGUI::International::get(8,$namespace).'</span>',$answers);
|
||||
$output .= $_[0]->SUPER::www_edit($f->printRowsOnly);
|
||||
if ($_[0]->get("wobjectId") ne "new") {
|
||||
$output .= '<p>';
|
||||
$output .= '<a href="'.WebGUI::URL::page('func=resetVotes&wid='.$_[0]->get("wobjectId").'">')
|
||||
.WebGUI::International::get(10,$namespace).'</a>';
|
||||
}
|
||||
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 .= '<span class="pollQuestion">'.$_[0]->get("question").'</span><br>';
|
||||
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('<input type="radio" name="answer" value="a'.$i.'"> <span class="pollAnswer">'.$_[0]->get('a'.$i).'</span><br>');
|
||||
}
|
||||
}
|
||||
$f->raw('<br>');
|
||||
$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 .= '<span class="pollAnswer"><hr size="1">'.$_[0]->get('a'.$i).'<br></span>';
|
||||
@data = WebGUI::SQL->quickArray("select count(*), answer from Poll_answer where answer='a$i' and wobjectId="
|
||||
.$_[0]->get("wobjectId")." group by answer");
|
||||
$output .= '<table cellpadding=0 cellspacing=0 border=0><tr><td width="'.
|
||||
round($_[0]->get("graphWidth")*$data[0]/$totalResponses).'" class="pollColor"><img src="'.
|
||||
$session{setting}{lib}.'/spacer.gif" height="1" width="1"></td><td class="pollAnswer"> '.
|
||||
round(100*$data[0]/$totalResponses).'% ('.($data[0]+0).')</td></tr></table>';
|
||||
}
|
||||
}
|
||||
$output .= '<span class="pollAnswer"><hr size="1"><b>Total Votes:</b> '.$totalResponses.'</span>';
|
||||
}
|
||||
return $_[0]->processMacros($output);
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub www_vote {
|
||||
my ($hasVoted);
|
||||
($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 ($session{form}{answer} ne "" && WebGUI::Privilege::isInGroup($_[0]->get("voteGroup"),$session{user}{userId}) && !($hasVoted)) {
|
||||
WebGUI::SQL->write("insert into Poll_answer values (".$_[0]->get("wobjectId").",
|
||||
'$session{form}{answer}', $session{user}{userId}, '$session{env}{REMOTE_ADDR}')");
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
|
||||
|
||||
1;
|
||||
|
||||
|
|
@ -60,7 +60,7 @@ sub _traversePageTree {
|
|||
sub duplicate {
|
||||
my ($w, $f);
|
||||
$w = $_[0]->SUPER::duplicate($_[1]);
|
||||
$w = WebGUI::Wobject::Item->new({wobjectId=>$w,namespace=>$namespace});
|
||||
$w = WebGUI::Wobject::SiteMap->new({wobjectId=>$w,namespace=>$namespace});
|
||||
$w->set({
|
||||
startAtThisLevel=>$_[0]->get("startAtThisLevel"),
|
||||
indent=>$_[0]->get("indent"),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue