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