forked from science-ation/science-ation
Separating judging timeslot selection into the user object
This commit is contained in:
parent
0bcd811101
commit
92d46976f7
@ -779,3 +779,54 @@ function projectcategories_load($conferences_id = false) {
|
|||||||
return $cats;
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
@ -39,27 +39,8 @@ else
|
|||||||
|
|
||||||
$u = user_load($edit_id);
|
$u = user_load($edit_id);
|
||||||
|
|
||||||
/* Load the judging rounds */
|
// Load the judging rounds
|
||||||
$times = array();
|
$times = get_timeslots($conference['id']);
|
||||||
$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++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
switch($_GET['action']) {
|
switch($_GET['action']) {
|
||||||
case 'save':
|
case 'save':
|
||||||
@ -75,26 +56,21 @@ case 'save':
|
|||||||
$u['years_regional'] = intval($_POST['years_regional']);
|
$u['years_regional'] = intval($_POST['years_regional']);
|
||||||
$u['years_national'] = intval($_POST['years_national']);
|
$u['years_national'] = intval($_POST['years_national']);
|
||||||
$u['highest_psd'] = stripslashes($_POST['highest_psd']);
|
$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);
|
user_save($u);
|
||||||
|
|
||||||
if(is_array($_POST['questions'])){
|
if(is_array($_POST['questions'])){
|
||||||
questions_save_answers("judgereg",$u['id'],$_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");
|
happy_("Preferences successfully saved");
|
||||||
|
|
||||||
$u = user_load($u['id']);
|
$u = user_load($u['id']);
|
||||||
@ -135,24 +111,14 @@ if(count($times) > 1) $required[] = 'time[]';
|
|||||||
|
|
||||||
<?
|
<?
|
||||||
/* Get all their available times */
|
/* Get all their available times */
|
||||||
$q = mysql_query("SELECT * FROM judges_availability WHERE users_id=\"{$u['id']}\" ORDER BY `start`");
|
foreach($times as $slot){
|
||||||
|
$options[$slot['id']] = trim($slot['name'] . ' (' . $slot['date'] . ' ' . $slot['starttime'] . ' - ' . $slot['endtime'] . ')');
|
||||||
$sel = array();
|
|
||||||
while($r=mysql_fetch_object($q)) {
|
|
||||||
foreach($times as $x=>$t) {
|
|
||||||
if($r->start == $t['starttime'] && $r->end == $t['endtime'] && $r->date == $t['date'])
|
|
||||||
$sel[] = $x;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
$items = array();
|
foreach($u['available_times'] as $idx => $t){
|
||||||
foreach($times as $x=>$t) {
|
if($t == 'yes') $sel[] = $idx;
|
||||||
$st = substr($t['starttime'], 0, 5);
|
|
||||||
$end = substr($t['endtime'], 0, 5);
|
|
||||||
$items[$x] = "{$t['name']} ({$times[$x]['date']} $st - $end)";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
echo '<tr>';
|
echo '<tr>';
|
||||||
user_edit_item($u, 'Time Availability', 'time[]', 'checklist', $items, $sel);
|
user_edit_item($u, 'Time Availability', 'time[]', 'checklist', $options, $sel);
|
||||||
echo '</tr>';
|
echo '</tr>';
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
|
110
user.inc.php
110
user.inc.php
@ -202,12 +202,42 @@ function user_load($users_id, $accounts_id = false)
|
|||||||
}
|
}
|
||||||
break;
|
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 :) */
|
/* Do this assignment without recursion :) */
|
||||||
unset($u['orig']);
|
unset($u['orig']);
|
||||||
|
/*
|
||||||
|
echo "<pre>";
|
||||||
|
print_r($u);
|
||||||
|
echo "</pre>";
|
||||||
|
*/
|
||||||
$orig = $u;
|
$orig = $u;
|
||||||
$u['orig'] = $orig;
|
$u['orig'] = $orig;
|
||||||
$u['required_fields']=user_all_fields_required(array_keys($u['roles']));
|
$u['required_fields']=user_all_fields_required(array_keys($u['roles']));
|
||||||
@ -300,7 +330,8 @@ function user_get_field_labels(){
|
|||||||
'position' => 'Position',
|
'position' => 'Position',
|
||||||
'notes' => 'Notes',
|
'notes' => 'Notes',
|
||||||
'grade' => 'Grade',
|
'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 ********/
|
/******* Now we add fields that are not stored directly in the users table ********/
|
||||||
$specialFieldRoles = array(
|
$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(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'] = array();
|
||||||
$fields['special_awards']['field'] = 'special_awards';
|
$fields['special_awards']['field'] = 'special_awards';
|
||||||
$fields['special_awards']['display'] = $fieldLabels['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']['options'] = array('yes' => 'Yes', 'no' => 'No');
|
||||||
$fields['special_awards']['entries'] = get_special_awards($conference['id']);
|
$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.
|
// get the available_times info if available
|
||||||
// separated because it's used in a couple of spots
|
if(count(array_intersect($specialFieldRoles['available_times'], $userRoles)) > 0){
|
||||||
function get_special_awards($conferenceId){
|
$fields['available_times'] = array();
|
||||||
$returnval = array();
|
$fields['available_times']['field'] = 'available_times';
|
||||||
$q=mysql_query("SELECT award_awards.id,
|
$fields['available_times']['display'] = $fieldLabels['available_times'];
|
||||||
award_awards.name,
|
$fields['available_times']['type'] = 'multiselectlist';
|
||||||
award_awards.criteria,
|
$fields['available_times']['options'] = array('yes' => 'Yes', 'no' => 'No');
|
||||||
sponsors.organization
|
$fields['available_times']['entries'] = array();
|
||||||
FROM award_awards
|
$timeslots = get_timeslots($conference['id']);
|
||||||
JOIN award_types ON award_types.id = award_awards.award_types_id
|
foreach($timeslots as $slot){
|
||||||
JOIN sponsors ON sponsors.id = award_awards.sponsors_id
|
$fields['available_times']['entries'][$slot['id']] = trim($slot['name'] . ' (' . $slot['date'] . ' ' . $slot['starttime'] . ' - ' . $slot['endtime'] . ')');
|
||||||
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;
|
// echo "<pre>";
|
||||||
|
// print_r($fields);
|
||||||
|
// echo "</pre>";
|
||||||
|
|
||||||
|
return $fields;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* FIXME: these are going to need conference IDs too */
|
/* 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
|
// 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) &&
|
array_key_exists('special_awards', $u) &&
|
||||||
count(array_diff_assoc($u['special_awards'], $u['orig']['special_awards'])) > 0
|
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();
|
$aaids = array();
|
||||||
foreach($u['special_awards'] as $id => $yesno){
|
foreach($u['special_awards'] as $id => $yesno){
|
||||||
if(strtolower(trim($yesno)) == 'yes'){
|
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
|
/* Record all the data in orig that we saved so subsequent
|
||||||
* calls to user_save don't try to overwrite data already
|
* calls to user_save don't try to overwrite data already
|
||||||
* saved to the database */
|
* saved to the database */
|
||||||
|
Loading…
Reference in New Issue
Block a user