diff options
Diffstat (limited to 'httemplate/misc/process')
-rwxr-xr-x | httemplate/misc/process/catchall.cgi | 33 | ||||
-rw-r--r-- | httemplate/misc/process/cust_main-import.cgi | 30 | ||||
-rw-r--r-- | httemplate/misc/process/cust_main-import_charges.cgi | 26 | ||||
-rwxr-xr-x | httemplate/misc/process/delete-customer.cgi | 29 | ||||
-rwxr-xr-x | httemplate/misc/process/link.cgi | 43 | ||||
-rw-r--r-- | httemplate/misc/process/meta-import.cgi | 178 |
6 files changed, 339 insertions, 0 deletions
diff --git a/httemplate/misc/process/catchall.cgi b/httemplate/misc/process/catchall.cgi new file mode 100755 index 000000000..44a63f9f8 --- /dev/null +++ b/httemplate/misc/process/catchall.cgi @@ -0,0 +1,33 @@ +<% + +$FS::svc_domain::whois_hack=1; + +$cgi->param('svcnum') =~ /^(\d*)$/ or die "Illegal svcnum!"; +my $svcnum =$1; + +my $old = qsearchs('svc_domain',{'svcnum'=>$svcnum}) if $svcnum; + +my $new = new FS::svc_domain ( { + map { + ($_, scalar($cgi->param($_))); + } ( fields('svc_domain'), qw( pkgnum svcpart ) ) +} ); + +$new->setfield('action' => 'M'); + +my $error; +if ( $svcnum ) { + $error = $new->replace($old); +} else { + $error = $new->insert; + $svcnum = $new->getfield('svcnum'); +} + +if ($error) { + $cgi->param('error', $error); + print $cgi->redirect(popurl(2). "catchall.cgi?". $cgi->query_string ); +} else { + print $cgi->redirect(popurl(3). "view/svc_domain.cgi?$svcnum"); +} + +%> diff --git a/httemplate/misc/process/cust_main-import.cgi b/httemplate/misc/process/cust_main-import.cgi new file mode 100644 index 000000000..9e1adce54 --- /dev/null +++ b/httemplate/misc/process/cust_main-import.cgi @@ -0,0 +1,30 @@ +<% + + my $fh = $cgi->upload('csvfile'); + #warn $cgi; + #warn $fh; + + my $error = defined($fh) + ? FS::cust_main::batch_import( { + filehandle => $fh, + agentnum => scalar($cgi->param('agentnum')), + refnum => scalar($cgi->param('refnum')), + pkgpart => scalar($cgi->param('pkgpart')), + 'fields' => [qw( cust_pkg.setup dayphone first last address1 address2 + city state zip comments )], + } ) + : 'No file'; + + if ( $error ) { + %> + <!-- mason kludge --> + <% + eidiot($error); +# $cgi->param('error', $error); +# print $cgi->redirect( "${p}cust_main-import.cgi + } else { + %> + <!-- mason kludge --> + <%= header('Import sucessful') %> <% + } +%> diff --git a/httemplate/misc/process/cust_main-import_charges.cgi b/httemplate/misc/process/cust_main-import_charges.cgi new file mode 100644 index 000000000..14df1bd8d --- /dev/null +++ b/httemplate/misc/process/cust_main-import_charges.cgi @@ -0,0 +1,26 @@ +<% + + my $fh = $cgi->upload('csvfile'); + #warn $cgi; + #warn $fh; + + my $error = defined($fh) + ? FS::cust_main::batch_charge( { + filehandle => $fh, + 'fields' => [qw( custnum amount pkg )], + } ) + : 'No file'; + + if ( $error ) { + %> + <!-- mason kludge --> + <% + eidiot($error); +# $cgi->param('error', $error); +# print $cgi->redirect( "${p}cust_main-import_charges.cgi + } else { + %> + <!-- mason kludge --> + <%= header('Import sucessful') %> <% + } +%> diff --git a/httemplate/misc/process/delete-customer.cgi b/httemplate/misc/process/delete-customer.cgi new file mode 100755 index 000000000..16bdbaea8 --- /dev/null +++ b/httemplate/misc/process/delete-customer.cgi @@ -0,0 +1,29 @@ +<% + +my $conf = new FS::Conf; +die "Customer deletions not enabled" unless $conf->exists('deletecustomers'); + +$cgi->param('custnum') =~ /^(\d+)$/; +my $custnum = $1; +my $new_custnum; +if ( $cgi->param('new_custnum') ) { + $cgi->param('new_custnum') =~ /^(\d+)$/ + or die "Illegal new customer number: ". $cgi->param('new_custnum'); + $new_custnum = $1; +} else { + $new_custnum = ''; +} +my $cust_main = qsearchs( 'cust_main', { 'custnum' => $custnum } ) + or die "Customer not found: $custnum"; + +my $error = $cust_main->delete($new_custnum); + +if ( $error ) { + $cgi->param('error', $error); + print $cgi->redirect(popurl(2). "delete-customer.cgi?". $cgi->query_string ); +} elsif ( $new_custnum ) { + print $cgi->redirect(popurl(3). "view/cust_main.cgi?$new_custnum"); +} else { + print $cgi->redirect(popurl(3)); +} +%> diff --git a/httemplate/misc/process/link.cgi b/httemplate/misc/process/link.cgi new file mode 100755 index 000000000..5d80adeb9 --- /dev/null +++ b/httemplate/misc/process/link.cgi @@ -0,0 +1,43 @@ +<% + +$cgi->param('pkgnum') =~ /^(\d+)$/; +my $pkgnum = $1; +$cgi->param('svcpart') =~ /^(\d+)$/; +my $svcpart = $1; +$cgi->param('svcnum') =~ /^(\d*)$/; +my $svcnum = $1; + +unless ( $svcnum ) { + my $part_svc = qsearchs('part_svc',{'svcpart'=>$svcpart}); + my $svcdb = $part_svc->getfield('svcdb'); + $cgi->param('link_field') =~ /^(\w+)$/; + my $link_field = $1; + my $svc_x = ( grep { $_->cust_svc->svcpart == $svcpart } + qsearch( $svcdb, { $link_field => $cgi->param('link_value') }) + )[0]; + eidiot("$link_field not found!") unless $svc_x; + $svcnum = $svc_x->svcnum; +} + +my $old = qsearchs('cust_svc',{'svcnum'=>$svcnum}); +die "svcnum not found!" unless $old; +#die "svcnum $svcnum already linked to package ". $old->pkgnum if $old->pkgnum; +my $new = new FS::cust_svc ({ + 'svcnum' => $svcnum, + 'pkgnum' => $pkgnum, + 'svcpart' => $svcpart, +}); + +my $error = $new->replace($old); + +unless ($error) { + #no errors, so let's view this customer. + print $cgi->redirect(popurl(3). "view/cust_pkg.cgi?$pkgnum"); +} else { +%> +<!-- mason kludge --> +<% + idiot($error); +} + +%> diff --git a/httemplate/misc/process/meta-import.cgi b/httemplate/misc/process/meta-import.cgi new file mode 100644 index 000000000..59d236f64 --- /dev/null +++ b/httemplate/misc/process/meta-import.cgi @@ -0,0 +1,178 @@ +<!-- mason kludge --> +<%= header('Map tables') %> + +<SCRIPT> +var gSafeOnload = new Array(); +var gSafeOnsubmit = new Array(); +window.onload = SafeOnload; +function SafeAddOnLoad(f) { + gSafeOnload[gSafeOnload.length] = f; +} +function SafeOnload() { + for (var i=0;i<gSafeOnload.length;i++) + gSafeOnload[i](); +} +function SafeAddOnSubmit(f) { + gSafeOnsubmit[gSafeOnsubmit.length] = f; +} +function SafeOnsubmit() { + for (var i=0;i<gSafeOnsubmit.length;i++) + gSafeOnsubmit[i](); +} +</SCRIPT> + +<FORM NAME="OneTrueForm" METHOD="POST" ACTION="meta-import.cgi"> + +<% + #use DBIx::DBSchema; + my $schema = new_native DBIx::DBSchema + map { $cgi->param($_) } qw( data_source username password ); + foreach my $field (qw( data_source username password )) { %> + <INPUT TYPE="hidden" NAME=<%= $field %> VALUE="<%= $cgi->param($field) %>"> + <% } + + my %schema; + use Tie::DxHash; + tie %schema, 'Tie::DxHash'; + if ( $cgi->param('schema') ) { + my $schema_string = $cgi->param('schema'); + %> <INPUT TYPE="hidden" NAME="schema" VALUE="<%=$schema_string%>"> <% + %schema = map { /^\s*(\w+)\s*=>\s*(\w+)\s*$/ + or die "guru meditation #420: $_"; + ( $1 => $2 ); + } + split( /\n/, $schema_string ); + } + + #first page + unless ( $cgi->param('magic') ) { %> + + <INPUT TYPE="hidden" NAME="magic" VALUE="process"> + <%= hashmaker('schema', [ $schema->tables ], + [ grep !/^h_/, dbdef->tables ], ) %> + <br><INPUT TYPE="submit" VALUE="done"> + <% + + #second page + } elsif ( $cgi->param('magic') eq 'process' ) { %> + + <INPUT TYPE="hidden" NAME="magic" VALUE="process2"> + <% + + my %unique; + foreach my $table ( keys %schema ) { + + my @from_columns = $schema->table($table)->columns; + my @fs_columns = dbdef->table($schema{$table})->columns; + + %> + <%= hashmaker( $table.'__'.$unique{$table}++, + \@from_columns => \@fs_columns, + $table => $schema{$table}, ) %> + <br><hr><br> + <% + + } + + %> + <br><INPUT TYPE="submit" VALUE="done"> + <% + + #third (results) + } elsif ( $cgi->param('magic') eq 'process2' ) { + + print "<pre>\n"; + + my %unique; + foreach my $table ( keys %schema ) { + ( my $spaces = $table ) =~ s/./ /g; + print "'$table' => { 'table' => '$schema{$table}',\n". + #(length($table) x ' '). " 'map' => {\n"; + "$spaces 'map' => {\n"; + my %map = map { /^\s*(\w+)\s*=>\s*(\w+)\s*$/ + or die "guru meditation #420: $_"; + ( $1 => $2 ); + } + split( /\n/, $cgi->param($table.'__'.$unique{$table}++) ); + foreach ( keys %map ) { + print "$spaces '$_' => '$map{$_}',\n"; + } + print "$spaces },\n"; + print "$spaces },\n"; + + } + print "\n</pre>"; + + } else { + warn "unrecognized magic: ". $cgi->param('magic'); + } + + %> +</FORM> +</BODY> +</HTML> + + <% + #hashmaker widget + sub hashmaker { + my($name, $from, $to, $labelfrom, $labelto) = @_; + my $fromsize = scalar(@$from); + my $tosize = scalar(@$to); + "<TABLE><TR><TH>$labelfrom</TH><TH>$labelto</TH></TR><TR><TD>". + qq!<SELECT NAME="${name}_from" SIZE=$fromsize>\n!. + join("\n", map { qq!<OPTION VALUE="$_">$_</OPTION>! } sort { $a cmp $b } @$from ). + "</SELECT>\n<BR>". + qq!<INPUT TYPE="button" VALUE="refill" onClick="repack_${name}_from()">!. + '</TD><TD>'. + qq!<SELECT NAME="${name}_to" SIZE=$tosize>\n!. + join("\n", map { qq!<OPTION VALUE="$_">$_</OPTION>! } sort { $a cmp $b } @$to ). + "</SELECT>\n<BR>". + qq!<INPUT TYPE="button" VALUE="refill" onClick="repack_${name}_to()">!. + '</TD></TR>'. + '<TR><TD COLSPAN=2>'. + qq!<INPUT TYPE="button" VALUE="map" onClick="toke_$name(this.form)">!. + '</TD></TR><TR><TD COLSPAN=2>'. + qq!<TEXTAREA NAME="$name" COLS=80 ROWS=8></TEXTAREA>!. + '</TD></TR></TABLE>'. + "<script> + function toke_$name() { + fromObject = document.OneTrueForm.${name}_from; + for (var i=fromObject.options.length-1;i>-1;i--) { + if (fromObject.options[i].selected) + fromname = deleteOption_$name(fromObject,i); + } + toObject = document.OneTrueForm.${name}_to; + for (var i=toObject.options.length-1;i>-1;i--) { + if (toObject.options[i].selected) + toname = deleteOption_$name(toObject,i); + } + document.OneTrueForm.$name.value = document.OneTrueForm.$name.value + fromname + ' => ' + toname + '\\n'; + } + function deleteOption_$name(object,index) { + value = object.options[index].value; + object.options[index] = null; + return value; + } + function repack_${name}_from() { + var object = document.OneTrueForm.${name}_from; + object.options.length = 0; + ". join("\n", + map { "addOption_$name(object, '$_');\n" } + ( sort { $a cmp $b } @$from ) ). " + } + function repack_${name}_to() { + var object = document.OneTrueForm.${name}_to; + object.options.length = 0; + ". join("\n", + map { "addOption_$name(object, '$_');\n" } + ( sort { $a cmp $b } @$to ) ). " + } + function addOption_$name(object,value) { + var length = object.length; + object.options[length] = new Option(value, value, false, false); + } + </script>". + ''; + } + +%> |