Merge branch 'master' of ssh://git.freeside.biz/home/git/freeside
[freeside.git] / httemplate / misc / phone_avail-import.html
1 <% include('/elements/header.html', 'Phone number (DID) import') %>
2
3 Import a file containing phone numbers (DIDs).
4 <BR><BR>
5
6 <& /elements/form-file_upload.html,
7      'name'      => 'PhonenumImportForm',
8      'action'    => 'process/phone_avail-import.html',
9      'num_files' => 1,
10      'fields'    => [ 'format', 'availbatch', 'exportnum', 'countrycode',
11                       'ordernum', 'confirmed', 'vendor_order_id' ],
12      'message'   => 'DID import successful',
13      'url'       => $p."search/phone_avail.html?availbatch=$availbatch",
14      'onsubmit'  => "document.PhonenumImportForm.submitButton.disabled=true;",
15 &>
16
17 <% &ntable("#cccccc", 2) %>
18
19
20   <INPUT TYPE="hidden" NAME="availbatch" VALUE="<% $availbatch %>">
21
22 % if ( $ordernum ) {
23     <TR>
24         <TD ALIGN="RIGHT">Bulk DID Order #</TD>
25         <TD><% $ordernum %>
26             <INPUT TYPE="hidden" NAME="ordernum" VALUE="<% $ordernum %>">
27         </TD>
28     </TR>
29     <TR>
30         <TD ALIGN="RIGHT">Vendor Order #</TD>
31         <TD>
32             <INPUT TYPE="text" NAME="vendor_order_id" VALUE="<% $vendor_order_id %>">
33         </TD>
34     </TR>
35     
36     <% include( '/elements/tr-input-date-field.html', {
37                     'name' => 'confirmed',
38                     'label' => 'Order Confirmed',
39                     'value' => $confirmed,
40            })
41     %>
42
43 % } 
44   <TR>
45     <TD ALIGN="RIGHT">Import Format</TD>
46     <TD><% $format %><INPUT TYPE="hidden" NAME="format" VALUE="<% $format %>"></TD>
47   </TR>
48
49 % if ( scalar(@exports) == 1 ) { 
50 %   my $export = $exports[0];
51     <TR>
52         <TD>Export</TD>
53         <TD>
54             <INPUT TYPE="hidden" name="exportnum" value="<%$export->exportnum%>">
55             <% $export->exportname %>
56         </TD>
57     </TR>
58 % } else {
59   <% include( '/elements/tr-select-table.html',
60                 'table'       => 'part_export',
61                 'name_col'    => 'label',
62                 'order_by'    => 'ORDER BY exportname, machine',
63                 'label'       => 'Export',
64                 'empty_label' => 'Select export',
65                 'hashref'     => { 'exporttype' => 'internal_diddb', },
66                 #'label_callback' => 
67             )
68   %>
69 % }
70
71   <TR>
72     <TH ALIGN="right">Country code</TH>
73     <TD>
74       <INPUT TYPE  = "text"
75              NAME  = "countrycode"
76              VALUE = "<% $conf->config('default_phone_countrycode') || 1 %>"
77       >
78     </TD>
79   </TR>
80
81   <% include( '/elements/file-upload.html',
82                 'field' => 'file',
83                 'label' => 'Filename',
84             )
85   %>
86
87   <TR>
88     <TD COLSPAN=2 ALIGN="center" STYLE="padding-top:6px">
89       <INPUT TYPE    = "submit"
90              ID      = "submitButton"
91              NAME    = "submitButton"
92              VALUE   = "Import file"
93       >
94     </TD>
95   </TR>
96
97 </TABLE>
98
99 </FORM>
100
101 <BR>
102
103 Uploaded files can be CSV (comma-separated value) files or Excel spreadsheets.  The file should have a .CSV or .XLS extension.
104 <BR><BR>
105
106 % if ( $ordernum ) {
107     <b>Bulk</b> format has the following field order: <i>state, number, rate center, rate_center_abbrev, msa, latanum</i>
108 % } else {
109     <b>Default</b> format has the following field order: <i>state, number, name</i><br>
110 % }
111 <BR><BR>
112 Field information:
113 <ul>
114   <li><i>state</i>: Two-letter state code, i.e. "CA"
115   <li><i>number</i>: Phone number
116
117 % if ( $ordernum ) { 
118   <li><i>rate center</i>: rate center (required)
119   <li><i>rate_center_abbrev</i>: rate center abbreviation
120   <li><i>msa</i>: MSA
121   <li><i>latanum</i>: LATA #
122 % } else {
123   <li><i>name</i>: optional, rate center
124 % }
125 </ul>
126 <BR><BR>
127
128 <% include('/elements/footer.html') %>
129
130 <%init>
131
132 die "access denied"
133   unless $FS::CurrentUser::CurrentUser->access_right('Import');
134
135 my $conf = new FS::Conf;
136
137 my $ordernum = $cgi->param('ordernum');
138 $ordernum = '' unless $ordernum =~ /^\d+$/;
139
140 my $vendor_order_id = '';
141 my $confirmed = '';
142
143 my $order = '';
144 $order = qsearchs('did_order', { 'ordernum' => $ordernum } ) 
145     if $ordernum;
146
147 die 'invalid ordernum' unless (!$ordernum || $order);
148
149 my $format = 'default';
150
151 if ( $order ) {
152     $format = 'bulk';
153     $confirmed = $order->confirmed;
154     $vendor_order_id = $order->vendor_order_id;
155 }
156
157
158 my $availbatch =
159   time2str('webimport-%Y/%m/%d-%T'. "-$$-". rand() * 2**32, time);
160                 
161 my @exports = qsearch('part_export', { 'exporttype' => 'internal_diddb', });
162
163 </%init>