381cdc2eab801dabf0320970dbbb24161e08a3d3
[freeside.git] / httemplate / edit / cust_main-contacts.html
1 <% include('elements/edit.html',
2      'name_singular'   => 'customer contacts', #yes, we're editing all of them
3      'table'           => 'cust_main',
4      'post_url'       => popurl(1). 'process/cust_main-contacts.html',
5      'labels'          => { 'custnum'     => ' ', #XXX supress this line entirely, its being redundant
6                             'contactnum'  => ' ', #'Contact',
7                             #'locationnum' => '&nbsp;',
8                           },
9      'fields'          => [
10        { 'field'             => 'contactnum',
11          'type'              => 'contact',
12          'colspan'           => 6,
13          'm2m_method'        => 'cust_contact',
14          'm2m_dstcol'        => 'contactnum',   
15          'm2_label'          => ' ', #'Contact',
16          'm2_error_callback' => $m2_error_callback,
17        },
18      ],
19      #'new_callback'    => $new_callback,
20      #'edit_callback'   => $edit_callback,
21      #'error_callback'  => $error_callback,
22      'agent_virt'      => 1,
23      'menubar'          => [], #remove "view all" link
24
25      #XXX it would be nice if this could instead be after the error but before
26      # the table
27      'html_init'        => include('/elements/small_custview.html',
28                                      $custnum,
29                                      $conf->config('countrydefault') || 'US',
30                                      1, #no balance
31                                   ),
32    )
33 %>
34 <%init>
35
36 my $curuser = $FS::CurrentUser::CurrentUser;
37 my $conf = new FS::Conf;
38
39 my $custnum;
40 if ( $cgi->param('error') ) {
41   $custnum = scalar($cgi->param('custnum'));
42
43   die "access denied"
44     unless $curuser->access_right(($custnum ? 'Edit' : 'New'). ' customer'); #contacts?
45
46 } elsif ( $cgi->keywords ) { #editing
47   $custnum = ($cgi->keywords)[0];
48
49   die "access denied"
50     unless $curuser->access_right('Edit customer');
51
52 } else { #new customer
53
54   #this doesn't really work here, we're an edit only
55   die "guru meditation #32";
56
57   die "access denied"
58     unless $curuser->access_right('New customer');
59
60 }
61
62 #my $new_callback = sub {
63 #  my( $cgi, $prospect_main, $fields_listref, $opt_hashref ) = @_;
64 #};
65
66 #my $edit_callback = sub {
67 # my( $cgi, $prospect_main, $fields_listref, $opt_hashref ) = @_;
68 #};
69
70 #my $error_callback = sub {
71 #  my( $cgi, $prospect_main, $fields_listref, $opt_hashref ) = @_;
72 #};
73
74 my $m2_error_callback = sub {
75   my($cgi, $object) = @_;
76
77   #process_o2m fields in process/cust_main-contacts.html
78   my @fields = qw( first last title comment );
79   my @gfields = ( '', map "_$_", @fields );
80
81   map {
82         if ( /^contactnum(\d+)$/ ) {
83           my $num = $1;
84           if ( grep $cgi->param("contactnum$num$_"), @gfields ) {
85             my $x = new FS::contact {
86               'contactnum' => scalar($cgi->param("contactnum$num")),
87               map { $_ => scalar($cgi->param("contactnum${num}_$_")) } @fields,
88             };
89             $x;
90           } else {
91             ();
92           }
93         } else {
94           ();
95         }
96       }
97       $cgi->param;
98 };
99
100 </%init>