Merge branch 'master' of git.freeside.biz:/home/git/freeside
[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 if ( $cgi->param('redirect') ) {
64   my $session = $cgi->param('redirect');
65   my $pref = $curuser->option("redirect$session");
66   die "unknown redirect session $session\n" unless length($pref);
67   $cgi = new CGI($pref);
68 }
69
70 my $custnum;
71 if ( $cgi->param('error') ) {
72   $custnum = scalar($cgi->param('custnum'));
73
74   die "access denied"
75     unless $curuser->access_right(($custnum ? 'Edit' : 'New'). ' customer'); #contacts?
76
77 } elsif ( $cgi->keywords ) { #editing
78   $custnum = ($cgi->keywords)[0];
79
80   die "access denied"
81     unless $curuser->access_right('Edit customer');
82
83 } else { #new customer
84
85   #this doesn't really work here, we're an edit only
86   die "guru meditation #32";
87
88   die "access denied"
89     unless $curuser->access_right('New customer');
90
91 }
92
93 #my $new_callback = sub {
94 #  my( $cgi, $prospect_main, $fields_listref, $opt_hashref ) = @_;
95 #};
96
97 #my $edit_callback = sub {
98 # my( $cgi, $prospect_main, $fields_listref, $opt_hashref ) = @_;
99 #};
100
101 #my $error_callback = sub {
102 #  my( $cgi, $prospect_main, $fields_listref, $opt_hashref ) = @_;
103 #};
104
105 my $m2_error_callback = sub {
106   my($cgi, $object) = @_;
107
108   #process_o2m fields in process/cust_main-contacts.html
109   my @fields = FS::contact->cgi_contact_fields;
110   my @gfields = ( '', map "_$_", @fields );
111
112   map {
113         if ( /^contactnum(\d+)$/ ) {
114           my $num = $1;
115           if ( grep $cgi->param("contactnum$num$_"), @gfields ) {
116             my $x = new FS::contact {
117               'contactnum' => scalar($cgi->param("contactnum$num")),
118               map { $_ => scalar($cgi->param("contactnum${num}_$_")) } @fields,
119             };
120             $x;
121           } else {
122             ();
123           }
124         } else {
125           ();
126         }
127       }
128       $cgi->param;
129 };
130
131 </%init>