# -----------------------------------------------------------------------------
#
#   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_3.pl,v 1.4 2002/11/18 14:58:06 k_reger Exp $
#
# -----------------------------------------------------------------------------
# Program-Data
# -----------------------------------------------------------------------------
# Project  :
# System   :
# Program  :
# Module   : $RCSfile: CreateAppRc_3.pl,v $
# Version  : $Revision: 1.4 $
# Date     : $Date: 2002/11/18 14:58:06 $
# State    : $State: Exp $
#
# Description:
#   Set different attributes for the application-modes
#
# -----------------------------------------------------------------------------
# Change-log (See at end of this file)
# $Log: CreateAppRc_3.pl,v $
# Revision 1.4  2002/11/18 14:58:06  k_reger
# - Target-Db added
#
#
# --- Known Bugs -------------
# 
# --- TODO -------------------
# 
# ----------------------------------------------------------------------------

use strict;
use vars qw($oSessionGL $oConfPoolGL);

sub PreCreateForm ()
{
   my $cRecord;
   my $pDbHdl;
   my $pStmtHdl;
   my @lResult = ();
   my @lFields;
   my $oConfigFileTmp;
   my $oConfigFile;
   my $lAtt;

   my $cTable    = $oSessionGL->getState("CreateAppRc,DbTable");
   my $cDatabase = $oSessionGL->getState("CreateAppRc,Database") ||
	   &MyVal('DB', 'Database');

   &SetField("DbTable", $cTable);
   &MySetVal("Header", "Title",
             i18n(&MyVal("Header", "Title", "")) . " ($cTable)");
   &MySetVal("State Init", "Header",
             i18n(&MyVal("Header", "Title", "")));

   $oConfigFileTmp = ConfigFile->new
       ($oSessionGL->getState("CreateAppRc,ConfigFile"),
        ReadOnly => 0);

   # this is the config-file, we work with
   $oConfigFile = ConfigFile->new
       (&GetAttr("BaseDir") . "/lib/WWWdb/Dyn/" .
        $cDatabase . "/". $cTable . ".rc",
        ReadOnly => 0);

   # Should this field appear in query-mode
   $oConfigFileTmp->setValue("Layout Label Ruler1",
                             "Text", "<HR>");

   $oConfigFileTmp->CreateSectionAndEntries
       (["Layout Label Hdr_Qry",
         [["Text"   => i18n("Qry-Section")],
          ["Pos"    => "+2.0+5.0"],
          ["BgColor" => "#dddddd"],
          ["Bold"    => "True"],
          ["Big"    => "True"],
          ["Font"    => "Color=blue"]]],

        ["Layout Label Qry_BgColor2",
         [["Text"   => i18n("Second Background-Color for query-mode")],
          ["Pos"    => "+1.0.0"]]],
        ["Layout Field Qry_BgColor2",
         [["Pos"    => "+0.+1+4.0"],
          ["Type"   => "Text"],
          ["Size"   => "10"]]],

        ["Layout Label Qry_NrOfColLine",
         [["Text"   => i18n("After how many records should appear a " .
                            "line with the second Background-Color")],
          ["Pos"    => "+1.0.0"]]],
        ["Layout Field Qry_NrOfColLine",
         [["Pos"    => "+0.+1+4.0"],
          ["Type"   => "Select"],
          ["Size"   => "1"],
          ["Values" => (join "\n", (1 .. 20,
                                    25, 30, 35, 40, 50,
                                    100, 200, 300, 400,
                                    9999))]]])
           if ($cTable ne "UserFormat");

   $oConfigFileTmp->CreateSectionAndEntries
       (["Layout Label Hdr_State_All",
         [["Text"   => i18n("State All-Section")],
           ["Pos"    => "+1.0+5.0"],
           ["BgColor" => "#dddddd"],
           ["Bold"    => "True"],
           ["Big"    => "True"],
           ["Font"    => "Color=blue"]]],

         ["Layout Label State_All_BtnCancel",
          [["Text"   => i18n("Label for <B>Cancel</B>-Button:<BR>" .
                             "(A '-' will disable that button)")],
           ["Pos"    => "+1.0.0"]]],
         ["Layout Field State_All_BtnCancel",
          [["Pos"    => "+0.+1+4.0"],
           ["Size"   => "40"]]],

         ["Layout Label Hdr_State_Init",
          [["Text"   => i18n("State Init-Section")],
           ["Pos"    => "+1.0+5.0"],
           ["BgColor" => "#dddddd"],
           ["Bold"    => "True"],
           ["Big"    => "True"],
           ["Font"    => "Color=blue"]]],

         ["Layout Label State_Init_Header",
          [["Text"   => i18n("Header for this mode")],
           ["Pos"    => "+1.0.0"]]],
         ["Layout Field State_Init_Header",
          [["Pos"    => "+0.+1+4.0"],
           ["Size"   => "60"]]],

         ["Layout Label State_Init_BtnNew",
          [["Text"   => i18n("Label for <B>New</B>-Button:<BR>" .
                             "(A '-' will disable that button)")],
           ["Pos"    => "+1.0.0"]]],
         ["Layout Field State_Init_BtnNew",
          [["Pos"    => "+0.+1+4.0"],
           ["Size"   => "40"]]],

         ["Layout Label State_Init_BtnQry",
          [["Text"   => i18n("Label for <B>Qry</B>-Button:<BR>" .
                             "(A '-' will disable that button)")],
           ["Pos"    => "+1.0.0"]]],
         ["Layout Field State_Init_BtnQry",
          [["Pos"    => "+0.+1+4.0"],
           ["Size"   => "40"]]]);

   $oConfigFileTmp->CreateSectionAndEntries
       (["Layout Label Hdr_State_Work",
          [["Text"   => i18n("State Work-Section")],
           ["Pos"    => "+1.0+5.0"],
           ["BgColor" => "#dddddd"],
           ["Bold"    => "True"],
           ["Big"    => "True"],
           ["Font"    => "Color=blue"]]],

         ["Layout Label State_Work_Header",
          [["Text"   => i18n("Header for this mode")],
           ["Pos"    => "+1.0.0"]]],
         ["Layout Field State_Work_Header",
          [["Pos"    => "+0.+1+4.0"],
           ["Size"   => "60"]]],

         ["Layout Label State_Work_BtnUpd",
          [["Text"   => i18n("Label for <B>Upd</B>-Button:<BR>" .
                             "(A '-' will disable that button)")],
           ["Pos"    => "+1.0.0"]]],
         ["Layout Field State_Work_BtnUpd",
          [["Pos"    => "+0.+1+4.0"],
           ["Size"   => "40"]]],

         ["Layout Label State_Work_BtnDel",
          [["Text"   => i18n("Label for <B>Del</B>-Button:<BR>" .
                             "(A '-' will disable that button)")],
           ["Pos"    => "+1.0.0"]]],
         ["Layout Field State_Work_BtnDel",
          [["Pos"    => "+0.+1+4.0"],
           ["Size"   => "40"]]],

         ["Layout Label Hdr_State_Qry",
          [["Text"   => i18n("State Qry-Section")],
           ["Pos"    => "+1.0+5.0"],
           ["BgColor" => "#dddddd"],
           ["Bold"    => "True"],
           ["Big"    => "True"],
           ["Font"    => "Color=blue"]]],

         ["Layout Label State_Qry_Header",
          [["Text"   => i18n("Header for this mode")],
           ["Pos"    => "+1.0.0"]]],
         ["Layout Field State_Qry_Header",
          [["Pos"    => "+0.+1+4.0"],
           ["Size"   => "60"]]])
           if ($cTable ne "UserFormat");

   &SetField("Qry_BgColor2",
             $oConfigFile->getValue("Qry",
                                    "BgColor2",
                                    "#eeeeee"));
   &SetField("Qry_NrOfColLine",
             $oConfigFile->getValue("Qry",
                                    "NrOfColLine",
                                    "2"));
   &SetField("State_All_BtnCancel",
             $oConfigFile->getValue("State All",
                                    "BtnCancel",
                                    i18n("Back")));
   &SetField("State_Init_Header",
             $oConfigFile->getValue("State Init",
                                    "Header",
                                    i18n("Search / Create")));
   &SetField("State_Init_BtnNew",
             $oConfigFile->getValue("State Init",
                                    "BtnNew",
                                    i18n("Create")));
   &SetField("State_Init_BtnQry",
             $oConfigFile->getValue("State Init",
                                    "BtnQry",
                                    i18n("Search")));
   &SetField("State_Work_Header",
             $oConfigFile->getValue("State Work",
                                    "Header",
                                    i18n("Work with ...")));
   &SetField("State_Work_BtnUpd",
             $oConfigFile->getValue("State Work",
                                    "BtnUpd",
                                    i18n("Save")));
   &SetField("State_Work_BtnDel",
             $oConfigFile->getValue("State Work",
                                    "BtnDel",
                                    i18n("Delete")));
   &SetField("State_Qry_Header",
             $oConfigFile->getValue("State Qry",
                                    "Header",
                                    i18n("Select Data")));

   $oConfigFileTmp->WriteFile_Ini();

   $oConfPoolGL->addConfigFile ($oConfigFileTmp);

}

sub MyBtnFinish ()
{  
	my $cTable    = $oSessionGL->getState("CreateAppRc,DbTable");
	my $cDatabase = $oSessionGL->getState("CreateAppRc,Database") ||
		&MyVal('DB', 'Database');

   if(!&GetAttr("RecordOk"))
   {
      &GenPage();
   }
   else
   {

      &GenConfigFile();
	  
	  &Redirect(&GetAttr("SessionId"), 
				sprintf("WWWdb:Dyn:%s:%s", 
						$cDatabase,
						$cTable));
   }
}


sub MyBtnNext ()
{

   if(!&GetAttr("RecordOk"))
   {
      &GenPage();
   }
   else
   {
      GenConfigFile();

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


sub MyBtnPrev ()
{
   print &Redirect(&GetAttr("SessionId"), "WWWdb:Wiz:CreateAppRc_2");
}


sub GenConfigFile ()
{
   my $oConfigFile;
   my $cTable    = $oSessionGL->getState("CreateAppRc,DbTable");
   my $cDatabase = $oSessionGL->getState("CreateAppRc,Database") ||
	   &MyVal('DB', 'Database');

   my $cConfigDir = (&GetAttr("BaseDir") . 
					 "/lib/WWWdb/Dyn/" . 
					 $cDatabase . "/");

   $oConfigFile = ConfigFile->new
       ($cConfigDir . $cTable . ".rc",
        ReadOnly => 0);

   $oConfigFile->CreateSectionAndEntries
       (["Qry",
         [["BgColor2"    => &GetField("Qry_BgColor2")]]],
        ["Qry",
         [["NrOfColLine" => &GetField("Qry_NrOfColLine")]]],
        ["State All",
         [["Header"      => &GetField("State_All_Header")],
          ["BtnCancel"   => &GetField("State_All_BtnCancel")]]],
        ["State Qry",
         [["Header"      => &GetField("State_Qry_Header")]]],
        ["State Init",
         [["Header"      => &GetField("State_Init_Header")],
          ["BtnNew"      => &GetField("State_Init_BtnNew")],
          ["BtnQry"      => &GetField("State_Init_BtnQry")]]],
        ["State Work",
         [["Header"      => &GetField("State_Work_Header")],
          ["BtnUpd"      => &GetField("State_Work_BtnUpd")],
          ["BtnDel"      => &GetField("State_Work_BtnDel")]]]);

   $oConfigFile->WriteFile_Ini();


   system("cd $cConfigDir; " .
          "mv $cTable.rc.new $cTable.rc");

}



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


   $cResult .= (br() x 2 .
                b(i18n("See also:")) .
                li(&ResolveRefField("wwwdb://WWWdb:Wiz:CreateAppRc_0",
                                    i18n("Select database"))) .
                li(&ResolveRefField("wwwdb://WWWdb:Wiz:CreateAppRc_1",
                                    i18n("Select DB-table"))) .
                li(&ResolveRefField("wwwdb://WWWdb:Wiz:CreateAppRc_2",
                                    i18n("Select DB-fields"))) .
                li(&ResolveRefField("wwwdb://WWWdb:Wiz:CreateAppRc_2a",
                                    i18n("Field-order"))) .
                li(&ResolveRefField("wwwdb://WWWdb:Wiz:CreateAppRc_3",
                                    i18n("Mode-Information"))) .
                li(&ResolveRefField("wwwdb://WWWdb:Wiz:CreateAppRc_4",
                                    i18n("Field attributes"))) .
                li(&ResolveRefField("wwwdb://WWWdb:Wiz:CreateAppRc_5",
                                    i18n("Plugins")))
                );

   return small($cResult);

}



1;

