#!/usr/bin/perl -w
# This code is a part of Slash, and is released under the GPL.
# Copyright 1997-2001 by Open Source Development Network. See README
# and COPYING for more information, or see http://slashcode.com/.
# $Id: web,v 1.1.2.1 2001/03/29 17:28:49 pudge Exp $

# this program does some really cool stuff.
# so i document it here.  yay for me!

use strict;
use Slash;
use Slash::Display;
use Slash::Utility;
use vars qw($VERSION);

($VERSION) = ' $Revision: 1.1.2.1 $ ' =~ /\$Revision:\s+([^\s]+)/;


# this is an example main().  feel free to use what you think
# works best for your program, just make it readable and clean.

use constant ALLOWED	=> 0;
use constant FUNCTION	=> 1;

sub main {
	my $slashdb   = getCurrentDB();
	my $constants = getCurrentStatic();
	my $user      = getCurrentUser();
	my $form      = getCurrentForm();

	# possible value of "op" parameter in form
	my %ops = (
	# Ex:	op	=> [is_allowed,		\&function	],
		foo	=> [ 1,			\&showFoo	],
		bar	=> [ 1,			\&saveBar	],
		baz	=> [ !$user->{is_anon},	\&editBaz	],
		buz	=> [ $user->{is_admin},	\&createBuz	],
		default	=> [ 1,			\&showFoo	]
	);

	# prepare op to proper value if bad value given
	my $op = $form->{op};
	if (!$op || !exists $ops{$op} || !$ops{$op}[ALLOWED]) {
		$op = 'default';
	}

	header(getData('header'));	# from data;SCRIPTNAME;default

	# dispatch of op
	$ops{$op}[FUNCTION]->($slashdb, $constants, $user, $form);

	# writeLog('SOME DATA');	# if appropriate
	footer();
}

sub showFoo {
	my($slashdb, $constants, $user, $form) = @_;
	# ...
}

# etc.

createEnvironment();
main();

1;
