2a7185b5c464864f91f129a6f4bf4b48660e7941
[freeside.git] / httemplate / edit / process / cust_main-contacts.html
1 <% include('elements/process.html',
2      'table'          => 'cust_main',
3      'error_redirect' => popurl(3). 'edit/cust_main-contacts.html?',
4      'agent_virt'     => 1,
5      'skip_process'   => 1, #we don't want to make any changes to cust_main
6      'precheck_callback' => $precheck_callback,
7      'process_o2m' => {
8        'table'  => 'contact',
9        'fields' => FS::contact->cgi_contact_fields,
10      },
11      'redirect' => popurl(3). 'view/cust_main.cgi?',
12    )
13 %>
14 <%init>
15 my $precheck_callback = sub {
16   my $cgi = shift;
17   my $conf = FS::Conf->new;
18   if ( $conf->exists('cust_main-require_invoicing_list_email') ) {
19     my $has_email = 0;
20     foreach my $prefix (grep /^contactnum\d+$/, $cgi->param) {
21       if ( length($cgi->param($prefix . '_emailaddress'))
22            and $cgi->param($prefix . '_invoice_dest') ) {
23         $has_email = 1;
24         last;
25       }
26     }
27     return "At least one contact must receive email invoices"
28       unless $has_email;
29   }
30   '';
31 };
32 </%init>