summaryrefslogtreecommitdiff
path: root/httemplate/edit/upload_target.html
blob: 47fea78a04b275910058f22b4f121843a16af861 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
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>