#!/usr/bin/perl
# tta_addusr.cgi
# Add Users to Services with Tarantella
# 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';
&headerstta($text{'index_addusr'}, "", "addusr" ,undef,1,1,"$text{'headpage_right'}"."$text{'head_logout'}",undef,undef,"$text{head_below}" );
 $ttacmd="new_person";
 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 "var ask_confpasscache=true;\n"; 
 print "/******************************************************************\n"; 
 print "   setPasswdDefault(formObj)\n"; 
 print "   If password is empty assign username as default value in the form.\n"; 
 print "*******************************************************************/\n"; 
 print "function setPasswdDefault(formObj) {\n"; 
 print "   if (emptyField(formObj.username)) {\n"; 
 print "      formObj.username.value=\"\";\n"; 
 print "      formObj.password.value=\"\";\n"; 
 print "      return\n"; 
 print "   }   \n"; 
 print "   username=StringClip(true,formObj.username.value);\n"; 
 print "   formObj.username.value=username;\n"; 
 print "   if (emptyField(formObj.password)) {\n"; 
 print "        formObj.password.value=username;\n"; 
 print "        setStatusBar(msg0);\n"; 
 print "   }\n"; 
 print "}\n"; 
 print "/******************************************************************\n"; 
 print "   showPasswd(formObj)\n"; 
 print "   Show Password value from form.\n"; 
 print "*******************************************************************/\n"; 
 print "function showPasswd(formObj) {\n"; 
 print "   alert(\"Password es:\"+formObj.password.value+\"\");\n"; 
 print "}\n"; 
 print "/******************************************************************\n"; 
 print "   Chek_fields(obj)\n"; 
 print "*******************************************************************/\n"; 
 print "function Chek_fields(obj) {\n"; 
 print "     if ( get_value(\"select\",obj.userou) == \"none\" ) {\n"; 
 print "          alert(obj.userou.name+\":\"+msg1);\n"; 
 print "		    obj.userou.focus();\n"; 
 print "          return false;\n"; 
 print "     }         \n"; 
 if ( $config{'has_systemusers'} eq "true") {
      print "     if ( emptyField(obj.sysuser) == true ) {\n";
 }
 if ( $config{'has_ldapusers'} eq "true" ) {
      print "        if ( emptyField(obj.username) == true ) {\n"; 
      print "          alert(obj.username.name+\":\"+msg1+\"->\"+obj.username.value+\"<-\");\n"; 
      print "	       obj.username.focus();\n"; 
      print "          return false;\n"; 
      print "              } \n";
 } else {
      print "          alert(obj.sysuser.name+\":\"+msg1+\"->\"+obj.sysuser.value+\"<-\");\n"; 
      print "	       obj.sysuser.focus();\n"; 
      print "          return false;\n"; 
 }
 if ( $config{'has_systemusers'} eq "true") {
     print "     }  else {  return true }   \n"; 
 }
 if ( $config{'has_ldapusers'} eq "true" ) {
      print "     if ( emptyField(obj.password) == true ) {\n"; 
      print "          alert(obj.password.name+\":\"+msg1+\"->\"+obj.password.value+\"<-\");\n"; 
      print "		    obj.password.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 "</SCRIPT>\n"; 
 print "<table width=100% border>\n";
 print "<tr $tb> <td><font color='$revtext'><b>$text{'titidx_adusr'}</b></font></td> </tr>\n";
 print "<tr $cb> <td><table align=left>\n";
 print "<form METHOD=POST name=newUser ACTION=\"addusr.cgi\" onSubmit=\"return Chek_fields(this)\">\n"; 
 print "	<input TYPE=\"hidden\" NAME=\"ttacmd\" VALUE=\"",$ttacmd,"\">\n"; 
 if ( $config{'has_ldapusers'} eq "true" ) {
    print "	<td valign=top>",&hlink("<b>$text{'f_username'}</b>","fusername"),"&nbsp;</td>";
    print "        <td valign=top><input TYPE=\"text\" NAME=\"username\" VALUE=\"\" cols=\"22\" size=\"15\" ALIGN=left\n"; 
    print "			onChange='document.forms[0].sysuser.value=\"\";setPasswdDefault(newUser)' onFocus='setPasswdDefault(newUser)'></td></tr>\n"; 
    print "	<tr><td valign=top>",&hlink("<b>$text{'f_password'}</b>","fpassword"),"</td>\n"; 
    print "	<td valign=top><input TYPE=\"button\" NAME=\"?\" VALUE=\"?\" onClick=\"showPasswd(newUser);\" >\n"; 
    print "	<input TYPE=\"password\" NAME=\"password\" VALUE=\"\" cols=\"22\" size=\"12\" \n"; 
    print "			onChange=\"setPasswdDefault(newUser)\" onFocus=\"setPasswdDefault(newUser)\"></td></tr>\n"; 
    print "<tr><td><hr></td><td><hr></td></tr>\n";
 }
 if ( $config{'has_systemusers'} eq "true") {
    print "	<tr><td>",&hlink("<b>$text{'sys_user'}</b>","fsysuser"),"&nbsp;</td>";
     print "<td><input type=\"text\" name=sysuser value=\"$sysuser\" cols=15 size=15";
     print "			onChange='document.forms[0].username.value=\"\";document.forms[0].password.value=\"\"' >\n"; 
    print " &nbsp; &nbsp; &nbsp; &nbsp;<a onClick='javascript: window.open(\"/useradmin/edit_user.cgi\", \"edituser\", \"toolbar=no,menubar=no,scrollbars=yes,width=800,height=400\");return false' class='menu1' href='javascript: window.open(\"/useradmin/edit_user.cgi\", \"edituser\", \"toolbar=no,menubar=no,scrollbars=yes,width=800,height=400\");return false'>$text{'create'}</a>&nbsp;";
   print " &nbsp; &nbsp; &nbsp;<input type=button onClick='ifield = document.forms[0].sysuser; chooser = window.open(\"/useradmin/my_user_chooser.cgi?multi=0&user=\"+escape(ifield.value), \"chooser\", \"toolbar=no,menubar=no,scrollbars=yes,width=500,height=200\"); chooser.ifield = ifield; window.ifield = ifield' value=\"$text{select}\">\n";
    print "&nbsp;&nbsp;&nbsp;&nbsp&nbsp;",&hlink("<b>$text{'sync_user'}</b>","fsyncuser"),"&nbsp;";
    print "<input type=\"checkbox\" name=\"syncuser\" value=\"true\" >&nbsp;</td></tr>\n";
    print "<tr><td><hr></td><td><hr></td></tr>\n";
 }

# print "	<tr><td valign=top>",&hlink("<b>$text{'f_passwdcache'}</b>","fpasswdcache"),"</td>\n"; 
# print "	<td valign=top><input TYPE=\"button\" NAME=\"?\" VALUE=\"?\" onClick=\"showPasswd(newUser);\" >&nbsp;\n"; 
# print "	 <input TYPE=\"checkbox\" NAME=\"passwdcache\" VALUE=\"true\" checked></td></tr>\n"; 
# print "	<tr><td valign=top>",&hlink("<b>$text{'f_administrador'}</b>","fadministrador"),"&nbsp;</td> <td valign=top>\n";
#print  "        <input TYPE=\"checkbox\" NAME=\"administrador\" VALUE=\"false\"></td></tr>\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=\"none\">",&hlink("<b>$text{'f_selecou'}</b>","fselecou"),"\n"; 
%h_ou=&list_ous();
 &out_htmlselobj(\%h_ou,"descrip","alias",$userou);
 print "	</select>\n"; 
 print "<input type=button onClick='selfield = document.forms[0].userou; ifield = document.forms[0].userou.options[document.forms[0].userou.selectedIndex]; if ( ifield.value == \"$userou\" ) { ifield.value = \"\" } ; chooser = window.open(\"/stta/obj_chooser.cgi?type=ou&multi=$multiobj&ord=ens&deft=alias&f=select&obj=\"+escape(ifield.value), \"chooser\", \"toolbar=no,menubar=no,scrollbars=yes,width=800,height=500\"); chooser.ifield = ifield; window.ifield = ifield' value=\"$text{browse}\"></td></tr>\n";
 print "        <tr><td>",&hlink("<b>$text{'f_norunttacmd'}</b>","fnorunttacmd"),"</td>\n";
 print "        <td><input type=\"checkbox\" name=\"ttanorun\" value=\"true\" ></td></tr>\n";
 print "<tr><td><hr></td><td><hr></td></tr>\n";
 if ( $config{'is_ldapcache'} eq "true" ) { $formObj="newUser";$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;</td>\n";
 print "        <td valign=top><input TYPE=\"reset\" NAME=\"",$text{'f_cancelreq'},"\" VALUE=\"",$text{'f_cancelreq'},"\"></td></tr>\n";
 print "	</form></td></tr>\n"; 
 print "<tr><tr></table></table><hr><p>\n";
 &footer($config{'back_return'},$text{'index'}); 
 print "<p><p><p>\n";
 do "footer.pl";
 exit;
