/
draft_options_set.php
299 lines (269 loc) · 11.9 KB
/
draft_options_set.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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
<?
/***************************************************************************
* options_set.php
* -------------------
* begin : Friday, Mar 28, 2008
* copyright : (C) 2008 J. David Baker
* email : me@jdavidbaker.com
*
***************************************************************************/
/***************************************************************************
*
* 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; either version 2 of the License, or
* (at your option) any later version.
*
***************************************************************************/
include "includes/classes.inc.php";
global $settings;
global $login;
if (preg_match("/[a-zA-Z0-9._%-]+@[a-zA-Z0-9._%-]+\.[a-zA-Z]{2,4}/", $_POST['team_email'])) {
$col[] = "team_email = '".$_POST['team_email']."'";
$has_email = true;
} else {
$col[] = "team_email = NULL";
$has_email = false;
}
if ($_POST['team_autopick']) {
$col[] = "team_autopick = '1'";
} else {
$col[] = "team_autopick = '0'";
}
$col[] = "team_email_prefs = '".$_POST['team_email_prefs']."'";
$col[] = "team_autopick_wait = '".$_POST['team_autopick_wait']."'";
if ($_POST['team_multipos']) {
// This is stored kind of backwards
$col[] = "team_multipos = '0'";
} else {
$col[] = "team_multipos = '1'";
}
if ($_POST['pick_method_id']) {
if ( $settings->get_value(kSettingStaffDraftOn)==1 ){
$_POST['pick_method_id'] = kPlayerQueue;
}
// Check to make sure that if we have a scout pick that we have a mock draft
if ($_POST['pick_method_id'] == kScoutPick) {
$statement = "select * from mock_draft";
if (!mysql_num_rows(mysql_query($statement))) {
$_SESSION['message'] = "Scout pick is not available for this draft.";
$_POST['pick_method_id'] = kPlayerQueue;
}
}
$col[] = "pick_method_id = '".$_POST['pick_method_id']."'";
}
if ($login->is_site_admin() ){
if ($_POST['email_type']==kEmailTypeSMTP ){
//avoid setting them if they just switched to SMTP and didn't have the options yet
if ( $settings->get_value(kSettingEmailType)==kEmailTypeSMTP){
$statement = "update settings set setting_value='".$_POST['smtp_server']."' where setting_id=".kSettingSMTPServer.";";
mysql_query($statement);
$statement = "update settings set setting_value=".$_POST['smtp_port']." where setting_id=".kSettingSMTPPort.";";
mysql_query($statement);
$statement = "update settings set setting_value='".$_POST['smtp_user']."' where setting_id=".kSettingSMTPUser.";";
mysql_query($statement);
if ( strcmp($_POST['smtp_password'],"********")!=0 ){
$statement = "update settings set setting_value='".$_POST['smtp_password']."' where setting_id=".kSettingSMTPPassword.";";
mysql_query($statement);
}
$statement = "update settings set setting_value=".$_POST['smtp_encryption_type']." where setting_id=".kSettingSMTPEncryptType.";";
mysql_query($statement);
}
}
$statement = "update settings set setting_value=".$_POST['email_type']." where setting_id=".kSettingEmailType.";";
mysql_query($statement);
if (!$_SESSION['message']) {
$_SESSION['message'] = "Options updated.";
}
}
if ($login->is_admin() ){
if ( $settings->get_value(kSettingChatType)==kChatTypeTemplate){
$statement = "update settings set setting_value='".$_POST['chat_template_code']."' where setting_id=".kSettingChatTemplateCode.";";
mysql_query($statement);
}
$statement = "update settings set setting_value=".$_POST['chat_type']." where setting_id=".kSettingChatType.";";
mysql_query($statement);
if (!$_SESSION['message']) {
$_SESSION['message'] = "Options updated.";
}
}
if ($login->is_site_admin() && !$has_email) {
// Admin must have an e-mail address
$_SESSION['message'] = "The admin account must have an e-mail address.";
} else if ($login->is_site_admin()){
$statement = "update team set ".implode(",",$col)." where team_id = '1'";
mysql_query($statement);
// Send e-mails?
if ($_POST['email_type']!=kEmailTypeOff && $_POST['send_emails']) {
$settings->set_value(kSettingSendMails, $_POST['send_emails']);
} else {
$settings->set_value(kSettingSendMails, 0);
}
// Send e-mails?
if ($_POST['email_type']!=kEmailTypeOff && $_POST['send_admin_emails']) {
$settings->set_value(kSettingAdminEmail, $_POST['send_admin_emails']);
} else {
$settings->set_value(kSettingAdminEmail, 0);
}
if (!$_SESSION['message']) {
$_SESSION['message'] = "Options updated.";
}
} else {
if (!$_SESSION['message']) {
$_SESSION['message'] = "Options updated.";
}
}
// If admin, we might be changing the options
if ($login->is_admin()) {
$draft_type = $_POST['draft_type'];
$settings->set_value(kSettingDraftType, $draft_type);
if ($_POST['time_access'] > 0) {
// Draft clock
if ($_POST['start_hour'] > 0 && $_POST['end_hour'] > 0) {
$start_time = strtotime($_POST['start_hour'].':'.sprintf("%02d", $_POST['start_min']).' '.$_POST['start_ampm']);
$end_time = strtotime($_POST['end_hour'].':'.sprintf("%02d", $_POST['end_min']).' '.$_POST['end_ampm']);
if ($start_time > $end_time) {
$_SESSION['message'] = "The start time was later than the end time.";
} else {
$settings->set_value(kSettingStartTime, $start_time);
$settings->set_value(kSettingEndTime, $end_time);
}
} else {
$settings->set_value(kSettingStartTime, 0);
$settings->set_value(kSettingEndTime, 0);
}
// Set the pick time limit
$hour = $_POST['pick_limit_hour'];
$min = $_POST['pick_limit_min'];
$time = $hour * 60 + $min;
// How long is the draft clock running? We can't have the pick time be longer than that.
$window = $settings->get_value(kSettingEndTime) - $settings->get_value(kSettingStartTime);
if ($window && ($time*60) > $window) {
$_SESSION['message'] = "The pick time limit cannot be longer than the daily window";
$time = floor($window/60);
}
$settings->set_value(kSettingPickTimeLimit, $time);
// Make sure no teams have the option set longer than the new pick time limit
if ($time) {
$new_wait_limit = $time-5;
if ($new_wait_limit < 0) {
$new_wait_limit = 0;
}
$statement = "update team set team_autopick_wait = '$new_wait_limit' where team_autopick_wait >= '$time'";
mysql_query($statement);
}
// Somehow teams are getting set to a negative time limit
$statement = "update team set team_autopick_wait = '0' where team_autopick_wait < '0'";
mysql_query($statement);
//Set the pick time limit per round!
$statement = "select * from pick where pick_id is not NULL order by pick_id desc limit 1";
$result = mysql_query($statement);
$result = mysql_fetch_array($result);
$rounds = $result['pick_id']/32;
for ( $i=1; $i<$rounds+1; $i++ ){
// Set the pick time limit
$hour = $_POST['round_'.$i.'_pick_limit_hour'];
$min = $_POST['round_'.$i.'_pick_limit_min'];
$time = $hour * 60 + $min;
// How long is the draft clock running? We can't have the pick time be longer than that.
$window = $settings->get_value(kSettingEndTime) - $settings->get_value(kSettingStartTime);
if ($window && ($time*60) > $window) {
$_SESSION['message'] = "The round '.$i.' pick time limit cannot be longer than the daily window";
$time = floor($window/60);
}
$settings->set_value((100+$i), $time);
// Make sure no teams have the option set longer than the new pick time limit
if ($time) {
$new_wait_limit = $time-5;
if ($new_wait_limit < 0) {
$new_wait_limit = 0;
}
$statement = "update team set team_autopick_wait = '$new_wait_limit' where team_autopick_wait >= '$time'";
mysql_query($statement);
}
// Somehow teams are getting set to a negative time limit
$statement = "update team set team_autopick_wait = '0' where team_autopick_wait < '0'";
mysql_query($statement);
}
if ($_POST['max_autopick_delay'] > $time) {
$_POST['max_autopick_delay'] = $time;
}
// Time zone
$settings->set_value(kSettingTimeZone, $_POST['time_zone']);
}
if($draft_type == "slotted_draft") {
$start_time = strtotime(date("Y-m-d ", strtotime("now")).date("H:i:s", $settings->get_value(kSettingStartTime)));
$end_time = strtotime(date("Y-m-d ", strtotime("now")).date("H:i:s", $settings->get_value(kSettingEndTime)));
if($settings->get_value(kSettingStartTime) == 0 || $settings->get_value(kSettingEndTime) == 0){
$_SESSION['message'] = "You must specify a start and an end time to run a slotted draft";
}
if(strtotime("now") > $start_time){
$start_time += 3600 * 24;
$end_time += 3600 * 24;
}
$current_round = 0;
$current_time_for_each_pick = 0;
$statement = "select * from pick order by pick_id";
$result = mysql_query($statement);
while($row_pick = mysql_fetch_array($result)){
if($row_pick['pick_id'] == 0)
continue;
if($row_pick['player_id'] > 0)
continue;
$round = ceil(($row_pick['pick_id'])/32);
if($current_round != $round){
$current_round = $round;
$current_time_for_each_pick = $settings->get_value((100+$current_round));
}
$expire = $start_time + ($current_time_for_each_pick*60);
if($expire > $end_time){
$expire = strtotime(date("Y-m-d ", $start_time + (3600 * 24)).date("H:i:s", $settings->get_value(kSettingStartTime))) + $current_time_for_each_pick*60;
$end_time += 3600 * 24;
}
$start_time = $expire;
$statement = "update pick set slotted_draft_expire = '".date("Y-m-d H:i:s", $expire)."' where pick_id = ".$row_pick['pick_id'];
mysql_query($statement);
}
}
if ($_POST['pick_id']) {
// We have a halt round
$pick_id = $_POST['pick_id'];
$statement = "update pick set player_id = '".kDraftHalt."', pick_time = NULL
where player_id is NULL and pick_id >= '$pick_id'";
mysql_query($statement);
$statement = "update pick set player_id = NULL, pick_time = NULL
where player_id = '".kDraftHalt."' and pick_id < '$pick_id'";
mysql_query($statement);
reset_current_pick_clock();
} else {
// No halt round, all player_id's need to be NULL
$statement = "update pick set player_id = NULL, pick_time = NULL
where player_id = '".kDraftHalt."'";
mysql_query($statement);
reset_current_pick_clock();
}
// Set the league name
if ($_POST['league_name']) {
$settings->set_value(kSettingLeagueName, $_POST['league_name']);
}
//$settings->set_value(kSettingAutoPickWhenClockOff,$_POST['auto_when_clock_off']);
// set kSettingRolloverMethod
$settings->set_value(kSettingRolloverMethod, $_POST['rollover_method']);
// set kSettingAutopickReduction
$settings->set_value(kSettingAutopickReduction, $_POST['autopick_reduction']);
// What to do with expired picks
if ( $settings->get_value(kSettingStaffDraftOn)==0 )
$settings->set_value(kSettingExpiredPick, $_POST['team_expire']);
// Max delay
$settings->set_value(kSettingMaxDelay, $_POST['max_autopick_delay']);
// Make sure none of the teams have a greater value
if ($_POST['max_autopick_delay']) {
$statement = "update team set team_autopick_wait = '".$_POST['max_autopick_delay']."' where
team_autopick_wait > '".$_POST['max_autopick_delay']."'";
mysql_query($statement);
}
}
// In case we have updated the autopick setting, let's run the queue
process_pick_queue();
header("Location: draft_options.php");
?>