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