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

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

&ReadParse();

 $aliasgrpapps=$in{aliasgrpapps};
 if (!$aliasgrpapps) { &redirect("cache_selgrpapps.cgi?form=modgrpapps"); }
 $postform = $in{postform};
 &headerstta($text{'index_modgrpapps'}, "","modgrpapps" ,undef,1,0,"$text{'headpage_right'}"."$text{'head_logout'}",undef,undef,"$text{head_below}" ); 
 $ttacmd="edit";
 # Cleaning and reset values ...
 $descrip="";
 $maxsess="";
 $grpappsname="";
 $dn_grpapps="";
 $ens_grpapps="";
 $alias="";
 $conntype="";
 $inherit="";
 $cdm="";
 $webtop="";
 %h_grpapps=&list_grpapps();
 if  ( $h_grpapps{$aliasgrpapps}->{'alias'} ne $aliasgrpapps ) {
       $err_msg=$text{'list_errno'};
       &footHere;
       exit;
 }
 $dn_grpapps=$h_grpapps{$aliasgrpapps}->{'obj'};
 $ens_grpapps=$h_grpapps{$aliasgrpapps}->{'ens'};
 $grpappsname=$h_grpapps{$aliasgrpapps}->{'name'};
 $descrip=$h_grpapps{$aliasgrpapps}->{'descrip'};
 $alias=$h_grpapps{$aliasgrpapps}->{'alias'};
 $maxsess=$h_grpapps{$aliasgrpapps}->{'maxsess'};

if ( $config{'is_ldapcache'} eq "true" ) { 
   if ( $dn_grpapps ne "" ) { 
       $dn_cache="cn=$config{ldapcache_defaultobj},$dn_grpapps,".$config{ldapcache_base};  
   } else {
       $dn_cache="cn=$config{ldapcache_defaultobj},".$config{ldapcache_base};  
   }
   $ldapcache_server=$in{ldapcacheserver} || "1";
   &connect_cache();
   # loading variables
   &load_tta3tier_vars($dn_cache);
 }
 $ens_obj = "\"".$config{tta_base}."/$ens_grpapps\"";
 if ( $grpappsname ) {
      if ( $in{postform} ) {
           # loading object attributes ...
           $op="attributes";
           $type_cmd="attributes";
           $status_cmd=&run_tta_cmd($type_cmd,$ens_obj);
           if ( !$status_cmd ) { $str_cmds="<tr><td> ".$text{'tta_noobject'}."</td></tr>";}
       }
 } else {
      # loading object defaults ....
      $temp_f=$config{'tta_defaults_grpapps'}; 
 } 
 # Assigning and collecting values to be used in the form ...
 %h_ttaobj=&load_ttaobj();
 $descrip =$h_ttaobj{'description'}->{'value'};
 $cdm     =$h_ttaobj{'cdm'}->{'value'};
 $inherit =$h_ttaobj{'inherit'}->{'value'};
 $webtop  =$h_ttaobj{'webtop'}->{'value'};
 $conntype=$h_ttaobj{'conntype'}->{'value'};
 $temp_f="";
 print "<hr><p>\n";
 print "<SCRIPT SRC=\"global.js\">\n"; 
 print "</SCRIPT>\n"; 
 print "<SCRIPT LANGUAGE=\"JavaScript\">\n"; 
 print "<!--\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 "var ask_confadmin=true;\n"; 
 print "\n"; 
 &htmlCheckAlias("grpapps");
if ( $config{'is_ldapcache'} eq "true" ) { &htmlCacheaShowPassw }
 print "/******************************************************************\n"; 
 print "   Check_fields(obj)\n"; 
 print "*******************************************************************/\n"; 
 print "function Check_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=1; \n"; 
# print "     }\n"; 
# print "     else {\n"; 
# print "          obj.inherit.value=0; \n"; 
# print "     }\n"; 
 if ( $config{'is_ldapcache'} eq "true" ) { &script_cache_chek; }; 
 print "     if ( get_value(\"select\",obj.usergrpapps) != \"none\" ) {\n"; 
 print "          return confirm(obj.grpappsname.value+msg7+get_value('select',obj.usergrpapps));\n"; 
 print "     }         \n"; 
 print "\n"; 
 print "     return true;\n"; 
 print "}\n"; 
 print "//-->\n"; 
 print "</SCRIPT>\n"; 
 print "\n"; 
 print "<table width=100% border>\n";
 print "<tr $tb> <td><font color='$revtext'><b>$text{'titidx_adgrpapps'}</b></td> </tr>\n";
 print "<tr $cb> <td><table width=100%>\n";
 print "<form METHOD=POST name=modgrpapps ACTION=\"modgrpapps.cgi\" onSubmit=\"return Check_fields(this)\">\n"; 
 print "	<input TYPE=\"hidden\" NAME=\"ttacmd\" VALUE=\"",$ttacmd,"\">\n"; 
 print "	<input TYPE=\"hidden\" NAME=\"aliasgrpapps\" VALUE=\"",$aliasgrpapps,"\">\n"; 
 print "	<input TYPE=\"hidden\" NAME=\"grpappsname\" VALUE=\"",$grpappsname,"\">\n"; 
 print "	<tr><td valign=top>",&hlink("<b>$text{'f_aliasgrpapps'}</b>","faliasgrpapps"),"&nbsp;</td>\n";
 print "         <td valign=top><b>$aliasgrpapps</b>&nbsp;</td></tr>\n";     
 print "	<tr><td valign=top>",&hlink("<b>$text{'f_grpappsobjname'}</b>","fgrpappsobjname"),"&nbsp;</td>\n";
 print "         <td valign=top><b>$grpappsname</b>&nbsp;</td></tr>\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"; 

%h_webtops=&list_webtops();
$nItems=0;
foreach $item (keys (%h_webtops)) {
     if ( $h_webtops{$item}->{'obj'} eq $webtop ) {
          print " <option VALUE=\"".$h_webtops{$item}->{'alias'}."\" selected>". $h_webtops{$item}->{'name'}."\n";
    }
     else {
          print " <option VALUE=\"".$h_webtops{$item}->{'alias'}."\" >".$h_webtops{$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\"></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\"></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=\"5\" size=\"5\" ALIGN=left onChange=\"isNroThis(this)\">\n";
if ( $config{'is_ldapcache'} eq "true" ) { $formObj="modgrpapps";$msgObj=$text{'default_obj'};&htmlCacheapp(msgObj) }
 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;\n";
 print "        <td valign=top><input TYPE=\"reset\" NAME=\"",$text{'f_cancelreq'},"\" VALUE=\"",$text{'f_cancelreq'},"\"></td></tr>\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;
