Converted the Mail Form into the Data Form.
This commit is contained in:
parent
f7ca23aa03
commit
8f6348a5bb
8 changed files with 939 additions and 902 deletions
575
lib/WebGUI/Wobject/DataForm.pm
Normal file
575
lib/WebGUI/Wobject/DataForm.pm
Normal file
|
|
@ -0,0 +1,575 @@
|
|||
package WebGUI::Wobject::DataForm;
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
# WebGUI is Copyright 2001-2003 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 qw(vars subs);
|
||||
use Tie::CPHash;
|
||||
use Tie::IxHash;
|
||||
use WebGUI::DateTime;
|
||||
use WebGUI::Form;
|
||||
use WebGUI::FormProcessor;
|
||||
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;
|
||||
use WebGUI::Utility;
|
||||
|
||||
our @ISA = qw(WebGUI::Wobject);
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub _createField {
|
||||
my $data = $_[0];
|
||||
my %param;
|
||||
$param{name} = WebGUI::URL::urlize($data->{name});
|
||||
$param{name} = "field_".$data->{sequenceNumber} if ($param{name} eq ""); # Empty fieldname not allowed
|
||||
$session{form}{$param{name}} =~ s/\^.*?\;//gs ; # remove macro's from user input
|
||||
$param{value} = $data->{value};
|
||||
$param{size} = $data->{width};
|
||||
$param{rows} = $data->{rows} || 5;
|
||||
$param{columns} = $data->{width};
|
||||
$param{vertical} = 1;
|
||||
if ($data->{type} eq "checkbox") {
|
||||
$param{value} = ($data->{defaultValue} =~ /checked/i) ? 1 : "";
|
||||
}
|
||||
if (isIn($data->{type},qw(selectList checkboxList))) {
|
||||
my @defaultValues;
|
||||
if ($session{form}{$param{name}}) {
|
||||
@defaultValues = $session{cgi}->param($param{name});
|
||||
} else {
|
||||
foreach (split(/\n/, $data->{defaultValue})) {
|
||||
s/\s+$//; # remove trailing spaces
|
||||
push(@defaultValues, $_);
|
||||
}
|
||||
}
|
||||
$param{value} = \@defaultValues;
|
||||
}
|
||||
if (isIn($data->{type},qw(selectList checkboxList radioList))) {
|
||||
delete $param{size};
|
||||
my %options;
|
||||
tie %options, 'Tie::IxHash';
|
||||
foreach (split(/\n/, $data->{possibleValues})) {
|
||||
s/\s+$//; # remove trailing spaces
|
||||
$options{$_} = $_;
|
||||
}
|
||||
$param{options} = \%options;
|
||||
}
|
||||
if ($data->{type} eq "yesNo") {
|
||||
if ($data->{defaultValue} =~ /yes/i) {
|
||||
$param{value} = 1;
|
||||
} elsif ($data->{defaultValue} =~ /no/i) {
|
||||
$param{value} = 0;
|
||||
}
|
||||
}
|
||||
my $cmd = "WebGUI::Form::".$data->{type};
|
||||
return &$cmd(\%param);
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub _fieldAdminIcons {
|
||||
my $fid = $_[1];
|
||||
my $output;
|
||||
$output = deleteIcon('func=deleteField&wid='.$_[0]->get("wobjectId").'&fid='.$fid) unless ($_[2]);
|
||||
$output .= 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);
|
||||
return $output;
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub duplicate {
|
||||
my ($w, %data, $sth);
|
||||
tie %data, 'Tie::CPHash';
|
||||
$w = $_[0]->SUPER::duplicate($_[1]);
|
||||
$w = WebGUI::Wobject::DataForm->new({wobjectId=>$w,namespace=>$_[0]->get("namespace")});
|
||||
$sth = WebGUI::SQL->read("select * from DataForm_field where wobjectId=".$_[0]->get("wobjectId"));
|
||||
while (%data = $sth->hash) {
|
||||
$data{DataForm_fieldId} = "new";
|
||||
$w->setCollateral("DataForm_field","DataForm_fieldId",\%data);
|
||||
}
|
||||
$sth->finish;
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub getTemplateVars {
|
||||
my $self = shift;
|
||||
my $var = shift;
|
||||
$var->{error_loop} = [] unless (exists $var->{error_loop});
|
||||
$var->{canEdit} = (WebGUI::Privilege::canEditPage());
|
||||
$var->{"export.tab.url"} = WebGUI::URL::page('func=exportTab&wid='.$self->get("wobjectId"));
|
||||
$var->{"export.tab.label"} = WebGUI::International::get(84,$self->get("namespace"));
|
||||
$var->{"back.url"} = WebGUI::URL::page();
|
||||
$var->{"back.label"} = WebGUI::International::get(18,$self->get("namespace"));
|
||||
$var->{"addField.url"} = WebGUI::URL::page('func=editField&wid='.$self->get("wobjectId"));
|
||||
$var->{"addField.label"} = WebGUI::International::get(76,$self->get("namespace"));
|
||||
$var->{"form.start"} = WebGUI::Form::formHeader()
|
||||
.WebGUI::Form::hidden({name=>"wid",value=>$self->get("wobjectId")})
|
||||
.WebGUI::Form::hidden({name=>"func",value=>"process"});
|
||||
my @fields;
|
||||
my $where = "where a.wobjectId=".$self->get("wobjectId");
|
||||
my $select = "select a.name, a.label, a.status, a.isMailField, a.subtext, a.type, a.defaultValue, a.possibleValues, a.width, a.rows";
|
||||
my $join;
|
||||
if ($var->{entryId}) {
|
||||
$var->{"form.start"} .= WebGUI::Form::hidden({name=>"entryId",value=>$var->{entryId}});
|
||||
my $entry = $self->getCollateral("DataForm_entry","DataForm_entryId",$var->{entryId});
|
||||
$var->{ipAddress} = $entry->{ipAddress};
|
||||
$var->{username} = $entry->{username};
|
||||
$var->{userId} = $entry->{userId};
|
||||
$var->{date} = WebGUI::DateTime::epochToHuman($entry->{submissionDate});
|
||||
$var->{epoch} = $entry->{submissionDate};
|
||||
$var->{"edit.URL"} = WebGUI::URL::page('func=view&wid='.$self->get("wobjectId").'&entryId='.$var->{entryId});
|
||||
$where .= " and b.DataForm_entryId=".$var->{entryId};
|
||||
$join = "left join DataForm_entryData as b on a.name=b.name";
|
||||
$select .= ", b.value";
|
||||
}
|
||||
my %data;
|
||||
tie %data, 'Tie::CPHash';
|
||||
my $sth = WebGUI::SQL->read("$select from DataForm_field as a $join $where order by a.sequenceNumber");
|
||||
while (%data = $sth->hash) {
|
||||
my $formValue = $session{form}{WebGUI::URL::urlize($data{name})};
|
||||
if (defined $formValue) {
|
||||
$data{value} = $formValue;
|
||||
} elsif (not exists $data{value}) {
|
||||
$data{value} = $data{defaultValue};
|
||||
}
|
||||
push(@fields,{
|
||||
"field.form" => _createField(\%data),
|
||||
"field.name" => $data{name},
|
||||
"field.value" => $data{value},
|
||||
"field.label" => $data{label},
|
||||
"field.isMailField" => $data{isMailField},
|
||||
"field.isRequired" => ($data{status} eq "required"),
|
||||
"field.isHidden" => ($data{status} eq "hidden" && !$session{var}{adminOn}),
|
||||
"field.isDisplayed" => ($data{status} eq "displayed"),
|
||||
"field.isEditable" => ($data{status} eq "editable"),
|
||||
"field.subtext" => $data{subtext},
|
||||
"field.controls" => $self->_fieldAdminIcons($data{DataForm_fieldId},$data{isMailField})
|
||||
});
|
||||
}
|
||||
$sth->finish;
|
||||
$var->{field_loop} = \@fields;
|
||||
$var->{"form.send"} = WebGUI::Form::submit({value=>WebGUI::International::get(73, $self->get("namespace"))});
|
||||
$var->{"form.save"} = WebGUI::Form::submit();
|
||||
$var->{"form.end"} = "</form>";
|
||||
return $var;
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub name {
|
||||
return WebGUI::International::get(1,$_[0]->get("namespace"));
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub new {
|
||||
my $class = shift;
|
||||
my $property = shift;
|
||||
my $self = WebGUI::Wobject->new(
|
||||
-properties=>$property,
|
||||
-extendedProperties=>{
|
||||
acknowledgement=>{},
|
||||
templateId=>{
|
||||
defaultValue=>1
|
||||
},
|
||||
emailTemplateId=>{
|
||||
defaultValue=>2
|
||||
},
|
||||
acknowlegementTemplateId=>{
|
||||
defaultValue=>3,
|
||||
},
|
||||
mailData=>{
|
||||
defaultValue=>0
|
||||
},
|
||||
}
|
||||
);
|
||||
bless $self, $class;
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub purge {
|
||||
WebGUI::SQL->write("delete from DataForm_field where wobjectId=".$_[0]->get("wobjectId"));
|
||||
WebGUI::SQL->write("delete from DataForm_entry where wobjectId=".$_[0]->get("wobjectId"));
|
||||
WebGUI::SQL->write("delete from DataForm_entryData where wobjectId=".$_[0]->get("wobjectId"));
|
||||
$_[0]->SUPER::purge();
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub sendEmail {
|
||||
my $var = $_[1];
|
||||
my $message = WebGUI::Macro::process($_[0]->processTemplate($_[0]->get("emailTemplateId"),$var));
|
||||
my ($to, $subject, $from, $bcc, $cc);
|
||||
foreach my $row (@{$var->{field_loop}}) {
|
||||
if ($row->{"field.name"} eq "to") {
|
||||
$to = $row->{"field.value"};
|
||||
} elsif ($row->{"field.name"} eq "from") {
|
||||
$from = $row->{"field.value"};
|
||||
} elsif ($row->{"field.name"} eq "cc") {
|
||||
$cc = $row->{"field.value"};
|
||||
} elsif ($row->{"field.name"} eq "bcc") {
|
||||
$bcc = $row->{"field.value"};
|
||||
} elsif ($row->{"field.name"} eq "subject") {
|
||||
$subject = $row->{"field.value"};
|
||||
}
|
||||
}
|
||||
if ($to =~ /\@/) {
|
||||
WebGUI::Mail::send(
|
||||
$to,
|
||||
$subject,
|
||||
$message,
|
||||
$cc,
|
||||
$from,
|
||||
$bcc
|
||||
);
|
||||
} else {
|
||||
my ($userId) = WebGUI::SQL->quickArray("select userId from users where username=".quote($to));
|
||||
my $groupId;
|
||||
# if no user is found, try finding a matching group
|
||||
unless ($userId) {
|
||||
($groupId) = WebGUI::SQL->quickArray("select groupId from groups where groupName=".quote($to));
|
||||
}
|
||||
unless ($userId || $groupId) {
|
||||
WebGUI::ErrorHandler::warn($_[0]->get("wobjectId").": Unable to send message, no user or group found.");
|
||||
} else {
|
||||
WebGUI::MessageLog::addEntry($userId, $groupId, $subject, $message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub uiLevel {
|
||||
return 5;
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub www_deleteField {
|
||||
return WebGUI::Privilege::insufficient() unless (WebGUI::Privilege::canEditPage());
|
||||
return $_[0]->confirm(WebGUI::International::get(19,$_[0]->get("namespace")),
|
||||
WebGUI::URL::page('func=deleteFieldConfirm&wid='.$_[0]->get("wobjectId").'&fid='.$session{form}{fid}));
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub www_deleteFieldConfirm {
|
||||
return WebGUI::Privilege::insufficient() unless (WebGUI::Privilege::canEditPage());
|
||||
$_[0]->deleteCollateral("DataForm_field","DataForm_fieldId",$session{form}{fid});
|
||||
$_[0]->reorderCollateral("DataForm_field","DataForm_fieldId");
|
||||
return "";
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub www_edit {
|
||||
my $layout = WebGUI::HTMLForm->new;
|
||||
$layout->template(
|
||||
-name=>"templateId",
|
||||
-value=>$_[0]->getValue("templateId"),
|
||||
-namespace=>$_[0]->get("namespace"),
|
||||
-label=>WebGUI::International::get(78,$_[0]->get("namespace")),
|
||||
-afterEdit=>'func=edit&wid='.$_[0]->get("wobjectId")
|
||||
);
|
||||
$layout->template(
|
||||
-name=>"emailTemplateId",
|
||||
-value=>$_[0]->getValue("emailTemplateId"),
|
||||
-namespace=>$_[0]->get("namespace"),
|
||||
-label=>WebGUI::International::get(80,$_[0]->get("namespace")),
|
||||
-afterEdit=>'func=edit&wid='.$_[0]->get("wobjectId")
|
||||
);
|
||||
$layout->template(
|
||||
-name=>"acknowlegementTemplateId",
|
||||
-value=>$_[0]->getValue("acknowlegementTemplateId"),
|
||||
-namespace=>$_[0]->get("namespace"),
|
||||
-label=>WebGUI::International::get(81,$_[0]->get("namespace")),
|
||||
-afterEdit=>'func=edit&wid='.$_[0]->get("wobjectId")
|
||||
);
|
||||
my $properties = WebGUI::HTMLForm->new;
|
||||
$properties->HTMLArea(
|
||||
-name=>"acknowledgement",
|
||||
-label=>WebGUI::International::get(16, $_[0]->get("namespace")),
|
||||
-value=>($_[0]->get("acknowledgement") || WebGUI::International::get(3, $_[0]->get("namespace")))
|
||||
);
|
||||
$properties->yesNo(
|
||||
-name=>"mailData",
|
||||
-label=>WebGUI::International::get(74,$_[0]->get("namespace")),
|
||||
-value=>$_[0]->getValue("mailData")
|
||||
);
|
||||
if ($_[0]->get("wobjectId") eq "new") {
|
||||
$properties->whatNext(
|
||||
-options=>{
|
||||
addField=>WebGUI::International::get(76,$_[0]->get("namespace")),
|
||||
backToPage=>WebGUI::International::get(745)
|
||||
},
|
||||
-value=>"addField"
|
||||
);
|
||||
}
|
||||
return $_[0]->SUPER::www_edit(
|
||||
-properties=>$properties->printRowsOnly,
|
||||
-layout=>$layout->printRowsOnly,
|
||||
-helpId=>1,
|
||||
-headingId=>7
|
||||
);
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub www_editSave {
|
||||
return WebGUI::Privilege::insufficient() unless (WebGUI::Privilege::canEditPage());
|
||||
$_[0]->SUPER::www_editSave();
|
||||
if ($session{form}{wid} eq "new") {
|
||||
$_[0]->setCollateral("DataForm_field","DataForm_fieldId",{
|
||||
DataForm_fieldId=>"new",
|
||||
name=>"from",
|
||||
label=>WebGUI::International::get(10,$_[0]->get("namespace")),
|
||||
status=>"editable",
|
||||
isMailField=>1,
|
||||
width=>45,
|
||||
type=>"email"
|
||||
});
|
||||
$_[0]->setCollateral("DataForm_field","DataForm_fieldId",{
|
||||
DataForm_fieldId=>"new",
|
||||
name=>"to",
|
||||
label=>WebGUI::International::get(11,$_[0]->get("namespace")),
|
||||
status=>"hidden",
|
||||
isMailField=>1,
|
||||
width=>45,
|
||||
type=>"email",
|
||||
defaultValue=>$session{setting}{companyEmail}
|
||||
});
|
||||
$_[0]->setCollateral("DataForm_field","DataForm_fieldId",{
|
||||
DataForm_fieldId=>"new",
|
||||
name=>"cc",
|
||||
label=>WebGUI::International::get(12,$_[0]->get("namespace")),
|
||||
status=>"hidden",
|
||||
isMailField=>1,
|
||||
width=>45,
|
||||
type=>"email"
|
||||
});
|
||||
$_[0]->setCollateral("DataForm_field","DataForm_fieldId",{
|
||||
DataForm_fieldId=>"new",
|
||||
name=>"bcc",
|
||||
label=>WebGUI::International::get(13,$_[0]->get("namespace")),
|
||||
status=>"hidden",
|
||||
isMailField=>1,
|
||||
width=>45,
|
||||
type=>"email"
|
||||
});
|
||||
$_[0]->setCollateral("DataForm_field","DataForm_fieldId",{
|
||||
DataForm_fieldId=>"new",
|
||||
name=>"subject",
|
||||
label=>WebGUI::International::get(14,$_[0]->get("namespace")),
|
||||
status=>"editable",
|
||||
isMailField=>1,
|
||||
width=>45,
|
||||
type=>"text",
|
||||
defaultValue=>WebGUI::International::get(2,$_[0]->get("namespace"))
|
||||
});
|
||||
}
|
||||
if ($session{form}{proceed} eq "addField") {
|
||||
return $_[0]->www_editField();
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub www_editField {
|
||||
return WebGUI::Privilege::insufficient() unless (WebGUI::Privilege::canEditPage());
|
||||
my ($output, %field, $f, %fieldStatus);
|
||||
tie %field, 'Tie::CPHash';
|
||||
tie %fieldStatus, 'Tie::IxHash';
|
||||
|
||||
%fieldStatus = (
|
||||
"hidden" => WebGUI::International::get(4, $_[0]->get("namespace")),
|
||||
"visible" => WebGUI::International::get(5, $_[0]->get("namespace")),
|
||||
"editable" => WebGUI::International::get(6, $_[0]->get("namespace")),
|
||||
"required" => WebGUI::International::get(75, $_[0]->get("namespace"))
|
||||
);
|
||||
$session{form}{fid} = "new" if ($session{form}{fid} eq "");
|
||||
unless ($session{form}{fid} eq "new") {
|
||||
%field = WebGUI::SQL->quickHash("select * from DataForm_field where DataForm_fieldId=$session{form}{fid}");
|
||||
}
|
||||
$output = helpIcon(2,$_[0]->get("namespace"));
|
||||
$output .= '<h1>'.WebGUI::International::get(20,$_[0]->get("namespace")).'</h1>';
|
||||
$f = WebGUI::HTMLForm->new;
|
||||
$f->hidden("wid",$_[0]->get("wobjectId"));
|
||||
$f->hidden("fid",$session{form}{fid});
|
||||
$f->hidden("func","editFieldSave");
|
||||
$f->text(
|
||||
-name=>"label",
|
||||
-label=>WebGUI::International::get(77,$_[0]->get("namespace")),
|
||||
-value=>$field{label}
|
||||
);
|
||||
$f->text(
|
||||
-name=>"name",
|
||||
-label=>WebGUI::International::get(21,$_[0]->get("namespace")),
|
||||
-value=>$field{name}
|
||||
);
|
||||
$f->text(
|
||||
-name=>"subtext",
|
||||
-value=>$field{subtext},
|
||||
-label=>WebGUI::International::get(79,$_[0]->get("namespace")),
|
||||
);
|
||||
$f->select(
|
||||
-name=>"status",
|
||||
-options=>\%fieldStatus,
|
||||
-label=>WebGUI::International::get(22,$_[0]->get("namespace")),
|
||||
-value=>[ $field{status} ||= "editable" ]
|
||||
);
|
||||
$f->fieldType(
|
||||
-name=>"type",
|
||||
-label=>WebGUI::International::get(23,$_[0]->get("namespace")),
|
||||
-value=>[$field{type} ||= "text"]
|
||||
);
|
||||
$f->integer(
|
||||
-name=>"width",
|
||||
-label=>WebGUI::International::get(8, $_[0]->get("namespace")),
|
||||
-value=>($field{width} || 45)
|
||||
);
|
||||
$f->integer(
|
||||
-name=>"rows",
|
||||
-value=>$field{rows} || "5",
|
||||
-label=>WebGUI::International::get(27, $_[0]->get("namespace")),
|
||||
-subtext=>WebGUI::International::get(28, $_[0]->get("namespace")),
|
||||
);
|
||||
$f->textarea(
|
||||
-name=>"possibleValues",
|
||||
-label=>WebGUI::International::get(24,$_[0]->get("namespace")),
|
||||
-value=>$field{possibleValues}
|
||||
);
|
||||
$f->textarea(
|
||||
-name=>"defaultValue",
|
||||
-label=>WebGUI::International::get(25,$_[0]->get("namespace")),
|
||||
-value=>$field{defaultValue}
|
||||
);
|
||||
if ($session{form}{fid} eq "new") {
|
||||
$f->whatNext(
|
||||
-options=>{
|
||||
addField=>WebGUI::International::get(76,$_[0]->get("namespace")),
|
||||
backToPage=>WebGUI::International::get(745)
|
||||
},
|
||||
-value=>"addField"
|
||||
);
|
||||
}
|
||||
$f->submit;
|
||||
$output .= $f->print;
|
||||
return $output;
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub www_editFieldSave {
|
||||
return WebGUI::Privilege::insufficient() unless (WebGUI::Privilege::canEditPage());
|
||||
$session{form}{name} = $session{form}{label} if ($session{form}{name} eq "");
|
||||
$_[0]->setCollateral("DataForm_field","DataForm_fieldId",{
|
||||
DataForm_fieldId=>$session{form}{fid},
|
||||
width=>$session{form}{width},
|
||||
name=>$session{form}{name},
|
||||
label=>$session{form}{label},
|
||||
status=>$session{form}{status},
|
||||
type=>$session{form}{type},
|
||||
possibleValues=>$session{form}{possibleValues},
|
||||
defaultValue=>$session{form}{defaultValue},
|
||||
subtext=>$session{form}{subtext},
|
||||
rows=>$session{form}{rows}
|
||||
});
|
||||
if ($session{form}{proceed} eq "addField") {
|
||||
$session{form}{fid} = "new";
|
||||
return $_[0]->www_editField();
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub www_exportTab {
|
||||
return WebGUI::Privilege::insufficient() unless (WebGUI::Privilege::canEditPage());
|
||||
$session{header}{filename} = WebGUI::URL::urlize($_[0]->get("title")).".tab";
|
||||
$session{header}{mimetype} = "text/tab";
|
||||
return WebGUI::SQL->quickTab("select a.label, a.name, b.value, c.ipAddress, c.username, c.submissionDate, c.DataForm_entryId
|
||||
from DataForm_field a left join DataForm_entryData b on a.name=b.name left join DataForm_entry c on
|
||||
b.DataForm_entryId=c.DataForm_entryId where c.wobjectId=".$_[0]->get("wobjectId")." order by c.DataForm_entryId, a.sequenceNumber");
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub www_moveFieldDown {
|
||||
return WebGUI::Privilege::insufficient() unless (WebGUI::Privilege::canEditPage());
|
||||
$_[0]->moveCollateralDown("DataForm_field","DataForm_fieldId",$session{form}{fid});
|
||||
return "";
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub www_moveFieldUp {
|
||||
return WebGUI::Privilege::insufficient() unless (WebGUI::Privilege::canEditPage());
|
||||
$_[0]->moveCollateralUp("DataForm_field","DataForm_fieldId",$session{form}{fid});
|
||||
return "";
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub www_process {
|
||||
my $entryId = $_[0]->setCollateral("DataForm_entry","DataForm_entryId",{
|
||||
DataForm_entryId=>$session{form}{entryId},
|
||||
wobjectId=>$_[0]->get("wobjectId"),
|
||||
userId=>$session{user}{userId},
|
||||
username=>$session{user}{username},
|
||||
ipAddress=>$session{env}{REMOTE_ADDR},
|
||||
submissionDate=>time()
|
||||
},0);
|
||||
my ($var, %row, @errors, $updating, $hadErrors);
|
||||
$var->{entryId} = $entryId;
|
||||
tie %row, "Tie::CPHash";
|
||||
my $sth = WebGUI::SQL->read("select DataForm_fieldId,name,status,type,defaultValue,isMailField from DataForm_field
|
||||
where wobjectId=".$_[0]->get("wobjectId")." order by sequenceNumber");
|
||||
while (%row = $sth->hash) {
|
||||
my $value = WebGUI::FormProcessor::process(WebGUI::URL::urlize($row{name}),$row{type},$row{defaultValue});
|
||||
if ($row{status} eq "required" || $row{status} eq "editable") {
|
||||
$value = WebGUI::Macro::filter($value);
|
||||
}
|
||||
if ($row{status} eq "required" && not defined $value) {
|
||||
push (@errors,{
|
||||
"error.message"=>$row{name}." ".WebGUI::International::get(29,$_[0]->get("namespace")),
|
||||
});
|
||||
$hadErrors = 1;
|
||||
}
|
||||
unless ($hadErrors) {
|
||||
my ($exists) = WebGUI::SQL->quickArray("select count(*) from DataForm_entryData where DataForm_entryId=$entryId
|
||||
and name=".quote($row{name}));
|
||||
if ($exists) {
|
||||
WebGUI::SQL->write("update DataForm_entryData set value=".quote($value)."
|
||||
where DataForm_entryId=$entryId and name=".quote($row{name}));
|
||||
$updating = 1;
|
||||
} else {
|
||||
WebGUI::SQL->write("insert into DataForm_entryData (DataForm_entryId,wobjectId,name,value) values
|
||||
($entryId, ".$_[0]->get("wobjectId").", ".quote($row{name}).", ".quote($value).")");
|
||||
}
|
||||
}
|
||||
}
|
||||
$sth->finish;
|
||||
$var->{error_loop} = \@errors;
|
||||
$var = $_[0]->getTemplateVars($var);
|
||||
if ($hadErrors && !$updating) {
|
||||
WebGUI::SQL->write("delete from DataForm_entryData where DataForm_entryId=".$entryId);
|
||||
$_[0]->deleteCollateral("DataForm_entry","DataForm_entryId",$entryId);
|
||||
$_[0]->www_view($var);
|
||||
} else {
|
||||
$_[0]->sendEmail($var) unless ($updating);
|
||||
return $_[0]->processTemplate($_[0]->get("acknowlegementTemplateId"),$var);
|
||||
}
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub www_view {
|
||||
my $var;
|
||||
$var->{entryId} = $session{form}{entryId};
|
||||
$var = $_[1] || $_[0]->getTemplateVars($var);
|
||||
return $_[0]->processTemplate($_[0]->get("templateId"),$var);
|
||||
}
|
||||
|
||||
|
||||
|
||||
1;
|
||||
|
||||
|
||||
|
|
@ -1,710 +0,0 @@
|
|||
package WebGUI::Wobject::MailForm;
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
# WebGUI is Copyright 2001-2003 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 Tie::IxHash;
|
||||
use WebGUI::Form;
|
||||
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);
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub duplicate {
|
||||
my ($w, %data, $sth);
|
||||
tie %data, 'Tie::CPHash';
|
||||
$w = $_[0]->SUPER::duplicate($_[1]);
|
||||
$w = WebGUI::Wobject::MailForm->new({wobjectId=>$w,namespace=>$_[0]->get("namespace")});
|
||||
$sth = WebGUI::SQL->read("select * from MailForm_field where wobjectId=".$_[0]->get("wobjectId"));
|
||||
while (%data = $sth->hash) {
|
||||
$data{MailForm_fieldId} = "new";
|
||||
$w->setCollateral("MailForm_field","MailForm_fieldId",\%data);
|
||||
}
|
||||
$sth->finish;
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub name {
|
||||
return WebGUI::International::get(1,$_[0]->get("namespace"));
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub new {
|
||||
my $class = shift;
|
||||
my $property = shift;
|
||||
my $self = WebGUI::Wobject->new(
|
||||
-properties=>$property,
|
||||
-extendedProperties=>{
|
||||
width=>{
|
||||
defaultValue=>45
|
||||
},
|
||||
fromField=>{},
|
||||
fromStatus=>{
|
||||
defaultValue=>3
|
||||
},
|
||||
toField=>{
|
||||
defaultValue=>$session{setting}{companyEmail}
|
||||
},
|
||||
toStatus=>{
|
||||
defaultValue=>1
|
||||
},
|
||||
ccField=>{},
|
||||
ccStatus=>{
|
||||
defaultValue=>1
|
||||
},
|
||||
bccField=>{},
|
||||
bccStatus=>{
|
||||
defaultValue=>1
|
||||
},
|
||||
subjectField=>{},
|
||||
subjectStatus=>{
|
||||
defaultValue=>3
|
||||
},
|
||||
acknowledgement=>{},
|
||||
storeEntries=>{
|
||||
defaultValue=>1
|
||||
}
|
||||
}
|
||||
);
|
||||
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_entryData where wobjectId=".$_[0]->get("wobjectId"));
|
||||
$_[0]->SUPER::purge();
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub uiLevel {
|
||||
return 5;
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub www_deleteField {
|
||||
return WebGUI::Privilege::insufficient() unless (WebGUI::Privilege::canEditPage());
|
||||
return $_[0]->confirm(WebGUI::International::get(19,$_[0]->get("namespace")),
|
||||
WebGUI::URL::page('func=deleteFieldConfirm&wid='.$_[0]->get("wobjectId").'&fid='.$session{form}{fid}));
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub www_deleteFieldConfirm {
|
||||
return WebGUI::Privilege::insufficient() unless (WebGUI::Privilege::canEditPage());
|
||||
$_[0]->deleteCollateral("MailForm_field","MailForm_fieldId",$session{form}{fid});
|
||||
$_[0]->reorderCollateral("MailForm_field","MailForm_fieldId");
|
||||
return "";
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub www_edit {
|
||||
my %fieldStatus = ( 1 => WebGUI::International::get(4, $_[0]->get("namespace")),
|
||||
2 => WebGUI::International::get(5, $_[0]->get("namespace")),
|
||||
3 => WebGUI::International::get(6, $_[0]->get("namespace")) );
|
||||
my $proceed = 1 if ($_[0]->get("wobjectId") eq "new");
|
||||
my $f = WebGUI::HTMLForm->new;
|
||||
$f->integer(
|
||||
-name=>"width",
|
||||
-label=>WebGUI::International::get(8, $_[0]->get("namespace")),
|
||||
-value=>$_[0]->getValue("width")
|
||||
);
|
||||
$f->raw( $_[0]->_textSelectRow(
|
||||
"fromField",
|
||||
WebGUI::International::get(10, $_[0]->get("namespace")),
|
||||
$_[0]->getValue("fromField"),
|
||||
128,
|
||||
"fromStatus",
|
||||
\%fieldStatus,
|
||||
$_[0]->getValue("fromStatus")
|
||||
) );
|
||||
$f->raw( $_[0]->_textSelectRow(
|
||||
"toField",
|
||||
WebGUI::International::get(11, $_[0]->get("namespace")),
|
||||
$_[0]->getValue("toField"),
|
||||
128,
|
||||
"toStatus",
|
||||
\%fieldStatus,
|
||||
$_[0]->getValue("toStatus")
|
||||
) );
|
||||
$f->raw( $_[0]->_textSelectRow(
|
||||
"ccField",
|
||||
WebGUI::International::get(12, $_[0]->get("namespace")),
|
||||
$_[0]->getValue("ccField"),
|
||||
128,
|
||||
"ccStatus",
|
||||
\%fieldStatus,
|
||||
$_[0]->getValue("ccStatus")
|
||||
) );
|
||||
$f->raw( $_[0]->_textSelectRow(
|
||||
"bccField",
|
||||
WebGUI::International::get(13, $_[0]->get("namespace")),
|
||||
$_[0]->getValue("bccField"),
|
||||
128,
|
||||
"bccStatus",
|
||||
\%fieldStatus,
|
||||
$_[0]->getValue("bccStatus")
|
||||
) );
|
||||
$f->raw( $_[0]->_textSelectRow(
|
||||
"subjectField",
|
||||
WebGUI::International::get(14, $_[0]->get("namespace")),
|
||||
($_[0]->get("subjectField") || WebGUI::International::get(2, $_[0]->get("namespace"))),
|
||||
128,
|
||||
"subjectStatus",
|
||||
\%fieldStatus,
|
||||
$_[0]->getValue("subjectStatus")
|
||||
) );
|
||||
$f->HTMLArea(
|
||||
-name=>"acknowledgement",
|
||||
-label=>WebGUI::International::get(16, $_[0]->get("namespace")),
|
||||
-value=>($_[0]->get("acknowledgement") || WebGUI::International::get(3, $_[0]->get("namespace")))
|
||||
);
|
||||
$f->yesNo(
|
||||
-name=>"storeEntries",
|
||||
-label=>WebGUI::International::get(26,$_[0]->get("namespace")),
|
||||
-value=>[ $_[0]->getValue("storeEntries") ]
|
||||
);
|
||||
$f->yesNo(
|
||||
-name=>"proceed",
|
||||
-label=>WebGUI::International::get(15,$_[0]->get("namespace")),
|
||||
-value=>$proceed
|
||||
);
|
||||
return $_[0]->SUPER::www_edit(
|
||||
-properties=>$f->printRowsOnly,
|
||||
-helpId=>1,
|
||||
-headingId=>7
|
||||
);
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub www_editSave {
|
||||
return WebGUI::Privilege::insufficient() unless (WebGUI::Privilege::canEditPage());
|
||||
$_[0]->SUPER::www_editSave();
|
||||
if ($session{form}{proceed}) {
|
||||
return $_[0]->www_editField();
|
||||
} else {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub www_editField {
|
||||
return WebGUI::Privilege::insufficient() unless (WebGUI::Privilege::canEditPage());
|
||||
my ($output, %field, $f, %fieldTypes, %fieldStatus, %validation);
|
||||
tie %field, 'Tie::CPHash';
|
||||
tie %fieldTypes, 'Tie::IxHash';
|
||||
tie %validation, 'Tie::IxHash';
|
||||
|
||||
%fieldStatus = ( 1 => WebGUI::International::get(4, $_[0]->get("namespace")),
|
||||
2 => WebGUI::International::get(5, $_[0]->get("namespace")),
|
||||
3 => WebGUI::International::get(6, $_[0]->get("namespace")) );
|
||||
|
||||
%fieldTypes = ( text => "Textbox",
|
||||
checkbox => "Checkbox",
|
||||
checkList => "Checkbox List",
|
||||
radioList => "Radio Buttons List",
|
||||
textarea => "Textarea",
|
||||
date => "Date",
|
||||
email => "Email Address",
|
||||
url => "URL",
|
||||
yesNo => "Yes/No",
|
||||
select => "Drop-Down Box",
|
||||
);
|
||||
|
||||
%validation = ( none => "None",
|
||||
notnull => "Not empty",
|
||||
number => "Number",
|
||||
word => "Word char [a-zA-Z0-9_]",
|
||||
email => "Valid E-mail address",
|
||||
);
|
||||
|
||||
%field = WebGUI::SQL->quickHash("select * from MailForm_field where MailForm_fieldId='$session{form}{fid}'");
|
||||
$output = helpIcon(2,$_[0]->get("namespace"));
|
||||
$output .= '<h1>'.WebGUI::International::get(20,$_[0]->get("namespace")).'</h1>';
|
||||
$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,$_[0]->get("namespace")),$field{name});
|
||||
|
||||
$f->text(
|
||||
-name=>"subtext",
|
||||
-value=>$field{subtext},
|
||||
-label=>"Subtext",
|
||||
-subtext=>"Optional extra text"
|
||||
);
|
||||
|
||||
my $status = [ $field{status} ||= 3 ]; # make it modifiable by default
|
||||
$f->select("status",\%fieldStatus,WebGUI::International::get(22,$_[0]->get("namespace")),$status);
|
||||
my $type = [ $field{type} ||= "text" ];
|
||||
$f->select("type",\%fieldTypes,WebGUI::International::get(23,$_[0]->get("namespace")),$type);
|
||||
$f->select("validation",\%validation,"Input validation", [$field{validation} || "none"]);
|
||||
$f->integer("width",WebGUI::International::get(8, $_[0]->get("namespace")),$field{width} || $_[0]->get("width") || 45);
|
||||
$f->integer(
|
||||
-name=>"rows",
|
||||
-value=>$field{rows} || "",
|
||||
-label=>WebGUI::International::get(27, $_[0]->get("namespace")),
|
||||
-subtext=>WebGUI::International::get(28, $_[0]->get("namespace")),
|
||||
);
|
||||
|
||||
$f->textarea("possibleValues",WebGUI::International::get(24,$_[0]->get("namespace")),$field{possibleValues});
|
||||
$f->textarea("defaultValue",WebGUI::International::get(25,$_[0]->get("namespace")),$field{defaultValue});
|
||||
$f->yesNo("proceed",WebGUI::International::get(15,$_[0]->get("namespace")));
|
||||
$f->submit;
|
||||
$output .= $f->print;
|
||||
return $output;
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub www_editFieldSave {
|
||||
return WebGUI::Privilege::insufficient() unless (WebGUI::Privilege::canEditPage());
|
||||
my ($seq);
|
||||
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("MailForm_fieldId");
|
||||
WebGUI::SQL->write("insert into MailForm_field (wobjectId,MailForm_fieldId,sequenceNumber, width) values
|
||||
(".$_[0]->get("wobjectId").",$session{form}{fid},".($seq+1).", $session{form}{width} )");
|
||||
}
|
||||
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}).
|
||||
", width=".quote($session{form}{width}).
|
||||
", rows=".quote($session{form}{rows}).
|
||||
", validation=".quote($session{form}{validation}).
|
||||
", subtext=".quote($session{form}{subtext}).
|
||||
" where MailForm_fieldId=$session{form}{fid}");
|
||||
if ($session{form}{proceed}) {
|
||||
$session{form}{fid} = "new";
|
||||
return $_[0]->www_editField();
|
||||
} else {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub www_moveFieldDown {
|
||||
return WebGUI::Privilege::insufficient() unless (WebGUI::Privilege::canEditPage());
|
||||
$_[0]->moveCollateralDown("MailForm_field","MailForm_fieldId",$session{form}{fid});
|
||||
return "";
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub www_moveFieldUp {
|
||||
return WebGUI::Privilege::insufficient() unless (WebGUI::Privilege::canEditPage());
|
||||
$_[0]->moveCollateralUp("MailForm_field","MailForm_fieldId",$session{form}{fid});
|
||||
return "";
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub www_view {
|
||||
my ($output, $sth, $f, $row, %data);
|
||||
tie %data, 'Tie::CPHash';
|
||||
$output = $_[0]->displayTitle;
|
||||
$output .= $_[0]->description.'<p>';
|
||||
|
||||
# get all international text for each field caption
|
||||
my %text = (
|
||||
from => WebGUI::International::get(10, $_[0]->get("namespace")),
|
||||
to => WebGUI::International::get(11, $_[0]->get("namespace")),
|
||||
cc => WebGUI::International::get(12, $_[0]->get("namespace")),
|
||||
bcc => WebGUI::International::get(13, $_[0]->get("namespace")),
|
||||
subject => WebGUI::International::get(14, $_[0]->get("namespace")),
|
||||
);
|
||||
|
||||
if ($session{var}{adminOn}) {
|
||||
$output .= '<a href="'.WebGUI::URL::page('func=editField&wid='.$_[0]->get("wobjectId")).'">'
|
||||
.WebGUI::International::get(9,$_[0]->get("namespace")).'</a>';
|
||||
}
|
||||
|
||||
$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 = '<tr><td class="formDescription" valign="';
|
||||
if ($_[0]->get("${field}Status") == 2) {
|
||||
# Read-only field
|
||||
$row .= "middle\">\u$field: </td><td class='tableData' valign='middle'>".$_[0]->get("${field}Field");
|
||||
} else {
|
||||
# Modifiable Field
|
||||
if ($field eq 'content') {
|
||||
my $taWidth = $_[0]->get("width") - 9;
|
||||
$row .= "top\">".$text{$field}.": </td><td><textarea name='${field}Field' rows='10' cols='$taWidth'>".$_[0]->get("${field}Field")."</textarea>";
|
||||
} else {
|
||||
my $caption = $text{$field};
|
||||
$row .= "top\">$caption: </td><td><input type='text' name='${field}Field' size='".$_[0]->get("width")."' maxlength='128' value='".$_[0]->get("${field}Field")."'>";
|
||||
}
|
||||
}
|
||||
$row .= "</td></tr>";
|
||||
$f->raw($row);
|
||||
}
|
||||
}
|
||||
|
||||
$sth = WebGUI::SQL->read("select * from MailForm_field where wobjectId=".$_[0]->get("wobjectId")." order by sequenceNumber");
|
||||
while (%data = $sth->hash) {
|
||||
if ($data{status} == 1) {
|
||||
# hidden field, don't show on form for security reasons
|
||||
$row = "";
|
||||
# but show for admins
|
||||
if ($session{var}{adminOn}) {
|
||||
$row = "<tr><td class='formDescription' valign='middle'>\u".$data{name}." (hidden) </td><td class='tableData' valign='middle'>".$data{defaultValue};
|
||||
$row .= $_[0]->_fieldAdminIcons($data{MailForm_fieldId});
|
||||
}
|
||||
} elsif ($data{status} == 2) {
|
||||
# read-only field
|
||||
$row = "<tr><td class='formDescription' valign='middle'>\u".$data{name}." </td><td class='tableData' valign='middle'>".$data{defaultValue};
|
||||
if ($session{var}{adminOn}) {
|
||||
$row .= $_[0]->_fieldAdminIcons($data{MailForm_fieldId});
|
||||
}
|
||||
$row .= "</td></tr>";
|
||||
} else {
|
||||
# modifiable field
|
||||
$row = $_[0]->_createField(\%data);
|
||||
}
|
||||
$f->raw($row);
|
||||
}
|
||||
|
||||
$f->submit(WebGUI::International::get(73, $_[0]->get("namespace")));
|
||||
$output .= $f->print;
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub _createField {
|
||||
my ($self, $data) = @_;
|
||||
|
||||
my $name = WebGUI::URL::urlize($data->{name});
|
||||
my $f = WebGUI::HTMLForm->new( 'noTable' );
|
||||
|
||||
$session{form}{$name} =~ s/\^.*?\;//gs ; # remove macro's from user input
|
||||
|
||||
SWITCH: for ($data->{type}) {
|
||||
/^text$/ && do {
|
||||
$f->text(
|
||||
-name=>$name,
|
||||
-label=>$data->{name},
|
||||
-value=>$session{form}{$name} || $data->{defaultValue},
|
||||
-maxlength=>255,
|
||||
-size=>$data->{width} || $self->get("width"),
|
||||
-subtext=>$data->{subtext},
|
||||
);
|
||||
last SWITCH;
|
||||
};
|
||||
/^email$/ && do {
|
||||
$f->email(
|
||||
-name=>$name,
|
||||
-label=>$data->{name},
|
||||
-value=>$session{form}{$name} || $data->{defaultValue},
|
||||
-maxlength=>255,
|
||||
-size=>$data->{width} || $self->get("width"),
|
||||
-subtext=>$data->{subtext},
|
||||
);
|
||||
last SWITCH;
|
||||
};
|
||||
/^url$/ && do {
|
||||
$f->url(
|
||||
-name=>$name,
|
||||
-label=>$data->{name},
|
||||
-value=>$session{form}{$name} || $data->{defaultValue},
|
||||
-maxlength=>255,
|
||||
-size=>$data->{width} || $self->get("width"),
|
||||
-subtext=>$data->{subtext},
|
||||
);
|
||||
last SWITCH;
|
||||
};
|
||||
/^textarea$/ && do {
|
||||
$f->textarea(
|
||||
-name=>$name,
|
||||
-label=>$data->{name},
|
||||
-value=>$session{form}{$name} || $data->{defaultValue},
|
||||
-maxlength=>255,
|
||||
-size=>$data->{width} || $self->get("width"),
|
||||
-subtext=>$data->{subtext},
|
||||
-columns=>$data->{width} || $self->get("width") - 9,
|
||||
-rows=>$data->{rows} || 9,
|
||||
);
|
||||
last SWITCH;
|
||||
};
|
||||
/^date$/ && do {
|
||||
$f->date(
|
||||
-name=>$name,
|
||||
-label=>$data->{name},
|
||||
-value=>$session{form}{$name} || $data->{defaultValue},
|
||||
-size=>$data->{width} || $self->get("width"),
|
||||
-subtext=>$data->{subtext},
|
||||
);
|
||||
last SWITCH;
|
||||
};
|
||||
/^yesNo$/ && do {
|
||||
my $value;
|
||||
if ($data->{defaultValue} =~ /yes/i) {
|
||||
$value = 1;
|
||||
} elsif ($data->{defaultValue} =~ /no/i) {
|
||||
$value = 0;
|
||||
} else {
|
||||
$value = 2;
|
||||
}
|
||||
$f->yesNo(
|
||||
-name=>$name,
|
||||
-label=>$data->{name},
|
||||
-value=>$session{form}{$name} || $data->{defaultValue},
|
||||
-subtext=>$data->{subtext},
|
||||
);
|
||||
last SWITCH;
|
||||
};
|
||||
/^checkbox$/ && do {
|
||||
my $value = ($data->{defaultValue} =~ /checked/i) ? 1 : "";
|
||||
|
||||
$f->checkbox(
|
||||
-name=>$name,
|
||||
-label=>$data->{name},
|
||||
-value=>$session{form}{$name} || $data->{defaultValue},
|
||||
-subtext=>$data->{subtext},
|
||||
);
|
||||
last SWITCH;
|
||||
};
|
||||
/^select$/ && do {
|
||||
# size, multiple, extras, subtext
|
||||
my %selectOptions;
|
||||
tie %selectOptions, 'Tie::IxHash';
|
||||
# add an empty option if no default value is provided
|
||||
foreach (split(/\n/, $data->{possibleValues})) {
|
||||
s/\s+$//; # remove trailing spaces
|
||||
$selectOptions{$_} = $_;
|
||||
}
|
||||
$f->selectList(
|
||||
-name=>$name,
|
||||
-options=>\%selectOptions,
|
||||
-label=>$data->{name},
|
||||
-value=>[$session{form}{$name}] || [$data->{defaultValue}],
|
||||
-subtext=>$data->{subtext},
|
||||
);
|
||||
last SWITCH;
|
||||
};
|
||||
/^checkList$/ && do {
|
||||
my (%selectOptions, @defaultValues);
|
||||
my $vertical = 1; # TODO: Make this configurable
|
||||
$name = "field_".$data->{sequenceNumber} if ($name eq ""); # Empty fieldname not allowed
|
||||
tie %selectOptions, 'Tie::IxHash';
|
||||
foreach (split(/\n/, $data->{possibleValues})) {
|
||||
s/\s+$//; # remove trailing spaces
|
||||
$selectOptions{$_} = $_;
|
||||
}
|
||||
if ($session{form}{$name}) {
|
||||
@defaultValues = $session{cgi}->param($name);
|
||||
} else {
|
||||
# put default values in array
|
||||
foreach (split(/\n/, $data->{defaultValue})) {
|
||||
s/\s+$//; # remove trailing spaces
|
||||
push(@defaultValues, $_);
|
||||
}
|
||||
}
|
||||
$f->checkList(
|
||||
-name=>$name,
|
||||
-options=>\%selectOptions,
|
||||
-label=>$data->{name},
|
||||
-value=>\@defaultValues,
|
||||
-subtext=>$data->{subtext},
|
||||
-vertical=>$vertical
|
||||
);
|
||||
last SWITCH;
|
||||
};
|
||||
/^radioList$/ && do {
|
||||
my (%selectOptions, $defaultValue);
|
||||
my $vertical = 1; # TODO: Make this configurable
|
||||
$name = "field_".$data->{sequenceNumber} if ($name eq ""); # Empty fieldname not allowed
|
||||
tie %selectOptions, 'Tie::IxHash';
|
||||
foreach (split(/\n/, $data->{possibleValues})) {
|
||||
s/\s+$//; # remove trailing spaces
|
||||
$selectOptions{$_} = $_;
|
||||
}
|
||||
if ($session{form}{$name}) {
|
||||
$defaultValue = $session{form}{$name};
|
||||
} else {
|
||||
$defaultValue = $data->{defaultValue};
|
||||
}
|
||||
$f->radioList(
|
||||
-name=>$name,
|
||||
-options=>\%selectOptions,
|
||||
-label=>$data->{name},
|
||||
-value=>$defaultValue,
|
||||
-subtext=>$data->{subtext},
|
||||
-vertical=>$vertical
|
||||
);
|
||||
last SWITCH;
|
||||
};
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
my $row = '<tr><td class="formDescription" valign="top">'.$data->{name}.'</td><td class="tableData">'.$f->printRowsOnly();
|
||||
if ($session{var}{adminOn}) {
|
||||
$row .= $self->_fieldAdminIcons($data->{MailForm_fieldId});
|
||||
}
|
||||
$row .= '</td></tr>';
|
||||
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::Form::_fixQuotes($textValue);
|
||||
my $textSize = $session{setting}{textBoxSize};
|
||||
$output = '<input type="text" name="'.$textName.'" value="'.$textValue.'" size="'.
|
||||
$textSize.'" maxlength="'.$textMaxLength.'">';
|
||||
$output .= ' ';
|
||||
my $selectSize = 1;
|
||||
$output .= '<select name="'.$selectName.'" size="'.$selectSize.'">';
|
||||
foreach my $key (keys %$selectOptions) {
|
||||
$output .= '<option value="'.$key.'"';
|
||||
if ($selectValue eq $key) {
|
||||
$output .= " selected";
|
||||
}
|
||||
$output .= '>'.${$selectOptions}{$key};
|
||||
}
|
||||
$output .= '</select>';
|
||||
return '<tr><td class="formDescription" valign="top">'.$textLabel.'</td><td class="tableData">'.$output."</td></tr>\n";
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub www_send {
|
||||
$session{form}{toField} = $_[0]->get("toField") unless ($session{form}{toField});
|
||||
$session{form}{fromField} = $_[0]->get("fromField") unless ($session{form}{fromField});
|
||||
$session{form}{subjectField} = $_[0]->get("subjectField") unless ($session{form}{subjectField});
|
||||
$session{form}{ccField} = $_[0]->get("ccField") unless ($session{form}{ccField});
|
||||
$session{form}{bccField} = $_[0]->get("bccField") unless ($session{form}{bccField});
|
||||
|
||||
# store results
|
||||
my $entryId = getNextId("MailForm_entryId");
|
||||
if ($_[0]->get("storeEntries")) {
|
||||
WebGUI::SQL->write("insert into MailForm_entry values ($entryId, ".$_[0]->get("wobjectId").", ".$session{user}{userId}.", ".quote($session{user}{username}).", ".quote($session{env}{REMOTE_ADDR}).", ".quote(time()).")");
|
||||
}
|
||||
|
||||
# create the message from all fields
|
||||
my ($message, $sth, %data, $error, $output);
|
||||
$sth = WebGUI::SQL->read("select * from MailForm_field where wobjectId=".$_[0]->get("wobjectId")." order by sequenceNumber");
|
||||
while (%data = $sth->hash) {
|
||||
my $urlizedName = WebGUI::URL::urlize($data{name});
|
||||
my $value = $session{form}{$urlizedName} || $_[0]->processMacros($data{defaultValue});
|
||||
# fix value for special types
|
||||
if ($data{type} eq "yesNo") {
|
||||
$value = ($value == 1) ? "yes" : "no";
|
||||
} elsif ($data{type} eq "checkbox") {
|
||||
$value = ($value) ? "checked" : "not checked";
|
||||
} elsif ($data{type} eq "checkList") {
|
||||
$data{name} = $urlizedName = "field_".$data{sequenceNumber} if ($urlizedName eq "");
|
||||
my @values = $session{cgi}->param($urlizedName);
|
||||
$value = join(", ",@values);
|
||||
}
|
||||
$error .= $_[0]->_validate($value, $data{validation}, $data{name}); #Validate input
|
||||
# store results
|
||||
if ($_[0]->get("storeEntries")) {
|
||||
WebGUI::SQL->write("insert into MailForm_entryData values ($entryId, ".$_[0]->get("wobjectId").", ".$data{sequenceNumber}.", ".quote($data{name}).", ".quote($value).")");
|
||||
}
|
||||
|
||||
$data{name} .= ":" unless ($data{name} =~ /:$/);
|
||||
$message .= "$data{name} $value\n";
|
||||
}
|
||||
if ($error ne "") {
|
||||
$output .= $error . $_[0]->www_view;
|
||||
return $output;
|
||||
}
|
||||
|
||||
my $to = $session{form}{toField};
|
||||
if ($to =~ /\@/) {
|
||||
# send a direct email if the To field is an email address
|
||||
my ($subject, $cc, $from, $bcc) = ($session{form}{subjectField},$session{form}{ccField},
|
||||
$session{form}{fromField},$session{form}{bccField});
|
||||
# From is either the logged on user, filled out, or the site
|
||||
if ($from && $session{user}) {
|
||||
# add their name from their profile if available
|
||||
$from = ("$session{user}{firstName} $session{user}{lastName}" || $session{user}{username}) . " <$from>";
|
||||
} elsif ($from) {
|
||||
# leave the from as-is
|
||||
}
|
||||
WebGUI::Mail::send($to,$subject,$message,$cc,$from,$bcc);
|
||||
} else {
|
||||
my ($userId) = WebGUI::SQL->quickArray("select userId from users where username=".quote($to));
|
||||
my $groupId;
|
||||
# if no user is found, try finding a matching group
|
||||
unless ($userId) {
|
||||
($groupId) = WebGUI::SQL->quickArray("select groupId from groups where groupName=".quote($to));
|
||||
}
|
||||
unless ($userId || $groupId) {
|
||||
$error = "Unable to send message, no user or group found.";
|
||||
} else {
|
||||
WebGUI::MessageLog::addEntry($userId, $groupId, $session{form}{subjectField}, $message);
|
||||
}
|
||||
}
|
||||
|
||||
$output = $_[0]->displayTitle;
|
||||
$error = $@ if $@;
|
||||
$output .= ($error || $_[0]->get("acknowledgement"))."<p>\n<a href=\"./$session{page}{urlizedTitle}\">".WebGUI::International::get(18, $_[0]->get("namespace"))."</a>";
|
||||
return $output;
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub _validate {
|
||||
my ($self, $value, $validation, $fieldName) = @_;
|
||||
|
||||
return "" if ($validation eq "none");
|
||||
|
||||
my %regex = ( notnull => qr/^.+$/,
|
||||
number => qr/^[\d\.]+$/,
|
||||
word => qr/^\w+$/,
|
||||
email => qr/^\s*<?[^@<>]+@[^@.<>]+(?:\.[^@.<>]+)+>?\s*$/,
|
||||
);
|
||||
my %message = ( notnull => ""$fieldName" ".WebGUI::International::get(29,$_[0]->get("namespace")),
|
||||
number => ""$fieldName" ".WebGUI::International::get(30,$_[0]->get("namespace")),
|
||||
word => ""$fieldName" ".WebGUI::International::get(31,$_[0]->get("namespace")),
|
||||
email => ""$value" " .WebGUI::International::get(32,$_[0]->get("namespace")),
|
||||
);
|
||||
|
||||
if ($value !~ $regex{$validation}) {
|
||||
return "<LI>".$message{$validation}."</LI>";
|
||||
}
|
||||
|
||||
return "";
|
||||
|
||||
}
|
||||
1;
|
||||
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue