RT# 75817 - Added password change link to cust main page
[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      'labels'           => {
28                              'contactnum'  => ' ', #'Contact',
29                              #'locationnum' => '&nbsp;',
30                            },
31      'fields'           => [
32        { 'field'             => 'contactnum',
33          'type'              => 'contact',
34          'colspan'           => 6,
35          'custnum'           => $custnum,
36          'm2m_method'        => 'cust_contact',
37          'm2m_dstcol'        => 'contactnum',   
38          'm2_label'          => ' ', #'Contact',
39          'm2_error_callback' => $m2_error_callback,
40        },
41      ],
42      #'new_callback'     => $new_callback,
43      #'edit_callback'    => $edit_callback,
44      #'error_callback'   => $error_callback,
45      'agent_virt'       => 1,
46      'html_table_class' => 'fsinnerbox',
47      'menubar'          => [], #remove "view all" link
48
49      #XXX it would be nice if this could instead be after the error but before
50      # the table
51      'html_init'       => include('/elements/small_custview.html',
52                                     $custnum,
53                                     $conf->config('countrydefault') || 'US',
54                                     1, #no balance
55                                  ).
56                           '<BR>',
57 &>
58 <%init>
59
60 my $curuser = $FS::CurrentUser::CurrentUser;
61 my $conf = new FS::Conf;
62
63 my $custnum;
64 if ( $cgi->param('error') ) {
65   $custnum = scalar($cgi->param('custnum'));
66
67   die "access denied"
68     unless $curuser->access_right(($custnum ? 'Edit' : 'New'). ' customer'); #contacts?
69
70 } elsif ( $cgi->keywords ) { #editing
71   $custnum = ($cgi->keywords)[0];
72
73   die "access denied"
74     unless $curuser->access_right('Edit customer');
75
76 } else { #new customer
77
78   #this doesn't really work here, we're an edit only
79   die "guru meditation #32";
80
81   die "access denied"
82     unless $curuser->access_right('New customer');
83
84 }
85
86 #my $new_callback = sub {
87 #  my( $cgi, $prospect_main, $fields_listref, $opt_hashref ) = @_;
88 #};
89
90 #my $edit_callback = sub {
91 # my( $cgi, $prospect_main, $fields_listref, $opt_hashref ) = @_;
92 #};
93
94 #my $error_callback = sub {
95 #  my( $cgi, $prospect_main, $fields_listref, $opt_hashref ) = @_;
96 #};
97
98 my $m2_error_callback = sub {
99   my($cgi, $object) = @_;
100
101   #process_o2m fields in process/cust_main-contacts.html
102   my @fields = FS::contact->cgi_contact_fields;
103   my @gfields = ( '', map "_$_", @fields );
104
105   map {
106         if ( /^contactnum(\d+)$/ ) {
107           my $num = $1;
108           if ( grep $cgi->param("contactnum$num$_"), @gfields ) {
109             my $x = new FS::contact {
110               'contactnum' => scalar($cgi->param("contactnum$num")),
111               map { $_ => scalar($cgi->param("contactnum${num}_$_")) } @fields,
112             };
113             $x;
114           } else {
115             ();
116           }
117         } else {
118           ();
119         }
120       }
121       $cgi->param;
122 };
123
124 </%init>