#!/usr/bin/perl
# tta_deldomain.cgi
# Delete OrgUnits from Services with Tarantella
# STTA Rev. 1.3 Copyright (c) 2001-2002 Jesús Pérez Lorenzo  --- license GNU GPL 

require './stta-lib.pl';
do "ldap-lib.pl";

&headerstta($text{'index_deldomain'}, "", "deldomain",undef,1,1,$text{headpage_rigth} ); 
print "<hr><p>\n";
if ( $config{'is_ldapcache'} ne "true" ) { &footCacheHere; exit }
&foreign_require("proc", "proc-lib.pl");
$ldapcache_server=1;
&connect_cache();
&ReadParse();

 $domainname=$in{domainname};

    if ($domainname ) {
        $descrip="";
        $ensdomain="";
        $dnsdomain="";
        %h_domains=&list_domains();
        if ( $h_domains{$domainname}->{'alias'} ne $domainname) {
             $err_msg=$domainname.":".$text{'list_errno'};
             &footHere;
             exit;
        }
        $ensdomain=$h_domains{$domainname}->{ens};
        $dndomain=$h_domains{$domainname}->{obj};
        $obj_name=$h_domains{$domainname}->{name};
        $descrip=$h_domains{$domainname}->{descrip};
    }
    print "<table width=100% border>\n";
    print "<tr $tb> <td><b>$text{'titidx_deldomain'} $domainname - $obj_name </b></td> </tr>\n";
    print "<tr $cb> <td><table width=100%>\n";
    print "<center>\n";
    if (!$dndomain ) { &footHere; exit }  ;
    print "<tr></tr><tr></tr>\n";
    print "<tr><td><pre>\n";
    if (!$ensdomain ) { &footHere; exit }  ;
         $ens_obj = "--name \"".$config{tta_ldapcacheApps}."/$ensdomain\" --children";
         $type_cmd="delete";
#        if (&run_tta_cmd("delete",$ens_obj)) { 
#             print "</pre><tr><p><b>$text{'user_delete'}... Tarantella </b></tr>\n";
              &webmin_log($config{'domain_list'}, "domain", "delete",$h_domains{$domainname});
              delete $h_domains{$domainname};
              foreach $item (keys (%h_domains)) { push (@listdomains,$h_domains{$item}); }
              @list__domains = sort {$a->{name} cmp $b->{name}} @listdomains;
              &lock_file($config{'domain_list'});
	      open(FILEDOMAINS, ">$config{'domain_list'}");
                   foreach $domain (@list__domains) {
                            $lindomain=$domain->{'alias'}."::".$domain->{'name'}."::".$domain->{'obj'}."::".$domain->{'ens'}."::".$domain->{'maxsess'}."::".$domain->{'descrip'}."::\n";
                            print FILEDOMAINS "$lindomain\n";
                   }
               close (FILEDOMAINS);
               &unlock_file($config{'domain_list'});
               $str=$text{'user_delete'}.$domainname;
               &additional_log('deldomains.cgi', "domain", $str);
               &webmin_log($config{'domain_list'}, "domain", "delete");
               if ( $config{'is_ldapcache'} eq "true" ) {
                    $dn = "$dndomain,".$config{ldapcache_base};
                    if ( &del_ldap_obj($dn) eq 0 ) {
                         print "<tr><b>".$text{'user_delete'}."... LDAP CACHE ... </b></tr>\n";              
                    } else { &html_errshow("ldap")};
               }
         print "</tr></td></pre>\n";
#   } else { &html_errshow("tta")};
 print "<tr><tr></table></table><hr><p>\n";
 &footer($config{'back_return'},$text{'index'});
 print "<p><p><p>\n";
 do "footer.pl";
