#!/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 = ('Student Discipline' => 'Student Discipline', 'Discipline Entry' => 'Discipline Entry', 'Main' => 'Main', 'Use One or the Other to identify student, but not both.' => 'Use One or the Other to identify student, but not both.', 'Student Number' => 'Student Number', 'disciplined' => 'disciplined', 'Students' => 'Students', 'Infraction' => 'Infraction', 'Repeated Behavior
Consequence' => 'Repeated Behavior
Consequence', 'Description' => 'Description', 'Action Taken' => 'Action Taken', 'Please Log In' => 'Please Log In', 'Lastname/Lastname,Firstname/Initials/StudentNumber' => 'Lastname/Lastname,Firstname/Initials/StudentNumber', 'Select Student' => 'Select Student', 'Search' => 'Search', 'No Student(s) Found' => 'No Student(s) Found', 'Save Record' => 'Save Record', 'Parental Contact' => 'Parental Contact', 'None' => 'None', 'Phoned' => 'Phoned', 'Letter' => 'Letter', 'Interview (caregiver)' => 'Interview (caregiver)', 'Your discipline record is now stored.' => 'Your discipline record is now stored.', 'Mistake' => 'Mistake', 'Description' => 'Description', 'Action' => 'Action', 'If Repeated' => 'If Repeated', 'Please Contact' => 'Please Contact', 'Add another record' => 'Add another record', 'Back!' => 'Back!', 'Error' => 'Error', 'Please record the following error' => 'Please record the following error', ); my $self = 'tdiscadd.pl'; use DBI; use CGI; use CGI::Session; my @tim = localtime(time); my $year = $tim[5] + 1900; my $month = $tim[4] + 1; my $currdate = "$year-$month-$tim[3]"; my $q = new CGI; 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); # Get Session my $session = new CGI::Session("driver:mysql;serializer:FreezeThaw", undef,{Handle => $dbh}) or die CGI::Session->errstr; my $userid; # Get Session Values (a defined userid means it was passed) if ( not $session->param('logged_in') ){ $userid = $session->param('userid'); print $q->header; print "$doctype\n". $lex{'Student Discipline'}. "\n"; print "\n"; print "[ ". $lex{Main}. " ]\n"; print "

". $lex{'Please Log In'}. "

\n"; print "\n"; die; } # Ok, we have a login. Values below we have in environment. $userid = $session->param('userid'); my $duration = $session->param('duration'); if (not ($duration =~ m/\+/)) { # if no format, add one. $duration = '+'. $duration. 'm'; } $session->expire('logged_in',$duration); print $session->header; print "$doctype\n". $lex{'Student Discipline'}. " \n"; print "
[ ". $lex{Main}. " ]
\n"; if ( $arr{processflag} ) { processSearch( $arr{student} ); } elsif ( $arr{writeflag} ) { writeRecord(); } elsif (not $arr{student} ) { showSearch(); } # Stuff Infractions into an array. my @infarray; my $sth = $dbh->prepare("select name from infraction where name != '' order by name"); $sth->execute; if ( $DBI::errstr ) { print $DBI::errstr; die $DBI::errstr; } while (my $name = $sth->fetchrow) { push @infarray, $name; } my $studnum = $arr{student}; my $sth = $dbh->prepare("select lastname, firstname from student where studnum = ?"); $sth->execute( $studnum ); if ( $DBI::errstr ) { print $DBI::errstr; die $DBI::errstr; } my ($lastname, $firstname) = $sth->fetchrow; $studname = "$firstname $lastname ($studnum)"; print "

". $lex{'Discipline Entry'}. "

\n"; print "

$studname

\n"; print "
\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n\n"; print "
Date
". $lex{'Infraction'}. "
". $lex{Description}. "
". $lex{'Action Taken'}. "
". $lex{'Repeated Behavior
Consequence'}. "
". $lex{'Parental Contact'}. ""; print " " . $lex{None}. "\n"; print "". $lex{Phoned}. "\n"; print "".$lex{Letter}. "\n"; print "".$lex{'Interview (caregiver)'}; print "
\n"; #------------- sub showSearch { #------------- print "

". $lex{'Select Student'}. "

\n"; print "
"; print "\n"; print $lex{'Lastname/Lastname,Firstname/Initials/StudentNumber'}; print "
\n"; print "
\n"; print "\n"; exit; } #---------------- sub processSearch { #---------------- my $student = shift; my @students; # Setup the Search if ($student =~ /\d+/) { # we have a student number push @students, $student; } else { # we have words hopefully with a comma my ($lastname,$firstname) = split /\,/, $student; $firstname =~ s/^\s*//; $lastname =~ s/^\s*//; if ($lastname and $firstname){ # both entered. $sth = $dbh->prepare("select studnum from student where lastname = ? and firstname = ?"); $sth->execute( $lastname, $firstname ); } elsif ($lastname and not $firstname){ # only lastname (no comma) if (length($lastname) == 2){ # search by initials: fi, li. my $fi = substr($lastname,0,1). '%'; my $li = substr($lastname,1,1). '%'; $sth = $dbh->prepare("select studnum from student where lastname $sql{like} ? and firstname $sql{like} ?"); $sth->execute( $li, $fi ); } else { $sth = $dbh->prepare("select studnum from student where lastname = ? order by firstname"); $sth->execute( $lastname ); } } else { # print an error.... print '

'. $lex{'Entry Error'}. ': '; print $lex{'No Student(s) Found'}.".

\n"; print "\n"; exit; } } # Last Else if ( $sth ) { # if text we should have a statement handle (sth) if ($DBI::errstr){ print $DBI::errstr; die $DBI::errstr; } $rows = $sth->rows; if ($rows < 1) { print '

'. $lex{'No Student(s) Found'}. ".

\n"; print "\n"; exit; } while ( my $studnum = $sth->fetchrow ) { push @students, $studnum; } } print "
\n"; print "\n"; # display found students, if any... $sth1 = $dbh->prepare("select lastname, firstname from student where studnum = ?"); foreach my $studnum (@students) { $sth1->execute($studnum); my ($lastname, $firstname) = $sth1->fetchrow; print ""; print ""; print ""; print "\n"; } print "\n"; print "\n"; exit; } # End of processSearch; #-------------- sub writeRecord { #-------------- delete $arr{writeflag}; foreach my $key ( keys %arr ) { if ( $arr{$key} ) { $arr{$key} = $dbh->quote( $arr{$key} ); } else { $arr{$key} = $sql{default}; } #print "K:$key V:$arr{$key}
\n"; } if ( not $arr{parent} ) { $arr{parent} = $sql{default}; } $sth = $dbh->prepare("insert into discipline values ( $sql{default}, $arr{date}, $arr{studnum}, $arr{mistake}, $arr{description}, $arr{action}, $arr{repeat}, $arr{parent}, '$userid', $sql{default} )"); $sth->execute; if (not $DBI::errstr ) { print "

". $lex{'Your discipline record is now stored.'}. "

\n"; print "
$firstname $lastname ($studnum)
\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "
". $lex{Mistake}. "$arr{mistake}
". $lex{Description}. "$arr{description}
". $lex{Action}. "$arr{action}
". $lex{'If Repeated'}. "$arr{repeat}
". $lex{'Parental Contact'}; print "$arr{parent}
\n"; print "

[ ". $lex{Main}. " | "; print $lex{'Add another record'}. " ]

\n"; print "
\n"; } else { print "

". $lex{'There was an error storing your record.'}. " \n"; print $lex{'Please Contact'}; print " $adminname $adminemail
\n"; print $lex{'Please record the following error'}. ": $DBI::errstr

\n"; } print "\n"; exit; } # end of writeRecord.