X-Git-Url: http://git.freeside.biz/gitweb/?p=freeside.git;a=blobdiff_plain;f=fs_selfservice%2FFS-SelfService%2Fcgi%2Fselfservice.cgi;h=8f1c4a568910b2d2230634e291af6fecabbe6f49;hp=25d61aca69451559e4ed350912efa46652395b84;hb=5d5e7f7248d786938c08c867c9ad8f855f92c532;hpb=123bc067cc9fd8b247fb0b4e9a86066f32e83991 diff --git a/fs_selfservice/FS-SelfService/cgi/selfservice.cgi b/fs_selfservice/FS-SelfService/cgi/selfservice.cgi index 25d61aca6..8f1c4a568 100644 --- a/fs_selfservice/FS-SelfService/cgi/selfservice.cgi +++ b/fs_selfservice/FS-SelfService/cgi/selfservice.cgi @@ -8,21 +8,23 @@ use CGI::Carp qw(fatalsToBrowser); use Text::Template; use HTML::Entities; use Date::Format; +use Date::Parse 'str2time'; use Number::Format 1.50; use FS::SelfService qw( access_info login_info login customer_info edit_info invoice payment_info process_payment realtime_collect process_prepay list_pkgs order_pkg signup_info order_recharge - part_svc_info provision_acct provision_external + part_svc_info provision_acct provision_external provision_phone unprovision_svc change_pkg suspend_pkg domainselector list_svcs list_svc_usage list_cdr_usage list_support_usage - myaccount_passwd list_invoices create_ticket - mason_comp + myaccount_passwd list_invoices create_ticket get_ticket did_report + adjust_ticket_priority + mason_comp port_graph ); $template_dir = '.'; -$DEBUG = 1; +$DEBUG = 0; $form_max = 255; @@ -72,8 +74,54 @@ if ( $cgi->param('session') eq 'login' ) { $session_id = $cgi->param('session'); #order|pw_list XXX ??? -$cgi->param('action') =~ - /^(myaccount|tktcreate|invoices|view_invoice|make_payment|make_ach_payment|make_term_payment|make_thirdparty_payment|payment_results|ach_payment_results|recharge_prepay|recharge_results|logout|change_bill|change_ship|change_pay|process_change_bill|process_change_ship|process_change_pay|customer_order_pkg|process_order_pkg|customer_change_pkg|process_change_pkg|process_order_recharge|provision|provision_svc|process_svc_acct|process_svc_external|delete_svc|view_usage|view_usage_details|view_cdr_details|view_support_details|change_password|process_change_password|customer_suspend_pkg|process_suspend_pkg)$/ +my @actions = ( qw( + myaccount + tktcreate + tktview + ticket_priority + didreport + invoices + view_invoice + make_payment + make_ach_payment + make_term_payment + make_thirdparty_payment + post_thirdparty_payment + payment_results + ach_payment_results + recharge_prepay + recharge_results + logout + change_bill + change_ship + change_pay + process_change_bill + process_change_ship + process_change_pay + customer_order_pkg + process_order_pkg + customer_change_pkg + process_change_pkg + process_order_recharge + provision + provision_svc + process_svc_acct + process_svc_phone + process_svc_external + delete_svc + view_usage + view_usage_details + view_cdr_details + view_support_details + view_port_graph + real_port_graph + change_password + process_change_password + customer_suspend_pkg + process_suspend_pkg +)); + +$cgi->param('action') =~ ( '^(' . join('|', @actions) . ')$' ) or die "unknown action ". $cgi->param('action'); my $action = $1; @@ -83,8 +131,10 @@ $FS::SelfService::DEBUG = $DEBUG; my $result = eval "&$action();"; die $@ if $@; -if ( $result->{error} eq "Can't resume session" - || $result->{error} eq "Expired session" ) { #ick +warn Dumper($result) if $DEBUG; + +if ( $result->{error} && ( $result->{error} eq "Can't resume session" + || $result->{error} eq "Expired session") ) { #ick my $login_info = login_info(); do_template('login', $login_info); @@ -106,7 +156,9 @@ do_template($action, { #-- use Data::Dumper; -sub myaccount { my $result = customer_info( 'session_id' => $session_id ); warn Dumper($result); $result;} +sub myaccount { + customer_info( 'session_id' => $session_id ); +} sub change_bill { my $payment_info = payment_info( 'session_id' => $session_id ); @@ -224,6 +276,30 @@ sub tktcreate { ); } +sub tktview { + get_ticket( 'session_id' => $session_id, + 'ticket_id' => ($cgi->param('ticket_id') || ''), + 'subject' => ($cgi->param('subject') || ''), + 'reply' => ($cgi->param('reply') || ''), + ); +} + +sub ticket_priority { + my %values; + foreach ( $cgi->param ) { + if ( /^ticket(\d+)$/ ) { + # a 'ticket1001' param implies the existence of a 'priority1001' param + # but if that's empty, we need to send it as empty rather than forget + # it. + $values{$1} = $cgi->param("priority$1") || ''; + } + } + $action = 'myaccount'; + # this returns an updated customer_info for myaccount + adjust_ticket_priority( 'session_id' => $session_id, + 'values' => \%values ); +} + sub customer_order_pkg { my $init_data = signup_info( 'customer_session_id' => $session_id ); return $init_data if ( $init_data->{'error'} ); @@ -573,9 +649,22 @@ sub ach_payment_results { } sub make_thirdparty_payment { + payment_info('session_id' => $session_id); +} + +sub post_thirdparty_payment { $cgi->param('payby_method') =~ /^(CC|ECHECK)$/ or die "illegal payby method"; - realtime_collect( 'session_id' => $session_id, 'method' => $1 ); + my $method = $1; + $cgi->param('amount') =~ /^(\d+(\.\d*)?)$/ + or die "illegal amount"; + my $amount = $1; + my $result = realtime_collect( + 'session_id' => $session_id, + 'method' => $method, + 'amount' => $amount, + ); + $result; } sub make_term_payment { @@ -612,9 +701,20 @@ sub logout { FS::SelfService::logout( 'session_id' => $session_id ); } +sub didreport { + my $result = did_report( 'session_id' => $session_id, + 'format' => $cgi->param('type'), + 'recentonly' => $cgi->param('recentonly'), + ); + die $result->{'error'} if exists $result->{'error'} && $result->{'error'}; + $result; +} + sub provision { my $result = list_pkgs( 'session_id' => $session_id ); die $result->{'error'} if exists $result->{'error'} && $result->{'error'}; + $result->{'pkgpart'} = $cgi->param('pkgpart') if $cgi->param('pkgpart'); + $result->{'filter'} = $cgi->param('filter') if $cgi->param('filter'); $result; } @@ -622,7 +722,7 @@ sub provision_svc { my $result = part_svc_info( 'session_id' => $session_id, - map { $_ => $cgi->param($_) } qw( pkgnum svcpart ), + map { $_ => $cgi->param($_) } qw( pkgnum svcpart svcnum ), ); die $result->{'error'} if exists $result->{'error'} && $result->{'error'}; @@ -631,6 +731,47 @@ sub provision_svc { or die 'Unknown svcdb '. $result->{'svcdb'}; $action .= "_$1"; + $result->{'numavail'} = $cgi->param('numavail'); + $result->{'lnp'} = $cgi->param('lnp'); + + $result; +} + +sub process_svc_phone { + my @bulkdid = $cgi->param('bulkdid'); + my $phonenum = $cgi->param('phonenum'); + my $lnp = $cgi->param('lnp'); + + my $result; + if($lnp) { + $result = provision_phone ( + 'session_id' => $session_id, + 'countrycode' => '1', + map { $_ => $cgi->param($_) } qw( pkgnum svcpart phonenum + lnp_desired_due_date lnp_other_provider + lnp_other_provider_account ) + ); + } else { + $result = provision_phone ( + 'session_id' => $session_id, + 'bulkdid' => [ @bulkdid ], + 'countrycode' => '1', + map { $_ => $cgi->param($_) } qw( pkgnum svcpart phonenum svcnum email forwarddst ) + ); + } + + if ( exists $result->{'error'} && $result->{'error'} ) { + $action = 'provision_svc_phone'; + return { + $cgi->Vars, + %{ part_svc_info( 'session_id' => $session_id, + map { $_ => $cgi->param($_) } qw( pkgnum svcpart svcnum ) + ) + }, + 'error' => $result->{'error'}, + }; + } + $result; } @@ -677,18 +818,39 @@ sub delete_svc { sub view_usage { list_svcs( 'session_id' => $session_id, - 'svcdb' => [ 'svc_acct', 'svc_phone' ], + 'svcdb' => [ 'svc_acct', 'svc_phone', 'svc_port', ], 'ncancelled' => 1, ); } +sub real_port_graph { + my $svcnum = $cgi->param('svcnum'); + my $res = port_graph( + 'session_id' => $session_id, + 'svcnum' => $svcnum, + 'beginning' => str2time($cgi->param('start')." 00:00:00"), + 'ending' => str2time($cgi->param('end')." 23:59:59"), + ); + my @usage = @{$res->{'usage'}}; + my $png = $usage[0]->{'png'}; + { 'content' => $png, 'format' => 'png' }; +} + +sub view_port_graph { + my $svcnum = $cgi->param('svcnum'); + { 'svcnum' => $svcnum, + 'start' => $cgi->param($svcnum.'_start'), + 'end' => $cgi->param($svcnum.'_end'), + } +} + sub view_usage_details { - list_svc_usage( - 'session_id' => $session_id, - 'svcnum' => $cgi->param('svcnum'), - 'beginning' => $cgi->param('beginning') || '', - 'ending' => $cgi->param('ending') || '', - ); + list_svc_usage( + 'session_id' => $session_id, + 'svcnum' => $cgi->param('svcnum'), + 'beginning' => $cgi->param('beginning') || '', + 'ending' => $cgi->param('ending') || '', + ); } sub view_cdr_details { @@ -759,29 +921,57 @@ sub do_template { : {}; $fill_in->{$_} = $access_info->{$_} foreach keys %$access_info; - my $source = "$template_dir/$name.html"; - #warn "creating template for $source\n"; - my $template = new Text::Template( TYPE => 'FILE', - SOURCE => $source, - DELIMITERS => [ '<%=', '%>' ], - UNTAINT => 1, - ) - or die $Text::Template::ERROR; - - #warn "filling in $template with $fill_in\n"; - print $cgi->header( '-expires' => 'now' ), - $template->fill_in( PACKAGE => 'FS::SelfService::_selfservicecgi', - HASH => $fill_in - ); -} + + if($result && ref($result) && $result->{'format'} && $result->{'content'} + && $result->{'format'} eq 'csv') { + print $cgi->header('-expires' => 'now', + '-Content-Type' => 'text/csv', + '-Content-Disposition' => "attachment;filename=output.csv", + ), + $result->{'content'}; + } + elsif($result && ref($result) && $result->{'format'} && $result->{'content'} + && $result->{'format'} eq 'xls') { + print $cgi->header('-expires' => 'now', + '-Content-Type' => 'application/vnd.ms-excel', + '-Content-Disposition' => "attachment;filename=output.xls", + '-Content-Length' => length($result->{'content'}), + ), + $result->{'content'}; + } + elsif($result && ref($result) && $result->{'format'} && $result->{'content'} + && $result->{'format'} eq 'png') { + print $cgi->header('-expires' => 'now', + '-Content-Type' => 'image/png', + ), + $result->{'content'}; + } + else { + my $source = "$template_dir/$name.html"; + my $template = new Text::Template( TYPE => 'FILE', + SOURCE => $source, + DELIMITERS => [ '<%=', '%>' ], + UNTAINT => 1, + ) + or die $Text::Template::ERROR; + + my $data = $template->fill_in( + PACKAGE => 'FS::SelfService::_selfservicecgi', + HASH => $fill_in, + ) || "Error processing template $source"; # at least print _something_ + print $cgi->header( '-expires' => 'now' ); + print $data; + } + } #*FS::SelfService::_selfservicecgi::include = \&Text::Template::fill_in_file; package FS::SelfService::_selfservicecgi; -#use FS::SelfService qw(regionselector expselect popselector); use HTML::Entities; -use FS::SelfService qw(regionselector popselector domainselector location_form); +use FS::SelfService qw( + regionselector popselector domainselector location_form didselector +); #false laziness w/agent.cgi use vars qw(@INCLUDE_ARGS);