forked from science-ation/science-ation
480 lines
19 KiB
PHP
480 lines
19 KiB
PHP
<?php
|
|
/*
|
|
This file is a plug-in to the 'Science Fair In A Box' project
|
|
SFIAB Website: http://www.sfiab.ca
|
|
|
|
Copyright (C) 2011 At Work Software (dennis@spanogle.net>
|
|
Copyright (C) 2011 Dennis Spanogle <dennis@spanogle.net>
|
|
|
|
This program 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, version 2.
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
General Public License for more details.
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
along with this program; see the file COPYING. If not, write to
|
|
the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
Boston, MA 02111-1307, USA.
|
|
*/
|
|
?>
|
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
|
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" >
|
|
<head><title>SFIAB Evaluations Link</title>
|
|
<link rel="stylesheet" href="sfiab.css" type="text/css" />
|
|
</head>
|
|
<body>
|
|
|
|
<?php
|
|
include "sfiab_common.inc.php"; // check SFIAB install and get config etc.
|
|
include "eval_common.inc.php"; // check Evaluations setup and get eval_config
|
|
include "eval_menu_inc.php";
|
|
echo "<h2>Link Evaluations and SFIAB Data</h2><br /><br />";
|
|
echo "<br /><br />";
|
|
$errors = 0;
|
|
echo "Click the button to link SFIAB and Evaluations. (Be patient, may take a while)";
|
|
echo "<form method=\"post\" action=\"eval_link_sfiab.php\">";
|
|
echo "<input type=\"hidden\" name=\"action\" value=\"link\" />";
|
|
echo "<br />";
|
|
echo "<input type=\"submit\" value=\"Link Now\">";
|
|
echo "</form>";
|
|
if(!$_POST['action'] == "link")
|
|
{
|
|
exit;
|
|
}
|
|
echo "Linking Process complete - status follows:<br /><br />";
|
|
// get the eval_scheme id and eval_schemes.assignto_project_when fields
|
|
$q=mysql_query("SELECT * FROM eval_schemes");
|
|
if (!q){
|
|
echo "ERROR: Cannot open eval_schemes. You must have schemes set up prior to linking";
|
|
exit;
|
|
}
|
|
// build an array of eval_schemes table
|
|
while($r=mysql_fetch_object($q))
|
|
{
|
|
$crit = $r->assignto_project_when;
|
|
$words = explode(' ', $crit); //this should get the parameter, '+' and the value
|
|
//echo "".$r->scheme_id." ".$words[0]." ".$words[1]." ".$words[2]."<br />";
|
|
$schmidval = $r->scheme_id;
|
|
$schemes[] = array($schmidval,$words[0],$words[1],$words[2]);
|
|
}
|
|
/*
|
|
For now, the evaluations are done by the teams (judges_teams_id) - one evaluation per divisional round perhaps.
|
|
the table judges_teams_timeslots_projects_link contains the necessary fields 'Projects_id' and 'judges_teams_id'
|
|
|
|
Eventually perhaps Another table - eval_project_assignements will link 'Who does the eval' to the 'Projects_id' to be evaluated.
|
|
table eval_projects_entries has:
|
|
Judges_teams_id (this will be always be set to a judges_teams_id whick I will assume for now is always > 0 )
|
|
Judge_user_id (this will be set to 0 to indicate we use judges_teams. set > 0 if we use individual judges later..) criteria_id (this is which evaluation criteria is being entered (entered by team or upload or ... null => no entry)
|
|
level_id (this is the score - entered as an Id so we can get the value and calculate a score generically. null =>no entry)
|
|
(A) Using sfiab projects table and eval_projects table.
|
|
1.) For each project in SFIAB
|
|
if project.id in eval_projects then verify entries (judges, team etc) and update
|
|
if not in eval_projects do link (insert row in eval_projects) and fill in entries (judges, team etc.
|
|
entries: project_id; team (also scheme_id <-- setup); eval_score; final_score; eval_score_status; overall_status) set scheme_id according to the values in eval_schemes.assignto_project_when fields (something = something)
|
|
2.) For each project in eval_projects
|
|
if project_id NOT in SFIAB then remove from eval_projects
|
|
(B) Using judges_teams_timeslots_projects_link and eval_projects_entries.
|
|
See if eval_projects_entries has any entries => any criteria_id and or level_id will have non-null entries
|
|
If NO then: Empty the table and reload it from judges_teams_timeslots_projects_links SFIAB table
|
|
|
|
If YES then:
|
|
1 Remove all records in eval_projects_entries without entries
|
|
2 See if we can save the ones with entries.
|
|
For each record with an entry criteria_id or level_id
|
|
If matching team/project in SFIAB then leave it
|
|
If not matching team/project in SFIAB then remove it
|
|
3. For each record in judges_teams_timeslots_projects_links
|
|
If same project, team in eval then skip (have record and have entry)
|
|
else add record.
|
|
|
|
this for later?? or remove
|
|
SELECT Exhibitors.Exhibit_ID, Exhibits.EXN, Exhibits.Exhibit_ID AS Expr1, Exhibitors.UserId
|
|
FROM Exhibitors LEFT OUTER JOIN
|
|
Exhibits ON Exhibitors.Exhibit_ID = Exhibits.Exhibit_ID
|
|
*/
|
|
// projects has projectcategories_id ( ) and projectdivisions_id ( ) and as possible scheme setups valuse
|
|
// Students has grade as possilbe scheme setup values
|
|
// ************************ NOTE This gets ALL projects, even those not assigned to a judge team(open versus complete) *******************************
|
|
$qst = "SELECT students.registrations_id, projects.registrations_id, projects.id, projects.shorttitle, students.grade, ";
|
|
$qst = $qst."projects.projectcategories_id, projects.projectdivisions_id, projects.cwsfdivisionid ";
|
|
$qst = $qst." FROM students LEFT OUTER JOIN projects ON students.registrations_id = projects.registrations_id ORDER by projects.id";
|
|
// note the sort order is important if my code works to discover teams
|
|
$nscnt = 0;
|
|
$nprj = 0;
|
|
$ns = 0;
|
|
$pid = -1;
|
|
//echo $qst;
|
|
$q=mysql_query($qst);
|
|
if ($q) {
|
|
while($r=mysql_fetch_object($q))
|
|
{
|
|
$ns += 1; // count students
|
|
$cwdiv = $r->cwsfdivisionid;
|
|
$grade = $r->grade;
|
|
$divid = $r->projectdivisions_id;
|
|
$cat = $r->projectcategories_id;
|
|
if ($r->id == $pid){
|
|
// we already did this project but... it is a team project since # students > 1
|
|
if ($r->grade > $grade) {
|
|
$grade = $r->grade; // always select the highest grade in the team (matched help.html)
|
|
}
|
|
$team = "yes";
|
|
}
|
|
else{
|
|
// project.id changed so save the last one
|
|
// but only if see if we did the save
|
|
if ($pid == -1){
|
|
$pid = $r->id; // setup first time
|
|
//echo "Did First time pid = ".$pid." <br />";
|
|
$team = "no";
|
|
}
|
|
else {
|
|
// done with last so save it (note does not save the last one.
|
|
$nprj += 1; // count projects
|
|
insert_project($schemes, $pid, $divid, $team, $cat, $grade, $cwdiv);
|
|
// get ready for the next
|
|
$pid = $r->id;
|
|
$team = "no";
|
|
}
|
|
}
|
|
}
|
|
$nprj += 1; // count projects
|
|
insert_project($schemes, $pid, $divid, $team, $cat, $grade, $cwdiv);
|
|
}
|
|
else{
|
|
echo('<br/>Error performing query!<br/>'.$qst.'<br/> mysqlerror: '.mysql_error().'<br /><br />');
|
|
echo "<br />Query failed<br />";
|
|
$errors += 1;
|
|
}
|
|
if (errors == 0){
|
|
echo "SFIAB has ".$ns." Students and ".$nprj." Projects. <br />";
|
|
echo "<br />Evaluations links to SFIAB have been updated!<br />";
|
|
echo " This means:<br />";
|
|
echo " ** Each Project in SFIAB is now included in Evaluations' data.<br />";
|
|
echo " ** Projects removed from SFIAB since the last link-up were removed from Evaluations' data.<br />";
|
|
echo " Note: Project evaluations entered (if any) were retained! SFIAB projects 'newly added' will have no evaluation entries.<br />";
|
|
echo "<br />";
|
|
}
|
|
else{
|
|
echo "There were errors! Review the notices and correct the problems!<br />";
|
|
}
|
|
// **************** create/ update the eval_projects_entries table *************************
|
|
|
|
// now see if any extra records in local table (not in SFIAB) to delete - remember eval_projects contains ALL projects, not just those complete.
|
|
$loc = mysql_query("SELECT project_id from eval_projects"); // All projects = even those not assigned a judge team
|
|
while($lr =mysql_fetch_object($loc))
|
|
{
|
|
$q=mysql_query("SELECT id FROM projects WHERE id = '".$lr->project_id."' ");
|
|
$remr = mysql_fetch_object($q)->id;
|
|
if(mysql_num_rows($q) ==0){ // will probably find 2 for project_id = 0 (due to way $qst is formed above
|
|
$del = mysql_query("DELETE from eval_projects WHERE project_id = '".$lr->project_id."' " );
|
|
if (! $del){
|
|
echo "delete error project_id=".$lr->project_id."<br />";
|
|
}
|
|
else {
|
|
echo "Deleted project_id ".$lr->project_id." from evaluations data.<br />";
|
|
}
|
|
}
|
|
}
|
|
// could have some records left for projects that are not complete if.. was complete, then had an evaluation, then was set as incomplete
|
|
// I will not worry about this at this time.
|
|
// *****************************************************************************************************
|
|
// Now do the work on eval_projects_entries table using SFIAB judges_teams_timeslots_projects_links
|
|
echo "<br />Updating Projects Evaluations Entries! <br />";
|
|
$num_entries = 0;
|
|
$chknum_entries = 0;
|
|
// First delete all entries without evaluations
|
|
$q = mysql_query("DELETE FROM eval_projects_entries WHERE level_id IS NULL");
|
|
if (!q){
|
|
echo "Error opening table eval_projects_entries ";
|
|
exit;
|
|
}
|
|
$qst = "SELECT * FROM eval_projects_entries WHERE level_id IS NOT NULL";
|
|
$q=mysql_query($qst);
|
|
if (!q){
|
|
echo "Error opening table eval_projects_entries ";
|
|
exit;
|
|
}
|
|
else {
|
|
if(mysql_num_rows($q) > 0){ // will probably find 2 for project_id = 0 (due to way $qst is formed above
|
|
// Have records
|
|
$num_entries = mysql_num_rows($q);
|
|
echo "Found ".$num_entries ." records with entries<br />";
|
|
// now see if those left have entries in judges_teams_timeslots_projects_link
|
|
// if not, then they also can be deleted
|
|
$q=mysql_query($qst);
|
|
while($r=mysql_fetch_object($q)) {
|
|
$qeval = mysql_query("SELECT * FROM judges_teams_timeslots_projects_link WHERE projects_id = '$r->project_id' AND judges_teams_id = '$r->judges_teams_id'"); // find matching entry
|
|
if (mysql_num_rows($qeval) == 0){
|
|
echo "project_id andjudge_team_id not in SFIAB so removed<br />";
|
|
$qremove = mysql_query("DELETE FROM eval_projects_entries WHERE project_id = '$r->project_id' AND judges_teams_id = '$r->judges_teams_id'");
|
|
}
|
|
}
|
|
}
|
|
else {
|
|
echo "Good! No recores had entries<br />";
|
|
}
|
|
}
|
|
|
|
// Add all records from judges_teams_timeslots_projects_links NOT in eval_projects_entries
|
|
$q = mysql_query("SELECT * FROM judges_teams_timeslots_projects_link");
|
|
$count = 0;
|
|
while($r=mysql_fetch_object($q)) {
|
|
//$skip = 0;
|
|
//$qeval = mysql_query($qst); // find all with level_id entries
|
|
//while($reval=mysql_fetch_object($qeval)) {
|
|
// if($reval->project_id == $r->projects_id ){
|
|
// if($reval->judges_teams_id == $r->judges_teams_id) {
|
|
// $skip = 1; // found this one with at least one level_id entry non-null entries so do not add it
|
|
// }
|
|
// }
|
|
//}
|
|
//if ($skip == 0){
|
|
// insert a record for each criteria ID that does NOT have a current level_id non null. New entries level_id will be set null
|
|
// for the project, get the scheme id.
|
|
$qprj= mysql_query("SELECT * FROM eval_projects WHERE project_id = '".$r->projects_id."' ");
|
|
if($qprj){
|
|
// for the scheme id get all the criteria ids
|
|
while($rprj =mysql_fetch_object($qprj)) {
|
|
$qcrit= mysql_query("SELECT * FROM eval_criteria WHERE scheme_id = '".$rprj->scheme_id."' ");
|
|
if($qcrit){
|
|
while($rcrit =mysql_fetch_object($qcrit)) {
|
|
// find this record (project, Team, criteria has an entry for level_id)
|
|
if ($num_entries > 0){ // no sense checking if no evaluations done at start.
|
|
$qcheck = mysql_query("SELECT * FROM eval_projects_entries WHERE project_id='".$r->projects_id."' AND judges_teams_id = '".$r->judges_teams_id."' AND criteria_id ='".$rcrit->criteria_id."' ");
|
|
if (mysql_num_rows($qcheck) > 0) {
|
|
$chknum_entries += 1;
|
|
}
|
|
else{
|
|
$qadd = mysql_query("INSERT INTO eval_projects_entries (project_id, judges_teams_id, judges_timeslots_id, criteria_id) VALUES ('$r->projects_id', '$r->judges_teams_id', '$r->judges_timeslots_id', ' $rcrit->criteria_id' )");
|
|
$count += 1;
|
|
}
|
|
} // if ($num_entries > 0)
|
|
else{
|
|
$qadd = mysql_query("INSERT INTO eval_projects_entries (project_id, judges_teams_id, judges_timeslots_id, criteria_id) VALUES ('$r->projects_id', '$r->judges_teams_id', '$r->judges_timeslots_id', ' $rcrit->criteria_id' )");
|
|
$count += 1;
|
|
} // else (if ($num_entries > 0)
|
|
} // while $rcrit
|
|
} // if $qcrit
|
|
} // while $rprj
|
|
} // if $qprj
|
|
//}
|
|
else {
|
|
//echo "skipped<br />";
|
|
$skipped +=1;
|
|
}
|
|
}
|
|
if ($chknum_entries == $num_entries){
|
|
|
|
echo "<br />Eval_projects_entries updated! ".$num_entries." evaluation entries were retained. Total evals to do = ".($count + $num_entries)."<br />";
|
|
}
|
|
else{
|
|
echo "<br />ERROR num_entries =".$num_entries." not same as check of num_entries = ".$chknum_entries."<br />";
|
|
}
|
|
exit;
|
|
|
|
// ******************************** function to insert or update eval_projects table ****************************
|
|
|
|
function insert_project($schemes, $pid, $div, $team, $cat, $grade, $cwdiv )
|
|
{
|
|
/*
|
|
if this project is in eval_projects then update scheme_id, team (leaves eval_score, etc)
|
|
if this project is NOT in eval_projects then insert project_id, team, scheme_id
|
|
if this project is in eval_projects_entries then update judges_teams_id, judges_timeslots_id, judge_user_id
|
|
(leave entries criteria_id, level_id)
|
|
if this project is NOT in eval_projects_entries then insert project_id, judges_teams_id, judges_timeslots_id, judge_user_id
|
|
*/
|
|
// see if any of the possible selection parameters for this project are matched to a scheme (see help)
|
|
// The $schemes array and example
|
|
// id par con val
|
|
// 0 1 2 3
|
|
// 1 team = no
|
|
// 2 team = yes
|
|
$proj_scheme_id = 9999; //set this as the default in case we find no matches
|
|
foreach ($schemes as $sch)
|
|
{
|
|
$match = 0;
|
|
// get the parameter
|
|
$par = $sch[1];
|
|
//get the condition
|
|
$con = $sch[2];
|
|
// get the value
|
|
$val = $sch[3];
|
|
// see if this project's values matches the parameter and condition
|
|
// for the example above this will set proj_scheme_id to 1 for team=no 2 for team=yes
|
|
if($par == 'team'){ // there is a team condition in schemes
|
|
if ($con == "="){
|
|
if ($team == $val){ // is this projects team setting = scheme setting 'yes' or 'no'
|
|
$proj_scheme_id = $sch[0];
|
|
escape;
|
|
}
|
|
}
|
|
if ($con == '!='){
|
|
if ($team != $val){ // is this projects team setting != scheme setting != 'yes' or != 'no'
|
|
$proj_scheme_id = $sch[0];
|
|
escape;
|
|
}
|
|
}
|
|
if ($con == '<'){
|
|
if ($team < $val){ // is this projects team setting < scheme setting of 'yes' or 'no'
|
|
$proj_scheme_id = $sch[0];
|
|
escape;
|
|
}
|
|
}
|
|
if ($con == '>') {
|
|
if ($team > $val){ // is this projects team setting > scheme setting of 'yes' or 'no'
|
|
$proj_scheme_id = $sch[0];
|
|
escape;
|
|
}
|
|
}
|
|
}
|
|
if($par == 'div'){
|
|
if ($con == "="){
|
|
if ($div == $val){ // is this projects division setting = the setting in a scheme
|
|
$proj_scheme_id = $sch[0];
|
|
escape;
|
|
}
|
|
}
|
|
if ($con == '!='){
|
|
if ($div != $val){ // is this projects division setting != the setting in a scheme
|
|
$proj_scheme_id = $sch[0];
|
|
escape;
|
|
}
|
|
}
|
|
if ($con == '<'){
|
|
if ($div < $val){ // is this projects division setting <t he setting in a scheme
|
|
$proj_scheme_id = $sch[0];
|
|
escape;
|
|
}
|
|
}
|
|
if ($con == '>') {
|
|
if ($div > $val){ // is this projects division setting > the setting in a scheme
|
|
$proj_scheme_id = $sch[0];
|
|
escape;
|
|
}
|
|
}
|
|
}
|
|
if($par == 'cat'){
|
|
if ($con == "="){
|
|
if ($cat == $val){ // is this projects category setting = the setting in a scheme
|
|
$proj_scheme_id = $sch[0];
|
|
escape;
|
|
}
|
|
}
|
|
if ($con == '!='){
|
|
if ($cat != $val){ // is this projects category setting != the setting in a scheme
|
|
$proj_scheme_id = $sch[0];
|
|
escape;
|
|
}
|
|
}
|
|
if ($con == '<'){
|
|
if ($cat < $val){ // is this projects category setting = the setting in a scheme
|
|
$proj_scheme_id = $sch[0];
|
|
escape;
|
|
}
|
|
}
|
|
if ($con == '>') {
|
|
if ($cat > $val){ // is this projects category setting = the setting in a scheme
|
|
$proj_scheme_id = $sch[0];
|
|
escape;
|
|
}
|
|
}
|
|
}
|
|
if($par == 'grade'){
|
|
if ($con == "="){
|
|
if ($grade == $val){ // is this projects team grade = the setting in a scheme
|
|
$proj_scheme_id = $sch[0];
|
|
escape;
|
|
}
|
|
}
|
|
if ($con == '!='){
|
|
if ($grade != $val){
|
|
$proj_scheme_id = $sch[0];
|
|
escape;
|
|
}
|
|
}
|
|
if ($con == '<'){
|
|
if ($grade < $val){
|
|
$proj_scheme_id = $sch[0];
|
|
escape;
|
|
}
|
|
}
|
|
if ($con == '>') {
|
|
if ($grade> $val){
|
|
$proj_scheme_id = $sch[0];
|
|
escape;
|
|
}
|
|
}
|
|
}
|
|
if($par == 'cwdiv'){ // check the canada wide div id = scheme setting for cwdiv.
|
|
if ($con == "="){
|
|
if ($cwdiv == $val){
|
|
$proj_scheme_id = $sch[0];
|
|
escape;
|
|
}
|
|
}
|
|
if ($con == '!='){
|
|
if ($cwdiv != $val){
|
|
$proj_scheme_id = $sch[0];
|
|
escape;
|
|
}
|
|
}
|
|
if ($con == '<'){
|
|
if ($cwdiv < $val){
|
|
$proj_scheme_id = $sch[0];
|
|
escape;
|
|
}
|
|
}
|
|
if ($con == '>') {
|
|
if ($cwdiv> $val){
|
|
$proj_scheme_id = $sch[0];
|
|
escape;
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
// echo "Save Scheme= ".$proj_scheme_id." Save pid= ".$pid." Team= ".$team." div= ".$div." cat= ".$cat." grade= ".$grade." cwdiv= ".$cwdiv."<br />";
|
|
// ready to update or add the eval_projects table entry
|
|
// See if a record for this project ID
|
|
$ev = mysql_query("SELECT * FROM eval_projects WHERE project_id = $pid");
|
|
if (mysql_num_rows($ev) > 0) {
|
|
|
|
//echo "found - updating<br />";
|
|
$ev = mysql_query("UPDATE eval_projects SET team = '$team', scheme_id = '$proj_scheme_id' WHERE project_id = $pid");
|
|
echo mysql_error();
|
|
}
|
|
else {
|
|
// echo "not found - adding<br />";
|
|
$ev = mysql_query("INSERT INTO eval_projects (project_id, team, scheme_id) VALUES ('$pid', '$team', '$proj_scheme_id')");
|
|
echo mysql_error();
|
|
}
|
|
/* keep this code here until I copy it to the score entry routines
|
|
// DO NOT .. Do the same for table eval_projects_entries
|
|
// Every entry into this table must be done when we know the values for criteria_id and value-id
|
|
// because these are the entries from a judge or team or... so then... we enter the judges_team_id and timeslot
|
|
//or... in an optional method of assigning judges the judge_user_id
|
|
$ev = mysql_query("SELECT * FROM eval_projects_entries WHERE project_id = $pid");
|
|
if (mysql_num_rows($ev) > 0) {
|
|
|
|
//echo "found - updating<br />";
|
|
$ev = mysql_query("UPDATE eval_projects_entries SET judges_teams_id = '$judges_teams_id', judges_timeslots_id = '$judges_timeslots_id', judge_user_id = '$judge_user_id' WHERE project_id = $pid");
|
|
echo mysql_error();
|
|
}
|
|
else {
|
|
// echo "not found - adding<br />";
|
|
$ev = mysql_query("INSERT INTO eval_projects_entries (project_id, judges_teams_id, judges_timeslots_id, judge_user_id ) VALUES ('$pid', '$judges_teams_id', '$judges_timeslots_id', '$judge_user_id')");
|
|
echo mysql_error();
|
|
}
|
|
*/
|
|
|
|
|
|
}
|
|
?>
|
|
|
|
</body>
|