summaryrefslogtreecommitdiff
path: root/httemplate/edit/cust_main-contacts.html
blob: 27cea9d3a0cd3f83107e29f33de9b6c5d0a708d6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
<SCRIPT>
  function checkPasswordValidation(fieldid)  {
    var validationResult = document.getElementById(fieldid+'_result').innerHTML;
    if (validationResult.match(/Password valid!/)) {
      return true;
    }
    else {
      return false;
    }
  }
</SCRIPT>

<& '/elements/validate_password_js.html', &>

<& elements/edit.html,
     'name_singular'    => 'customer contacts', #yes, we're editing all of them
     'table'            => 'cust_main',
     'post_url'         => popurl(1). 'process/cust_main-contacts.html',
     'no_pkey_display'  => 1,
     'submit_id'        => 'submit',
     'labels'           => { 'custnum'     => ' ', #XXX supress this line entirely, its being redundant
                             'contactnum'  => ' ', #'Contact',
                             #'locationnum' => '&nbsp;',
                           },
     'fields'           => [
       { 'field'             => 'contactnum',
         'type'              => 'contact',
         'colspan'           => 6,
         'custnum'           => $custnum, 
         'm2m_method'        => 'cust_contact',
         'm2m_dstcol'        => 'contactnum',   
         'm2_label'          => ' ', #'Contact',
         'm2_error_callback' => $m2_error_callback,
       },
     ],
     #'new_callback'    => $new_callback,
     #'edit_callback'   => $edit_callback,
     #'error_callback'  => $error_callback,
     'agent_virt'      => 1,
     'menubar'          => [], #remove "view all" link

     #XXX it would be nice if this could instead be after the error but before
     # the table
     'html_init'        => include('/elements/small_custview.html',
                                     $custnum,
                                     $conf->config('countrydefault') || 'US',
                                     1, #no balance
                                  ),
&>
<%init>

my $curuser = $FS::CurrentUser::CurrentUser;
my $conf = new FS::Conf;

if ( $cgi->param('redirect') ) {
  my $session = $cgi->param('redirect');
  my $pref = $curuser->option("redirect$session");
  die "unknown redirect session $session\n" unless length($pref);
  $cgi = new CGI($pref);
}

my $custnum;
if ( $cgi->param('error') ) {
  $custnum = scalar($cgi->param('custnum'));

  die "access denied"
    unless $curuser->access_right(($custnum ? 'Edit' : 'New'). ' customer'); #contacts?

} elsif ( $cgi->keywords ) { #editing
  $custnum = ($cgi->keywords)[0];

  die "access denied"
    unless $curuser->access_right('Edit customer');

} else { #new customer

  #this doesn't really work here, we're an edit only
  die "guru meditation #32";

  die "access denied"
    unless $curuser->access_right('New customer');

}

#my $new_callback = sub {
#  my( $cgi, $prospect_main, $fields_listref, $opt_hashref ) = @_;
#};

#my $edit_callback = sub {
# my( $cgi, $prospect_main, $fields_listref, $opt_hashref ) = @_;
#};

#my $error_callback = sub {
#  my( $cgi, $prospect_main, $fields_listref, $opt_hashref ) = @_;
#};

my $m2_error_callback = sub {
  my($cgi, $object) = @_;

  #process_o2m fields in process/cust_main-contacts.html
  my @fields = qw( first last title comment );
  my @gfields = ( '', map "_$_", @fields );

  map {
        if ( /^contactnum(\d+)$/ ) {
          my $num = $1;
          if ( grep $cgi->param("contactnum$num$_"), @gfields ) {
            my $x = new FS::contact {
              'contactnum' => scalar($cgi->param("contactnum$num")),
              map { $_ => scalar($cgi->param("contactnum${num}_$_")) } @fields,
            };
            $x;
          } else {
            ();
          }
        } else {
          ();
        }
      }
      $cgi->param;
};

</%init>