#!/usr/bin/perl
# tta_filter.cgi
# filter 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';
$has_ldapusers="";
if ( $ldap_ok ne true && $config{has_ldapusers} eq "true" ){
     $has_ldapusers=$config{'has_ldapusers'};
     $config{'has_ldapusers'}="false";
}
&ReadParse();

$postform=$in{form};
$multiobj=$in{multi} || "0";
$filter = "*";
if ( "$postform" eq "winldapusers" ) {
#    &headerstta($text{'index_winldapusers'}, "", $postform,undef,1,0,"$text{'headpage_right'}"."$text{'head_logout'}",undef,undef,"$text{head_below}" );
#     &headerstta("", "", $postform,undef,1,0,"$text{'headpage_right'}"."$text{'head_logout'}",undef,undef,"$text{head_below}" );
       &headerstta("", "", $postform, 0, 1, 1);
 } else {
     &headerstta($text{'index_filter'}, "", "filter",undef,1,0,"$text{'headpage_right'}"."$text{'head_logout'}",undef,undef,"$text{head_below}" );
};

 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.filter) == true ) {\n"; 
 print "          alert(obj.filter.name+\":\"+msg1+\"->\"+obj.filter.value+\"<-\");\n"; 
 print "		    obj.filter.focus();\n"; 
 print "          return false;\n"; 
 print "     }         \n"; 
 if ( $postform eq "ldap_loglist" ) {
      print "     if ( emptyField(obj.file) == true ) {\n"; 
      print "          if ( obj.outscreen.checked ) {\n";
      print "               return true;\n"; 
      print "          }\n"; 
      print "          alert(obj.file.name+\":\"+msg1+\"->\"+obj.file.value+\"<-\");\n"; 
      print "		    obj.file.focus();\n"; 
      print "          return false;\n"; 
      print "     }         \n"; 
 }
 print "     return true;\n"; 
 print "}\n"; 
 print "//-->\n"; 
 print "</SCRIPT>\n"; 
 print "<p>\n"; 
 print "<table width=100% border>\n";
 print "<tr $tb> <td><font color='$revtext'><b>$text{'titidx_filter'}  </b></td> </tr>\n";
 print "<tr $cb> <td><table align=left>\n";
 if ( $postform eq "ldap_loglist" ) {
      print "<form METHOD=POST name=tta_filter ACTION=\"$postform.cgi\" onSubmit=\"return Check_fields(this)\">\n"; 
 } else {
      print "<form METHOD=POST name=tta_filter ACTION=\"tta_selusr.cgi?form=$postform\" onSubmit=\"return Check_fields(this)\">\n"; 
 }

 print "	<td valign=top>",&hlink("<b>$text{'f_filtercn'}</b>","ffiltercn"),"&nbsp;</td>";
 print "        <td valign=top><input TYPE=\"text\" NAME=\"filter\" VALUE=\"$filter\" cols=\"22\" size=\"12\" ALIGN=left </td></tr>\n"; 
 print "   <tr><td valign=top>",&hlink("<b>$text{'f_userou'}</b>","fuserou"),"&nbsp;</td><td valign=top><select NAME=\"base\">\n"; 
 print " 		<option VALUE=\"\">",&hlink("<b>$text{'f_selecou'}</b>","fselecou"),"\n"; 
$nItems=0;
%h_ou=&list_ous();
&out_htmlselobj(\%h_ou,"descrip","obj",$base);
 print "	</select>\n"; 
 print "<input type=button onClick='selfield = document.forms[0].base; ifield = document.forms[0].base.options[document.forms[0].base.selectedIndex]; if ( ifield.value == \"$base\" ) { ifield.value = \"\" } ; chooser = window.open(\"/stta/obj_chooser.cgi?type=ou&multi=$multiobj&ord=ens&deft=obj&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 valign=top>",&hlink("<b>$text{'f_orderby'}</b>","forderby"),"&nbsp;</td><td valign=top><select NAME=\"sort_on\">\n"; 
 print " 		<option VALUE=\"none\">",&hlink("<b>$text{'f_selecord'}</b>","fselecou"),"\n"; 
 print "  	     <option VALUE=\"browse\">$text{browse}</b>\n";

@l_orderby = split(/,/,$text{'dn_orderby'}, -1);
@l_tit_orderby = split(/,/,$text{'dn_tit_orderby'}, -1);
$nItems=0;
foreach $item (
@l_orderby) {
     print "  	     <option VALUE=\"$item\" ";
     print ">$l_tit_orderby[$nItems]</b>\n";
     $nItems++;
}
 print "	</select></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=\"checkbox\" name=\"sysuser\" value=\"true\" ";
      print "checked"; 
      print "></td></tr>\n";

 }
 if ( $config{'has_ldapusers'} eq "true" ) {
      print "   <tr><td valign=top>",&hlink("<b>$text{'f_ldapserver'}</b>","fldapserver"),"&nbsp;</td><td valign=top><select NAME=\"ldapserver\">\n"; 
      print " <option VALUE=\"1\" >".$config{ldap_servertitle}."\n";
      if ( $config{ldap2_server}.length gt 0 ) {
           print " <option VALUE=\"2\" >".$config{ldap2_servertitle}."\n";
      }
      print " <option VALUE=\"0\" >".$text{selec_noldapsrv}."\n";
      print "	</select></td></tr>\n"; 
 }
 if ( $postform eq "ldap_loglist" ) {
     print "<tr $cb><td valign=top>",&hlink("<b>$text{'f_filereport'}</b>","ffilereport"),"&nbsp;</td>\n";
     print "        <td valign=top><input TYPE=\"text\" NAME=\"file\" VALUE=\"$fileName\" cols=\"40\" size=\"40\" ALIGN=left></td> </tr>\n";
     print "<tr $cb><td valign=top>$text{viewon_screen}</td>\n";
     print "<td><input type=checkbox name=outscreen value=1 ></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></td></tr>\n"; 
 print "<tr><tr></table></table><hr><p>\n";
if ( "$postform" ne "winldapusers") {  
   &footer($config{'back_return'},$text{'index'}); 
}
 print "<p><p><p>\n";
 if ( $has_ldapusers ne "" ) { $config{'has_ldapusers'}= $has_ldapusers } 
 do "footer.pl";
 exit;
