# html-lib.pl
# STTA Rev. 1.3 Copyright (c) 2001-2002 Jesús Pérez Lorenzo  --- license GNU GPL 
# Common functions 

# header(title, image, [help], [config], [nomodule], [nowebmin], [rightside],
#        [header], [body])
# Output a page header with some title and image. The header may also
# include a link to help, and a link to the config page.
# The header will also have a link to to webmin index, and a link to the
# module menu if there is no config link
sub headerstta
{
   local $text_str;
   local $html_str;

   $text_str=" ";
   $html_str="";
   if ( $config{check_services} eq "true" ) { 
         &checkSTTA_services("all","status",\$text_str);
   }
   &header($_[0],$_[1],$_[2],$_[3],$_[4],$_[5],$_[6],$_[7],$_[8]);
   if ( $config{stta_srvtitle} ne "" ) { print "<b> $config{stta_srvtitle} </b> <BR>\n"; }
    print "<SCRIPT LANGUAGE=\"JavaScript\">\n";
    print "/******************************************************************\n";
    print "   show_stta(item)\n";
    print "*******************************************************************/\n";
    print "function show_stta(item) {\n";
    print "   w_stta= window.open('','stta_ops','toolbar=no,menubar=no,scrollbars=yes,width=800,height=300,resizable=yes');\n";
    print "  w_stta.document.writeln('<body bgcolor=#ffffff link=#0000ee vlink=#0000ee text=#000000>');\n";
    print "   w_stta.document.writeln('<head><title>STTA</title></head>');\n";
    print "   w_stta.document.writeln('<table BORDER=0 WIDTH=100%>');\n";
    print "   w_stta.document.writeln('<tr>');\n";
    print "   w_stta.document.writeln(\"<td valign=top align=left><a href='/help.cgi/stta/toc'> <img align=middle border=0 alt='$text{index}' src='images/stta_button.gif'><tt>$text{index}</tt></a></td>\");\n";
    print "   w_stta.document.writeln(\"<td valign=top align=right>",
          "<a href='javascript:self.close()'>",
          "<img align=middle border=0 alt=$text{index_title}",
          " src='images/$current_lang/stta_title.gif' width='300' height='29'>",
          " <tt>$text{msg_close}</tt></a></td>\");\n";
    print "   w_stta.document.writeln('</tr></table>');\n";
    print "   w_stta.document.writeln('<HR noshade size=2>');\n";

    &printSTTA_config(\$text_str,"=");
    $text_str=~s/STTA:/<tr><td><li>/g;
    $text_str=~s/\n/<\/b><\/td><\/tr>/g;
    $text_str=~s/==/<td><b>/g;
    $html_str.="<table width=100% border><tr $tb> <td><b>".$text{srvSTATUS}."</b></td></tr>";
    $html_str.="<tr $cb> <td><table width=100%><td>";
    $html_str.="<ul>$text_str</ul>";
    $html_str.="</table></table>";
    print "   w_stta.document.writeln('".$html_str."');\n";

    if ($access{'global'} && $access{'supervision'} == 1) { &js_sttamenu(); }
    if ( $config{check_services} ne "true" ) { 
         print "   w_stta.document.writeln(\"<A onClick=\\\"window.open('stta_view.cgi', 'stta_view','toolbar=no,menubar=no,scrollbars=yes,width=800,height=300,resizable=yes');return false\\\" href='stta_view.cgi'>$text{srvSTATUS}</A>\");\n";
    }
    print "   w_stta.document.writeln('<HR noshade size=2>');\n";
    print "   w_stta.document.close();\n";
    print "}\n";
    print "</SCRIPT>\n";
}

# JavaScript with in depth menu
sub js_sttamenu
{
    local $text_str;

    print "   w_stta.document.writeln('<table width=100%>');\n";
    print "   w_stta.document.writeln('<ul><tr><td><li>');\n";
    print "   w_stta.document.writeln(\"",
    &html_objlink("config","STTA $text{'config_title'}",\%config,$text{'config_title'},"docwrite"),"\");\n";
    if ( $config{check_services} eq "true" ) { 
         print "   w_stta.document.writeln('</tr></td><tr><td><li>');\n";
         print "   w_stta.document.writeln(\"",
               &html_objlink("ttaprops",$text{'index_ttaproperties'},\%ttaprops,$text{index_globaltta},"docwrite"),"\");\n";
         print "   w_stta.document.writeln('</tr></td><tr><td><li>');\n";
         print "   w_stta.document.writeln(\"",
         &html_objlink("ttaparams tta",$text{ttastatus_title},\%{$sttaparams{tta}},$text{ttastatus_title},"docwrite"),"\");\n";
         print"   w_stta.document.writeln('</tr></td><tr><td><li>');\n";
         print "w_stta.document.writeln(\"",
         &html_objlink("ttaparams ldap",$text{index_ldap},\%{$sttaparams{ldap}},$text{index_ldap},"docwrite"),"\");\n";
         $lnum=0;
         print "   w_stta.document.writeln('</tr></td>');\n";
         foreach $item (@ttahosts) {
            print "   w_stta.document.writeln('<tr><td><li>');\n";
            print "   w_stta.document.writeln(\"",
            &html_objlink("host",$item->{name},\%{$ttahosts[lnum]},$item->{name},"docwrite"),"\");\n";
            $lnum++;
            print"   w_stta.document.writeln('</td></tr>');\n";
         }
    }
    print "   w_stta.document.writeln('<tr><td><li>');\n";
    print "   w_stta.document.writeln(\"",
    &html_objlink("access stta",$text{index_acl},\%access,$text{index_acl},"docwrite"),"\");\n";
    print "   w_stta.document.writeln('<tr><td><li>');\n";
    print "   w_stta.document.writeln(\"<A onClick=\\\"window.open('tta_alivehosts.cgi', 'hostsalive','toolbar=no,menubar=no,scrollbars=yes,width=800,height=300,resizable=yes');return false\\\" href='tta_alivehosts.cgi'>$text{index_alivehosts}</A>\");\n";
    print "   w_stta.document.writeln('<tr><td><li>');\n";
    print "   w_stta.document.writeln(\"<A onClick=\\\"window.open('/proc/index_search.cgi?user=&mode=1&match=slapd&cpu=&fs=%2F&files=', 'ldap-proc','toolbar=no,menubar=no,scrollbars=yes,width=800,height=300,resizable=yes');return false\\\" href='/proc/index_search.cgi?user=&mode=1&match=slapd&cpu=&fs=%2F&files='>$text{ldapps_title}</A>\");\n";
    print "   w_stta.document.writeln('<tr><td><li>');\n";
    print "   w_stta.document.writeln(\"<A onClick=\\\"window.open('/proc/index_search.cgi?user=&mode=1&match=ttaauxserv&cpu=&fs=%2F&files=:', 'tta-proc','toolbar=no,menubar=no,scrollbars=yes,width=800,height=300,resizable=yes');return false\\\" href='/proc/index_search.cgi?user=&mode=1&match=ttaauxserv&cpu=&fs=%2F&files=:'>$text{ttaps_title}</A>\");\n";
    print "   w_stta.document.writeln('</ul></td></tr>');\n";
    print "   w_stta.document.writeln('</table><BR>');\n";
}
# config_icons(context, program)
# Displays up to 17 icons, one for each type of configuration directive, for
# some context (global, virtual, directory or htaccess)
sub config_icons
{
local($m, $func, $e, %etype, $i, $c);
      foreach $m (sort { $a cmp $b } (keys %httpd_modules)) {
              $func = $m."_directives";
	      foreach $e (&$func($httpd_modules{$m})) {
		      if ($e->{$_[0]}) { $etype{$e->{'type'}}++; }
		      }
              }
      print "<table width=100% cellpadding=5>\n";
      for($i=0; $text{"type_$i"}; $i++) {
	      if ($etype{$i} && $access_types{$i}) {
		      if ($c%5 == 0) { print "<tr>\n"; }
		      print "<td valign=top align=center width=20%>\n";
		      &generate_icon("images/type_icon_$i.gif", $text{"type_$i"},
			             $_[1]."type=$i");
		      print "</td>\n";
		      if ($c%5 == 4) { print "<tr>\n"; }
		      $c++;
		      }
	      }
      for($i=2; $i<@_; $i++) {
	      if ($c%5 == 0) { print "<tr>\n"; }
	      print "<td valign=top align=center width=20%>\n";
	      &generate_icon($_[$i]->{'icon'}, $_[$i]->{'name'}, $_[$i]->{'link'});
	      print "</td>\n";
	      if ($c%5 == 4) { print "<tr>\n"; }
	      $c++;
	      }
      print "</table><p>\n";
}

sub footHere
{

        if ( $err_msg ) { 
              print "<hr><table width=100% border>\n";
              print "<tr></tr><tr $cb><td align=center><b>$err_msg</b></td></tr>\n";
              print "<tr><tr><table>\n";
        }
        print "<tr><tr></table></table><hr><p>\n";
        &footer($config{'back_return'},$text{'index'});
        print "<p><p><p>\n";
        do "footer.pl";
}

# restart_button()
# Returns HTML for a link to put in the top-right corner of every page
sub restart_button
{
	$rv = "<a href=\"tta_restart.cgi\">$text{'tta_restart'}</a><br>\n";
	$rv .= "<a href=\"$config{url_tta}\">$text{'tta_help'}</a>\n";
	$rv .= "<a href=\"ldap_restart.cgi\">$text{'ldap_restart'}</a>\n";
        if ( $config{'is_ldapcache'} eq "true" ) {
       	    $rv .= "<a href=\"ldapcache_restart.cgi\">$text{'ldapcache_restart'}</a>\n";
        }
	$rv .= "<a href=\"$config{url_ldap}\">$text{'ldap_help'}</a>\n";
return $rv;
}

# show_error([message])
# Display an error message and exit. The variable $whatfailed must be set
# to the name of the operation that failed.
sub show_error
{
	print "<hr>\n";
	print "<h3>",($whatfailed ? "$whatfailed : " : ""),@_,"</h3>\n";
	print "<hr>\n";
}

sub SrvError
{
      if ( $cginame ne "stta_warn.cgi" ) {
           &redirect("stta_warn.cgi?msg=$err_msg");
      }
}

# footCacheHere()
# Display a message, close tables and put page foot ... 
# almost ready to exit with good look & feel
sub footCacheHere {
 print "<table width=100% border>\n";
 print "<tr $tb> <td><b>|</b></td> </tr>\n";
 if ( !$err_msg ) { $err_msg=$text{'ldapcache_disable'}; }
 print "<tr></tr><tr $cb><td td align=center><b>$err_msg</center></b></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";
}

# htmlCacheapp(msgObj,formObj)
# Display all htmls labels to get input for "ttacacheapp" object 
sub htmlCacheapp 
{
 print "<tr><td valign=top><b>$msgObj</b>&nbsp;</td></tr>\n";
 print "	<tr><td valign=top>",&hlink("<b>$text{'f_3tierlogin'}</b>","f3tierlogin"),"</td>\n"; 
 print "	<td valign=top><input TYPE=\"text\" NAME=\"tta3tier_login\" VALUE=\"$tta3tier_login\" cols=\"20\" size=\"20\" ALIGN=left></td></tr>\n"; 
 print "	<tr><td valign=top>",&hlink("<b>$text{'f_3tierpassword'}</b>","f3tierpassword"),"\n"; 
 print "	<td valign=top><input TYPE=\"password\" NAME=\"tta3tier_password\" VALUE=\"$tta3tier_password\" cols=\"20\" size=\"20\" ALIGN=left>\n"; 
 print "	<input TYPE=\"button\" NAME=\"?\" VALUE=\"?\" onClick=\"showPasswd($formObj);\" ></td></tr>"; 
 print "	<tr><td valign=top>",&hlink("<b>$text{'f_3tiertitle'}</b>","f3tiertitle"),"&nbsp;</td>\n";
print "		<td valign=top><input TYPE=\"text\" NAME=\"tta3tier_title\" VALUE=\"$tta3tier_title\" cols=\"30'\" size=\"30\" ALIGN=left></td></tr>\n"; 
 print "  	<tr><td valign=top>",&hlink("<b>$text{'f_3tierdomain'}</b>","f3tierdomain"),"</td>\n"; 
 print "        <td valign=top><input TYPE=\"text\" NAME=\"tta3tier_domain\" VALUE=\"$tta3tier_domain\" cols=\"12\" size=\"12\" ALIGN=left></td></tr>\n"; 
 print "	<tr><td valign=top>",&hlink("<b>$text{'f_3tierstringcmd'}</b>","f3tierstringcmd"),"</td>\n"; 
 print "	<td valign=top><input TYPE=\"text\" NAME=\"tta3tier_stringcmd\" VALUE=\"$tta3tier_stringcmd\" cols=\"60\" size=\"40\" ALIGN=left></td></tr>\n"; 
 print "	<tr><td valign=top>",&hlink("<b>$text{'f_3tierappkey1'}</b>","f3tierappkey1"),"</td>\n"; 
 print "	<td valign=top><input TYPE=\"text\" NAME=\"tta3tier_appkey1\" VALUE=\"$tta3tier_appkey1\" cols=\"20\" size=\"20\" ALIGN=left></td></tr>\n"; 
 print "	<tr><td valign=top>",&hlink("<b>$text{'f_3tierappkey2'}</b>","f3tierappkey2"),"</td>\n"; 
 print "	<td valign=top><input TYPE=\"text\" NAME=\"tta3tier_appkey2\" VALUE=\"$tta3tier_appkey2\" cols=\"20\" size=\"20\" ALIGN=left></td></tr>\n"; 
 print "	<tr><td valign=top>",&hlink("<b>$text{'f_3tierappkey3'}</b>","f3tierappkey3"),"</td>\n"; 
 print "	<td valign=top><input TYPE=\"text\" NAME=\"tta3tier_appkey3\" VALUE=\"$tta3tier_appkey3\" cols=\"20\" size=\"20\" ALIGN=left></td></tr>\n"; 
 print "	<tr><td valign=top>",&hlink("<b>$text{'f_3tierappkey4'}</b>","f3tierappkey4"),"</td>\n"; 
 print "	<td valign=top><input TYPE=\"text\" NAME=\"tta3tier_appkey4\" VALUE=\"$tta3tier_appkey4\" cols=\"20\" size=\"20\" ALIGN=left></td></tr>\n"; 
 print "	<tr><td valign=top>",&hlink("<b>$text{'f_3tierappkey5'}</b>","f3tierappkey5"),"</td>\n"; 
 print "	<td valign=top><input TYPE=\"text\" NAME=\"tta3tier_appkey5\" VALUE=\"$tta3tier_appkey5\" cols=\"20\" size=\"20\" ALIGN=left></td></tr>\n"; 
 print "	<tr><td valign=top>",&hlink("<b>$text{'f_3tierappkey6'}</b>","f3tierappkey6"),"</td>\n"; 
 print "	<td valign=top><input TYPE=\"text\" NAME=\"tta3tier_appkey6\" VALUE=\"$tta3tier_appkey6\" cols=\"20\" size=\"20\" ALIGN=left></td></tr>\n"; 
 print "        <tr><td valign=top>",&hlink("<b>$text{'f_3tiermaxsess'}</b>","f3tiermaxsess"),"&nbsp;</td>\n";
 if ( $tta3tier_maxsess eq "" ) { $tta3tier_maxsess=$config{default_maxsess}; }
 print "        <td valign=top><input TYPE=\"text\" NAME=\"tta3tier_maxsess\" VALUE=\"$tta3tier_maxsess\" cols=\"5\" size=\"5\" ALIGN=left onChange=\"isNroThis(this)\">\n";

if ( $config{'check_ticket'} eq "false"  && $tta3tier_ticketstatus eq "" ) { $tta3tier_ticketstatus="no"; }
 print "   <tr><td valign=top>",&hlink("<b>$text{'f_ticketstatus'}</b>","fticketstatus"),"&nbsp;</td><td valign=top><select NAME=\"tta3tier_ticketstatus\">\n";
 print "                <option VALUE=\"none\">",&hlink("<b>$text{'f_ticketstatus_sel'}</b>","fticket_status_sel"),"\n";
 
@l_target = split(/,/,$text{'ticket_status_value'}, -1);
$nItems=0;
foreach $item (@l_target) {
     print "         <option ";
     if ( $item eq $tta3tier_ticketstatus ) { print "selected " ; }
     print "VALUE=\"$item\" ";
     $targetext='ticket_'.$item.'_tit';
     print ">$text{$targetext}</b>\n";
     $nItems++;
}
print "        </select></td></tr>\n";
 print "        <tr><td valign=top>",&hlink("<b>$text{'f_endticket'}</b>","fendticket"),"&nbsp;</td>\n";
 print "        <td valign=top><input TYPE=\"text\" NAME=\"tta3tier_endticket\" VALUE=\"$tta3tier_endticket\" cols=\"7\" size=\"7\" ALIGN=left onChange=\"\">\n";
 print "        <tr><td valign=top>",&hlink("<b>$text{'f_ticketcounter'}</b>","fticketcounter"),"&nbsp;</td>\n";
 print "        <td valign=top><input TYPE=\"text\" NAME=\"tta3tier_ticketcounter\" VALUE=\"$tta3tier_ticketcounter\" cols=\"5\" size=\"5\" ALIGN=left onChange=\"isNroThis(this)\">\n";

 print "   <tr><td valign=top>",&hlink("<b>$text{'f_doifendticket'}</b>","fdoifendticket"),"&nbsp;</td><td valign=top><select NAME=\"tta3tier_doifendticket\">\n";
 print "                <option VALUE=\"none\">",&hlink("<b>$text{'f_doifendticket_sel'}</b>","f_doifendticket_sel"),"\n";
 
@l_target = split(/,/,$text{'ticket_ifend_value'}, -1);
$nItems=0;
foreach $item (@l_target) {
     print "         <option ";
     if ( $item eq $tta3tier_doifendticket ) { print "selected " ; }
     print "VALUE=\"$item\" ";
     $targetext='ticket_'.$item.'_tit';
     print ">$text{$targetext}</b>\n";
     $nItems++;
}
print "        </select></td></tr>\n";

print "</td></tr>\n";
}

#script_cache_chek()
#Print javascript lines to check "ttacacheapp" object input fields
#
sub script_cache_chek
{
    print "     if ( emptyField(obj.tta3tier_login) == false ) {\n";
    print "          if ( emptyField(obj.tta3tier_password) == true ) {\n";
    print "                 alert(obj.tta3tier_password.name+\":\"+msg1+\"->\"+obj.tta3tier_password.value+\"<-\");\n";
    print "                 obj.tta3tier_password.focus();\n";
    print "                 return false;\n";
    print "          }\n";
    print "          if ( emptyField(obj.tta3tier_title) == true ) {\n";
    print "                 alert(obj.tta3tier_title.name+\":\"+msg1+\"->\"+obj.tta3tier_title.value+\"<-\");\n";
    print "                 obj.tta3tier_title.focus();\n";
    print "                 return false;\n";
    print "          }\n";
    print "          nro=parseInt(obj.tta3tier_maxsess.value);\n";
    print "          if ( nro+1 > 0) { \n";
    print "               obj.tta3tier_maxsess.value=nro;\n";
    print "          } else {;\n";
    print "               alert(obj.tta3tier_maxsess.name+\":\"+msg1+\"->\"+obj.tta3tier_maxsess.value+\"<-\");\n";
    print "               obj.tta3tier_maxsess.focus();\n";
    print "               return false;\n";
    print "          };\n";
    print "          if ( get_value(\"select\",obj.tta3tier_ticketstatus) == \"none\" ) {\n";
    print "                alert(obj.tta3tier_ticketstatus.name+\":\"+msg1+\"->\"+obj.tta3tier_ticketstatus.value+\"<-\");\n";
    print "                      obj.tta3tier_ticketstatus.focus();\n";
    print "                      return false;\n";
    print "          }   \n";
    print "          if ( get_value(\"select\",obj.tta3tier_ticketstatus) != \"no\" ) {\n";
    print "               if ( emptyField(obj.tta3tier_endticket) == true ) {\n";
    print "                      alert(obj.tta3tier_endticket.name+\":\"+msg1+\"->\"+obj.tta3tier_endticket.value+\"<-\");\n";
    print "                      obj.tta3tier_endticket.focus();\n";
    print "                      return false;\n";
    print "               }\n";
    print "               nro=parseInt(obj.tta3tier_ticketcounter.value);\n";
    print "               if ( nro+1 > 0) { \n";
    print "                    obj.tta3tier_ticketcounter.value=nro;\n";
    print "               } else {;\n";
    print "                    alert(obj.tta3tier_ticketcounter.name+\":\"+msg1+\"->\"+obj.tta3tier_ticketcounter.value+\"<-\");\n";
    print "                    obj.tta3tier_ticketcounter.focus();\n";
    print "                    return false;\n";
    print "               };\n";
    print "               if ( emptyField(obj.tta3tier_doifendticket) == \"none\" ) {\n";
    print "                      alert(obj.tta3tier_doifendticket.name+\":\"+msg1+\"->\"+obj.tta3tier_doifendticket.value+\"<-\");\n";
    print "                      obj.tta3tier_doifendticket.focus();\n";
    print "                      return false;\n";
    print "               }\n";
    print "          }   \n";
    print "     }\n";
}

# htmlCacheShowPassw(msgObj,formObj)
# Display all htmls labels to get input for "ttacacheapp" object 
sub htmlCacheaShowPassw
{
 print "/******************************************************************\n"; 
 print "   showPasswd(formObj)\n"; 
 print "   Show Password value from form.\n"; 
 print "*******************************************************************/\n"; 
 print "function showPasswd(formObj) {\n"; 
 print "   alert(\"Password:\"+formObj.tta3tier_password.value+\"\");\n"; 
 print "}\n"; 
}

# htmlCheckAlias
# Out javascript to control aliases, it is need to get @_ with hash object list
sub htmlCheckAlias
{
  local (%h_obj);         

  print "/******************************************************************\n"; 
  print "   checkAlias_$_[0](Obj)\n"; 
  print "   checkAlias from the array and return false is already exist\n"; 
  print "*******************************************************************/\n"; 
  print "function checkAlias_$_[0](Obj) {\n"; 
  print "   var isalready = false; \n";
  print "   var listAlias = new Array();\n"; 
  if ( "$_[0]" eq "hostaddress" ) {
       %h_obj=&list_hosts();
  } else {
       %h_obj=eval("\&list_$_[0]()");
  }
  $nItem=0;
  foreach $item (keys (%h_obj)) {
      if ( "$_[0]" eq "hostaddress" ) {
         if ( $ipaddress eq "" && $h_obj{$item}->{'ipname'} ne $ipaddress ) { 
              print " listAlias[".$nItem++."] = \"".$h_obj{$item}->{'ipname'}."\";\n";
         }
      } else {
         print " listAlias[".$nItem++."] = \"".$h_obj{$item}->{'alias'}."\";\n";
      }
  }
  print "   \n"; 
  print "   for (var i=0; i < listAlias.length; i++) {\n"; 
  print "       if ( Obj.value == listAlias[i] ) { \n"; 
  print "            isalready = true; \n";
  print "            break;\n"; 
  print "       }\n"; 
  print "   }\n"; 
  print "   if ( isalready == true ) { \n"; 
  print "          alert(Obj.name+\":\"+msg1+\"->\"+Obj.value+\"<-\");\n";
  print "                    Obj.focus();\n";
  print "   }\n"; 
  print "   return isalready;\n"; 
  print "}\n"; 
}

# htmlWinLdapUsers(msgObj,formObj)
# Open Window to show Users
sub htmlWinLdapUsers
{
 print "<input type=button onClick='window.open(\"tta_selusr.cgi?form=winldapusers\", \"selusr\", \"toolbar=no,menubar=no,scrollbar=yes,width=750,height=450\")' value=\"?\">\n";
}

sub outicons_table
# This is to output code for the "Tabs" interface menu 
{
          local ($i) = 0;
          foreach $lnk (@olinks) {
             print "<td valign=top align=center width=$per\%>\n";
             print "<table border bgcolor=#ffffff><tr><td><a href=$lnk>",
                   "<img src=$oicons[$i] alt=\"\" border=0></a>",
                   "</td></tr></table>\n";
             print "<a href=$lnk>$otitles[$i]</a></td>\n";
             $i++;
             if ($pos++ % $cols == $cols - 1) { print "</tr><tr>\n"; }
          }
          while($pos++ % $cols) {
                print "<td width=$per\%></td>\n";
          }
          print "</tr><tr>\n"; 
}

sub outconfig_icons
{
	local($i);
        local ($n) = 0;
	for($i=2; $i<@_; $i++) {
             print "<td valign=top align=center width=$per\%>\n";
             print "<table border bgcolor=#ffffff><tr><td><a href=$_[$i]->{'link'}>",
                   "<img src=$_[$i]->{'icon'} alt=\"\" border=0></a>",
                   "</td></tr></table>\n";
             print "<a href=$_[$i]->{'link'}>$_[$i]->{'name'}</a></td>\n";
             $n++;
             if ($pos++ % $cols == $cols - 1) { print "</tr><tr>\n"; }
        }
        while($pos++ % $cols) {
                print "<td width=$per\%></td>\n";
        }
        print "</tr><tr>\n"; 
}

# html_objlink($type,$object,%{$p},$anchor,$_[4]);
# $_[4] = return | print | docwrite
sub html_objlink
{
   local $text_str="";
   local $html_str="<head><title>STTA: $_[3]</title></head>";

   return undef if (!%{$_[2]}); 
 
        $no_out=0;
        &show_hash(\%{$_[2]},"","=","",\$text_str);
        $text_str=~s/\n/<\/tr><tr><td>/g;
        $text_str=~s/===/<\/td><td>/g;
        $html_str.="<table width=100% border><tr $tb> <td><b>$_[0]: $_[1]</b></td></tr>";
        $html_str.="<tr $cb> <td><table width=100%><td>";
        $html_str.="<tr><td>$text_str</td></tr>";
        $html_str.="</td></tr></table></table>";
   if ( $_[4] eq "print" ) {
        print "<A onClick=\"javascript:w_name=window.open('', 'obj','toolbar=no,menubar=no,scrollbars=yes,width=800,height=300,resizable=yes');w_name.document.writeln('$html_str');w_name.document.close();return false\" href=\"javascript:\" >$_[3]</A>";
   } elsif ( $_[4] eq "docwrite" ) {
        return "<A onClick=\\\"javascript:w_name=window.open('', 'obj','toolbar=no,menubar=no,scrollbars=yes,width=800,height=300,resizable=yes');w_name.document.writeln('$html_str');w_name.document.close();return false\\\" href='javascript:' ><b>$_[3]</b></A>";
   } else {
        return "<A onClick=\"javascript:w_name=window.open('', 'obj','toolbar=no,menubar=no,scrollbars=yes,width=800,height=300,resizable=yes');w_name.document.writeln('$html_str');w_name.document.close();return false\" href=\"javascript:\" >$_[3]</A>";
   }

}
sub html_errshow
{
    local $where_err = $_[0]; 

    print "<hr><table width=100% border><tr></tr><tr $cb><td align=center>\n";
    if ( "$where_err" eq "ldap-rep" )  {
            print "($dn):<br><b>".$text{'replica_err'} ."-->".$line_conn."</b><br>\n";
            print "<b> ".$text{'replica_msg'} ."</b><br>\n";
    } elsif ( "$where_err" eq "tta" )  {
            print "<b>$text{f_error}: $text{'msgerr_tta'}</b><br>\n";
    } 
    if ( $err_msg ) { print "<b>$err_msg</b><br>\n"; }
    if ( $err gt 0 ) {
        print "$text{f_error} ($err):<b>".eval("\$text{'msgerr_$err'}")."</b><br>\n";
    }
    if ( $debug gt 0 ) { print &text('viewlog_action',$stta_sid); }
    print "<tr><tr></table>\n";

}
1;  # Return true
