Added the wobject superclass and the first wobject "Item".

This commit is contained in:
JT Smith 2002-05-13 23:20:16 +00:00
parent 98960353c4
commit 842a0eb9db
11 changed files with 585 additions and 222 deletions

View file

@ -103,6 +103,7 @@ sub _createThumbnail {
sub copy {
my ($a, $b, $newNode);
$newNode = WebGUI::Node->new($_[1],$_[2]);
$newNode->create;
$a = FileHandle->new($_[0]->getPath,"r");
$b = FileHandle->new(">".$newNode->getPath.'/'.$_[0]->getFilename);
if (defined $a) {

View file

@ -1123,7 +1123,7 @@ sub url {
$extras = shift;
$subtext = shift;
$size = shift || $session{setting}{textBoxSize} || 30;
$output = '<script language="JavaScript">function addHTTP(element) {if (!element.value.match(":\/\/"))
$output = '<script language="JavaScript">function addHTTP(element) {if (!element.value.match(":\/\/") && element.value != "")
{ element.value = "http://"+element.value}}</script>';
$output .= '<input type="text" name="'.$name.'" value="'.$value.'" size="'.
$size.'" maxlength="'.$maxLength.'" onBlur="addHTTP(this.form.'.$name.')" '.$extras.'>';

View file

@ -21,7 +21,7 @@ use WebGUI::URL;
our @ISA = qw(Exporter);
our @EXPORT = qw(&helpIcon &becomeIcon &cutIcon &copyIcon &deleteIcon &editIcon &moveUpIcon &moveDownIcon
&moveTopIcon &moveBottomIcon &viewIcon);
&pageIcon &moveTopIcon &moveBottomIcon &viewIcon);
=head1 NAME

View file

@ -60,9 +60,9 @@ sub _reorderPages {
#-------------------------------------------------------------------
sub _traversePageTree {
my ($a, $b, %page, %widget, $output, $depth, $i, $spacer);
my ($a, $b, %page, %wobject, $output, $depth, $i, $spacer);
tie %page, 'Tie::CPHash';
tie %widget, 'Tie::CPHash';
tie %wobject, 'Tie::CPHash';
$spacer = '<img src="'.$session{setting}{lib}.'/spacer.gif" width=12>';
for ($i=1;$i<=$_[1];$i++) {
$depth .= $spacer;
@ -71,11 +71,11 @@ sub _traversePageTree {
while (%page = $a->hash) {
$output .= $depth.'<img src="'.$session{setting}{lib}.'/page.gif" align="middle">'.
' <a href="'.WebGUI::URL::gateway($page{urlizedTitle}).'">'.$page{title}.'</a><br>';
$b = WebGUI::SQL->read("select * from widget where pageId=$page{pageId}");
while (%widget = $b->hash) {
$b = WebGUI::SQL->read("select * from wobject where pageId=$page{pageId}");
while (%wobject = $b->hash) {
$output .= $depth.$spacer.
'<img src="'.$session{setting}{lib}.'/widget.gif"> '.
$widget{title}.'<br>';
'<img src="'.$session{setting}{lib}.'/wobject.gif"> '.
$wobject{title}.'<br>';
}
$b->finish;
$output .= _traversePageTree($page{pageId},$_[1]+1);

View file

@ -47,17 +47,17 @@ sub www_search {
$result{$data[0]} += 1;
}
$sth->finish;
$sth = WebGUI::SQL->read("select pageId from widget where title like '%".$term."%' and pageId > 25");
$sth = WebGUI::SQL->read("select pageId from wobject where title like '%".$term."%' and pageId > 25");
while (@data = $sth->array) {
$result{$data[0]} += 5;
}
$sth->finish;
$sth = WebGUI::SQL->read("select pageId from widget where description like '%".$term."%' and pageId > 25");
$sth = WebGUI::SQL->read("select pageId from wobject where description like '%".$term."%' and pageId > 25");
while (@data = $sth->array) {
$result{$data[0]} += 2;
}
$sth->finish;
$sth = WebGUI::SQL->read("select widget.pageId from Article,widget where Article.widgetId=widget.widgetId and Article.body like '%".$term."%'");
$sth = WebGUI::SQL->read("select wobject.pageId from Article,wobject where Article.wobjectId=wobject.wobjectId and Article.body like '%".$term."%'");
while (@data = $sth->array) {
$result{$data[0]} += 2;
}

View file

@ -127,7 +127,7 @@ sub www_viewStatistics {
($data) = WebGUI::SQL->quickArray("select count(*) from page where parentId>25");
$data++;
$output .= '<tr><td class="tableHeader">'.WebGUI::International::get(147).'</td><td class="tableData">'.$data.'</td></tr>';
($data) = WebGUI::SQL->quickArray("select count(*) from widget");
($data) = WebGUI::SQL->quickArray("select count(*) from wobject");
$data--;
$output .= '<tr><td class="tableHeader">'.WebGUI::International::get(148).'</td><td class="tableData">'.$data.'</td></tr>';
($data) = WebGUI::SQL->quickArray("select count(*) from style where styleId>25");

View file

@ -22,12 +22,13 @@ our @ISA = qw(Exporter);
our @EXPORT = qw(&www_purgeTrash &www_purgeTrashConfirm);
#-------------------------------------------------------------------
sub _purgeWidgets {
my ($b, $widgetId, $widgetType, $func);
$b = WebGUI::SQL->read("select widgetId, namespace from widget where pageId=$_[0]");
while (($widgetId,$widgetType) = $b->array) {
$func = "WebGUI::Widget::".$widgetType."::purge";
&$func($widgetId);
sub _purgeWobjects {
my ($b, $wobjectId, $namespace, $w, $cmd);
$b = WebGUI::SQL->read("select wobjectId, namespace from wobject where pageId=$_[0]");
while (($wobjectId,$namespace) = $b->array) {
$cmd = "WebGUI::Wobject::".$namespace;
$w = $cmd->new({wobjectId=>$wobjectId,namespace=>$namespace});
$w->purge;
}
$b->finish;
}
@ -38,7 +39,7 @@ sub _recursePageTree {
$a = WebGUI::SQL->read("select pageId from page where parentId=$_[0]");
while (($pageId) = $a->array) {
_recursePageTree($pageId);
_purgeWidgets($pageId);
_purgeWobjects($pageId);
WebGUI::SQL->write("delete from page where pageId=$pageId");
}
$a->finish;
@ -65,7 +66,7 @@ sub www_purgeTrash {
sub www_purgeTrashConfirm {
if (WebGUI::Privilege::isInGroup(3)) {
_recursePageTree(3);
_purgeWidgets(3);
_purgeWobjects(3);
return "";
} else {
return WebGUI::Privilege::adminOnly();

View file

@ -47,10 +47,11 @@ our @EXPORT = qw(&quote &getNextId);
$hashRef = WebGUI::SQL->buildHashRef($sql);
@arr = WebGUI::SQL->quickArray($sql);
%hash = WebGUI::SQL->quickHash($sql);
$hashRef = WebGUI::SQL->quickHashRef($sql);
WebGUI::SQL->write($sql);
$id = getNextId("widgetId");
$id = getNextId("wobjectId");
$string = quote($string);
=head1 DESCRIPTION
@ -355,6 +356,30 @@ sub quickHash {
}
}
#-------------------------------------------------------------------
=head2 quickHashRef ( sql [, dbh ] )
Executes a query and returns a single row of data as a hash
reference.
=item sql
An SQL query.
=item dbh
By default this method uses the WebGUI database handler. However,
you may choose to pass in your own if you wish.
=cut
sub quickHashRef {
my ($sth, %hash);
tie %hash, "Tie::CPHash";
%hash = $_[0]->quickHash($_[1],$_[2]);
return \%hash;
}
#-------------------------------------------------------------------

View file

@ -1,201 +0,0 @@
package WebGUI::Widget::Item;
our $namespace = "Item";
#-------------------------------------------------------------------
# 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::Attachment;
use WebGUI::Form;
use WebGUI::International;
use WebGUI::Privilege;
use WebGUI::Session;
use WebGUI::Shortcut;
use WebGUI::SQL;
use WebGUI::URL;
use WebGUI::Widget;
#-------------------------------------------------------------------
sub duplicate {
my (%data, $newWidgetId, $pageId, $file);
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});
$file = WebGUI::Attachment->new($data{attachment},$_[0]);
$file->copy($newWidgetId);
WebGUI::SQL->write("insert into Item values ($newWidgetId, ".
quote($data{description}).", ".quote($data{linkURL}).", ".quote($data{attachment}).")");
}
#-------------------------------------------------------------------
sub purge {
purgeWidget($_[0],$_[1],$namespace);
}
#-------------------------------------------------------------------
sub widgetName {
return WebGUI::International::get(4,$namespace);
}
#-------------------------------------------------------------------
sub www_add {
my ($output, %hash);
tie %hash,'Tie::IxHash';
if (WebGUI::Privilege::canEditPage()) {
$output = helpLink(1,$namespace);
$output .= '<h1>'.WebGUI::International::get(4,$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,30,widgetName()));
$output .= tableFormRow(WebGUI::International::get(175),WebGUI::Form::checkbox("processMacros",1,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",''));
$output .= tableFormRow(WebGUI::International::get(1,$namespace),WebGUI::Form::text("linkURL",20,2048));
$output .= tableFormRow(WebGUI::International::get(2,$namespace),WebGUI::Form::file("attachment"));
$output .= formSave();
$output .= '</table></form>';
return $output;
} else {
return WebGUI::Privilege::insufficient();
}
return $output;
}
#-------------------------------------------------------------------
sub www_addSave {
my ($widgetId, $attachment);
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});
$attachment = WebGUI::Attachment->new("",$widgetId);
$attachment->save("attachment");
WebGUI::SQL->write("insert into Item values ($widgetId, ".quote($session{form}{description}).", ".quote($session{form}{linkURL}).", ".quote($attachment->getFilename).")");
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_deleteAttachment {
if (WebGUI::Privilege::canEditPage()) {
WebGUI::SQL->write("update Item set attachment='' where widgetId=$session{form}{wid}");
return www_edit();
} else {
return WebGUI::Privilege::insufficient();
}
}
#-------------------------------------------------------------------
sub www_edit {
my ($output, %data, %hash, @array);
tie %data, 'Tie::CPHash';
tie %hash, 'Tie::IxHash';
if (WebGUI::Privilege::canEditPage()) {
%data = getProperties($namespace,$session{form}{wid});
$output .= helpLink(1,$namespace);
$output .= '<h1>'.WebGUI::International::get(4,$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,30,$data{title}));
$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}));
$output .= tableFormRow(WebGUI::International::get(1,$namespace),
WebGUI::Form::text("linkURL",20,2048,$data{linkURL}));
if ($data{attachment} ne "") {
$output .= tableFormRow(WebGUI::International::get(2,$namespace),'<a href="'.
WebGUI::URL::page('func=deleteAttachment&wid='.$session{form}{wid})
.'">'.WebGUI::International::get(3,$namespace).'</a>');
} else {
$output .= tableFormRow(WebGUI::International::get(2,$namespace),
WebGUI::Form::file("attachment"));
}
$output .= formSave();
$output .= '</table></form>';
return $output;
} else {
return WebGUI::Privilege::insufficient();
}
}
#-------------------------------------------------------------------
sub www_editSave {
my ($attachment, $sqlAdd);
if (WebGUI::Privilege::canEditPage()) {
update();
$attachment = WebGUI::Attachment->new("",$session{form}{wid});
$attachment->save("attachment");
if ($attachment->getFilename ne "") {
$sqlAdd = ', attachment='.quote($attachment->getFilename);
}
WebGUI::SQL->write("update Item set description=".quote($session{form}{description}).
", linkURL=".quote($session{form}{linkURL}).
$sqlAdd." where widgetId=$session{form}{wid}");
return "";
} else {
return WebGUI::Privilege::insufficient();
}
}
#-------------------------------------------------------------------
sub www_view {
my (%data, @test, $output, $file);
tie %data, 'Tie::CPHash';
%data = getProperties($namespace,$_[0]);
if (defined %data) {
if ($data{linkURL} ne "") {
$output .= '<a href="'.$data{linkURL}.'"><span class="itemTitle">'.$data{title}.'</span></a>';
} else {
$output .= '<span class="itemTitle">'.$data{title}.'</span>';
}
if ($data{attachment} ne "") {
$file = WebGUI::Attachment->new($data{attachment},$_[0]);
$output .= ' - <a href="'.$file->getURL.'"><img src="'.$file->getIcon.'" border=0 alt="'.
$data{attachment}.'" width=16 height=16 border=0 align="middle"></a>';
}
if ($data{description} ne "") {
$output .= ' - '.$data{description};
}
}
if ($data{processMacros} == 1) {
$output = WebGUI::Macro::process($output);
}
return $output;
}
1;

389
lib/WebGUI/Wobject.pm Normal file
View file

@ -0,0 +1,389 @@
package WebGUI::Wobject;
#-------------------------------------------------------------------
# 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 CGI::Carp qw(fatalsToBrowser);
use DBI;
use strict qw(subs vars);
use Tie::IxHash;
use WebGUI::DateTime;
use WebGUI::Icon;
use WebGUI::International;
use WebGUI::Macro;
use WebGUI::Node;
use WebGUI::Session;
use WebGUI::SQL;
use WebGUI::Template;
use WebGUI::URL;
use WebGUI::Utility;
#-------------------------------------------------------------------
sub _reorderWobjects {
my ($sth, $i, $wid);
$sth = WebGUI::SQL->read("select wobjectId from wobject where pageId=$_[0] order by templatePosition,sequenceNumber");
while (($wid) = $sth->array) {
$i++;
WebGUI::SQL->write("update wobject set sequenceNumber='$i' where wobjectId=$wid");
}
$sth->finish;
}
#-------------------------------------------------------------------
sub _getNextSequenceNumber {
my ($sequenceNumber);
($sequenceNumber) = WebGUI::SQL->quickArray("select max(sequenceNumber) from wobject where pageId='$_[0]'");
return ($sequenceNumber+1);
}
#-------------------------------------------------------------------
sub _getPositions {
my (%hash);
tie %hash, "Tie::IxHash";
%hash = WebGUI::Template::getPositions($session{page}{template});
return \%hash;
}
#-------------------------------------------------------------------
=head2 duplicate ( [ pageId ] )
Duplicates this wobject with a new wobject ID. Returns the new
wobject Id.
NOTE: This method is meant to be extended by all sub-classes.
=item pageId
If specified the wobject will be duplicated to this pageId,
otherwise it will be duplicated to the clipboard.
=cut
sub duplicate {
my ($pageId, $w);
$pageId = $_[1] || 2;
$w = WebGUI::Wobject->new({
wobjectId => "new",
namespace => $_[0]->get("namespace")
});
$w->set({
pageId => $pageId,
title => $_[0]->get("title"),
description => $_[0]->get("description"),
displayTitle => $_[0]->get("displayTitle"),
processMacros => $_[0]->get("processMacros"),
startDate => $_[0]->get("startDate"),
endDate => $_[0]->get("startDate"),
templatePosition => $_[0]->get("templatePosition")
});
return $w->get("wobjectId");
}
#-------------------------------------------------------------------
=head2 get ( [ propertyName ] )
Returns a hash reference containing all of the properties of this
wobject instance.
=item propertyName
If an individual propertyName is specified, then only that
property value is returned as a scalar.
=cut
sub get {
if ($_[1] ne "") {
return $_[0]->{_property}{$_[1]};
} else {
return $_[0]->{_property};
}
}
#-------------------------------------------------------------------
sub inDateRange {
if ($_[0]->get("startDate") < time() && $_[0]->get("startDate") > time()) {
return 1;
} else {
return 0;
}
}
#-------------------------------------------------------------------
=head2 new ( hashRef )
Constructor.
NOTE: This method is meant to be extended by all sub-classes.
=item hashRef
A hash reference containing at minimum "wobjectId" and "namespace"
and wobjectId may be set to "new" if you're creating a new
instance. This hash reference should be the one created by
WebGUI.pm and passed to the wobject subclass.
NOTE: It may seem a little weird that the initial data for the
wobject instance is coming from WebGUI.pm, but this was done
to lessen database traffic thus increasing the speed of all
wobjects.
=cut
sub new {
bless {_property => $_[1] }, $_[0];
}
#-------------------------------------------------------------------
sub processMacros {
if ($_[0]->get("processMacros")) {
return WebGUI::Macro::process($_[1]);
} else {
return $_[1];
}
}
#-------------------------------------------------------------------
=head2 purge ( )
Removes this wobject from the database and all it's attachments
from the filesystem.
NOTE: This method is meant to be extended by all sub-classes.
=cut
sub purge {
my ($node);
WebGUI::SQL->write("delete from ".$_[0]->get("namespace")." where wobjectId=".$_[0]->get("wobjectId"));
WebGUI::SQL->write("delete from wobject where wobjectId=".$_[0]->get("wobjectId"));
$node = WebGUI::Node->new($_[0]->get("wobjectId"));
$node->delete;
}
#-------------------------------------------------------------------
=head2 set ( [ hashRef ] )
Stores the values specified in hashRef to the database.
NOTE: This method should be extended by all subclasses.
=item hashRef
A hash reference of the properties of this wobject instance. This
method will accept any name/value pair and associate it with this
wobject instance in memory, but will only store the following
fields to the database:
title, displayTitle, description, processMacros,
pageId, templatePosition, startDate, endDate, sequenceNumber
=cut
sub set {
my ($key, $sql);
if ($_[0]->{_property}{wobjectId} eq "new") {
$_[0]->{_property}{wobjectId} = getNextId("widgetId");
$_[0]->{_property}{pageId} = ${$_[1]}{pageId} || $session{page}{pageId};
$_[0]->{_property}{sequenceNumber} = _getNextSequenceNumber($_[0]->{_property}{pageId});
$_[0]->{_property}{addedBy} = $session{user}{userId};
$_[0]->{_property}{dateAdded} = time();
WebGUI::SQL->write("insert into wobject
(wobjectId, namespace, dateAdded, addedBy, sequenceNumber, pageId)
values (
".$_[0]->{_property}{wobjectId}.",
".quote($_[0]->{_property}{namespace}).",
".$_[0]->{_property}{dateAdded}.",
".$_[0]->{_property}{addedBy}.",
".$_[0]->{_property}{sequenceNumber}.",
".$_[0]->{_property}{pageId}."
)");
WebGUI::SQL->write("insert into ".$_[0]->{_property}{namespace}." (wobjectId) values (".$_[0]->{_property}{wobjectId}.")");
}
$_[0]->{_property}{lastEdited} = time();
$_[0]->{_property}{editedBy} = $session{user}{userId};
$sql = "update wobject set";
foreach $key (keys %{$_[1]}) {
$_[0]->{_property}{$key} = ${$_[1]}{$key};
if (isIn($key, qw(title displayTitle description processMacros pageId templatePosition startDate endDate sequenceNumber))) {
$sql .= " ".$key."=".quote(${$_[1]}{$key}).",";
}
}
$sql .= " lastEdited=".$_[0]->{_property}{lastEdited}.",
editedBy=".$_[0]->{_property}{editedBy}."
where wobjectId=".$_[0]->{_property}{wobjectId};
WebGUI::SQL->write($sql);
}
#-------------------------------------------------------------------
sub www_cut {
if (WebGUI::Privilege::canEditPage()) {
$_[0]->set({pageId=>2});
_reorderWobjects($session{page}{pageId});
return "";
} else {
return WebGUI::Privilege::insufficient();
}
}
#-------------------------------------------------------------------
sub www_delete {
my ($output);
if (WebGUI::Privilege::canEditPage()) {
$output = helpIcon(14);
$output .= '<h1>'.WebGUI::International::get(42).'</h1>';
$output .= WebGUI::International::get(43);
$output .= '<p>';
$output .= '<div align="center"><a href="'.WebGUI::URL::page('func=deleteConfirm&wid='.
$_[0]->get("wobjectId")).'">';
$output .= WebGUI::International::get(44);
$output .= '</a>';
$output .= '&nbsp;&nbsp;&nbsp;&nbsp;<a href="'.WebGUI::URL::page().'">';
$output .= WebGUI::International::get(45);
$output .= '</a></div>';
return $output;
} else {
return WebGUI::Privilege::insufficient();
}
}
#-------------------------------------------------------------------
sub www_deleteConfirm {
if (WebGUI::Privilege::canEditPage()) {
$_[0]->set({pageId=>3});
_reorderWobjects($_[0]->get("pageId"));
return "";
} else {
return WebGUI::Privilege::insufficient();
}
}
#-------------------------------------------------------------------
sub www_edit {
my ($f, $title, $templatePosition, $endDate);
$title = $_[0]->get("title") || $_[0]->get("namespace");
$templatePosition = $_[0]->get("templatePosition") || 'A';
$endDate = $_[0]->get("endDate") || (time()+315360000);
$f = WebGUI::HTMLForm->new;
$f->hidden("wid",$_[0]->get("wobjectId"));
$f->hidden("namespace",$_[0]->get("namespace")) if ($_[0]->get("wobjectId") eq "new");
$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("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"));
$f->date("endDate",WebGUI::International::get(498),$endDate);
$f->HTMLArea("description",WebGUI::International::get(85),$_[0]->get("description"));
$f->raw($_[1]);
$f->submit;
return $f->print;
}
#-------------------------------------------------------------------
sub www_editSave {
my ($title, $templatePosition, $startDate, $endDate);
$title = $session{form}{title} || $_[0]->get("namespace");
$templatePosition = $session{form}{templatePosition} || 'A';
$startDate = setToEpoch($session{form}{startDate}) || setToEpoch(time());
$endDate = setToEpoch($session{form}{endDate}) || setToEpoch(time()+315360000);
$_[0]->set({
title=>$title,
displayTitle=>$session{form}{displayTitle},
processMacros=>$session{form}{processMacros},
templatePosition=>$templatePosition,
startDate=>$startDate,
endDate=>$endDate,
description=>$session{form}{description}
});
return "";
}
#-------------------------------------------------------------------
sub www_moveBottom {
if (WebGUI::Privilege::canEditPage()) {
$_[0]->set({sequenceNumber=>99999});
_reorderWobjects($_[0]->get("pageId"));
return "";
} else {
return WebGUI::Privilege::insufficient();
}
}
#-------------------------------------------------------------------
sub www_moveDown {
my ($wid, $thisSeq);
if (WebGUI::Privilege::canEditPage()) {
($thisSeq) = WebGUI::SQL->quickArray("select sequenceNumber from wobject where wobjectId=".$_[0]->get("wobjectId"));
($wid) = WebGUI::SQL->quickArray("select wobjectId from wobject where pageId=".$_[0]->get("pageId")
." and sequenceNumber=".($thisSeq+1));
if ($wid ne "") {
WebGUI::SQL->write("update wobject set sequenceNumber=sequenceNumber+1 where wobjectId=".$_[0]->get("wobjectId"));
WebGUI::SQL->write("update wobject set sequenceNumber=sequenceNumber-1 where wobjectId=$wid");
_reorderWobjects($_[0]->get("pageId"));
}
return "";
} else {
return WebGUI::Privilege::insufficient();
}
}
#-------------------------------------------------------------------
sub www_moveTop {
if (WebGUI::Privilege::canEditPage()) {
$_[0]->set({sequenceNumber=>0});
_reorderWobjects($_[0]->get("pageId"));
return "";
} else {
return WebGUI::Privilege::insufficient();
}
}
#-------------------------------------------------------------------
sub www_moveUp {
my ($wid, $thisSeq);
if (WebGUI::Privilege::canEditPage()) {
($thisSeq) = WebGUI::SQL->quickArray("select sequenceNumber from wobject where wobjectId=".$_[0]->get("wobjectId"));
($wid) = WebGUI::SQL->quickArray("select wobjectId from wobject where pageId=".$_[0]->get("pageId")
." and sequenceNumber=".($thisSeq-1));
if ($wid ne "") {
WebGUI::SQL->write("update wobject set sequenceNumber=sequenceNumber-1 where wobjectId=".$_[0]->get("wobjectId"));
WebGUI::SQL->write("update wobject set sequenceNumber=sequenceNumber+1 where wobjectId=$wid");
_reorderWobjects($_[0]->get("pageId"));
}
return "";
} else {
return WebGUI::Privilege::insufficient();
}
}
#-------------------------------------------------------------------
sub www_paste {
my ($output, $nextSeq);
if (WebGUI::Privilege::canEditPage()) {
($nextSeq) = WebGUI::SQL->quickArray("select max(sequenceNumber) from wobject where pageId=$session{page}{pageId}");
$nextSeq += 1;
$_[0]->set({sequenceNumber=>$nextSeq, pageId=>$session{page}{pageId}});
return "";
} else {
return WebGUI::Privilege::insufficient();
}
}
1;

148
lib/WebGUI/Wobject/Item.pm Normal file
View file

@ -0,0 +1,148 @@
package WebGUI::Wobject::Item;
#-------------------------------------------------------------------
# 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::Attachment;
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 = "Item";
our $name = WebGUI::International::get(4,$namespace);
#-------------------------------------------------------------------
sub duplicate {
my ($w, $f);
$w = $_[0]->SUPER::duplicate($_[1]);
$w = WebGUI::Wobject::Item->new({wobjectId=>$w,namespace=>$namespace});
$w->set({
linkURL=>$_[0]->get("linkURL"),
attachment=>$_[0]->get("attachment"),
});
$f = WebGUI::Attachment->new($_[0]->get("attachment"),$_[0]->get("wobjectId"));
$f->copy($w->get("wobjectId"));
}
#-------------------------------------------------------------------
sub new {
my ($self, $class, $property);
$class = shift;
$property = shift;
$self = WebGUI::Wobject->new($property);
bless $self, $class;
}
#-------------------------------------------------------------------
sub set {
my ($key, $sql, @update, $i);
$_[0]->SUPER::set($_[1]);
foreach $key (keys %{$_[1]}) {
if (isIn($key, qw(linkURL attachment))) {
$update[$i] .= " ".$key."=".quote($_[1]->{$key});
$i++;
}
}
WebGUI::SQL->write("update Item set".join(",",@update)." where wobjectId=".$_[0]->get("wobjectId")) if (@update);
}
#-------------------------------------------------------------------
sub www_copy {
if (WebGUI::Privilege::canEditPage()) {
$_[0]->duplicate;
return "";
} else {
return WebGUI::Privilege::insufficient();
}
}
#-------------------------------------------------------------------
sub www_deleteAttachment {
if (WebGUI::Privilege::canEditPage()) {
$_[0]->set({attachment=>''});
return $_[0]->www_edit();
} else {
return WebGUI::Privilege::insufficient();
}
}
#-------------------------------------------------------------------
sub www_edit {
my ($output, $f);
if (WebGUI::Privilege::canEditPage()) {
$output = helpIcon(1,$_[0]->get("namespace"));
$output .= '<h1>'.WebGUI::International::get(4,$namespace).'</h1>';
$f = WebGUI::HTMLForm->new;
$f->url("linkURL",WebGUI::International::get(1,$_[0]->get("namespace")),$_[0]->get("linkURL"));
if ($_[0]->get("attachment") eq "") {
$f->file("attachment",WebGUI::International::get(2,$_[0]->get("namespace")))
} else {
$f->readOnly('<a href="'.WebGUI::URL::page('func=deleteAttachment&wid='.$session{form}{wid}).'">'
.WebGUI::International::get(3,$namespace).'</a>',WebGUI::International::get(2,$_[0]->get("namespace")))
}
$output .= $_[0]->SUPER::www_edit($f->printRowsOnly);
return $output;
} else {
return WebGUI::Privilege::insufficient();
}
}
#-------------------------------------------------------------------
sub www_editSave {
my ($attachment);
if (WebGUI::Privilege::canEditPage()) {
$_[0]->SUPER::www_editSave();
$attachment = WebGUI::Attachment->new("",$_[0]->get("wobjectId"));
$attachment->save("attachment");
$_[0]->set({
linkURL=>$session{form}{linkURL},
attachment=>$attachment->getFilename
});
return "";
} else {
return WebGUI::Privilege::insufficient();
}
}
#-------------------------------------------------------------------
sub www_view {
my (@test, $output, $file);
if ($_[0]->get("displayTitle")) {
$output = '<span class="itemTitle">'.$_[0]->get("title").'</span>';
if ($_[0]->get("linkURL")) {
$output = '<a href="'.$_[0]->get("linkURL").'">'.$output.'</span></a>';
}
}
if ($_[0]->get("attachment") ne "") {
$file = WebGUI::Attachment->new($_[0]->get("attachment"),$_[0]->get("wobjectId"));
if ($_[0]->get("displayTitle")) {
$output .= ' - ';
}
$output .= '<a href="'.$file->getURL.'"><img src="'.$file->getIcon.'" border=0 alt="'.
$_[0]->get("attachment").'" width=16 height=16 border=0 align="middle"></a>';
}
if ($_[0]->get("description") ne "") {
$output .= ' - '.$_[0]->get("description");
}
return $_[0]->processMacros($output);
}
1;