#!/usr/bin/perl # Copyright 2001-2009 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 = ( 'Delete Staff Member' => 'Delete Staff Member', 'Delete' => 'Delete', 'Staff' => 'Staff', 'Preregistration' => 'Preregistration', 'Main' => 'Main', 'Eoy' => 'Eoy', 'Are you sure you want to delete this record?' => 'Are you sure you want to delete this record?', 'Delete the Record' => 'Delete the Record', 'Record Deletion Failed. Please contact' => 'Record Deletion Failed. Please contact', 'Edit/Delete Staff Members' => 'Edit/Delete Staff Members', 'Edit/Delete Prereg Staff Members' => 'Edit/Delete Prereg Staff Members', 'deleted' => 'deleted', 'Name' => 'Name', 'User Id' => 'User Id', 'Homeroom' => 'Homeroom', 'Subjects Taught' => 'Subjects Taught', 'Error' => 'Error', 'Yes' => 'Yes', ); my $self = 'staffdel.pl'; use CGI; use DBI; 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 $table; if ($arr{tbl}) { $table = 'prereg_staff'; $tableview = ''. $lex{Preregistration}. ''. q{ }. $lex{Staff}; } else { $table = 'staff'; $tableview = $lex{Staff}; } $dsn = "DBI:$dbtype:dbname=$dbase"; $dbh = DBI->connect($dsn,$user,$password); $sth = $dbh->prepare("select lastname, firstname, userid, homeroom from $table where id = ?"); $sth->execute( $arr{id} ); if ($DBI::errstr) { print $DBI::errstr; die $DBI::errstr; } my ($lastname, $firstname, $userid, $homeroom) = $sth->fetchrow; $sth = $dbh->prepare("select count(*) from subject where teacher like '%$userid%'"); $sth->execute; if ($DBI::errstr) { print $DBI::errstr; die $DBI::errstr; } my $subjectcount = $sth->fetchrow; print "$doctype\n".$lex{'Delete Staff Member'}." $chartype\n\n[ "; print $lex{Main}, " | "; print $lex{Eoy}, " ]

"; print $lex{Delete}. q{ }. $tableview; print "

\n"; if ($arr{deleteflag}) { delete $arr{deleteflag}; deleteRecord(); } print "
". $lex{'Name'}. "$firstname $lastname
". $lex{'User Id'}. "$userid
". $lex{'Homeroom'}. "$homeroom
". $lex{'Subjects Taught'}. "$subjectcount
\n"; print "

".$lex{'Are you sure you want to delete this record?'}."

\n"; #--------------- sub deleteRecord { #--------------- #foreach my $key (keys %arr) { print "K:$key V:$arr{$key}
\n"; } $sth = $dbh->prepare("delete from $table where id = ?"); $sth->execute( $arr{itemid} ); if ($DBI::errstr) { print $lex{'Record Deletion Failed. Please contact'}. " $adminname
\n"; print $DBI::errstr."\n"; } else { print "

$arr{name} ". $lex{deleted}. ".

\n"; } print "

[ "; if ($arr{tbl}) { print ""; print $lex{'Edit/Delete Prereg Staff Members'}; } else { print "". $lex{'Edit/Delete Staff Members'}; } print " ]

\n"; print ""; exit; }