#!/usr/bin/perl
# tta_delgrpapps.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_delgrpapps'}, "", "delgrpapps",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();

 $grpappsobjname=$in{grpappsobjname};

    if ($grpappsobjname ) {
        $descrip="";
        $ensgrpapps="";
        $dnsgrpapps="";
        $obj_name="";
        %h_grpapps=&list_grpapps();
        if ( $h_grpapps{$grpappsobjname}->{'alias'} ne $grpappsobjname) {
             $err_msg=$grpappsobjname.":".$text{'list_errno'};
             &footHere;
             exit;
        }
        $ensgrpapps=$h_grpapps{$grpappsobjname}->{ens};
        $dngrpapps=$h_grpapps{$grpappsobjname}->{obj};
        $descrip=$h_grpapps{$grpappsobjname}->{descrip};
        $obj_name=$h_grpapps{$grpappsobjname}->{name};
    }
    print "<table width=100% border>\n";
    print "<tr $tb> <td><b>$text{'titidx_delgrpapps'} $grpappsobjname - $obj_name</b></td> </tr>\n";
    print "<tr $cb> <td><table width=100%>\n";
    print "<center>\n";
    if (!$dngrpapps ) { &footHere; exit }  ;
    print "<tr></tr><tr></tr>\n";
    print "<tr><td><pre>\n";
    if (!$ensgrpapps ) { &footHere; exit }  ;
        $ens_obj = "--name \"".$config{tta_base}."/$ensgrpapps\" --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{'grpapps_list'}, "grpapps", "delete",$h_grpapps{$grpappsobjname});
              delete $h_grpapps{$grpappsobjname};
              foreach $item (keys (%h_grpapps)) { push (@listgrpapps,$h_grpapps{$item}); }
              @list_grpapps = sort {$a->{'name'} cmp $b->{'name'}} @listgrpapps;
              &lock_file($config{'grpapps_list'});
	      open(FILEGRPAPPS, ">$config{'grpapps_list'}");
                   foreach $grpapps (@list_grpapps) {
                       if ( $grpapps->{'alias'} ne $grpappsobjname) {
                            $lingrpapps=$grpapps->{'alias'}."::".$grpapps->{'name'}."::".$grpapps->{'obj'}."::".$grpapps->{'ens'}."::".$grpapps->{'maxsess'}."::".$grpapps->{'descrip'}."::\n";
                            print FILEGRPAPPS "$lingrpapps";
                       }
                   }
               close (FILEGRPAPPS);
               &unlock_file($config{'grpapps_list'});
               $str=$text{'user_delete'}.$grpappsobjname;
               &additional_log('delgrpapps.cgi', "grpapps", $str);
               &webmin_log($config{'grpapps_list'}, "grpapps", "delete");
               %h_apps=&list_apps();
               foreach $item (keys (%h_apps)) { push (@listapps,$h_apps{$item}); }
               @list__apps = sort {$a->{'name'} cmp $b->{'name'}} @listapps;
               &lock_file($config{'app_list'});
               open(FILEAPPS, ">$config{'app_list'}");
                   foreach $app (@list__apps) {
                       if ( $app->{'grpalias'} ne $grpappsobjname) {
                            $linapp=$app->{'alias'}."::".$app->{'name'}."::".
                                    $app->{'grpalias'}."::".$app->{'obj'}."::".
                                    $app->{'ens'}."::".$app->{'maxsess'}."::".
                                    $app->{'descrip'}."::\n";
                            print FILEAPPS "$linapp";
                       } else {
                          &webmin_log($config{'app_list'}, "apps", "delete grpapps",@app);
                       }
                   }
               close (FILEAPPS);
               &unlock_file($config{'app_list'});
               $str=$text{'user_delete'}.$appname;
               &additional_log('delapps.cgi', "app", $str);
               &webmin_log($config{'app_list'}, "app", "delete grpapps");
               if ( $config{'is_ldapcache'} eq "true" ) {
                    $dn = "$dngrpapps,".$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")};
               }
        } else { &html_errshow("tta")};
 print "</tr></td></pre>\n";
 print "<tr><tr></table></table><hr><p>\n";
 &footer($config{'back_return'},$text{'index'});
 print "<p><p><p>\n";
 do "footer.pl";
 exit;
