% my $conf = new FS::Conf; my $mydomain = $conf->config('domain'); my($svcnum, $pkgnum, $svcpart, $part_svc, $svc_acct_sm ); if ( $cgi->param('error') ) { $svc_acct_sm = new FS::svc_acct_sm ( { map { $_, scalar($cgi->param($_)) } fields('svc_acct_sm') } ); $svcnum = $svc_acct_sm->svcnum; $pkgnum = $cgi->param('pkgnum'); $svcpart = $cgi->param('svcpart'); #$part_svc=qsearchs('part_svc',{'svcpart'=>$svcpart}); #die "No part_svc entry!" unless $part_svc; } else { my($query) = $cgi->keywords; if ( $query =~ /^(\d+)$/ ) { #editing $svcnum=$1; $svc_acct_sm=qsearchs('svc_acct_sm',{'svcnum'=>$svcnum}) or die "Unknown (svc_acct_sm) svcnum!"; my($cust_svc)=qsearchs('cust_svc',{'svcnum'=>$svcnum}) or die "Unknown (cust_svc) svcnum!"; $pkgnum=$cust_svc->pkgnum; $svcpart=$cust_svc->svcpart; #$part_svc=qsearchs('part_svc',{'svcpart'=>$svcpart}); #die "No part_svc entry!" unless $part_svc; } else { #adding $svc_acct_sm = new FS::svc_acct_sm({}); foreach $_ (split(/-/,$query)) { #get & untaint pkgnum & svcpart $pkgnum=$1 if /^pkgnum(\d+)$/; $svcpart=$1 if /^svcpart(\d+)$/; } my $part_svc=qsearchs('part_svc',{'svcpart'=>$svcpart}); die "No part_svc entry!" unless $part_svc; $svcnum=''; #set fixed and default fields from part_svc foreach my $part_svc_column ( grep { $_->columnflag } $part_svc->all_part_svc_column ) { $svc_acct_sm->setfield( $part_svc_column->columnname, $part_svc_column->columnvalue, ); } } } my $action = $svc_acct_sm->svcnum ? 'Edit' : 'Add'; my %username = (); my %domain = (); if ($pkgnum) { #find all possible uids (and usernames) my @u_acct_svcparts = (); foreach my $u_part_svc ( qsearch('part_svc',{'svcdb'=>'svc_acct'}) ) { push @u_acct_svcparts,$u_part_svc->getfield('svcpart'); } my($cust_pkg)=qsearchs('cust_pkg',{'pkgnum'=>$pkgnum}); my($custnum)=$cust_pkg->getfield('custnum'); foreach my $i_cust_pkg ( qsearch('cust_pkg',{'custnum'=>$custnum}) ) { my($cust_pkgnum)=$i_cust_pkg->getfield('pkgnum'); my($acct_svcpart); foreach $acct_svcpart (@u_acct_svcparts) { #now find the corresponding #record(s) in cust_svc ( for this #pkgnum ! ) my($i_cust_svc); foreach $i_cust_svc ( qsearch('cust_svc',{'pkgnum'=>$cust_pkgnum,'svcpart'=>$acct_svcpart}) ) { my($svc_acct)=qsearchs('svc_acct',{'svcnum'=>$i_cust_svc->getfield('svcnum')}); $username{$svc_acct->getfield('uid')}=$svc_acct->getfield('username'); } } } #find all possible domains (and domsvc's) my @d_acct_svcparts = (); foreach my $d_part_svc ( qsearch('part_svc',{'svcdb'=>'svc_domain'}) ) { push @d_acct_svcparts,$d_part_svc->getfield('svcpart'); } foreach $i_cust_pkg ( qsearch('cust_pkg',{'custnum'=>$custnum}) ) { my($cust_pkgnum)=$i_cust_pkg->getfield('pkgnum'); my($acct_svcpart); foreach $acct_svcpart (@d_acct_svcparts) { my($i_cust_svc); foreach $i_cust_svc ( qsearch('cust_svc',{'pkgnum'=>$cust_pkgnum,'svcpart'=>$acct_svcpart}) ) { my($svc_domain)=qsearch('svc_domain',{'svcnum'=>$i_cust_svc->getfield('svcnum')}); $domain{$svc_domain->getfield('svcnum')}=$svc_domain->getfield('domain'); } } } } elsif ( $action eq 'Edit' ) { my($svc_acct)=qsearchs('svc_acct',{'uid'=>$svc_acct_sm->domuid}); $username{$svc_acct_sm->uid} = $svc_acct->username; my($svc_domain)=qsearchs('svc_domain',{'svcnum'=>$svc_acct_sm->domsvc}); $domain{$svc_acct_sm->domsvc} = $svc_domain->domain; } else { die "\$action eq Add, but \$pkgnum is null!\n"; } my $p1 = popurl(1); print header("Mail Alias $action", ''); print qq!Error: !, $cgi->param('error'), "" if $cgi->param('error'); print qq!