#!/usr/bin/perl
# file_showlist.cgi
# Show List files from STTA
# 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();
if ( ! $access{'supervision'} )   { &redirect("index.cgi"); }
$postform = ($in{postform}) ? $in{postform} : "showlist";
$cgiPost = ($in{cgiPost}) ? $in{cgiPost} : "file";
$cgiName = ($in{cgiName}) ? $in{cgiName} : "file_showlist.cgi";
$wkdir = ($in{wkdir}) ? $in{wkdir} : eval("\$config{'stta_defslist'}");
if ( ! $in{fName} && ! $in{fExt} )   { &redirect("index.cgi"); }
if ( $postform eq "filemgr" ) { $postform="showlist"; }
$fName=$in{fName};
$fExt=$in{fExt};
if ( ! $in{fName} )   { 
     if ( $fExt eq "ous" ) { $fName=$config{ou_list}}
     elsif ( $fExt eq "grphosts" ) {$fName= $config{grphosts_list}}
     elsif ( $fExt eq "hosts" ) { $fName=$config{hosts_list}}
     elsif ( $fExt eq "hostsuser" ) { $fName=$config{hostsuser_list}}
     elsif ( $fExt eq "profcache" ) { $fName=$config{profcache_list}}
     elsif ( $fExt eq "apps" ) { $fName=$config{apps_list}}
     elsif ( $fExt eq "grpapps" ) { $fName=$config{grpapps_list}}
     elsif ( $fExt eq "domains" ) { $fName=$config{domains_list}}
     elsif ( $fExt eq "links" ) { $fName=$config{links_list}}
     elsif ( $fExt eq "actions" ) { $fName=$config{acts_list}}
     elsif ( $fExt eq "webtops" ) { $fName=$config{tta_webtops}}
}
if ( ! $in{fExt} )   { 
     if ( $config{ou_list} =~ /$fName$/ ) { $fExt="ous" }
     elsif ( $config{grphosts_list} =~ /$fName$/ ) { $fExt="grphosts" }
     elsif ( $config{hosts_list} =~ /$fName$/) { $fExt="hosts" }
     elsif ( $config{hostsuser_list} =~ /$fName$/) { $fExt="hostsuser" }
     elsif ( $config{profcache_list} =~ /$fName$/) { $fExt="profcache" }
     elsif ( $config{apps_list} =~ /$fName$/) { $fExt="apps" }
     elsif ( $config{grpapps_list} =~ /$fName$/) { $fExt="grpapps" }
     elsif ( $config{domains_list} =~ /$fName$/) { $fExt="domains" }
     elsif ( $config{links_list} =~ /$fName$/) { $fExt="links" }
     elsif ( $config{acts_list} =~ /$fName$/) { $fExt="actions" }
     elsif ( $config{tta_webtops} =~ /$fName$/) { $fExt="webtops" }
}
$fExtName=$text{"index_".$fExt};
$cmd=$in{cmd};
if ( $in{fPerm} ) {
     if ( substr($in{fPerm},0,1) ne "-" ) {
        @l_target = split(/,/,$text{'f_perm_value'}, -1);
        @l_target_tit = split(/,/,$text{'f_perm_desc'}, -1);
        $nItems=0;
        foreach $item (@l_target) {
                if ( $l_target_tit[$nItems] eq $in{fPerm} ) {
                     $fMode=$l_target_tit{$nItems};
                     $fPerm=substr($fMode,2,1);
                     last;
                }
                $nItems++;
        }
     } else {
        $fMode=$in{fPerm};
        $fPerm=substr($fMode,2,1);
     }
}
$filePerm = ($in{filePerm}) ? $in{filePerm} : $fMode;
$perm=$in{perm};
if ( $perm ne "new" && substr($in{fPerm},1,3) eq "rwx" ) { $perm="all"; }

&headerstta(eval("\$text{'index_$postform'}"), "", $postform ,undef,1,0,"$text{'headpage_right'}"."$text{'head_logout'}",undef,undef,"$text{head_below}" );
if ( $perm ne "read" && $fPerm eq "w" ) {
 print "<hr>\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_confpassmon=true;\n"; 
 print "/******************************************************************\n"; 
 print "   Check_fields(obj)\n"; 
 print "*******************************************************************/\n"; 
 print "function Check_fields(obj) {\n"; 
 print "     if ( emptyField(obj.fName) == true ) {\n"; 
 print "          alert(obj.fName.name+\":\"+msg1+\"->\"+obj.fName.value+\"<-\");\n"; 
 print "		    obj.fName.focus();\n"; 
 print "          return false;\n"; 
 print "     }         \n"; 
 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>";
if ( $postform ne "showlist" ) { print $text{'showlist'}; }
print " ".eval("\$text{'titidx_$postform'}")." \"$fExtName\"</b></td> </tr>\n";
print "<tr $cb> <td><table width=100%>\n";
if ( $in{fName} )   { 
  if ( $perm eq "read" || $fPerm ne "w" ) {
      print "<tr><td>>";
      print &text('file_err',$text{'showlist'},$wkdir,$fName,$fMode);
      print "</td></tr>\n";
      &footHere;
      exit 1;
  }
}
if ( $fExtName eq "" ) {
    print "<tr><td> $in{fName} -- $fName -- $config{ou_list} -- $fExt -- $fExtName ";
#    print &text('showlist_errName',$text{'showlist'},$fExt,$wkdir,$fName,$fMode);
    print "</td></tr>\n";
    &footHere;
    exit;
}
 print "<left><form METHOD=POST name=".$postform." ACTION=\"\" onSubmit=\"return Check_fields(this)\">\n"; 
 print "  <input TYPE=\"hidden\" NAME=\"cmd\" VALUE=\"",$cmd,"\">\n";
 print "  <input TYPE=\"hidden\" NAME=\"postform\" VALUE=\"$postform\">\n";
 print "  <input TYPE=\"hidden\" NAME=\"wkdir\" VALUE=\"$wkdir\">\n";
 print "  <input TYPE=\"hidden\" NAME=\"perm\" VALUE=\"$perm\">\n";
 print "  <input TYPE=\"hidden\" NAME=\"fPerm\" VALUE=\"$fMode\">\n";
 print "  <input TYPE=\"hidden\" NAME=\"filePerm\" VALUE=\"$filePerm\">\n";
 
 %h_obj=eval("\&list_$fExt()");
if (%h_obj) {
   # print "<center><textarea name=\"f_lines\" rows=\"22\" cols=\"90\" wrap=\"virtual\"> \n";
    print  "<pre>"; 
    &showrec_list(\%h_obj);
    print  "</pre>\n"; 
   # print "</textarea>\n";
     print "</table><tr $cb> <td><table width=100%>\n"; 
} else {
    print "<TR><TD colspan=4> $fExt:" . $text{msg_1} . "\n";
 }
 print "  <tr><td valign=top>",&hlink("<b>$text{'f_filelistName'}</b>","ffilelistName"),"&nbsp;</td>\n";
 print "  <input TYPE=\"hidden\" NAME=\"fName\" VALUE=\"$fName\">\n";
 print "  <td valign=top><b>$fName</b></td></tr>\n";
if ( $in{fName} )   { 
 print "  <tr><td valign=top>",&hlink("<b>$text{'f_fperm'}</b>","ffperm"),"&nbsp;</td>\n";
 @l_target = split(/,/,$text{'f_perm_value'}, -1);
 @l_target_tit = split(/,/,$text{'f_perm_desc'}, -1);
 $nItems=0;
 foreach $item (@l_target) {
        if ( $fMode eq $l_target_tit[$nItems] ) { 
             print "  <input TYPE=\"hidden\" NAME=\"filePerm\" VALUE=\"$item\">\n";
             print "<b>$l_target_tit[$nItems]</b>\n";
             last;
        }
        $nItems++;
 }
 print "</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'});
 do "footer.pl";
 exit;


