From 5db70ffc070ad4f4175c569a52e015d514133094 Mon Sep 17 00:00:00 2001 From: JT Smith Date: Fri, 12 Jul 2002 02:37:28 +0000 Subject: [PATCH] Added feature to expire pages. --- docs/upgrades/upgrade_4.2.0-4.3.0.sql | 6 +- lib/WebGUI/Icon.pm | 129 +++++++++++++++++++------- lib/WebGUI/Operation/Page.pm | 29 ++++-- lib/WebGUI/Privilege.pm | 24 +++-- 4 files changed, 138 insertions(+), 50 deletions(-) diff --git a/docs/upgrades/upgrade_4.2.0-4.3.0.sql b/docs/upgrades/upgrade_4.2.0-4.3.0.sql index a95849f66..8ff86c812 100644 --- a/docs/upgrades/upgrade_4.2.0-4.3.0.sql +++ b/docs/upgrades/upgrade_4.2.0-4.3.0.sql @@ -656,8 +656,10 @@ delete from international where namespace='WebGUI' and internationalId=128; delete from settings where name='attachmentDirectoryLocal'; delete from settings where name='attachmentDirectoryWeb'; delete from settings where name='lib'; - - +update international set message='Attachment' where internationalId=33 and languageId=1 and namespace='UserSubmission'; +alter table page add column startDate int not null default 946710000; +alter table page add column endDate int not null default 2082783600; +update page set styleId=-6 where styleId=-3; diff --git a/lib/WebGUI/Icon.pm b/lib/WebGUI/Icon.pm index 6f071e0dd..4b0a56f64 100644 --- a/lib/WebGUI/Icon.pm +++ b/lib/WebGUI/Icon.pm @@ -21,7 +21,7 @@ use WebGUI::URL; our @ISA = qw(Exporter); our @EXPORT = qw(&helpIcon &becomeIcon &cutIcon ©Icon &deleteIcon &editIcon &moveUpIcon &moveDownIcon - &pageIcon &moveTopIcon &moveBottomIcon &viewIcon); + &wobjectIcon &pageIcon &moveTopIcon &moveBottomIcon &viewIcon); =head1 NAME @@ -42,6 +42,7 @@ our @EXPORT = qw(&helpIcon &becomeIcon &cutIcon ©Icon &deleteIcon &editIcon $html = moveUpIcon('op=something'); $html = pageIcon(); $html = viewIcon('op=something'); + $html = wobjectIcon(); =head1 DESCRIPTION @@ -58,7 +59,7 @@ our @EXPORT = qw(&helpIcon &becomeIcon &cutIcon ©Icon &deleteIcon &editIcon #------------------------------------------------------------------- -=head2 becomeIcon ( urlParameters ) +=head2 becomeIcon ( urlParameters [, pageURL ] ) Generates a button with the word "Become" printed on it. @@ -67,18 +68,23 @@ our @EXPORT = qw(&helpIcon &becomeIcon &cutIcon ©Icon &deleteIcon &editIcon Any URL parameters that need to be tacked on to the current URL to accomplish whatever function this button represents. +=item pageURL + + The URL to any page. Defaults to the current page. + =cut sub becomeIcon { - my ($output); - $output = ''; + my ($output, $pageURL); + $pageURL = $_[1] || $session{page}{urlizedTitle}; + $output = ''; $output .= 'Become'; return $output; } #------------------------------------------------------------------- -=head2 copyIcon ( urlParameters ) +=head2 copyIcon ( urlParameters [, pageURL ] ) Generates a button with the word "Copy" printed on it. @@ -87,18 +93,23 @@ sub becomeIcon { Any URL parameters that need to be tacked on to the current URL to accomplish whatever function this button represents. +=item pageURL + + The URL to any page. Defaults to the current page. + =cut sub copyIcon { - my ($output); - $output = ''; + my ($output, $pageURL); + $pageURL = $_[1] || $session{page}{urlizedTitle}; + $output = ''; $output .= 'Copy'; return $output; } #------------------------------------------------------------------- -=head2 cutIcon ( urlParameters ) +=head2 cutIcon ( urlParameters [, pageURL ] ) Generates a button with the word "Cut" printed on it. @@ -107,18 +118,23 @@ sub copyIcon { Any URL parameters that need to be tacked on to the current URL to accomplish whatever function this button represents. +=item pageURL + + The URL to any page. Defaults to the current page. + =cut sub cutIcon { - my ($output); - $output = ''; + my ($output, $pageURL); + $pageURL = $_[1] || $session{page}{urlizedTitle}; + $output = ''; $output .= 'Cut'; return $output; } #------------------------------------------------------------------- -=head2 deleteIcon ( urlParameters ) +=head2 deleteIcon ( urlParameters [, pageURL ] ) Generates a button with an "X" printed on it. @@ -127,18 +143,23 @@ sub cutIcon { Any URL parameters that need to be tacked on to the current URL to accomplish whatever function this button represents. +=item pageURL + + The URL to any page. Defaults to the current page. + =cut sub deleteIcon { - my ($output); - $output = ''; + my ($output, $pageURL); + $pageURL = $_[1] || $session{page}{urlizedTitle}; + $output = ''; $output .= 'Delete'; return $output; } #------------------------------------------------------------------- -=head2 editIcon ( urlParameters ) +=head2 editIcon ( urlParameters [, pageURL ] ) Generates a button with the word "Edit" printed on it. @@ -147,18 +168,23 @@ sub deleteIcon { Any URL parameters that need to be tacked on to the current URL to accomplish whatever function this button represents. +=item pageURL + + The URL to any page. Defaults to the current page. + =cut sub editIcon { - my ($output); - $output = ''; + my ($output, $pageURL); + $pageURL = $_[1] || $session{page}{urlizedTitle}; + $output = ''; $output .= 'Edit'; return $output; } #------------------------------------------------------------------- -=head2 becomeIcon ( helpId [, namespace ] ) +=head2 helpIcon ( helpId [, namespace ] ) Generates a button with the word "Help" printed on it. @@ -184,7 +210,7 @@ sub helpIcon { #------------------------------------------------------------------- -=head2 moveBottomIcon ( urlParameters ) +=head2 moveBottomIcon ( urlParameters [, pageURL ] ) Generates a button with a double down arrow printed on it. @@ -193,18 +219,23 @@ sub helpIcon { Any URL parameters that need to be tacked on to the current URL to accomplish whatever function this button represents. +=item pageURL + + The URL to any page. Defaults to the current page. + =cut sub moveBottomIcon { - my ($output); - $output = ''; + my ($output, $pageURL); + $pageURL = $_[1] || $session{page}{urlizedTitle}; + $output = ''; $output .= 'Move To Bottom'; return $output; } #------------------------------------------------------------------- -=head2 moveDownIcon ( urlParameters ) +=head2 moveDownIcon ( urlParameters [, pageURL ] ) Generates a button with a down arrow printed on it. @@ -213,18 +244,23 @@ sub moveBottomIcon { Any URL parameters that need to be tacked on to the current URL to accomplish whatever function this button represents. +=item pageURL + + The URL to any page. Defaults to the current page. + =cut sub moveDownIcon { - my ($output); - $output = ''; + my ($output, $pageURL); + $pageURL = $_[1] || $session{page}{urlizedTitle}; + $output = ''; $output .= 'Move Down'; return $output; } #------------------------------------------------------------------- -=head2 moveTopIcon ( urlParameters ) +=head2 moveTopIcon ( urlParameters [, pageURL ] ) Generates a button with a double up arrow printed on it. @@ -233,18 +269,23 @@ sub moveDownIcon { Any URL parameters that need to be tacked on to the current URL to accomplish whatever function this button represents. +=item pageURL + + The URL to any page. Defaults to the current page. + =cut sub moveTopIcon { - my ($output); - $output = ''; + my ($output, $pageURL); + $pageURL = $_[1] || $session{page}{urlizedTitle}; + $output = ''; $output .= 'Move To Top'; return $output; } #------------------------------------------------------------------- -=head2 moveUpIcon ( urlParameters ) +=head2 moveUpIcon ( urlParameters [, pageURL ] ) Generates a button with an up arrow printed on it. @@ -253,11 +294,16 @@ sub moveTopIcon { Any URL parameters that need to be tacked on to the current URL to accomplish whatever function this button represents. +=item pageURL + + The URL to any page. Defaults to the current page. + =cut sub moveUpIcon { - my ($output); - $output = ''; + my ($output, $pageURL); + $pageURL = $_[1] || $session{page}{urlizedTitle}; + $output = ''; $output .= 'Move Up'; return $output; } @@ -278,7 +324,7 @@ sub pageIcon { #------------------------------------------------------------------- -=head2 viewIcon ( urlParameters ) +=head2 viewIcon ( urlParameters [, pageURL ] ) Generates a button with the word "View" printed on it. @@ -287,15 +333,34 @@ sub pageIcon { Any URL parameters that need to be tacked on to the current URL to accomplish whatever function this button represents. +=item pageURL + + The URL to any page. Defaults to the current page. + =cut sub viewIcon { - my ($output); - $output = ''; + my ($output, $pageURL); + $pageURL = $_[1] || $session{page}{urlizedTitle}; + $output = ''; $output .= 'View'; return $output; } +#------------------------------------------------------------------- + +=head2 wobjectIcon ( ) + + Generates an icon that looks like a wobject. It's purpose is to + represent whether you're looking at page properties or Wobject + properties. + +=cut + +sub wobjectIcon { + return 'Wobject Settings'; +} + 1; diff --git a/lib/WebGUI/Operation/Page.pm b/lib/WebGUI/Operation/Page.pm index 36ae10ea5..7a61f86f6 100644 --- a/lib/WebGUI/Operation/Page.pm +++ b/lib/WebGUI/Operation/Page.pm @@ -12,6 +12,7 @@ package WebGUI::Operation::Page; use Exporter; use strict; +use WebGUI::DateTime; use WebGUI::HTMLForm; use WebGUI::Icon; use WebGUI::International; @@ -31,7 +32,8 @@ sub _recursivelyChangePrivileges { my ($sth, $pageId); $sth = WebGUI::SQL->read("select pageId from page where parentId=$_[0]"); while (($pageId) = $sth->array) { - WebGUI::SQL->write("update page set ownerId=$session{form}{ownerId}, ownerView=$session{form}{ownerView}, + WebGUI::SQL->write("update page set startDate=$session{form}{startDate}, endDate=$session{form}{endDate}, + ownerId=$session{form}{ownerId}, ownerView=$session{form}{ownerView}, ownerEdit=$session{form}{ownerEdit}, groupId='$session{form}{groupId}', groupView=$session{form}{groupView}, groupEdit=$session{form}{groupEdit}, worldView=$session{form}{worldView}, worldEdit=$session{form}{worldEdit} where pageId=$pageId"); @@ -73,13 +75,18 @@ sub _traversePageTree { } $a = WebGUI::SQL->read("select * from page where (pageId<2 or pageId>25) and parentId='$_[0]' order by sequenceNumber"); while (%page = $a->hash) { - $output .= $depth.''. - ' '.$page{title}.'
'; + $output .= $depth + .pageIcon() + .deleteIcon('op=deletePage',$page{urlizedTitle}) + .editIcon('op=editPage',$page{urlizedTitle}) + .' '.$page{title}.'
'; $b = WebGUI::SQL->read("select * from wobject where pageId=$page{pageId}"); while (%wobject = $b->hash) { - $output .= $depth.$spacer. - ' '. - $wobject{title}.'
'; + $output .= $depth.$spacer + .wobjectIcon() + .deleteIcon('func=delete&wid='.$wobject{wobjectId},$page{urlizedTitle}) + .editIcon('func=edit&wid='.$wobject{wobjectId},$page{urlizedTitle}) + .' '. $wobject{title}.'
'; } $b->finish; $output .= _traversePageTree($page{pageId},$_[1]+1); @@ -137,7 +144,7 @@ sub www_deletePageConfirm { #------------------------------------------------------------------- sub www_editPage { - my ($f, $output, %hash, %page); + my ($f, $endDate, $output, %hash, %page); tie %hash, "Tie::IxHash"; if (WebGUI::Privilege::canEditPage($session{form}{npp})) { $f = WebGUI::HTMLForm->new; @@ -152,11 +159,13 @@ sub www_editPage { } else { %page = %{$session{page}}; } + $page{endDate} = (time()+315360000) if ($page{endDate} < 0); $output = helpIcon(1); $output .= '

'.WebGUI::International::get(102).'

'; $f->hidden("pageId",$page{pageId}); $f->hidden("parentId",$page{parentId}); $f->hidden("op","editPageSave"); + $f->submit if ($page{pageId} ne "new"); $f->raw(''.WebGUI::International::get(103).''); $f->readOnly($page{pageId},WebGUI::International::get(500)); $f->text("title",WebGUI::International::get(99),$page{title}); @@ -172,6 +181,8 @@ sub www_editPage { '   '.WebGUI::International::get(6).''); $f->yesNo("recurseStyle",'','','','   '.WebGUI::International::get(106)); $f->raw('
'.WebGUI::International::get(107).''); + $f->date("startDate",WebGUI::International::get(497),$page{startDate}); + $f->date("endDate",WebGUI::International::get(498),$page{endDate}); %hash = WebGUI::SQL->buildHash("select users.userId,users.username from users,groupings where groupings.groupId=4 and groupings.userId=users.userId order by users.username"); $f->select("ownerId",\%hash,WebGUI::International::get(108),[$page{ownerId}],'','','', @@ -213,6 +224,8 @@ sub www_editPageSave { $session{form}{menuTitle} = $session{form}{title} if ($session{form}{menuTitle} eq ""); $session{form}{urlizedTitle} = $session{form}{menuTitle} if ($session{form}{urlizedTitle} eq ""); $session{form}{urlizedTitle} = WebGUI::URL::makeUnique(WebGUI::URL::urlize($session{form}{urlizedTitle}),$session{form}{pageId}); + $session{form}{startDate} = setToEpoch($session{form}{startDate}) || setToEpoch(time()); + $session{form}{endDate} = setToEpoch($session{form}{endDate}) || setToEpoch(time()+315360000); WebGUI::SQL->write("update page set title=".quote($session{form}{title}).", styleId=$session{form}{styleId}, @@ -224,6 +237,8 @@ sub www_editPageSave { groupEdit=$session{form}{groupEdit}, worldView=$session{form}{worldView}, worldEdit=$session{form}{worldEdit}, + startDate=$session{form}{startDate}, + endDate=$session{form}{endDate}, metaTags=".quote($session{form}{metaTags}).", urlizedTitle='$session{form}{urlizedTitle}', defaultMetaTags='$session{form}{defaultMetaTags}', diff --git a/lib/WebGUI/Privilege.pm b/lib/WebGUI/Privilege.pm index 631979569..d4052868d 100644 --- a/lib/WebGUI/Privilege.pm +++ b/lib/WebGUI/Privilege.pm @@ -47,7 +47,7 @@ sub canEditPage { my ($isContentManager,%page); tie %page, 'Tie::CPHash'; if ($_[0] ne "") { - %page = WebGUI::SQL->quickHash("select * from page where pageId=$_[0]"); + %page = WebGUI::SQL->quickHash("select ownerId,ownerEdit,worldEdit,groupId,groupEdit from page where pageId=$_[0]"); } else { %page = %{$session{page}}; } @@ -56,10 +56,10 @@ sub canEditPage { return 1; } elsif ($session{user}{userId} eq $page{ownerId} && $page{ownerEdit} && $isContentManager) { return 1; - } elsif (isInGroup(3)) { - return 1; } elsif (isInGroup($page{groupId}) && $page{groupEdit} && $isContentManager) { return 1; + } elsif (isInGroup(3)) { # admin check + return 1; } else { return 0; } @@ -67,21 +67,27 @@ sub canEditPage { #------------------------------------------------------------------- sub canViewPage { - my (%page); + my (%page, $inDateRange); tie %page, 'Tie::CPHash'; if ($_[0] eq "") { %page = %{$session{page}}; } else { - %page = WebGUI::SQL->quickHash("select * from page where pageId=$_[0]"); + %page = WebGUI::SQL->quickHash("select ownerId,ownerView,groupId,groupView,worldView,startDate,endDate + from page where pageId=$_[0]"); } - if ($page{worldView}) { + if ($page{startDate} < time() && $page{endDate} > time()) { + $inDateRange = 1; + } + if ($page{worldView} && $inDateRange) { return 1; - } elsif ($session{user}{userId} eq $page{ownerId} && $page{ownerView}) { + } elsif ($session{user}{userId} eq $page{ownerId} && $page{ownerView} && $inDateRange) { + return 1; + } elsif (isInGroup($page{groupId}) && $page{groupView} && $inDateRange) { return 1; } elsif (isInGroup(3)) { # admin check return 1; - } elsif (isInGroup($page{groupId}) && $page{groupView}) { - return 1; + } elsif (canEditPage($_[0])) { + return 1; } else { return 0; }