#!/usr/bin/perl # Copyright 2001-2007 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', 'Transfer Table error' => 'Transfer Table error', ); use DBI; use CGI; $q = new CGI; print $q->header; %arr = $q->Vars; require "../../etc/admin.conf" or die "Cannot read admin.conf!"; $dsn = "DBI:$dbtype:dbname=$dbase"; $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. $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; } $studnum = $arr{studnum}; $description = $arr{description}; $description =~ s/'/\\'/g; # strip off leading text... $arr{entrytype} =~ s/(.*)\((.*)\)/$2/; $sth = $dbh->prepare("select * from studentwd where studnum = '$studnum'"); $sth->execute; $rows = $sth->rows; @student = $sth->fetchrow; if ($rows < 1) { #Error! print '

'. $lex{'Student Not Found'}. "!

\n"; die; } $student[0] = $sql{default}; # reset the studid/id foreach $student (@student){ $student =~ s/'/''/g; $student = "\'".$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 = '$studnum'"); $sth->execute; if ( $DBI::errstr) { 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}', '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{'Transfer Table error'}. ": $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

"; } print "

[ ". $lex{Main}. " ]

\n";