allow manual override of phone number, RT#19883
[freeside.git] / httemplate / elements / select-did.html
1 <%doc>
2
3 Example:
4
5   include('/elements/select-did.html',
6             #can't actuall change from phonenum yet# 'field'   => 'phonenum',
7
8             'svcpart' => 5,
9             #OR
10             'object' => $svc_phone,
11          );
12
13 </%doc>
14 % if ( $use_selector ) {
15
16 %   if ( $export->option('restrict_selection') eq 'non-tollfree'
17 %                   || !$export->option('restrict_selection') ) {
18     <TABLE>
19       <TR>
20
21 %       my( $phonenum_checked, $manual_checked ) = ( '', '' );
22 %       if ( $export->get_dids_can_manual ) {
23 %         #not 100% perfect UI on error handling, but it'll do
24 %         if ( $opt{'curr_value'} ) {
25 %           $phonenum_checked = '';
26 %           $manual_checked   = 'CHECKED';
27 %         } else {
28 %           $phonenum_checked = 'CHECKED';
29 %           $manual_checked   = '';
30 %         }
31
32         <TD VALIGN="top">
33           <INPUT TYPE     = "radio"
34                  NAME     = "phonenum_which"
35                  VALUE    = "phonenum"
36                  onChange = "phonenum_which_changed(this)"
37                  <% $phonenum_checked %>
38           > Inventory
39         </TD>
40 %       }
41
42 %       if ( $export->get_dids_npa_select ) {
43
44         <TD VALIGN="top">
45           <% include('/elements/select-state.html',
46                        'prefix'        => 'phonenum_', #$field.'_',
47                        'country'       => $country,
48                        'svcpart'       => $svcpart,
49                        'disable_empty' => 0,
50                        'empty_label'   => 'Select state',
51                        'disabled'      => ( $manual_checked ? 1 : 0 ),
52                     )
53           %>
54           <BR><FONT SIZE="-1" ID="phonenum_state_label" <% $manual_checked ? 'STYLE="color:#999999"' : '' %>>State</FONT>
55         </TD>
56
57           <TD VALIGN="top">
58             <% include('/elements/select-areacode.html',
59                          'state_prefix' => 'phonenum_', #$field.'_',
60                          'svcpart'      => $svcpart,
61                          'empty'        => 'Select area code',
62                       )
63             %>
64             <BR><FONT SIZE="-1" ID="areacode_label" <% $manual_checked ? 'STYLE="color:#999999"' : '' %>>Area code</FONT>
65           </TD>
66
67           <TD VALIGN="top">
68             <% include('/elements/select-exchange.html',
69                          'svcpart'  => $svcpart,
70                          'empty'    => 'Select exchange',
71                       )
72             %>
73             <BR><FONT SIZE="-1" ID="exchange_label" <% $manual_checked ? 'STYLE="color:#999999"' : '' %>>City / Exchange</FONT>
74           </TD>
75
76 %       } else {
77 %
78 %       #this code path currently only being used by fibernetics
79 %       # should change "Province" label to "State" or make it configurable
80 %       # if/when other folks need an areacode-less DID selector that goes
81 %       # directly from state to region
82
83         <TD VALIGN="top">
84           <% include('/elements/select.html',
85                        'field'    => 'phonenum_state',
86                        'id'       => 'phonenum_state',
87                        'options'  => [ '', @{ $export->get_dids } ],
88                        'labels'   => { '' => 'Select province' },
89                        'onchange' => 'phonenum_state_changed(this);',
90                        'disabled' => ( $manual_checked ? 1 : 0 ),
91                     )
92           %>
93           <BR><FONT SIZE="-1" ID="phonenum_state_label" <% $manual_checked ? 'STYLE="color:#999999"' : '' %>>Province</FONT>
94         </TD>
95
96           <TD VALIGN="top">
97             <% include('/elements/select-region.html',
98                          'state_prefix'  => 'phonenum_', #$field.'_',
99                          'svcpart'       => $svcpart,
100                          'empty'         => 'Select region',
101                       )
102             %>
103             <BR><FONT SIZE="-1" ID="region_label" <% $manual_checked ? 'STYLE="color:#999999"' : '' %>>Region</FONT>
104           </TD>
105
106 %       }
107
108         <TD VALIGN="top">
109           <% include('/elements/select-phonenum.html',
110                        'svcpart'  => $svcpart,
111                        'empty'    => 'Select phone number',
112                        'bulknum'  => $bulknum,
113                        'multiple' => $multiple,
114                        'region'   => ! $export->get_dids_npa_select,
115                     )
116           %>
117           <BR><FONT SIZE="-1" ID="phonenum_phonenum_label" <% $manual_checked ? 'STYLE="color:#999999"' : '' %>>Phone number</FONT>
118         </TD>
119
120       </TR>
121
122 %       if ( $export->get_dids_can_manual ) {
123           <TR>
124
125             <TD VALIGN="top">
126               <INPUT TYPE     = "radio"
127                      NAME     = "phonenum_which"
128                      VALUE    = "phonenum_manual"
129                      onChange = "phonenum_which_changed(this)"
130                      <% $manual_checked %>
131               > Manual entry
132             </TD>
133
134             <TD VALIGN="top">
135               <& /elements/input-text.html,
136                    %opt,
137                    field    => 'phonenum_manual',
138                    id       => 'phonenum_manual',
139                    type     => 'text',
140                    disabled => ( $phonenum_checked ? 1 : 0 ),
141               &>
142             </TD>
143           </TR>
144
145           <SCRIPT TYPE="text/javascript">
146             function phonenum_which_changed(what) {
147
148               if ( what.value == 'phonenum' && what.checked ) {
149
150                 what.form.phonenum_manual.disabled = true;
151                 what.form.phonenum_manual.style.backgroundColor = '#dddddd';
152
153                 what.form.phonenum_state.disabled = false;
154
155                 document.getElementById('phonenum_state_label').style.color = '#000000';
156                 if ( document.getElementById('areacode_label') ) {
157                   document.getElementById('areacode_label').style.color = '#000000';
158                 }
159                 if ( document.getElementById('exchange_label') ) {
160                   document.getElementById('exchange_label').style.color = '#000000';
161                 }
162                 if ( document.getElementById('region_label') ) {
163                   document.getElementById('region_label').style.color = '#000000';
164                 }
165                 document.getElementById('phonenum_phonenum_label').style.color = '#000000';
166
167                 var value = what.form.phonenum_state.options[ what.form.phonenum_state.selectedIndex].value;
168
169                 if ( value != '' ) {
170
171                   if ( what.form.areacode ) {
172                     what.form.areacode.disabled = false;
173
174                     var areacode_value = what.form.areacode.options[ what.form.areacode.selectedIndex].value;
175
176                     if ( areacode_value != '' ) {
177                       what.form.exchange.disabled = false;
178
179                       var exchange_value = what.form.exchange.options[ what.form.exchange.selectedIndex].value;
180
181                       if ( exchange_value != '' ) {
182                         what.form.phonenum.disabled = false;
183                       }
184
185                     }
186
187                   }
188                   if ( what.form.region ) {
189                     what.form.region.disabled = false;
190                     
191                     var region_value = what.form.region.options[ what.form.region.selectedIndex].value;
192
193                     if ( region_value != '' ) {
194                       what.form.phonenum.disabled = false;
195                     }
196
197                   }
198
199                 }
200
201               }
202
203               if ( what.value == 'phonenum_manual' && what.checked ) {
204
205                 what.form.phonenum_manual.disabled = false;
206                 what.form.phonenum_manual.style.backgroundColor = '#ffffff';
207
208                 what.form.phonenum_state.disabled = true;
209
210                 document.getElementById('phonenum_state_label').style.color = '#999999';
211                 if ( document.getElementById('areacode_label') ) {
212                   document.getElementById('areacode_label').style.color = '#999999';
213                 }
214                 if ( document.getElementById('exchange_label') ) {
215                   document.getElementById('exchange_label').style.color = '#999999';
216                 }
217                 if ( document.getElementById('region_label') ) {
218                   document.getElementById('region_label').style.color = '#999999';
219                 }
220                 document.getElementById('phonenum_phonenum_label').style.color = '#999999';
221
222                 if ( what.form.areacode ) {
223                   what.form.areacode.disabled = true;
224                 }
225
226                 if ( what.form.exchange ) {
227                   what.form.exchange.disabled = true;
228                 }
229
230                 if ( what.form.region ) {
231                   what.form.region.disabled = true;
232                 }
233
234                 what.form.phonenum.disabled = true;
235               }
236
237             }
238           </SCRIPT>
239
240 %       }
241
242     </TABLE>
243
244 % } 
245 %   if (     ( $export->option('restrict_selection') eq 'tollfree'
246 %                || !$export->option('restrict_selection')
247 %            )
248 %        and $export->get_dids_can_tollfree
249 %      ) {
250             <font size="-1">Toll-free</font>
251             <% include('/elements/select-phonenum.html',
252                        'svcpart' => $svcpart,
253                        'empty'   => 'Select phone number',
254                        'tollfree' => 1,
255                        'prefix' => 'tollfree',
256                        'bulknum' => 0,
257                     )
258             %>
259 %       }
260
261 %       if ( $bulknum ) {
262             <div id="bulkdid" style="padding-top: 11px">
263 %               my $i;
264 %               for($i=0; $i < $bulknum; $i++) {
265                     <div id="bulkdid_<%$i%>" style="display: none">
266                         <input type="checkbox" id="checkbox_bulkdid_<%$i%>"
267                             name="bulkdid" value="">
268                         <label for="checkbox_bulkdid_<%$i%>" 
269                             id="label_bulkdid_<%$i%>"></label>
270                     </div>
271 %               }
272             </div>
273 %       }
274
275 % } else {
276
277     <% include( '/elements/input-text.html', %opt, 'type'=>'text' ) %>
278
279 % }
280 <%init>
281
282 my %opt = @_;
283
284 my $conf = new FS::Conf;
285
286 #false laziness w/tr-select-did.html
287 #XXX make sure this comes through on errors too
288 my $svcpart  = $opt{'svcpart'}
289             || $opt{'object'}->svcpart
290             || $opt{'object'}->cust_svc->svcpart;
291
292 my $part_svc = qsearchs('part_svc', { 'svcpart'=>$svcpart } );
293 die "unknown svcpart $svcpart" unless $part_svc;
294
295 my @exports = $part_svc->part_export_did;
296 if ( scalar(@exports) > 1 ) {
297   die "more than one DID-providing export attached to svcpart $svcpart";
298 }
299 my $export = '';
300 $export = $exports[0] if scalar(@exports);
301
302 my $use_selector = scalar(@exports) ? 1 : 0;
303
304 my $bulknum = $opt{'bulknum'} || 0; #Bulk DID orders via ordering system, vs.
305 my $multiple = $opt{'multiple'} || 0; #just selecting a bunch at a time
306
307 my $country  = ( $export && $export->option('country') )
308             || $conf->config('countrydefault')
309             || 'US';
310
311 #my $field = $opt{'field'} || 'phonenum';
312
313 </%init>