migrated poll to asset system and further modularized trash and clipboard
This commit is contained in:
parent
616c5f0f28
commit
920fa27263
11 changed files with 655 additions and 107 deletions
|
|
@ -17,7 +17,6 @@ package WebGUI::Asset;
|
|||
use strict;
|
||||
use Tie::IxHash;
|
||||
use WebGUI::AdminConsole;
|
||||
use WebGUI::Clipboard;
|
||||
use WebGUI::DateTime;
|
||||
use WebGUI::ErrorHandler;
|
||||
use WebGUI::Form;
|
||||
|
|
@ -566,6 +565,52 @@ sub getAssetManagerControl {
|
|||
return $output;
|
||||
}
|
||||
|
||||
|
||||
sub getAssetsInClipboard {
|
||||
my $self = shift;
|
||||
my $limitToUser = shift;
|
||||
my $userId = shift || $session{user}{userId};
|
||||
my @assets;
|
||||
my $limit;
|
||||
unless ($limitToUser) {
|
||||
$limit = "and lastUpdatedBy=".quote($userId);
|
||||
}
|
||||
my $sth = WebGUI::SQL->read("select assetId, title, className from asset where state='clipboard' $limit order by lastUpdated desc");
|
||||
while (my ($id, $title, $class) = $sth->array) {
|
||||
push(@assets, {
|
||||
title => $title,
|
||||
assetId => $id,
|
||||
className => $class
|
||||
});
|
||||
}
|
||||
$sth->finish;
|
||||
return \@assets;
|
||||
}
|
||||
|
||||
|
||||
sub getAssetsInTrash {
|
||||
my $self = shift;
|
||||
my $limitToUser = shift;
|
||||
my $userId = shift || $session{user}{userId};
|
||||
my @assets;
|
||||
my $limit;
|
||||
unless ($limitToUser) {
|
||||
$limit = "and lastUpdatedBy=".quote($userId);
|
||||
}
|
||||
my $sth = WebGUI::SQL->read("select assetId, title, className from asset where state='trash' $limit order by lastUpdated desc");
|
||||
while (my ($id, $title, $class) = $sth->array) {
|
||||
push(@assets, {
|
||||
title => $title,
|
||||
assetId => $id,
|
||||
className => $class
|
||||
});
|
||||
}
|
||||
$sth->finish;
|
||||
return \@assets;
|
||||
}
|
||||
|
||||
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 getEditForm ( )
|
||||
|
|
@ -863,7 +908,11 @@ sub getLineage {
|
|||
# create whatever type of object was requested
|
||||
my $asset;
|
||||
if ($rules->{returnObjects}) {
|
||||
$asset = WebGUI::Asset->newByDynamicClass($properties->{assetId}, $properties->{className});
|
||||
if ($self->getId eq $properties->{assetId}) { # possibly save ourselves a hit to the database
|
||||
$asset = $self;
|
||||
} else {
|
||||
$asset = WebGUI::Asset->newByDynamicClass($properties->{assetId}, $properties->{className});
|
||||
}
|
||||
} elsif ($rules->{returnQuickReadObjects}) {
|
||||
$asset = WebGUI::Asset->newByPropertyHashRef($properties);
|
||||
} else {
|
||||
|
|
@ -1479,6 +1528,7 @@ sub update {
|
|||
push(@setPairs,"lastUpdated=".time());
|
||||
}
|
||||
foreach my $property (keys %{$definition->{properties}}) {
|
||||
next unless (exists $properties->{$property});
|
||||
my $value = $properties->{$property} || $definition->{properties}{$property}{defaultValue};
|
||||
if (defined $value) {
|
||||
if (exists $definition->{properties}{$property}{filter}) {
|
||||
|
|
@ -1621,27 +1671,215 @@ sub www_editSave {
|
|||
}
|
||||
|
||||
sub www_editTree {
|
||||
return "not yet implemented";
|
||||
my $self = shift;
|
||||
my $ac = WebGUI::AdminConsole->new("assets");
|
||||
return $ac->render(WebGUI::Privilege::insufficient()) unless ($self->canEdit);
|
||||
my $tabform = WebGUI::TabForm->new;
|
||||
$tabform->hidden({name=>"func",value=>"editTreeSave"});
|
||||
$tabform->addTab("properties",WebGUI::International::get("properties","Asset"),9);
|
||||
$tabform->getTab("properties")->readOnly(
|
||||
-label=>WebGUI::International::get(104),
|
||||
-uiLevel=>9,
|
||||
-subtext=>'<br />'.WebGUI::International::get("change","Asset").' '.WebGUI::Form::yesNo({name=>"change_url"}),
|
||||
-value=>WebGUI::Form::selectList({
|
||||
name=>"baseUrlBy",
|
||||
extras=>'id="baseUrlBy" onchange="toggleSpecificBaseUrl()"',
|
||||
options=>{
|
||||
parentUrl=>"Parent URL",
|
||||
specifiedBase=>"Specified Base",
|
||||
none=>"None"
|
||||
}
|
||||
}).'<span id="baseUrl"></span> / '.WebGUI::Form::selectList({
|
||||
name=>"endOfUrl",
|
||||
options=>{
|
||||
menuTitle=>WebGUI::International::get(411),
|
||||
title=>WebGUI::International::get(99),
|
||||
currentUrl=>"Current URL"
|
||||
}
|
||||
})."<script type=\"text/javascript\">
|
||||
function toggleSpecificBaseUrl () {
|
||||
if (document.getElementById('baseUrlBy').options[document.getElementById('baseUrlBy').selectedIndex].value == 'specifiedBase') {
|
||||
document.getElementById('baseUrl').innerHTML='<input type=\"text\" name=\"baseUrl\" />';
|
||||
} else {
|
||||
document.getElementById('baseUrl').innerHTML='';
|
||||
}
|
||||
}
|
||||
toggleSpecificBaseUrl();
|
||||
</script>"
|
||||
);
|
||||
$tabform->addTab("display",WebGUI::International::get(105),5);
|
||||
$tabform->getTab("display")->yesNo(
|
||||
-name=>"isHidden",
|
||||
-value=>$self->get("isHidden"),
|
||||
-label=>WebGUI::International::get(886),
|
||||
-uiLevel=>6,
|
||||
-subtext=>'<br />'.WebGUI::International::get("change","Asset").' '.WebGUI::Form::yesNo({name=>"change_isHidden"})
|
||||
);
|
||||
$tabform->getTab("display")->yesNo(
|
||||
-name=>"newWindow",
|
||||
-value=>$self->get("newWindow"),
|
||||
-label=>WebGUI::International::get(940),
|
||||
-uiLevel=>6,
|
||||
-subtext=>'<br />'.WebGUI::International::get("change","Asset").' '.WebGUI::Form::yesNo({name=>"change_newWindow"})
|
||||
);
|
||||
$tabform->getTab("display")->yesNo(
|
||||
-name=>"displayTitle",
|
||||
-label=>WebGUI::International::get(174),
|
||||
-value=>$self->getValue("displayTitle"),
|
||||
-uiLevel=>5,
|
||||
-subtext=>'<br />'.WebGUI::International::get("change","Asset").' '.WebGUI::Form::yesNo({name=>"change_displayTitle"})
|
||||
);
|
||||
$tabform->getTab("display")->template(
|
||||
-name=>"styleTemplateId",
|
||||
-label=>WebGUI::International::get(1073),
|
||||
-value=>$self->getValue("styleTemplateId"),
|
||||
-namespace=>'style',
|
||||
-afterEdit=>'op=editPage&npp='.$session{form}{npp},
|
||||
-subtext=>'<br />'.WebGUI::International::get("change","Asset").' '.WebGUI::Form::yesNo({name=>"change_styleTemplateId"})
|
||||
);
|
||||
$tabform->getTab("display")->template(
|
||||
-name=>"printableStyleTemplateId",
|
||||
-label=>WebGUI::International::get(1079),
|
||||
-value=>$self->getValue("printableStyleTemplateId"),
|
||||
-namespace=>'style',
|
||||
-afterEdit=>'op=editPage&npp='.$session{form}{npp},
|
||||
-subtext=>'<br />'.WebGUI::International::get("change","Asset").' '.WebGUI::Form::yesNo({name=>"change_printableStyleTemplateId"})
|
||||
);
|
||||
$tabform->getTab("display")->interval(
|
||||
-name=>"cacheTimeout",
|
||||
-label=>WebGUI::International::get(895),
|
||||
-value=>$self->getValue("cacheTimeout"),
|
||||
-uiLevel=>8,
|
||||
-subtext=>'<br />'.WebGUI::International::get("change","Asset").' '.WebGUI::Form::yesNo({name=>"change_cacheTimeout"})
|
||||
);
|
||||
$tabform->getTab("display")->interval(
|
||||
-name=>"cacheTimeoutVisitor",
|
||||
-label=>WebGUI::International::get(896),
|
||||
-value=>$self->getValue("cacheTimeoutVisitor"),
|
||||
-uiLevel=>8,
|
||||
-subtext=>'<br />'.WebGUI::International::get("change","Asset").' '.WebGUI::Form::yesNo({name=>"change_cacheTimeoutVisitor"})
|
||||
);
|
||||
$tabform->addTab("security",WebGUI::International::get(107),6);
|
||||
$tabform->getTab("security")->yesNo(
|
||||
-name=>"encryptPage",
|
||||
-value=>$self->get("encryptPage"),
|
||||
-label=>WebGUI::International::get('encrypt page'),
|
||||
-uiLevel=>6,
|
||||
-subtext=>'<br />'.WebGUI::International::get("change","Asset").' '.WebGUI::Form::yesNo({name=>"change_encryptPage"})
|
||||
);
|
||||
$tabform->getTab("security")->dateTime(
|
||||
-name=>"startDate",
|
||||
-label=>WebGUI::International::get(497),
|
||||
-value=>$self->get("startDate"),
|
||||
-uiLevel=>6,
|
||||
-subtext=>'<br />'.WebGUI::International::get("change","Asset").' '.WebGUI::Form::yesNo({name=>"change_startDate"})
|
||||
);
|
||||
$tabform->getTab("security")->dateTime(
|
||||
-name=>"endDate",
|
||||
-label=>WebGUI::International::get(498),
|
||||
-value=>$self->get("endDate"),
|
||||
-uiLevel=>6,
|
||||
-subtext=>'<br />'.WebGUI::International::get("change","Asset").' '.WebGUI::Form::yesNo({name=>"change_endDate"})
|
||||
);
|
||||
my $subtext;
|
||||
if (WebGUI::Grouping::isInGroup(3)) {
|
||||
$subtext = manageIcon('op=listUsers');
|
||||
} else {
|
||||
$subtext = "";
|
||||
}
|
||||
my $clause;
|
||||
if (WebGUI::Grouping::isInGroup(3)) {
|
||||
my $contentManagers = WebGUI::Grouping::getUsersInGroup(4,1);
|
||||
push (@$contentManagers, $session{user}{userId});
|
||||
$clause = "userId in (".quoteAndJoin($contentManagers).")";
|
||||
} else {
|
||||
$clause = "userId=".quote($self->get("ownerUserId"));
|
||||
}
|
||||
my $users = WebGUI::SQL->buildHashRef("select userId,username from users where $clause order by username");
|
||||
$tabform->getTab("security")->selectList(
|
||||
-name=>"ownerUserId",
|
||||
-options=>$users,
|
||||
-label=>WebGUI::International::get(108),
|
||||
-value=>[$self->get("ownerUserId")],
|
||||
-subtext=>$subtext,
|
||||
-uiLevel=>6,
|
||||
-subtext=>'<br />'.WebGUI::International::get("change","Asset").' '.WebGUI::Form::yesNo({name=>"change_ownerUserId"})
|
||||
);
|
||||
$tabform->getTab("security")->group(
|
||||
-name=>"groupIdView",
|
||||
-label=>WebGUI::International::get(872),
|
||||
-value=>[$self->get("groupIdView")],
|
||||
-uiLevel=>6,
|
||||
-subtext=>'<br />'.WebGUI::International::get("change","Asset").' '.WebGUI::Form::yesNo({name=>"change_groupIdView"})
|
||||
);
|
||||
$tabform->getTab("security")->group(
|
||||
-name=>"groupIdEdit",
|
||||
-label=>WebGUI::International::get(871),
|
||||
-value=>[$self->get("groupIdEdit")],
|
||||
-excludeGroups=>[1,7],
|
||||
-uiLevel=>6,
|
||||
-subtext=>'<br />'.WebGUI::International::get("change","Asset").' '.WebGUI::Form::yesNo({name=>"change_groupIdEdit"})
|
||||
);
|
||||
return $ac->render($tabform->print, "Edit Branch");
|
||||
}
|
||||
|
||||
sub www_editTreeSave {
|
||||
return "not yet implemented";
|
||||
my $self = shift;
|
||||
return $self->getAdminConsole->render(WebGUI::Privilege::insufficient()) unless ($self->canEdit);
|
||||
my %data;
|
||||
$data{isHidden} = WebGUI::FormProcessor::yesNo("isHidden") if (WebGUI::FormProcessor::yesNo("change_isHidden"));
|
||||
$data{newWindow} = WebGUI::FormProcessor::yesNo("newWindow") if (WebGUI::FormProcessor::yesNo("change_newWindow"));
|
||||
$data{displayTitle} = WebGUI::FormProcessor::yesNo("displayTitle") if (WebGUI::FormProcessor::yesNo("change_displayTitle"));
|
||||
$data{styleTemplateId} = WebGUI::FormProcessor::template("styleTemplateId") if (WebGUI::FormProcessor::yesNo("change_styleTemplateId"));
|
||||
$data{printableStyleTemplateId} = WebGUI::FormProcessor::template("printableStyleTemplateId") if (WebGUI::FormProcessor::yesNo("change_printableStyleTemplateId"));
|
||||
$data{cacheTimeout} = WebGUI::FormProcessor::interval("cacheTimeout") if (WebGUI::FormProcessor::yesNo("change_cacheTimeout"));
|
||||
$data{cacheTimeoutVisitor} = WebGUI::FormProcessor::interval("cacheTimeoutVisitor") if (WebGUI::FormProcessor::yesNo("change_cacheTimeoutVisitor"));
|
||||
$data{encryptPage} = WebGUI::FormProcessor::yesNo("encryptPage") if (WebGUI::FormProcessor::yesNo("change_encryptPage"));
|
||||
$data{startDate} = WebGUI::FormProcessor::dateTime("startDate") if (WebGUI::FormProcessor::yesNo("change_startDate"));
|
||||
$data{endDate} = WebGUI::FormProcessor::dateTime("endDate") if (WebGUI::FormProcessor::yesNo("change_endDate"));
|
||||
$data{ownerUserId} = WebGUI::FormProcessor::selectList("ownerUserId") if (WebGUI::FormProcessor::yesNo("change_ownerUserId"));
|
||||
$data{groupIdView} = WebGUI::FormProcessor::group("groupIdView") if (WebGUI::FormProcessor::yesNo("change_groupIdView"));
|
||||
$data{groupIdEdit} = WebGUI::FormProcessor::group("groupIdEdit") if (WebGUI::FormProcessor::yesNo("change_groupIdEdit"));
|
||||
my ($urlBaseBy, $urlBase, $endOfUrl);
|
||||
my $changeUrl = WebGUI::FormProcessor::yesNo("change_url");
|
||||
if ($changeUrl) {
|
||||
$urlBaseBy = WebGUI::FormProcessor::selectList("urlBaseBy");
|
||||
$urlBase = WebGUI::FormProcessor::text("urlBase");
|
||||
$endOfUrl = WebGUI::FormProcessor::selectList("endOfUrl");
|
||||
}
|
||||
my $descendants = $self->getLineage(["self","descendants"],{returnObjects=>1});
|
||||
foreach my $descendant (@{$descendants}) {
|
||||
my $url;
|
||||
if ($changeUrl) {
|
||||
if ($urlBaseBy eq "parentUrl") {
|
||||
delete $descendant->{_parent};
|
||||
$data{url} = $descendant->getParent->get("url")."/";
|
||||
} elsif ($urlBaseBy eq "specifiedUrl") {
|
||||
$data{url} = $urlBase."/";
|
||||
} else {
|
||||
$data{url} = "";
|
||||
}
|
||||
if ($endOfUrl eq "menuTitle") {
|
||||
$data{url} .= $descendant->get("menuTitle");
|
||||
} elsif ($endOfUrl eq "title") {
|
||||
$data{url} .= $descendant->get("title");
|
||||
} else {
|
||||
$data{url} .= $descendant->get("url");
|
||||
}
|
||||
}
|
||||
$descendant->update(\%data);
|
||||
}
|
||||
return $self->www_manageAssets;
|
||||
}
|
||||
|
||||
sub www_emptyClipboard {
|
||||
my $self = shift;
|
||||
my $ac = WebGUI::AdminConsole->new("clipboard");
|
||||
return $ac->render(WebGUI::Privilege::insufficient()) unless (WebGUI::Grouping::isInGroup(4));
|
||||
my $limit;
|
||||
unless ($session{form}{systemTrash} && WebGUI::Grouping::isInGroup(3)) {
|
||||
$limit = "and lastUpdatedBy=".quote($session{user}{userId});
|
||||
}
|
||||
my $sth = WebGUI::SQL->read("select assetId,className from asset where state='clipboard' $limit");
|
||||
while (my ($id, $class) = $sth->array) {
|
||||
my $asset = WebGUI::Asset->newByDynamicClass($id,$class);
|
||||
foreach my $assetData (@{$self->getAssetsInClipboard($session{form}{systemClipboard} && WebGUI::Grouping::isInGroup(3))}) {
|
||||
my $asset = WebGUI::Asset->newByDynamicClass($assetData->{assetId},$assetData->{className});
|
||||
$asset->trash;
|
||||
}
|
||||
$sth->finish;
|
||||
return $self->www_manageClipboard();
|
||||
}
|
||||
|
||||
|
|
@ -1649,16 +1887,10 @@ sub www_emptyTrash {
|
|||
my $self = shift;
|
||||
my $ac = WebGUI::AdminConsole->new("trash");
|
||||
return $ac->render(WebGUI::Privilege::insufficient()) unless (WebGUI::Grouping::isInGroup(4));
|
||||
my $limit;
|
||||
unless ($session{form}{systemTrash} && WebGUI::Grouping::isInGroup(3)) {
|
||||
$limit = "and lastUpdatedBy=".quote($session{user}{userId});
|
||||
}
|
||||
my $sth = WebGUI::SQL->read("select assetId,className from asset where state='trash' $limit");
|
||||
while (my ($id, $class) = $sth->array) {
|
||||
my $asset = WebGUI::Asset->newByDynamicClass($id,$class);
|
||||
foreach my $assetData (@{$self->getAssetsInTrash($session{form}{systemTrash} && WebGUI::Grouping::isInGroup(3))}) {
|
||||
my $asset = WebGUI::Asset->newByDynamicClass($assetData->{assetId},$assetData->{className});
|
||||
$asset->purgeTree;
|
||||
}
|
||||
$sth->finish;
|
||||
return $self->www_manageTrash();
|
||||
}
|
||||
|
||||
|
|
@ -1707,9 +1939,9 @@ sub www_manageClipboard {
|
|||
my $ac = WebGUI::AdminConsole->new("clipboard");
|
||||
return $ac->render(WebGUI::Privilege::insufficient()) unless (WebGUI::Grouping::isInGroup(4));
|
||||
my @assets;
|
||||
my ($header, $limit);
|
||||
my ($header,$limit);
|
||||
$ac->setHelp("clipboard manage");
|
||||
if ($session{form}{systemTrash} && WebGUI::Grouping::isInGroup(3)) {
|
||||
if ($session{form}{systemClipboard} && WebGUI::Grouping::isInGroup(3)) {
|
||||
$header = WebGUI::International::get(965);
|
||||
$ac->addSubmenuItem($self->getUrl('func=manageClipboard'), WebGUI::International::get(949));
|
||||
$ac->addSubmenuItem($self->getUrl('func=emptyClipboard&systemClipboard=1'), WebGUI::International::get(959),
|
||||
|
|
@ -1718,13 +1950,11 @@ sub www_manageClipboard {
|
|||
$ac->addSubmenuItem($self->getUrl('func=manageClipboard&systemClipboard=1'), WebGUI::International::get(954));
|
||||
$ac->addSubmenuItem($self->getUrl('func=emptyClipboard'), WebGUI::International::get(950),
|
||||
'onclick="return window.confirm(\''.WebGUI::International::get(951).'\')"');
|
||||
$limit = "and lastUpdatedBy=".quote($session{user}{userId});
|
||||
$limit = 1;
|
||||
}
|
||||
my $sth = WebGUI::SQL->read("select assetId,className from asset where state='clipboard' $limit");
|
||||
while (my ($id, $class) = $sth->array) {
|
||||
push(@assets,WebGUI::Asset->newByDynamicClass($id,$class));
|
||||
foreach my $assetData (@{$self->getAssetsInClipboard($limit)}) {
|
||||
push(@assets,WebGUI::Asset->newByDynamicClass($assetData->{assetId},$assetData->{className}));
|
||||
}
|
||||
$sth->finish;
|
||||
return $ac->render($self->getAssetManagerControl(\@assets), $header);
|
||||
}
|
||||
|
||||
|
|
@ -1745,13 +1975,11 @@ sub www_manageTrash {
|
|||
$ac->addSubmenuItem($self->getUrl('func=manageTrash&systemTrash=1'), WebGUI::International::get(964));
|
||||
$ac->addSubmenuItem($self->getUrl('func=emptyTrash'), WebGUI::International::get(11),
|
||||
'onclick="return window.confirm(\''.WebGUI::International::get(651).'\')"');
|
||||
$limit = "and lastUpdatedBy=".quote($session{user}{userId});
|
||||
$limit = 1;
|
||||
}
|
||||
my $sth = WebGUI::SQL->read("select assetId,className from asset where state='trash' $limit");
|
||||
while (my ($id, $class) = $sth->array) {
|
||||
push(@assets,WebGUI::Asset->newByDynamicClass($id,$class));
|
||||
foreach my $assetData (@{$self->getAssetsInTrash($limit)}) {
|
||||
push(@assets,WebGUI::Asset->newByDynamicClass($assetData->{assetId},$assetData->{className}));
|
||||
}
|
||||
$sth->finish;
|
||||
return $ac->render($self->getAssetManagerControl(\@assets), $header);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -11,13 +11,9 @@ package WebGUI::Asset::Wobject::Article;
|
|||
#-------------------------------------------------------------------
|
||||
|
||||
use strict;
|
||||
use Tie::CPHash;
|
||||
use WebGUI::DateTime;
|
||||
use WebGUI::Forum;
|
||||
use WebGUI::Forum::UI;
|
||||
use WebGUI::HTML;
|
||||
use WebGUI::HTMLForm;
|
||||
use WebGUI::Icon;
|
||||
use WebGUI::International;
|
||||
use WebGUI::Paginator;
|
||||
use WebGUI::Privilege;
|
||||
|
|
|
|||
349
lib/WebGUI/Asset/Wobject/Poll.pm
Normal file
349
lib/WebGUI/Asset/Wobject/Poll.pm
Normal file
|
|
@ -0,0 +1,349 @@
|
|||
package WebGUI::Asset::Wobject::Poll;
|
||||
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
# WebGUI is Copyright 2001-2004 Plain Black Corporation.
|
||||
#-------------------------------------------------------------------
|
||||
# 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 WebGUI::Form;
|
||||
use WebGUI::Grouping;
|
||||
use WebGUI::International;
|
||||
use WebGUI::Privilege;
|
||||
use WebGUI::Session;
|
||||
use WebGUI::SQL;
|
||||
use WebGUI::User;
|
||||
use WebGUI::Utility;
|
||||
use WebGUI::Asset::Wobject;
|
||||
|
||||
our @ISA = qw(WebGUI::Asset::Wobject);
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub _hasVoted {
|
||||
my $self = shift;
|
||||
my ($hasVoted) = WebGUI::SQL->quickArray("select count(*) from Poll_answer
|
||||
where assetId=".quote($self->getId)." and ((userId=".quote($session{user}{userId})."
|
||||
and userId<>1) or (userId=1 and ipAddress='$session{env}{REMOTE_ADDR}'))");
|
||||
return $hasVoted;
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub definition {
|
||||
my $class = shift;
|
||||
my $definition = shift;
|
||||
push(@{$definition}, {
|
||||
tableName=>'Poll',
|
||||
className=>'WebGUI::Asset::Wobject::Poll',
|
||||
properties=>{
|
||||
active=>{
|
||||
fieldType=>"yesNo",
|
||||
defaultValue=>1
|
||||
},
|
||||
karmaPerVote=>{
|
||||
fieldType=>"integer",
|
||||
defaultValue=>0
|
||||
},
|
||||
graphWidth=>{
|
||||
fieldType=>"integer",
|
||||
defaultValue=>150
|
||||
},
|
||||
voteGroup=>{
|
||||
fieldType=>"group",
|
||||
defaultValue=>7
|
||||
},
|
||||
question=>{
|
||||
fieldType=>"text",
|
||||
defaultValue=>undef
|
||||
},
|
||||
randomizeAnswers=>{
|
||||
defaultValue=>1,
|
||||
fieldType=>"yesNo"
|
||||
},
|
||||
a1=>{
|
||||
fieldType=>"hidden",
|
||||
defaultValue=>undef
|
||||
},
|
||||
a2=>{
|
||||
fieldType=>"hidden",
|
||||
defaultValue=>undef
|
||||
},
|
||||
a3=>{
|
||||
fieldType=>"hidden",
|
||||
defaultValue=>undef
|
||||
},
|
||||
a4=>{
|
||||
fieldType=>"hidden",
|
||||
defaultValue=>undef
|
||||
},
|
||||
a5=>{
|
||||
fieldType=>"hidden",
|
||||
defaultValue=>undef
|
||||
},
|
||||
a6=>{
|
||||
fieldType=>"hidden",
|
||||
defaultValue=>undef
|
||||
},
|
||||
a7=>{
|
||||
fieldType=>"hidden",
|
||||
defaultValue=>undef
|
||||
},
|
||||
a8=>{
|
||||
fieldType=>"hidden",
|
||||
defaultValue=>undef
|
||||
},
|
||||
a9=>{
|
||||
fieldType=>"hidden",
|
||||
defaultValue=>undef
|
||||
},
|
||||
a10=>{
|
||||
fieldType=>"hidden",
|
||||
defaultValue=>undef
|
||||
},
|
||||
a11=>{
|
||||
fieldType=>"hidden",
|
||||
defaultValue=>undef
|
||||
},
|
||||
a12=>{
|
||||
fieldType=>"hidden",
|
||||
defaultValue=>undef
|
||||
},
|
||||
a13=>{
|
||||
fieldType=>"hidden",
|
||||
defaultValue=>undef
|
||||
},
|
||||
a14=>{
|
||||
fieldType=>"hidden",
|
||||
defaultValue=>undef
|
||||
},
|
||||
a15=>{
|
||||
fieldType=>"hidden",
|
||||
defaultValue=>undef
|
||||
},
|
||||
a16=>{
|
||||
fieldType=>"hidden",
|
||||
defaultValue=>undef
|
||||
},
|
||||
a17=>{
|
||||
fieldType=>"hidden",
|
||||
defaultValue=>undef
|
||||
},
|
||||
a18=>{
|
||||
fieldType=>"hidden",
|
||||
defaultValue=>undef
|
||||
},
|
||||
a19=>{
|
||||
fieldType=>"hidden",
|
||||
defaultValue=>undef
|
||||
},
|
||||
a20=>{
|
||||
fieldType=>"hidden",
|
||||
defaultValue=>undef
|
||||
}
|
||||
}
|
||||
});
|
||||
return $class->SUPER::definition($definition);
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub getEditForm {
|
||||
my $self = shift;
|
||||
my $tabform = $self->SUPER::getEditForm;
|
||||
my ($i, $answers);
|
||||
for ($i=1; $i<=20; $i++) {
|
||||
if ($self->get('a'.$i) =~ /\C/) {
|
||||
$answers .= $self->getValue("a".$i)."\n";
|
||||
}
|
||||
}
|
||||
$tabform->getTab("security")->yesNo(
|
||||
-name=>"active",
|
||||
-label=>WebGUI::International::get(3,"Poll"),
|
||||
-value=>$self->getValue("active")
|
||||
);
|
||||
$tabform->getTab("security")->group(
|
||||
-name=>"voteGroup",
|
||||
-label=>WebGUI::International::get(4,"Poll"),
|
||||
-value=>[$self->getValue("voteGroup")]
|
||||
);
|
||||
if ($session{setting}{useKarma}) {
|
||||
$tabform->getTab("properties")->integer(
|
||||
-name=>"karmaPerVote",
|
||||
-label=>WebGUI::International::get(20,"Poll"),
|
||||
-value=>$self->getValue("karmaPerVote")
|
||||
);
|
||||
} else {
|
||||
$tabform->getTab("properties")->hidden(
|
||||
-name=>"karmaPerVote",
|
||||
-value=>$self->getValue("karmaPerVote")
|
||||
);
|
||||
}
|
||||
$tabform->getTab("display")->integer(
|
||||
-name=>"graphWidth",
|
||||
-label=>WebGUI::International::get(5,"Poll"),
|
||||
-value=>$self->getValue("graphWidth")
|
||||
);
|
||||
$tabform->getTab("properties")->text(
|
||||
-name=>"question",
|
||||
-label=>WebGUI::International::get(6,"Poll"),
|
||||
-value=>$self->getValue("question")
|
||||
);
|
||||
$tabform->getTab("properties")->textarea(
|
||||
-name=>"answers",
|
||||
-label=>WebGUI::International::get(7,"Poll"),
|
||||
-subtext=>('<span class="formSubtext"><br>'.WebGUI::International::get(8,"Poll").'</span>'),
|
||||
-value=>$answers
|
||||
);
|
||||
$tabform->getTab("display")->yesNo(
|
||||
-name=>"randomizeAnswers",
|
||||
-label=>WebGUI::International::get(72,"Poll"),
|
||||
-value=>$self->getValue("randomizeAnswers")
|
||||
);
|
||||
$tabform->getTab("properties")->yesNo(
|
||||
-name=>"resetVotes",
|
||||
-label=>WebGUI::International::get(10,"Poll")
|
||||
);
|
||||
return $tabform;
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub getIcon {
|
||||
my $self = shift;
|
||||
my $small = shift;
|
||||
return $session{config}{extrasURL}.'/assets/small/poll.gif' if ($small);
|
||||
return $session{config}{extrasURL}.'/assets/poll.gif';
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub getIndexerParams {
|
||||
my $self = shift;
|
||||
my $now = shift;
|
||||
return {
|
||||
Poll => {
|
||||
sql => "select Poll.wobjectId as wid,
|
||||
Poll.question as question,
|
||||
Poll.a1 as a1, Poll.a2 as a2, Poll.a3 as a3, Poll.a4 as a4, Poll.a5 as a5,
|
||||
Poll.a6 as a6, Poll.a7 as a7, Poll.a8 as a8, Poll.a9 as a9, Poll.a10 as a10,
|
||||
Poll.a11 as a11, Poll.a12 as a12, Poll.a13 as a13, Poll.a14 as a14, Poll.a15 as a15,
|
||||
Poll.a16 as a16, Poll.a17 as a17, Poll.a18 as a18, Poll.a19 as a19, Poll.a20 as a20,
|
||||
wobject.namespace as namespace,
|
||||
wobject.addedBy as ownerId,
|
||||
page.urlizedTitle as urlizedTitle,
|
||||
page.languageId as languageId,
|
||||
page.pageId as pageId,
|
||||
page.groupIdView as page_groupIdView,
|
||||
wobject.groupIdView as wobject_groupIdView,
|
||||
7 as wobject_special_groupIdView
|
||||
from Poll, wobject, page
|
||||
where Poll.wobjectId = wobject.wobjectId
|
||||
and wobject.pageId = page.pageId
|
||||
and wobject.startDate < $now
|
||||
and wobject.endDate > $now
|
||||
and page.startDate < $now
|
||||
and page.endDate > $now",
|
||||
fieldsToIndex => ["question", "a1", "a2", "a3", "a4", "a5", "a6", "a7", "a8", "a9", "a10",
|
||||
"a11", "a12", "a13", "a14", "a15", "a16", "a17", "a18", "a19", "a20"],
|
||||
contentType => 'wobjectDetail',
|
||||
url => 'WebGUI::URL::append($data{urlizedTitle}, "func=view&wid=$data{wid}")',
|
||||
headerShortcut => 'select question from Poll where wobjectId = \'$data{wid}\'',
|
||||
bodyShortcut => 'select a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,a15,a16,a17,a18,a19,a20
|
||||
from Poll where wobjectId = \'$data{wid}\'',
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub getName {
|
||||
return WebGUI::International::get(1,"Poll");
|
||||
}
|
||||
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub processPropertiesFromFormPost {
|
||||
my $self = shift;
|
||||
$self->SUPER::processPropertiesFromFormPost;
|
||||
my (@answer, $i, $property);
|
||||
@answer = split("\n",$session{form}{answers});
|
||||
for ($i=1; $i<=20; $i++) {
|
||||
$property->{'a'.$i} = $answer[($i-1)];
|
||||
}
|
||||
$self->update($property);
|
||||
$self->deleteCollateral("Poll_answer","assetId",$self->getId) if ($session{form}{resetVotes});
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub view {
|
||||
my $self = shift;
|
||||
my (%var, $answer, @answers, $showPoll, $f);
|
||||
$var{question} = $self->get("question");
|
||||
if ($self->get("active") eq "0") {
|
||||
$showPoll = 0;
|
||||
} elsif (WebGUI::Grouping::isInGroup($self->get("voteGroup"),$session{user}{userId})) {
|
||||
if ($self->_hasVoted()) {
|
||||
$showPoll = 0;
|
||||
} else {
|
||||
$showPoll = 1;
|
||||
}
|
||||
} else {
|
||||
$showPoll = 0;
|
||||
}
|
||||
$var{canVote} = $showPoll;
|
||||
my ($totalResponses) = WebGUI::SQL->quickArray("select count(*) from Poll_answer where assetId=".quote($self->getId));
|
||||
$var{"responses.label"} = WebGUI::International::get(12,"Poll");
|
||||
$var{"responses.total"} = $totalResponses;
|
||||
$var{"form.start"} = WebGUI::Form::formHeader();
|
||||
$var{"form.start"} .= WebGUI::Form::hidden({name=>'func',value=>'vote'});
|
||||
$var{"form.submit"} = WebGUI::Form::submit({value=>WebGUI::International::get(11,"Poll")});
|
||||
$var{"form.end"} = WebGUI::Form::formFooter();
|
||||
$totalResponses = 1 if ($totalResponses < 1);
|
||||
for (my $i=1; $i<=20; $i++) {
|
||||
if ($self->get('a'.$i) =~ /\C/) {
|
||||
my ($tally) = WebGUI::SQL->quickArray("select count(*) from Poll_answer where answer='a"
|
||||
.$i."' and assetId=".quote($self->getId)." group by answer");
|
||||
push(@answers,{
|
||||
"answer.form"=>WebGUI::Form::radio({name=>"answer",value=>"a".$i}),
|
||||
"answer.text"=>$self->get('a'.$i),
|
||||
"answer.graphWidth"=>round($self->get("graphWidth")*$tally/$totalResponses),
|
||||
"answer.number"=>$i,
|
||||
"answer.percent"=>round(100*$tally/$totalResponses),
|
||||
"answer.total"=>($tally+0)
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
randomizeArray(\@answers) if ($self->get("randomizeAnswers"));
|
||||
$var{answer_loop} = \@answers;
|
||||
return $self->processTemplate(\%var,"Poll",$self->get("templateId"));
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub www_edit {
|
||||
my $self = shift;
|
||||
return WebGUI::Privilege::insufficient() unless $self->canEdit;
|
||||
$self->getAdminConsole->setHelp("poll add/edit");
|
||||
return $self->getAdminConsole->render($self->getEditForm->print,WebGUI::International::get("9","Poll"));
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub www_vote {
|
||||
my $self = shift;
|
||||
my $u;
|
||||
if ($session{form}{answer} ne "" && WebGUI::Grouping::isInGroup($self->get("voteGroup")) && !($self->_hasVoted())) {
|
||||
WebGUI::SQL->write("insert into Poll_answer values (".quote($self->getId).",
|
||||
".quote($session{form}{answer}).", ".quote($session{user}{userId}).", '$session{env}{REMOTE_ADDR}')");
|
||||
if ($session{setting}{useKarma}) {
|
||||
$u = WebGUI::User->new($session{user}{userId});
|
||||
$u->karma($self->get("karmaPerVote"),"Poll (".$self->getId.")","Voted on this poll.");
|
||||
}
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
|
||||
|
||||
1;
|
||||
|
||||
|
|
@ -1,21 +0,0 @@
|
|||
package WebGUI::Clipboard;
|
||||
|
||||
use strict;
|
||||
use WebGUI::Session;
|
||||
use WebGUI::SQL;
|
||||
|
||||
sub getAssetsInClipboard {
|
||||
my @assets;
|
||||
my $sth = WebGUI::SQL->read("select assetId, title from asset where state='clipboard' order by lastUpdated desc");
|
||||
while (my ($assetId, $title) = $sth->array) {
|
||||
push(@assets, {
|
||||
title => $title,
|
||||
assetId => $assetId
|
||||
});
|
||||
}
|
||||
$sth->finish;
|
||||
return \@assets;
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
|
|
@ -2045,7 +2045,7 @@ sub submit {
|
|||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 template ( name [, value, label, namespace, afterEdit, extras, uiLevel, defaultValue ] )
|
||||
=head2 template ( name [, value, label, namespace, afterEdit, extras, uiLevel, defaultValue, subtext ] )
|
||||
|
||||
Adds a template select list to the form.
|
||||
|
||||
|
|
@ -2083,20 +2083,24 @@ The UI level for this field. See the WebGUI developer's site for details. Defaul
|
|||
|
||||
If no value is specified, this will be used.
|
||||
|
||||
=head3 subtext
|
||||
|
||||
Any extra information you want to include after the field.
|
||||
|
||||
=cut
|
||||
|
||||
sub template {
|
||||
my ($output, $subtext);
|
||||
my ($output, $buttons);
|
||||
my ($self, @p) = @_;
|
||||
my ($name, $value, $label, $namespace, $afterEdit, $extras, $uiLevel, $defaultValue) =
|
||||
rearrange([qw(name value label namespace afterEdit extras uiLevel defaultValue)], @p);
|
||||
my ($name, $value, $label, $namespace, $afterEdit, $extras, $uiLevel, $defaultValue, $subtext) =
|
||||
rearrange([qw(name value label namespace afterEdit extras uiLevel defaultValue subtext)], @p);
|
||||
if (_uiLevelChecksOut($uiLevel)) {
|
||||
$label = $label || WebGUI::International::get(356);
|
||||
if (WebGUI::Grouping::isInGroup(8)) {
|
||||
if ($afterEdit) {
|
||||
$subtext = editIcon("op=editTemplate&tid=".$value."&namespace=".$namespace."&afterEdit=".WebGUI::URL::escape($afterEdit));
|
||||
$buttons = editIcon("op=editTemplate&tid=".$value."&namespace=".$namespace."&afterEdit=".WebGUI::URL::escape($afterEdit));
|
||||
}
|
||||
$subtext .= manageIcon("op=listTemplates&namespace=$namespace");
|
||||
$buttons .= manageIcon("op=listTemplates&namespace=$namespace");
|
||||
}
|
||||
$output = WebGUI::Form::template({
|
||||
"name"=>$name,
|
||||
|
|
@ -2105,7 +2109,7 @@ sub template {
|
|||
"extras"=>$extras,
|
||||
defaultValue=>$defaultValue
|
||||
});
|
||||
$output .= _subtext($subtext);
|
||||
$output .= _subtext($buttons.$subtext);
|
||||
$output = $self->_tableFormRow($label,$output);
|
||||
} else {
|
||||
$output = WebGUI::Form::hidden({
|
||||
|
|
|
|||
|
|
@ -14,7 +14,6 @@ use strict qw(refs vars);
|
|||
use Tie::CPHash;
|
||||
use Tie::IxHash;
|
||||
use WebGUI::AdminConsole;
|
||||
use WebGUI::Clipboard;
|
||||
use WebGUI::Grouping;
|
||||
use WebGUI::International;
|
||||
use WebGUI::Macro;
|
||||
|
|
@ -52,47 +51,21 @@ sub process {
|
|||
# $var{package_loop} = \@packages;
|
||||
#--contenttypes adder
|
||||
$var{'contentTypes.label'} = WebGUI::International::get(1083);
|
||||
foreach my $namespace (@{$session{config}{wobjects}}) {
|
||||
my $cmd = "WebGUI::Wobject::".$namespace;
|
||||
my $load = "use ".$cmd;
|
||||
eval($load);
|
||||
WebGUI::ErrorHandler::warn("Wobject failed to compile: $cmd.".$@) if($@);
|
||||
my $w = eval{$cmd->new({namespace=>$namespace,wobjectId=>"new"})};
|
||||
if ($@) {
|
||||
WebGUI::ErrorHandler::warn("Could not use wobject $namespace because: ".$@);
|
||||
next;
|
||||
}
|
||||
next if ($w->uiLevel > $session{user}{uiLevel});
|
||||
$hash{WebGUI::URL::page('func=edit&wid=new&namespace='.$namespace)} = $w->name;;
|
||||
}
|
||||
%hash = sortHash(%hash);
|
||||
$var{'addcontent.label'} = WebGUI::International::get(1);
|
||||
my @addcontent;
|
||||
$i = 0;
|
||||
foreach my $key (keys %hash) {
|
||||
push(@addcontent,{
|
||||
'contenttype.url'=>$key,
|
||||
'contenttype.label'=>$hash{$key},
|
||||
'contenttype.count'=>$i
|
||||
});
|
||||
$i++;
|
||||
}
|
||||
# $var{'contenttypes_loop'} = \@addcontent;
|
||||
foreach my $link (@{$session{asset}->getAssetAdderLinks}) {
|
||||
foreach my $link (@{$session{asset}->getAssetAdderLinks}) {
|
||||
push(@{$var{'contenttypes_loop'}},{'contenttype.url'=>$link->{url},'contenttype.label'=>$link->{label}});
|
||||
}
|
||||
$var{'addpage.url'} = WebGUI::URL::page('op=editPage&npp='.$session{page}{pageId});
|
||||
$var{'addpage.label'} = WebGUI::International::get(2);
|
||||
#--clipboard paster
|
||||
$var{'clipboard.label'} = WebGUI::International::get(1082);
|
||||
my $clipboard = WebGUI::Clipboard::getAssetsInClipboard();
|
||||
foreach my $item (@{$clipboard}) {
|
||||
my $title = $item->{title};
|
||||
$title =~ s/'//g; # stops it from breaking the javascript menus
|
||||
push(@{$var{clipboard_loop}}, {
|
||||
'clipboard.label'=>$title,
|
||||
'clipboard.url'=>WebGUI::URL::page("func=paste&assetId=".$item->{assetId})
|
||||
});
|
||||
if (exists $session{asset}) {
|
||||
foreach my $item (@{$session{asset}->getAssetsInClipboard(1)}) {
|
||||
my $title = $item->{title};
|
||||
$title =~ s/'//g; # stops it from breaking the javascript menus
|
||||
push(@{$var{clipboard_loop}}, {
|
||||
'clipboard.label'=>$title,
|
||||
'clipboard.url'=>WebGUI::URL::page("func=paste&assetId=".$item->{assetId})
|
||||
});
|
||||
}
|
||||
}
|
||||
#--admin functions
|
||||
%hash = (
|
||||
|
|
|
|||
|
|
@ -1,6 +1,13 @@
|
|||
package WebGUI::i18n::English::Asset;
|
||||
|
||||
our $I18N = {
|
||||
|
||||
'change' => {
|
||||
message => q|Change?|,
|
||||
lastUpdated => 1099344172,
|
||||
context => q|Used when editing an entire branch, and asks whether the user wants to change this field recursively.|
|
||||
},
|
||||
|
||||
'assets' => {
|
||||
message => q|Assets|,
|
||||
lastUpdated => 1099344172,
|
||||
|
|
|
|||
|
|
@ -111,7 +111,7 @@ Enter the possible answers to your question. Enter only one answer per line. Pol
|
|||
In order to be sure that the ordering of the answers in the poll does not bias your users, it is often helpful to present the options in a random order each time they are shown. Select "yes" to randomize the answers on the poll.
|
||||
<p>
|
||||
|
||||
<b>Reset votes.</b><br>
|
||||
<b>Reset votes?</b><br>
|
||||
Reset the votes on this Poll. This option is only available when editing an existing Poll.
|
||||
<br><br>
|
||||
|,
|
||||
|
|
@ -174,8 +174,8 @@ Reset the votes on this Poll. This option is only available when editing an exi
|
|||
},
|
||||
|
||||
'10' => {
|
||||
message => q|Reset votes.|,
|
||||
lastUpdated => 1031514049
|
||||
message => q|Reset votes?|,
|
||||
lastUpdated => 1091514049
|
||||
},
|
||||
|
||||
'5' => {
|
||||
|
|
|
|||
|
|
@ -2213,7 +2213,7 @@ will be modified to make it unique.|,
|
|||
|
||||
'651' => {
|
||||
message => q|Emptying your trash will remove these assets from your site forever. Are you sure you want to continue?|,
|
||||
lastUpdated => 1031514049
|
||||
lastUpdated => 1101514049
|
||||
},
|
||||
|
||||
'498' => {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue