#!/usr/bin/perl
# tta_addmodcache.cgi
# Change Tarantella User Paswords

require './tarantella-lib.pl';
&ReadParse();
 
&header($text{'index_addldapcache'}, "", "addldapcache");
if ( $config{'is_ldapcache'} ne "true" ) { &footCacheHere; exit }
 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 "/******************************************************************\n"; 
 print "   Chek_fields(obj)\n"; 
 print "*******************************************************************/\n";
 print "function Chek_fields(obj) {\n"; 
 print "     if ( emptyField(obj.username) == true ) {\n"; 
 print "         if ( get_value(\"select\",obj.user_ou) == \"none\" ) {\n"; 
 print "               alert(\"error $text{'obj_origin'}\"+\":\"+msg1);\n";
 print "               obj.user_ou.focus();\n"; 
 print "               return false;\n"; 
 print "          } else {         \n"; 
 print "             objValue=get_value(\"select\",obj.user_ou);\n"; 
 print "          }         \n"; 
 print "     } else {        \n"; 
 print "             objValue=obj.username.value;       \n"; 
 print "             if ( emptyField(obj.userou) == true ) {\n"; 
 print "                  alert(obj.username.value+\"->\"+obj.userou.name+\":\"+msg1);\n"; 
 print "	          obj.userou.focus();\n"; 
 print "                  return false;\n"; 
 print "             };\n"; 
 print "             if ( get_value(\"select\",obj.user_ou) != \"none\" ) {\n"; 
 print "                  alert(\"error $text{'obj_origin'}\"+\":\"+msg1);\n";
 print "		  obj.user_ou.focus();\n"; 
 print "                  return false;\n"; 
 print "             }  \n"; 
 print "     }         \n"; 
 print "     if ( get_value(\"select\",obj.usergrphosts) == \"none\" ) {\n";
 print "        if ( get_value(\"select\",obj.hostname) == \"none\" ) {\n";
 print "           if ( get_value(\"select\",obj.grpappsname) == \"none\" ) {\n";
 print "              if ( get_value(\"select\",obj.appname) == \"none\" ) {\n";
 print "                 if ( get_value(\"select\",obj.domain) == \"none\" ) {\n";
 print "                      alert(\"error $text{'obj_target'}\"+\":\"+msg1);\n";
 print "                      obj.usergrphosts.focus();\n";
 print "                      return false;\n";
 print "                 }   \n";
 print "              }    \n";
 print "            }   \n";
 print "         }   \n";
 print "     }  \n";
 print "     onlyOne=false;  \n";
 print "     if ( get_value(\"select\",obj.usergrphosts) != \"none\" ) {\n";
 print "          onlyOne=true;  \n";
 print "     }  \n";
 print "     if ( get_value(\"select\",obj.hostname) !== \"none\" ) {\n";
 print "          if ( onlyOne == true ) {  \n";
 print "               alert(\"error $text{'obj_target'}\"+\":\"+msg1);\n";
 print "               return false;\n";
 print "          } else {  \n";
 print "               onlyOne=true;  \n";
 print "          }  \n";
 print "     }  \n";
 print "     if ( get_value(\"select\",obj.appname) != \"none\" ) {\n";
 print "          if ( onlyOne == true ) {  \n";
 print "               alert(\"error $text{'obj_target'}\"+\":\"+msg1);\n";
 print "               return false;\n";
 print "          } else {  \n";
 print "               onlyOne=true;  \n";
 print "          }  \n";
 print "     }  \n";
 print "     if ( get_value(\"select\",obj.grpappsname) != \"none\" ) {\n";
 print "          if ( onlyOne == true ) {  \n";
 print "               alert(\"error $text{'obj_target'}\"+\":\"+msg1);\n";
 print "               return false;\n";
 print "          } else {  \n";
 print "               onlyOne=true;  \n";
 print "          }  \n";
 print "     }  \n";
 print "     if ( get_value(\"select\",obj.domain) != \"none\" ) {\n";
 print "          if ( onlyOne == true ) {  \n";
 print "               alert(\"error $text{'obj_target'}\"+\":\"+msg1);\n";
 print "               return false;\n";
 print "          } else {  \n";
 print "               onlyOne=true;  \n";
 print "          }  \n";
 print "     }  \n";
 print "     if ( emptyField(obj.tta3tier_login) == true ) {\n";
 print "          alert(obj.tta3tier_login.name+\":\"+msg1+\"->\"+obj.tta3tier_login.value+\"<-\");\n";
 print "          obj.tta3tier_login.focus();\n";
 print "          return false;\n";
 print "      }  \n";
 if ( $config{'is_ldapcache'} eq "true" ) { &script_cache_chek; }; 
 print "     return true;\n"; 
 print "}\n"; 
 print "/******************************************************************\n";
 print "   testCookie(Obj,formObj)\n";
 print "   testCookie from form.\n";
 print "*******************************************************************/\n";
 print "function testCookie(obj,formObj) {\n";
 print "   if ( emptyField(obj) == true ) {\n"; 
 print "         val=getCookie(formObj.username.name);\n";
 print "         if ( val != formObj.username.value ) { \n";
 print "               obj.value=\"\"; \n";
 print "         } else { \n";
 print "               CheckCookie(obj);\n";
 print "         }\n";
 print "    } \n";
 print "}\n";
if ( $config{'is_ldapcache'} eq "true" ) { &htmlCacheaShowPassw }
 print "//-->\n"; 
 print "</SCRIPT>\n"; 
 print "\n"; 
 print "<table width=100% border>\n";
 print "<tr $tb> <td><b>$text{'titidx_addldapcache'}</b></td> </tr>\n";
 print "<tr $cb> <td><table width=100%>\n";
 print "<form METHOD=POST name=addldapcache ACTION=\"addobj.cgi\" onSubmit=\"return Chek_fields(this)\">\n"; 
 print "<tr><td valign=top><b>$text{'obj_origin'}</b>&nbsp;</td></tr>\n";
 print "        <tr><td valign=top>",&hlink("<b>$text{'f_username'}</b>","fusername"),"&nbsp;",$in{'username'},"</td>";
 print "	<td valign=top>\n";
 $msgObj=$text{'selusr_win'};
 $formObj="addldapcache.username";
 &htmlWinLdapUsers($msgObj,$formObj);

 print "        <input TYPE=\"text\" NAME=\"username\" VALUE=\"$username\" cols=\"22\" size=\"12\" ALIGN=left onFocus=\"CheckCookie(this);\" onChange=\"addldapcache.userou.value=''\" >\n"; 
 print "        <input TYPE=\"text\" NAME=\"userou\" VALUE=\"$userou\" cols=\"22\" size=\"22\" ALIGN=left onFocus=\"testCookie(this,addldapcache)\"></td></tr>\n"; 
 print "   <tr><td valign=top>",&hlink("<b>$text{'f_userou'}</b>","fuserou"),"&nbsp;</td>\n";
 print "      <td valign=top><select NAME=\"user_ou\">\n";
 print "                <option VALUE=\"none\">",&hlink("<b>$text{'f_selecou'}</b>","fselecou"),"\n";
 $nItems=0;
 foreach $item (&list_ous()) {
      if ( $nItems == 0 ) {
           print " <option VALUE=\"".$item->{'alias'}."\" >". $item->{'name'}."\n";
     }
      else {
           print " <option VALUE=\"".$item->{'alias'}."\" >".$item->{'name'}."  ";
      }
      $nItems++;
 }
 print "        </select></td></tr>\n";
 print "<tr><td valign=top><b>$text{'obj_target'}</b>&nbsp;</td></tr>\n";

 print "   <tr><td valign=top>",&hlink("<b>$text{'f_appobjname'}</b>","fappobjname"),"&nbsp;</td>\n";
 print "   <td valign=top><select NAME=\"appname\">\n";
 print "                <option VALUE=\"none\">",&hlink("<b>$text{'f_selecapp'}</b>","fselecapps"),"\n";
 $nItems=0;
 foreach $item (&list_apps()) {
      if ( $nItems == 0 ) {
           print " <option VALUE=\"".$item->{'alias'}."\">". $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_grpappsobjname'}</b>","fgrpappsobjname"),"&nbsp;</td>\n";
  print "   <td valign=top><select NAME=\"grpappsname\">\n";
  print "                <option VALUE=\"none\">",&hlink("<b>$text{'f_selecgrpapps'}</b>","fselecgrpapps"),"\n";
 $nItems=0;
 foreach $item (&list_grpapps()) {
      if ( $nItems == 0 ) {
           print " <option VALUE=\"".$item->{'alias'}."\">". $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_hostname'}</b>","fhostname"),"&nbsp;</td>\n";
  print "   <td valign=top><select NAME=\"hostname\">\n";
  print "                <option VALUE=\"none\">",&hlink("<b>$text{'f_selechosts'}</b>","fselechosts"),"\n";
 $nItems=0;
 foreach $item (&list_hosts()) {
      if ( $nItems == 0 ) {
           print " <option VALUE=\"".$item->{'alias'}."\">". $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_usergrphosts'}</b>","fusergrphosts"),"&nbsp;</td>\n"
   ;
  print "   <td valign=top><select NAME=\"usergrphosts\">\n";
  print "                <option VALUE=\"none\">",&hlink("<b>$text{'f_selecgrphosts'}</b>","fselecgrphosts"),"\n";
 $nItems=0;
 foreach $item (&list_grphosts()) {
      if ( $nItems == 0 ) {
           print " <option VALUE=\"".$item->{'alias'}."\">". $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_domain'}</b>","fdomain"),"</td>\n";
 print "   <td valign=top><select NAME=\"domain\">\n";
 print "                <option VALUE=\"none\">",&hlink("<b>$text{'f_selecdomain'}</b>","fselecapps"),"\n";
 $nItems=0;
 foreach $item (&list_domains()) {
      if ( $nItems == 0 ) {
           print " <option VALUE=\"".$item->{'alias'}."\">". $item->{'name'}."\n";
     }
      else {
           print " <option VALUE=\"".$item->{'alias'}."\" >".$item->{'name'}."  ";
      }
      $nItems++;
 }
  print "        </select></td></tr>\n";
 if ( $config{'is_ldapcache'} eq "true" ) { $formObj="addldapcache";$msgObj=$text{'obj_params'};&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;</td>\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\n";
 exit;
