# $Id: sys_conf.pm,v 1.1 2004/07/28 15:37:39 gwolf Exp $
######################################
# Comas - Conference Management System
######################################
# Copyright 2003 CONSOL
# Congreso Nacional de Software Libre (http://www.consol.org.mx/)
#   Gunnar Wolf <gwolf@gwolf.cx>
#   Manuel Rabade <mig@mig-29.net>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
######################################

######################################
# Module: Comas::HTML::committee::sys_conf
# Handles the general system configuration
######################################
# Depends on:
#
# Comas::Admin - Manage administrative tasks for a Comas database
# Comas::HTML::common - Common functions for the HTML FrontEnd

# This module is not meant to be called on its own, it should be called from
# Comas::HTML.

package Comas::HTML::committee::sys_conf;

use strict;
use warnings;
use Carp;

use Comas::Admin;
use Comas::HTML::common qw(:all);
use Comas::Conf qw(:read :write);

use Exporter;

our @ISA = qw(Exporter);
our @EXPORT_OK = qw( sys_conf_menu sys_conf_modif );
our %EXPORT_TAGS = (all => [@EXPORT_OK]);

=head1 NAME
    
Comas::HTML::committee::sys_conf

=head1 SYNOPSIS

This module is not meant to be used by itself, but as an auxiliary to
L<Comas::HTML>. Please check L<Comas::HTML>'s documentation, in the
B<Front End Tasks> section, for further details on the usage for this functions.

=head1 SEE ALSO

L<Comas::HTML|Comas::HTML> module documentation

=head1 AUTHOR

Gunnar Wolf, gwolf@gwolf.cx

Manuel Rabade, mig@mig-29.net

Comas has been developed for CONSOL, Congreso Nacional de Software Libre,
http://www.consol.org.mx/

=head1 COPYRIGHT

Copyright 2003 Gunnar Wolf and Manuel Rabade

This library is free software, you can redistribute it and/or modify it
under the terms of the GPL version 2 or later.

=cut


1;

sub sys_conf_menu {
    my ($h, $msg, $template, @keys, %conf);
    $h = shift;
    $msg = shift;

    unless ($h->_ck_committee_task) {
	return $h->committee_menu('NOT_AUTHORIZED');
    }
    
    $template = $h->new_template('committee/sys_conf/menu.tmpl');

    $template->param($msg => 1) if defined $msg;
    unless (@keys = conf_entries($h->{-db_adm})) {
	$template->param(NO_KEYS => 1);
    }

    for my $key (@keys) {
	$conf{$key} = [get_info($h->{-db_adm}, $key)];
    }

    $template->param(config => [map {{-key => $_,
				      -descr => $conf{$_}[0],
				      -value => $conf{$_}[1]}}
				sort keys %conf]);

    return $template->output;
}

sub sys_conf_modif {
    my ($h, $key, $value);
    $h = shift;
    $key = shift;

    $value = $h->{-params}{-value};
    return $h->sys_conf_menu('NO_VALUE_MODIF') unless 
	defined $value and $value ne '';
    set_conf($h->{-db_adm}, $key, $value) or
	return $h->sys_conf_menu('ERROR_MODIF');

    return $h->sys_conf_menu('SUCCESS_MODIF');

}

# $Log: sys_conf.pm,v $
# Revision 1.1  2004/07/28 15:37:39  gwolf
# Added system configuration functionality (managing the 'config' table)
#
