#!/usr/bin/perl
# Copyright Les Richardson 2001-2019
# This file is part of Open Administration for Schools. Released under GPL Licensing.
my %lex = ('Nominal Roll' => 'Nominal Roll',
'Reset' => 'Reset',
'Main' => 'Main',
'Eoy' => 'Eoy',
'Continue' => 'Continue',
'Select Field' => 'Select Field',
'No Field Selected' => 'No Field Selected',
'Field Fill' => 'Field Fill',
'Grade' => 'Grade',
'Homeroom' => 'Homeroom',
'Student' => 'Student',
'Contact' => 'Contact',
'Error' => 'Error',
'Record(s) Updated' => 'Record(s) Updated',
'Blank' => 'Blank',
'Not Found' => 'Not Found',
'Field' => 'Field',
);
my $self = 'resetnomroll.pl';
my $maxTypeCount = 30; # don't allow more than $maxTypeCount different types in a selection list
#my %disallow = qw(id 1); # double since a HASH.
use DBI;
use CGI;
eval require "../../etc/admin.conf";
if ( $@ ) {
print $lex{Error}. ": $@
\n";
die $lex{Error}. ": $@\n";
}
my $q = new CGI;
print $q->header( -charset, $charset );
my %arr = $q->Vars;
my $dsn = "DBI:$dbtype:dbname=$dbase";
my $dbh = DBI->connect($dsn,$user,$password);
$dbh->{mysql_enable_utf8} = 1;
# Show top of page.
print qq{$doctype\n
$lex{Reset} $lex{Student} $lex{Field}
\n};
if ( not $arr{page} ) { # load jQuery
print qq{\n};
}
print qq{$chartype\n\n};
print qq{[ $lex{Main} | \n};
print qq{$lex{Eoy} ]\n};
print qq{$lex{Reset} $lex{'Nominal Roll'}
\n};
# Select what to do.
if ( not $arr{page} ) {
showStartPage();
} elsif ( $arr{page} == 1 ) {
delete $arr{page};
selectChanges();
} elsif ( $arr{page} == 2 ) {
delete $arr{page};
writeChanges();
}
#----------------
sub showStartPage {
#----------------
# Read student fields, and defaults into a @fields and %fieldname hash.
my $sth = $dbh->prepare("select fieldid, fieldname, formtype
from meta where tableid = 'student_inac' order by fieldname");
$sth->execute;
my (@fields, %fieldnames);
while ( ( my $fieldid, $fieldname, $formtype ) = $sth->fetchrow ) {
if ( $formtype eq 'readonly' ) { next; } # skip disallowed fields to edit
$fieldname =~ s/\(//g;
$fieldname =~ s/\)//g; # strip parenthese. (sp?)
push @fields, $fieldid;
$fieldname{ $fieldid } = $fieldname;
}
# Start the form.
print qq{\n};
exit;
} # end of showStartPage
#----------------
sub selectChanges {
#----------------
#foreach my $key ( sort keys %arr ) { print qq{K:$key V:$arr{$key}
\n}; }
# Read in meta library
eval require "../../lib/libmeta.pl";
if ( $@ ) {
print $lex{Error}. ": $@
\n";
die $lex{Error}. ": $@\n";
}
# Setup field name and fieldid.
my $fieldid = $arr{field};
if ( not $fieldid ) {
print qq{$lex{'No Field Selected'}
\n};
print qq{