a9fc775ee6f8b30da1b7e7be9120840c94a4d364
[freeside.git] / httemplate / view / svc_domain.cgi
1 <% include("/elements/header.html",'Domain View', menubar(
2   ( ( $pkgnum || $custnum )
3     ? ( "View this customer (#$display_custnum)" => "${p}view/cust_main.cgi?$custnum",
4       )
5     : ( "Delete this (unaudited) domain" =>
6           "javascript:areyousure('${p}misc/cancel-unaudited.cgi?$svcnum', 'Delete $domain and all records?' )" )
7   )
8 )) %>
9
10 <% include('/elements/error.html') %>
11
12 Service #<% $svcnum %>
13 <BR>Service: <B><% $part_svc->svc %></B>
14 <BR>Domain name: <B><% $domain %></B>
15 % if ($export) {
16 <BR>Status: <B><% $status %></B>
17 %   if ( $FS::CurrentUser::CurrentUser->access_right('Manage domain registration') ) {
18 %     if ( defined($ops{'register'}) ) {
19     <A HREF="<% ${p} %>edit/process/domreg.cgi?op=register&svcnum=<% $svcnum %>">Register at <% $registrar->{'name'} %></A>&nbsp;
20 %     }
21 %     if ( defined($ops{'transfer'}) ) {
22     <A HREF="<% ${p} %>edit/process/domreg.cgi?op=transfer&svcnum=<% $svcnum %>">Transfer to <% $registrar->{'name'} %></A>&nbsp;
23 %     }
24 %     if ( defined($ops{'renew'}) ) {
25     <A HREF="<% ${p} %>edit/process/domreg.cgi?op=renew&svcnum=<% $svcnum %>&period=1">Renew at <% $registrar->{'name'} %></A>&nbsp;
26 %     }
27 %     if ( defined($ops{'revoke'}) ) {
28     <A HREF="<% ${p} %>edit/process/domreg.cgi?op=revoke&svcnum=<% $svcnum %>">Revoke</A>
29 %     }
30 %   }
31 % }
32
33 % if ( $FS::CurrentUser::CurrentUser->access_right('Edit domain catchall') ) {
34     <BR>Catch all email <A HREF="<% ${p} %>misc/catchall.cgi?<% $svcnum %>">(change)</A>:
35 % } else {
36     <BR>Catch all email:
37 % }
38
39 <% $email ? "<B>$email</B>" : "<I>(none)<I>" %>
40 <BR><BR><A HREF="<% ${p} %>misc/whois.cgi?custnum=<%$custnum%>;svcnum=<%$svcnum%>;domain=<%$domain%>">View whois information.</A>
41 <BR><BR>
42 <SCRIPT>
43   function areyousure(href, message) {
44     if ( confirm(message) == true )
45       window.location.href = href;
46   }
47   function slave_areyousure() {
48     return confirm("Remove all records and slave from " + document.SlaveForm.recdata.value + "?");
49   }
50 </SCRIPT>
51
52 % my @records; if ( @records = $svc_domain->domain_record ) { 
53
54   <% include('/elements/table-grid.html') %>
55
56 % my $bgcolor1 = '#eeeeee';
57 %     my $bgcolor2 = '#ffffff';
58 %     my $bgcolor = $bgcolor2;
59
60   <tr>
61     <th CLASS="grid" BGCOLOR="#cccccc">Zone</th>
62     <th CLASS="grid" BGCOLOR="#cccccc">Type</th>
63     <th CLASS="grid" BGCOLOR="#cccccc">Data</th>
64   </tr>
65
66 % foreach my $domain_record ( @records ) {
67 %       my $type = $domain_record->rectype eq '_mstr'
68 %                    ? "(slave)"
69 %                    : $domain_record->recaf. ' '. $domain_record->rectype;
70
71
72     <tr>
73       <td CLASS="grid" BGCOLOR="<% $bgcolor %>"><% $domain_record->reczone %></td>
74       <td CLASS="grid" BGCOLOR="<% $bgcolor %>"><% $type %></td>
75       <td CLASS="grid" BGCOLOR="<% $bgcolor %>"><% $domain_record->recdata %>
76
77 % unless ( $domain_record->rectype eq 'SOA'
78 %          || ! $FS::CurrentUser::CurrentUser->access_right('Edit domain nameservice')
79 %        ) { 
80 %   ( my $recdata = $domain_record->recdata ) =~ s/"/\\'\\'/g;
81       (<A HREF="javascript:areyousure('<%$p%>misc/delete-domain_record.cgi?<%$domain_record->recnum%>', 'Delete \'<% $domain_record->reczone %> <% $type %> <% $recdata %>\' ?' )">delete</A>)
82 % } 
83       </td>
84     </tr>
85
86
87 %   if ( $bgcolor eq $bgcolor1 ) {
88 %      $bgcolor = $bgcolor2;
89 %    } else {
90 %      $bgcolor = $bgcolor1;
91 %    }
92
93 % } 
94
95   </table>
96 % } 
97
98 % if ( $FS::CurrentUser::CurrentUser->access_right('Edit domain nameservice') ) {
99     <BR>
100     <FORM METHOD="POST" ACTION="<%$p%>edit/process/domain_record.cgi">
101       <INPUT TYPE="hidden" NAME="svcnum" VALUE="<%$svcnum%>">
102       <INPUT TYPE="text" NAME="reczone"> 
103       <INPUT TYPE="hidden" NAME="recaf" VALUE="IN"> IN 
104       <SELECT NAME="rectype">
105 %       foreach (qw( A NS CNAME MX PTR TXT) ) { 
106           <OPTION VALUE="<%$_%>"><%$_%></OPTION>
107 %       } 
108       </SELECT>
109       <INPUT TYPE="text" NAME="recdata">
110       <INPUT TYPE="submit" VALUE="Add record">
111     </FORM>
112
113     <BR><BR>
114     or
115     <BR><BR>
116
117     <FORM NAME="SlaveForm" METHOD="POST" ACTION="<%$p%>edit/process/domain_record.cgi">
118       <INPUT TYPE="hidden" NAME="svcnum" VALUE="<%$svcnum%>">
119 %     if ( @records ) { 
120          Delete all records and 
121 %     } 
122       Slave from nameserver IP 
123       <INPUT TYPE="hidden" NAME="svcnum" VALUE="<%$svcnum%>">
124       <INPUT TYPE="hidden" NAME="reczone" VALUE="@"> 
125       <INPUT TYPE="hidden" NAME="recaf" VALUE="IN">
126       <INPUT TYPE="hidden" NAME="rectype" VALUE="_mstr">
127       <INPUT TYPE="text" NAME="recdata">
128       <INPUT TYPE="submit" VALUE="Slave domain" onClick="return slave_areyousure()">
129     </FORM>
130
131 % }
132
133 <BR><BR>
134
135 <% joblisting({'svcnum'=>$svcnum}, 1) %>
136
137 <% include('/elements/footer.html') %>
138 <%init>
139
140 die "access denied"
141   unless $FS::CurrentUser::CurrentUser->access_right('View customer services');
142
143 my($query) = $cgi->keywords;
144 $query =~ /^(\d+)$/;
145 my $svcnum = $1;
146 my $svc_domain = qsearchs({
147   'select'    => 'svc_domain.*',
148   'table'     => 'svc_domain',
149   'addl_from' => ' LEFT JOIN cust_svc  USING ( svcnum  ) '.
150                  ' LEFT JOIN cust_pkg  USING ( pkgnum  ) '.
151                  ' LEFT JOIN cust_main USING ( custnum ) ',
152   'hashref'   => {'svcnum'=>$svcnum},
153   'extra_sql' => ' AND '. $FS::CurrentUser::CurrentUser->agentnums_sql(
154                             'null_right' => 'View/link unlinked services'
155                           ),
156 });
157 die "Unknown svcnum" unless $svc_domain;
158
159 my $cust_svc = qsearchs('cust_svc',{'svcnum'=>$svcnum});
160 my $pkgnum = $cust_svc->getfield('pkgnum');
161 my($cust_pkg, $custnum, $display_custnum);
162 if ($pkgnum) {
163   $cust_pkg = qsearchs('cust_pkg', {'pkgnum'=>$pkgnum} );
164   $custnum = $cust_pkg->custnum;
165   $display_custnum = $cust_pkg->cust_main->display_custnum;
166 } else {
167   $cust_pkg = '';
168   $custnum = '';
169 }
170
171 my $part_svc = qsearchs('part_svc',{'svcpart'=> $cust_svc->svcpart } );
172 die "Unknown svcpart" unless $part_svc;
173
174 my $email = '';
175 if ($svc_domain->catchall) {
176   my $svc_acct = qsearchs('svc_acct',{'svcnum'=> $svc_domain->catchall } );
177   die "Unknown svcpart" unless $svc_acct;
178   $email = $svc_acct->email;
179 }
180
181 my $domain = $svc_domain->domain;
182
183 my $status = 'Unknown';
184 my %ops = ();
185
186 my @exports = $part_svc->part_export();
187
188 my $registrar;
189 my $export;
190
191 # Find the first export that does domain registration
192 foreach (@exports) {
193         $export = $_ if $_->can('registrar');
194 }
195 # If we have a domain registration export, get the registrar object
196 if ($export) {
197         $registrar = $export->registrar;
198         my $domstat = $export->get_status( $svc_domain );
199         if (defined($domstat->{'message'})) {
200                 $status = $domstat->{'message'};
201         } elsif (defined($domstat->{'unregistered'})) {
202                 $status = 'Not registered';
203                 $ops{'register'} = "Register";
204         } elsif (defined($domstat->{'status'})) {
205                 $status = $domstat->{'status'} . ' ' . $domstat->{'contact_email'} . ' ' . $domstat->{'last_update_time'};
206         } elsif (defined($domstat->{'expdate'})) {
207                 $status = "Expires " . $domstat->{'expdate'};
208                 $ops{'renew'} = "Renew";
209                 $ops{'revoke'} = "Revoke";
210         } else {
211                 $status = $domstat->{'reason'};
212                 $ops{'transfer'} = "Transfer";
213         }
214 }
215
216 </%init>