#!/usr/bin/perl
# Copyright 2001-2008 Leslie Richardson
# This file is part of Open Admin for Schools.
# Open Admin for Schools 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.
my %lex = (
'Re-enrol Students' => 'Re-enrol Students',
'There was an error removing the student from the withdrawn student table' =>
'There was an error removing the student from the withdrawn student table',
'There was an error storing your data' => 'There was an error storing your data',
'Your student is now back in the student table' =>
'Your student is now back in the student table',
'Main' => 'Main',
'Error' => 'Error',
);
use DBI;
use CGI;
my $q = new CGI;
print $q->header;
my %arr = $q->Vars;
eval require "../../etc/admin.conf";
if ( $@ ) {
print $lex{Error}. ": $@ \n";
die $lex{Error}. ": $@ \n";
}
my $dsn = "DBI:$dbtype:dbname=$dbase";
my $dbh = DBI->connect($dsn,$user,$password);
# Page Header
print "$doctype\n
". $lex{'Re-enrol Students'}. "
$chartype\n
\n";
my %m;
# Create mapping hash between name and the array index variable of value.
# This will remove dependency on array index values with restructured student tables.
my $sth = $dbh->prepare("select fieldid, arrayidx from meta where tableid = 'student'
order by arrayidx");
$sth->execute;
if ( $DBI::errstr ){ print $DBI::errstr; die $DBI::errstr; }
while ( my ($fi,$idx) = $sth->fetchrow ) {
$m{$fi} = $idx;
}
my $studnum = $arr{studnum};
my $description = $dbh->quote( $arr{description} );
# strip off leading text...
$arr{entrytype} =~ s/(.*)\((.*)\)/$2/;
my $sth = $dbh->prepare("select * from studentwd where studnum = ?");
$sth->execute( $studnum );
my $rows = $sth->rows;
my @student = $sth->fetchrow;
if ( $rows < 1 ) { #Error!
print '
'. $lex{'Student Not Found'}. "!
\n";
print "\n";
die;
}
$student[0] = $sql{default}; # reset the studid/id
foreach my $student ( @student ) {
$student = $dbh->quote( $student ) . ',';
}
chop $student[$#student]; # Chop trailing comma in last element
$sth = $dbh->prepare("insert into student values ( @student )");
$sth->execute;
if ( not $DBI::errstr ) {
print '
'. $lex{'Your student is now back in the student table'}. ".
\n";
$sth = $dbh->prepare("delete from studentwd where studnum = ?");
$sth->execute( $studnum );
if ( $DBI::errstr) {
print '
';
print $lex{'There was an error removing the student from the withdrawn student table'};
print ". \n". $lex{'Please contact'};
print " $adminname [ $adminemail ] \n";
print "$DBI::errstr
";
die;
}
chop $student[$m{provnum}]; # Remove trailing comma
$sth2 = $dbh->prepare("insert into transfer values (
$sql{default},'$studnum','$arr{date}', 're-enrol',$description, '$arr{entrytype}',
$sql{default},'$arr{prov}','$arr{country}','Y',
$student[$m{lastname}] $student[$m{firstname}] $student[$m{initial}] $student[$m{birthdate}] $student[$m{provnum}] )");
$sth2->execute;
if ( $DBI::errstr ) { print $lex{Error}. " Transfer Table: $DBI::errstr\n"; }
} else {
print '
'. $lex{'There was an error storing your data'};
print ". \n". $lex{'Please contact'};
print " $adminname [ $adminemail ] \n";
print "$DBI::errstr