summaryrefslogtreecommitdiff
path: root/httemplate/edit
diff options
context:
space:
mode:
authorMark Wells <mark@freeside.biz>2012-10-27 14:24:00 -0700
committerMark Wells <mark@freeside.biz>2012-10-27 14:24:00 -0700
commiteccc8de2366e2e004a37761b8da2b447ec861ecb (patch)
treebce8f9b106ae4fec53432600847352a48b0d14b5 /httemplate/edit
parent2c2da653a3d39945d8d2c244d102ccbee862053b (diff)
ICS invoice spool format and email delivery, #17620
Diffstat (limited to 'httemplate/edit')
-rwxr-xr-xhttemplate/edit/ftp_target.html46
-rw-r--r--httemplate/edit/process/ftp_target.html12
-rw-r--r--httemplate/edit/process/upload_target.html25
-rwxr-xr-xhttemplate/edit/upload_target.html82
4 files changed, 107 insertions, 58 deletions
diff --git a/httemplate/edit/ftp_target.html b/httemplate/edit/ftp_target.html
deleted file mode 100755
index aebf9aaed..000000000
--- a/httemplate/edit/ftp_target.html
+++ /dev/null
@@ -1,46 +0,0 @@
-<& elements/edit.html,
- 'post_url' => popurl(1).'process/ftp_target.html',
- 'name' => 'FTP target',
- 'table' => 'ftp_target',
- 'viewall_url' => "${p}browse/ftp_target.html",
- 'labels' => { targetnum => 'Target',
- hostname => 'Server',
- username => 'Username',
- password => 'Password',
- path => 'Directory',
- port => 'Port',
- secure => 'Use SFTP',
- handling => 'Special handling',
- },
- 'fields' => [
- { field => 'hostname', size => 40 },
- { field => 'port', size => 8 },
- { field => 'secure', type => 'checkbox', value => 'Y' },
- 'username',
- 'password',
- { field => 'path', size => 40 },
- { field => 'handling',
- type => 'select',
- options => [ FS::ftp_target->handling_types ],
- },
- ],
- 'menubar' => \@menubar,
- 'edit_callback' => $edit_callback,
-&>
-<%init>
-
-my $curuser = $FS::CurrentUser::CurrentUser;
-
-die "access denied"
- unless $curuser->access_right('Configuration');
-
-my @menubar = ('View all FTP targets' => $p.'browse/ftp_target.html');
-my $edit_callback = sub {
- my ($cgi, $object) = @_;
- if ( $object->targetnum ) {
- push @menubar, 'Delete this target',
- $p.'misc/delete-ftp_target.html?'.$object->targetnum;
- }
-};
-
-</%init>
diff --git a/httemplate/edit/process/ftp_target.html b/httemplate/edit/process/ftp_target.html
deleted file mode 100644
index 35f56c490..000000000
--- a/httemplate/edit/process/ftp_target.html
+++ /dev/null
@@ -1,12 +0,0 @@
-<& elements/process.html,
- 'table' => 'ftp_target',
- 'viewall_dir' => 'browse',
- 'agent_null' => 1,
-&>
-<%init>
-my $curuser = $FS::CurrentUser::CurrentUser;
-
-die "access denied"
- unless $curuser->access_right('Configuration');
-
-</%init>
diff --git a/httemplate/edit/process/upload_target.html b/httemplate/edit/process/upload_target.html
new file mode 100644
index 000000000..8755bed56
--- /dev/null
+++ b/httemplate/edit/process/upload_target.html
@@ -0,0 +1,25 @@
+<& elements/process.html,
+ 'table' => 'upload_target',
+ 'viewall_dir' => 'browse',
+ 'agent_null' => 1,
+ 'precheck_callback'=> \&precheck,
+&>
+<%init>
+my $curuser = $FS::CurrentUser::CurrentUser;
+
+die "access denied"
+ unless $curuser->access_right('Configuration');
+
+sub precheck {
+ my $cgi = shift;
+ my $protocol = $cgi->param('protocol');
+ # promote whatever set of fields was selected to the "real" values
+ my $params = $cgi->Vars;
+ foreach ( keys %$params ) {
+ if ( $_ =~ /^${protocol}_(\w+)/ ) {
+ $cgi->param($1, $cgi->param($_));
+ }
+ }
+}
+
+</%init>
diff --git a/httemplate/edit/upload_target.html b/httemplate/edit/upload_target.html
new file mode 100755
index 000000000..47fea78a0
--- /dev/null
+++ b/httemplate/edit/upload_target.html
@@ -0,0 +1,82 @@
+<& elements/edit.html,
+ 'post_url' => popurl(1).'process/upload_target.html',
+ 'name' => 'Upload target',
+ 'table' => 'upload_target',
+ 'viewall_url' => "${p}browse/upload_target.html",
+ 'labels' => { targetnum => 'Target',
+ protocol => 'Protocol',
+ handling => 'Special handling',
+ },
+ 'fields' => [
+ { field => 'protocol',
+ type => 'selectlayers',
+ options => [ '', 'sftp', 'ftp', 'email' ],
+ labels => { '' => '',
+ 'email' => 'Email',
+ 'sftp' => 'SFTP',
+ 'ftp' => 'FTP',
+ },
+ layer_fields => \%protocol_fields,
+ layer_values_callback => \&values_callback,
+ },
+ { field => 'handling',
+ type => 'select',
+ options => [ FS::upload_target->handling_types ],
+ },
+ ],
+ 'menubar' => \@menubar,
+ 'edit_callback' => $edit_callback,
+&>
+<%init>
+
+my $curuser = $FS::CurrentUser::CurrentUser;
+
+die "access denied"
+ unless $curuser->access_right('Configuration');
+
+my @menubar = ('View all FTP targets' => $p.'browse/upload_target.html');
+my $edit_callback = sub {
+ my ($cgi, $object) = @_;
+ if ( $object->targetnum ) {
+ push @menubar, 'Delete this target',
+ $p.'misc/delete-upload_target.html?'.$object->targetnum;
+ }
+};
+
+my %protocol_fields = (
+ '' => [],
+ 'sftp' => [
+ 'hostname' => { label => 'Server' },
+ 'username' => { label => 'Username' },
+ 'password' => { label => 'Password' },
+ 'port' => { label => 'Port', size => 8 },
+ 'path' => { label => 'Path', size => 30 },
+ ],
+ 'email' => [
+ 'username' => { label => 'To:' },
+ 'hostname' => { label => '@' },
+ 'subject' => { label => 'Subject:' },
+ ],
+);
+$protocol_fields{'ftp'} = [ @{ $protocol_fields{'sftp'} } ];
+foreach my $k (keys %protocol_fields) {
+ # disambiguate the field names
+ foreach (@{ $protocol_fields{$k} }) {
+ $_ = $k.'_'.$_ unless ref $_;
+ }
+}
+
+sub values_callback {
+ my ($cgi, $object) = @_;
+ my $layer_values;
+ # really simple, the interpretation of the fields is the same for all
+ # three layers
+ foreach my $l (qw(email ftp sftp)) {
+ $layer_values->{$l} = { map { $l.'_'.$_ => ($cgi->param($l.'_'.$_) ||
+ $object->get($_) ) }
+ $object->fields };
+ }
+ $layer_values;
+}
+
+</%init>