#!/usr/bin/perl
# tta_dellink.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_dellink'}, "", "dellink",undef,1,1,$text{headpage_rigth} ); 
print "<hr><p>\n";
&foreign_require("proc", "proc-lib.pl");
#$ldapcache_server=1;
#&connect_cache();
&ReadParse();

 $linkname=$in{linkname};

    if ($linkname ) {
        $descrip="";
        $enslink="";
        $dnslink="";
        %h_links=&list_links();
        if ( $h_links{$linkname}->{'alias'} ne $linkname) {
             $err_msg=$linkname.":".$text{'list_errno'};
             &footHere;
             exit;
        }
        $enslink=$h_links{$linkname}->{ens};
        $dnlink=$h_links{$linkname}->{obj};
        $obj_name=$h_links{$linkname}->{name};
        $descrip=$h_links{$linkname}->{descrip};
    }
    print "<table width=100% border>\n";
    print "<tr $tb> <td><b>$text{'titidx_dellink'} $linkname - $obj_name </b></td> </tr>\n";
    print "<tr $cb> <td><table width=100%>\n";
    print "<center>\n";
    if (!$dnlink ) { &footHere; exit }  ;
    print "<tr></tr><tr></tr>\n";
    print "<tr><td><pre>\n";
    if (!$enslink ) { &footHere; exit }  ;
#        $ens_obj = "--name \"".$config{tta_ldapcacheApps}."/$enslink\" --children";
        $ens_obj = "--name \"".$config{tta_ldapcacheApps}."/$enslink\" ";
       print " $ens_obj<br>";
        $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{'link_list'}, "link", "delete",$h_links{$linkname});
              delete $h_links{$linkname};
              foreach $item (keys (%h_links)) { push (@listlinks,$h_links{$item}); }
              @list__links = sort {$a->{name} cmp $b->{name}} @listlinks;
              &lock_file($config{'link_list'});
	      open(FILELINKS, ">$config{'link_list'}");
                   foreach $link (@list__links) {
                            $linlink=$link->{'alias'}."::".$link->{'name'}."::".$link->{'obj'}."::".$link->{'ens'}."::".$link->{'maxsess'}."::".$link->{'descrip'}."::\n";
                            print FILELINKS "$linlink";
                   }
               close (FILELINKS);
               &unlock_file($config{'link_list'});
               $str=$text{'user_delete'}.$linkname;
               &additional_log('dellinks.cgi', "link", $str);
               &webmin_log($config{'link_list'}, "link", "delete");
               print "<tr><b>".$str."... </b></tr>\n";              
#               if ( $config{'is_ldapcache'} eq "true" ) {
#                    $dn = "$dnlink,".$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";
