#!/usr/bin/perl
# addusr.cgi
# ...  Servicios de Tarantella.

 require './tarantella-lib.pl';
&foreign_require("proc", "proc-lib.pl");
do "ldap-lib.pl";

&header($text{'index_addusr'}, "", "");
&connect ();
&ReadParse();

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

  $username=$in{username};

 if ($username)  {
    $organizationname="";
    $dn_ou="";
    foreach $ou (&list_ous()) {
         if ( $ou->{'alias'} eq $in{userou}) {
            $dn_ou=$ou->{obj};
            $organizationname=$ou->{name};
            break;
         }
    }
    $password=$in{password};
    $dn = "cn=$username,$dn_ou,".$config{ldap_base};
    $entry = $conn->newEntry ();
    $entry->setDN ($dn);
    $entry->{objectclass} =
          ["top", "person", "organizationalperson", "inetorgperson"];
    $entry->{userpassword} = [$password];
    $entry->{organizationname} = [$organizationname];
    $entry->{sn} = [$username];
    $entry->{cn} = [$username];
    $conn->add ($entry);
    if ($err = $conn->getErrorCode ()) {
	print "<hr>\n";
        print "<b> add ($dn): $err:".$conn->getErrorString ()."</b>\n";
	print "<hr>\n";
    } 
    else {
       print "<tr></tr>\n";
       print "<tr><b>".$text{'user_made'}.$username." ->  ".$in{userou}."</b></tr>\n";
       print "<tr><form METHOD=POST name=addusr ACTION=\"tta_modusr.cgi\" >\n"; 
       print "  <input TYPE=\"hidden\" NAME=\"username\" VALUE=\"",$username,"\"\n";
       print "  <input TYPE=\"hidden\" NAME=\"userou\" VALUE=\"",$in{userou},"\">\n";
       print "  <input TYPE=\"hidden\" NAME=\"administrador\" VALUE=\"",$in{administrador},"\">\n";
       print "  <input TYPE=\"hidden\" NAME=\"dn\" VALUE=\"",$dn,"\">\n";
       print "  <input TYPE=\"hidden\" NAME=\"passwdcache\" VALUE=\"",$in{passwdcache},"\">\n";
       print "        <tr><td valign=top><input TYPE=\"submit\" NAME=\"",$text{'f_modatt'},"\" VALUE=\"",$text{'f_modatt'},"\">\n";
       print "        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\n";
       print "	</form>\n"; 
    }
 }
 print "<tr><tr></table></table><hr><p>\n";
 &footer($config{'back_return'},$text{'index'});
 print "<p><p><p>\n";
 do "footer.pl";
 exit;
