#! /usr/bin/perl

=head1 NAME

user_reports - reports of user administration

=head1 SYNOPSIS

 https://server/schulkonsole/user_reports

=head1 DESCRIPTION

C<user_reports> lets you view reports of user administration.
The HTML template is user_reports.tt.

=head2 Template variables

Additionally to the variables of Schulkonsole::Session C<user_reports>
provides the following variables:

=over

=cut

use strict;
use utf8;
use lib '/usr/share/schulkonsole';
use Schulkonsole::Session;
use Schulkonsole::Sophomorix;

my $this_file = 'user_reports';


my $sk_session = new Schulkonsole::Session($this_file);
if (not $sk_session->get_password()) {
	my $q = new CGI;
	my $url = $q->url( -full => 1 );

	# we send cookies over secure connections only
	if ($url =~ s/^http:/https:/g) {
		$sk_session->redirect($url);
	} else {
		$sk_session->exit_with_login_page($this_file);
	}
}

my $q = $sk_session->query();

my $id = $sk_session->userdata('id');
my $password = $sk_session->get_password();


my $lines;
eval {
COMMANDS: {
$q->param('showadmin') and do {
	$lines = Schulkonsole::Sophomorix::read_admin_report_file($id, $password);

	last COMMANDS;
};

$q->param('showoffice') and do {
	$lines = Schulkonsole::Sophomorix::read_office_report_file($id, $password);

	last COMMANDS;
};

} # end COMMANDS
};
if ($@) {
	$sk_session->standard_error_handling($this_file, $@);
}



=item C<content>

A report

=cut

$sk_session->set_var('content', join('', @$lines)) if $lines;



$sk_session->print_page("$this_file.tt", $this_file);


=back

=head2 Form fields

=over

=item C<showadmin>

Show the file C<report.admin> (in template variable C<content>)

=item C<showoffice>

Show the file C<report.office> (in template variable C<content>)

=back

