science-ation/volunteer_position.php

159 lines
4.3 KiB
PHP

<?
/*
This file is part of the 'Science Fair In A Box' project
SFIAB Website: http://www.sfiab.ca
Copyright (C) 2005 Sci-Tech Ontario Inc <info@scitechontario.org>
Copyright (C) 2005 James Grant <james@lightbox.org>
Copyright (C) 2007 David Grant <dave@lightbox.org>
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.
*/
?>
<?
require_once("common.inc.php");
require_once("user.inc.php");
require_once("volunteer.inc.php");
user_auth_required('volunteer');
$u = user_load($_SESSION['users_id']);
/* Load the user's volunteer position selections */
//send the header
$type = $_SESSION['users_type'];
send_header("{$user_what[$type]} - Volunteer Positions",
array("{$user_what[$type]} Registration" => "{$type}_main.php")
);
if($_POST['action']=="save")
{
$vals = '';
if(is_array($_POST['posn'])) {
/* Load available IDs */
$posns = array();
$q = "SELECT * FROM volunteer_positions WHERE year='{$config['FAIRYEAR']}'";
$r = mysql_query($q);
while($p = mysql_fetch_object($r)) {
$posns[] = $p->id;
}
/* Match selections with avaiulable positions */
foreach($_POST['posn'] as $id=>$val) {
if(!in_array($id, $posns)) continue;
if($vals != '') $vals .=',';
$vals .= "('{$_SESSION['users_id']}','$id','{$config['FAIRYEAR']}')";
}
}
/* Delete existing selections */
mysql_query("DELETE FROM volunteer_positions_signup
WHERE
users_id='{$_SESSION['users_id']}'
AND year='{$config['FAIRYEAR']}' ");
echo mysql_error();
/* Add new selections if there are any */
if($vals != '') {
$q = "INSERT INTO volunteer_positions_signup (users_id, volunteer_positions_id,year)
VALUES $vals";
$r=mysql_query($q);
echo mysql_error();
}
echo notice(i18n("Volunteer Positions successfully updated"));
}
//output the current status
$newstatus=volunteer_status_position($u);
if($newstatus!='complete')
{
echo error(i18n("Volunteer Position Selection Incomplete"));
}
else
{
echo happy(i18n("Volunteer Position Selection Complete"));
}
echo "<form name=\"personalform\" method=\"post\" action=\"volunteer_position.php\">\n";
echo "<input type=\"hidden\" name=\"action\" value=\"save\" />\n";
echo "<table>\n";
/* Read current selections */
$q = "SELECT * FROM volunteer_positions_signup WHERE
users_id = '{$_SESSION['users_id']}'
AND year='{$config['FAIRYEAR']}'";
$r = mysql_query($q);
$checked_positions = array();
while($p = mysql_fetch_object($r)) {
$checked_positions[] = $p->volunteer_positions_id;
}
/* Load available volunteer positions */
$q = "SELECT *,UNIX_TIMESTAMP(start) as ustart, UNIX_TIMESTAMP(end) as uend
FROM volunteer_positions WHERE year='{$config['FAIRYEAR']}'";
$r = mysql_query($q);
while($p = mysql_fetch_object($r)) {
echo '<tr><td>';
$checked = false;
if($_SESSION['lang'] == 'en') {
$sday = strftime("%a. %B %e, %Y", $p->ustart);
$stime = strftime("%H:%M", $p->ustart);
$eday = strftime("%a. %B %e, %Y", $p->uend);
$etime = strftime("%H:%M", $p->uend);
if($sday == $eday) {
$start = $stime;
$end = "$etime, $sday";
} else {
$start = "$sday, $stime";
$end = "$eday, $etime";
}
} else {
$start = $p->start;
$end = $p->end;
}
$ch = in_array($p->id, $checked_positions) ? 'checked="checked"' : '';
echo "<input $ch type=\"checkbox\" name=\"posn[$p->id]\" value=\"checked\" />";
echo '</td><td>';
echo '<b>'.i18n($p->name).'</b></td>' ;
echo "<td align=\"right\">($start - $end)</td></tr>";
echo '<tr><td></td><td colspan="2"><div style="font-size: 0.75em;">';
echo i18n($p->desc);
echo '<br /><br /></div></td></tr>';
}
echo "</table>";
echo "<input type=\"submit\" value=\"".i18n("Save Position Selection")."\" />\n";
echo "</form>";
echo "<br />";
send_footer();
?>