-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathjudge_availability.php
163 lines (140 loc) · 4.58 KB
/
judge_availability.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
<?
/*
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>
Copyright (C) 2009 David Grant <dave@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.
*/
?>
<?
require_once('common.inc.php');
require_once('user.inc.php');
require_once('judge.inc.php');
/* Sort out who we're editting */
if($_POST['users_id'])
$eid = intval($_POST['users_id']); /* From a save form */
else if(array_key_exists('embed_edit_id', $_SESSION))
$eid = $_SESSION['embed_edit_id']; /* From the embedded editor */
else
$eid = $_SESSION['users_id']; /* Regular entry */
if($eid != $_SESSION['users_id']) {
/* Not editing ourself, we had better be
* a committee member */
user_auth_required('committee','admin');
}
$u = user_load($eid);
$times = array();
/* Load the judging rounds */
$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':
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 "<h4>".i18n('Time Availability')."</h4>";
echo "<br />";
} else {
//send the header
send_header('Time Availability',
array('Judge Registration' => 'judge_main.php')
);
}
?>
<script type="text/javascript">
function judgeavailability_save()
{
$("#debug").load("<?=$config['SFIABDIRECTORY']?>/judge_availability.php?action=save", $("#judgeavailability_form").serializeArray());
return false;
}
</script>
<?
judge_status_update($u);
if($_SESSION['embed'] != true) {
//output the current status
$newstatus=judge_status_availability($u);
if($newstatus!='complete')
echo error(i18n("Time Availability Preferences Incomplete"));
else
echo happy(i18n("Time Availability Preferences Complete"));
}
?>
<form id="judgeavailability_form" >
<input type="hidden" name="users_id" value="<?=$u['id']?>" />
<br />
<table>
<?
/* Get all their available times */
$q = mysql_query("SELECT * FROM judges_availability WHERE users_id=\"{$u['id']}\" ORDER BY `start`");
$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] = 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 '<br /><br />';
}
foreach($times as $x=>$t) {
$ch = $sel[$x] == true ? 'checked="checked"' : '';
echo "<tr><td>";
echo "<input onclick=\"checkboxclicked(this)\" $ch type=\"checkbox\" name=\"time[]\" value=\"$x\" />";
$st = substr($t['starttime'], 0, 5);
$end = substr($t['endtime'], 0, 5);
echo "</td><td><b>{$times[$x]['date']} $st - $end</b></td></tr>";
echo "<tr><td></td><td><p>{$t['name']}</td>";
echo "</tr>";
}
?>
</table>
<br />
<br />
<input type="submit" onclick="judgeavailability_save();return false;" value="<?=i18n("Save Time Availability Preferences")?>" />
</form>
<?
if($_SESSION['embed'] != true) send_footer();
?>