-
Notifications
You must be signed in to change notification settings - Fork 0
/
functions.php
566 lines (484 loc) · 22 KB
/
functions.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
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
<?php // Winning Deterministic Algorithm
//DB Reconciliation Functions
//***---------------------------
function getUserIdFromName($db,$user_name) {
$sql = "SELECT user_id FROM users WHERE user_name='$user_name'";
$result = mysqli_query($db, $sql) or die(mysqli_error_list($db));
return $row = mysqli_fetch_array($result)['user_id'];
}
function getUserNameFromId($db,$user_id) {
$sql = "SELECT user_name FROM users WHERE user_id='$user_id'";
$result = mysqli_query($db, $sql) or die(mysqli_error_list($db));
return $row = mysqli_fetch_array($result)['user_name'];
}
function getUserEmailFromId($db,$user_id) {
$sql = "SELECT user_email FROM users WHERE user_id='$user_id'";
$result = mysqli_query($db, $sql) or die(mysqli_error_list($db));
return $row = mysqli_fetch_array($result)['user_email'];
}
function notifyUser($email,$name,$num_games,$num_picks) {
global $SITE_HOST, $BASE_DIR;
$to = $email;
$subject = 'Football Pick Reminder';
// message
$message = '
<html>
<head>
<title>'.$subject.'</title>
</head>
<body>
<p>
Dear '.$name.',
</p>
<p>
Our official pick selection authenticators have noticed that you have only selected '.$num_picks.' of '.$num_games.' this week. Please <a href="http://'.$SITE_HOST.'/'.$BASE_DIR.'/picks.php">login to the site</a> to complete your pick selection.
</p>
<p>
Sincerely,<br>
Evose Football Mangement Team
</p>
</body>
</html>
';
// To send HTML mail, the Content-type header must be set
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
// Additional headers
$headers .= 'From: Evose Football <football@evose.com>' . "\r\n";
$headers .= 'Cc: tim.wiater@us.michelin.com' . "\r\n";
//$headers .= 'Bcc: birthdaycheck@example.com' . "\r\n";
// Mail it
if(mail($to, $subject, $message, $headers)) {
echo 'Mail sent.';
} else {
echo 'Mail Error';
}
}
function guessCurrentWeek() {
global $current_season_year, $current_season_type, $current_week, $this_season_year, $this_season_type, $this_week, $this_group_id, $this_user_id, $this_default_group;
// Guess Current Week
$query = "SELECT * FROM game WHERE finished=FALSE ORDER BY start_time ASC";
$result = pg_query($query) or die('Query failed: ' . pg_last_error());
$next_game = pg_fetch_array($result, null, PGSQL_ASSOC);
$current_season_year = $next_game['season_year'];
$current_season_type = $next_game['season_type'];
$current_week = $next_game['week'];
// Get any passed variables and extract them
extract($_REQUEST,EXTR_PREFIX_ALL,"this");
//echo 'This group: '.$this_group;
if(!isset($this_season_year)) { // user did not pass year so assume current
$this_season_year = $current_season_year;
}
if(!isset($this_season_type)) { // user did specify so assume current
$this_season_type = $current_season_type;
}
if(!isset($this_week)) { // user did specify so assume current
$this_week = $current_week;
}
if(!isset($this_group_id)) {
if(isset($this_user_id)) {
$this_group_id = $this_default_group;
} else {
$this_group_id = 0;
}
}
}
function getSeasonYearTypes($db,$group_id) {
//Use SQL Union to find seasons that belong to any group
//$season_years = getSeasonYears(); //get all years
//$season_types = getSeasonTypes(); //get all types
$sql = "SELECT season_year, season_type, group_id FROM picks\n"
. "UNION\n"
. "SELECT season_year, season_type, group_id FROM g_seasons";
$result = mysqli_query($db, $sql) or die(mysqli_error_list($db));
while($row = mysqli_fetch_array($result)) {
$season_years[] = $row['season_year'];
$season_types[] = $row['season_type'];
$groups[] = $row['group_id'];
}
return [$groups, $season_years, $season_types];
}
function addWin($db,$u,$s,$t,$w,$verbose) {
$sql = "UPDATE points SET winner='1' WHERE user_id='$u' AND season_year='$s' AND season_type='$t' AND week='$week'";
if(mysqli_query($db,$sql)) {
if($verbose) { echo "Win Added for User $u for $s $t Week $w<br>\n";}
} else {
echo mysqli_error($db);
}
}
function addPoint($db,$id,$p,$verbose) {
$sql = "UPDATE picks SET points='$p' WHERE pick_id='$id'";
if(mysqli_query($db,$sql)) {
if($verbose) { echo "$p Point Added to Pick $id<br>\n";}
} else {
echo mysqli_error($db);
}
}
function reconcilePoints($db,$user_id,$group_id,$season_year,$season_type,$week,$verbose) {
// check picks table for games that match season/week and sum them
//$sql = "SELECT SUM(points) AS points_sum FROM picks WHERE user_id='$user_id' AND season_year='$season_year' AND season_type='$season_type' AND week='$week'";
//$result = mysqli_query($db,$sql);
//$row = mysqli_fetch_assoc($result);
//$sum = $row['points_sum'];
//echo $sum;
$this_points_id = updatePoints($db,$user_id,$group_id,$season_year,$season_type,$week,$verbose); //piggy pack on update script on final time
$sql = "UPDATE points SET reconciled=1 WHERE points_id='$this_points_id'";
echo "<p>$sql</p>";
//$result = mysqli_query($db,$sql);
if(mysqli_query($db,$sql)) {
if($verbose) { echo "Point total id <b>$this_points_id</b> for user_id <b>$user_id</b> in group_id <b>$group_id</b> for <b>$season_year</b> <b>$season_type</b> Week <b>$week</b> has been <b>RECONCILED</b>.<br>\n"; }
} else {
echo mysqli_error($db);
}
}
function reconcileWinners($db,$winner,$group_id,$season_year,$season_type,$week,$verbose=FALSE) {
//New streamlined reconciliation process, added 8/22/15, this just sets the falgs in the db
$sql = "UPDATE points SET reconciled=1, winner=1 WHERE user_id='".getUserIdFromName($db,$winner)."' AND group_id='".$group_id."' AND season_year='".$season_year."' AND season_type='".$season_type."' AND week='".$week."'";
if(mysqli_query($db,$sql)) {
if($verbose) { echo "And has been reconciled in the database. $sql<br>\n"; }
} else {
echo mysqli_error($db);
}
//Set all users for that week as reconciled also, just with NULL winner
$sql = "UPDATE points SET reconciled=1 WHERE group_id='".$group_id."' AND season_year='".$season_year."' AND season_type='".$season_type."' AND week='".$week."'";
if(mysqli_query($db,$sql)) {
if($verbose) { echo "The other loser have also been reconciled in the database. $sql<br>\n"; }
} else {
echo mysqli_error($db);
}
}
function reconcileWeeklyPoints($db,$group_id,$season_year,$season_type,$week) {
// get users from mysql db that belong to the group
$users = getUsers($db, $group_id);
foreach($users as $user) {
$this_user_id = $user['user_id'];
echo "<p>User ".$user['user_name']."(id $this_user_id)</p>";
// Get all of the users picks for the season year type week
//$pick_result = mysqli_query($db, "SELECT * FROM picks WHERE user_id='$this_user_id' AND group_id='$group_id' AND season_year='$season_year' AND season_type='$season_type' AND week='$week'");
//$sql = "SELECT * FROM picks WHERE user_id='$this_user_id' AND group_id='$group_id' AND season_year='$season_year' AND season_type='$season_type' AND week='$week'";
$sql = "SELECT picks.pick_id, picks.game_id, picks.winner, points.reconciled\n"
. "FROM picks \n"
. "LEFT JOIN points \n"
. "ON points.user_id=picks.user_id\n"
. "WHERE picks.user_id='$this_user_id' AND picks.group_id='$group_id' AND picks.season_year='$season_year' AND picks.season_type='$season_type' AND picks.week='$week' AND points.reconciled is NULL";
echo "<p>$sql</p>";
$pick_result = mysqli_query($db, $sql) or die(mysqli_error($db));
while($user_pick = mysqli_fetch_array($pick_result)) {
$user_picks[] = $user_pick;
}
// Performing SQL query for all games
$query = "SELECT * FROM game WHERE season_year='$season_year' AND season_type='$season_type' AND week='$week'";
$result = pg_query($query) or die('Query failed: ' . pg_last_error());
while ($games = pg_fetch_array($result, null, PGSQL_ASSOC)) {
extract($games,EXTR_PREFIX_ALL,"this"); //load all game variables from db_array
if(strtotime($this_start_time) < time()) {
$has_started = true;
} else {
$has_started = false;
}
if($this_finished=="t") {
$has_finished = true;
}else {
$has_finished = false;
}
if(isset($user_picks)) { //at least some picks in db
foreach($user_picks as $pick) {
if($pick['game_id'] == $this_gsis_id) { //user has already picked game so set winner
$this_winner = $pick['winner'];
// pass this_winner to a script that checks the actual_winner for the jesus_id in the nfl_db
// if it returns true, print correct or add to score,,,,
// if false, print LOSER and don't ++score
if(strtotime($this_start_time) < time()) { //game started
if(getGameWinner($this_gsis_id) == $this_winner) {
if($this_finished == "t") {
//echo "<span style=\"color:green;\">Correct</span>";
// add point to picks table for user and gsis_id
addPoint($db,$pick['pick_id'],1,true);
reconcilePoints($db,$this_user_id,$group_id,$this_season_year,$this_season_type,$this_week,true);
}
} else {
if($this_finished == "t") {
//echo "<span style=\"color:red;\">Loser</span>";
addPoint($db,$pick['pick_id'],0,true);
reconcilePoints($db,$this_user_id,$group_id,$this_season_year,$this_season_type,$this_week,true);
}
}
}
}
}//End Foreach pick
}
} //End While
} //End User Foreach
}//END FUNCTION
function updatePoints($db,$user_id,$group_id,$season_year,$season_type,$week,$verbose) {
// check picks table for games that match season/week and sum them
//$sql = "SELECT SUM(points) AS points_sum FROM picks WHERE user_id='$user_id' AND season_year='$season_year' AND season_type='$season_type' AND week='$week'";
//$result = mysqli_query($db,$sql);
//$row = mysqli_fetch_assoc($result);
//$sum = $row['points_sum'];
//echo $sum;
$sum = getWeeklyPoints($db,$user_id,$group_id,$season_year,$season_type,$week);
$sql = "SELECT * FROM points WHERE user_id='$user_id' AND group_id='$group_id' AND season_year='$season_year' AND season_type='$season_type' AND week='$week'";
$result = mysqli_query($db,$sql);
if(mysqli_num_rows($result) > 0) { // user has points for week in db so update
// update points total in points table for user
$sql = "UPDATE points SET points='$sum' WHERE user_id='$user_id' AND group_id='$group_id' AND season_year='$season_year' AND season_type='$season_type' AND week='$week'";
//$result = mysqli_query($db,$sql);
if(mysqli_query($db,$sql)) {
if($verbose) { echo "Point total for user_id $user_id in group_id $group_id for $season_year $season_type Week $week updated to $sum.<br>\n"; }
return mysqli_insert_id($db);
} else {
echo mysqli_error($db);
}
} else { //no point total has been added so insert
$sql = "INSERT INTO points (points_id, user_id, group_id, season_year, season_type, week, points,winner) VALUES (NULL,'$user_id','$group_id','$season_year','$season_type','$week',$sum,NULL)";
if(mysqli_query($db, $sql)) {
if($verbose) { echo "Point total for user_id $user_id in group_id $group_id for $season_year $season_type Week $week inserted as $sum.<br>\n"; }
return mysqli_insert_id($db);
} else {
echo mysqli_error($db);
}
}
}
function updateWins($db,$season_year,$season_type,$week) {
// check picks table for games that match season/week and sum them
//$sql = "SELECT SUM(points) AS points_sum FROM picks WHERE user_id='$user_id' AND season_year='$season_year' AND season_type='$season_type' AND week='$week'";
//$result = mysqli_query($db,$sql);
//$row = mysqli_fetch_assoc($result);
//$sum = $row['points_sum'];
//echo $sum;
//$sum = getWeeklyPoints($db,$user_id,$season_year,$season_type,$week);
$sql = "SELECT SUM(points) AS points_sum FROM picks WHERE season_year='$season_year' AND season_type='$season_type' AND week='$week' ORDER BY points_sum";
$result = mysqli_query($db,$sql);
if(mysqli_num_rows($result) > 0) { // A winner was found
$user_id = mysqli_insert_id($db);
// update points total in points table for user
$sql = "UPDATE points SET winner=1 WHERE user_id='$user_id' AND season_year='$season_year' AND season_type='$season_type' AND week='$week'";
//$result = mysqli_query($db,$sql);
if(mysqli_query($db,$sql)) {
//echo "Weekly winner updated";
} else {
echo mysqli_error($db);
}
}
}
function getGameWinner($game_id) {
// Performing SQL query
$query = "SELECT * FROM game WHERE gsis_id='$game_id'";
$result = pg_query($query) or die('Query failed: ' . pg_last_error());
$game = pg_fetch_array($result, null, PGSQL_ASSOC);
if($game['home_score']>$game['away_score']) {
return $game['home_team'];
} elseif($game['home_score']==$game['away_score']) {
return "tied";
} else {
return $game['away_team'];
}
}
function getGameScore($game_id) {
// Performing SQL query
$query = "SELECT * FROM game WHERE gsis_id='$game_id'";
$result = pg_query($query) or die('Query failed: ' . pg_last_error());
$game = pg_fetch_array($result, null, PGSQL_ASSOC);
return $game['home_score'] + $game['away_score'];
}
function getMondayNightKickoffTime($game_id) {
// Performing SQL query
$query = "SELECT start_time FROM game WHERE gsis_id='$game_id'";
$result = pg_query($query) or die('Query failed: ' . pg_last_error());
$game = pg_fetch_array($result, null, PGSQL_ASSOC);
return $game['start_time'];
}
function getMondayNightGame($season_year,$season_type,$week) {
// Performing SQL query
//echo "check the score of game on Monday $season_year $season_type Week $week. ";
$query = "SELECT gsis_id FROM game WHERE day_of_week='Monday' AND season_year='$season_year' AND season_type='$season_type' AND week='$week' ORDER BY start_time DESC";
$result = pg_query($query) or die('Query failed: ' . pg_last_error());
if(pg_num_rows($result)==0) {// just get last game
$query = "SELECT gsis_id FROM game WHERE season_year='$season_year' AND season_type='$season_type' AND week='$week' ORDER BY start_time DESC";
$result = pg_query($query) or die('Query failed: ' . pg_last_error());
}
$game = pg_fetch_array($result, null, PGSQL_ASSOC);
//echo $game['gsis_id'];
return $game['gsis_id'];
}
function getFirstKickoffOfWeek($season_year,$season_type,$week) {
// Performing SQL query
$query = "SELECT start_time FROM game WHERE season_year='$season_year' AND season_type='$season_type' AND week='$week' ORDER BY start_time ASC";
$result = pg_query($query) or die('Query failed: ' . pg_last_error());
$game = pg_fetch_array($result, null, PGSQL_ASSOC);
return $game['start_time'];
}
function allGamesFinished($season_year,$season_type,$week) {
$query = "SELECT * FROM game WHERE finished='f' AND season_year='$season_year' AND season_type='$season_type' AND week='$week'";
$result = pg_query($query) or die('Query failed: ' . pg_last_error());
if(pg_num_rows($result) > 0) {
return FALSE;
} else {
return TRUE;
}
}
function getNumberOfGames($season_year,$season_type,$week) {
$query = "SELECT COUNT(gsis_id) as num_games FROM game WHERE season_year='$season_year' AND season_type='$season_type' AND week='$week'";
$result = pg_query($query) or die('Query failed: ' . pg_last_error());
$game = pg_fetch_array($result, null, PGSQL_ASSOC);
return $game['num_games'];
}
function getWeeklyPoints($db,$user_id,$group_id,$season_year,$season_type,$week) {
//updatePoints($db,$user_id,$season_year,$season_type,$week);
$sql = "SELECT SUM(points) AS points_sum FROM picks WHERE user_id='$user_id' AND group_id='$group_id' AND season_year='$season_year' AND season_type='$season_type' AND week='$week'";
$result = mysqli_query($db,$sql);
$row = mysqli_fetch_assoc($result);
if($row['points_sum'] > 0) {
return $row['points_sum'];
} else {
return 0;
}
}
function getWeeklyScore($db,$user_id,$group_id,$game_id) {
//updatePoints($db,$user_id,$season_year,$season_type,$week);
$sql = "SELECT SUM(score) as sum_score,game_id,winner FROM picks WHERE user_id='$user_id' AND group_id='$group_id' AND game_id='$game_id' AND score IS NOT NULL";
$result = mysqli_query($db,$sql);
$row = mysqli_fetch_assoc($result);
if($row['sum_score'] >= 0) {
return [$row['game_id'],$row['sum_score'],$row['winner']];
} else {
return [$row['game_id'],NULL,NULL];
}
}
function getWeeklyWinner($db,$group_id,$season_year,$season_type,$week) { // pull out the user_id of the person with the highest point toal for the week for the group
$sql = "SELECT * FROM points WHERE group_id='$group_id' AND season_year='$season_year' AND season_type='$season_type' AND week='$week' ORDER BY SUM(points)";
$result = mysqli_query($db,$sql);
if(mysqli_num_rows($result) == 1) { // A winner was found
$row = mysqli_fetch_assoc($result);
return $row['user_id'];
//return mysqli_insert_id($db);
} elseif(mysqli_num_rows($result) > 1) {
return "tie";
} else {
return "no winner/error";
}
}
function getUserWins($db,$user_id,$group_id,$season_year) { // pull out the user_id of the person with the highest point toal for the week
$sql = "SELECT * FROM points WHERE user_id='$user_id' AND group_id='$group_id' AND season_year='$season_year' ORDER BY SUM(points)";
$result = mysqli_query($db,$sql);
return mysqli_num_rows($result);
/*
if(mysqli_num_rows($result) == 1) { // A winner was found
$row = mysqli_fetch_assoc($result);
return $row['user_id'];
//return mysqli_insert_id($db);
} elseif(mysqli_num_rows($result) > 1) {
return "tie";
} else {
return "no winner/error";
}
*/
}
function getSeasonPoints($db,$user_id,$group_id,$season_year) {
$sql = "SELECT SUM(points) AS points_sum FROM picks WHERE user_id='$user_id' AND group_id='$group_id' AND season_year='$season_year'";
$result = mysqli_query($db,$sql);
$row = mysqli_fetch_assoc($result);
if($row['points_sum'] > 0) {
return $row['points_sum'];
} else {
return 0;
}
}
function getUsers($db,$group_id = 'all') { // get all users from mysql db
if($group_id == 'all') {
$result = mysqli_query($db, "SELECT * FROM users");
} else {
$result = mysqli_query($db, "SELECT * FROM users INNER JOIN g_members ON users.user_id=g_members.user_id WHERE g_members.group_id='$group_id'");
}
while($user = mysqli_fetch_array($result)) {
$users[] = $user;
}
return $users;
}
function getGroups($db,$user_id = 'all') {
if($user_id == 'all') {
$result = mysqli_query($db, "SELECT * FROM groups");
} else {
$sql = "SELECT *\n"
. "FROM groups\n"
. "INNER JOIN g_members\n"
. "ON groups.group_id=g_members.group_id\n"
. "WHERE g_members.user_id='$user_id'";
$result = mysqli_query($db, $sql);
}
while($group = mysqli_fetch_array($result)) {
$groups[] = $group;
}
mysqli_free_result($result);
return $groups;
}
function getPublicGroups($db) {
$result = mysqli_query($db, "SELECT * FROM groups WHERE private IS NULL");
while($group = mysqli_fetch_array($result)) {
$groups[] = $group;
}
mysqli_free_result($result);
return $groups;
}
function getGroupSeasonTypes($db,$group_id,$season_year) {
$sql = "SELECT season_type FROM g_seasons WHERE group_id = '$group_id' AND season_year = '$season_year'";
$result = mysqli_query($db,$sql);
while($row = mysqli_fetch_array($result,MYSQLI_ASSOC)) {
$these_season_types[] = $row['season_type'];
}
mysqli_free_result($result);
return $these_season_types;
}
function getGroupName($db,$group_id) {
$result = mysqli_query($db, "SELECT group_name FROM groups WHERE group_id='$group_id'");
return mysqli_fetch_array($result)['group_name'];
}
function getSeasonYears() {
$query = "SELECT DISTINCT season_year FROM game ORDER BY season_year ASC";
$result = pg_query($query) or die('Query failed: ' . pg_last_error());
$all_results = pg_fetch_all($result);
foreach($all_results as $year) {
$display_years[] = $year['season_year'];
}
return $display_years;
}
function getSeasonTypes() {
$query = "SELECT DISTINCT season_type FROM game";
$result = pg_query($query) or die('Query failed: ' . pg_last_error());
$all_results = pg_fetch_all($result);
foreach($all_results as $type) {
$display_types[] = $type['season_type'];
}
return $display_types;
}
function getWeeks($season_year,$season_type) {
$query = "SELECT DISTINCT week FROM game WHERE season_type='$season_type' AND season_year='$season_year' ORDER BY week ASC";
$result = pg_query($query) or die('Query failed: ' . pg_last_error());
//echo $result;
//echo "$season_year $season_type";
$all_results = pg_fetch_all($result);
//print_r($all_results);
if($all_results) {
foreach($all_results as $week) {
$display_weeks[] = $week['week'];
}
} else {
$display_weeks = [];
}
return $display_weeks;
}
function getNumWeeks($season_year,$season_type) {
$query = "SELECT DISTINCT COUNT(week) as num_weeks FROM game WHERE season_type='$season_type' AND season_year='$season_year'";
$result = pg_query($query) or die('Query failed: ' . pg_last_error());
//echo $result;
//echo "$season_year $season_type";
return pg_num_rows($result);
}
function calculateWinnings($users,$weeks,$wins,$anty) {
//starting balance = weeks*anty
//total pot = users * weeks * anty
//winnings = (wins * users * anty) - (total_weeks*anty)
return ($wins * count($users) * $anty) - ($weeks * $anty);
}
?>