X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=httemplate%2Fmisc%2Fprocess%2Flink.cgi;h=77546f3f7102049733294d1f2249183a313c692a;hb=3a02c437eadd9a39f7e56056ca987a4846650209;hp=acdd1ad031cf32ba8010edc3008d3cbe63228bb7;hpb=f7fd2a3e34da751cbc02bbf215e99c6dc89adc15;p=freeside.git diff --git a/httemplate/misc/process/link.cgi b/httemplate/misc/process/link.cgi index acdd1ad03..77546f3f7 100755 --- a/httemplate/misc/process/link.cgi +++ b/httemplate/misc/process/link.cgi @@ -1,4 +1,22 @@ -<% +%unless ($error) { +% #no errors, so let's view this customer. +% my $custnum = $new->cust_pkg->custnum; +% my $show = $curuser->default_customer_view =~ /^(jumbo|packages)$/ +% ? '' +% : ';show=packages'; +% my $frag = "cust_pkg$pkgnum"; #hack for IE ignoring real #fragment +<% $cgi->redirect(popurl(3). "view/cust_main.cgi?custnum=$custnum$show;fragment=$frag#$frag" ) %> +%} else { +% errorpage($error); +%} +<%init> + +my $curuser = $FS::CurrentUser::CurrentUser; + +die "access denied" + unless $curuser->access_right('View/link unlinked services'); + +my $DEBUG = 0; $cgi->param('pkgnum') =~ /^(\d+)$/; my $pkgnum = $1; @@ -16,14 +34,31 @@ unless ( $svcnum ) { if ( $cgi->param('link_field2') =~ /^(\w+)$/ ) { $search{$1} = $cgi->param('link_value2'); } - my $svc_x = ( sort { ($b->cust_svc->pkgnum > 0) <=> ($a->cust_svc->pkgnum > 0) + + my @svc_x = ( sort { ($a->cust_svc->pkgnum > 0) <=> ($b->cust_svc->pkgnum > 0) or ($b->cust_svc->svcpart == $svcpart) <=> ($a->cust_svc->svcpart == $svcpart) } qsearch( $svcdb, \%search ) - )[0]; - eidiot("$link_field not found!") unless $svc_x; + ); + + if ( $DEBUG ) { + warn scalar(@svc_x). " candidate accounts found for linking ". + "(svcpart $svcpart):\n"; + foreach my $svc_x ( @svc_x ) { + warn " ". $svc_x->email. + " (svcnum ". $svc_x->svcnum. ",". + " pkgnum ". $svc_x->cust_svc->pkgnum. ",". + " svcpart ". $svc_x->cust_svc->svcpart. ")\n"; + } + } + + my $svc_x = $svc_x[0]; + + errorpage("$link_field not found!") unless $svc_x; + $svcnum = $svc_x->svcnum; + } my $old = qsearchs('cust_svc',{'svcnum'=>$svcnum}); @@ -33,25 +68,11 @@ my($error, $new); if ( $old->pkgnum && ! $conf->exists('legacy_link-steal') ) { $error = "svcnum $svcnum already linked to package ". $old->pkgnum; } else { - $new = new FS::cust_svc ({ - 'svcnum' => $svcnum, - 'pkgnum' => $pkgnum, - 'svcpart' => $svcpart, - }); + $new = new FS::cust_svc { $old->hash }; + $new->pkgnum($pkgnum); + $new->svcpart($svcpart); $error = $new->replace($old); } -unless ($error) { - #no errors, so let's view this customer. - my $custnum = $new->cust_pkg->custnum; - print $cgi->redirect(popurl(3). "view/cust_main.cgi?$custnum". - "#cust_pkg$pkgnum" ); -} else { -%> - -<% - idiot($error); -} - -%> +