#!/usr/bin/perl -T
# $Id: misc_conf_template.cgi,v 1.3 2025/07/24 05:27:26 sqko Exp $
############################################################
############################################################
###                                                      ###
###   Originally designed by Soeren Koch                 ###
###                                                      ###
###   Impelemented by Soeren Koch                        ###
###                                                      ###
###   Copyright by Soeren Koch January 2005              ###
###                                                      ###
############################################################
############################################################
use strict;
use warnings;
use CGI qw(:standard :netscape);
use Fcntl qw(:DEFAULT :flock);
use RFC::Main;
use RFC::RFCCGI qw(:cgi :html);
use RFC::Header;
use Sys::Hostname;

my %conf_keys = (
    'main' => ['cell_area','logall','warning_mails','equipmentid','authorisation','status','authorisationid','mailuser','set_warning_email_on_start'],
    'report' => ['gas_names_ivtable','temp_names_history','water_names_history','gas_names_history','current_names_history','simple_names_history'],
    'userinterface' => ['temp','gas','voltage','current','alert','pO2_voltagerange'],
    'control_logic' => ['templog_for_temperature_addjust'],
    'datalog' => ['additional_log_program','log_program_arguments'],
    );


my $ref = &RFC::RFCCGI::get_user_data_ref();
my $uid = $$ref{'uid'};
my $r = param('rig');
my $rig = RFC::Rig->new($r);    

if (!defined(param))
{
    print process('to_login.tt');
}
else
{
    if ($uid)
    {
        print process('main_nav.tt');
        $_ = param('action');
      CASE:
        {
            ### Insert case statements ###
            ### Default response ####

	    ### Default response ###
	    &main_page();
        }
        print process('end_html.tt');
    }
    else 
    {
        print process('not_auth.tt');
    }
}

sub main_page
{
    my %data = ();
    foreach my $section (keys %conf_keys)
    {
	foreach my $key (@{$conf_keys{$section}})
	{
	    $data{$key} = $rig->get_cv($section,$key);
	}
    }
    my $dir = $RFC::Header::libdir.'logprograms/';
    opendir MYDIR,$dir or die "Could not open dir $dir $!";
    my @l = grep { (!/^\./) && -f "$dir$_"} readdir(MYDIR);
    $data{'logprograms'} = [@l];
    $data{'templogs'} = [$rig->list_devices('templog')];
    print process('misc_conf.tt',&get_template_data_ref(\%data));
}

