diff --git a/common.inc.functions.php b/common.inc.functions.php index e59d2f0..b10c869 100644 --- a/common.inc.functions.php +++ b/common.inc.functions.php @@ -779,3 +779,54 @@ function projectcategories_load($conferences_id = false) { return $cats; } +// a convenience function for getting the available event timeslots in the given conference +function get_timeslots($conferenceId){ + $times = array(); + $q = mysql_query("SELECT id,date,starttime,endtime,name FROM judges_timeslots WHERE round_id='0' AND conferences_id='$conferenceId' ORDER BY starttime,type"); + $x = 0; + while($r = mysql_fetch_object($q)){ + $endtime = $r->endtime; + $starttime = $r->starttime; + $found = false; + foreach($times as $xx => $t){ + if($t['date'] == $r->date && $t['starttime'] == $starttime && $t['endtime'] == $endtime){ + $times[$xx]['name'] .= ", {$r->name}"; + $found = true; + break; + } + } + if(!$found) { + $times[$x] = array( 'date' => $r->date, + 'starttime' => $starttime, + 'endtime' => $endtime, + 'name' => $r->name, + 'id' => $r->id); + $x++; + } + } + return $times; +} + +// a convenience function for getting the special awards that are relevant to the specified conference. +// separated because it's used in a couple of spots +function get_special_awards($conferenceId){ + $returnval = array(); + $q = mysql_query("SELECT award_awards.id, + award_awards.name, + award_awards.criteria, + sponsors.organization + 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' + AND award_types.conferences_id = '$conferenceId' + ORDER BY name"); + + while($row = mysql_fetch_assoc($q)){ + $returnval[$row['id']] = $row['name']; + } + return $returnval; +} + diff --git a/judge_other.php b/judge_other.php index 2bcc624..dff7f1e 100644 --- a/judge_other.php +++ b/judge_other.php @@ -39,27 +39,8 @@ else $u = user_load($edit_id); -/* Load the judging rounds */ -$times = array(); -$q = mysql_query("SELECT date,starttime,endtime,name FROM judges_timeslots WHERE round_id='0' AND conferences_id='{$conference['id']}' ORDER BY starttime,type"); -$x = 0; -while($r = mysql_fetch_object($q)) { - $found = false; - foreach($times as $xx => $t) { - if($t['date'] == $r->date && $t['starttime'] == $r->starttime && $t['endtime'] == $r->endtime) { - $times[$xx]['name'] .= ", {$r->name}"; - $found = true; - break; - } - } - if(!$found) { - $times[$x] = array( 'date' => $r->date, - 'starttime' => $r->starttime, - 'endtime' => $r->endtime, - 'name' => $r->name); - $x++; - } -} +// Load the judging rounds +$times = get_timeslots($conference['id']); switch($_GET['action']) { case 'save': @@ -75,26 +56,21 @@ 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'; + } + } + } user_save($u); if(is_array($_POST['questions'])){ questions_save_answers("judgereg",$u['id'],$_POST['questions']); } - - mysql_query("DELETE FROM judges_availability WHERE users_id='{$u['id']}'"); - - if(is_array($_POST['time']) ) { - foreach($_POST['time'] as $x => $blah) { - if(trim($times[$x]['starttime']) == '') continue; - - mysql_query("INSERT INTO judges_availability (users_id, `date`,`start`,`end`) - VALUES ('{$u['id']}', - '{$times[$x]['date']}', - '{$times[$x]['starttime']}','{$times[$x]['endtime']}')"); - } - } - - happy_("Preferences successfully saved"); $u = user_load($u['id']); @@ -135,24 +111,14 @@ if(count($times) > 1) $required[] = 'time[]'; $t) { - if($r->start == $t['starttime'] && $r->end == $t['endtime'] && $r->date == $t['date']) - $sel[] = $x; - } + foreach($times as $slot){ + $options[$slot['id']] = trim($slot['name'] . ' (' . $slot['date'] . ' ' . $slot['starttime'] . ' - ' . $slot['endtime'] . ')'); } - $items = array(); - foreach($times as $x=>$t) { - $st = substr($t['starttime'], 0, 5); - $end = substr($t['endtime'], 0, 5); - $items[$x] = "{$t['name']} ({$times[$x]['date']} $st - $end)"; + foreach($u['available_times'] as $idx => $t){ + if($t == 'yes') $sel[] = $idx; } - echo ''; - user_edit_item($u, 'Time Availability', 'time[]', 'checklist', $items, $sel); + user_edit_item($u, 'Time Availability', 'time[]', 'checklist', $options, $sel); echo ''; } ?> diff --git a/user.inc.php b/user.inc.php index 7bf26bc..0f53254 100644 --- a/user.inc.php +++ b/user.inc.php @@ -202,12 +202,42 @@ function user_load($users_id, $accounts_id = false) } break; + case 'available_times': + // a rather complicated match-up, as they're linked by time values, not by record id's + $times = get_timeslots($u['conferences_id']); + $q = mysql_query("SELECT * FROM judges_availability WHERE users_id=\"{$u['id']}\""); + + $sel = array(); + while($r=mysql_fetch_object($q)) { + foreach($times as $t) { + if($r->start == $t['starttime'] && $r->end == $t['endtime'] && $r->date == $t['date']) + $sel[] = $t['id']; + } + } + $items = array(); + foreach($times as $t) { + $st = substr($t['starttime'], 0, 5); + $end = substr($t['endtime'], 0, 5); + $items[$t['id']] = trim("{$t['name']} ({$t['date']} $st - $end)"); + if(in_array($t['id'], $sel)){ + $items[$t['id']] = 'yes'; + }else{ + $items[$t['id']] = 'no'; + } + } + $u['available_times'] = $items; + break; } } /* Do this assignment without recursion :) */ unset($u['orig']); +/* +echo "
";
+print_r($u);
+echo "
"; +*/ $orig = $u; $u['orig'] = $orig; $u['required_fields']=user_all_fields_required(array_keys($u['roles'])); @@ -300,7 +330,8 @@ function user_get_field_labels(){ 'position' => 'Position', 'notes' => 'Notes', 'grade' => 'Grade', - 'special_awards' => 'Special Awards' + 'special_awards' => 'Special Awards', + 'available_times' => 'Times Available' ); } @@ -478,12 +509,12 @@ function user_get_fields($userRoles = null){ /******* Now we add fields that are not stored directly in the users table ********/ $specialFieldRoles = array( - 'special_awards' => array('judge', 'student') + 'special_awards' => array('judge', 'student'), + 'available_times' => array('judge', 'volunteer') ); + // get the special_awards info if necessary if(count(array_intersect($specialFieldRoles['special_awards'], $userRoles)) > 0){ - //if(in_array('judge', $userRoles)){ - // find out if they have any special awards flagged $fields['special_awards'] = array(); $fields['special_awards']['field'] = 'special_awards'; $fields['special_awards']['display'] = $fieldLabels['special_awards']; @@ -491,30 +522,25 @@ function user_get_fields($userRoles = null){ $fields['special_awards']['options'] = array('yes' => 'Yes', 'no' => 'No'); $fields['special_awards']['entries'] = get_special_awards($conference['id']); } - return $fields; -} -// a convenience function for getting the special awards that are relevant to the specified conference. -// separated because it's used in a couple of spots -function get_special_awards($conferenceId){ - $returnval = array(); - $q=mysql_query("SELECT award_awards.id, - award_awards.name, - award_awards.criteria, - sponsors.organization - 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' - AND award_types.conferences_id='$conferenceId' - ORDER BY name"); - - while($row = mysql_fetch_assoc($q)){ - $returnval[$row['id']] = $row['name']; + // get the available_times info if available + if(count(array_intersect($specialFieldRoles['available_times'], $userRoles)) > 0){ + $fields['available_times'] = array(); + $fields['available_times']['field'] = 'available_times'; + $fields['available_times']['display'] = $fieldLabels['available_times']; + $fields['available_times']['type'] = 'multiselectlist'; + $fields['available_times']['options'] = array('yes' => 'Yes', 'no' => 'No'); + $fields['available_times']['entries'] = array(); + $timeslots = get_timeslots($conference['id']); + foreach($timeslots as $slot){ + $fields['available_times']['entries'][$slot['id']] = trim($slot['name'] . ' (' . $slot['date'] . ' ' . $slot['starttime'] . ' - ' . $slot['endtime'] . ')'); + } } - return $returnval; +// echo "
";
+//	print_r($fields);
+//	echo "
"; + + return $fields; } /* FIXME: these are going to need conference IDs too */ @@ -607,11 +633,11 @@ function user_save(&$u) } // Save the other user data that is not stored in the users table - if( + + if( // if this user has an altered special awards selection, it needs to be saved array_key_exists('special_awards', $u) && count(array_diff_assoc($u['special_awards'], $u['orig']['special_awards'])) > 0 ){ - // this user has an altered special awards selection that needs to be saved $aaids = array(); foreach($u['special_awards'] as $id => $yesno){ if(strtolower(trim($yesno)) == 'yes'){ @@ -627,6 +653,34 @@ function user_save(&$u) } } + if( // if this user has an altered available judging times selection, we need to save it + array_key_exists('available_times', $u) && + count(array_diff_assoc($u['available_times'], $u['orig']['available_times'])) > 0 + ){ + mysql_query("DELETE FROM judges_availability WHERE users_id='{$u['id']}'"); + + $query = 'SELECT date, starttime, endtime FROM judges_timeslots WHERE id IN ('; + $ids = array(); + foreach($u['available_times'] as $id => $yesno){ + if(strtolower(trim($yesno)) == 'yes'){ + $ids[] = $id; + } + } + $query .= implode(',', $ids) . ')'; + if(count($ids) > 0){ + $insertVals = array(); + $results = mysql_query($query); + while($row = mysql_fetch_assoc($results)){ + $insertVals[] = "({$u['id']},'{$row['date']}','{$row['starttime']}','{$row['endtime']}')"; + } + if(count($insertVals) > 0){ + $query = "INSERT INTO judges_availability (users_id, `date`,`start`,`end`) VALUES "; + $query .= implode(',', $insertVals); + } + 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 */