#!/usr/bin/perl
# tta_addprofcache.cgi
# Change Tarantella User Paswords
# 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';
&ReadParse();
 
 &headerstta($text{'index_addprofcache'}, "", "addprofcache",undef,1,0,"$text{'headpage_right'}"."$text{'head_logout'}",undef,undef,"$text{head_below}" );
 if ( $config{'is_ldapcache'} eq "true" ) {
     $err_msg=$text{'ldapcache_enable'};
     &footCacheHere;
     exit;
 }
 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 "/******************************************************************\n"; 
 print "   Check_fields(obj)\n"; 
 print "*******************************************************************/\n";
 print "function Check_fields(obj) {\n"; 
 print "     if ( emptyField(obj.profilename) == true ) {\n"; 
 print "          alert(obj.profilename.name+\":\"+msg1+\"->\"+obj.profilename.value+\"<-\");\n"; 
 print "		    obj.profilename.focus();\n"; 
 print "          return false;\n"; 
 print "     }         \n"; 
 print "     if ( emptyField(obj.username) == true ) {\n"; 
 print "         if ( get_value(\"select\",obj.userou) == \"\" ) {\n"; 
 print "              alert(obj.userou.name+\":\"+msg1);\n"; 
 print "		    obj.userou.focus();\n"; 
 print "               return false;\n"; 
 print "          } else {         \n"; 
 print "             objValue=get_value(\"select\",obj.userou);\n"; 
 print "          }         \n"; 
 print "     } else {        \n"; 
 print "             objValue=obj.username.value;       \n"; 
 print "     }         \n"; 
 print "     if ( get_value(\"select\",obj.usergrphosts) == \"\" ) {\n";
 print "        if ( get_value(\"select\",obj.hostname) == \"\" ) {\n";
 print "             alert(obj.usergrphosts.name+\":\"+msg1);\n";
 print "                    obj.usergrphosts.focus();\n";
 print "              return false;\n";
 print "        }        \n";
 print "     }         \n";
 print "     if ( get_value(\"select\",obj.userhostname) == \"\" ) {\n";
 print "              alert(obj.userhostname.name+\":\"+msg1);\n"; 
 print "		    obj.userhostname.focus();\n"; 
 print "               return false;\n"; 
 print "     }         \n"; 
 print "     if ( get_value(\"select\",obj.usergrphosts) != \"\" ) {\n";
 print "          return confirm(obj.profilename.value+\" : \"+objValue+msg7+get_value('select',obj.usergrphosts)+msg7+get_value('select',obj.userhostname));\n";
 print "     }         \n";
 print "     if ( get_value(\"select\",obj.hostname) != \"\" ) {\n";
 print "          return confirm(obj.profilename.value+\" : \"+objValue+msg7+get_value('select',obj.hostname)+msg7+get_value('select',obj.userhostname));\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_addprofcache'}-- $username</b></td> </tr>\n";
 print "<tr $cb> <td><table width=100%>\n";
 print "<form METHOD=POST name=newUser ACTION=\"addprofcache.cgi\" onSubmit=\"return Check_fields(this)\">\n"; 
print "        <tr><td valign=top>",&hlink("<b>$text{'f_profilename'}</b>","fprofilename"),"&nbsp;</td>";
print "        <td valign=top><input TYPE=\"text\" NAME=\"profilename\" VALUE=\"$profilename\" cols=\"22\" size=\"22\" ALIGN=left></tr></td>\n"; 
print "	<tr><td valign=top>",&hlink("<b>$text{'f_descrip'}</b>","fdescrip"),"\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_username'}</b>","fusername"),"&nbsp;",$in{'username'},"</td>";
print "        <td valign=top><input TYPE=\"text\" NAME=\"username\" VALUE=\"$username\" cols=\"22\" size=\"12\" ALIGN=left></tr></td>\n"; 
print "   <tr><td valign=top>",&hlink("<b>$text{'f_userou'}</b>","fuserou"),"&nbsp;</td>\n";
print "      <td valign=top><select NAME=\"userou\">\n";
print "                <option VALUE=\"\">",&hlink("<b>$text{'f_selecou'}</b>","fselecou"),"\n";
$nItems=0;
%h_ou=&list_ous();
foreach $item (keys (%h_ou)) {
   print " <option VALUE=\"".$h_ou{$item}->{'alias'}."\">". $h_ou{$item}->{'name'}."\n";
   $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=\"\">",&hlink("<b>$text{'f_selecgrphosts'}</b>","fselecgrphosts"),"\n";
$nItems=0;
%h_grphost=&list_grphosts();
foreach $item (keys (%h_grphost)) {
   print " <option VALUE=\"".$h_grphost{$item}->{'alias'}."\">". $h_grphost{$item}->{'name'}."\n";
   $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=\"\">",&hlink("<b>$text{'f_selechosts'}</b>","fselechosts"),"\n";
$nItems=0;
%h_host=&list_hosts();
foreach $item (keys (%h_host)) {
   print " <option VALUE=\"".$h_host{$item}->{'alias'}."\">". $h_host{$item}->{'name'}."\n";
   $nItems++;
}
 print "        </select></td></tr>\n";
 print "   </select></td></tr>\n";
 print "   <tr><td valign=top>",&hlink("<b>$text{'f_hostusername'}</b>","fhostusername"),"&nbsp;</td>\n";
 print "   <td valign=top><select NAME=\"userhostname\">\n";
 print "                <option VALUE=\"\">",&hlink("<b>$text{'f_seluserhost'}</b>","fseluserhosts"),"\n";
$nItems=0;
%h_hostuser=&list_hostsuser();
foreach $item (keys (%h_hostuser)) {
   print " <option VALUE=\"".$h_hostuser{$item}->{'username'}."\">". $h_hostuser{$item}->{'name'}."\n";
   $nItems++;
}
 print "        </select></td></tr>\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 "<tr><tr></table></table><hr><p>\n"; 
 &footer($config{'back_return'},$text{'index'}); 
 print "<p><p><p>\n";
 do "footer.pl\n";
 exit;
