2005-05-06 20:02:20 +00:00
< ?
2025-01-29 03:30:48 +00:00
/*
* This file is part of the 'Science Fair In A Box' project
2025-02-10 19:54:20 +00:00
* Science - ation Website : https :// science - ation . ca /
2025-01-29 03:30:48 +00:00
*
* Copyright ( C ) 2005 Sci - Tech Ontario Inc < info @ scitechontario . org >
* Copyright ( C ) 2005 James Grant < james @ lightbox . org >
2025-02-10 19:54:20 +00:00
* Copyright ( C ) 2024 AlgoLibre Inc . < science - ation @ algolibre . io >
2025-01-29 03:30:48 +00:00
*
* 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 .
*/
2005-05-06 20:02:20 +00:00
?>
< ?
function getProjectsEligibleForAward ( $award_id )
{
global $config ;
2025-01-05 16:04:50 -05:00
global $pdo ;
2005-05-06 20:02:20 +00:00
2025-01-29 03:30:48 +00:00
$prjq = $pdo -> prepare ( " SELECT
2005-05-06 20:02:20 +00:00
award_awards . id ,
award_awards_projectcategories . projectcategories_id ,
award_awards_projectdivisions . projectdivisions_id ,
projects . projectnumber ,
projects . title ,
2010-01-27 20:24:19 +00:00
projects . id AS projects_id ,
projects . fairs_id
2005-05-06 20:02:20 +00:00
FROM
award_awards ,
award_awards_projectcategories ,
award_awards_projectdivisions ,
projects
WHERE
award_awards . id = '$award_id'
AND award_awards . id = award_awards_projectcategories . award_awards_id
AND award_awards . id = award_awards_projectdivisions . award_awards_id
AND projects . projectcategories_id = award_awards_projectcategories . projectcategories_id
AND projects . projectdivisions_id = award_awards_projectdivisions . projectdivisions_id
AND projects . projectnumber is not null
2025-01-29 03:30:48 +00:00
AND projects . year = '" . $config[' FAIRYEAR '] . "'
2005-05-06 20:02:20 +00:00
ORDER BY
2007-12-29 08:46:40 +00:00
projectsort
2005-05-06 20:02:20 +00:00
" );
2024-12-09 01:06:15 -05:00
$prjq -> execute ();
2025-01-29 03:30:48 +00:00
$projects = array ();
while ( $prjr = $prjq -> fetch ( PDO :: FETCH_OBJ )) {
$projects [ $prjr -> projectnumber ] = array (
'id' => $prjr -> projects_id ,
'projectnumber' => $prjr -> projectnumber ,
'title' => $prjr -> title ,
'fairs_id' => $prjr -> fairs_id
);
2005-05-06 20:02:20 +00:00
}
return $projects ;
}
2011-03-30 21:40:50 +00:00
function getLanguagesOfProjectsEligibleForAward ( $award_id )
{
2025-01-28 17:33:03 -05:00
global $config , $pdo ;
2011-03-30 21:40:50 +00:00
2025-01-29 03:30:48 +00:00
$prjq = $pdo -> prepare ( " SELECT DISTINCT(projects.language) AS language
2011-03-30 21:40:50 +00:00
FROM
award_awards ,
award_awards_projectcategories ,
award_awards_projectdivisions ,
projects
WHERE
award_awards . id = '$award_id'
AND award_awards . id = award_awards_projectcategories . award_awards_id
AND award_awards . id = award_awards_projectdivisions . award_awards_id
AND projects . projectcategories_id = award_awards_projectcategories . projectcategories_id
AND projects . projectdivisions_id = award_awards_projectdivisions . projectdivisions_id
AND projects . projectnumber is not null
2025-01-29 03:30:48 +00:00
AND projects . year = '" . $config[' FAIRYEAR '] . "'
2011-03-30 21:40:50 +00:00
ORDER BY
language
" );
2024-12-09 01:06:15 -05:00
$prjq -> execute ();
2025-01-29 03:30:48 +00:00
$languages = array ();
while ( $r = $prjq -> fetch ( PDO :: FETCH_OBJ )) {
if ( $r -> language )
$languages [] = $r -> language ;
2011-03-30 21:40:50 +00:00
}
return $languages ;
}
2005-05-12 19:47:50 +00:00
function getProjectsEligibleOrNominatedForAwards ( $awards_ids_array )
2005-05-06 20:02:20 +00:00
{
2025-01-29 03:30:48 +00:00
global $pdo ;
$projects = array ();
2025-02-10 19:54:20 +00:00
foreach ( $awards_ids_array as $award_id ) {
2025-01-29 03:30:48 +00:00
$q = $pdo -> prepare ( " SELECT award_types.type FROM award_awards, award_types WHERE award_awards.id=' $award_id ' AND award_awards.award_types_id=award_types.id " );
2024-12-09 01:06:15 -05:00
$q -> execute ();
2025-01-29 03:30:48 +00:00
$r = $q -> fetch ( PDO :: FETCH_OBJ );
2005-05-12 19:47:50 +00:00
2025-01-29 03:30:48 +00:00
$awardprojects = array ();
2005-05-12 19:47:50 +00:00
2025-01-29 03:30:48 +00:00
// for special awards, we only want the ones that were nominated for it.
// for everything else, we weant all the eligible projects
if ( $r -> type == 'Special' )
$awardprojects = getProjectsNominatedForSpecialAward ( $award_id );
2005-05-12 19:47:50 +00:00
else
2025-01-29 03:30:48 +00:00
$awardprojects = getProjectsEligibleForAward ( $award_id );
2005-05-12 19:47:50 +00:00
2025-01-29 03:30:48 +00:00
// $projects[$award_id]=$awardprojects;
2005-05-12 19:47:50 +00:00
2025-01-29 03:30:48 +00:00
// this will just overwrite ones that already exist, but still keep things in order because the main key is the projectnumber (i hope)
2025-02-10 19:54:20 +00:00
foreach ( $awardprojects as $proj )
2025-01-29 03:30:48 +00:00
$projects [ $proj [ 'projectnumber' ]] = $proj ;
2005-05-06 20:02:20 +00:00
}
return $projects ;
}
2005-05-10 21:51:22 +00:00
2005-05-11 04:13:27 +00:00
function getSpecialAwardsEligibleForProject ( $projectid )
2005-05-10 21:51:22 +00:00
{
2025-01-28 17:33:03 -05:00
global $config , $pdo ;
2005-05-10 21:51:22 +00:00
2025-01-29 03:30:48 +00:00
$awardsq = $pdo -> prepare ( " SELECT
2005-05-11 04:13:27 +00:00
award_awards . id ,
award_awards . name ,
award_awards . criteria ,
award_awards_projectcategories . projectcategories_id ,
award_awards_projectdivisions . projectdivisions_id ,
2008-01-24 07:46:12 +00:00
projects . id AS projects_id ,
award_awards . self_nominate
2005-05-11 04:13:27 +00:00
FROM
award_awards ,
award_awards_projectcategories ,
award_awards_projectdivisions ,
award_types ,
projects
WHERE
award_types . type = 'Special'
AND award_types . id = award_awards . award_types_id
AND award_awards . id = award_awards_projectcategories . award_awards_id
AND award_awards . id = award_awards_projectdivisions . award_awards_id
2025-02-04 20:35:59 +00:00
AND projects . projectcategories_id = award_awards_projectcategories . projectcategories_id
2005-05-11 04:13:27 +00:00
AND projects . projectdivisions_id = award_awards_projectdivisions . projectdivisions_id
AND award_awards . id is not null
2025-01-29 03:30:48 +00:00
AND projects . year = '" . $config[' FAIRYEAR '] . "'
2005-05-11 04:13:27 +00:00
AND projects . id = '$projectid'
2025-01-29 03:30:48 +00:00
AND award_types . year = '" . $config[' FAIRYEAR '] . "'
AND award_awards . year = '" . $config[' FAIRYEAR '] . "'
2005-05-11 04:13:27 +00:00
ORDER BY
award_awards . name
" );
2025-01-29 03:30:48 +00:00
$awardsq -> execute ();
$awards = array ();
show_pdo_errors_if_any ( $pdo );
while ( $r = $awardsq -> fetch ( PDO :: FETCH_OBJ )) {
$awards [ $r -> id ] = array (
'id' => $r -> id ,
'criteria' => $r -> criteria ,
'name' => $r -> name ,
'self_nominate' => $r -> self_nominate
);
2005-05-11 04:13:27 +00:00
}
return $awards ;
}
function getSpecialAwardsNominatedForProject ( $projectid )
{
2025-01-19 21:13:25 -05:00
global $config , $pdo ;
2005-05-11 04:13:27 +00:00
2025-01-29 03:30:48 +00:00
$awardsq = $pdo -> prepare ( " SELECT
2005-05-11 04:13:27 +00:00
award_awards . id ,
award_awards . name ,
award_awards . criteria ,
2010-01-27 20:24:19 +00:00
projects . id AS projects_id ,
projects . fairs_id
2005-05-11 04:13:27 +00:00
FROM
award_awards ,
project_specialawards_link ,
projects
WHERE
project_specialawards_link . projects_id = '$projectid'
AND project_specialawards_link . award_awards_id = award_awards . id
2025-01-29 03:30:48 +00:00
AND projects . year = '" . $config[' FAIRYEAR '] . "'
2005-05-11 04:13:27 +00:00
AND projects . id = '$projectid'
ORDER BY
award_awards . name
" );
2024-12-09 01:06:15 -05:00
$awardsq -> execute ();
2025-01-29 03:30:48 +00:00
$awards = array ();
show_pdo_errors_if_any ( $pdo );
while ( $r = $awardsq -> fetch ( PDO :: FETCH_OBJ )) {
$awards [ $r -> id ] = array (
'id' => $r -> id ,
'criteria' => $r -> criteria ,
'name' => $r -> name ,
'fairs_id' => $r -> fairs_id
);
2005-05-11 04:13:27 +00:00
}
return $awards ;
}
2007-03-05 04:27:44 +00:00
function getNominatedForNoSpecialAwardsForProject ( $projectid )
{
2025-01-19 21:13:25 -05:00
global $config , $pdo ;
2025-01-29 03:30:48 +00:00
$awardsq = $pdo -> prepare ( " SELECT
2007-03-05 04:27:44 +00:00
projects . id AS projects_id
FROM
project_specialawards_link ,
projects
WHERE
project_specialawards_link . projects_id = '$projectid'
2025-01-29 03:30:48 +00:00
AND projects . year = '" . $config[' FAIRYEAR '] . "'
2007-03-05 04:27:44 +00:00
AND projects . id = '$projectid'
AND project_specialawards_link . award_awards_id IS NULL
" );
2024-12-09 01:06:15 -05:00
$awardsq -> execute ();
2025-01-29 03:30:48 +00:00
if ( $awardsq -> rowCount () == 1 )
return true ;
return false ;
2007-03-05 04:27:44 +00:00
}
2005-05-12 19:47:50 +00:00
function getProjectsNominatedForSpecialAward ( $award_id )
{
2025-01-28 17:33:03 -05:00
global $config , $pdo ;
2005-05-12 19:47:50 +00:00
2025-01-29 03:30:48 +00:00
// if they dont use special award nominations, then we will instead get all of the projects that
// are eligible for the award, instead of nominated for it.
if ( $config [ 'specialawardnomination' ] != 'none' ) {
$prjq = $pdo -> prepare ( " SELECT
2006-01-26 15:06:56 +00:00
projects . projectnumber ,
projects . title ,
2011-03-30 21:40:50 +00:00
projects . language ,
2006-01-26 15:06:56 +00:00
projects . id AS projects_id
FROM
project_specialawards_link ,
projects
WHERE
project_specialawards_link . award_awards_id = '$award_id'
AND project_specialawards_link . projects_id = projects . id
AND projects . projectnumber is not null
2025-01-29 03:30:48 +00:00
AND projects . year = '" . $config[' FAIRYEAR '] . "'
2006-01-26 15:06:56 +00:00
ORDER BY
2007-12-29 08:46:40 +00:00
projectsort
2006-01-26 15:06:56 +00:00
" );
2024-12-09 01:06:15 -05:00
$prjq -> execute ();
2025-01-29 03:30:48 +00:00
$projects = array ();
while ( $prjr = $prjq -> fetch ( PDO :: FETCH_OBJ )) {
$projects [ $prjr -> projectnumber ] = array (
'id' => $prjr -> projects_id ,
'projectnumber' => $prjr -> projectnumber ,
'language' => $prjr -> language ,
'title' => $prjr -> title
);
2006-01-26 15:06:56 +00:00
}
2025-01-29 03:30:48 +00:00
// return the projects that have self-nominated themselves for the award
2006-01-26 15:06:56 +00:00
return $projects ;
2025-01-29 03:30:48 +00:00
} else {
// return the projects that are eligible for the award instead
2006-01-26 15:06:56 +00:00
return getProjectsEligibleForAward ( $award_id );
2005-05-12 19:47:50 +00:00
}
}
2011-03-30 21:40:50 +00:00
function getLanguagesOfProjectsNominatedForSpecialAward ( $award_id )
{
2025-01-19 21:13:25 -05:00
global $config , $pdo ;
2011-03-30 21:40:50 +00:00
2025-01-29 03:30:48 +00:00
// if they dont use special award nominations, then we will instead get all of the projects that
// are eligible for the award, instead of nominated for it.
if ( $config [ 'specialawardnomination' ] != 'none' ) {
$prjq = $pdo -> prepare ( " SELECT DISTINCT(projects.language) AS language
2011-03-30 21:40:50 +00:00
FROM
project_specialawards_link ,
projects
WHERE
project_specialawards_link . award_awards_id = '$award_id'
AND project_specialawards_link . projects_id = projects . id
AND projects . projectnumber is not null
2025-01-29 03:30:48 +00:00
AND projects . year = '" . $config[' FAIRYEAR '] . "'
2011-03-30 21:40:50 +00:00
ORDER BY language
" );
2024-12-09 01:06:15 -05:00
$prjq -> execute ();
2025-01-29 03:30:48 +00:00
$languages = array ();
while ( $r = $prjq -> fetch ( PDO :: FETCH_OBJ )) {
// dont count "" as a language, if the project doesnt have a language specified too bad they're up shit creek without a paddle
if ( $r -> langauge ) {
$languages [] = $r -> language ;
2011-03-30 21:40:50 +00:00
}
}
return $languages ;
2025-01-29 03:30:48 +00:00
} else {
// return the projects that are eligible for the award instead
2011-03-30 21:40:50 +00:00
return getLanguagesOfProjectsEligibleForAward ( $award_id );
}
}
2005-05-11 04:13:27 +00:00
function getSpecialAwardsNominatedByRegistrationID ( $id )
{
2025-01-28 17:33:03 -05:00
global $config , $pdo ;
2005-05-11 04:13:27 +00:00
2025-01-29 03:30:48 +00:00
$awardq = $pdo -> prepare ( " SELECT
2005-05-10 21:51:22 +00:00
award_awards . id ,
award_awards . name ,
award_awards_projectcategories . projectcategories_id ,
award_awards_projectdivisions . projectdivisions_id ,
projects . id AS projects_id
FROM
award_awards ,
award_awards_projectcategories ,
award_awards_projectdivisions ,
projects
WHERE
award_awards . id = '$award_id'
AND award_awards . id = award_awards_projectcategories . award_awards_id
AND award_awards . id = award_awards_projectdivisions . award_awards_id
AND projects . projectcategories_id = award_awards_projectcategories . projectcategories_id
AND projects . projectdivisions_id = award_awards_projectdivisions . projectdivisions_id
AND projects . projectnumber is not null
2025-01-29 03:30:48 +00:00
AND projects . year = '" . $config[' FAIRYEAR '] . "'
2005-05-10 21:51:22 +00:00
ORDER BY
2007-12-29 08:46:40 +00:00
projectsort
2005-05-10 21:51:22 +00:00
" );
2024-12-09 01:06:15 -05:00
$awardq -> execute ();
2025-01-29 03:30:48 +00:00
$projects = array ();
2025-02-04 20:35:59 +00:00
while ( $prjr = $awardq -> fetch ( PDO :: FETCH_OBJ )) {
2025-01-29 03:30:48 +00:00
$projects [ $prjr -> projectnumber ] = array (
'id' => $prjr -> projects_id ,
'projectnumber' => $prjr -> projectnumber ,
'title' => $prjr -> title
);
2005-05-10 21:51:22 +00:00
}
return $projects ;
}
2009-09-25 19:14:37 +00:00
function project_load ( $pid )
{
2025-01-28 17:33:03 -05:00
global $pdo ;
2009-09-25 19:14:37 +00:00
/* Load this project */
2024-12-09 01:06:15 -05:00
$q = $pdo -> prepare ( " SELECT * FROM projects WHERE id=' $pid ' " );
$q -> execute ();
$proj = $q -> fetch ();
2009-09-25 19:14:37 +00:00
/* Load the students */
2024-12-09 01:06:15 -05:00
$q = $pdo -> prepare ( " SELECT students.*,schools.school FROM students
2009-09-25 19:14:37 +00:00
LEFT JOIN schools ON schools . id = students . schools_id
WHERE registrations_id = '{$proj[' registrations_id ']}' AND students . year = '{$proj[' year ']}' ORDER BY students . id " );
2024-12-09 01:06:15 -05:00
$q -> execute ();
2009-09-25 19:14:37 +00:00
$proj [ 'num_students' ] = 0 ;
2025-01-29 03:30:48 +00:00
while ( $s = $q -> fetch ( PDO :: FETCH_OBJ )) {
2009-09-25 19:14:37 +00:00
$proj [ 'num_students' ] ++ ;
$proj [ 'student' ][] = $s ;
}
return $proj ;
}
2005-05-10 21:51:22 +00:00
?>