fix window.onload under IE8, #24210
[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   <&| /elements/onload.js &>
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 %#sales person
133 <& /elements/tr-select-sales.html,
134      'curr_value' => $cust_main->salesnum,
135 &>
136
137 %# referral (advertising source)
138 %my $refnum = $cust_main->refnum || $conf->config('referraldefault') || 0;
139 %if ( $custnum && ! $conf->exists('editreferrals') ) {
140
141   <INPUT TYPE="hidden" NAME="refnum" VALUE="<% $refnum %>">
142
143 % } else { 
144
145    <& /elements/tr-select-part_referral.html,
146                 'curr_value' => $refnum
147    &>
148 % } 
149
150
151 %# referring customer
152 %my $referring_cust_main = '';
153 %if ( $cust_main->referral_custnum
154 %     and $referring_cust_main =
155 %           qsearchs('cust_main', { custnum => $cust_main->referral_custnum } )
156 %     and ! $curuser->access_right('Edit referring customer')
157 %) {
158
159   <TR>
160     <TD ALIGN="right"><% mt('Referring customer') |h %></TD>
161     <TD>
162       <A HREF="<% popurl(1) %>/cust_main.cgi?<% $cust_main->referral_custnum %>"><% $cust_main->referral_custnum %>: <% $referring_cust_main->name |h %></A>
163     </TD>
164   </TR>
165   <INPUT TYPE="hidden" NAME="referral_custnum" VALUE="<% $cust_main->referral_custnum %>">
166
167 % } elsif ( ! $conf->exists('disable_customer_referrals') ) { 
168
169   <TR>
170     <TD ALIGN="right"><% mt('Referring customer') |h %></TD>
171     <TD>
172       <& /elements/search-cust_main.html,
173                     'field_name' => 'referral_custnum',
174                     'curr_value' => $cust_main->referral_custnum,
175       &>
176     </TD>
177   </TR>
178
179 % } else { 
180   <INPUT TYPE="hidden" NAME="referral_custnum" VALUE="">
181 % } 
182
183 %# signup date
184 % if ( $conf->exists('cust_main-edit_signupdate') ) {
185     <& /elements/tr-input-date-field.html, {
186                   'name'        => 'signupdate',
187                   'value'       => $cust_main->signupdate,
188                   'label'       => emt('Signup date'),
189                   'format'      => ( $conf->config('date_format') || "%m/%d/%Y" ),
190               }
191     &>
192 % }
193
194 % # permission to edit ticket subjects
195 % if ( $conf->exists('ticket_system-selfservice_edit_subject') ) {
196   <TR>
197     <TD ALIGN="right">
198       <INPUT TYPE="checkbox" NAME="edit_subject" VALUE="Y" <% 
199         $cust_main->edit_subject ? 'CHECKED' : '' %>></TD>
200     <TD ALIGN="left"><% mt('Can edit ticket subjects') |h %></TD>
201   </TR>
202 % } else {
203   <INPUT TYPE="hidden" NAME="edit_subject" VALUE="<% $cust_main->edit_subject %>">
204 % }
205
206 % # permission to edit
207 % if ( $conf->exists('cust_main-edit_calling_list_exempt') ) {
208   <TR>
209     <TD ALIGN="right">
210       <INPUT TYPE="checkbox" NAME="calling_list_exempt" VALUE="Y" <% 
211         $cust_main->calling_list_exempt ? 'CHECKED' : '' %>></TD>
212     <TD ALIGN="left"><% mt('Calling list exempt') |h %></TD>
213   </TR>
214 % } else {
215   <INPUT TYPE="hidden" NAME="calling_list_exempt" VALUE="<% $cust_main->calling_list_exempt %>">
216 % }
217
218 </TABLE>
219
220 <%init>
221
222 my( $cust_main, %opt ) = @_;
223
224 my $custnum = $opt{'custnum'};
225
226 if ( $cgi->param('error') ) {
227   $cust_main->set('residential_commercial',
228     ($cgi->param('residential_commercial') eq 'Commercial')
229       ? 'Commercial'
230       : 'Residential'
231   );
232 } elsif ( $custnum ) { #editing
233   $cust_main->set('residential_commercial',
234     length($cust_main->company)
235       ? 'Commercial'
236       : 'Residential'
237   );
238 } else { #new customer
239   #config to default to commercial and/or disable residential when someone needs
240   $cust_main->set('residential_commercial', 'Residential');
241 }
242
243 my $conf = new FS::Conf;
244
245 my $curuser = $FS::CurrentUser::CurrentUser;
246
247 my $r = qq!<font color="#ff0000">*</font>&nbsp;!;
248
249 # which agents lock the service address, if any
250 my %ship_locked_agents;
251 foreach (qsearch('agent',{})) {
252   my $agentnum = $_->agentnum;
253   next unless $conf->exists('agent-ship_address', $_->agentnum);
254   my $cust_main = $_->agent_cust_main or next;
255   my $agent_ship_location = $cust_main->ship_location;
256   $ship_locked_agents{$agentnum} = +{
257     map { $_ => $agent_ship_location->$_ }
258     qw(address1 city state zip country latitude longitude district)
259   };
260 }
261
262 </%init>