package WebGUI::Wobject::MailForm;
#-------------------------------------------------------------------
# WebGUI is Copyright 2001-2002 Plain Black LLC.
#-------------------------------------------------------------------
# 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::MessageLog;
use WebGUI::Privilege;
use WebGUI::Session;
use WebGUI::SQL;
use WebGUI::URL;
use WebGUI::Wobject;
our @ISA = qw(WebGUI::Wobject);
our $namespace = "MailForm";
our $name = WebGUI::International::get(1,$namespace);
our @fields = qw(width fromField fromStatus toField toStatus
ccField ccStatus bccField bccStatus subjectField subjectStatus acknowledgement storeEntries);
#-------------------------------------------------------------------
sub _reorderFields {
my ($sth, $i, $fid);
$sth = WebGUI::SQL->read("select mailFieldId from MailForm_field where wobjectId=$_[0] order by sequenceNumber");
while (($fid) = $sth->array) {
WebGUI::SQL->write("update MailForm_field set sequenceNumber='$i' where mailFieldId=$fid");
$i++;
}
$sth->finish;
}
#-------------------------------------------------------------------
sub duplicate {
my ($w, %data, $newFieldId, $sth);
tie %data, 'Tie::CPHash';
$w = $_[0]->SUPER::duplicate($_[1]);
$w = WebGUI::Wobject::MailForm->new({wobjectId=>$w,namespace=>$namespace});
$w->set({
width=>$_[0]->get("width"),
fromField=>$_[0]->get("fromField"),
fromStatus=>$_[0]->get("fromStatus"),
toField=>$_[0]->get("toField"),
toStatus=>$_[0]->get("toStatus"),
ccField=>$_[0]->get("ccField"),
ccStatus=>$_[0]->get("ccStatus"),
bccField=>$_[0]->get("bccField"),
bccStatus=>$_[0]->get("bccStatus"),
subjectField=>$_[0]->get("subjectField"),
subjectStatus=>$_[0]->get("subjectStatus"),
acknowledgement=>$_[0]->get("acknowledgement"),
storeEntries=>$_[0]->get("storeEntries"),
});
$sth = WebGUI::SQL->read("select * from MailForm_field where wobjectId=".$_[0]->get("wobjectId"));
while (%data = $sth->hash) {
$newFieldId = getNextId("mailFieldId");
WebGUI::SQL->write(
"insert into MailForm_field values (".$w->get("wobjectId").", $newFieldId, $data{sequenceNumber}, ".
quote($data{name}).", ".
quote($data{status}).", ".
quote($data{type}).", ".
quote($data{possibleValues}).", ".
quote($data{defaultValue}).")" );
}
$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 MailForm_field where wobjectId=".$_[0]->get("wobjectId"));
WebGUI::SQL->write("delete from MailForm_entry where wobjectId=".$_[0]->get("wobjectId"));
WebGUI::SQL->write("delete from MailForm_entry_data where wobjectId=".$_[0]->get("wobjectId"));
$_[0]->SUPER::purge();
}
#-------------------------------------------------------------------
sub set {
$_[0]->SUPER::set($_[1],[@fields]);
}
#-------------------------------------------------------------------
sub www_copy {
if (WebGUI::Privilege::canEditPage()) {
$_[0]->duplicate;
return "";
} else {
return WebGUI::Privilege::insufficient();
}
}
#-------------------------------------------------------------------
sub www_deleteField {
my ($output);
if (WebGUI::Privilege::canEditPage()) {
$output = '
';
$f = WebGUI::HTMLForm->new;
$f->hidden("wid",$_[0]->get("wobjectId"));
$session{form}{fid} = "new" if ($session{form}{fid} eq "");
$f->hidden("fid",$session{form}{fid});
$f->hidden("func","editFieldSave");
$f->text("name",WebGUI::International::get(21,$namespace),$field{name});
my $status = [ $field{status} ||= 3 ]; # make it modifiable by default
$f->select("status",\%fieldStatus,WebGUI::International::get(22,$namespace),$status);
my $type = [ $field{type} ||= "text" ];
$f->select("type",\%fieldTypes,WebGUI::International::get(23,$namespace),$type);
$f->textarea("possibleValues",WebGUI::International::get(24,$namespace),$field{possibleValues});
$f->text("defaultValue",WebGUI::International::get(25,$namespace),$field{defaultValue});
$f->yesNo("proceed",WebGUI::International::get(15,$namespace));
$f->submit;
$output .= $f->print;
return $output;
} else {
return WebGUI::Privilege::insufficient();
}
return $output;
}
#-------------------------------------------------------------------
sub www_editFieldSave {
my ($seq);
if (WebGUI::Privilege::canEditPage()) {
if ($session{form}{fid} eq "new") {
($seq) = WebGUI::SQL->quickArray("select max(sequenceNumber) from MailForm_field where wobjectId=".$_[0]->get("wobjectId"));
$session{form}{fid} = getNextId("mailFieldId");
WebGUI::SQL->write("insert into MailForm_field (wobjectId,mailFieldId,sequenceNumber) values
(".$_[0]->get("wobjectId").",$session{form}{fid},".($seq+1).")");
}
WebGUI::SQL->write("update MailForm_field set name=".quote($session{form}{name}).
", status=".quote($session{form}{status}).
", type=".quote($session{form}{type}).
", possibleValues=".quote($session{form}{possibleValues}).
", defaultValue=".quote($session{form}{defaultValue}).
" where mailFieldId=$session{form}{fid}");
if ($session{form}{proceed}) {
$session{form}{fid} = "new";
return $_[0]->www_editField();
} else {
return "";
}
} else {
return WebGUI::Privilege::insufficient();
}
}
#-------------------------------------------------------------------
sub www_moveFieldDown {
my (@data, $thisSeq);
if (WebGUI::Privilege::canEditPage()) {
($thisSeq) = WebGUI::SQL->quickArray("select sequenceNumber from MailForm_field where mailFieldId=$session{form}{fid}");
@data = WebGUI::SQL->quickArray("select mailFieldId from MailForm_field where wobjectId=".$_[0]->get("wobjectId")." and sequenceNumber=$thisSeq+1 group by wobjectId");
if ($data[0] ne "") {
WebGUI::SQL->write("update MailForm_field set sequenceNumber=sequenceNumber+1 where mailFieldId=$session{form}{fid}");
WebGUI::SQL->write("update MailForm_field set sequenceNumber=sequenceNumber-1 where mailFieldId=$data[0]");
}
return "";
} else {
return WebGUI::Privilege::insufficient();
}
}
#-------------------------------------------------------------------
sub www_moveFieldUp {
my (@data, $thisSeq);
if (WebGUI::Privilege::canEditPage()) {
($thisSeq) = WebGUI::SQL->quickArray("select sequenceNumber from MailForm_field where mailFieldId=$session{form}{fid}");
@data = WebGUI::SQL->quickArray("select mailFieldId from MailForm_field where wobjectId=".$_[0]->get("wobjectId")." and sequenceNumber=$thisSeq-1 group by wobjectId");
if ($data[0] ne "") {
WebGUI::SQL->write("update MailForm_field set sequenceNumber=sequenceNumber-1 where mailFieldId=$session{form}{fid}");
WebGUI::SQL->write("update MailForm_field set sequenceNumber=sequenceNumber+1 where mailFieldId=$data[0]");
}
return "";
} else {
return WebGUI::Privilege::insufficient();
}
}
#-------------------------------------------------------------------
sub www_view {
my ($output, $sth, $f, $row, %data);
tie %data, 'Tie::CPHash';
$output = $_[0]->displayTitle;
$output .= $_[0]->description.'
';
# get all international text for each field caption
my %text = (
from => WebGUI::International::get(10, $namespace),
to => WebGUI::International::get(11, $namespace),
cc => WebGUI::International::get(12, $namespace),
bcc => WebGUI::International::get(13, $namespace),
subject => WebGUI::International::get(14, $namespace),
);
if ($session{var}{adminOn}) {
$output .= ''
.WebGUI::International::get(9,$namespace).'';
}
$f = WebGUI::HTMLForm->new();
$f->hidden("wid",$_[0]->get("wobjectId"));
$f->hidden('func','send');
foreach my $field (qw(from to cc bcc subject)) {
if ($_[0]->get("${field}Status") == 1) {
# Hidden field, don't show on form for security reasons
} else {
my $row = '
\u$field:
".$_[0]->get("${field}Field");
} else {
# Modifiable Field
if ($field eq 'content') {
my $taWidth = $_[0]->get("width") - 9;
$row .= "top\">".$text{$field}.":
";
$f->raw($row);
}
}
$sth = WebGUI::SQL->read("select * from MailForm_field where wobjectId=".$_[0]->get("wobjectId")." order by sequenceNumber");
while (%data = $sth->hash) {
# process macros on default values
$data{defaultValue} = $_[0]->processMacros($data{defaultValue});
if ($data{status} == 1) {
# hidden field, don't show on form for security reasons
$row = "";
# but show for admins
if ($session{var}{adminOn}) {
$row = "
';
return $row;
}
#-------------------------------------------------------------------
sub _fieldAdminIcons {
my $fid = $_[1];
return ' '.deleteIcon('func=deleteField&wid='.$_[0]->get("wobjectId").'&fid='.$fid)
.editIcon('func=editField&wid='.$_[0]->get("wobjectId").'&fid='.$fid)
.moveUpIcon('func=moveFieldUp&wid='.$_[0]->get("wobjectId").'&fid='.$fid)
.moveDownIcon('func=moveFieldDown&wid='.$_[0]->get("wobjectId").'&fid='.$fid);
}
# Other methods
#-------------------------------------------------------------------
# textSelectRow basically combines HTMLForm::text with HTMLForm::select
# to put a text box and select box on the same table row
sub _textSelectRow {
my ($self, $textName, $textLabel, $textValue, $textMaxLength, $selectName, $selectOptions, $selectValue) = @_;
my $output;
$textValue = WebGUI::HTMLForm::_fixQuotes($textValue);
my $textSize = $session{setting}{textBoxSize};
$output = '';
$output .= ' ';
my $selectSize = 1;
$output .= '