science-ation/activities.php
james a035a6f8e3 Add registration/fields API
Fix $roles array use colliding with global $roles array ($roles should never be used anywhere! its a master list of all of the roles set in the bootstrap!)
2010-10-22 15:06:49 +00:00

200 lines
5.6 KiB
PHP

<?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>
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.
*/
?>
<?php
require_once('common.inc.php');
require_once('user.inc.php');
require_once('activities.inc.php');
require_once("questions.inc.php");
require_once('user_edit.inc.php');
/* Ensure they're logged in as a judge, volunteer or admin */
user_auth_required(array(), array('judge', 'volunteer', 'admin'));
$edit_id = isset($_GET['users_id']) ? intval($_GET['users_id']) : $_SESSION['users_id'];
if($edit_id != $_SESSION['users_id'])
user_auth_required('admin');
else
user_auth_required();
$u = user_load($edit_id);
// load the times at which the various events are happening
$times = array();
$q = mysql_query("
SELECT schedule.id, date, hour, minute, duration, title
FROM schedule
JOIN events ON schedule.events_id = events.id
WHERE schedule.conferences_id = {$conference['id']}
ORDER BY date, hour, minute
");
$x = 0;
while($r = mysql_fetch_assoc($q)){
$dateParts = explode('-', $r['date']);
$startTime = mktime($r['hour'], $r['minute'], 0, $dateParts[1], $dateParts[2], $dateParts[0]);
$endTime = $startTime + $r['duration'] * 60;
$times[$r['id']] = array(
'date' => $r['date'],
'starttime' => date('g:ia', $startTime),
'endtime' => date('g:ia', $endTime),
'name' => $r['title'],
);
}
switch($_GET['action']) {
case 'save':
if(!is_array($_POST['languages'])) $_POST['languages']=array();
$u['languages'] = array();
foreach($_POST['languages'] AS $val)
$u['languages'][] = $val;
$u['willing_chair'] = ($_POST['willing_chair'] == 'yes') ? 'yes' : 'no';
$u['highest_psd'] = stripslashes($_POST['highest_psd']);
user_save($u);
/*
if(is_array($_POST['questions'])){
questions_save_answers("judgereg",$u['id'],$_POST['questions']);
}
*/
// save the availability selection
mysql_query("DELETE FROM schedule_users_availability_link WHERE users_id='{$u['id']}'");
if(is_array($_POST['time']) ) {
foreach($_POST['time'] as $idx) {
mysql_query("
INSERT INTO schedule_users_availability_link (schedule_id, users_id)
VALUES($idx, {$u['id']})
");
}
}
happy_("Preferences successfully saved");
$u = user_load($u['id']);
$newstatus=activities_status($u);
?>
<script type="text/javascript">
user_update_tab_status('activities','<?=$newstatus?>');
</script>
<?
exit;
}
$fields = array('languages[]', 'willing_chair','highest_psd','time[]');
$required = array('languages[]');
if(count($times) > 1) $required[] = 'time[]';
?>
<h4><?=i18n("Activity Information")?> - <span class="status_activities"></span></h4>
<br/>
<form class="editor" id="activities_form">
<table width="90%">
<tr><td style="text-align: left" colspan="2"><b><?=i18n('Language(s)')?></b><hr /></td></tr>
<tr><?=user_edit_item($u, 'Languages', 'languages[]', 'languages')?></tr>
<?php if(count($times) > 1) { ?>
<tr><td style="text-align: left" colspan="2"><br /><b><?=i18n('Time Availability')?></b><hr />
<i><?=i18n('Please specify the events you are available for')?></i>
</td></tr>
<?php
// get a list of the times they already have selected
$sel = array();
$q = mysql_query("
SELECT eual.* FROM schedule_users_availability_link eual
JOIN schedule ON schedule.id = eual.schedule_id
WHERE eual.users_id=\"{$u['id']}\"
AND schedule.conferences_id = {$conference['id']}
ORDER BY `schedule`.`date`, `schedule`.`hour`, `schedule`.`minute`
");
while($r = mysql_fetch_assoc($q)) {
foreach($times as $x => $t) {
if($x == $r['schedule_id']){
$sel[] = $x;
}
}
}
$items = array();
foreach($times as $x => $t) {
$items[$x] = "{$t['name']} ({$t['date']} {$t['starttime']} - {$t['endtime']})";
}
echo '<tr>';
user_edit_item($u, 'Time Availability', 'time[]', 'checklist', $items, $sel);
echo '</tr>';
}
//questions_print_answer_editor('judgereg', $u, 'questions');
?>
</table>
<br />
<button><?=i18n("Save Information")?></button>
</form>
<script type="text/javascript">
function activities_save()
{
$("#debug").load("<?=$config['SFIABDIRECTORY']?>/activities.php?action=save&users_id=<?=$u['id']?>", $("#activities_form").serializeArray());
return false;
}
$(document).ready(function() {
$("#activities_form").validate({
errorPlacement: function(error, element) {
if( element.attr('type') == 'checkbox' ) {
error.insertAfter( element.parent("span") );
} else {
error.insertAfter(element);
}
},
rules: {
"languages[]": { required: true },
"time[]": { required: <?=in_array('time[]', $required)?'true':'false'?> },
},
messages: {
"languages[]": { required: "<?=i18n('Please select the language(s) you can work in')?>" },
"time[]": { required: "<?=i18n('Please select the time(s) you are available')?>" }
},
submitHandler: function() {
activities_save();
return false;
},
cancelHandler: function() {
activities_save();
return false;
}
});
user_update_tab_status('activities');
});
</script>