fix blanking of ship_ fields, #21327
[freeside.git] / httemplate / edit / cust_main / top_misc.html
1 <% &ntable("#cccccc") %>
2
3 %# tags
4 <& /elements/tr-select-cust_tag.html,
5              'custnum' => $custnum,
6              'cgi'     => $cgi,
7 &>
8
9 <SCRIPT TYPE="text/javascript">
10 var ship_locked_agents = <% encode_json(\%ship_locked_agents) %>;
11 var ship_fields = ['address1', 'city', 'state', 
12   'zip', 'country', 'latitude', 'longitude'];
13 function agent_changed(what) {
14   var agentnum = what.value;
15   var f = what.form;
16   if ( ship_locked_agents[agentnum] ) {
17     f['same'].checked = false;
18     f['same'].disabled = true;
19     samechanged(f['same']);
20     for(var x in ship_locked_agents[agentnum]) {
21       f['ship_'+x].value = ship_locked_agents[agentnum][x];
22       f['ship_'+x].disabled = true;
23       f['ship_'+x].style.backgroundColor = '#dddddd';
24     }
25     f['ship_address2'].disabled = false;
26     f['ship_address2'].style.backgroundColor = '#ffffff';
27   } else {
28     for(var i=0; i<ship_fields.length; i++) {
29       x = ship_fields[i];
30       f['ship_'+x].disabled = false;
31     }
32     f['same'].disabled = false;
33   }
34 }
35 window.onload = function() {
36   agent_changed(document.getElementById('agentnum'));
37 };
38 </SCRIPT>
39 %# agent
40 % if ( $cgi->param('lock_agentnum') =~ /^(\d+)$/ && $curuser->agentnum($1) ) {
41 %
42 %   my $agentnum = $1;
43 %   $cust_main->agentnum($agentnum);
44
45     <INPUT TYPE="hidden" NAME="lock_agentnum" VALUE="<% $agentnum %>">
46     <INPUT TYPE="hidden" NAME="agentnum"      ID="agentnum" 
47       VALUE="<% $agentnum %>">
48     <TR>
49       <TD ALIGN="right"><% mt('Agent') |h %></TD>
50       <TD CLASS="fsdisabled"><% $cust_main->agent->agent |h %></TD>
51     </TR>
52
53 % } else {
54
55   <& /elements/tr-select-agent.html, 
56                 'curr_value'    => $cust_main->agentnum,
57                 'label'         => "<B>${r}".emt('Agent')."</B>",
58                 'empty_label'   => emt('Select agent'),
59                 'disable_empty' => ( $cust_main->agentnum ? 1 : 0 ),
60                 'viewall_right' => emt('None'), 
61                 'onchange'      => 'agent_changed(this)',
62   &>
63
64 % }
65
66 %# agent_custid
67 % if ( $conf->exists('cust_main-edit_agent_custid') ) {
68
69     <TR>
70       <TD ALIGN="right"><% mt('Customer identifier') |h %></TD>
71       <TD><INPUT TYPE="text" NAME="agent_custid" VALUE="<% $cust_main->agent_custid %>"></TD>
72     </TR>
73
74 % } else {
75
76     <INPUT TYPE="hidden" NAME="agent_custid" VALUE="<% $cust_main->agent_custid %>">
77
78 % }
79
80 %# class
81 <& /elements/tr-select-cust_class.html,
82              'curr_value'  => $cust_main->classnum,
83              'label'       => emt("Class"),
84 &>
85
86 %# referral (advertising source)
87 %my $refnum = $cust_main->refnum || $conf->config('referraldefault') || 0;
88 %if ( $custnum && ! $conf->exists('editreferrals') ) {
89
90   <INPUT TYPE="hidden" NAME="refnum" VALUE="<% $refnum %>">
91
92 % } else { 
93
94    <& /elements/tr-select-part_referral.html,
95                 'curr_value' => $refnum
96    &>
97 % } 
98
99
100 %# referring customer
101 %my $referring_cust_main = '';
102 %if ( $cust_main->referral_custnum
103 %     and $referring_cust_main =
104 %           qsearchs('cust_main', { custnum => $cust_main->referral_custnum } )
105 %     and ! $curuser->access_right('Edit referring customer')
106 %) {
107
108   <TR>
109     <TD ALIGN="right"><% mt('Referring customer') |h %></TD>
110     <TD>
111       <A HREF="<% popurl(1) %>/cust_main.cgi?<% $cust_main->referral_custnum %>"><% $cust_main->referral_custnum %>: <% $referring_cust_main->name |h %></A>
112     </TD>
113   </TR>
114   <INPUT TYPE="hidden" NAME="referral_custnum" VALUE="<% $cust_main->referral_custnum %>">
115
116 % } elsif ( ! $conf->exists('disable_customer_referrals') ) { 
117
118   <TR>
119     <TD ALIGN="right"><% mt('Referring customer') |h %></TD>
120     <TD>
121       <& /elements/search-cust_main.html,
122                     'field_name' => 'referral_custnum',
123                     'curr_value' => $cust_main->referral_custnum,
124       &>
125     </TD>
126   </TR>
127
128 % } else { 
129   <INPUT TYPE="hidden" NAME="referral_custnum" VALUE="">
130 % } 
131
132 %# signup date
133 % if ( $conf->exists('cust_main-edit_signupdate') ) {
134     <& /elements/tr-input-date-field.html, {
135                   'name'        => 'signupdate',
136                   'value'       => $cust_main->signupdate,
137                   'label'       => emt('Signup date'),
138                   'format'      => ( $conf->config('date_format') || "%m/%d/%Y" ),
139               }
140     &>
141 % }
142
143 % # permission to edit ticket subjects
144 % if ( $conf->exists('ticket_system-selfservice_edit_subject') ) {
145   <TR>
146     <TD ALIGN="right">
147       <INPUT TYPE="checkbox" NAME="edit_subject" VALUE="Y" <% 
148         $cust_main->edit_subject ? 'CHECKED' : '' %>></TD>
149     <TD ALIGN="left"><% mt('Can edit ticket subjects') |h %></TD>
150   </TR>
151 % } else {
152   <INPUT TYPE="hidden" NAME="edit_subject" VALUE="<% $cust_main->edit_subject %>">
153 % }
154
155 % # permission to edit
156 % if ( $conf->exists('cust_main-edit_calling_list_exempt') ) {
157   <TR>
158     <TD ALIGN="right">
159       <INPUT TYPE="checkbox" NAME="calling_list_exempt" VALUE="Y" <% 
160         $cust_main->calling_list_exempt ? 'CHECKED' : '' %>></TD>
161     <TD ALIGN="left"><% mt('Calling list exempt') |h %></TD>
162   </TR>
163 % } else {
164   <INPUT TYPE="hidden" NAME="calling_list_exempt" VALUE="<% $cust_main->calling_list_exempt %>">
165 % }
166
167 </TABLE>
168
169 <%init>
170
171 my( $cust_main, %opt ) = @_;
172
173 my $custnum = $opt{'custnum'};
174
175 my $conf = new FS::Conf;
176
177 my $curuser = $FS::CurrentUser::CurrentUser;
178
179 my $r = qq!<font color="#ff0000">*</font>&nbsp;!;
180
181 # which agents lock the service address, if any
182 my %ship_locked_agents;
183 foreach (qsearch('agent',{})) {
184   my $agentnum = $_->agentnum;
185   next unless $conf->exists('agent-ship_address', $_->agentnum);
186   my $agent_cust_main = $_->agent_cust_main or next;
187   my $pre = '';
188   $pre = 'ship_' if $agent_cust_main->has_ship_address;
189   $ship_locked_agents{$agentnum} = +{
190     map { $_ => $agent_cust_main->get($pre.$_) }
191     qw(address1 city state zip country latitude longitude)
192   };
193 }
194
195 </%init>