Updates on the data that gets returned when describing the user structure

Modified user code to properly save the volunteer availability data
Updated the UI to properly use the user_save function to update judge and volunteer info
This commit is contained in:
jacob 2010-11-16 22:51:42 +00:00
parent 61fba8a93c
commit 0ff766175b
4 changed files with 41 additions and 44 deletions

View File

@ -810,13 +810,9 @@ function get_judging_timeslots($conferenceId){
// a convenience function for getting the special awards that are relevant to the specified conference.
function get_special_awards($conferenceId){
$returnval = array();
$q = mysql_query("SELECT award_awards.id,
award_awards.name,
award_awards.criteria,
sponsors.organization
$q = mysql_query("SELECT award_awards.*
FROM award_awards
JOIN award_types ON award_types.id = award_awards.award_types_id
JOIN sponsors ON sponsors.id = award_awards.sponsors_id
WHERE
(award_types.type='Special' OR award_types.type='Other')
AND award_awards.conferences_id = '$conferenceId'
@ -824,7 +820,7 @@ function get_special_awards($conferenceId){
ORDER BY name");
while($row = mysql_fetch_assoc($q)){
$returnval[$row['id']] = $row['name'];
$returnval[$row['id']] = $row;
}
return $returnval;
}

View File

@ -56,15 +56,10 @@ case 'save':
$u['years_regional'] = intval($_POST['years_regional']);
$u['years_national'] = intval($_POST['years_national']);
$u['highest_psd'] = stripslashes($_POST['highest_psd']);
if(is_array($_POST['time']) && array_key_exists('available_times', $u)){
foreach($u['available_times'] as $idx => $val){
if(in_array($idx, $_POST['time'])){
$u['available_times'][$idx] = 'yes';
}else{
$u['available_times'][$idx] = 'no';
}
}
if(is_array($_POST['time'])){
$u['available_times'] = $_POST['time'];
}else if(array_key_exists('available_times', $u)){
$u['available_times'] = array();
}
user_save($u);
@ -114,11 +109,8 @@ if(count($times) > 1) $required[] = 'time[]';
foreach($times as $slot){
$options[$slot['id']] = trim($slot['name'] . ' (' . $slot['date'] . ' ' . $slot['starttime'] . ' - ' . $slot['endtime'] . ')');
}
foreach($u['available_times'] as $idx => $t){
if($t == 'yes') $sel[] = $idx;
}
echo '<tr>';
user_edit_item($u, 'Time Availability', 'time[]', 'checklist', $options, $sel);
user_edit_item($u, 'Time Availability', 'time[]', 'checklist', $options, $u['available_times']);
echo '</tr>';
}
?>

View File

@ -76,7 +76,6 @@ function user_load($users_id, $accounts_id = false)
// get a list of all fields relevant to this user
$fieldDat = user_get_fields(array_keys($u['roles']));
// we need to separate the fields that are in the users table from those in separate tables
$fields = array_unique(array_merge(array_keys($fieldDat), array('id', 'accounts_id', 'conferences_id')));
$userFields = array();
@ -552,7 +551,7 @@ function user_get_fields($userRoles = null){
$fields['special_awards']['field'] = 'special_awards';
$fields['special_awards']['display'] = i18n($fieldInfo['special_awards']['label']);
$fields['special_awards']['group'] = i18n($fieldInfo['special_awards']['group']);
$fields['special_awards']['type'] = 'multiselectlist';
$fields['special_awards']['type'] = 'multiselect';
$fields['special_awards']['options'] = array('yes' => 'Yes', 'no' => 'No');
$fields['special_awards']['entries'] = get_special_awards($conference['id']);
}
@ -563,12 +562,12 @@ function user_get_fields($userRoles = null){
$fields['available_times']['field'] = 'available_times';
$fields['available_times']['display'] = i18n($fieldInfo['available_times']['label']);
$fields['available_times']['group'] = i18n($fieldInfo['available_times']['group']);
$fields['available_times']['type'] = 'multiselectlist';
$fields['available_times']['type'] = 'multiselect';
$fields['available_times']['options'] = array('yes' => 'Yes', 'no' => 'No');
$fields['available_times']['entries'] = array();
$timeslots = get_judging_timeslots($conference['id']);
foreach($timeslots as $slot){
$fields['available_times']['entries'][$slot['id']] = trim($slot['name'] . ' (' . $slot['date'] . ' ' . $slot['starttime'] . ' - ' . $slot['endtime'] . ')');
$fields['available_times']['entries'][$slot['id']] = $slot;
}
}
@ -578,7 +577,7 @@ function user_get_fields($userRoles = null){
$fields['available_events']['field'] = 'available_events';
$fields['available_events']['display'] = i18n($fieldInfo['available_events']['label']);
$fields['available_events']['group'] = i18n($fieldInfo['available_events']['group']);
$fields['available_events']['type'] = 'multiselectlist';
$fields['available_events']['type'] = 'multiselect';
$fields['available_events']['options'] = array('yes' => 'Yes', 'no' => 'No');
$fields['available_events']['entries'] = array();
$q=mysql_query("SELECT schedule.id, schedule.date, schedule.hour, schedule.minute, schedule.duration, events.name FROM schedule JOIN events ON schedule.events_id=events.id WHERE schedule.conferences_id='{$conference['id']}'");
@ -593,7 +592,7 @@ function user_get_fields($userRoles = null){
$fields['volunteer_positions']['field'] = 'volunteer_positions';
$fields['volunteer_positions']['display'] = i18n($fieldInfo['volunteer_positions']['label']);
$fields['volunteer_positions']['group'] = i18n($fieldInfo['volunteer_positions']['group']);
$fields['volunteer_positions']['type'] = 'multiselectlist';
$fields['volunteer_positions']['type'] = 'multiselect';
$fields['volunteer_positions']['options'] = array('yes' => 'Yes', 'no' => 'No');
$fields['volunteer_positions']['entries'] = array();
$q = mysql_query("SELECT * FROM volunteer_positions WHERE conferences_id = {$conference['id']}");
@ -721,6 +720,32 @@ function user_save(&$u)
}
}
if( // if this user has an altered event availability selection, we need to save it
array_key_exists('available_events', $u) &&
count(array_diff_assoc($u['available_events'], $u['orig']['available_events'])) > 0
){
mysql_query("DELETE FROM schedule_users_availability_link WHERE users_id = {$u['id']}");
if(count($u['available_events']) > 0){
$query = "INSERT INTO schedule_users_availability_link (users_id, schedule_id), VALUES (" . $u['id'] . ", ";
$query .= implode('), (' . $u['id'] . ', ', $u['available_events']);
$query .= ")";
mysql_query($query);
}
}
if( // if this user has an altered selection of volunteer positions, we'll need to change that too
array_key_exists('volunteer_positions', $u) &&
count(array_diff_assoc($u['volunteer_positions'], $u['orig']['volunteer_positions'])) > 0
){
mysql_query("DELETE FROM volunteer_positions_signup WHERE users_id = {$u['id']}");
if(count($u['volunteer_positions']) > 0){
$query = "INSERT INTO volunteer_positions_signup (users_id, conferences_id, volunteer_positions_id) VALUES({$u['id']},{$conference['id']},";
$query .= implode('), (' . $u['id'] . ', ' . $conference['id'] . ', ', $u['volunteer_positions']);
$query .= ")";
mysql_query($query);
}
}
/* Record all the data in orig that we saved so subsequent
* calls to user_save don't try to overwrite data already
* saved to the database */

View File

@ -49,27 +49,11 @@ if($_GET['action']=="save"){
/* Match selections with available positions */
foreach($_POST['posn'] as $id=>$val) {
if(!in_array($id, $posns)) continue;
if($vals != '') $vals .=',';
$vals .= "('{$u['id']}','$id','{$conference['id']}')";
$vals[] = $id;
}
}
/* Delete existing selections */
mysql_query("DELETE FROM volunteer_positions_signup
WHERE
users_id='{$u['id']}'
AND conferences_id='{$conference['id']}' ");
echo mysql_error();
/* Add new selections if there are any */
if($vals != '') {
$q = "INSERT INTO volunteer_positions_signup (users_id, volunteer_positions_id,conferences_id)
VALUES $vals";
$r=mysql_query($q);
echo mysql_error();
}
$u['volunteer_positions'] = $vals;
user_save($u);
$newstatus = volunteer_status_position($u);
?>
<script type="text/javascript">