4.x style
[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
8 <SCRIPT>
9   function checkPasswordValidation(fieldid)  {
10     var validationResult = document.getElementById(fieldid+'_result').innerHTML;
11     if (validationResult.match(/Password valid!/)) {
12       return true;
13     }
14     else {
15       return false;
16     }
17   }
18 </SCRIPT>
19
20 <& '/elements/validate_password_js.html', &>
21
22 <& elements/edit.html,
23      'name_singular'    => 'customer contacts', #yes, we're editing all of them
24      'table'            => 'cust_main',
25      'post_url'         => popurl(1). 'process/cust_main-contacts.html',
26      'no_pkey_display'  => 1,
27      'submit_id'        => 'submit',
28      'labels'           => {
29                              'contactnum'  => ' ', #'Contact',
30                              #'locationnum' => '&nbsp;',
31                            },
32      'fields'           => [
33        { 'field'             => 'contactnum',
34          'type'              => 'contact',
35          'colspan'           => 6,
36          'custnum'           => $custnum,
37          'm2m_method'        => 'cust_contact',
38          'm2m_dstcol'        => 'contactnum',   
39          'm2_label'          => ' ', #'Contact',
40          'm2_error_callback' => $m2_error_callback,
41        },
42      ],
43      #'new_callback'     => $new_callback,
44      #'edit_callback'    => $edit_callback,
45      #'error_callback'   => $error_callback,
46      'agent_virt'       => 1,
47      'html_table_class' => 'fsinnerbox',
48      'menubar'          => [], #remove "view all" link
49
50      #XXX it would be nice if this could instead be after the error but before
51      # the table
52      'html_init'       => include('/elements/small_custview.html',
53                                     $custnum,
54                                     $conf->config('countrydefault') || 'US',
55                                     1, #no balance
56                                  ).
57                           '<BR>',
58 &>
59 <%init>
60
61 my $curuser = $FS::CurrentUser::CurrentUser;
62 my $conf = new FS::Conf;
63
64 if ( $cgi->param('redirect') ) {
65   my $session = $cgi->param('redirect');
66   my $pref = $curuser->option("redirect$session");
67   die "unknown redirect session $session\n" unless length($pref);
68   $cgi = new CGI($pref);
69 }
70
71 my $custnum;
72 if ( $cgi->param('error') ) {
73   $custnum = scalar($cgi->param('custnum'));
74
75   die "access denied"
76     unless $curuser->access_right(($custnum ? 'Edit' : 'New'). ' customer'); #contacts?
77
78 } elsif ( $cgi->keywords ) { #editing
79   $custnum = ($cgi->keywords)[0];
80
81   die "access denied"
82     unless $curuser->access_right('Edit customer');
83
84 } else { #new customer
85
86   #this doesn't really work here, we're an edit only
87   die "guru meditation #32";
88
89   die "access denied"
90     unless $curuser->access_right('New customer');
91
92 }
93
94 #my $new_callback = sub {
95 #  my( $cgi, $prospect_main, $fields_listref, $opt_hashref ) = @_;
96 #};
97
98 #my $edit_callback = sub {
99 # my( $cgi, $prospect_main, $fields_listref, $opt_hashref ) = @_;
100 #};
101
102 #my $error_callback = sub {
103 #  my( $cgi, $prospect_main, $fields_listref, $opt_hashref ) = @_;
104 #};
105
106 my $m2_error_callback = sub {
107   my($cgi, $object) = @_;
108
109   #process_o2m fields in process/cust_main-contacts.html
110   my @fields = FS::contact->cgi_contact_fields;
111   my @gfields = ( '', map "_$_", @fields );
112
113   map {
114         if ( /^contactnum(\d+)$/ ) {
115           my $num = $1;
116           if ( grep $cgi->param("contactnum$num$_"), @gfields ) {
117             my $x = new FS::contact {
118               'contactnum' => scalar($cgi->param("contactnum$num")),
119               map { $_ => scalar($cgi->param("contactnum${num}_$_")) } @fields,
120             };
121             $x;
122           } else {
123             ();
124           }
125         } else {
126           ();
127         }
128       }
129       $cgi->param;
130 };
131
132 </%init>