diff options
author | Ivan Kohler <ivan@freeside.biz> | 2012-10-09 12:32:39 -0700 |
---|---|---|
committer | Ivan Kohler <ivan@freeside.biz> | 2012-10-09 12:32:39 -0700 |
commit | 98460903530ead429f608ba6fce4eac1a8ee3cf3 (patch) | |
tree | 45b9931e70847c830ede208a2aa4ecd15df758ed | |
parent | 0f3189c19c3cb41f7daafbc102d692a8426cb427 (diff) | |
parent | a977d27ac2e9d8f8e1adbbdcfc3547bc378dde63 (diff) |
Merge branch 'master' of git.freeside.biz:/home/git/freeside
-rw-r--r-- | FS/FS/part_export/dma_radiusmanager.pm | 139 | ||||
-rw-r--r-- | httemplate/edit/process/quick-cust_pkg.cgi | 4 | ||||
-rw-r--r-- | httemplate/elements/table-tickets.html | 10 | ||||
-rw-r--r-- | httemplate/view/elements/svc_Common.html | 2 | ||||
-rwxr-xr-x | httemplate/view/svc_acct.cgi | 2 | ||||
-rwxr-xr-x | httemplate/view/svc_domain.cgi | 2 | ||||
-rw-r--r-- | httemplate/view/svc_external.cgi | 2 | ||||
-rwxr-xr-x | httemplate/view/svc_forward.cgi | 2 | ||||
-rw-r--r-- | httemplate/view/svc_www.cgi | 2 |
9 files changed, 87 insertions, 78 deletions
diff --git a/FS/FS/part_export/dma_radiusmanager.pm b/FS/FS/part_export/dma_radiusmanager.pm index ab77c4645..d46a996ca 100644 --- a/FS/FS/part_export/dma_radiusmanager.pm +++ b/FS/FS/part_export/dma_radiusmanager.pm @@ -9,14 +9,17 @@ use FS::radius_group; use Tie::IxHash; use Digest::MD5 'md5_hex'; +use Locale::Country qw(code2country); +use Locale::SubCountry; +use Date::Format 'time2str'; + tie %options, 'Tie::IxHash', 'dbname' => { label=>'Database name', default=>'radius' }, 'username' => { label=>'Database username' }, 'password' => { label=>'Database password' }, 'manager' => { label=>'Manager name' }, - 'groupid' => { label=>'Group ID', default=>'1' }, - 'service_prefix' => { label=>'Service name prefix' }, - 'nasnames' => { label=>'NAS IDs/addresses' }, + 'template_name' => { label=>'Template service name' }, + 'service_prefix' => { label=>'Service name prefix' }, 'debug' => { label=>'Enable debugging', type=>'checkbox' }, ; @@ -57,6 +60,12 @@ sub dma_rm_queue { my $cust_main = $cust_pkg->cust_main; my $location = $cust_pkg->cust_location; + my $address = $location->address1; + $address .= ' '.$location->address2 if $location->address2; + my $country = code2country($location->country); + my $lsc = Locale::SubCountry->new($location->country); + my $state = $lsc->full_name($location->state) if defined($lsc); + my %params = ( # for the remote side username => $svc_acct->username, @@ -70,9 +79,9 @@ sub dma_rm_queue { mobile => $cust_main->mobile, address => $location->address1, # address2? city => $location->city, - state => $location->state, + state => $state, #full name zip => $location->zip, - country => $location->country, + country => $country, #full name gpslat => $location->latitude, gpslong => $location->longitude, comment => 'svcnum'.$svcnum, @@ -118,6 +127,8 @@ sub dma_rm_action { $params{srvid} = $srvid; if ( $action eq 'insert' ) { + $params{'createdon'} = time2str('%Y-%m-%d', time); + $params{'expiration'} = time2str('%Y-%m-%d', time); warn "rm_users: inserting svcnum$svcnum\n" if $DEBUG; my $sth = $dbh->prepare( 'INSERT INTO rm_users ( '. join(', ', keys(%params)). @@ -223,6 +234,14 @@ not, create one. Then return its srvid. sub export_part_svc { my ($self, $part_svc, $dbh) = @_; + # if $dbh exists, use the existing transaction + # otherwise create our own and commit when finished + my $commit = 0; + if (!$dbh) { + $dbh = $self->connect; + $commit = 1; + } + my $name = $self->option('service_prefix').$part_svc->svc; my %params = ( @@ -230,19 +249,22 @@ sub export_part_svc { 'enableservice' => 1, 'nextsrvid' => -1, 'dailynextsrvid' => -1, + # force price-related fields to zero + 'unitprice' => 0, + 'unitpriceadd' => 0, + 'unitpricetax' => 0, + 'unitpriceaddtax' => 0, ); my @fixed_groups; # use speed settings from fixed usergroups configured on this part_svc if ( my $psc = $part_svc->part_svc_column('usergroup') ) { - if ( $psc->columnflag eq 'F' ) { - # each part_svc really should only have one fixed group with non-null - # speed settings, but go by priority order for consistency - @fixed_groups = - sort { $a->priority <=> $b->priority } - grep { $_ } - map { FS::radius_group->by_key($_) } - split(/\s*,\s*/, $psc->columnvalue); - } + # each part_svc really should only have one fixed group with non-null + # speed settings, but go by priority order for consistency + @fixed_groups = + sort { $a->priority <=> $b->priority } + grep { $_ } + map { FS::radius_group->by_key($_) } + split(/\s*,\s*/, $psc->columnvalue); } # otherwise there are no fixed groups, so leave speed empty foreach (qw(down up)) { @@ -263,74 +285,71 @@ sub export_part_svc { $sth->execute($name) or die $dbh->errstr; if ( $sth->rows > 1 ) { die "Multiple services with name '$name' found in Radius Manager.\n"; - } elsif ( $sth->rows == 1 ) { - my $row = $sth->fetchrow_arrayref; - my $srvid = $row->[0]; - warn "rm_services: updating srvid#$srvid\n" if $DEBUG; - $sth = $dbh->prepare( - 'UPDATE rm_services SET '.join(', ', map {"$_ = ?"} keys %params) . - ' WHERE srvid = ?' - ); - $sth->execute(values(%params), $srvid) or die $dbh->errstr; - return $srvid; - } else { # $sth->rows == 0 - # create a new one - # but first... get the next available srvid + + } elsif ( $sth->rows == 0 ) { + # leave this blank to disable creating new service defs + my $template_name = $self->option('template_name'); + + die "Can't create a new service profile--no template service specified.\n" + unless $template_name; + + warn "rm_services: fetching template '$template_name'\n" if $DEBUG; + $sth = $dbh->prepare('SELECT * FROM rm_services WHERE srvname = ? LIMIT 1'); + $sth->execute($template_name); + die "Can't create a new service profile--template service ". + "'$template_name' not found.\n" unless $sth->rows == 1; + my $template = $sth->fetchrow_hashref; + %params = (%$template, %params); + + # get the next available srvid $sth = $dbh->prepare('SELECT MAX(srvid) FROM rm_services'); $sth->execute or die $dbh->errstr; - my $srvid = 1; # just in case you somehow have nothing in your database + my $srvid; if ( $sth->rows ) { $srvid = $sth->fetchrow_arrayref->[0] + 1; } $params{'srvid'} = $srvid; - # NOW create a new one + + # create a new one based on the template warn "rm_services: inserting '$name' as srvid#$srvid\n" if $DEBUG; $sth = $dbh->prepare( 'INSERT INTO rm_services ('.join(', ', keys %params). ') VALUES ('.join(', ', map {'?'} keys %params).')' ); $sth->execute(values(%params)) or die $dbh->errstr; - # also link it to our manager name + # also link it to all the managers allowed on the template service warn "rm_services: linking to manager\n" if $DEBUG; $sth = $dbh->prepare( - 'INSERT INTO rm_allowedmanagers (srvid, managername) VALUES (?, ?)' + 'INSERT INTO rm_allowedmanagers (srvid, managername) '. + 'SELECT ?, managername FROM rm_allowedmanagers WHERE srvid = ?' ); - $sth->execute($srvid, $self->option('manager')) or die $dbh->errstr; - # and allow it on our NAS + $sth->execute($srvid, $template->{srvid}) or die $dbh->errstr; + # and the same for NASes + warn "rm_services: linking to nas\n" if $DEBUG; $sth = $dbh->prepare( - 'INSERT INTO rm_allowednases (srvid, nasid) VALUES (?, ?)' + 'INSERT INTO rm_allowednases (srvid, nasid) '. + 'SELECT ?, nasid FROM rm_allowednases WHERE srvid = ?' ); - foreach my $nasid ($self->nas_ids($dbh)) { - warn "rm_services: linking to nasid#$nasid\n" if $DEBUG; - $sth->execute($srvid, $nasid) or die $dbh->errstr; - } - return $srvid; - } -} - -=item nas_ids DBH + $sth->execute($srvid, $template->{srvid}) or die $dbh->errstr; -Convert the 'nasnames option into a list of real NAS ids. + $dbh->commit if $commit; + return $srvid; -=cut + } else { # $sth->rows == 1, it already exists -sub nas_ids { - my $self = shift; - my $dbh = shift; - - my @nasnames = split(/\s*,\s*/, $self->option('nasnames')); - return unless @nasnames; - # pass these through unchanged - my @ids = grep { /^\d+$/ } @nasnames; - @nasnames = grep { not /^\d+$/ } @nasnames; - my $in_nasnames = join(',', map {$dbh->quote($_)} @nasnames); + my $row = $sth->fetchrow_arrayref; + my $srvid = $row->[0]; + warn "rm_services: updating srvid#$srvid\n" if $DEBUG; + $sth = $dbh->prepare( + 'UPDATE rm_services SET '.join(', ', map {"$_ = ?"} keys %params) . + ' WHERE srvid = ?' + ); + $sth->execute(values(%params), $srvid) or die $dbh->errstr; - my $sth = $dbh->prepare("SELECT id FROM nas WHERE nasname IN ($in_nasnames)"); - $sth->execute or die $dbh->errstr; - my $rows = $sth->fetchall_arrayref; - push @ids, $_->[0] foreach @$rows; + $dbh->commit if $commit; + return $srvid; - return @ids; + } } 1; diff --git a/httemplate/edit/process/quick-cust_pkg.cgi b/httemplate/edit/process/quick-cust_pkg.cgi index c5eee0cb8..2dadbccdc 100644 --- a/httemplate/edit/process/quick-cust_pkg.cgi +++ b/httemplate/edit/process/quick-cust_pkg.cgi @@ -64,9 +64,9 @@ die 'no custnum or prospectnum' unless $cust_main || $prospect_main; $cgi->param('pkgpart') =~ /^(\d+)$/ or die 'illegal pkgpart '. $cgi->param('pkgpart'); my $pkgpart = $1; -$cgi->param('quantity') =~ /^(\d+)$/ +$cgi->param('quantity') =~ /^(\d*)$/ or die 'illegal quantity '. $cgi->param('quantity'); -my $quantity = $1; +my $quantity = $1 || 1; $cgi->param('refnum') =~ /^(\d*)$/ or die 'illegal refnum '. $cgi->param('refnum'); my $refnum = $1; diff --git a/httemplate/elements/table-tickets.html b/httemplate/elements/table-tickets.html index 6d1a45a0d..ffcaf0677 100644 --- a/httemplate/elements/table-tickets.html +++ b/httemplate/elements/table-tickets.html @@ -94,12 +94,12 @@ View </TABLE> <%init> -use Date::Parse qw(str2time); -use Date::Format qw(time2str); my %opt = @_; my $conf = new FS::Conf; +return '' unless $conf->config('ticket_system'); + my $object = $opt{'object'}; $object = $object->cust_svc if $object->isa('FS::svc_Common'); my( @tickets ) = $object->tickets; @@ -116,8 +116,10 @@ if ( $object->isa('FS::cust_main') ) { $object->custnum, { 'statuses' => [ 'resolved' ] } ); -} -elsif ( $object->isa('FS::cust_svc') ) { +} elsif ( $object->isa('FS::cust_svc') ) { + + return '' unless $object->pkgnum; + $thing = 'service'; $open_link = FS::TicketSystem->href_service_tickets($object->svcnum); diff --git a/httemplate/view/elements/svc_Common.html b/httemplate/view/elements/svc_Common.html index 04d2b2962..f7c685c28 100644 --- a/httemplate/view/elements/svc_Common.html +++ b/httemplate/view/elements/svc_Common.html @@ -114,9 +114,7 @@ function areyousure(href) { % } -% if ( $conf->config('ticket_system') ) { <& /elements/table-tickets.html, object => $cust_svc &> -% } <% joblisting({'svcnum'=>$svcnum}, 1) %> diff --git a/httemplate/view/svc_acct.cgi b/httemplate/view/svc_acct.cgi index 3ad21bb4d..199591356 100755 --- a/httemplate/view/svc_acct.cgi +++ b/httemplate/view/svc_acct.cgi @@ -76,9 +76,7 @@ <& elements/svc_export_settings.html, $svc_acct &> -% if ( $conf->config('ticket_system') ) { <& /elements/table-tickets.html, object => $cust_svc &> -% } <BR> <% joblisting({'svcnum'=>$svcnum}, 1) %> diff --git a/httemplate/view/svc_domain.cgi b/httemplate/view/svc_domain.cgi index fcccd74b4..c9592a570 100755 --- a/httemplate/view/svc_domain.cgi +++ b/httemplate/view/svc_domain.cgi @@ -36,9 +36,7 @@ <% include('elements/svc_export_settings.html', $svc_domain) %> -% if ( $conf->config('ticket_system') ) { <& /elements/table-tickets.html, object => $cust_svc &> -% } <% joblisting({'svcnum'=>$svcnum}, 1) %> diff --git a/httemplate/view/svc_external.cgi b/httemplate/view/svc_external.cgi index 72e553598..077dc77b7 100644 --- a/httemplate/view/svc_external.cgi +++ b/httemplate/view/svc_external.cgi @@ -24,9 +24,7 @@ </TABLE></TD></TR></TABLE> -% if ( $conf->config('ticket_system') ) { <& /elements/table-tickets.html, object => $cust_svc &> -% } <BR><% joblisting({'svcnum'=>$svcnum}, 1) %> diff --git a/httemplate/view/svc_forward.cgi b/httemplate/view/svc_forward.cgi index 2cb78ebd5..75c8f5c25 100755 --- a/httemplate/view/svc_forward.cgi +++ b/httemplate/view/svc_forward.cgi @@ -53,9 +53,7 @@ <% include('elements/svc_export_settings.html', $svc_forward) %> -% if ( $conf->config('ticket_system') ) { <& /elements/table-tickets.html, object => $cust_svc &> -% } <% joblisting({'svcnum'=>$svcnum}, 1) %> diff --git a/httemplate/view/svc_www.cgi b/httemplate/view/svc_www.cgi index fbb02a00f..f51c7604c 100644 --- a/httemplate/view/svc_www.cgi +++ b/httemplate/view/svc_www.cgi @@ -49,9 +49,7 @@ </TABLE> <BR> -% if ( $conf->config('ticket_system') ) { <& /elements/table-tickets.html, object => $cust_svc &> -% } <% joblisting({'svcnum'=>$svcnum}, 1) %> |