import torrus 1.0.9
[freeside.git] / httemplate / edit / process / domreg.cgi
1 %if ($error) {
2 %  $cgi->param('error', $error);
3 %    errorpage($error);
4 %} else {
5 <% $cgi->redirect(popurl(3). "view/svc_domain.cgi?$svcnum") %>
6 %}
7 <%init>
8
9 die "access denied"
10   unless $FS::CurrentUser::CurrentUser->access_right('Provision customer service'); #something else more specific?
11
12 $cgi->param('op') =~ /^(register|transfer|revoke|renew)$/ or die "Illegal operation";
13 my $operation = $1;
14 #my($query) = $cgi->keywords;
15 #$query =~ /^(\d+)$/;
16 $cgi->param('svcnum') =~ /^(\d*)$/ or die "Illegal svcnum!";
17 my $svcnum = $1;
18 my $svc_domain = qsearchs({
19   'select'    => 'svc_domain.*',
20   'table'     => 'svc_domain',
21   'addl_from' => ' LEFT JOIN cust_svc  USING ( svcnum  ) '.
22                  ' LEFT JOIN cust_pkg  USING ( pkgnum  ) '.
23                  ' LEFT JOIN cust_main USING ( custnum ) ',
24   'hashref'   => {'svcnum'=>$svcnum},
25   'extra_sql' => ' AND '. $FS::CurrentUser::CurrentUser->agentnums_sql,
26 });
27 die "Unknown svcnum" unless $svc_domain;
28
29 my $cust_svc = qsearchs('cust_svc',{'svcnum'=>$svcnum});
30 my $part_svc = qsearchs('part_svc',{'svcpart'=> $cust_svc->svcpart } );
31 die "Unknown svcpart" unless $part_svc;
32
33 my $error = '';
34
35 my @exports = $part_svc->part_export();
36
37 my $registrar;
38 my $export;
39
40 # Find the first export that does domain registration
41 foreach (@exports) {
42         $export = $_ if $_->can('registrar');
43 }
44
45 my $period = 1; # Current OpenSRS export can only handle 1 year registrations
46
47 # If we have a domain registration export, get the registrar object
48 if ($export) {
49         if ($operation eq 'register') {
50                 $error = $export->register( $svc_domain, $period );
51         } elsif ($operation eq 'transfer') {
52                 $error = $export->transfer( $svc_domain );
53         } elsif ($operation eq 'revoke') {
54                 $error = $export->revoke( $svc_domain );
55         } elsif ($operation eq 'renew') {
56                 $cgi->param('period') =~ /^(\d+)$/ or die "Illegal renewal period!";
57                 $period = $1;
58                 $error = $export->renew( $svc_domain, $period );
59         }
60 }
61
62 </%init>