# -----------------------------------------------------------------------------
#
#   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: AllTables.pl,v 1.1 2002/11/19 15:11:24 k_reger Exp $
#
# -----------------------------------------------------------------------------
# Program-Data
# -----------------------------------------------------------------------------
# Project  :
# System   :
# Program  :
# Module   : $RCSfile: AllTables.pl,v $
# Version  : $Revision: 1.1 $
# Date     : $Date: 2002/11/19 15:11:24 $
# State    : $State: Exp $
#
# Description:
#   Generate a site-map, using the categories and objects in the
#   database
#
# -----------------------------------------------------------------------------
# Change-log (See at end of this file)
# $Log: AllTables.pl,v $
# Revision 1.1  2002/11/19 15:11:24  k_reger
# - Generate config-files for all tables of current database
#
# Revision 1.1  2002/04/05 13:01:15  k_reger
# - New site-map
#
#
# --- Known Bugs -------------
# 
# --- TODO -------------------
# - pass parameters for categories only
# ----------------------------------------------------------------------------

use WWWdb::DbSession;
use vars qw($oDbTargetGL $oSessionGL %hParam);

use strict;
# use diagnostics;


sub PreCreateForm ()
{
	my $bAutoRedirect = 0;
	my @lUrlParams = split ";", &GetAttr("UrlParams");
	

	foreach (@lUrlParams)
	{ 
		if (/^auto$/)
		{
			$bAutoRedirect = 1;
		} 
		
	}
	
	&MySetVal("Layout Label links", "Text", &GenLinks($bAutoRedirect));
	
	return;
	
}

sub GenLinks($) 
{
	my $bAutoRedirectPI = shift;

	my $cResult = "";
	my @lResult = ();
	
	# Anonymous users are not allowed to use this application
	if($oSessionGL->getState("IsAnonymous"))
	{
		&OkForm("ERROR",
				sprintf(i18n("Sorry, please %s first as WWWdb-user!"),
						"<A HREF=" .
						&CreateReference(&GetAttr("SessionId"),
										 "WWWdb:System:Login") .
						">" .
						i18n("login") .
						"</A>"),
				"BtnExit");
		&MyExit();
	}
	
	@lResult = $oDbTargetGL->getDbHandle()->tables();

	foreach (@lResult)
	{

		# Non-admins may only non wwwdb-tables
		if(!$oSessionGL->getState("ActualLogin") ||
		   !$oSessionGL->getState("IsAdmin"))
		{
			next 
				if /^wwwdb_/;
		}

		# generate entry
		$cResult .= b(&ResolveRefField
					  (sprintf("wwwdb://WWWdb:Wiz:CreateAppRc_2;table=%s;%s",
							   $_,
							   $bAutoRedirectPI? "auto": ""),
					   " " . $_ . " ") . # " " suppresses translation
					  br());
	}
	
	return $cResult;
}


1;





