#!/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. %lex = ( 'Edit' => 'Edit', 'Student Table' => 'Student Table', 'Main' => 'Main', 'Your student update is now stored' => 'Your student update is now stored', 'Bold' => 'Bold', 'Required Field' => 'Required Field', 'Cannot open' => 'Cannot open', 'Edit Another Student' => 'Edit Another Student', 'Main' => 'Main', 'There was an error storing your data' => 'There was an error storing your data', 'Contact' => 'Contact', 'Update Student Data' => 'Update Student Data', 'Withdrawn' => 'Withdrawn', 'Preregistration' => 'Preregistration', 'Record the following error' => 'Record the following error', ); use CGI; use DBI; my $self = 'studed.pl'; 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"; } eval require "../lib/libmeta.pl"; if ( $@ ) { print $lex{Error}. " $@
\n"; die $lex{Error}. " $@\n"; } # Don't make into 'my' vars... $dsn = "DBI:$dbtype:dbname=$dbase"; $dbh = DBI->connect($dsn,$user,$password); if ( not $arr{tb} ) { # no passed table to edit... $arr{tb} = 'student'; } if ( $arr{writeflag} ) { delete $arr{writeflag}; updateRecord(); } # Select table to Edit. my $table; # table to edit... if ( $arr{tb} eq 'wd' ){ # if passed a tb=wd param, then edit alt table. $sth = $dbh->prepare("select * from studentwd where studid = ?"); $wd = ''. $lex{Withdrawn}. ''; $table = 'studentwd'; } elsif ( $arr{tb} eq 'prereg' ){ # if tb=pre then edit prereg table. $sth = $dbh->prepare("select * from prereg where studid = ?"); $wd = ''. $lex{Preregistration}. ''; $table = 'prereg'; } else { $sth = $dbh->prepare("select * from student where studid = ?"); $table = 'student'; } $sth->execute( $arr{recnum} ); if ($DBI::errstr){ print $DBI::errstr; die $DBI::errstr;} @rec = $sth->fetchrow; $studnum = $rec[4]; print "$doctype\n". $lex{Edit}. ' '. $lex{'Student Table'}. " $chartype\n\n"; print "[ ". $lex{Main}. " ]\n"; print "

". $lex{Edit}. " $wd ", $lex{'Student Table'},"

\n"; print "
\n"; print "
[ ". $lex{Bold}. " = ". $lex{'Required Field'}. " ]\n"; print "
\n"; # Read in Template unless ( open (FH,"<../template/student.tpl") ) { print $lex{'Cannot open'}. " template - $!\n"; die $lex{'Cannot open'}. " template - $!\n"; } my $text; { local $/; $text = ; close FH;} # Parse for simple field replacement / highlighting <*name*> elements while ( $text =~ m/\<\*(.*)\*\>/g){ push @replace, $1; } #print "
Replacements:
\n",@replace,"
\n"; # Create Hash to hold replacement text. foreach my $val (@replace){ $replacement{$val} = &metaReplace('student',$val); } #print "
Replacement Text
\n",%replacement,"
\n"; # Now put replacement text back in. $text =~ s{\<\*(.*?)\*\>} { exists($replacement{$1}) ? $replacement{$1} : $1 }gsex; # now parse for form entry replacement elements <@name@> # Extract fields from template while ( $text =~ m/\<\@(.*)\@\>/g){ push @fields, $1; } # Preprocess Template for Values $text =~ s/\<\@studnum\@\>/$studnum/; # get replacement values for fields foreach my $val (@fields){ $values{$val} = metaput($table,$val,$studnum,'edit'); } # now put field values back into $text variable... $text =~ s{ \<\@(.*?)\@\> } { exists($values{$1}) ? $values{$1} : "$values{$1}-$1" }gsex; print $text,"\n"; print "\n"; print "\n"; #--------------- sub updateRecord { #--------------- my $table = $arr{tb}; delete $arr{tb}; # delete table value my $recnum = $arr{recnum}; delete $arr{recnum}; #foreach my $key (keys %arr){ print "K: $key VAL: $arr{$key}
\n";} foreach my $key ( keys %arr ) { my $sth = $dbh->prepare("update $table set $key = ? where studid = ?"); $sth->execute( $arr{$key}, $recnum ); if ( $DBI::errstr ) { print $DBI::errstr; } } if ( not $DBI::errstr ) { print ''; print $lex{'Your student update is now stored'}. ".\n"; } else { print "". $lex{'There was an error storing your data'}; print $lex{Contact}. " $adminname "; print "$adminemail."; print $lex{'Record the following error'}. ": $DBI::errstr\n"; } print "

[ ". $lex{'Edit Another Student'}; print " | ". $lex{Main}; print " ]

\n"; exit; } # End of updateRecord