2006-01-31 22:34:04 +00:00
< ?
2006-08-01 19:43:15 +00:00
function judges_scheduler_check_timeslots ()
2006-01-31 22:34:04 +00:00
{
2024-12-19 22:29:06 -05:00
global $config , $pdo ;
2006-01-31 22:34:04 +00:00
2025-01-29 03:30:48 +00:00
$q = $pdo -> prepare ( 'SELECT * FROM judges_timeslots WHERE '
2025-02-09 17:24:37 +00:00
. " year=? "
2025-01-29 03:30:48 +00:00
. " AND `type`='divisional1' " );
2025-02-09 17:24:37 +00:00
$q -> execute ([ $config [ 'FAIRYEAR' ]]);
2025-01-29 03:30:48 +00:00
if ( $q -> rowCount ()) {
$round = $q -> fetch ( PDO :: FETCH_OBJ );
2025-02-09 17:24:37 +00:00
$q = $pdo -> prepare ( " SELECT * FROM judges_timeslots WHERE round_id=? AND type='timeslot' " );
$q -> execute ([ $round -> id ]);
2024-12-06 20:54:02 -05:00
return $q -> rowCount ();
2025-01-29 03:30:48 +00:00
} else
2010-01-18 16:24:34 +00:00
return 0 ;
2006-08-01 19:43:15 +00:00
}
2006-01-31 22:34:04 +00:00
2010-03-26 06:03:31 +00:00
function judges_scheduler_check_timeslots_sa ()
{
2024-12-19 22:29:06 -05:00
global $config , $pdo ;
2010-03-26 06:03:31 +00:00
$rows = 0 ;
2025-01-29 03:30:48 +00:00
$q = $pdo -> prepare ( 'SELECT * FROM judges_timeslots WHERE '
2025-02-09 17:24:37 +00:00
. " year=? "
2025-01-29 03:30:48 +00:00
. " AND `type`='special' " );
2025-02-09 17:24:37 +00:00
$q -> execute ([ $config [ 'FAIRYEAR' ]]);
2025-01-29 03:30:48 +00:00
if ( $q -> rowCount ()) {
while (( $round = $q -> fetch ( PDO :: FETCH_OBJ ))) {
2025-02-09 17:24:37 +00:00
$rq = $pdo -> prepare ( " SELECT * FROM judges_timeslots WHERE round_id=? AND type='timeslot' " );
$rq -> execute ([ $round -> id ]);
2024-12-06 20:54:02 -05:00
$rows += $rq -> rowCount ();
2010-03-26 06:03:31 +00:00
}
}
return $rows ;
}
2006-08-01 19:43:15 +00:00
function judges_scheduler_check_awards ()
{
2024-12-19 22:29:06 -05:00
global $config , $pdo ;
2006-01-31 22:34:04 +00:00
2025-02-09 17:24:37 +00:00
$q = $pdo -> prepare ( " SELECT * FROM projectdivisions WHERE year=? ORDER BY id " );
$q -> execute ([ $config [ 'FAIRYEAR' ]]);
2025-01-29 03:30:48 +00:00
while ( $r = $q -> fetch ( PDO :: FETCH_OBJ ))
$div [ $r -> id ] = $r -> division ;
2006-01-31 22:34:04 +00:00
2025-02-09 17:24:37 +00:00
$q = $pdo -> prepare ( " SELECT * FROM projectcategories WHERE year=? ORDER BY id " );
$q -> execute ([ $config [ 'FAIRYEAR' ]]);
2025-01-29 03:30:48 +00:00
while ( $r = $q -> fetch ( PDO :: FETCH_OBJ ))
$cat [ $r -> id ] = $r -> category ;
2006-01-31 22:34:04 +00:00
2006-08-01 19:43:15 +00:00
$dkeys = array_keys ( $div );
$ckeys = array_keys ( $cat );
2025-01-29 03:30:48 +00:00
if ( $config [ 'filterdivisionbycategory' ] == 'yes' ) {
2025-02-09 17:24:37 +00:00
$q = $pdo -> prepare ( " SELECT * FROM projectcategoriesdivisions_link WHERE year=? ORDER BY projectdivisions_id,projectcategories_id " );
$q -> execute ([ $config [ 'FAIRYEAR' ]]);
2025-01-29 03:30:48 +00:00
$divcat = array ();
while ( $r = $q -> fetch ( PDO :: FETCH_OBJ )) {
$divcat [] = array ( 'c' => $r -> projectcategories_id , 'd' => $r -> projectdivisions_id );
2007-12-10 19:21:21 +00:00
}
2025-01-29 03:30:48 +00:00
} else {
$divcat = array ();
foreach ( $dkeys AS $d ) {
foreach ( $ckeys AS $c ) {
$divcat [] = array ( 'c' => $c , 'd' => $d );
2007-12-10 19:21:21 +00:00
}
}
}
2006-08-01 19:43:15 +00:00
$missing_awards = array ();
2025-01-29 03:30:48 +00:00
foreach ( $divcat AS $dc ) {
$d = $dc [ 'd' ];
$c = $dc [ 'c' ];
$q = $pdo -> prepare ( " SELECT award_awards.id FROM
2006-01-31 22:34:04 +00:00
award_awards ,
award_awards_projectcategories ,
award_awards_projectdivisions
WHERE
2025-02-09 17:24:37 +00:00
award_awards . year = ?
AND award_awards_projectcategories . year = ?
AND award_awards_projectdivisions . year = ?
2006-01-31 22:34:04 +00:00
AND award_awards . id = award_awards_projectcategories . award_awards_id
AND award_awards . id = award_awards_projectdivisions . award_awards_id
2025-02-09 17:24:37 +00:00
AND award_awards_projectcategories . projectcategories_id = ?
AND award_awards_projectdivisions . projectdivisions_id = ?
2006-01-31 22:34:04 +00:00
AND award_awards . award_types_id = '1'
" );
2025-02-09 17:24:37 +00:00
$q -> execute ([ $config [ 'FAIRYEAR' ], $config [ 'FAIRYEAR' ], $config [ 'FAIRYEAR' ], $c , $d ]);
2025-01-29 03:30:48 +00:00
show_pdo_errors_if_any ( $pdo );
if ( $q -> rowCount () != 1 ) {
$missing_awards [] = " { $cat [ $c ] } - { $div [ $d ] } ( " . i18n ( '%1 found' , array ( $q -> rowCount ())) . ')' ;
}
2006-01-31 22:34:04 +00:00
}
2006-08-01 19:43:15 +00:00
return $missing_awards ;
}
function judges_scheduler_check_jdivs ()
{
2024-12-19 22:29:06 -05:00
global $config , $pdo ;
2006-08-01 19:43:15 +00:00
2025-01-29 03:30:48 +00:00
$q = $pdo -> prepare ( 'SELECT DISTINCT jdiv_id FROM judges_jdiv ' );
2024-12-06 20:54:02 -05:00
$q -> execute ();
$rows = $q -> rowCount ();
2006-08-01 19:43:15 +00:00
return $rows ;
}
function judges_scheduler_check_judges ()
{
2024-12-19 22:29:06 -05:00
global $config , $pdo ;
2006-08-11 21:10:33 +00:00
$ok = 1 ;
2006-08-01 19:43:15 +00:00
$jdiv = array ();
2024-12-19 22:29:06 -05:00
$projectlanguagetotal = array ();
$projecttotal = 0 ;
2025-01-29 03:30:48 +00:00
$q = $pdo -> prepare ( 'SELECT * FROM judges_jdiv ORDER BY jdiv_id' );
2024-12-06 20:54:02 -05:00
$q -> execute ();
2025-01-29 03:30:48 +00:00
while ( $r = $q -> fetch ( PDO :: FETCH_OBJ )) {
2008-02-28 20:23:27 +00:00
/* Ignore any div/cat with jdiv 0 */
2025-01-29 03:30:48 +00:00
if ( $r -> jdiv_id == 0 )
continue ;
2008-02-28 20:23:27 +00:00
2006-08-01 19:43:15 +00:00
$d = $r -> projectdivisions_id ;
$c = $r -> projectcategories_id ;
$l = $r -> lang ;
2025-01-29 03:30:48 +00:00
$qp = $pdo -> prepare ( 'SELECT COUNT(projects.id) as cnt FROM projects, registrations WHERE '
2025-02-09 17:24:37 +00:00
. " projects.year=? AND "
. " projectdivisions_id=? AND "
. " projectcategories_id=? AND "
. " language=? AND "
2025-01-29 03:30:48 +00:00
. ' registrations.id = projects.registrations_id '
. getJudgingEligibilityCode ());
2025-02-09 17:24:37 +00:00
$qp -> execute ([ $config [ 'FAIRYEAR' ], $d , $c , $l ]);
2024-12-06 20:54:02 -05:00
$qr = $qp -> fetch ( PDO :: FETCH_OBJ );
2025-01-29 03:30:48 +00:00
// if (get_value_from_3d_array($jdiv, $r->jdiv_id, 'num_projects', 'total') !== null){
$jdiv [ $r -> jdiv_id ][ 'num_projects' ][ 'total' ] += $qr -> cnt ;
// }
2025-01-21 02:07:33 -05:00
$jdiv [ $r -> jdiv_id ][ 'num_projects' ][ $l ] += $qr -> cnt ;
2009-03-27 20:31:57 +00:00
2025-01-29 03:30:48 +00:00
$projectlanguagetotal [ $l ] += $qr -> cnt ;
$projecttotal += $qr -> cnt ;
2006-01-31 22:34:04 +00:00
}
2009-03-27 20:31:57 +00:00
$totalteams [ 'total' ] = 0 ;
2025-01-29 03:30:48 +00:00
echo '<table border=1 width="85%"><tr><th></th>'
. '<th colspan="' . ( count ( $config [ 'languages' ]) + 1 ) . '">' . i18n ( 'Projects' ) . '</th>'
. '<th colspan="' . ( count ( $config [ 'languages' ]) + 1 ) . '">' . i18n ( 'Estimated Required Teams' ) . '</th></tr>' ;
echo '<tr>' ;
echo '<th></th><th>' . i18n ( 'Total' ) . '</th>' ;
foreach ( $config [ 'languages' ] AS $lkey => $lname )
echo " <th> $lkey </th> " ;
echo '<th>' . i18n ( 'Total' ) . '</th>' ;
foreach ( $config [ 'languages' ] AS $lkey => $lname )
echo " <th> $lkey </th> " ;
echo " </tr> \n " ;
foreach ( $jdiv AS $jdiv_id => $jd ) {
$c = $jd [ 'num_projects' ][ 'total' ];
// total judge teams calculation
$t [ 'total' ] = ceil ( $c / $config [ 'max_projects_per_team' ] * $config [ 'times_judged' ]);
if ( $t [ 'total' ] < $config [ 'times_judged' ] && $c > 0 )
$t [ 'total' ] = $config [ 'times_judged' ];
$jdiv [ $jdiv_id ][ 'num_jteams' ][ 'total' ] = $t [ 'total' ];
$totalteams [ 'total' ] += $t [ 'total' ];
// language teams calculation
foreach ( $config [ 'languages' ] AS $lkey => $lname ) {
$c = $jd [ 'num_projects' ][ $lkey ];
$t [ 'total_' . $lkey ] = ceil ( $c / $config [ 'max_projects_per_team' ] * $config [ 'times_judged' ]);
if ( $t [ 'total_' . $lkey ] < $config [ 'times_judged' ] && $c > 0 )
$t [ 'total_' . $lkey ] = $config [ 'times_judged' ];
$jdiv [ $jdiv_id ][ 'num_jteams' ][ 'total_' . $lkey ] = $t [ 'total_' . $lkey ];
$totalteams [ 'total_' . $lkey ] += $t [ 'total_' . $lkey ];
}
2010-04-06 18:30:23 +00:00
2025-01-29 03:30:48 +00:00
echo " <tr><td>Judging Division Group $jdiv_id </td> " ;
echo " <td align= \" center \" > { $jd [ 'num_projects' ][ 'total' ] } </td> " ;
$langstr = '' ;
foreach ( $config [ 'languages' ] AS $lkey => $lname ) {
$clang = ( $jd [ 'num_projects' ][ $lkey ] ? $jd [ 'num_projects' ][ $lkey ] : 0 );
echo " <td align= \" center \" > $clang </td> " ;
}
echo " <td align= \" center \" > { $t [ 'total' ] } </td> " ;
foreach ( $config [ 'languages' ] AS $lkey => $lname ) {
$clang = ( $jd [ 'num_projects' ][ $lkey ] ? $jd [ 'num_projects' ][ $lkey ] : 0 );
// echo "<td align=\"center\">{$t['total']}</td>";
echo " <td align= \" center \" > { $t [ 'total_' . $lkey ] } </td> " ;
2010-04-06 18:30:23 +00:00
}
2009-03-27 20:31:57 +00:00
2025-01-29 03:30:48 +00:00
echo '</tr>' ;
2006-08-01 19:43:15 +00:00
}
2025-01-29 03:30:48 +00:00
echo '</table>' ;
echo '<br />' ;
echo '<b>' ;
echo i18n ( 'Total judging teams required: %1' , array ( $totalteams [ 'total' ]));
echo '<br />' ;
echo '<br />' ;
$minjudges [ 'total' ] = ( $totalteams [ 'total' ] * $config [ 'min_judges_per_team' ]);
$maxjudges [ 'total' ] = ( $totalteams [ 'total' ] * $config [ 'max_judges_per_team' ]);
echo i18n ( 'Minimum number of judges required: %1' , array ( $minjudges [ 'total' ])) . '<br />' ;
foreach ( $config [ 'languages' ] AS $lkey => $lname ) {
if ( $minjudges [ 'total' ] && $projecttotal )
$minjudges [ $lkey ] = round ( $totalteams [ 'total_' . $lkey ] * $config [ 'min_judges_per_team' ]); // $projectlanguagetotal[$lkey]/$projecttotal*$minjudges['total']);
else
$minjudges [ $lkey ] = 0 ;
echo ' ' . i18n ( 'Minimum number of %1 judges required: %2' , array ( $lname , $minjudges [ $lkey ])) . '<br />' ;
}
echo i18n ( 'Maximum number of judges needed: %1' , array ( $maxjudges [ 'total' ]));
echo '<br />' ;
echo '<br />' ;
/* $jq = mysql_query ( " SELECT COUNT(judges.id) AS num FROM judges,judges_years WHERE complete='yes' AND deleted='no' AND judges_years.year=' { $config [ 'FAIRYEAR' ] } ' AND judges_years.judges_id=judges.id " );
$jr = mysql_fetch_object ( $jq );
$currentjudges = $jr -> num ; */
2009-09-09 00:26:12 +00:00
/* FIXME: this his highly inefficient :), but won't be done very often */
$judges = judges_load_all ();
$currentjudges = count ( $judges );
2006-08-01 19:43:15 +00:00
echo " Current number of registered judges: $currentjudges " ;
2025-01-29 03:30:48 +00:00
echo '</b>' ;
echo '<br />' ;
if ( $currentjudges < $minjudges [ 'total' ]) {
echo error ( i18n ( 'You do not have sufficient number of total judges based on your parameters' ));
$ok = false ;
}
foreach ( $config [ 'languages' ] AS $lkey => $lname ) {
$lcount = 0 ;
foreach ( $judges AS $j ) {
foreach ( $j [ 'languages' ] AS $jlang ) {
if ( $jlang == $lkey )
$lcount ++ ;
2010-01-08 20:25:40 +00:00
}
}
2025-01-29 03:30:48 +00:00
$currentjudges = $lcount ;
echo ' <b>' . i18n ( 'Current number of registered judges that can judge in %1: %2' , array ( $lname , $currentjudges )) . '</b>' ;
echo '<br />' ;
if ( $currentjudges < $minjudges [ $lkey ]) {
echo error ( i18n ( 'You do not have sufficient number of %1 judges based on your parameters' , array ( $lname )));
$ok = false ;
}
2006-01-31 22:34:04 +00:00
}
2025-01-29 03:30:48 +00:00
if ( ! $ok ) {
echo ' ' ;
echo '<a href="judges_schedulerconfig.php">' . i18n ( 'Update Scheduler Configuration' ) . '</a> (' . i18n ( 'or get more judges!' ) . ')' ;
} else
echo happy ( i18n ( 'You have a sufficient number of judges based on your parameters' ));
// now check if we can find a divisional award for each division and category
2006-01-31 22:34:04 +00:00
return $ok ;
}
?>