#!/usr/bin/perl
# tta_modou.cgi
# Modify Tarantella Services OrgUnits

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

 $userou = $in{userou};
 $dn = $in{dn};
 if (!$userou) { &redirect("tta_selou.cgi?form=modou"); }
 $postform = $in{postform};
 $ttacmd="edit";
 # Cleaning and reset values ...
 $descrip="";
 $conntype="";
 $inherit="";
 $cdm="";
 $webtop="";
 &header($text{'index_moddou'}, "", "modou");
 print "<hr><p>\n"; 
 if ( $postform eq "tta_selou" ) {
    $ouname = $in{ouname};
    $userorg = $userou;
    $aliasou = $userou;
    foreach $ou (&list_ous()) {
         if ( $ou->{'alias'} eq $userou) {
            $dn_ou=$ou->{obj};
            $ouname=$ou->{name};
            $ens_ou=$ou->{ens};
            $organizationname=$ou->{name};
            last;
         }
    }
    $dn = "$dn_ou,".$config{ldap_base};
    $ens_obj = "\"".$config{tta_base}."/$ens_ou\"";
 } else {
    $ouname = $in{ouname};
    $userorg = $in{userorg};
    $aliasou = $in{aliasou};
    $organizationname="";
    $dn_ou="";
    $ens_ou="";
    foreach $ou (&list_ous()) {
         if ( $ou->{'alias'} eq $userou) {
            $dn_ou=$ou->{obj};
            $ens_ou=$ou->{ens};
            $organizationname=$ou->{name};
            last;
         }
     }
     $ens_obj = "\"".$config{tta_base}."/$ens_ou/ou=".$ouname."\"";
 }
 if ( $ouname ) {
      if ( $in{postform} ) {
           # loading object attributes ...
           $op="attributes";
           $type_cmd="attributes";
           $no_out=1;
           $status_cmd=&run_tta_cmd($type_cmd,$ens_obj);
           if ( !$status ) { $str_cmds="<tr><td> ".$text{'tta_noobject'}."</td></tr>";
       }
 } else {
      # loading object defaults ....
      $temp_f=$config{'tta_defaults_ou'}; 
 } 
 # Assigning and collecting values to be used in the form ...
 foreach $i (&load_ttaobj()) {
            if ( $i->{'property'} eq "description" ) { $descrip=$i->{'value'} };
            if ( $i->{'property'} eq "cdm" ) { $cdm=$i->{'value'} };
            if ( $i->{'property'} eq "inherit" ) { $inherit=$i->{'value'} };
            if ( $i->{'property'} eq "webtop" ) { $webtop=$i->{'value'} };
            if ( $i->{'property'} eq "conntype" ) { $conntype=$i->{'value'} };
 #      print "<p>(".$i->{'property'}.")-(".$i->{'value'}.")\n";
 }
 $temp_f="";
 print "<SCRIPT SRC=\"global.js\">\n"; 
 print "</SCRIPT>\n"; 
 print "<SCRIPT LANGUAGE=\"JavaScript\">\n"; 
 print "/*  Strings for locales  */\n"; 
 print "var msg0=\"".$text{'msg_0'},"\";\n";
 print "var msg1=\"".$text{'msg_1'},"\";\n";
 print "var msg2=\"".$text{'msg_2'},"\";\n";
 print "var msg3=\"".$text{'msg_3'},"\";\n";
 print "var msg4=\"".$text{'msg_4'},"\";\n";
 print "var msg5=\"".$text{'msg_5'},"\";\n";
 print "var msg6=\"".$text{'msg_6'},"\";\n";
 print "var msg7=\"".$text{'msg_7'},"\";\n";
 print "/******************************************************************\n"; 
 print "   showHelp(item)\n"; 
 print "*******************************************************************/\n"; 
 print "function showHelp(item) {\n"; 
 print "     var str=\"\";\n"; 
 print "     if ( item == \"conntype\" ) {\n"; 
 print "          window.open('/help.cgi/tarantella/conntype','help',",
                    "'toolbar=no,menubar=no,scrollbars=yes,width=400,height=300,resizable=yes')\n";
 print "     }\n"; 
 print "     if ( item == \"cdm\" ) {\n"; 
 print "          window.open('/help.cgi/tarantella/cdm','help',",
                    "'toolbar=no,menubar=no,scrollbars=yes,width=400,height=300,resizable=yes')\n";
 print "     }\n"; 
 print "}\n"; 
 print "/******************************************************************\n"; 
 print "   Chek_fields(obj)\n"; 
 print "*******************************************************************/\n"; 
 print "function Chek_fields(obj) {\n"; 
 print "     if ( get_value(\"select\",obj.webtop) == \"none\" ) {\n"; 
 print "          alert(obj.webtop.name+\":\"+msg1);\n"; 
 print "		    obj.webtop.focus();\n"; 
 print "          return false;\n"; 
 print "     }     \n"; 
 print "     nro=parseInt(obj.maxsess.value);\n";
 print "     if ( nro+1 > 0) { \n";
 print "          obj.maxsess.value=nro;\n";
 print "     } else {;\n";
 print "          alert(obj.maxsess.name+\":\"+msg1+\"->\"+obj.maxsess.value+\"<-\");\n";
 print "          obj.maxsess.focus();\n";
 print "          return false;\n";
 print "     };\n";
 print "     if ( obj.inherit.checked ) {\n"; 
 print "          obj.inherit.value=true; \n"; 
 print "     }\n"; 
 print "     else {\n"; 
 print "          obj.inherit.value=false; \n"; 
 print "     }\n"; 
 print "     return true;\n"; 
 print "}\n"; 
 print "//-->\n"; 
 print "</SCRIPT>\n"; 
 print "<table width=100% border>\n";
 if ( $ouname ) {
     print "<tr $tb> <td><b>".&text('titidx_modou',$organizationname)."</b></td> </tr>\n";
 }
 else {
     print "<tr $tb> <td><b>".$text{'titidx_modou0'}."</b></td> </tr>\n";
 }
 print $str_cmds."\n";  
 print "<tr $cb> <td><table width=100%>\n";
 print "<form METHOD=POST name=modou ACTION=\"modou.cgi\" onSubmit=\"return Chek_fields(this)\">\n"; 
 print "\n"; 
 if ( $ouname ) {
       print "	<input TYPE=\"hidden\" NAME=\"ouname\" VALUE=\"",$ouname,"\">\n"; 
       print "	<input TYPE=\"hidden\" NAME=\"userou\" VALUE=\"",$userou,"\">\n"; 
       print "	<input TYPE=\"hidden\" NAME=\"userorg\" VALUE=\"",$userou,"\">\n"; 
       print "	<input TYPE=\"hidden\" NAME=\"aliasou\" VALUE=\"",$aliasou,"\">\n"; 
       print "	<input TYPE=\"hidden\" NAME=\"dn\" VALUE=\"",$dn,"\">\n"; 
 } 
 else {
  print "	<tr><td valign=top>",&hlink("<b>$text{'f_ouname'}</b>","founame"),"&nbsp;",$ouname,"\n"; 
 print "        <td valign=top><input TYPE=\"text\" NAME=\"ouname\" VALUE=\"\" cols=\"22\" size=\"12\" ALIGN=left></td></tr>\n";
  }
 print "	<input TYPE=\"hidden\" NAME=\"ttacmd\" VALUE=\"",$ttacmd,"\">\n"; 
 print "	<tr><td valign=top>",&hlink("<b>$text{'f_descrip'}</b>","fdescrip"),"</td>\n"; 
 print "	<td valign=top><input TYPE=\"text\" NAME=\"descrip\" VALUE=\"$descrip\" cols=\"40\" size=\"40\" ALIGN=left></td></tr>\n"; 
 print "   <tr><td valign=top>",&hlink("<b>$text{'f_webtop'}</b>","fwebtop"),"&nbsp;<td valign=top><select NAME=\"webtop\">\n"; 

$nItems=0;
foreach $item (&list_webtops()) {
     if ( $item->{'obj'} eq $webtop ) {
          print " <option VALUE=\"".$item->{'alias'}."\" selected>". $item->{'name'}."\n";
    }
     else {
          print " <option VALUE=\"".$item->{'alias'}."\" >".$item->{'name'}."  ";
     }
     $nItems++;
}
 print "	</select></td></tr>\n"; 
 print "	<tr><td valign=top>",&hlink("<b>$text{'f_inherit'}</b>","finherit"),"&nbsp; </td><td valign=top><input TYPE=\"checkbox\" NAME=\"inherit\" VALUE=\"$inherit\" ";
 if ( $inherit eq 1 ) { print " checked "; }
 print "></td></tr>\n"; 
 print "	<tr><td valign=top>",&hlink("<b>$text{'f_conect'}</b>","fconect"),"\n"; 
 print "	   ",&hlink("<b>$text{'f_ipaddr'}</b>","fipaddr"),"-",&hlink("<b>$text{'f_contype'}</b>","fcontype"),"&nbsp;</td>\n"; 
"\n"; 
 print "	  <td valign=top> <input TYPE=\"button\" NAME=\"?\" VALUE=\"?\" onClick=\"showHelp('conntype');\" >\n"; 
 print "	   <input TYPE=\"text\" NAME=\"conntype\" VALUE=\"$conntype\" cols=\"32\" size=\"32\" ALIGN=left></td></tr>   \n"; 
 print "      <tr><td valign=top>",&hlink("<b>$text{'f_cdm'}</b>","fcdm"),"</td>\n"; 
 print "	   <td valign=top><input TYPE=\"button\" NAME=\"?\" VALUE=\"?\" onClick=\"showHelp('cdm');\" >\n"; 
 print "	   <input TYPE=\"text\" NAME=\"cdm\" VALUE=\"$cdm\" cols=\"42\" size=\"42\" ALIGN=left></td></tr>   \n"; 
 print "        <tr><td valign=top>",&hlink("<b>$text{'f_maxsess'}</b>","fmaxsess"),"&nbsp;</td>\n";
 print "        <td valign=top><input TYPE=\"text\" NAME=\"maxsess\" VALUE=\"$maxsess\" cols=\"4\" size=\"4\" ALIGN=left onChange=\"isNroThis(this)\">\n";
 print "\n"; 
 print "	<tr><td valign=top><input TYPE=\"submit\" NAME=\"",$text{'f_sendreq'},"\" VALUE=\"",$text{'f_sendreq'},"\">\n"; 
 print "	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>\n"; 
 print "	<td valign=top><input TYPE=\"reset\" NAME=\"",$text{'f_cancelreq'},"\" VALUE=\"",$text{'f_cancelreq'},"\"></td></tr>\n"; 
 print "	</form>\n"; 
 print "	\n"; 
 print "<tr></tr><tr></tr></table></table><hr><p>\n"; 
 &footer($config{'back_return'},$text{'index'}); 
 print "<p><p><p>\n";
 do "footer.pl";
 exit;



