From e03902bbec0499ac65e844d128d238ee3c0ca20b Mon Sep 17 00:00:00 2001 From: dave Date: Tue, 31 Aug 2010 07:23:49 +0000 Subject: [PATCH] Merge judge_availablilty into judge_other and delete judge_availability.php --- judge.inc.php | 18 ++--- judge_availability.php | 163 ----------------------------------------- judge_other.php | 75 ++++++++++++++++++- user_edit.inc.php | 15 +++- 4 files changed, 93 insertions(+), 178 deletions(-) delete mode 100644 judge_availability.php diff --git a/judge.inc.php b/judge.inc.php index 6809b6b8..cd36e182 100644 --- a/judge.inc.php +++ b/judge.inc.php @@ -65,6 +65,12 @@ function judge_status_other(&$u) /* They must select a language to judge in */ if(count($u['languages']) < 1) return 'incomplete'; + if($config['judges_availability_enable'] != 'no') { + $q = mysql_query("SELECT id FROM judges_availability + WHERE users_id=\"{$u['id']}\""); + if(mysql_num_rows($q) == 0) return 'incomplete'; + } + return 'complete'; } @@ -104,18 +110,6 @@ function judge_status_special_awards(&$u) return 'incomplete'; } -function judge_status_availability(&$u) -{ - global $config; - if($config['judges_availability_enable'] == 'no') return 'complete'; - - $q = mysql_query("SELECT id FROM judges_availability - WHERE users_id=\"{$u['id']}\""); - if(mysql_num_rows($q) > 0) return 'complete'; - - return 'incomplete'; -} - function judge_status_update(&$u) { global $config; diff --git a/judge_availability.php b/judge_availability.php deleted file mode 100644 index c21876c4..00000000 --- a/judge_availability.php +++ /dev/null @@ -1,163 +0,0 @@ - - Copyright (C) 2005 James Grant - Copyright (C) 2009 David Grant - - 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. -*/ -?> - $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']) { -case 'save': - mysql_query("DELETE FROM judges_availability WHERE users_id='{$u['id']}'"); - - if(is_array($_POST['time']) ) { - foreach($_POST['time'] as $x) { - 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_("Time Availability preferences successfully saved"); - exit; -} - -if($_SESSION['embed'] == true) { - display_messages(); - echo "

".i18n('Time Availability')."

"; - echo "
"; -} else { - //send the header - send_header('Time Availability', - array('Judge Registration' => 'judge_main.php') - ); -} - -?> - - -
- -
- -$t) { - if($r->start == $t['starttime'] && $r->end == $t['endtime'] && $r->date == $t['date']) { - $sel[$x] = true; - } - } -} - -if(count($times) > 1) { - echo i18n("Please Note, you will be scheduled to judge in ALL (not just one) judging timeslots you select."); - echo '

'; -} - -foreach($times as $x=>$t) { - $ch = $sel[$x] == true ? 'checked="checked"' : ''; - echo ""; - echo ""; - echo ""; -} -?> -
"; - echo ""; - $st = substr($t['starttime'], 0, 5); - $end = substr($t['endtime'], 0, 5); - echo "{$times[$x]['date']} $st - $end

{$t['name']}

-
-
- -" /> -
- - diff --git a/judge_other.php b/judge_other.php index d61080f4..896e7785 100644 --- a/judge_other.php +++ b/judge_other.php @@ -39,6 +39,30 @@ 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 year='{$config['FAIRYEAR']}' 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']) { case 'save': if(!is_array($_POST['languages'])) $_POST['languages']=array(); @@ -53,10 +77,24 @@ case 'save': $u['years_regional'] = intval($_POST['years_regional']); $u['years_national'] = intval($_POST['years_national']); $u['highest_psd'] = stripslashes($_POST['highest_psd']); - user_save($u); 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) { + 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']); @@ -69,9 +107,11 @@ case 'save': exit; } -$fields = array('languages[]', 'years_school','years_regional','years_national','willing_chair','highest_psd'); +$fields = array('languages[]', 'years_school','years_regional','years_national','willing_chair','highest_psd','time[]'); $required = array('languages[]'); +if(count($times) > 1) $required[] = 'time[]'; + ?>

-


@@ -88,6 +128,35 @@ $required = array('languages[]'); + 1) { ?> +

+ + + +$t) { + if($r->start == $t['starttime'] && $r->end == $t['endtime'] && $r->date == $t['date']) + $sel[] = $x; + } + } + $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)"; + } + + echo ''; + user_edit_item($u, 'Time Availability', 'time[]', 'checklist', $items, $sel); + echo ''; +} +?> +

@@ -121,6 +190,7 @@ $(document).ready(function() { rules: { "languages[]": { required: true }, + "time[]": { required: }, years_school: { min: 0, max:100 }, years_regional: { min: 0, max:100 }, years_national: { min: 0, max:100 } @@ -128,6 +198,7 @@ $(document).ready(function() { messages: { "languages[]": { required: "" }, + "time[]": { required: "" }, years_school: { min: "", max: "", diff --git a/user_edit.inc.php b/user_edit.inc.php index 2c1c577c..216fe432 100644 --- a/user_edit.inc.php +++ b/user_edit.inc.php @@ -24,7 +24,7 @@ require_once('account.inc.php'); -function user_edit_item(&$u, $label, $fname, $type='textbox', $data1=NULL) +function user_edit_item(&$u, $label, $fname, $type='textbox', $data1=NULL, $data2=NULL) { global $required, $fields, $config; @@ -87,6 +87,19 @@ function user_edit_item(&$u, $label, $fname, $type='textbox', $data1=NULL) } echo ""; break; + + case 'checklist': + /* data1 = items, data2 = checked items */ + echo ""; + $x = 0; + foreach($data1 AS $key=>$txt) { + $ch = (in_array($key,$data2)) ? 'checked="checked"' : ''; + if($x) echo '
'; + echo "$txt"; + $x=1; + } + echo "
"; + break; } echo ''; }