#! /usr/bin/perl
# Copyright 2001-2006 Leslie Richardson
# This file is part of Open Admin for Schools.
# Query Function for StudentPersonal Objects
# Passed Values: none.
use DBI;
use CGI;
use XML::Writer;
use XML::Writer::String;
use Data::UUID;
use HTTP::Request::Common qw(POST);
use HTTP::Headers;
use LWP::UserAgent;
use XML::LibXML;
my $self = 'syncenrol.pl';
# Read config variables
require "../../etc/admin.conf" or die "Cannot read admin.conf: $!";
require "slxmllib.pl" or die "Cannot read slxmllib.pl: $!";
# Override V1 with V2 values
# SDS XML Schema Declarations
$xmlns = "http://www.sasked.gov.sk.ca/xsd/sl/2.x/SLMessage_V2.xsd";
$xmlnsxsi = "http://www.w3.org/2001/XMLSchema-instance";
$xsischemaLocation="http://www.sasked.gov.sk.ca/xsd/sl/2.x/SLMessage_V2.xsd
http://www.sasked.gov.sk.ca/xsd/sl/2.x/SLMessage_V2.xsd";
my $q = new CGI;
my %arr = $q->Vars;
print $q->header;
if ($arr{debug}){
$debug = 1;
delete $arr{debug};
}
my $dsn = "DBI:$dbtype:dbname=$dbase";
$dbh = DBI->connect($dsn,$user,$password);
# Setup Date and Times
my @month = ("","January","February","March","April","May","June","July",
"August","September","October","November","December");
my @tim = localtime(time);
my $year = $tim[5] + 1900;
$tim[4]++;
for (0..4){if (length($tim[$_]) == 1){ $tim[$_] = '0'.$tim[$_];}}
my $currdate = "$year-$tim[4]-$tim[3]";
my $currtime = "$tim[2]:$tim[1]:$tim[0]";
my $currlongdate = "$month[$tim[4]] $tim[3], $year";
print "$doctype\n
SDS Query: School Enrollment
$chartype\n[ Main |
Export ]
Query School Student Enrollment
$currlongdate
\n";
# This shows the records to update....(and select)
if ($arr{transferflag}) { # Activate/Create Transfer records
activateTransfer();
die;
}
#if ($arr{activatedflag}) { # Activate the selected record
# delete $arr{activatedflag}; # not needed.
# updateEnrol(%arr);
# print "\n";
# die;
#}
# Find all local kids and push studnum into hash, display any blank provnum
my $sth = $dbh->prepare("select studnum, provnum, lastname, firstname
from student order by provnum");
$sth->execute;
if ($DBI::errstr){ print $DBI::errstr; die $DBI::errstr;}
$studcount = $sth->rows;
# Note any missing provincial numbers...
my $foundmissing = 0;
while (my ($studnum,$provnum,$lastname, $firstname) = $sth->fetchrow) {
if (not $provnum) {
if ($foundmissing == 0){ # print the table heading, once.
print "
\n";
}
$foundmissing = 1;
print "
Missing Provincial Number for: ";
print "$firstname $lastname ($studnum)
\n";
push @noprovnum, "$lastname:$firstname:$studnum"; # used to NOT withdraw them.
next;
}
$localStudent{$provnum} = 1;
$masterList{$provnum} = 1;
}
if ($foundmissing) {
print "
\n";
}
# Create a new user agent
my $ua = LWP::UserAgent->new();
$ua->agent("OpenAdmin");
$count++;
mkQueryString($count); # Generate $output string
# DEBUG Data Errors
if ($debug){
print "
\n";
}
# Create the https post request
my $req = POST $url, [ XML=>$output->value ];
$req->content_type('application/xml;charset="utf-8"');
$req->authorization_basic($sds_userid, $sds_password);
# Issue the request and receive a response
my $res = $ua->request($req);
# Check the status of the response
if ($res->is_success) {
# For Debugging Data Errors
if ($debug){
print "