#!/usr/bin/perl -w
#------------------------------------------------------------------------------
# /var/config/www/cgi-bin/doc.pl - displays documentation
#
# Copyright (c) 2004  eisfair webconf team
#
# Creation:     10.10.2004
# Last Update:  $Id$
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#------------------------------------------------------------------------------

use strict;
use CGI::Carp qw(fatalsToBrowser);
use webconf_base;
use navigation;

my @args = split(/&/,$ENV{'QUERY_STRING'});

my ($package, $file, $title) = ("", "", "Documentation");
my ($doc1, $doc2, $doc3)     = ("", "", "");

foreach (0 .. $#args)
{
    if    ($args[$_] =~ /^package=(.*)/)   { $package = decode_string($1); }
    elsif ($args[$_] =~ /^title=(.*)/)     { $title   = decode_string($1); }
    elsif ($args[$_] =~ /^file=(.*)/)      { $file    = decode_string($1); }
}

$doc1 = $file;
$doc2 = "/usr/share/doc/$package/$file";
$doc3 = "/usr/share/doc/$package/$package.txt";

print_head($title, $package, "class=\"servform\"");
print_caption($title, $package, "class=\"servform\"");
print_navigation("base", "setup.menu", "setup.services.menu");
print "<pre class=\"servform\" style=\"margin-left:5%\">\n";

open(DOC, "<$doc1")  ||
open(DOC, "<$doc2")  ||
open(DOC, "<$doc3")  || die("Could not open $file, reason: $!\n");
while (<DOC>)
{
    # remove carriage return
    $_ =~ s/\12//g;

    # remove end of file (^z)
    $_ =~ s/\26//g;

    # replace ampersand by its html code
    $_ =~ s/\&/\&amp\;/g;

    # replace < and > by its html code
    $_ =~ s/\</\&lt\;/g;
    $_ =~ s/\>/\&gt\;/g;

    # replace german umlaute by its html code
    $_ =~ s/ä/\&auml\;/g;
    $_ =~ s/ö/\&ouml\;/g;
    $_ =~ s/ü/\&uuml\;/g;
    $_ =~ s/Ä/\&Auml\;/g;
    $_ =~ s/Ö/\&Ouml\;/g;
    $_ =~ s/Ü/\&Uuml\;/g;
    $_ =~ s/ß/\&szlig\;/g;

    # replace 8-bit characters by a space
    $_ =~ s/[\177-\377]/ /g;

    print "$_\n";
}
close(DOC);

print "</pre>\n";


print_foot("class=\"servform\"");

