#!/usr/bin/perl
# tta_delgrpapps.cgi
# Delete OrgUnits from Tarantella Services

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

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

 $grpappsobjname=$in{grpappsobjname};
 print "<table width=100% border>\n";
 print "<tr $tb> <td><b>$text{'titidx_delgrpapps'} $grpappsobjname </b></td> </tr>\n";
 print "<tr $cb> <td><table width=100%>\n";
 print "<center>\n";

    if ($grpappsobjname ) {
        $descrip="";
        $ensgrpapps="";
        $dnsgrpapps="";
        foreach $grpapps (&list_grpapps()) {
             if ( $grpapps->{'alias'} eq $grpappsobjname) {
                $ensgrpapps=$grpapps->{ens};
                $dngrpapps=$grpapps->{obj};
                $descrip=$grpapps->{descrip};
                last;
             }
        }
    }
    if (!$dngrpapps ) { &footHere; exit }  ;
    $dn = "$dngrpapps,".$config{ldapcache_base};
    $ldapcache_server=1;
    &connect_cache ();
    if ( &del_cache_obj($dn) ne 0 ) { &footHere; exit }  ;
    if ( $config{ldapcache2_server}.length gt 0 ) {
             $ldapcache_server=2;
             &connect_cache ();
             if ( &del_cache_obj($dn) ne 0 ) { &err_replication() }
    }
    print "<tr></tr><tr></tr>\n";
    print "<tr><b>".$text{'user_delete'}."... LDAP CACHE ... </b></tr>\n";
    print "<tr><td><pre>\n";
    if ( $ensgrpapps ne "" ) {
         $ens_obj = "--name \"".$config{tta_ldapcacheApps}."/$ensgrpapps\" --children";
         $type_cmd="delete";
#        if (&run_tta_cmd("delete",$ens_obj)) { 
#             print "</pre><tr><p><b>$text{'user_delete'}... Tarantella </b></tr>\n";
              @listgrpapps=&list_grpapps();
              @list_grpapps = sort {$a->{'name'} cmp $b->{'name'}} @listgrpapps;
              &lock_file($config{'grpapps_list'});
	      open(FILEAPPS, ">$config{'grpapps_list'}");
                   foreach $grpapps (@list_grpapps) {
                       if ( $grpapps->{'alias'} ne $grpappsobjname) {
                            $lingrpapps=$grpapps->{'alias'}."::".$grpapps->{'name'}."::".$grpapps->{'obj'}."::".$grpapps->{'ens'}."::".$grpapps->{'descrip'}."\n";
                            print FILEAPPS "$lingrpapps";
                       }
                   }
               close (FILEAPPS);
               $str=$text{'user_delete'}.$grpappsobjname." ->  ".$;
               &additional_log('delgrpapps.cgi', undef, $str);
               &webmin_log($config{'grpapps_list'}, undef, "delete");
               &unlock_file($config{'grpapps_list'});
#        }
         print "</tr></td></pre>\n";
    }

 &footHere; 
 exit;
