fix editing of service address fields, from #21327
[freeside.git] / httemplate / edit / cust_main / top_misc.html
1 <TABLE CLASS="fsinnerbox">
2
3 <TR>
4   <TD ALIGN="right">Residential</TD>
5   <TD><INPUT TYPE     = "radio"
6              NAME     = "residential_commercial"
7              ID       = "residential_commercial_Residential"
8              VALUE    = "Residential"
9              onChange = "rescom_changed(this)"
10        <% $cust_main->residential_commercial eq 'Commercial' ? '' : 'CHECKED' %>
11   ></TD>
12 </TR>
13 <TR>
14   <TD ALIGN="right">Commercial</TD>
15   <TD><INPUT TYPE     = "radio"
16              NAME     = "residential_commercial"
17              ID       = "residential_commercial_Commercial"
18              VALUE    = "Commercial"
19              onChange = "rescom_changed(this)"
20        <% $cust_main->residential_commercial eq 'Commercial' ? 'CHECKED' : '' %>
21   ></TD>
22 </TR>
23 <SCRIPT TYPE="text/javascript">
24   function rescom_changed(what) {
25     if ( what.checked == (what.value == 'Commercial' ) ) {
26       document.getElementById('company_row').style.display = '';
27       document.getElementById('contacts_div').style.display = '';
28     } else {
29       if ( document.getElementById('company').value.length == 0 ) {
30         document.getElementById('company_row').style.display = 'none';
31       }
32       document.getElementById('contacts_div').style.display = 'none';
33     }
34   }
35
36   var ship_locked_agents = <% encode_json(\%ship_locked_agents) %>;
37   var ship_fields = ['address1', 'city', 'state', 'zip', 'country', 
38     'latitude', 'longitude', 'district'];
39   function agent_changed(what) {
40     var agentnum = what.value;
41     var f = what.form;
42     if ( ship_locked_agents[agentnum] ) {
43 %     # For this agent, the service location (except address2)
44 %     # should be locked to the agent's location.
45 %     # Set the ship_ fields to those values (just for display) and
46 %     # then disable them.
47       for(var x in ship_locked_agents[agentnum]) {
48         f['ship_'+x].value = ship_locked_agents[agentnum][x];
49         f['ship_'+x].disabled = true;
50       }
51       f['same'].checked = false;
52       f['same'].disabled = true;
53     } else {
54 %     # Unlock the ship_ location fields.  If they were previously
55 %     # disabled, then they contain some agent's address, which is 
56 %     # no longer meaningful.  So set them back to the customer's 
57 %     # current location.
58       for(var i=0; i<ship_fields.length; i++) {
59         x = ship_fields[i];
60         if ( f['ship_'+x].disabled )  {
61           f['ship_'+x].value  = f['old_ship_'+x].value;
62         }
63         f['ship_'+x].disabled = false;
64       }
65       f['same'].disabled = false;
66     }
67     samechanged(f['same']);
68   }
69   window.onload = function() {
70     agent_changed(document.getElementById('agentnum'));
71   }
72  
73 </SCRIPT>
74
75 % foreach my $field ($cust_main->virtual_fields) {
76     <% $cust_main->pvf($field)->widget('HTML', 'edit',$cust_main->getfield($field)) %>
77 % }
78
79 %# tags
80 <& /elements/tr-select-cust_tag.html,
81              'custnum' => $custnum,
82              'cgi'     => $cgi,
83 &>
84
85 %# agent
86 % if ( $cgi->param('lock_agentnum') =~ /^(\d+)$/ && $curuser->agentnum($1) ) {
87 %
88 %   my $agentnum = $1;
89 %   $cust_main->agentnum($agentnum);
90
91     <INPUT TYPE="hidden" NAME="lock_agentnum" VALUE="<% $agentnum %>">
92     <INPUT TYPE="hidden" NAME="agentnum"      ID="agentnum" 
93       VALUE="<% $agentnum %>">
94     <TR>
95       <TD ALIGN="right"><% mt('Agent') |h %></TD>
96       <TD CLASS="fsdisabled"><% $cust_main->agent->agent |h %></TD>
97     </TR>
98
99 % } else {
100
101   <& /elements/tr-select-agent.html, 
102                 'curr_value'    => $cust_main->agentnum,
103                 'label'         => "<B>${r}".emt('Agent')."</B>",
104                 'empty_label'   => emt('Select agent'),
105                 'disable_empty' => ( $cust_main->agentnum ? 1 : 0 ),
106                 'viewall_right' => emt('None'), 
107                 'onchange'      => 'agent_changed(this)',
108   &>
109
110 % }
111
112 %# agent_custid
113 % if ( $conf->exists('cust_main-edit_agent_custid') ) {
114
115     <TR>
116       <TD ALIGN="right"><% mt('Customer identifier') |h %></TD>
117       <TD><INPUT TYPE="text" NAME="agent_custid" VALUE="<% $cust_main->agent_custid %>"></TD>
118     </TR>
119
120 % } else {
121
122     <INPUT TYPE="hidden" NAME="agent_custid" VALUE="<% $cust_main->agent_custid %>">
123
124 % }
125
126 %# class
127 <& /elements/tr-select-cust_class.html,
128              'curr_value'  => $cust_main->classnum,
129              'label'       => emt("Class"),
130 &>
131
132 %# referral (advertising source)
133 %my $refnum = $cust_main->refnum || $conf->config('referraldefault') || 0;
134 %if ( $custnum && ! $conf->exists('editreferrals') ) {
135
136   <INPUT TYPE="hidden" NAME="refnum" VALUE="<% $refnum %>">
137
138 % } else { 
139
140    <& /elements/tr-select-part_referral.html,
141                 'curr_value' => $refnum
142    &>
143 % } 
144
145
146 %# referring customer
147 %my $referring_cust_main = '';
148 %if ( $cust_main->referral_custnum
149 %     and $referring_cust_main =
150 %           qsearchs('cust_main', { custnum => $cust_main->referral_custnum } )
151 %     and ! $curuser->access_right('Edit referring customer')
152 %) {
153
154   <TR>
155     <TD ALIGN="right"><% mt('Referring customer') |h %></TD>
156     <TD>
157       <A HREF="<% popurl(1) %>/cust_main.cgi?<% $cust_main->referral_custnum %>"><% $cust_main->referral_custnum %>: <% $referring_cust_main->name |h %></A>
158     </TD>
159   </TR>
160   <INPUT TYPE="hidden" NAME="referral_custnum" VALUE="<% $cust_main->referral_custnum %>">
161
162 % } elsif ( ! $conf->exists('disable_customer_referrals') ) { 
163
164   <TR>
165     <TD ALIGN="right"><% mt('Referring customer') |h %></TD>
166     <TD>
167       <& /elements/search-cust_main.html,
168                     'field_name' => 'referral_custnum',
169                     'curr_value' => $cust_main->referral_custnum,
170       &>
171     </TD>
172   </TR>
173
174 % } else { 
175   <INPUT TYPE="hidden" NAME="referral_custnum" VALUE="">
176 % } 
177
178 %# signup date
179 % if ( $conf->exists('cust_main-edit_signupdate') ) {
180     <& /elements/tr-input-date-field.html, {
181                   'name'        => 'signupdate',
182                   'value'       => $cust_main->signupdate,
183                   'label'       => emt('Signup date'),
184                   'format'      => ( $conf->config('date_format') || "%m/%d/%Y" ),
185               }
186     &>
187 % }
188
189 % # permission to edit ticket subjects
190 % if ( $conf->exists('ticket_system-selfservice_edit_subject') ) {
191   <TR>
192     <TD ALIGN="right">
193       <INPUT TYPE="checkbox" NAME="edit_subject" VALUE="Y" <% 
194         $cust_main->edit_subject ? 'CHECKED' : '' %>></TD>
195     <TD ALIGN="left"><% mt('Can edit ticket subjects') |h %></TD>
196   </TR>
197 % } else {
198   <INPUT TYPE="hidden" NAME="edit_subject" VALUE="<% $cust_main->edit_subject %>">
199 % }
200
201 % # permission to edit
202 % if ( $conf->exists('cust_main-edit_calling_list_exempt') ) {
203   <TR>
204     <TD ALIGN="right">
205       <INPUT TYPE="checkbox" NAME="calling_list_exempt" VALUE="Y" <% 
206         $cust_main->calling_list_exempt ? 'CHECKED' : '' %>></TD>
207     <TD ALIGN="left"><% mt('Calling list exempt') |h %></TD>
208   </TR>
209 % } else {
210   <INPUT TYPE="hidden" NAME="calling_list_exempt" VALUE="<% $cust_main->calling_list_exempt %>">
211 % }
212
213 </TABLE>
214
215 <%init>
216
217 my( $cust_main, %opt ) = @_;
218
219 my $custnum = $opt{'custnum'};
220
221 if ( $cgi->param('error') ) {
222   $cust_main->set('residential_commercial',
223     ($cgi->param('residential_commercial') eq 'Commercial')
224       ? 'Commercial'
225       : 'Residential'
226   );
227 } elsif ( $custnum ) { #editing
228   $cust_main->set('residential_commercial',
229     length($cust_main->company)
230       ? 'Commercial'
231       : 'Residential'
232   );
233 } else { #new customer
234   #config to default to commercial and/or disable residential when someone needs
235   $cust_main->set('residential_commercial', 'Residential');
236 }
237
238 my $conf = new FS::Conf;
239
240 my $curuser = $FS::CurrentUser::CurrentUser;
241
242 my $r = qq!<font color="#ff0000">*</font>&nbsp;!;
243
244 # which agents lock the service address, if any
245 my %ship_locked_agents;
246 foreach (qsearch('agent',{})) {
247   my $agentnum = $_->agentnum;
248   next unless $conf->exists('agent-ship_address', $_->agentnum);
249   my $cust_main = $_->agent_cust_main or next;
250   my $agent_ship_location = $cust_main->ship_location;
251   $ship_locked_agents{$agentnum} = +{
252     map { $_ => $agent_ship_location->$_ }
253     qw(address1 city state zip country latitude longitude district)
254   };
255 }
256
257 </%init>