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