#!/usr/bin/perl
# tta_sessbill.cgi
# Display Services with Tarantella Sessions Counters
# 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();
&foreign_require("proc", "proc-lib.pl");

 if ($access{'sessions'} ne 1 ) { &redirect("index.cgi"); }
 if ( $config{'tta_billing_dir'} eq "" ) {
     &headerstta($text{'index_ttasess_bill'}, "", "ttasess_bill",undef,1,0,"$text{'headpage_right'}"."$text{'head_logout'}",undef,undef,"$text{head_below}" );
         $err_msg=$text{'nohasbillsess_err'};
         &footHere;
         exit;
 } 
 $now = time();
 $ahora=&set_now($now);
 $ahora_str=set_datetime_str($ahora);

 &headerstta($text{'index_ttasess_bill'}, "", "ttasess_bill",undef,1,0,"$text{'headpage_right'}"."$text{'head_logout'}",undef,undef,"$text{head_below}" );
 print "<table width=100% border>\n";
 print "<tr $tb> <td><font color='$revtext'><b>$text{'titidx_ttasess_bill'}  $ahora </b></td> </tr>\n";
 print "<tr><td><table width=100%>\n";
 print "<tr $cb><td><table width=100%>\n";

 $file = $in{file};
 $datafrom = $in{datafrom};
 $outReport = $in{outreport};
 $outFormat = $in{format};
 $outDir = $in{outdir};
 $startdate = $in{startdate};
 $enddate = $in{enddate};
 if ( $datafrom eq "tta" && $startdate && $enddate ) {
     $outFile = &tempname();
     $type_cmd="billing";
     $str="$config{'tta_aliascmd'} query billing --full --start $startdate --end $enddate >$outFile";
     &run_tta_cmd($type_cmd);
     if ( -s $outFile ) {
         $file=$outFile;
     } else {
         &html_errshow("tta")
     }
 }
 if (!$file) { 
     print "<tr $cb><td><table align=left>\n";
     print "<tr><form METHOD=POST name=loadusrs ACTION=\"tta_sessbilling.cgi\" >\n"; 
     if ( $datafrom eq  "file"  ) {
           print "<td valign=top>",&hlink("<b>$text{'f_filelistName'}</b>","fbillingfile"),"&nbsp;";
           print "<td valign=top><input TYPE=\"text\" NAME=\"file\" VALUE=\"\" cols=\"52\" size=\"52\" ALIGN=left ", &file_chooser_button("file",0,0,$config{tta_billing_dir})," ($config{tta_billing_dir})</td></tr>\n";
     }
     if ( $datafrom eq "tta" ) {
           $enddate=`date +%Y/%m/%d`;
           print "<tr><td valign=top>",&hlink("<b>$text{'f_billstartdate'}</b>","fbillstartdate"),"&nbsp;</td>\n";
           print "<td valign=top><input TYPE=\"text\" NAME=\"startdate\" VALUE=\"\" cols=\"20\" size=\"20\"></td></tr>\n";
           print "<tr><td valign=top>",&hlink("<b>$text{'f_billenddate'}</b>","fbillstartdate"),"&nbsp;\n";
           print "<td valign=top><input TYPE=\"text\" NAME=\"enddate\" VALUE=\"$enddate\" cols=\"20\" size=\"20\"></td></tr>\n";
     }
     if ( !$datafrom ) {
           print "<tr><td valign=top>\n";
           print "<input type=radio name=\"datafrom\" value=\"tta\" checked >&nbsp;\n";
           print "$text{index_ttasess_bill} &nbsp;";
           print "<input type=radio name=\"datafrom\" value=\"file\" >&nbsp;\n";
           print "$text{f_loadfile} &nbsp;\n";
           print "</td>\n";
           print "<td><input type=checkbox name=\"outreport\" value=\"true\" >\n";
           print "$text{f_makereportbill} &nbsp;\n";
           print "</td>\n";
     } else {
          print "<tr><td valign=top><input TYPE=\"hidden\" NAME=\"datafrom\" VALUE=\"$datafrom\"></td></tr>\n";
          print "<tr><td valign=top><input TYPE=\"hidden\" NAME=\"outreport\" VALUE=\"$outReport\"></td></tr>\n";
    }
     if ( $outReport eq "true" ) {
           print "<td valign=top>",&hlink("<b>$text{'f_dirbillout'}</b>","fdirbillout"),"&nbsp;";
           print "<td valign=top><input TYPE=\"text\" NAME=\"outdir\" VALUE=\"".&out_now_filename($now)."\" cols=\"52\" size=\"52\" ALIGN=left ", &file_chooser_button("outdir",1,0,$config{tta_billing_dir}),"</td></tr>\n";
           print "   <tr><td valign=top>",&hlink("<b>$text{'f_formatbillout'}</b>","fformatbillout"),"&nbsp;</td><td valign=top><select NAME=\"format\">\n";
           print " <option VALUE=\"html\" >".$text{format_html}."\n";
           print " <option VALUE=\"cvs\" >".$text{format_cvs}."\n";
           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></tr>\n";
     print "	</form>\n"; 
     print "</td></tr></table>\n"; 
#     print "<tr $tb> <td><font color='$revtext'><b>$text{'load_data'}</b></td></tr>\n";
     print "</td></tr></table>\n"; 
 } else {
     if ( $outReport eq  "true"  ) {
          $outdir="$config{tta_billing_dir}/$outDir";
	  if ( ! -d $outdir ) { system("mkdir $outdir") }
          print "<tr><td><h2>$text{f_makereportbill} &nbsp; $outdir</h2</td></tr>\n";
     }
     if ( $datafrom eq  "file"  ) {
          $billing_logfile="$config{tta_billing_dir}/$file";
          $licenseinfo_file="$config{tta_billing_dir}/licenseinfo";
     }
     if ( $datafrom eq  "tta"  ) {
          $billing_logfile=$file;
          $licenseinfo_file="$config{tta_dir}/var/info/licenseinfo";
     }
     &out_billingdata();
 } 
 print "</td></tr></table>\n"; 

 print "</td></tr></table>\n"; 
 print "</table>\n"; 
 &footer($config{'back_return'},$text{'index'});
 print "<p><p><p>\n";
 do "footer.pl";
 exit;


sub out_billingdata
{

         $nlines=0;
         $nemuls=0;
         $napps=0;
         print "<tr><td><ul></td></tr>\n";
         print "<tr ><td valign=\"center\"> <li><a class=\"menu1\" href=\"#data\"> $text{l_data} </a></li></td></tr>\n";
         print "<tr><td valign=\"center\"> <li><a class=\"menu1\" href=\"#licenseinfo\"> $text{licenseinfo} </a></li></td></tr>\n";
         print "<tr><td valign=\"center\"> <li><a class=\"menu1\" href=\"#users\"> $text{index_users} </a></li></td></tr>\n";
         print "<tr><td valign=\"center\"> <li><a class=\"menu1\" href=\"#ous\"> $text{index_ous} </a></li></td></tr>\n";
         print "<tr><td valign=\"center\"> <li><a class=\"menu1\" href=\"#hosts\"> $text{index_hosts} </a></li></td></tr>\n";
         print "<tr><td valign=\"center\"> <li><a class=\"menu1\" href=\"#grphosts\"> $text{index_grphosts} </a></li></td></tr>\n";
         print "<tr><td valign=\"center\"> <li><a class=\"menu1\" href=\"#apps\"> $text{index_apps} </a></li></td></tr>\n";
         print "<tr><td valign=\"center\"> <li><a class=\"menu1\" href=\"#grpapps\"> $text{index_grpapps} </a></li></td></tr>\n";
         print "</ul><tr><td></td></tr>\n";
         print "<tr $cb><td><a name=\"data\"></td></tr>\n";
         print "<tr><td><table width=100%>\n";
         print "<tr $tb><td><h2><b><font color='$revtext'>$text{l_data}</font></b></h2></td></tr>\n";
         print "<tr><td><table align=\"center\" border>\n";
         print "<tr $tb>\n";
         print "<TD><center><B></B></center></TD>\n";
         print "<TD><center><B>".$text{l_ses_user} . "</B></center></TD>\n";
         print "<TD><center><B>".$text{l_ses_app} . "</B></center></TD>\n";
         print "<TD><center><B>".$text{l_ses_appsrv} . "</B></center></TD>\n";
         print "<TD><center><B>".$text{l_time} . "</B></center></TD>\n";
         print "<TD><center><B>".$text{l_ses_num} . "</B></center></TD>\n";
         print "<TD><center><B>".$text{l_servtta} . "</B></center></TD>\n";
         print "</tr>\n";
         if ( $outReport eq  "true"  ) { open (OUTRPTBILL, ">$outdir/data.$outFormat"); }
         open(BILLLOG, $billing_logfile);
         while(<BILLLOG>) {
              @line=split(/,/, $_,-1);               
              if ( $line[0] eq "report" ) {
                   $report_date=$line[5];
                   if ( $outReport eq  "true"  ) {
                        if  ( $outFormat eq "html" ) {
                            print OUTRPTBILL "<html><head></head><body><h1>$text{l_data}: $report_date </h1><br><hr>\n";
                            print OUTRPTBILL "<table><tr><td><table align=\"center\" border>\n";
                            print OUTRPTBILL "<tr $tb>\n";
                            print OUTRPTBILL "<TD><center><B>".$text{l_ses_user} . "</B></center></TD>\n";
                            print OUTRPTBILL "<TD><center><B>".$text{l_ses_app} . "</B></center></TD>\n";
                            print OUTRPTBILL "<TD><center><B>".$text{l_ses_appsrv} . "</B></center></TD>\n";
                            print OUTRPTBILL "<TD><center><B>".$text{l_time} . "</B></center></TD>\n";
                            print OUTRPTBILL "<TD><center><B>".$text{l_ses_num} . "</B></center></TD>\n";
                            print OUTRPTBILL "<TD><center><B>".$text{l_servtta} . "</B></center></TD>\n";
                            print OUTRPTBILL "</tr>\n";
                        } elsif  ( $outFormat eq "cvs" ) {
                            print OUTRPTBILL "$_";
                        }
                   }
                   next;
              }
              $ttaServer=$line[1];
              $UserName=$line[2];
              $UserName=~s/%2c/,/g;
              $AppName=$line[3];
              $AppName=~s/%2c/\//g;
              $HostName=$line[4];
              &scan_envsess();
              &alias_envsess();
              print "<tr $cb>\n";
              if ( $outReport eq "true" && $outFormat eq "html") { print OUTRPTBILL "<tr $cb>\n"; }
              if ( $debug gt 1 ) {
                  $lineOut=$_;
                  $lineOut=~s/,/\\n/g;
                  print "<td><a class=\"menu1\" href=\"javascript: alert('".$lineOut."')\">?</td>\n";
              }
             if ( ( $line[0] eq "webtop" ) ||
                  ( $prevNameUser ne $NameUser && $prevOuName ne $OuName )) {
                  print "<td>$NameUser <br> $OuName</td>\n";
                  if ( $outReport eq "true" && $outFormat eq "html") { 
                      print OUTRPTBILL "<td>$NameUser <br> $OuName</td>\n";
                  }
                  $prevNameUser=$NameUser;
                  $prevOuName=$OuName;
             } else {
                  if ( $outReport eq "true" && $outFormat eq "html") { 
                       print OUTRPTBILL "<td></td>\n";
                  }
                  print "<td></td>\n";
             }
             if ( $line[0] eq "webtop" ) {
                  $nemuls=$nemuls+1;
             } elsif ( $line[0] =~  "appl" ) {
                  $napps=$napps+1;
             }
             $nlines=$nlines+1;
             print "<td><b>$NameApp</b> <br> $NameAppGrp</td>\n";
             print "<td><b>$NameHost</b> <br> $NameHostGrp</td>\n";
             print "<td>$line[5]</td>\n";
             print "<td>$line[6]</td>\n";
             print "<td>$line[1]</td>\n";
             print "</tr>\n";
             if ( $outReport eq "true" ) { 
                  if  ( $outFormat eq "html" ) {
                       print OUTRPTBILL "<td><b>$NameApp</b> <br> $NameAppGrp</td>\n";
                       print OUTRPTBILL "<td><b>$NameHost</b> <br> $NameHostGrp</td>\n";
                       print OUTRPTBILL "<td>$line[5]</td>\n";
                       print OUTRPTBILL "<td>$line[6]</td>\n";
                       print OUTRPTBILL "<td>$ttaServer</td>\n";
                       print OUTRPTBILL "</tr>\n";
                  } elsif  ( $outFormat eq "cvs" ) {
                       print OUTRPTBILL "$line[0],$ttaServer";
                       $str="$NameUser/$OuName";
                       $str=~s/,/\//g;
                       print OUTRPTBILL ",$str";
                       $str="$NameApp/$NameAppGrp";
                       $str=~s/,/\//g;
                       print OUTRPTBILL ",$str";
                       $str="$NameHost/$NameHostGrp";
                       $str=~s/,/\//g;
                       print OUTRPTBILL ",$str";
                       print OUTRPTBILL "$line[5],$line[6]";
                  }
             }
	     &count_objects(); 
         }
         close(BILLLOG);
         if ( $outReport eq  "true"  ) { 
            if  ( $outFormat eq "html" ) {
                  print OUTRTPBILL "</table><tr $cb><td></td><tr>\n";
                  print OUTRTPBILL "<tr $tb><td><b><b><font color='$revtext'>".&text('l_billtotal',$report_date,$nlines,$nemuls,$napps)."</b></td></tr>\n";
                  print OUTRPTBILL "</body></html>\n";
            }
            close (OUTRPTBILL);
         }
         print "</table></table><tr $cb><td></td><tr>\n";
         print "<tr $tb><td><b><b><font color='$revtext'>".&text('l_billtotal',$report_date,$nlines,$nemuls,$napps)."</b></td></tr>\n";
         &out_licenseinfo();
         &out_sumobj(\%h_users,$text{index_users},"users");
         &out_sumobj(\%h_grpusers,$text{index_ous},"ous");
         &out_sumobj(\%h_hosts,$text{index_hosts},"hosts");
         &out_sumobj(\%h_grphosts,$text{index_grphosts},"grphosts");
         &out_sumobj(\%h_apps,$text{index_apps},"apps");
         &out_sumobj(\%h_grpapps,$text{index_grpapps},"grpapps");
         print "<tr $cb><td></td><tr>\n";
}
sub out_sumobj
{
    local %h_sumobj=%{$_[0]};
    local $titleTable=$_[1];
    local $linkName=$_[2];
    local $sumNum=0;
    local $sumCount=0;
    local @sumobj=();

    foreach $item (keys (%h_sumobj)) { push (@sumobj, $h_sumobj{$item}); }
    if ( $#sumobj < 0 ) { return };
    print "<tr $cb><td><a name=\"$linkName\"></td></tr>\n";
    print "<tr><td><table align=\"center\" width=100%>\n";
    print "<tr $tb><td><h2><b><font color='$revtext'>$titleTable</font></b></h2></td></tr>\n";
    print "<tr><td><table align=\"center\" border>\n";
    print "<tr $tb>\n";
    print "<TD><center><B>".$text{l_ses_object} . "</B></center></TD>\n";
    print "<TD><center><B>".$text{l_ses_num} . "</B></center></TD>\n";
    print "<TD><center><B>".$text{l_time} . "</B></center></TD>\n";
    print "<TD><center><B>".$text{l_group} . "</B></center></TD>\n";
    print "<TD><center><B>".$text{l_servtta} . "</B></center></TD>\n";
    print "</tr>\n";
    if ( $outReport eq  "true"  ) { 
         open (OUTRPTBILL, ">$outdir/$linkName.$outFormat"); 
         if  ( $outFormat eq "html" ) {
            print OUTRPTBILL "<html><head></head><body><h1>$titleTable: $report_date </h1><br><hr>\n";
            print OUTRPTBILL "<tr><td><table align=\"center\" border>\n";
            print OUTRPTBILL "<tr $tb>\n";
            print OUTRPTBILL "<TD><center><B>".$text{l_ses_object} . "</B></center></TD>\n";
            print OUTRPTBILL "<TD><center><B>".$text{l_ses_num} . "</B></center></TD>\n";
            print OUTRPTBILL "<TD><center><B>".$text{l_time} . "</B></center></TD>\n";
            print OUTRPTBILL "<TD><center><B>".$text{l_group} . "</B></center></TD>\n";
            print OUTRPTBILL "<TD><center><B>".$text{l_servtta} . "</B></center></TD>\n";
            print OUTRPTBILL "</tr>\n";
         }
    }
    foreach $item (keys (%h_sumobj)) {
          print "<tr $cb>\n";
          print "<td><b>" . $h_sumobj{$item}->{'name'}."</b></td>\n";
          print "<td>" . $h_sumobj{$item}->{'count'}."</td>\n";
          print "<td>" . $h_sumobj{$item}->{'num'}."</td>\n";
          print "<td>". $h_sumobj{$item}->{'grpname'}."</td>\n";
          print "<td>" . $h_sumobj{$item}->{'ttaserv'}."</td>\n";
          print "</tr>\n";
          if ( $outReport eq "true" ) { 
                  if  ( $outFormat eq "html" ) {
                        print OUTRPTBILL "<tr $cb>\n";
                        print OUTRPTBILL "<td><b>" . $h_sumobj{$item}->{'name'}."</b></td>\n";
                        print OUTRPTBILL "<td>" . $h_sumobj{$item}->{'count'}."</td>\n";
                        print OUTRPTBILL "<td>" . $h_sumobj{$item}->{'num'}."</td>\n";
                        print OUTRPTBILL "<td>". $h_sumobj{$item}->{'grpname'}."</td>\n";
                        print OUTRPTBILL "<td>" . $h_sumobj{$item}->{'ttaserv'}."</td>\n";
                        print OUTRPTBILL "</tr>\n";
                   } elsif  ( $outFormat eq "cvs" ) {
                        $str= $h_sumobj{$item}->{'name'};
                        $str=~s/,/\//g;
                        print OUTRPTBILL "$str";
                        print OUTRPTBILL "," . $h_sumobj{$item}->{'count'};
                        print OUTRPTBILL "," . $h_sumobj{$item}->{'num'};
                        $str= $h_sumobj{$item}->{'grpname'};
                        $str=~s/,/\//g;
                        print OUTRPTBILL ",$str";
                        print OUTRPTBILL "," . $h_sumobj{$item}->{'ttaserv'}."\n";
                  }
          }
          $sumNum=$sumNum+$h_sumobj{$item}->{'num'};
          $sumCount=$sumCount+$h_sumobj{$item}->{'count'};
    }
    print "<tr><td></td><td></td><td></td><td></td></tr>\n";
    print "<tr $cb><td><b>$text{total}</b></td>\n";
    print "<td>$sumCount</td>\n";
    print "<td>$sumNum</td>\n";
    print "<td>&nbsp;</td>\n";
    print "<td>&nbsp;</td>\n";
    print "</tr>\n";
    print "</table></table></td></tr>\n";
    if ( $outReport eq  "true"  ) { 
         if  ( $outFormat eq "html" ) {
               print OUTRPTBILL "<tr><td></td><td></td><td></td><td></td></tr>\n";
               print OUTRPTBILL "<tr $cb><td><b>$text{total}</b></td>\n";
               print OUTRPTBILL "<td>$sumCount</td>\n";
               print OUTRPTBILL "<td>$sumNum</td>\n";
               print OUTRPTBILL "<td>&nbsp;</td>\n";
               print OUTRPTBILL "<td>&nbsp;</td>\n";
               print OUTRPTBILL "</tr>\n";
               print OUTRPTBILL "</table></body></html>\n";
         }
         close (OUTRPTBILL);
    }
}

sub count_objects
{
            if ( $NameHost ne "" ) { 
                 if ( !defined($h_hosts{$NameHost}->{'name'}) ||
                      $h_hosts{$NameHost}->{'ttaserv'} ne $ttaServer ) {
                      $h_hosts{$NameHost}->{'count'}=1;
                      $h_hosts{$NameHost}->{'name'}=$NameHost;
                      $h_hosts{$NameHost}->{'grpname'}=$NameHostGrp;
                      $h_hosts{$NameHost}->{'ttaserv'}=$ttaServer;
                      $h_hosts{$NameHost}->{'num'}=$line[6];
                 } else {
                      $h_hosts{$NameHost}->{'count'}= $h_hosts{$NameHost}->{'count'}+1;
                      $h_hosts{$NameHost}->{'num'}= $h_hosts{$NameHost}->{'num'}+$line[6];
                 }
                 if ( $NameHostGrp  ne "" ) { 
                      if ( !defined($h_grphosts{$NameHostGrp}->{'name'}) || 
                           $h_grphosts{$NameHostGrp}->{'ttaserv'} ne $ttaServer ) {
                           $h_grphosts{$NameHostGrp}->{'count'}=1;
                           $h_grphosts{$NameHostGrp}->{'name'}=$NameHostGrp;
                           $h_grphosts{$NameUser}->{'ttaserv'}=$ttaServer;
                           $h_grphosts{$NameHostGrp}->{'num'}=$line[6];
                      } else {
                           $h_grphosts{$NameHostGrp}->{'count'}= $h_grphosts{$NameHostGrp}->{'count'}+1;
                           $h_grphosts{$NameHostGrp}->{'num'}=$h_grphosts{$NameHostGrp}->{'num'}+$line[6];
                      }
                }
            }
            if ( $NameApp ne "" ) { 
                 if ( !defined($h_apps{$NameApp}->{'name'}) ||
                      $h_apps{$NameApp}->{'ttaserv'} ne $ttaServer ) {
                      $h_apps{$NameApp}->{'count'}=1;
                      $h_apps{$NameApp}->{'name'}=$NameApp;
                      $h_apps{$NameApp}->{'grpname'}=$NameAppGrp;
                      $h_apps{$NameApp}->{'ttaserv'}=$ttaServer;
                      $h_apps{$NameApp}->{'num'}=$line[6];
                 } else {
                      $h_apps{$NameApp}->{'count'}= $h_apps{$NameApp}->{'count'}+1;
                      $h_apps{$NameApp}->{'num'}=$h_apps{$NameApp}->{'num'}+$line[6];
                 }
                 if ( $NameAppGrp  ne "" ) { 
                      if ( !defined($h_grpapps{$NameAppGrp}->{'name'}) ||
                           $h_grpapps{$NameAppGrp}->{'ttaserv'} ne $ttaServer ) {
                           $h_grpapps{$NameAppGrp}->{'count'}=1;
                           $h_grpapps{$NameAppGrp}->{'name'}=$NameAppGrp;
                           $h_grpapps{$NameAppGrp}->{'ttaserv'}=$ttaServer;
                           $h_grpapps{$NameAppGrp}->{'num'}=$line[6];
                      } else {
                           $h_grpapps{$NameAppGrp}->{'count'}= $h_grpapps{$NameAppGrp}->{'count'}+1;
                           $h_grpapps{$NameAppGrp}->{'num'}=$h_grpapps{$NameAppGrp}->{'num'}+$line[6];
                      }
                }
            }
            if ( $NameUser ne "" ) { 
                 if ( !defined($h_users{$NameUser}->{'name'}) ||
                      $h_users{$NameUser}->{'ttaserv'} ne $ttaServer ) {
                      $h_users{$NameUser}->{'count'}=1;
                      $h_users{$NameUser}->{'ttaserv'}=$ttaServer;
                      $h_users{$NameUser}->{'name'}=$NameUser;
                      $h_users{$NameUser}->{'grpname'}=$OuName;
                      $h_users{$NameUser}->{'num'}=$line[6];
                 } else {
                      $h_users{$NameUser}->{'count'}= $h_users{$NameUser}->{'count'}+1;
                      $h_users{$NameUser}->{'num'}= $h_users{$NameUser}->{'num'}+$line[6];
                 }
                 if ( $OuName ne "" ) { 
                      if ( !defined($h_grpusers{$OuName}->{'name'}) ||
                           $h_grpusers{$OuName}->{'ttaserv'} ne $ttaServer ) {
                           $h_grpusers{$OuName}->{'count'}=1;
                           $h_grpusers{$OuName}->{'name'}=$OuName;
                           $h_grpusers{$OuName}->{'ttaserv'}=$ttaServer;
                           $h_grpusers{$OuName}->{'num'}=$line[6];
                      } else {
                           $h_grpusers{$OuName}->{'count'}= $h_grpusers{$OuName}->{'count'}+1;
                           $h_grpusers{$OuName}->{'num'}=$h_grpusers{$OuName}->{'num'}+$line[6];
                      }
                }
            }
}

sub out_licenseinfo 
{
    local $nlins=0;

    if ( ! -r  $licenseinfo_file ) { return }
    print "<tr $cb><td><a name=\"licenseinfo\"></td></tr>\n";
    print "<tr><td><table align=\"center\" width=100%>\n";
    print "<tr $tb><td><h2><b><font color='$revtext'>$text{licenseinfo}</font></b></h2></td></tr>\n";
    print "<tr><td><table align=\"center\" border>\n";
    if ( $outReport eq  "true"  ) { 
         open (OUTRPTBILL, ">$outdir/licenseinfo.$outFormat"); 
         if  ( $outFormat eq "html" ) {
            print OUTRPTBILL "<html><head></head><body><h1>$text{licenseinfo}: $report_date </h1><br><hr>\n";
            print OUTRPTBILL "<tr><td><table align=\"center\" border>\n";
         }
    }
    open(LICENSEINFO, "$licenseinfo_file");
       while(<LICENSEINFO>) {
          $line=$_;               
          $line=~s/\|/<\/td><td>/g;
          if ( $nlins eq 0 ) {
              print "<tr $tb>";
          } else { 
              print "<tr $cb>";
          }
          print "<td>$line</td></tr>";
          if ( $outReport eq "true" ) { 
                  if  ( $outFormat eq "html" ) {
                        if ( $nlins eq 0 ) {
                            print OUTRPTBILL "<tr $tb>";
                        } else { 
                            print OUTRPTBILL "<tr $cb>";
                        }
                        print OUTRPTBILL "<td>$line</td></tr>";
                   } elsif  ( $outFormat eq "cvs" ) {
                        $str= $_;
                        $str=~s/|/,/g;
                        print OUTRPTBILL "$str";
                  }
          }
          $nlins=$nlins+1;
    }
    print "</table></table></td></tr>\n";
    if ( $outReport eq  "true"  ) { 
         if  ( $outFormat eq "html" ) {
               print OUTRPTBILL "</table></body></html>\n";
         }
         close (OUTRPTBILL);
    }
}
