diff --git a/docs/upgrades/upgrade_4.1.0-4.2.0.sql b/docs/upgrades/upgrade_4.1.0-4.2.0.sql index 362e966b6..3bfdf561d 100644 --- a/docs/upgrades/upgrade_4.1.0-4.2.0.sql +++ b/docs/upgrades/upgrade_4.1.0-4.2.0.sql @@ -802,3 +802,85 @@ insert into international values (604,'WebGUI',1,'Object'); +CREATE TABLE MailForm ( + wobjectId int(11) NOT NULL default '0', + width int(11) NOT NULL default '0', + fromField text, + fromStatus char(1) default '0', + toField text, + toStatus char(1) default '0', + ccField text, + ccStatus char(1) default '0', + bccField text, + bccStatus char(1) default '0', + subjectField text, + subjectStatus char(1) default '0', + acknowledgement text, + storeEntries char(1) default NULL +) TYPE=MyISAM; + +CREATE TABLE MailForm_field ( + wobjectId int(11) NOT NULL default '0', + mailFieldId int(11) NOT NULL default '0', + sequenceNumber int(11) NOT NULL default '0', + name varchar(255) NOT NULL default '', + status char(1) NOT NULL default '0', + type varchar(30) NOT NULL default '', + possibleValues text, + defaultValue text, + PRIMARY KEY (mailFieldId) +) TYPE=MyISAM; + +CREATE TABLE MailForm_entry ( + entryId int(11) NOT NULL default '0', + wobjectId int(11) NOT NULL default '0', + userId int(11) default NULL, + username varchar(255) default NULL, + ipAddress varchar(255) default NULL, + submissionDate int(11) NOT NULL default '0', + PRIMARY KEY (entryId) +) TYPE=MyISAM; + +CREATE TABLE MailForm_entry_data ( + entryId int(11) NOT NULL default '0', + wobjectId int(11) NOT NULL default '0', + sequenceNumber int(11) NOT NULL default '0', + name varchar(255) NOT NULL default '', + value text +) TYPE=MyISAM; + +INSERT INTO incrementer VALUES ('mailFieldId', 1000); +INSERT INTO incrementer VALUES ('mailEntryId', 1000); + +INSERT INTO international VALUES (1, 'MailForm', 1, 'Mail Form'); +INSERT INTO international VALUES (2, 'MailForm', 1, 'Your email subject here'); +INSERT INTO international VALUES (3, 'MailForm', 1, 'Thank you for your feedback!'); +INSERT INTO international VALUES (4, 'MailForm', 1, 'Hidden'); +INSERT INTO international VALUES (5, 'MailForm', 1, 'Displayed'); +INSERT INTO international VALUES (6, 'MailForm', 1, 'Modifiable'); +INSERT INTO international VALUES (7, 'MailForm', 1, 'Edit Mail Form'); +INSERT INTO international VALUES (8, 'MailForm', 1, 'Width'); +INSERT INTO international VALUES (9, 'MailForm', 1, 'Add Field'); +INSERT INTO international VALUES (10, 'MailForm', 1, 'From'); +INSERT INTO international VALUES (11, 'MailForm', 1, 'To (email, username, or group name)'); +INSERT INTO international VALUES (12, 'MailForm', 1, 'Cc'); +INSERT INTO international VALUES (13, 'MailForm', 1, 'Bcc'); +INSERT INTO international VALUES (14, 'MailForm', 1, 'Subject'); +INSERT INTO international VALUES (15, 'MailForm', 1, 'Proceed to add more fields?'); +INSERT INTO international VALUES (16, 'MailForm', 1, 'Acknowledgement'); +INSERT INTO international VALUES (17, 'MailForm', 1, 'Mail Sent'); +INSERT INTO international VALUES (18, 'MailForm', 1, 'Go back!'); +INSERT INTO international VALUES (19, 'MailForm', 1, 'Are you certain that you want to delete this field?'); +INSERT INTO international VALUES (20, 'MailForm', 1, 'Edit Field'); +INSERT INTO international VALUES (21, 'MailForm', 1, 'Field Name'); +INSERT INTO international VALUES (22, 'MailForm', 1, 'Status'); +INSERT INTO international VALUES (23, 'MailForm', 1, 'Type'); +INSERT INTO international VALUES (24, 'MailForm', 1, 'Possible Values (Drop-Down Box only)'); +INSERT INTO international VALUES (25, 'MailForm', 1, 'Default Value (optional)'); +INSERT INTO international VALUES (26, 'MailForm', 1, 'Store Entries?'); + +INSERT INTO help VALUES (1, 'MailForm', 1, 'Add/Edit', 'Mail Form', 'This wobject creates a simple form that will email an email address when it is filled out.\r\n

\r\n\r\nWidth
\r\nThe width of all fields in the form. The default value is 45.\r\n

\r\n\r\nFrom, To, Cc, Bcc, Subject
\r\nThese fields control how the email will look when sent, and who it is sent to. You can give your site visitors the ability to modify some or all of these fields, but typically the only fields you will want the user to be able to modify are From and Subject. Use the drop-down options by each field to choose whether or not the user can see or modify that field.
\r\n
\r\nYou may also choose to enter a WebGUI username or group in the To field, and the email will be sent to the corresponding user or group.\r\n

\r\n\r\nAcknowledgement
\r\nThis message will be displayed to the user after they click "Send".\r\n

\r\n\r\nStore Entries?
\r\nIf set to yes, when your mail form is submitted the entries will be saved to the database for later viewing. The tool to view these entries is not yet available, but when it is you will be able to view all entries from your form in a centralized location.\r\n

\r\n\r\nProceed to add more fields?
\r\nLeave this checked if you want to add additional fields to your form directly after creating it.', '13,1,2,3,4,5'); +INSERT INTO help VALUES (2, 'MailForm', 1, 'Add/Edit', 'Mail Form Fields', 'You may add as many additional fields to your Mail Form as you like.\r\n

\r\n\r\nField Name
\r\nThe name of this field. It must be unique among all of the other fields on your form.\r\n

\r\n\r\nStatus
\r\nHidden fields will not be visible to the user, but will be sent in the email.
\r\nDisplayed fields can be seen by the user but not modified.
\r\nModifiable fields can be filled in by the user.
\r\nIf you choose Hidden or Displayed, be sure to fill in a Default Value.\r\n

\r\n\r\nType
\r\nChoose the type of form element for this field. The following field types are supported:
\r\nURL: A textbox that will auto-format URL\'s entered.
\r\nTextbox: A standard textbox.
\r\nDate: A textbox field with a popup window to select a date.
\r\nYes/No: A set of yes/no radio buttons.
\r\nEmail Address: A textbox that requires the user to enter a valid email address.
\r\nTextarea: A simple textarea.
\r\nCheckbox: A single checkbox.
\r\nDrop-Down Box: A drop-down box. Use the Possible Values field to enter each option to be displayed in the box. Enter one option per line.\r\n

\r\n\r\nPossible Values
\r\nThis field is only used for the Drop-Down Box type. Enter the values you wish to appear in your drop-down box, one per line.\r\n

\r\n\r\nDefault Value (optional)
\r\nEnter the default value (if any) for the field. For Yes/No fields, enter "yes" to select "Yes" and "no" to select "No".\r\nFor Checkbox fields, enter "checked" to check the box.\r\n

\r\n\r\nProceed to add more fields?
\r\nLeave this checked if you want to add additional fields to your form directly after creating this field.', '14'); + +INSERT INTO helpSeeAlso VALUES (13, 2, 'MailForm'); +INSERT INTO helpSeeAlso VALUES (14, 1, 'MailForm'); diff --git a/lib/WebGUI/ErrorHandler.pm b/lib/WebGUI/ErrorHandler.pm index 5511d9e04..de691c0da 100644 --- a/lib/WebGUI/ErrorHandler.pm +++ b/lib/WebGUI/ErrorHandler.pm @@ -19,7 +19,7 @@ sub fatalError { if (exists $session{cgi}) { $cgi = $session{cgi}; $friendly = 1 if ($session{setting}{onCriticalError} eq "friendly"); - print WebGUI::Session::header(); + print WebGUI::Session::httpHeader(); } else { use CGI; $cgi = CGI->new; diff --git a/lib/WebGUI/Session.pm b/lib/WebGUI/Session.pm index ef0100f7c..7215679b6 100644 --- a/lib/WebGUI/Session.pm +++ b/lib/WebGUI/Session.pm @@ -135,10 +135,10 @@ sub _loadWobjects { $namespace = $1; $cmd = "use WebGUI::Wobject::".$namespace; eval($cmd); - WebGUI::ErrorHandler::fatalError("Wobject failed to compile: $namespace.") if($@); + WebGUI::ErrorHandler::fatalError("Wobject failed to compile: $namespace. ".$@) if($@); $cmd = "\$WebGUI::Wobject::".$namespace."::name"; $session{wobject}{$namespace} = eval($cmd); - WebGUI::ErrorHandler::fatalError("No name method in wobject: $namespace.") if($@); + WebGUI::ErrorHandler::fatalError("No name method in wobject: $namespace. ".$@) if($@); } } closedir(DIR); diff --git a/lib/WebGUI/Wobject/MailForm.pm b/lib/WebGUI/Wobject/MailForm.pm new file mode 100755 index 000000000..f73f3c844 --- /dev/null +++ b/lib/WebGUI/Wobject/MailForm.pm @@ -0,0 +1,636 @@ +package WebGUI::Wobject::MailForm; + +#------------------------------------------------------------------- +# 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 +#------------------------------------------------------------------- + +#----------------------------------------------------------------------- +# +# Name: MailForm.pm +# Revision: $Id$ +# Category: WebGUI Wobject +# Authors: Andy Grundman , +# Christophe Marcant +# +# TODO/Wishlist (in no particular order): +# 1) Support for radio/checkbox groups when added to HTMLForm.pm -andy +# +# 2) Add an option for a "secure" form, where the results of a submission are stored +# in the database and the "To" address is only sent a link back into WebGUI to view +# the results. This should be toggleable and default off because it's a hassle for +# most users. I could see this feature being used for quick-and-dirty credit card +# forms where the form and view are all done on an SSL server and credit card +# info is never sent via email. -andy +# +# 3) Add another option to each field to let it be required and force people to fill +# it out before being able to click send. -andy +# +# 4) Build viewer for stored form submissions. +# +# History: +# 7/07/02 andy 2.10 Better implementation for inclusion in WebGUI tree +# Support for unlimited number of additional fields +# Support for most form elements +# Uses MessageLog.pm for notification of users/groups +# Internationalization, Help (English only of course) +# 6/12/02 andy 2.01 Fixed save bug +# 6/11/02 andy 2.00 Initial port to Wobject API +# 3/28/02 christophe 1.00 Initial 1.0B public release +# +#----------------------------------------------------------------------- + +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 = '

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

'; + $output .= WebGUI::International::get(19,$namespace).'

'; + $output .= '

'.WebGUI::International::get(44).''; + $output .= '   '.WebGUI::International::get(45).'
'; + return $output; + } else { + return WebGUI::Privilege::insufficient(); + } +} + +#------------------------------------------------------------------- +sub www_deleteFieldConfirm { + my ($output); + if (WebGUI::Privilege::canEditPage()) { + WebGUI::SQL->write("delete from MailForm_field where mailFieldId=$session{form}{fid}"); + _reorderFields($_[0]->get("wobjectId")); + return ""; + } else { + return WebGUI::Privilege::insufficient(); + } +} + +#------------------------------------------------------------------- +sub www_edit { + my ($output, $f, $proceed); + if (WebGUI::Privilege::canEditPage()) { + + my %fieldStatus = ( 1 => WebGUI::International::get(4, $namespace), + 2 => WebGUI::International::get(5, $namespace), + 3 => WebGUI::International::get(6, $namespace) ); + + # field defaults + my %data = ( + width => 45, + fromField => '', + fromStatus => 3, + toField => $session{setting}{companyEmail}, + toStatus => 1, + ccField => '', + ccStatus => 1, + bccField => '', + bccStatus => 1, + subjectField => WebGUI::International::get(2, $namespace), + subjectStatus => 3, + acknowledgement => WebGUI::International::get(3, $namespace), + storeEntries => 1, + ); + # initialize fields from existing data, if any + foreach my $field (@fields) { + $data{$field} = $_[0]->get($field) if ($_[0]->get($field)); + } + + if ($_[0]->get("wobjectId") eq "new") { + $proceed = 1; + } + $output = helpIcon(1,$_[0]->get("namespace")); + $output .= '

'.WebGUI::International::get(7, $namespace).'

'; + $f = WebGUI::HTMLForm->new; + $f->integer("width",WebGUI::International::get(8, $namespace),$_[0]->get("width") || 45); + $f->raw( $_[0]->_textSelectRow("fromField",WebGUI::International::get(10, $namespace),$data{fromField},128, + "fromStatus",\%fieldStatus,$data{fromStatus}) ); + $f->raw( $_[0]->_textSelectRow("toField",WebGUI::International::get(11, $namespace),$data{toField},128, + "toStatus",\%fieldStatus,$data{toStatus}) ); + $f->raw( $_[0]->_textSelectRow("ccField",WebGUI::International::get(12, $namespace),$data{ccField},128, + "ccStatus",\%fieldStatus,$data{ccStatus}) ); + $f->raw( $_[0]->_textSelectRow("bccField",WebGUI::International::get(13, $namespace),$data{bccField},128, + "bccStatus",\%fieldStatus,$data{bccStatus}) ); + $f->raw( $_[0]->_textSelectRow("subjectField",WebGUI::International::get(14, $namespace),$data{subjectField},128, + "subjectStatus",\%fieldStatus,$data{subjectStatus}) ); + $f->HTMLArea("acknowledgement",WebGUI::International::get(16, $namespace),$_[0]->get("acknowledgement") || WebGUI::International::get(3, $namespace)); + my %storeEntriesOptions = ( + 1 => "Yes", + 0 => "No" + ); + $f->select("storeEntries",\%storeEntriesOptions,WebGUI::International::get(26,$namespace),[ $data{storeEntries} ]); + $f->yesNo("proceed",WebGUI::International::get(15,$namespace),$proceed); + $output .= $_[0]->SUPER::www_edit($f->printRowsOnly); + return $output; + } else { + return WebGUI::Privilege::insufficient(); + } +} + +#------------------------------------------------------------------- +sub www_editSave { + my ($property); + if (WebGUI::Privilege::canEditPage()) { + $_[0]->SUPER::www_editSave(); + foreach my $field (@fields) { + $property->{$field} = $session{form}{$field}; + } + $_[0]->set($property); + if ($session{form}{proceed}) { + $_[0]->www_editField(); + } else { + return ""; + } + } else { + return WebGUI::Privilege::insufficient(); + } +} + +#------------------------------------------------------------------- +sub www_editField { + my ($output, %field, $f); + tie %field, 'Tie::CPHash'; + + my %fieldStatus = ( 1 => WebGUI::International::get(4, $namespace), + 2 => WebGUI::International::get(5, $namespace), + 3 => WebGUI::International::get(6, $namespace) ); + + my %fieldTypes = ( text => "Textbox", + checkbox => "Checkbox", + textarea => "Textarea", + date => "Date", + email => "Email Address", + url => "URL", + yesNo => "Yes/No", + select => "Drop-Down Box" ); + + if (WebGUI::Privilege::canEditPage()) { + %field = WebGUI::SQL->quickHash("select * from MailForm_field where mailFieldId='$session{form}{fid}'"); + $output = helpIcon(2,$_[0]->get("namespace")); + $output .= '

'.WebGUI::International::get(20,$namespace).'

'; + $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}.": "; + } else { + my $caption = $text{$field}; + $row .= "top\">$caption: "; + } + } + $row .= ""; + $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 + } elsif ($data{status} == 2) { + # read-only field + $row = "\u".$data{name}." ".$data{defaultValue}; + if ($session{var}{adminOn}) { + $row .= $_[0]->_fieldAdminIcons($data{mailFieldId}); + } + $row .= ""; + } else { + # modifiable field + $row = $_[0]->_createField(\%data); + } + $f->raw($row); + } + + $f->submit("Send"); + $output .= $f->print; + + return $_[0]->processMacros($output); +} + +#------------------------------------------------------------------- +sub _createField { + my ($self, $data) = @_; + + my $name = WebGUI::URL::urlize($data->{name}); + my $f = WebGUI::HTMLForm->new( 'noTable' ); + + SWITCH: for ($data->{type}) { + /^text$/ && do { + # maxlength, extras, subtext + $f->text($name, $data->{name}, $data->{defaultValue}, 255, "", "", $self->get("width")); + last SWITCH; + }; + /^email$/ && do { + # maxlength, extras, subtext + $f->email($name, $data->{name}, $data->{defaultValue}, 255, "", "", $self->get("width")); + last SWITCH; + }; + /^url$/ && do { + # maxlength, extras, subtext + $f->url($name, $data->{name}, $data->{defaultValue}, 255, "", "", $self->get("width")); + last SWITCH; + }; + /^textarea$/ && do { + # subtext, extras, wrap, rows, cols + $f->textarea($name, $data->{name}, $data->{defaultValue}, "", "", "", 10, $self->get("width") - 9); + last SWITCH; + }; + /^date$/ && do { + # extras, subtext + $f->date($name, $data->{name}, $data->{defaultValue}, "", "", 15); # use small size for a date box + last SWITCH; + }; + /^yesNo$/ && do { + # extras, subtext + # allow user to enter friendly yes/no for default + my $value; + if ($data->{defaultValue} =~ /yes/i) { + $value = 1; + } elsif ($data->{defaultValue} =~ /no/i) { + $value = 0; + } else { + $value = 2; + } + $f->yesNo($name, $data->{name}, $value, "", ""); + last SWITCH; + }; + /^checkbox$/ && do { + # checked, subtext, extras + # the value option is used for checking the box here + my $value = ($data->{defaultValue} =~ /checked/i) ? 1 : ""; + $f->checkbox($name, $data->{name}, $value, "", "", ""); + last SWITCH; + }; + /^select$/ && do { + # size, multiple, extras, subtext + my %selectOptions; + # add an empty option if no default value is provided + foreach (split(/\n/, $data->{possibleValues})) { + $selectOptions{$_} = $_; + } + $f->select($name, \%selectOptions, $data->{name}, [ $data->{defaultValue} ], "", "", "", ""); + last SWITCH; + }; + } + + my $row = ''.$data->{name}.''.$f->printRowsOnly(); + if ($session{var}{adminOn}) { + $row .= $self->_fieldAdminIcons($data->{mailFieldId}); + } + $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 .= '