# -----------------------------------------------------------------------------
# TWC
# Treuwert-Computer GmbH
# Schloßbergring 9
# 79098 Freiburg
#
# Author: Klaus Reger <K.Reger@twc.de>
#
# -----------------------------------------------------------------------------
# Program-Data
# -----------------------------------------------------------------------------
# Project  :
# System   :
# Program  :
# Module   : $RCSfile: Welcome.pl,v $
# Version  : $Revision: 1.5 $
# Date     : $Date: 2002/02/28 14:48:20 $
# State    : $State: Exp $
#
# Description:
#   Celledur Willkommens- Seiten (index)
# -----------------------------------------------------------------------------
# $Log: Welcome.pl,v $
# Revision 1.5  2002/02/28 14:48:20  k_reger
# - Scan-Doc removed
#
# Revision 1.4  2001/01/25 11:28:58  k_reger
# - 'text' renamed to 'document'
#
# Revision 1.3  2000/10/18 08:03:40  k_reger
# - BUGFIX: use correct language
#
# Revision 1.1  2000/09/29 11:30:57  k_reger
# -This is a welcome-screen
#
# Revision 1.3  2000/09/05 09:59:57  klaus
# - CVS-Header eingefügt
#
# -----------------------------------------------------------------------------

sub PreDoAction ()
{
   &SetField("lang", &GetAttr("Lang"));
}


sub PreCreateForm()
{
   my $cNews = h2(i18n("WWWdb-News:"));
   my $iNrOfShownNews  = 6;
   my $cTextField = &GetField("document");

   if($cTextField =~ m!^<WWWdb FILE=(.*)/>$!)
   {
      my $cContentOfFile = "";
      my $cFileName;

      $cFileName = (&GetAttr("BaseDir") .
                    "/lib/Data/wwwdb_doc/" .
                    $1);

      open TEXTFILE, "<$cFileName" or
          die sprintf(i18n("Can't open %s"), $cFileName);

      # Read a text file and print it out
      while (<TEXTFILE>)
      {
         $cContentOfFile .= $_;
      }

      &SetField("document", $cContentOfFile);
   }

   # &SetField("lang", &GetAttr("Lang"));

   # get category-info
   $plBegriffe = $oDbSessionGL->SqlSelect
       ("SELECT
           id_doc, description, document, last_change
         FROM
           wwwdb_doc
         WHERE
           lang      = ?  AND
           category  = 'news'
         ORDER BY
           last_change desc",
        &GetAttr("Lang"));

   foreach $cBegriff (@{$plBegriffe})
   {
      my $cText = $cBegriff->[2];

      # Nur den ersten Absatz anzeigen
      $cText =~ s/<(p|br)>.*$/ .../gis;

      $cNews .= &ResolveRefField("wwwdb://WWWdb:News;id=" .
                                   $cBegriff->[0] .
                                   "," .
                                   &GetAttr("Lang"),
                                   b($cBegriff->[1]));
      $cNews .= br() . $cText;
      $cNews .= p({-ALIGN => "RIGHT"},
                  ((small(small($oDbSessionGL->
                                DateFromDb($cBegriff->[3]))))));
      $cNews .= br() x 1;

      $iNrOfShownNews --;

      last
          unless $iNrOfShownNews;
   }

   &SetField("news", small($cNews));

   &SetField("document", "&nbsp;" x 100 . br() .
             &GetField("document"));

}


sub PostBtnSelect()
{
   my $cField = &GetField("document");

   $cField = &ScanDoc($cField);

   &SetField("document", $cField);
}


sub PostFirstColumn ()
{
   my $cResult = "";


   if(&IsAttribOK("ActualLogin") && &IsAttribOK("IsAdmin"))
   {
      $cResult .= (br() x 2 .
                   b(i18n("Edit:")) .
                   br().
                   li(&ResolveRefField("wwwdb://WWWdb:System:Doc;id=" .
                                       &GetField("id_doc") .
                                       "," .
                                       &GetAttr("Lang"),
                                       i18n("This document"))));
   }

   return small($cResult);

}


1;
