RT# 75817 - Added password change link to cust main page
[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 my $custnum;
55 if ( $cgi->param('error') ) {
56   $custnum = scalar($cgi->param('custnum'));
57
58   die "access denied"
59     unless $curuser->access_right(($custnum ? 'Edit' : 'New'). ' customer'); #contacts?
60
61 } elsif ( $cgi->keywords ) { #editing
62   $custnum = ($cgi->keywords)[0];
63
64   die "access denied"
65     unless $curuser->access_right('Edit customer');
66
67 } else { #new customer
68
69   #this doesn't really work here, we're an edit only
70   die "guru meditation #32";
71
72   die "access denied"
73     unless $curuser->access_right('New customer');
74
75 }
76
77 #my $new_callback = sub {
78 #  my( $cgi, $prospect_main, $fields_listref, $opt_hashref ) = @_;
79 #};
80
81 #my $edit_callback = sub {
82 # my( $cgi, $prospect_main, $fields_listref, $opt_hashref ) = @_;
83 #};
84
85 #my $error_callback = sub {
86 #  my( $cgi, $prospect_main, $fields_listref, $opt_hashref ) = @_;
87 #};
88
89 my $m2_error_callback = sub {
90   my($cgi, $object) = @_;
91
92   #process_o2m fields in process/cust_main-contacts.html
93   my @fields = qw( first last title comment );
94   my @gfields = ( '', map "_$_", @fields );
95
96   map {
97         if ( /^contactnum(\d+)$/ ) {
98           my $num = $1;
99           if ( grep $cgi->param("contactnum$num$_"), @gfields ) {
100             my $x = new FS::contact {
101               'contactnum' => scalar($cgi->param("contactnum$num")),
102               map { $_ => scalar($cgi->param("contactnum${num}_$_")) } @fields,
103             };
104             $x;
105           } else {
106             ();
107           }
108         } else {
109           ();
110         }
111       }
112       $cgi->param;
113 };
114
115 </%init>