* Copyright (C) 2005 James Grant * Copyright (C) 2024 AlgoLibre Inc. * * 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. */ ?> prepare("SELECT * FROM fairs WHERE type='feeder' ORDER BY name"); $q->execute(); while (($f = $q->fetch(PDO::FETCH_ASSOC))) { $fairs[$f['id']] = $f; } switch ($action) { case 'addwinner': $prize_id = intval($_GET['prize_id']); $projects_id = intval($_GET['projects_id']); if (!$prize_id || !$projects_id) { error_('Illegal Assignment'); exit; } // first check how many we are allowed to have $q = $pdo->prepare("SELECT number FROM award_prizes WHERE id=?"); $q->execute([$prize_id]); show_pdo_errors_if_any($pdo); $r = $q->fetch(PDO::FETCH_ASSOC); $number = $r['number']; /* Get the award info */ $q = $pdo->prepare("SELECT * FROM award_awards WHERE id=?"); $q->execute([$award_awards_id]); show_pdo_errors_if_any($pdo); $a = $q->fetch(PDO::FETCH_ASSOC); /* Get the project */ $q = $pdo->prepare("SELECT fairs_id FROM projects WHERE id=?"); $q->execute([$projects_id]); show_pdo_errors_if_any($pdo); $p = $q->fetch(PDO::FETCH_ASSOC); $fairs_id = $p['fairs_id']; /* * Quick sanity check don't let a fair user do an assignment for someone not * in their fair */ if ($auth_type == 'fair' && $fairs_id != $_SESSION['fairs_id']) { error_('Illegal Assignemnt'); exit; } if ($a['per_fair'] == 'yes') { /* Count is the number of this fair already assigned */ $q = $pdo->prepare("SELECT COUNT(*) AS count FROM winners LEFT JOIN projects ON winners.projects_id=projects.id WHERE projects.fairs_id=? awards_prizes_id=?"); $q->execute([$fairs_id,$prize_id]); show_pdo_errors_if_any($pdo); $r = $q->fetch(PDO::FETCH_ASSOC); $count = $r['count']; } else { /* Count is the total number assigned */ $q = $pdo->prepare("SELECT COUNT(*) AS count FROM winners WHERE awards_prizes_id=?"); $q->execute([$prize_id]); show_pdo_errors_if_any($pdo); $r = $q->fetch(PDO::FETCH_ASSOC); $count = $r['count']; } if ($count < $number) { $stmt = $pdo->prepare("INSERT INTO winners (awards_prizes_id,projects_id,year) VALUES (?,?,?)"); $stmt->execute([$prize_id,$projects_id,$config['FAIRYEAR']]); happy_('Winning project added'); } else { error_('This prize cannot accept any more winners. Maximum: %1', $number); } exit; case 'deletewinner': $prize_id = intval($_GET['prize_id']); $projects_id = intval($_GET['projects_id']); if ($prize_id && $projects_id) { $stmt = $pdo->prepare("DELETE FROM winners WHERE awards_prizes_id=? AND projects_id=?"); $stmt->execute([$prize_id,$projects_id]); happy_('Winning project removed'); } exit; case 'award_load': $fairs_id = intval($_GET['fairs_id']); /* Load the award */ $q = $pdo->prepare("SELECT award_awards.id, award_awards.name, award_awards.criteria, award_awards.order AS awards_order, award_awards.per_fair, award_awards.external_additional_materials, award_awards.award_source_fairs_id, award_types.type FROM award_awards , award_types WHERE award_awards.year=? AND\taward_awards.award_types_id=award_types.id AND \taward_types.year=award_awards.year AND\taward_awards.id=? "); $q->execute([$config['FAIRYEAR'],$award_awards_id]); show_pdo_errors_if_any($pdo); if ($q->rowCount() != 1) { echo i18n("Invalid award to load $award_awards_id"); exit; } $r = $q->fetch(PDO::FETCH_ASSOC); print_award($r, $fairs_id); exit; case 'edit_load': $fairs_id = intval($_GET['fairs_id']); /* Force the fair user to only edit their fair */ // if($auth_type == 'fair') $fairs_id = $_SESSION['fairs_id']; /* Load the award */ $q = $pdo->prepare("SELECT award_awards.id, award_awards.name, award_awards.criteria, award_awards.order AS awards_order, award_awards.per_fair, award_awards.external_additional_materials, award_awards.award_source_fairs_id, award_types.type FROM award_awards , award_types WHERE award_awards.year=? AND\taward_awards.award_types_id=award_types.id AND \taward_types.year=award_awards.year AND\taward_awards.id=? "); $q->execute([$config['FAIRYEAR'],$award_awards_id]); show_pdo_errors_if_any($pdo); if ($q->rowCount() != 1) { echo i18n("Invalid award to edit $award_awards_id"); exit; } $r = $q->fetch(PDO::FETCH_ASSOC); $editor_data = array(); /* Load projects */ if ($r['type'] == 'Special') { $editor_data['projects_nominated'] = getProjectsNominatedForSpecialAward($r['id']); $editor_data['disable_nominated'] = false; } else { $editor_data['projects_nominated'] = array(); $editor_data['disable_nominated'] = true; } $editor_data['projects_eligible'] = getProjectsEligibleForAward($r['id']); /* Print the award header */ echo '
'; if ($fairs_id) echo '

' . i18n('Winners from') . ": {$fairs[$fairs_id]['name']}

"; echo "{$r['type']} - {$r['name']}
"; echo "{$r['criteria']}
"; /* Print the award with editor */ print_award($r, $fairs_id, true, $editor_data); exit; case 'additional_materials': $fairs_id = intval($_GET['fairs_id']); $q = $pdo->prepare("SELECT * FROM award_awards WHERE id=?"); $q->execute([$award_awards_id]); if ($fairs_id == 0) { echo "Unsupported Action: Can't get additional materials for fairs_id=0. Edit the project and set it's fair to anything except 'Local/Unspecified'."; exit; } $a = $q->fetch(PDO::FETCH_ASSOC); $q = $pdo->prepare("SELECT * FROM fairs WHERE id=?"); $q->execute([$fairs_id]); $fair = $q->fetch(PDO::FETCH_ASSOC); $pdf = fair_additional_materials($fair, $a, $config['FAIRYEAR']); foreach ($pdf['header'] as $h) header($h); echo $pdf['data']; exit; } if ($auth_type == 'fair') { send_header('Enter Winning Projects', array('Science Fair Main' => 'fair_main.php'), 'enter_winning_projects'); } else { send_header('Enter Winning Projects', array('Committee Main' => 'committee_main.php', 'Administration' => 'admin/index.php'), 'enter_winning_projects'); } ?> prepare("SELECT award_awards.id, award_awards.name, award_awards.order AS awards_order, award_awards.per_fair, award_awards.external_additional_materials, award_awards.award_source_fairs_id, award_types.type, sponsors.organization FROM award_awards ?, award_types, sponsors WHERE award_awards.year=? AND\taward_awards.award_types_id=award_types.id AND\taward_types.year=? AND\taward_awards.sponsors_id=sponsors.id ? ORDER BY awards_order"); $q->execute([$fair_join,$config['FAIRYEAR'],$config['FAIRYEAR'],$fair_where]); show_pdo_errors_if_any($pdo); if ($q->rowCount() == 0) { echo i18n('No awards to display.'); send_footer(); exit; } echo '
'; echo i18n('Choose an award to assign winners'); echo '
'; echo '
'; $fairs_id = ($auth_type == 'fair') ? $_SESSION['fairs_id'] : 0; while ($r = $q->fetch(PDO::FETCH_ASSOC)) { if ($r['per_fair'] == 'yes' && $auth_type != 'fair') { ?> - ()
$f) { ?>
'; } } else { ?> - ()
'; } echo '
'; } function print_award(&$r, $fairs_id, $editor = false, $editor_data = array()) { global $config, $auth_type; global $pdo; // echo "fair=$fairs_id"; /* * Setup the winner filter, we don't want to restrict this * to a specific fair for the 'fair' user */ $fairs_where = ''; if ($r['per_fair'] == 'yes') { if ($fairs_id == 0) { echo "blank fairs_id for per-fair award. bug.\n"; exit; } /* For per-fair awards, filter the results */ $fairs_where = "AND projects.fairs_id='$fairs_id'"; } /* Force the 'fair' user to only edit their own fair */ if ($auth_type == 'fair') $fairs_id = $_SESSION['fairs_id']; /* Load prizes for this award */ $q = $pdo->prepare("SELECT award_prizes.prize, award_prizes.number, award_prizes.id, award_prizes.cash, award_prizes.scholarship FROM award_prizes WHERE award_awards_id=? AND award_prizes.year=? ORDER BY `order`"); $q->execute([$r['id'],$config['FAIRYEAR']]); show_pdo_errors_if_any($pdo); echo '
'; $has_winners = false; while ($pr = $q->fetch(PDO::FETCH_OBJ)) { if ($editor == true) { echo '

'; } echo "  {$pr->prize}"; if ($pr->cash || $pr->scholarship) { echo ' ('; if ($pr->cash && $pr->scholarship) echo "\${$pr->cash} cash / \${$pr->scholarship} scholarship"; else if ($pr->cash) echo "\${$pr->cash} cash"; else if ($pr->scholarship) echo "\${$pr->scholarship} scholarship"; echo ')'; } /* Load winners for this prize */ $cq = $pdo->prepare("SELECT winners.projects_id, projects.projectnumber, projects.title, projects.fairs_id FROM winners LEFT JOIN projects ON projects.id=winners.projects_id WHERE winners.awards_prizes_id=? ? "); $cq->execute([$pr->id,$fairs_where]); show_pdo_errors_if_any($pdo); $count = $cq->rowCount(); // echo "winners=$count"; /* Print count */ $colour = ($count < $pr->number) ? 'red' : 'green'; echo " [$count/{$pr->number}]"; echo ''; echo '
'; /* List current winners for this prize */ $winners = array(); while ($w = $cq->fetch(PDO::FETCH_ASSOC)) { if ($w['projectnumber']) { echo '    '; if ($editor == true) { /* Print the delete X before the project */ if ($auth_type == 'fair' && $w['fairs_id'] != $fairs_id) { /* show a blank so everything lines up */ echo '    '; } else { echo "id},{$w['projects_id']});return false;\" href=\"#\" >"; echo ""; echo ' '; } $winners[] = $w['projects_id']; } $has_winners = true; echo "({$w['projectnumber']}) {$w['title']}"; echo '
'; } else { /* echo "    "; echo "No winner(s) specified"; */ } } /* Unlist all the winners we just printed from ALL lists */ if ($editor == true) { echo ''; } /* Print the select box if we need it */ if ($editor == true && $count < $pr->number) { $n_nom = 0; $n_eli = 0; ?>
   
    : -
'; if ($r['external_additional_materials'] == 1 && $editor == false && $r['award_source_fairs_id'] == NULL) { $d = 'disabled="disabled"'; $a = ''; if ($has_winners == true) { echo ""; $d = ''; $a = ''; } echo "$a
"; } echo '
'; } send_footer(); ?>