#!/usr/bin/perl
# tta_delou.cgi
# Delete OrgUnits from STTA
# STTA Rev. 1.3 Copyright (c) 2001-2004 Jesús Pérez Lorenzo  --- license GNU GPL 
# stta: (@#) 1.31051043346- [2004_01_29_102036]

 require './stta-lib.pl';
&foreign_require("proc", "proc-lib.pl");
if ( $config{'has_ldapusers'} eq "true" || $config{'is_ldapcache'} eq "true" ) {
     do "ldap-lib.pl";
}
&ReadParse();

 $userou=$in{userou};
 &headerstta($text{'index_delou'}, "", "delou",undef,1,0,"$text{'headpage_right'}"."$text{'head_logout'}",undef,undef,"$text{head_below}" ); 
 print "<hr><p>\n"; 
 print "<table width=100% border>\n";
 print "<tr $tb> <td><font color='$revtext'><b>$text{'titidx_delou'} $userou </b></td> </tr>\n";
 print "<tr $cb> <td><table width=100%>\n";
 print "<center>\n";

 if ( !$userou ) {  &footHere; exit }
 %h_ou=&list_ous();
 if ( $h_ou{$userou}->{'alias'} ne $userou ) {
         $err_msg=$text{'list_errno'};
         &footHere;
         exit;
 }
 $dn_ou=$h_ou{$userou}->{'obj'};
 $organizationname=$h_ou{$userou}->{'name'};
 $ens_ou=$h_ou{$userou}->{'ens'};
 if ( $dn_ou ne ""  && $config{'has_ldapusers'} eq "true" ) {
    $dn = "$dn_ou,".$config{ldap_base};
    $ldap_server=1;
    &connect ();
    if ( &del_ou() eq 0 ) { 
        if ( $config{ldap2_server}.length gt 0 ) {
             $ldap_server=2;
             &connect ();
             if ( &del_ou() ne 0 ) { &err_replication() }
        }
        print "<tr></tr><tr></tr>\n";
        print "<tr><b>".$text{'user_delete'}."... LDAP ... </b></tr>\n";
    } else { &html_errshow("ldap")};
  }
  if ( $ens_ou ne "" ) {
       print "<tr><td><pre>\n";
       $ens_obj = "--name \"".$config{tta_base}."/$ens_ou\" --children";
       $type_cmd="delete";
       if (&run_tta_cmd("delete",$ens_obj)) { 
                print "</pre><tr><p><b>$text{'user_delete'}... Tarantella </b></tr>\n";
       } else { &html_errshow("tta")};
       print "</tr></td></pre>\n";
       &out_objslist( "delete", "delou.cgi", "ou", "ou_list", $userou, "", \%h_ou );
       # Cleaning sysusers_list to delete users belonging to $userou  will be done also !!!
  }
  if ( $config{'is_ldapcache'} eq "true" ) { 
       $ldapcache_server=1;
       &connect_cache ();
       $dn = "$dn_ou,".$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><tr></table></table><hr><p>\n";
 &footer($config{'back_return'},$text{'index'});
 print "<p><p><p>\n";
 do "footer.pl";
 exit;
