# -----------------------------------------------------------------------------
#
#   Copyright (c) 1999-2002 by Klaus Reger <K.Reger@wwwdb.org>
#
#   You may distribute under the terms of either the GNU General Public
#   License or the Artistic License, as specified in the Perl README file.
#
#   THIS IS BETA SOFTWARE!
#
#   THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
#   IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
#   WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
#
#   $Id: CreateAppRc_0.pl,v 1.1 2002/11/18 14:57:59 k_reger Exp $
#
# -----------------------------------------------------------------------------
# Program-Data
# -----------------------------------------------------------------------------
# Project  :
# System   :
# Program  :
# Module   : $RCSfile: CreateAppRc_0.pl,v $
# Version  : $Revision: 1.1 $
# Date     : $Date: 2002/11/18 14:57:59 $
# State    : $State: Exp $
#
# Description:
#   Select a database
#
# -----------------------------------------------------------------------------
# Change-log (See at end of this file)
# $Log: CreateAppRc_0.pl,v $
# Revision 1.1  2002/11/18 14:57:59  k_reger
# - Target-Db added
#
#
# --- Known Bugs -------------
# 
# --- TODO -------------------
# 
# ----------------------------------------------------------------------------
use vars qw($oSessionGL);
use strict;

sub PreCreateForm ()
{
   my $cRecord;
   my $pDbHdl;
   my $pStmtHdl;
   my @lResult = ();
	   
   &SetField("DbDriver", &MyVal('DB', 'Driver'));
   &SetField("Database",
			 $oSessionGL->getState("CreateAppRc,Database") ||
			 &MyVal('DB', 'Driver'));
   &SetField("Host",
			 $oSessionGL->getState("CreateAppRc,Host"));
   &SetField("User",
			 $oSessionGL->getState("CreateAppRc,User"));
   &SetField("Password",
			 $oSessionGL->getState("CreateAppRc,Password"));
 

   @lResult = DBI->data_sources(&GetField("DbDriver"));

   foreach (@lResult)
   {
      # Remove the dbi:driver:-part
      s/(.*:)([^:]+)/$2/;


      # remove the description, if it exists
      if(/(.*)=(.*)/)
      {
         $_ = $2;
      }
   }

   &SetField("Database", &MyVal('DB', 'Database'));

   &MySetVal("Layout Field Database", "Values",
             join "\n", @lResult);
}


sub Check_DbRc_DbDriver()
{
   &AddError("Database", "Please select a database")
       if(!&GetField("Database"));
}



sub MyBtnNext ()
{
   &CheckRecord();

   if(!&GetField("Database"))
   {
      &GenPage();
   }
   else
   {
      $oSessionGL->setState("CreateAppRc,Database", &GetField("Database"));
      $oSessionGL->setState("CreateAppRc,User",     &GetField("User"));
      $oSessionGL->setState("CreateAppRc,Password", &GetField("Password"));
	  $oSessionGL->setState("CreateAppRc,DbTable",  &GetField("DbTable"));

      print &Redirect(&GetAttr("SessionId"), "WWWdb:Wiz:CreateAppRc_1;use_session");
   }
}


1;






