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