WebDev

SMF Modifications => General Code/Script Inquiries => Topic started by: Fog on December 07, 2013, 09:32:32 PM

Title: Pickems help
Post by: Fog on December 07, 2013, 09:32:32 PM
Here's the code for the attachment below:

<?php
require('includes/application_top.php');

$weekStats = array();
$playerTotals = array();
$possibleScoreTotal 0;
calculateStats();

include(
'includes/header.php');
?>

<h1>Standings</h1>
<h2>Weekly Stats</h2>
<table cellpadding="4" cellspacing="0" class="table1">
<tr><th align="left">Week</th><th align="left">Winner(s)</th><th>Score</th></tr>
<?php
if (isset($weekStats)) {
$i 0;
foreach($weekStats as $week => $stats) {
$winners '';
foreach($stats[winners] as $winner => $winnerID) {
$tmpUser $login->get_user_by_id($winnerID);
switch ($user_names_display) {
case 1:
$winners .= ((strlen($winners) > 0) ? ', ' '') . trim($tmpUser->firstname ' ' $tmpUser->lastname);
break;
case 2:
$winners .= ((strlen($winners) > 0) ? ', ' '') . $tmpUser->userName;
break;
default: //3
$winners .= ((strlen($winners) > 0) ? ', ' '') . '<abbrev title="' trim($tmpUser->firstname ' ' $tmpUser->lastname) . '">' $tmpUser->userName '</abbrev>';
break;
}
}
$rowclass = (($i == 0) ? ' class="altrow"' '');
echo ' <tr' $rowclass '><td>' $week '</td><td>' $winners '</td><td align="center">' $stats[highestScore] . '/' $stats[possibleScore] . '</td></tr>';
$i++;
}
} else {
echo ' <tr><td colspan="3">No weeks have been completed yet.</td></tr>' "\n";
}
?>

</table>
<p>&nbsp;</p>

<h2>User Stats</h2>
<table cellpadding="0" cellspacing="0">
<tr valign="top">
<td>
<b>By Name</b><br />
<table cellpadding="4" cellspacing="0" class="table1">
<tr><th align="left">Player</th><th align="left">Wins</th><th>Pick Ratio</th></tr>
<?php
if (isset($playerTotals)) {
//arsort($playerTotals);
$i 0;
foreach($playerTotals as $playerID => $stats) {
$rowclass = (($i == 0) ? ' class="altrow"' '');
$pickRatio $stats[score] . '/' $possibleScoreTotal;
$pickPercentage number_format((($stats[score] / $possibleScoreTotal) * 100), 2) . '%';
switch ($user_names_display) {
case 1:
echo ' <tr' $rowclass '><td class="tiny">' $stats[name] . '</td><td class="tiny" align="center">' $stats[wins] . '</td><td class="tiny" align="center">' $pickRatio ' (' $pickPercentage ')</td></tr>';
break;
case 2:
echo ' <tr' $rowclass '><td class="tiny">' $stats[userName] . '</td><td class="tiny" align="center">' $stats[wins] . '</td><td class="tiny" align="center">' $pickRatio ' (' $pickPercentage ')</td></tr>';
break;
default: //3
echo ' <tr' $rowclass '><td class="tiny"><abbrev title="' $stats[name] . '">' $stats[userName] . '<abbrev></td><td class="tiny" align="center">' $stats[wins] . '</td><td class="tiny" align="center">' $pickRatio ' (' $pickPercentage ')</td></tr>';
break;
}
$i++;
}
} else {
echo ' <tr><td colspan="3">No weeks have been completed yet.</td></tr>' "\n";
}
?>

</table>
</td>
<td>&nbsp;</td>
<td>
<b>By Wins</b><br />
<table cellpadding="4" cellspacing="0" class="table1">
<tr><th align="left">Player</th><th align="left">Wins</th><th>Pick Ratio</th></tr>
<?php
if (isset($playerTotals)) {
arsort($playerTotals);
$i 0;
foreach($playerTotals as $playerID => $stats) {
$rowclass = (($i == 0) ? ' class="altrow"' '');
$pickRatio $stats[score] . '/' $possibleScoreTotal;
$pickPercentage number_format((($stats[score] / $possibleScoreTotal) * 100), 2) . '%';
switch ($user_names_display) {
case 1:
echo ' <tr' $rowclass '><td class="tiny">' $stats[name] . '</td><td class="tiny" align="center">' $stats[wins] . '</td><td class="tiny" align="center">' $pickRatio ' (' $pickPercentage ')</td></tr>';
break;
case 2:
echo ' <tr' $rowclass '><td class="tiny">' $stats[userName] . '</td><td class="tiny" align="center">' $stats[wins] . '</td><td class="tiny" align="center">' $pickRatio ' (' $pickPercentage ')</td></tr>';
break;
default: //3
echo ' <tr' $rowclass '><td class="tiny"><abbrev title="' $stats[name] . '">' $stats[userName] . '</abbrev></td><td class="tiny" align="center">' $stats[wins] . '</td><td class="tiny" align="center">' $pickRatio ' (' $pickPercentage ')</td></tr>';
break;
}
$i++;
}
} else {
echo ' <tr><td colspan="3">No weeks have been completed yet.</td></tr>' "\n";
}
?>

</table>
</td>
<td>&nbsp;</td>
<td>
<b>By Pick Ratio</b><br />
<table cellpadding="4" cellspacing="0" class="table1">
<tr><th align="left">Player</th><th align="left">Wins</th><th>Pick Ratio</th></tr>
<?php
if (isset($playerTotals)) {
$playerTotals sort2d($playerTotals'score''desc');
$i 0;
foreach($playerTotals as $playerID => $stats) {
$rowclass = (($i == 0) ? ' class="altrow"' '');
$pickRatio $stats[score] . '/' $possibleScoreTotal;
$pickPercentage number_format((($stats[score] / $possibleScoreTotal) * 100), 2) . '%';
switch ($user_names_display) {
case 1:
echo ' <tr' $rowclass '><td class="tiny">' $stats[name] . '</td><td class="tiny" align="center">' $stats[wins] . '</td><td class="tiny" align="center">' $pickRatio ' (' $pickPercentage ')</td></tr>';
break;
case 2:
echo ' <tr' $rowclass '><td class="tiny">' $stats[userName] . '</td><td class="tiny" align="center">' $stats[wins] . '</td><td class="tiny" align="center">' $pickRatio ' (' $pickPercentage ')</td></tr>';
break;
default: //3
echo ' <tr' $rowclass '><td class="tiny"><abbrev title="' $stats[name] . '">' $stats[userName] . '</abbrev></td><td class="tiny" align="center">' $stats[wins] . '</td><td class="tiny" align="center">' $pickRatio ' (' $pickPercentage ')</td></tr>';
break;
}
$i++;
}
} else {
echo ' <tr><td colspan="3">No weeks have been completed yet.</td></tr>' "\n";
}
?>

</table>
</td>
</tr>
</table>
<p>&nbsp;</p>
<?php
include('includes/footer.php');
?>


What I'd like to display is instead of:

12 DLPackers 7/14  it would look like this 12 DLPackers 7-7

or

13 Fog 13/16  it would look like this 13 Fog 13-3

The 12 and 13 are the weeks and the 7/14 or 13/16 are wins compared to the number of games that week.

the 7-7 or 13-3 would be a win-lose record for that week.  Then what I'd like to try and create is an overall leader board with wins and loses.

Instead of this:

By Pick Ratio
Player Wins Pick Ratio
Fog 1 19/31 (61.29%)
SoCalSaint 0 15/31 (48.39%)
DLPackers 1 14/31 (45.16%)
SloopyDave 0 5/31 (16.13%)
Jeep99tj 0 4/31 (12.90%)

By Overall Record
Player Wins-Loses
Fog 19-12 
SoCalSaint 15-16
DLPackers 14-17
SloopyDave 5-26
Jeep99tj  4-27

---------------------------
Is there a way to add that PHP code in a PHP Block or PHP page with simple portal?
Title: Re: Pickems help
Post by: Chen Zhen on December 07, 2013, 10:50:09 PM

global $boarddir;
require_once($boarddir . '/includes/application_top.php');

$weekStats = array();
$playerTotals = array();
$possibleScoreTotal = 0;
calculateStats();

require_once($boarddir . '/includes/header.php');

echo '
<h1>Standings</h1>
<h2>Weekly Stats</h2>
<table cellpadding="4" cellspacing="0" class="table1">
<tr><th align="left">Week</th><th align="left">Winner(s)</th><th>Score</th></tr>';

if (!empty($weekStats)) {
$i = 0;
foreach($weekStats as $week => $stats) {
$winners = false;
foreach($stats['winners'] as $winner => $winnerID) {
$tmpUser = $login->get_user_by_id($winnerID);
switch ($user_names_display) {
case 1:
$winners .= ((strlen($winners) > 0) ? ', ' : '') . trim($tmpUser->firstname . ' ' . $tmpUser->lastname);
break;
case 2:
$winners .= ((strlen($winners) > 0) ? ', ' : '') . $tmpUser->userName;
break;
default: //3
$winners .= ((strlen($winners) > 0) ? ', ' : '') . '<abbrev title="' . trim($tmpUser->firstname . ' ' . $tmpUser->lastname) . '">' . $tmpUser->userName . '</abbrev>';
break;
}
}
$rowclass = (($i % 2 == 0) ? ' class="altrow"' : '');
echo ' <tr' . $rowclass . '><td>' . $week . '</td><td>' . $winners . '</td><td align="center">' . $stats['highestScore'] . '/' . $stats['possibleScore'] . '</td></tr>';
$i++;
}
} else {
echo ' <tr><td colspan="3">No weeks have been completed yet.</td></tr><br />';
}

echo '
</table>
<p>&nbsp;</p>

<h2>User Stats</h2>
<table cellpadding="0" cellspacing="0">
<tr valign="top">
<td>
<b>By Name</b><br />
<table cellpadding="4" cellspacing="0" class="table1">
<tr><th align="left">Player</th><th align="left">Wins</th><th>Pick Ratio</th></tr>';

if (!empty($playerTotals)) {
//arsort($playerTotals);
$i = 0;
foreach($playerTotals as $playerID => $stats) {
$rowclass = (($i % 2 == 0) ? ' class="altrow"' : '');
$pickRatio = $stats['score'] . '/' . $possibleScoreTotal;
$pickPercentage = number_format((($stats['score'] / $possibleScoreTotal) * 100), 2) . '%';
switch ($user_names_display) {
case 1:
echo ' <tr' . $rowclass . '><td class="tiny">' . $stats['name'] . '</td><td class="tiny" align="center">' . $stats['wins'] . '</td><td class="tiny" align="center">' . $pickRatio . ' (' . $pickPercentage . ')</td></tr>';
break;
case 2:
echo ' <tr' . $rowclass . '><td class="tiny">' . $stats['userName'] . '</td><td class="tiny" align="center">' . $stats['wins'] . '</td><td class="tiny" align="center">' . $pickRatio . ' (' . $pickPercentage . ')</td></tr>';
break;
default: //3
echo ' <tr' . $rowclass . '><td class="tiny"><abbrev title="' . $stats['name'] . '">' . $stats['userName'] . '<abbrev></td><td class="tiny" align="center">' . $stats['wins'] . '</td><td class="tiny" align="center">' . $pickRatio . ' (' . $pickPercentage . ')</td></tr>';
break;
}
$i++;
}
} else {
echo ' <tr><td colspan="3">No weeks have been completed yet.</td></tr><br />';
}
echo '
</table>
</td>
<td>&nbsp;</td>
<td>
<b>By Wins</b><br />
<table cellpadding="4" cellspacing="0" class="table1">
<tr><th align="left">Player</th><th align="left">Wins</th><th>Pick Ratio</th></tr>';

if (isset($playerTotals)) {
arsort($playerTotals);
$i = 0;
foreach($playerTotals as $playerID => $stats) {
$rowclass = (($i % 2 == 0) ? ' class="altrow"' : '');
$pickRatio = $stats['score'] . '/' . $possibleScoreTotal;
$pickPercentage = number_format((($stats['score'] / $possibleScoreTotal) * 100), 2) . '%';
switch ($user_names_display) {
case 1:
echo ' <tr' . $rowclass . '><td class="tiny">' . $stats['name'] . '</td><td class="tiny" align="center">' . $stats['wins'] . '</td><td class="tiny" align="center">' . $pickRatio . ' (' . $pickPercentage . ')</td></tr>';
break;
case 2:
echo ' <tr' . $rowclass . '><td class="tiny">' . $stats['userName'] . '</td><td class="tiny" align="center">' . $stats['wins'] . '</td><td class="tiny" align="center">' . $pickRatio . ' (' . $pickPercentage . ')</td></tr>';
break;
default: //3
echo ' <tr' . $rowclass . '><td class="tiny"><abbrev title="' . $stats['name'] . '">' . $stats['userName'] . '</abbrev></td><td class="tiny" align="center">' . $stats['wins'] . '</td><td class="tiny" align="center">' . $pickRatio . ' (' . $pickPercentage . ')</td></tr>';
break;
}
$i++;
}
} else {
echo ' <tr><td colspan="3">No weeks have been completed yet.</td></tr><br />';
}
echo '
</table>
</td>
<td>&nbsp;</td>
<td>
<b>By Pick Ratio</b><br />
<table cellpadding="4" cellspacing="0" class="table1">
<tr><th align="left">Player</th><th align="left">Wins</th><th>Pick Ratio</th></tr>';

if (isset($playerTotals)) {
$playerTotals = sort2d($playerTotals, 'score', 'desc');
$i = 0;
foreach($playerTotals as $playerID => $stats) {
$rowclass = (($i % 2 == 0) ? ' class="altrow"' : '');
$pickRatio = $stats['score'] . '/' . $possibleScoreTotal;
$pickPercentage = number_format((($stats['score'] / $possibleScoreTotal) * 100), 2) . '%';
switch ($user_names_display) {
case 1:
echo ' <tr' . $rowclass . '><td class="tiny">' . $stats['name'] . '</td><td class="tiny" align="center">' . $stats['wins'] . '</td><td class="tiny" align="center">' . $pickRatio . ' (' . $pickPercentage . ')</td></tr>';
break;
case 2:
echo ' <tr' . $rowclass . '><td class="tiny">' . $stats['userName'] . '</td><td class="tiny" align="center">' . $stats['wins'] . '</td><td class="tiny" align="center">' . $pickRatio . ' (' . $pickPercentage . ')</td></tr>';
break;
default: //3
echo ' <tr' . $rowclass . '><td class="tiny"><abbrev title="' . $stats['name'] . '">' . $stats['userName'] . '</abbrev></td><td class="tiny" align="center">' . $stats['wins'] . '</td><td class="tiny" align="center">' . $pickRatio . ' (' . $pickPercentage . ')</td></tr>';
break;
}
$i++;
}
} else {
echo ' <tr><td colspan="3">No weeks have been completed yet.</td></tr><br />';
}
echo '
</table>
</td>
</tr>
</table>
<p>&nbsp;</p>';

require_once($boarddir . '/includes/footer.php');


Fog,

  I did not change anything being displayed and only edited it for a php block. The files you are using should be located in the sub folder named includes which can be placed in your main smf directory. The issue I see here is that your going to attempt to pass arrays between files improperly. Those files should have functions that return the necessary values that you assign to an array (or variable).

ie. file named example.php


// this function is in a file called example.php and is located in the SMF board directory
function example_func()
{
   $a = array(0 => 'This is a test!!!', 1 => 'Another test!!!');

  return $a;
}



ie. put in php block:

// in your block code, you call the file and assign the array
global $boarddir;

require_once($boarddir . '/example.php');

$data = example_func();

// let's display the array data for this example
print_r($data);
Title: Re: Pickems help
Post by: Fog on December 07, 2013, 11:27:20 PM
There is a weekly entry form that one needs to complete or fill out. That will create results and then standings.  The results have to be manually inputted.

I should show you all the files.
Title: Re: Pickems help
Post by: Fog on December 08, 2013, 12:08:03 PM
It kind of works in a PHP Block but it wants you to login and comes up with a blank screen.

Back to the drawing board....
Title: Re: Pickems help
Post by: Fog on December 09, 2013, 11:38:45 PM
I see what it wants to do...

http://www.ngsforums.com/fog/phppickem-master/login.php

the reason why it's blank is I don't have the login php file in place and I need to get some css and other stuff in place.

Question...If I put in the login php code in the php block, would one be able to login and navigate within that block to see other pages?  a web site within a block?  Or would an Iframe code work better?
Title: Re: Pickems help
Post by: Chen Zhen on December 11, 2013, 03:44:44 PM
Fog,

  I am not sure I understand your question correctly. Would SP pages work for you instead of files?  iframe probably not necessary as one can use cURL or the SMF fetch_web_data($url) function to get a pages data (using cURL to fill a form if necessary). It all depends on what you want to do.
Title: Re: Pickems help
Post by: Fog on December 11, 2013, 09:40:15 PM
All I'm trying to do is display the standings of a game I have going on in a SP Block.  Your code works but only if you are logged in and if you're not it takes you to the login page.  Then I got to thinking can I navigate the whole web site I use for the game in a given SP Block...

The iframe idea will work I know but it's not really what I want to do.

I wish I had more knowledge on terms then I'd be able to convey my idea a bit better.
Title: Re: Pickems help
Post by: Chen Zhen on December 11, 2013, 10:21:03 PM

Fog,

  The second tiered site that contains the game, requires one to be logged in to view the data? If the second site is also SMF, why do you have it set up to be logged in to view the data if you do not want it that way? I suppose I just do not understand what you are attempting to accomplish.
Title: Re: Pickems help
Post by: Fog on December 11, 2013, 10:47:40 PM
QuoteThe second tiered site that contains the game, requires one to be logged in to view the data?

Yes they do...

QuoteIf the second site is also SMF, why do you have it set up to be logged in to view the data if you do not want it that way?

It's not SMF at all....Click Here (http://www.eastsidenapaautocare.com/fog/phppickem-master/index.php)

What I'd like to do is intergrade this game http://www.phppickem.com/ with SMF or SP Block/Page but I'm testing it as a standalone website.

I thought I would see if I could learn and see if I could display the standings of this game on the standalone site on a SP Block.  However the code that you modified will only work if you are logged on to the standalone site (I'im guessing this is the confusion), other wise the sp block takes you to the login page for the standalone site.

Then I got to thinking if one could navigate the standalone site within the sp block and the iframe idea came to mind.
Title: Re: Pickems help
Post by: Chen Zhen on December 11, 2013, 11:01:07 PM

Fog,

  If they have to be logged in to view the data on the other site and you're not able to change that aspect then you must work with that.
You could have them enter a user id and p/w for the game site in their SMF user profile and then use cURL to pass that data which would auto log them in to the game site when they navigate to it.

Title: Re: Pickems help
Post by: Fog on December 11, 2013, 11:07:25 PM
I'm thinking if I get rid of this part I don't need to require a login

global $boarddir;
require_once($boarddir . '/includes/application_top.php');

$weekStats = array();
$playerTotals = array();
$possibleScoreTotal = 0;
calculateStats();

require_once($boarddir . '/includes/header.php');
Title: Re: Pickems help
Post by: Fog on August 25, 2014, 10:51:34 PM
UD, I'm looking to create a tie breaker input box for the NFL Game I'm hosting.

We want to pick one game per week as a tie breaker.

Total points.

So I'm looking to create an input box that logs a members guess at total points.

Any help would be cool

Fog
Title: Re: Pickems help
Post by: Chen Zhen on August 26, 2014, 09:13:51 PM
Fog,

How are you orchestrating this input box?
Is it in a portal block/page or on an existing form?
Do you just want me to create a basic input display and then you do the rest?

If it is an existing form with other inputs you should be able to figure this out on your own.
Just copy one of the existing inputs and change its text (<- prior to input element) and request variable (<- name).
The type will be text or perhaps number for your purposes.

ref. http://www.w3schools.com/tags/tag_input.asp
Title: Re: Pickems help
Post by: Fog on August 27, 2014, 01:08:41 AM
You raise a good question...

I'm thinking a portal block...a Page would be way cool.

I'm thinking I would use Sunday Night Games.

Members would have an input box that would be logged, then we would need a way to use this info incase he have more than one winner per week.

If I have one winner and guesses 15/16 games right and the next pickers pick 14/16 games right I don't need a tie breaker.  If I have five members tied for the week I'm looking to use the tie breaker.

Week 1: Total Points for Seahawks vs Packer:  [input box here]
Week 2: Total Points for X vs Y: [input box here]
Title: Re: Pickems help
Post by: Fog on August 28, 2014, 12:38:21 AM
UD...We're better off trying to get our members to post it and we log it manually at this point.

If I send you the code to the game I'm hosting would you mind looking at it and seeing if there is a way to add a tie breaker?
Title: Re: Pickems help
Post by: Chen Zhen on August 28, 2014, 04:00:38 AM
Take a look at this:


// NFL ~ Current week - last game as tie breaker
// last updated: Sep 01 3:45am
global $user_info, $scripturl, $smcFunc, $sourcedir;
require_once($sourcedir . '/Subs-Package.php');
db_extend('packages');
checkNflTable();
$lastGamesArray = array(
0 => array('',''),
1 => array('SD', 'ARI'),
2 => array('PHI', 'IND'),
3 => array('CHI', 'NYJ'),
4 => array('NE', 'KC'),
5 => array('SEA', 'WSH'),
6 => array('SF', 'STL'),
7 => array('HOU', 'PIT'),
8 => array('WSH', 'DAL'),
9 => array('IND', 'NYG'),
10 => array('CAR', 'PHI'),
11 => array('PIT', 'TEN'),
12 => array('BAL', 'NO'),
13 => array('MIA', 'NYJ'),
14 => array('ATL', 'GB'),
15 => array('NO', 'CHI'),
16 => array('DEN', 'CIN'),
17 => array('STL', 'SEA'),
);

$onset = strtotime('Sep 7, 2014');
$gameCutOff = 1;
$feed = 'http://www.nfl.com/liveupdate/scorestrip/scorestrip.json';
$json = fetch_web_data($feed) ? fetch_web_data(utf8_encode($feed)) : false;
$json = preg_replace(array('~,,~', '~,,~', '~,,~'), array(',"",', ',"",', ',"",'), $json);
$html = json_decode($json, true);
$html = !empty($html['ss']) ? $html['ss'] : array();
$nfl_games = array();
$data = array();
$gameCount = 0;
$gameData = array('day', 'time', 'type', 'a', 'away', 'away_score', 'home', 'home_score', 'b', 'c', 'id', 'd', 'code', 'year');
$dayArray = array('Tue', 'Wed', 'Thu', 'Fri');

if (!empty($html))
{
foreach ($html as $key => $game)
{
for ($i=0; $i <=13; $i++)
$nfl_games[$gameCount][$gameData[$i]] = $game[$i];

$gameCount++;
}
$week_final = $nfl_games[count($nfl_games) - 1];

$actualTotal = (is_numeric($week_final['away_score']) || is_numeric($week_final['home_score'])) ? (int)$week_final['home_score'] + (int)$week_final['away_score'] : '??';
date_default_timezone_set('EST');
$currentDay = date('D', time());
$queryWeek = (time() - $onset !== abs(time() - $onset) || time() - $onset > 604800) ? 604800 : 0;
$time = strtotime('this ' . $week_final['day'] . ', ' . $week_final['time'] . 'pm') + $queryWeek;
$weekCounter = ((round(($time - $onset) / 604800)) > 0 ? round(($time - $onset) / 604800) : 1);
$cutoff = strtotime('this ' . $nfl_games[$gameCutOff]['day'] . ', ' . $nfl_games[$gameCutOff]['time'] . 'pm') + $queryWeek;
$displayCutOff = date('D M d h:iA', $cutoff) . ' EST';
$displayTime = date('D M d h:iA', $time) . ' EST';
$notAllowed = (time() - $cutoff >= 0) ? true : false;

$currentWeekApi = getInt($week_final['code']);
$currentMatchUp = $lastGamesArray[$weekCounter];
$confirm =  (in_array($week_final['home'], $currentMatchUp) && in_array($week_final['away'], $currentMatchUp)) ? true : false;
}

if ((!empty($html)) && empty($notAllowed) && time() < ($time + 86400) && in_array($currentDay, $dayArray) && $confirm && stripos($week_final['code'], 'PRE') === false && (int)$currentWeekApi == $weekCounter)
{

if (isset($_REQUEST['points']) && isset($_REQUEST['submit']))
{
$smcFunc['db_query']('', "
DELETE FROM {db_prefix}nfl_tiebreakers
WHERE id_member = {int:member} AND week = {int:current}",
array('member' => $user_info['id'], 'current' => $weekCounter)
);
$smcFunc['db_insert']('insert', "
{db_prefix}nfl_tiebreakers",
array('week' => 'int', 'id_member' => 'int', 'logged' => 'int', 'points' => 'int', 'home' => 'string', 'away' => 'string'),
array($weekCounter, $user_info['id'], $cutoff, (int)$_REQUEST['points'], $week_final['home'], $week_final['away']),
array('week')
);

}

$request = $smcFunc['db_query']('', "
SELECT week, id_member, logged, points, home, away
FROM {db_prefix}nfl_tiebreakers
WHERE week = {int:week} AND id_member = {int:member}",
array('week' => $weekCounter, 'member' => $user_info['id'])
);

while ($row = $smcFunc['db_fetch_assoc']($request))
{
$data = array(
'week' => !empty($row['week']) ? (int)$row['week'] : 0,
'id_member' => !empty($row['id_member']) ? (int)$row['id_member'] : 0,
'logged' => !empty($row['logged']) ? (int)$row['logged'] : 0,
'points' => isset($row['points']) ? (int)$row['points'] : null,
'home' => !empty($row['home']) ? $row['home'] : '',
'away' => !empty($row['away']) ? $row['away'] : '',
);
}
$smcFunc['db_free_result']($request);

echo '
<form id="nfl_pick" name="nfl_pickem" action="' . currentPageNflPickem() . '" method="post">
<div class="cat_bar">
<h3 class="centertext catbg">NFL Pool Weekly Picks</h3>
</div>
<table>
<tr style="padding:3px;">
<td style="padding:0px 8px 0px 8px;">Week</td>
<td style="padding:0px 8px 0px 8px;">Game Date</td>
<td style="padding:0px 8px 0px 8px;">Away</td>
<td style="padding:0px 8px 0px 8px;">Home</td>
<td style="padding:0px 8px 0px 8px;">Username</td>
<td style="padding:0px 8px 0px 8px;">Tie Breaking Points Total</td>
<td colspan="2">&nbsp;</td>
</tr>
</table>
<table>
<tr style="padding:3px;">
<td style="padding:0px 8px 0px 8px;">Cut-off Date</td>
<td style="padding:0px 8px 0px 8px;">Game Date</td>
<td style="padding:0px 8px 0px 8px;">Away</td>
<td style="padding:0px 8px 0px 8px;">Home</td>
<td style="padding:0px 8px 0px 8px;">Username</td>
<td style="padding:0px 8px 0px 8px;">Tie Breaking Points Total</td>
<td colspan="2">&nbsp;</td>
</tr>
<tr style="padding:3px;">
<td style="padding:0px 8px 0px 8px;">', $displayCutOff, '</td>
<td style="padding:0px 8px 0px 8px;">', $displayTime, '</td>
<td style="padding:0px 8px 0px 8px;">', $week_final['away'], '</td>
<td style="padding:0px 8px 0px 8px;">', $week_final['home'], '</td>
<td style="padding:0px 8px 0px 8px;"><a href="' . $scripturl. '?action=profile;u=' . $user_info['id'] . '">', $user_info['name'], '</a></td>
<td style="padding:0px 8px 0px 8px;text-align:center;">
<input name="points" type="number" maxlength="4" size="3" min="0" max="999" value="', (isset($data['points']) ? (int)$data['points'] : 0), '" />
', (isset($actualTotal) ? '<span title="Actual Total" style="padding:0px 3px 0px 3px;">[' .  $actualTotal . ']</span>' : ''), '
</td>
<td>
', (isset($data['points']) ? '<span style="color:green;">On Record' : '<span style="color:red;">Pending'), '</span>
</td>
<td>
<input class="submit" type="submit" name="submit" style="position:relative;left:100%;" />
</td>
</tr>
</table>
</form>
';
}
elseif (!empty($html) && $confirm && stripos($week_final['code'], 'PRE') === false)
{
$request = $smcFunc['db_query']('', "
SELECT week, id_member, logged, points, home, away
FROM {db_prefix}nfl_tiebreakers
WHERE week = {int:week} AND id_member = {int:member}",
array('week' => $weekCounter, 'member' => $user_info['id'])
);

while ($row = $smcFunc['db_fetch_assoc']($request))
{
$data = array(
'week' => !empty($row['week']) ? (int)$row['week'] : 0,
'id_member' => !empty($row['id_member']) ? (int)$row['id_member'] : 0,
'logged' => !empty($row['logged']) ? (int)$row['logged'] : 0,
'points' => isset($row['points']) ? (int)$row['points'] : null,
'home' => !empty($row['home']) ? $row['home'] : '',
'away' => !empty($row['away']) ? $row['away'] : '',
);
}
$smcFunc['db_free_result']($request);

echo '
<div style="display:inline;">
<div class="cat_bar">
<h3 class="centertext catbg">NFL Pool Weekly Picks</h3>
</div>
<table>
<tr style="padding:3px;">
<td style="padding:0px 8px 0px 8px;">Cut-off Date</td>
<td style="padding:0px 8px 0px 8px;">Game Date</td>
<td style="padding:0px 8px 0px 8px;">Away</td>
<td style="padding:0px 8px 0px 8px;">Home</td>
<td style="padding:0px 8px 0px 8px;">Username</td>
<td style="padding:0px 8px 0px 8px;">Tie Breaking Points Total</td>
<td colspan="2">&nbsp;</td>
</tr>
<tr style="padding:3px;">
<td style="padding:0px 8px 0px 8px;">', $displayCutOff, '</td>
<td style="padding:0px 8px 0px 8px;">', $displayTime, '</td>
<td style="padding:0px 8px 0px 8px;">', $week_final['away'], '</td>
<td style="padding:0px 8px 0px 8px;">', $week_final['home'], '</td>
<td style="padding:0px 8px 0px 8px;"><a href="' . $scripturl. '?action=profile;u=' . $user_info['id'] . '">', $user_info['name'], '</a></td>
<td style="padding:0px 8px 0px 8px;text-align:center;">
', (isset($data['points']) ? $data['points'] : '???'), '
', (isset($actualTotal) ? '<span title="Actual Total" style="padding:0px 3px 0px 3px;">[' .  $actualTotal . ']</span>' : ''), '
</td>
<td>
', (isset($data['points']) ? '<span style="color:green;">On Record' : '<span style="color:red;">No Data'), '</span>
</td>
<td>&nbsp;</td>
</tr>
</table>
</div>
';
}
elseif (stripos($week_final['code'], 'PRE') !== false)
echo 'Preseason games still in effect.';
else
echo 'No data at this time.';

/* Current url */
function currentPageNflPickem($pageURL = 'http://')
{
if (!empty($_SERVER["HTTPS"]))
$pageURL = "https://";

if ($_SERVER["SERVER_PORT"] != "80")
$pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
else
$pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];

return $pageURL;
}

function getInt($str)
{
preg_match("/([0-9]+[\.,]?)+/",$str,$matches);
return $matches[0];
}

/* Check NFL Table */
function checkNflTable()
{
global $smcFunc;

$smcFunc['db_create_table']('{db_prefix}nfl_tiebreakers',
array(
array(
'name' => 'week',
'type' => 'int',
'size' => 10,
'null' => false,
'unsigned' => true,
'auto' => false
),
array(
'name' => 'id_member',
'type' => 'int',
'size' => 10,
'null' => false,
'unsigned' => true,
),
array(
'name' => 'logged',
'type' => 'int',
'size' => 10,
'null' => false,
'unsigned' => true,
),
array(
'name' => 'points',
'type' => 'int',
'size' => 10,
'null' => false,
'unsigned' => true,
),
array(
'name' => 'home',
'type' => 'varchar',
'size' => 255,
'null' => false,
'unsigned' => true,
),
array(
'name' => 'away',
'type' => 'varchar',
'size' => 255,
'null' => false,
'unsigned' => true,
),
array(
'name' => 'picks',
'type' => 'varchar',
'size' => 255,
'null' => false,
'unsigned' => true,
),
),
array(
array(
'type' => 'primary',
'columns' => array('week')
),
),
array(),
'ignore'
);

$smcFunc['db_add_column']('{db_prefix}nfl_tiebreakers',
array(
'name' => 'picks',
'type' => 'varchar',
'size' => 255,
'null' => false,
'unsigned' => true,
),
array(),
'ignore',
'fatal'
);

return;
}


I'm not 100% positive regarding how that nfl.com API works atm since I have never used it before.
What I mean is that I may have to change the code for when the regular season is starting.
I will keep an eye on it though.

That will let your users log their tie-breaker point total for the last game (ususally a Monday nighter) where the cutoff is the second game of the weekly schedule start time.  The JSON parse of the NFL.com API should have the correct match-up for you.
Title: Re: Pickems help
Post by: Fog on August 28, 2014, 08:59:50 PM
I have it in a Simple Portal PHP Block and looks fine...now I just need an input field and create a DB
Title: Re: Pickems help
Post by: Fog on August 28, 2014, 11:08:35 PM
UD, here's the files for the game I'm using with my members.

It's a stand alone site right now

http://www.ngsforums.com/ngspickems/index.php

Since there is no tiebreaker with the "phppickem-master" zip

Our members are asking if we could come up with one...

I seek your help.

You're the master....

If you tinker with this game, I have a sql file I can send you for the 2014 schedule.
Title: Re: Pickems help
Post by: Fog on August 29, 2014, 01:50:38 AM
I see an input box now..

I'll get you a screen shot tomorrow.
Title: Re: Pickems help
Post by: Chen Zhen on August 29, 2014, 11:13:54 AM
The block code has been edited.
The cut-off for editing the tie breaker is Friday evening of each week and the tie breaker game is the last one for the week.
It will display the score of the final game if it is completed.
A way of letting the admin display the user picks for all or specific week is pending (later today perhaps).
The example still shows an allowable edit for this week because it is a pre-season schedule that was entirely on Thursday whereas the regular season should not work like that (cutoff Fridays).

So you want this for something outside of SMF or is this being displayed on your site whereas I can edit your file to load the SMF infrastructure (SSI.php) ??  I will look at this file later today.
Title: Re: Pickems help
Post by: Fog on August 29, 2014, 10:19:29 PM
What I'd like to do is have the tie breaker on SMF in the form of a block or page or a package.

This way we retain traffic that we may lose if the tie breaker was displayed on the stand alone game.

Think about this too...

Can we reward someone shop money or battle money?  I have SA Shop up and running and I'm offering NFL Baseball Caps for 5000 Shop Dollars.

So say each week we had each member input a int that reflects what the total points scored in that game for that given week.  In theory nobody would be able to see what others picked.  Then after the game is played it would display the results of who got the closest and reward them a certain amount of Shop Money and or Battle Money.

This could be a game outside of the Stand Alone Game of Pickems I found but we want to use it in a fashion so if we have a tie on the weekly picks we could fall back to who won the tiebreaker.

I don't know if I told you this, VBullentin has that Pickems Game that I have on a zip as a package for their boards.


Title: Re: Pickems help
Post by: Chen Zhen on September 01, 2014, 03:32:11 AM
I did not bother looking at that package you uploaded as of yet.
Instead I started developing my own application made specifically for SMF.
Right now it still needs a lot of work which I am going to have to do this week prior to the start of the regular season.
It will require testing once the regular season starts which you are more than welcome to volunteer.
Unfortunately because it requires testing during the NFL season to work out all issues it will not be ready to use as a stable package.

  However I will update the post in this thread (http://www.web-develop.ca/index.php?topic=60.msg901#msg901) with a block code that should allow your users to record the tie breaker.
I still have not put in a routine to let Admin look over the user entries since I have been working on the other dev project.
Hopefully I will have time to do that for you tomorrow.

Regards.
Title: Re: Pickems help
Post by: Fog on September 01, 2014, 10:54:41 AM
Let me know how I can help....

Thanks UD
Title: Re: Pickems help
Post by: Fog on September 01, 2014, 04:51:51 PM
This is what I see so far...

Here's a link to the page I'm testing it on:

http://ngsforums.com/forums/index.php?page=page2418

Title: Re: Pickems help
Post by: Fog on September 01, 2014, 08:16:25 PM
Things I would include:

Have to register for the game each season.

Reward players so they can spend it in Shop or playing Battle.

Auto Scoring.
Title: Re: Pickems help
Post by: Chen Zhen on September 03, 2014, 04:17:33 PM
Prior to adding any way of having it interact with other mods I think it will be best to get the game itself working properly.

Here is a test page:
http://www.web-develop.ca/index.php?page=nfl_pool

Currently the user stats part is not completed.
It also needs some other functions added to it but it is a decent start.





Fog,

  Try out the newer code from THIS POST (http://www.web-develop.ca/index.php?topic=60.msg901#msg901) again.
It should allow user input now (up until Sunday at 1pm).
Title: Re: Pickems help
Post by: Fog on September 03, 2014, 09:38:03 PM
The dates seem to be off a week.

It appears that I can't pick games

But I can see where I've been able to login my tie breaker.

Title: Re: Pickems help
Post by: Chen Zhen on September 04, 2014, 01:09:38 AM
I redid the time calculations so that the array containing part of the schedule (last game of each week) now contains the actual start times of the initial games and the final game.
It should work properly now, please test it.

Here is a copy of the code thus far which can be entered into a PHP block or page:
The array is set to ignore Thursday games so that users have more time to enter their picks.
Currently this can be changed manually since it is a page/block format.
When I change it to a mod then I will allow admin options for it.

Admin Mode allows actually setting the favorite and spreads whereas Game Mode allows the admin to play by making picks like other users.


// NFL ~ Current week - last game as tie breaker
// last updated: Sep 07 9:30pm ~ 2014
global $user_info, $scripturl, $smcFunc, $sourcedir, $context, $modSettings, $settings, $txt;
require_once($sourcedir . '/Subs-Package.php');
db_extend('packages');

if (empty($modSettings['nfl_installed']))
installNflTables();

$lastGamesArray = nfl_gameYear();
$feed = 'http://www.nfl.com/liveupdate/scorestrip/scorestrip.json';
$json = fetch_web_data($feed) ? fetch_web_data(utf8_encode($feed)) : false;
$json = preg_replace(array('~,,~', '~,,~', '~,,~'), array(',"",', ',"",', ',"",'), $json);
$html = json_decode($json, true);
$html = !empty($html['ss']) ? $html['ss'] : array();
$nfl_games = array();
$data = array();
$gameCount = 0;
$gameData = array('day', 'time', 'type', 'a', 'away', 'away_score', 'home', 'home_score', 'b', 'c', 'id', 'd', 'code', 'year');
$currentPage = currentPageNflPickem();
list($userName, $userNow, $picks, $user_picks, $weekArray, $spreads, $games, $nfl_pick) = array('Invalid User ID', 'Invalid User Id', array(), array(), array(), '', '', 0);

if (!empty($html))
{
$checkWeek = !empty($html[0]['12']) ? getInt($html[0]['12']) : 1;
$_SESSION['nfl_otherUser'] = !empty($_SESSION['nfl_otherUser']) ? (int)$_SESSION['nfl_otherUser'] : $user_info['id'];
$user = !empty($_REQUEST['member']) ? (int)$_REQUEST['member'] : ($_SESSION['nfl_otherUser'] != $user_info['id'] ? $_SESSION['nfl_otherUser'] : $user_info['id']);
$_SESSION['nfl_otherUser'] = $user;
$allowedEdit = $user == $user_info['id'] || $user_info['is_admin'] ? true : false;
$currentPage = stripos($currentPage, 'member=' . $user) === false ? $currentPage .= ';member=' . $user: $currentPage;
$placement = $lastGamesArray[$checkWeek][2];
$cutoff = $lastGamesArray[$checkWeek][$placement+4];
$gameCutOff = !empty($checkWeek) ? $lastGamesArray[$checkWeek][2] : 1;
$allowedView = time() - $cutoff == abs(time() - $cutoff) || $user_info['is_admin'] ? true : false;
$error = !empty($_REQUEST['error']) ? $_REQUEST['error'] : false;
$original = $html;
$context['nfl_mode'] = '';

if ((!empty($gameCutOff)) && count($html) > $gameCutOff)
{
for ($i=0; $i<$gameCutOff; $i++)
array_shift($html);
}

foreach ($html as $key => $game)
{
for ($i=0; $i <=13; $i++)
$nfl_games[$gameCount][$gameData[$i]] = !empty($game[$i]) ? $game[$i] : '';

$gameCount++;
}
$week_final = $nfl_games[count($nfl_games) - 1];

$actualTotal = (is_numeric($week_final['away_score']) || is_numeric($week_final['home_score'])) ? (int)$week_final['home_score'] + (int)$week_final['away_score'] : '??';
date_default_timezone_set('EST');
$myTime = time();
$time = $lastGamesArray[$checkWeek][3];
$displayCutOff = date('D M d h:iA', $cutoff) . ' EST';
$displayTime = date('D M d h:iA', $time) . ' EST';
$notAllowed = time() - $cutoff >= 0 ? true : false;
$currentWeekApi = getInt($week_final['code']);
$currentMatchUp = $lastGamesArray[$checkWeek];
$confirm =  (in_array($week_final['home'], $currentMatchUp) && in_array($week_final['away'], $currentMatchUp)) ? true : false;
$checkQueryStatus = $user_info['is_admin'] || $notAllowed ? true : false;

if (isset($_REQUEST['NflMember']) && isset($_REQUEST['submit']) && $checkQueryStatus)
{
$queryName = $smcFunc['htmlspecialchars']($_REQUEST['NflMember']);
$result =  $smcFunc['db_query']('', '
SELECT id_member, real_name, member_name
FROM {db_prefix}members
WHERE real_name = {string:member}
LIMIT 1',
array(
'member' => $smcFunc['htmltrim']($queryName),
)
);

while ($row = $smcFunc['db_fetch_assoc']($result))
{
list($_SESSION['nfl_otherUser'], $user) = array($row['id_member'], $row['id_member']);
$userName = $row['real_name'];
$userNow = !empty($row['real_name']) ? 'Editing week ' . $checkWeek . ' picks for ' . $row['real_name'] : (!empty($row['member_name']) ? $row['member_name'] : 'Invalid User ID');
}

$smcFunc['db_free_result']($result);

}
elseif ($user != $user_info['id'])
{
$result =  $smcFunc['db_query']('', '
SELECT id_member, real_name, member_name
FROM {db_prefix}members
WHERE id_member = {int:member}
LIMIT 1',
array(
'member' => $user,
)
);

while ($row = $smcFunc['db_fetch_assoc']($result))
{
list($_SESSION['nfl_otherUser'], $user) = array($row['id_member'], $row['id_member']);
$userName = $row['real_name'];
$userNow = !empty($row['real_name']) ? 'Editing week ' . $checkWeek . ' picks for ' . $row['real_name'] : (!empty($row['member_name']) ? $row['member_name'] : 'Invalid User ID');
}

$smcFunc['db_free_result']($result);
}
else
{
list($_SESSION['nfl_otherUser'], $user) = array($user_info['id'], $user_info['id']);
$userName = $user_info['name'];
$userNow = 'Editing week ' . $checkWeek . ' picks for ' . $user_info['name'];
}
}

if ((!empty($html)) && !$notAllowed && $confirm && stripos($week_final['code'], 'PRE') === false && $allowedEdit)
{
if (isset($_REQUEST['admin']))
$_SESSION['nfl_admin'] = !empty($_SESSION['nfl_admin']) ? false : true;
if (isset($_REQUEST['stats']))
$_SESSION['nfl_stats'] = !empty($_SESSION['nfl_stats']) ? false : true;

if (!$user_info['is_admin'])
list($_SESSION['nfl_admin'], $_SESSION['nfl_stats']) = array(false, false);

$userNow = !empty($_SESSION['nfl_admin']) ? 'Editing spreads for week ' . $checkWeek : $userNow;
if (isset($_REQUEST['points']) && isset($_REQUEST['submit']) && empty($_SESSION['nfl_admin']) && empty($_SESSION['nfl_stats']))
{
list($_SESSION['nfl_admin'], $_SESSION['nfl_stats']) = array(false, false);
$request = $smcFunc['db_query']('', "
SELECT id_member
FROM {db_prefix}nfl_weekly
WHERE id_member = {int:member}
LIMIT 1",
array('member' => $user)
);

$row = $smcFunc['db_fetch_row']($request);
for ($i=1; $i <=17; $i++)
$weekArray['week' . $i] = !empty($row['week' . $i]) ? $row['week' . $i] : '';

$smcFunc['db_free_result']($request);

$current = !empty($weekArray['week' . $checkWeek]) ? array_pop(explode('_', $weekArray['week' . $checkWeek])) : array();
$current = implode('_', $current);
for ($i=1; $i< count($nfl_games)+1; $i++)
$games .= !empty($_REQUEST['game_' . ($i-1)]) ? $_REQUEST['game_' . ($i-1)] . '_': (!empty($current) ? $current . '_' : '');

$games .= !empty($_REQUEST['points']) ? abs((int)$_REQUEST['points']) : '';
$weekArray['week' . $checkWeek] = trim($games, '_');

$smcFunc['db_query']('', "
DELETE FROM {db_prefix}nfl_weekly
WHERE id_member = {int:member}",
array('member' => $user, 'current' => $checkWeek)
);

$smcFunc['db_insert']('insert', "
{db_prefix}nfl_weekly",
array(
'id_member' => 'int',
'week1' => 'string',
'week2' => 'string',
'week3' => 'string',
'week4' => 'string',
'week5' => 'string',
'week6' => 'string',
'week7' => 'string',
'week8' => 'string',
'week9' => 'string',
'week10' => 'string',
'week11' => 'string',
'week12' => 'string',
'week13' => 'string',
'week14' => 'string',
'week15' => 'string',
'week16' => 'string',
'week17' => 'string'
),
array(
$user,
(!empty($weekArray['week1']) ? $weekArray['week1'] : ''),
(!empty($weekArray['week2']) ? $weekArray['week2'] : ''),
(!empty($weekArray['week3']) ? $weekArray['week3'] : ''),
(!empty($weekArray['week4']) ? $weekArray['week4'] : ''),
(!empty($weekArray['week5']) ? $weekArray['week5'] : ''),
(!empty($weekArray['week6']) ? $weekArray['week6'] : ''),
(!empty($weekArray['week7']) ? $weekArray['week7'] : ''),
(!empty($weekArray['week8']) ? $weekArray['week8'] : ''),
(!empty($weekArray['week9']) ? $weekArray['week9'] : ''),
(!empty($weekArray['week10']) ? $weekArray['week10'] : ''),
(!empty($weekArray['week11']) ? $weekArray['week11'] : ''),
(!empty($weekArray['week12']) ? $weekArray['week12'] : ''),
(!empty($weekArray['week13']) ? $weekArray['week13'] : ''),
(!empty($weekArray['week14']) ? $weekArray['week14'] : ''),
(!empty($weekArray['week15']) ? $weekArray['week15'] : ''),
(!empty($weekArray['week16']) ? $weekArray['week16'] : ''),
(!empty($weekArray['week17']) ? $weekArray['week17'] : '')
),
array('id_member')
);

}
elseif ($user_info['is_admin'] && isset($_REQUEST['submit']) && !empty($_SESSION['nfl_admin']) && empty($_SESSION['nfl_stats']))
{
$_SESSION['nfl_stats'] = false;
for ($i=0; $i<count($html); $i++)
{
$team = !empty($_REQUEST['game_' . $i]) ? $_REQUEST['game_' . $i] : $html[$i+1]['home'];
$spreads .= $team . (!empty($_REQUEST['spread_' . $i]) ? $_REQUEST['spread_' . $i] : '0.5') . '_';

}

$spreads = trim($spreads, '_');
$logged = time();

$smcFunc['db_query']('', "
DELETE FROM {db_prefix}nfl_tiebreakers
WHERE week = {int:week}",
array('week' => $checkWeek)
);

$smcFunc['db_insert']('insert', "
{db_prefix}nfl_tiebreakers",
array(
'week' => 'int',
'logged' => 'int',
'home' => 'string',
'away' => 'string',
'picks' => 'string'
),
array(
$checkWeek,
$logged,
(!empty($week_final['home']) ? $week_final['home'] : ''),
(!empty($week_final['away']) ? $week_final['away'] : ''),
$spreads
),
array('week')
);
}

if ($user_info['is_admin'] && !empty($_SESSION['nfl_stats']))
{
$_SESSION['nfl_stats'] = true;
$_SESSION['nfl_admin'] = false;
nfl_user_stats($currentPage, $checkWeek);
}
else
{
$request = $smcFunc['db_query']('', "
SELECT n.week, w.id_member, n.logged, n.home, n.away, n.picks, {raw:week_num}
FROM {db_prefix}nfl_tiebreakers as n
LEFT JOIN {db_prefix}nfl_weekly as w ON (w.id_member = {int:member})
WHERE week = {int:week}
LIMIT 1",
array('week' => $checkWeek, 'member' => $user, 'week_num' => 'w.week' . $checkWeek)
);

while ($row = $smcFunc['db_fetch_assoc']($request))
{
$data = array(
'week' => !empty($row['week']) ? (int)$row['week'] : 0,
'id_member' => !empty($row['id_member']) ? (int)$row['id_member'] : 0,
'logged' => !empty($row['logged']) ? (int)$row['logged'] : 0,
'home' => !empty($row['home']) ? $row['home'] : '',
'away' => !empty($row['away']) ? $row['away'] : '',
'picks' => !empty($row['picks']) ? $row['picks'] : '',
);

$picks = !empty($row['picks']) ? explode('_', $row['picks']) : array();
$user_picks = !empty($row['week' . $checkWeek]) ? explode('_', $row['week' . $checkWeek]) : array();
$context['nfl_user_points'] = (!empty($user_picks)) ? (int)getInt($user_picks[(count($user_picks) -1)]) : '';
array_pop($user_picks);
}
$smcFunc['db_free_result']($request);

if ((!empty($gameCutOff)) && count($picks) > count($html))
{
for ($i=count($picks); $i>count($html); $i--)
array_shift($picks);
}

if ((!empty($gameCutOff)) && count($user_picks) > count($html))
{
for ($i=count($user_picks); $i>count($html); $i--)
array_shift($user_picks);
}

foreach ($picks as $pickem)
{
$context['spread_' . $nfl_pick] = abs((int)getInt($pickem)) . '.5';
$pickem = trim(str_replace(range(0,9), '', $pickem), '.');
$context['game_' . $nfl_pick] = (!empty($pickem)) && $pickem === trim($nfl_games[$nfl_pick]['home']) ? $nfl_games[$nfl_pick]['home'] : $nfl_games[$nfl_pick]['away'];
$nfl_pick++;
}
$nfl_pick = 0;
foreach ($user_picks as $user_pickem)
{
$context['user_game_' . $nfl_pick] = (!empty($user_pickem)) && $user_pickem === $nfl_games[$nfl_pick]['home'] ? $nfl_games[$nfl_pick]['home'] : $nfl_games[$nfl_pick]['away'];
$nfl_pick++;
}

echo '
<script type="text/javascript"><!-- // --><![CDATA[
function NFL_confirmSubmit()
{
var agree=confirm("Do you confirm this action?");
if (agree)
return true ;
else
return false ;
}
// ]]></script>
<form id="nfl_pick" name="nfl_pick" action="' . $currentPage . '" method="post">
<div class="windowbg">
<div class="cat_bar">
<h3 class="centertext catbg">NFL Pool Weekly Picks</h3>
</div>
<table width="100%">
<tr>
<td class="centertext titlebg" colspan="5">
Week ', (int)$currentWeekApi, '<br />
</td>
</tr>
<tr>
<td class="centertext titlebg" colspan="5">
', $userNow, '<br />
</td>
</tr>
', $user_info['is_admin'] && empty($_SESSION['nfl_admin']) ? '
<tr>
<td class="centertext titlebg" colspan="5">
Game Mode<br />
</td>
</tr>' : ($user_info['is_admin'] && !empty($_SESSION['nfl_admin']) ? '
<tr>
<td class="centertext titlebg" colspan="5">
Admin Mode<br />
</td>
</tr>' : ''), '
<tr>
<td class="centertext" style="padding:8px 8px 0px 8px;">AWAY</td>
<td class="centertext" style="padding:8px 8px 0px 8px;">HOME</td>
<td class="centertext" style="padding:8px 8px 0px 8px;">DATE</td>
<td class="centertext" style="padding:8px 8px 0px 8px;">Point Spread</td>
<td class="centertext" style="padding:8px 8px 0px 8px;">Select Team</td>
</tr>
<tr>
<td colspan="5">&nbsp;</td>
</tr>';
foreach ($nfl_games as $key => $game)
{
$gameTime = date('D M d h:iA', (strtotime($game['day'] . ', ' . $game['time'] . 'pm'))) . ' EST';
$windowbg = (!empty($windowbg)) && $windowbg === 'windowbg' ? 'windowbg2' : 'windowbg';
echo '
<tr class="' . $windowbg . '">
<td style="padding:8px 8px 0px 8px;" ' . ((!empty($context['game_' . $key])) && $context['game_' . $key] === $game['away'] ? 'class="alert catbg2 centertext"' : 'class="centertext"') . '>', $game['away'], '</td>
<td style="padding:8px 8px 0px 8px;" ' . ((!empty($context['game_' . $key])) && $context['game_' . $key] === $game['home'] ? 'class="alert catbg2 centertext"' : 'class="centertext"') . '>', $game['home'], '</td>
<td class="centertext" style="padding:8px 8px 0px 8px;">', $gameTime, '</td>
<td class="centertext" style="padding:8px 8px 0px 8px;">
', !empty($_SESSION['nfl_admin']) ? '
<input name="spread_' . $key . '" type="number" maxlength="4" size="3" min="0" max="999" step="0.5" value="' . (isset($context['spread_' . $key]) ? abs((int)$context['spread_' . $key]) + 0.5 : 0.5) . '" />' : '
<span>' . (isset($context['spread_' . $key]) ? abs((int)$context['spread_' . $key]) + 0.5 : 0.5) . '</span>', '
</td>
<td class="centertext" style="padding:8px 8px 0px 8px;">
<select name="game_' . $key . '">
<option ', ($user_info['is_guest'] ? 'disabled ' : ''), 'value="' . $game['away'] . '" ', (empty($_SESSION['nfl_admin']) && !empty($context['user_game_' . $key]) && $context['user_game_' . $key] === $game['away'] ? 'selected' : (!empty($_SESSION['nfl_admin']) && !empty($context['game_' . $key]) && $context['game_' . $key] === $game['away'] ? 'selected' : '')), '>', $game['away'], '</option>
<option ', ($user_info['is_guest'] ? 'disabled ' : ''), 'value="' . $game['home'] . '" ', (empty($_SESSION['nfl_admin']) && !empty($context['user_game_' . $key]) && $context['user_game_' . $key] === $game['home'] ? 'selected' : (!empty($_SESSION['nfl_admin']) && !empty($context['game_' . $key]) && $context['game_' . $key] === $game['home'] ? 'selected' : '')), '>', $game['home'], '</option>
</select>
</td>
</tr>';
}
echo '
</table>
<div class="windowbg"><br /></div>
<table width="100%">
<tr>
<td class="centertext titlebg" colspan="7">
Tie Breaker<br />
</td>
</tr>
<tr style="padding:3px;">
<td style="padding:0px 8px 0px 8px;">Cut-off Date</td>
<td style="padding:0px 8px 0px 8px;">Game Date</td>
<td style="padding:0px 8px 0px 8px;">Away</td>
<td style="padding:0px 8px 0px 8px;">Home</td>
<td style="padding:0px 8px 0px 8px;">Username</td>
<td style="padding:0px 8px 0px 8px;">Points Total</td>
<td colspan="2">Status</td>
</tr>
<tr style="padding:3px;">
<td style="padding:0px 8px 0px 8px;">', $displayCutOff, '</td>
<td style="padding:0px 8px 0px 8px;">', $displayTime, '</td>
<td style="padding:0px 8px 0px 8px;">', $week_final['away'], '</td>
<td style="padding:0px 8px 0px 8px;">', $week_final['home'], '</td>
<td style="padding:0px 8px 0px 8px;"><a href="' . $scripturl. '?action=profile;u=' . $user . '">', $userName, '</a></td>
<td style="padding:0px 8px 0px 8px;" class="left">
<input ', (!empty($_SESSION['nfl_admin']) ? 'disabled ' : ''), 'name="points" type="number" maxlength="4" size="3" min="0" max="999" value="', (isset($context['nfl_user_points']) ? (int)$context['nfl_user_points'] : 0), '" />
', (isset($actualTotal) ? '<span title="Actual Total" style="padding:0px 3px 0px 3px;">[' .  $actualTotal . ']</span>' : ''), '
</td>
<td>
', (isset($context['nfl_user_points']) && empty($_SESSION['nfl_admin']) && empty($_SESSION['nfl_stats']) ? '<span style="color:green;">SAVED' : (empty($_SESSION['nfl_admin']) && empty($_SESSION['nfl_stats']) ? '<span style="color:red;">Pending' : (!empty($_SESSION['nfl_stats']) ? 'Stats Mode' : 'Admin Mode'))), '</span>
</td>
</tr>
<tr>
<td style="border:0px;" colspan="7"><hr /><br /></td>
</tr>
<tr>
<td colspan="7">
', (!empty($error) ? '<span class="error">Warning: You are not permitted to view other user picks until after the cut-off time.</span><br /><br />' : '&nbsp;'), '
</td>
</tr>
<tr ', ($user_info['is_guest'] ? 'style="display: none;"' : ''),'>
<td>
<input class="submit" type="submit" name="submit" value="Submit" onclick="var confirm = NFL_confirmSubmit(); if (confirm) {this.form.submit();} else {return false;}" />
</td>
<td colspan="4">
<div class="content">
<strong>Search Member:</strong>
<input type="text" name="NflMember" id="NflMember" value="" class="input_text" ' . (!empty($_SESSION['nfl_admin']) ? 'disabled ' : '') . '/>
<div id="NflQueryUserContainer"></div>
</div>
</td>
', empty($_SESSION['nfl_stats']) && $user_info['is_admin'] ? '
<td>
<input class="submit" type="submit" name="stats" value="View Overall" />
</td>' : (!empty($_SESSION['nfl_stats']) && $user_info['is_admin'] ? '
<td>
<input class="submit" type="submit" name="stats" value="Exit Overall" />
</td>' : '
<td>
&nbsp;
</td>'), '
', empty($_SESSION['nfl_admin']) && $user_info['is_admin'] ? '
<td>
<input class="submit" type="submit" name="admin" value="Admin Mode" />
</td>' : (!empty($_SESSION['nfl_admin']) && $user_info['is_admin'] ? '
<td>
<input class="submit" type="submit" name="admin" value="Game Mode" />
</td>' : '
<td>
&nbsp;
</td>'), '
</tr>
</table>
</div>
</form>
<script type="text/javascript" src="', $settings['default_theme_url'], '/scripts/suggest.js?fin20"></script>
<script type="text/javascript"><!-- // --><![CDATA[
var oAddMemberSuggest = new smc_AutoSuggest({
sSelf: \'oAddMemberSuggest\',
sSessionId: \'', $context['session_id'], '\',
sSessionVar: \'', $context['session_var'], '\',
sSuggestId: \'to_suggest\',
sControlId: \'NflMember\',
sSearchType: \'member\',
sPostName: \'nfl_pick\',
sURLMask: \'', !empty($_REQUEST['page']) ? 'page=' . $smcFunc['htmlspecialchars']($_REQUEST['page']) : (!empty($context['current_action']) ? 'action=' . $context['current_action'] : ''), ';member=%item_id%\',
sTextDeleteItem: \'', $txt['autosuggest_delete_item'], '\',
bItemList: false,
sItemListContainerId: \'NflQueryUserContainer\'
});
// ]]></script>';
}
}
elseif (!empty($html) && $confirm && stripos($week_final['code'], 'PRE') === false && $allowedView)
{
if (isset($_REQUEST['stats']))
$_SESSION['nfl_stats'] = !empty($_SESSION['nfl_stats']) ? false : true;

if (!$user_info['is_admin'])
list($_SESSION['nfl_admin'], $_SESSION['nfl_stats']) = array(false, false);
$userNow = !empty($_SESSION['nfl_admin']) ? 'Viewing spreads for week ' . $checkWeek : $userNow;

if ($user_info['is_admin'] && !empty($_SESSION['nfl_stats']))
{
$_SESSION['nfl_stats'] = true;
$_SESSION['nfl_admin'] = false;
nfl_user_stats($currentPage, $checkWeek);
}
else
{
list($_SESSION['nfl_admin'], $_SESSION['nfl_stats']) = array(false, false);
$request = $smcFunc['db_query']('', "
SELECT n.week, w.id_member, n.logged, n.home, n.away, n.picks, w.{raw:week_num}
FROM {db_prefix}nfl_tiebreakers as n
LEFT JOIN {db_prefix}nfl_weekly as w ON (w.id_member = {int:member})
WHERE week = {int:week}
LIMIT 1",
array('week' => $checkWeek, 'member' => $user, 'week_num' => 'week' . (string)$checkWeek)
);

while ($row = $smcFunc['db_fetch_assoc']($request))
{
$data = array(
'week' => !empty($row['week']) ? (int)$row['week'] : 0,
'id_member' => !empty($row['id_member']) ? (int)$row['id_member'] : 0,
'logged' => !empty($row['logged']) ? (int)$row['logged'] : 0,
'home' => !empty($row['home']) ? $row['home'] : '',
'away' => !empty($row['away']) ? $row['away'] : '',
'picks' => !empty($row['picks']) ? $row['picks'] : '',
);

$picks = !empty($row['picks']) ? explode('_', $row['picks']) : array();
$user_picks = !empty($row['week' . $checkWeek]) ? explode('_', $row['week' . $checkWeek]) : array();
$context['nfl_user_points'] = (!empty($user_picks)) ? (int)getInt($user_picks[(count($user_picks) -1)]) : '';
array_pop($user_picks);
}
$smcFunc['db_free_result']($request);

if ((!empty($gameCutOff)) && count($picks) > count($html))
{
for ($i=count($picks); $i>count($html); $i--)
array_shift($picks);
}

if ((!empty($gameCutOff)) && count($user_picks) > count($html))
{
for ($i=count($user_picks); $i>count($html); $i--)
array_shift($user_picks);
}

foreach ($picks as $pickem)
{
$context['spread_' . $nfl_pick] = abs((int)getInt($pickem)) . '.5';
$pickem = trim(str_replace(range(0,9), '', $pickem), '.');
$context['game_' . $nfl_pick] = (!empty($pickem)) && $pickem === $nfl_games[$nfl_pick]['home'] ? $nfl_games[$nfl_pick]['home'] : $nfl_games[$nfl_pick]['away'];
$nfl_pick++;
}
$nfl_pick = 0;
foreach ($user_picks as $user_pickem)
{
$context['user_game_' . $nfl_pick] = (!empty($user_pickem) && !empty($nfl_games[$nfl_pick]['home'])) && $user_pickem === $nfl_games[$nfl_pick]['home'] ? $nfl_games[$nfl_pick]['home'] : (!empty($nfl_games[$nfl_pick]['away']) ? $nfl_games[$nfl_pick]['away'] : '');
$nfl_pick++;
}

echo '
<script type="text/javascript"><!-- // --><![CDATA[
function NFL_confirmSubmit()
{
var agree=confirm("Do you confirm this action?");
if (agree)
return true ;
else
return false ;
}
// ]]></script>
<div style="display:inline;" class="windowbg">
<div class="cat_bar">
<h3 class="centertext catbg">NFL Pool Weekly Picks</h3>
</div>
<table width="100%">
<tr>
<td class="centertext titlebg" colspan="5">
Week ', (int)$currentWeekApi, '<br />
</td>
</tr>
<tr>
<td class="centertext titlebg" colspan="5">
', $userNow, '<br />
</td>
</tr>
<tr>
<td class="centertext" style="padding:8px 8px 0px 8px;">AWAY</td>
<td class="centertext" style="padding:8px 8px 0px 8px;">HOME</td>
<td class="centertext" style="padding:8px 8px 0px 8px;">DATE</td>
<td class="centertext" style="padding:8px 8px 0px 8px;">Point Spread</td>
<td class="centertext" style="padding:8px 8px 0px 8px;">Your Pick</td>
</tr>
<tr>
<td colspan="5">&nbsp;</td>
</tr>';
foreach ($nfl_games as $key => $game)
{
$gameTime = date('D M d h:iA', (strtotime($game['day'] . ', ' . $game['time'] . 'pm'))) . ' EST';
$windowbg = (!empty($windowbg)) && $windowbg === 'windowbg' ? 'windowbg2' : 'windowbg';
$fu = (!empty($context['game_' . $key]) && !empty($context['user_game_' . $key])) && $context['game_' . $key] !== $context['user_game_' . $key] ? '<span style="float:right;">[U]</span>' : '<span style="float:right;">[F]</span>';
echo '
<tr class="' . $windowbg . '">
<td style="padding:8px 8px 0px 8px;" ' . ((!empty($context['game_' . $key])) && $context['game_' . $key] === $game['away'] ? 'class="alert catbg2 centertext"' : 'class="centertext"') . '>', $game['away'], '</td>
<td style="padding:8px 8px 0px 8px;" ' . ((!empty($context['game_' . $key])) && $context['game_' . $key] === $game['home'] ? 'class="alert catbg2 centertext"' : 'class="centertext"') . '>', $game['home'], '</td>
<td class="centertext" style="padding:8px 8px 0px 8px;">', $gameTime, '</td>
<td class="centertext" style="padding:8px 8px 0px 8px;">', (!empty($context['spread_' . $key]) ? $context['spread_' . $key] : '0.5'), '</td>
<td class="centertext alert" style="padding:8px 8px 0px 8px;">', (!empty($context['user_game_' . $key]) ? $context['user_game_' . $key] . ' ' . $fu: '???'), '</td>
</tr>';
}
echo '
</table>
<div><br /></div>
<table width="100%">
<tr>
<td class="centertext titlebg" colspan="7">
Tie Breaker<br />
</td>
</tr>
<tr style="padding:3px;">
<td style="padding:0px 8px 0px 8px;">Cut-off Date</td>
<td style="padding:0px 8px 0px 8px;">Game Date</td>
<td style="padding:0px 8px 0px 8px;">Away</td>
<td style="padding:0px 8px 0px 8px;">Home</td>
<td style="padding:0px 8px 0px 8px;">Username</td>
<td style="padding:0px 8px 0px 8px;">Points Total</td>
<td colspan="2">Status</td>
</tr>
<tr style="padding:3px;">
<td style="padding:0px 8px 0px 8px;">', $displayCutOff, '</td>
<td style="padding:0px 8px 0px 8px;">', $displayTime, '</td>
<td style="padding:0px 8px 0px 8px;">', $week_final['away'], '</td>
<td style="padding:0px 8px 0px 8px;">', $week_final['home'], '</td>
<td style="padding:0px 8px 0px 8px;"><a href="' . $scripturl. '?action=profile;u=' . $user . '">', $userName, '</a></td>
<td style="padding:0px 8px 0px 8px;" class="left">
', (isset($context['nfl_user_points']) ? $context['nfl_user_points'] : '???'), '
', (isset($actualTotal) ? '<span title="Actual Total" style="padding:0px 3px 0px 3px;">[' .  $actualTotal . ']</span>' : ''), '
</td>
<td>
', (isset($context['nfl_user_points']) ? '<span style="color:green;">SAVED' : '<span style="color:red;">No Data'), '</span>
</td>
<td>&nbsp;</td>
</tr>
<tr>
<td style="border:0px;" colspan="7"><hr /><br /></td>
</tr>
<tr>
<td colspan="7">
', (!empty($error) ? '<span class="error">Warning: You are not permitted to view other user picks until after the cut-off time.</span><br /><br />' : '&nbsp;'), '
</td>
</tr>
</table>
<form id="nfl_pick" name="nfl_pickem" action="' . $currentPage . '" method="post">
<table width="100%">
<tr ', ($user_info['is_guest'] ? 'style="display: none;"' : ''),'>
<td>
<input class="submit" type="submit" name="submit" value="Submit" onclick="var confirm = NFL_confirmSubmit(); if (confirm) {this.form.submit();} else {return false;}" />
</td>
<td colspan="5">
<div class="content">
<strong>Search Member:</strong>
<input type="text" name="NflMember" id="NflMember" value="" class="input_text" ' . (!empty($_SESSION['nfl_admin']) ? 'disabled ' : '') . '/>
<div id="NflQueryUserContainer"></div>
</div>
</td>
', empty($_SESSION['nfl_stats']) && $user_info['is_admin'] ? '
<td>
<input class="submit" type="submit" name="stats" value="Overall" />
</td>' : (!empty($_SESSION['nfl_stats']) && $user_info['is_admin'] ? '
<td>
<input class="submit" type="submit" name="stats" value="Exit Overall" />
</td>' : '
<td>
&nbsp;
</td>'), '
</tr>
</table>
</form>
</div>
<script type="text/javascript" src="', $settings['default_theme_url'], '/scripts/suggest.js?fin20"></script>
<script type="text/javascript"><!-- // --><![CDATA[
var oAddMemberSuggest = new smc_AutoSuggest({
sSelf: \'oAddMemberSuggest\',
sSessionId: \'', $context['session_id'], '\',
sSessionVar: \'', $context['session_var'], '\',
sSuggestId: \'to_suggest\',
sControlId: \'NflMember\',
sSearchType: \'member\',
sPostName: \'nfl_pick\',
sURLMask: \'', !empty($_REQUEST['page']) ? 'page=' . $smcFunc['htmlspecialchars']($_REQUEST['page']) : (!empty($context['current_action']) ? 'action=' . $context['current_action'] : ''), ';member=%item_id%\',
sTextDeleteItem: \'', $txt['autosuggest_delete_item'], '\',
bItemList: false,
sItemListContainerId: \'NflQueryUserContainer\'
});
// ]]></script>
';
}
}
elseif (!empty($html) && $confirm && stripos($week_final['code'], 'PRE') === false && !$allowedView)
{
$currentPage = currentPageNflPickem() . ';error=1;member=' . $user_info['id'];
list($_SESSION['nfl_stats'], $_REQUEST['exit_stats']) = array(false, false);
header('Location: ' . $currentPage);
die();
}
elseif ((!empty($week_final)) && stripos($week_final['code'], 'PRE') !== false)
echo 'Preseason games still in effect.';
else
echo 'No data at this time.';

/* Current url */
function currentPageNflPickem($pageURL = 'http://')
{
global $context, $modSettings, $scripturl;

if (!empty($_SERVER["HTTPS"]))
$pageURL = "https://";

if ($_SERVER["SERVER_PORT"] != "80")
$pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
else
$pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];

$urlArray = explode('/', $pageURL);

return $pageURL;
}

function getInt($str)
{
preg_match("/([0-9]+[\.,]?)+/",$str,$matches);
return !empty($matches[0]) ? $matches[0] : 0;
}

/* Create NFL Tables */
function installNflTables()
{
global $smcFunc, $modSettings;

$smcFunc['db_create_table']('{db_prefix}nfl_tiebreakers',
array(
array(
'name' => 'week',
'type' => 'int',
'size' => 10,
'null' => false,
'unsigned' => true,
'auto' => false
),
array(
'name' => 'logged',
'type' => 'int',
'size' => 10,
'null' => false,
'unsigned' => true,
),
array(
'name' => 'home',
'type' => 'varchar',
'size' => 255,
'null' => false,
'unsigned' => true,
),
array(
'name' => 'away',
'type' => 'varchar',
'size' => 255,
'null' => false,
'unsigned' => true,
),
array(
'name' => 'picks',
'type' => 'varchar',
'size' => 255,
'null' => false,
'unsigned' => true,
),
),
array(
array(
'type' => 'primary',
'columns' => array('week')
),
),
array(),
'ignore'
);

$smcFunc['db_create_table']('{db_prefix}nfl_weekly',
array(
array(
'name' => 'id_member',
'type' => 'int',
'size' => 10,
'null' => false,
'unsigned' => true,
),
),
array(
array(
'type' => 'primary',
'columns' => array('id_member')
),
),
array(),
'ignore'
);

for ($i=1; $i<=17; $i++)
$smcFunc['db_add_column']('{db_prefix}nfl_weekly',
array(
'name' => 'week' . (string)$i,
'type' => 'varchar',
'size' => 255,
'null' => false,
'unsigned' => true,
),
array(),
'ignore',
'fatal'
);

$smcFunc['db_add_column']('{db_prefix}nfl_tiebreakers',
array(
'name' => 'picks',
'type' => 'varchar',
'size' => 255,
'null' => false,
'unsigned' => true,
),
array(),
'ignore',
'fatal'
);

// set the install flag
$setArray['nfl_installed'] = 1;
$modSettings['nfl_installed'] = 1;
updateSettings($setArray);

return;
}

function nfl_gameYear()
{
// 2014 weekly confirmation
$lastGamesArray = array(
0 => array('1', '1', '1', '1', '1', '1'),
1 => array('SD', 'ARI', '1', '1410232800', '1409880600', '1410112800'),
2 => array('PHI', 'IND', '1', '1410831000', '1410485100', '1410717600'),
3 => array('CHI', 'NYJ', '1', '1411435800', '1411089900', '1411322400'),
4 => array('NE', 'KC', '1', '1412040600', '1411694700', '1411927200'),
5 => array('SEA', 'WSH', '1', '1412645400', '1412299500', '1412532000'),
6 => array('SF', 'STL', '1', '1413250200', '1412904300', '1413136800'),
7 => array('HOU', 'PIT', '1', '1413855000', '1413509100', '1413741600'),
8 => array('WSH', 'DAL', '1', '1414459800', '1414113900', '1414346400'),
9 => array('IND', 'NYG', '1', '1415064600', '1414718700', '1414951200'),
10 => array('CAR', 'PHI', '1', '1415669400', '1415323500', '1415556000'),
11 => array('PIT', 'TEN', '1', '1416274200', '1415928300', '1416160800'),
12 => array('BAL', 'NO', '1', '1416879000', '1416533100', '1416765600'),
13 => array('MIA', 'NYJ', '3', '1417483800', '1417109100', '1417123800', '1417138200', '1417370400'),
14 => array('ATL', 'GB', '1', '1418088600', '1417742700', '1417975200'),
15 => array('NO', 'CHI', '1', '1418693400', '1418347500', '1418580000'),
16 => array('DEN', 'CIN', '1', '1419298200', '1418952300', '1419098400'),
17 => array('STL', 'SEA', '0', '1419801900', '1419789600', '1419789600'),
);

return $lastGamesArray;
}

function NFL_pool_pagination($content, $redirect, $count = 10)
{
/* PHP pagination - max 7 visible integers and 6 periods (all links) - current page encircled with square brackets
* This php pagination code was developed by Underdog copyright 2013, 2014
* http://web-develop.ca
* Licensed under the GNU Public License: http://www.gnu.org/licenses/gpl.html
*/

// This particular function is only used when opting an entire table else it is not necessary
global $context, $scripturl;

/*  Set the $context variables for the display template  */
$context['current_count'] = count($content);
$context['current_pages'] = ((int)($context['current_count'] / $count)) + 1;
$redirect = !empty($redirect) ? $redirect : $scripturl;
$maxPages = 1;

if (count($content) <= $count || $count < 2)
{
$context['current_pages'] = 0;
return $content;
}

// Did they enter an invalid page via the url?
if ((int)($context['current_count']/$count) == $context['current_count']/$count)
$maxPages = $context['current_count']/$count;
elseif($context['current_count'] %$count != 0)
$maxPages += ($context['current_count'] - ($context['current_count'] % $count)) / $count;

if ((int)$context['current_page']+1 > $maxPages)
redirectexit($redirect . 'current_page=' . $maxPages . ';#page_top');
elseif ((int)$context['current_page'] < 0)
redirectexit($redirect . 'current_page=1;#page_top');

// Now calculate the part of the array to display
if (($context['current_count'] / $count) == (int)($context['current_count'] / $count))
$context['current_pages'] = ($context['current_count'] / $count);

$context['current_showResults'] = array(((int)$context['current_page'] * $count), (((int)$context['current_page'] + 1) * $count) - 1);

if ((int)$context['current_page']+1 == (int)$context['current_pages'])
    $context['current_showResults'][1] = count($content);
else
    $context['current_showResults'][1] = (int)$context['current_page']*$count + ($count-1);

foreach($content as $key => $var)
{
$counter = array_search($key , array_keys($content));
if ($counter >= (int)$context['current_showResults'][0] && $counter <= (int)$context['current_showResults'][1])
$new_content[$key] = $var;
}

if (!empty($new_content))
$context['current_showResults'][1] = ((int)$context['current_page']*$count) + count($new_content);
else
$new_content = $content;

return $new_content;
}

function NFL_pool_pages($lang, $anchor, $link, $pages, $sort=false, $order=false)
{
/* PHP pagination - max 7 visible integers and 6 periods (all links) - current page encircled with square brackets
* This php pagination code was developed by Underdog copyright 2013, 2014
* http://web-develop.ca
* Licensed under the GNU Public License: http://www.gnu.org/licenses/gpl.html
*/
global $context;

$pageCount = 1;
$display = array('page' => false, 'pages' => '0');
$page = !empty($context['current_page']) ? (int)$context['current_page'] : 0;
$display['pages'] = !empty($pages) ? (int)$pages : 1;

if ($display['pages'] > 1)
{
    $display['page'] =  '
    <script type="text/javascript"><!-- // --><![CDATA[
function changeColor(s)
{
document.getElementById("link"+s).style.color = "red";
}
function changeColorBack(s)
{
document.getElementById("link"+s).style.color = "blue";
}
    // ]]></script>
    <span style="text-align:center;position:relative;width:99%;display:inline-block;">
' . $lang . '<br />';

    while ($pageCount < (int)$display['pages']+1)
    {
$current_page = (int)$page+1;
$total = (int)$display['pages'];

if ($pageCount == 1 || $pageCount == $total || $pageCount == $current_page || $pageCount == $current_page+1 ||
    $pageCount == $current_page+2 || $pageCount == $current_page-1 || $pageCount == $current_page-2)
{
    if ((int)$pageCount == (int)$page+1)
$display['page'] .= '
<a onclick="this.href=\'javascript: void(0)\';" onmouseout="changeColor('. $pageCount . ')" onmouseover="changeColorBack(' . $pageCount . ')" id="link' . $pageCount . '" style="color:red;text-decoration:none;" href="'. $link . ';current_page=' . $pageCount . ';' . $sort . $order . $anchor . '">[' . $pageCount . ']</a> ';
    else
$display['page'] .= '
<a onmouseout="changeColorBack(' . $pageCount . ')" onmouseover="changeColor(' . $pageCount . ')" id="link' . $pageCount . '" style="color:blue;text-decoration:none;" href="' . $link . ';current_page=' . $pageCount . ';' . $sort . $order . $anchor . '">' . $pageCount . '</a> ';
}
elseif ($pageCount < $current_page-2 && $pageCount > $current_page-6)
$display['page'] .= '
<a onmouseout="changeColorBack(' . $pageCount . ')" onmouseover="changeColor(' . $pageCount . ')" id="link' . $pageCount . '" style="color:blue;text-decoration:none;" href="' . $link . ';current_page=' . $pageCount . ';' . $sort . $order . $anchor . '">.</a> ';
elseif ($pageCount > $current_page+2 && $pageCount < $current_page+6)
$display['page'] .= '
<a onmouseout="changeColorBack(' . $pageCount . ')" onmouseover="changeColor(' . $pageCount . ')" id="link' . $pageCount . '" style="color:blue;text-decoration:none;" href="' . $link . ';current_page=' . $pageCount . ';' . $sort . $order . $anchor . '">.</a> ';

$pageCount++;
    }

    $display['page'] .= '
    </span>';
}

return $display;
}

function nfl_user_stats($currentPage, $checkWeek)
{
global $user_info, $scripturl, $smcFunc;
$nfl_pick = 0;

if (isset($_REQUEST['exit_stats']))
{
list($_SESSION['nfl_stats'], $_REQUEST['exit_stats']) = array(false, false);
header('Location: ' . $currentPage);
die();
}

$timeAlotted = !$user_info['is_admin'] ? time() : time() + 691200;
$member = isset($_REQUEST['nfl_member']) ? abs((int)$_REQUEST['nfl_member']) : 0;
$week = isset($_REQUEST['nfl_week']) ? abs((int)$_REQUEST['nfl_week']) : $checkWeek;
$context['current_page'] = !empty($context['current_page']) ? (int)$context['current_page'] : 1;
$context['current_page'] = (!empty($_REQUEST['current_page']) ? (int)$_REQUEST['current_page'] : $context['current_page']) -1;
$limit = ($context['current_page'] + 1) * 10;
$spreads = array();

$request = $smcFunc['db_query']('', "
SELECT week, picks
FROM {db_prefix}nfl_tiebreakers
ORDER BY week",
array()
);
while ($row = $smcFunc['db_fetch_assoc']($request))
{
$queryWeek = !empty($row['week']) ? (int)$row['week'] : 0;
$spreads['week' . $queryWeek] = !empty($row['picks']) ? $row['picks'] : array();
}
$smcFunc['db_free_result']($request);

foreach ($spreads as $weekCount => $pickem)
{
$weekFavs = explode('_', $pickem);
$weekSpreads[$weekCount] = array();
foreach ($weekFavs as $weekFav)
{
$spread = abs((int)getInt($pickem)) . '.5';
$team = trim(str_replace(range(0,9), '', $pickem), '.');
$weekSpreads[$weekCount][][$team] = $spread;
}

}

if ($member < 1)
{
$request = $smcFunc['db_query']('', "
SELECT u.id_member
FROM {db_prefix}nfl_weekly AS u
WHERE id_member >= {int:page}
ORDER BY id_member
LIMIT 10",
array('week' => $checkWeek, 'page' => $limit)
);
while ($row = $smcFunc['db_fetch_assoc']($request))
{
$memberQuery = !empty($row['id_member']) ? (int)$row['id_member'] : 0;
for ($i=1; $i <=17; $i++)
{
$data['user_' . $memberQuery]['week' . $i] = array(
'user_picks' => !empty($row['week' . $i]) ? explode('_', $row['week' . $i]) : array(),
'tie_points' => (int)getInt($user_picks[(count($user_picks) -1)]),
'picks' => !empty($row['week' . $i]) ? explode('_', $row['week' . $i]) : array(),
);
}
/*
$userPoints[] = (!empty($user_picks)) ? (int)getInt($user_picks[(count($user_picks) -1)]) : '';
array_pop($user_picks);
*/
}
$smcFunc['db_free_result']($request);

/*
foreach ($user_picks as $user_pickem)
{
$context['user_game_' . $nfl_pick] = (!empty($user_pickem)) && $user_pickem === $nfl_games[$nfl_pick]['home'] ? $nfl_games[$nfl_pick]['home'] : $nfl_games[$nfl_pick]['away'];
$nfl_pick++;
}
*/
}
else
{
$request = $smcFunc['db_query']('', "
SELECT u.id_member
FROM {db_prefix}nfl_weekly AS u
WHERE id_member = {int:member}
LIMIT 1",
array('week' => $checkWeek, 'member' => $member)
);
}

echo '
<div style="display:inline;" class="windowbg">
<div class="cat_bar">
<h3 class="centertext catbg">NFL Pool Overall Sheet</h3>
</div>
<form id="nfl_pick" name="nfl_pickem" action="' . $currentPage . '" method="post">
<table width="100%">
<tr ', ($user_info['is_guest'] ? 'style="display: none;"' : ''),'>
', $user_info['is_admin'] ? '
<td colspan="6">
<input class="submit" type="submit" name="submit" value="Submit" />
</td>
' : '
<td colspan="6">
&nbsp;
</td>', '
<td style="float:right;">
<input class="submit" type="submit" name="exit_stats" value="Exit Overall" />
</td>
</tr>
</table>
</form>
</div>';
return;
}


It has incomplete bits in there for viewing user info (including pages) which is my next thing to work on.
More descriptive titles and some instruction is needed.
I also will add the ability for it to auto calculate the weekly winner and will have it give options for viewing picks as follows:

Admin only:
- specific user picks
- ability to manually enter picks for a user (prior to onset of first game)

General:
- view list of all user picks for the week after weekly deadline (< using pages)
- view overall tally of points (<- using pages or view all) ~ week winners will be highlighted
- ability to print both of the above
Title: Re: Pickems help
Post by: Chen Zhen on September 07, 2014, 01:38:23 AM

I updated the code block for the last post yet again with some changes.
It now allows admin/users to query other peoples individual picks from an auto-complete name input.
Admins can view them anytime but regular users have to wait until after the cut-off date.
This also allows Admins to edit other user data for whatever reason (ie. manually adding user picks).

Imo it might be best for me to convert this project to a mod now and create a board for it.
After I do that the next step will be the overall display.
2 templates are needed for it...
1) Display all participants picks in a graph (names on left ~ fav/und on top) whereas it will display F or U for each game
2) After each week has completed a list is updated containing total correct for each week + winner of each week is highlighted

Its a slow process since my time is limited although I have 17 weeks to do it.  ;D
I may just scrap the current API, use a file containing an array of the current season and find another API or do a page scrape for outcomes/scores.

  The current API contains scores only for the current week and then it flips to the next week schedule at a certain day/time as far as I know. I could be wrong about that and have to wait for the first week to complete to see how it functions.
That means in order to ensure it updated that scores automatically one (admin) would have to make sure to log in at a certain time and intiiate the code one way or another else create a crom job to do it. Either way I do not like the idea of it having to be done at a limited window of time.. it needs a source that can be accessed at any time for any given regular season week.  Once I get everything else done (to a point) then I am going to look into this.


Title: Re: Pickems help
Post by: Chen Zhen on September 07, 2014, 09:23:41 PM

Ok fixed it again for the cut-off date.. hopefully it works properly now concerning not allowing people to edit their picks after the first game on the list starts (we skip Thursday game so it is Sun. 1pm EST). Hopefully that API displays all weeks in the json array which will make it easier for me!!
Title: Re: Pickems help
Post by: Fog on September 07, 2014, 10:43:56 PM
Just for reference and what some may compare what they are used to on sites like Yahoo is that they have 5 minutes before each game as the cutoff.

QuoteImo it might be best for me to convert this project to a mod now and create a board for it.
After I do that the next step will be the overall display.
2 templates are needed for it...
1) Display all participants picks in a graph (names on left ~ fav/und on top) whereas it will display F or U for each game
2) After each week has completed a list is updated containing total correct for each week + winner of each week is highlighted

You'll need an home page, entry form, results and standing pages. (4 templates)

Home Page:  Shows links to each weeks entry form and a messages.
Entry Form:  Allows you to make your weekly picks and submit a tiebreaker.
Results:  Allows players to see their picks for the week and once the games are done the results.
Standings: This displays current overall standings for all those that are playing.

Title: Re: Pickems help
Post by: Chen Zhen on September 09, 2014, 09:11:10 PM
I still have not had time to make this into a mod which will involve many changes for SMF standards.
Also the templates for user picks, overall points, etc. is not done yet.

I have however added the code for it to save the final scores of the actual games to the database. In doing so this test block/page now exceeds the bytes max for the allotted text column for Simple Portal. This means that in its current state one must use a php file and call it from a php block/page.

Attached is the necessary php file and here is the block code:
global $sourcedir;

require_once($sourcedir . '/nfl_test.php');
nfl_football_pool();

The file must be put into the ../Sources folder.



When the new week is fed into the API it may require me to rewrite how the code reads the json array.
At the moment I am unaware of that API's format for anything past 1 week.
It may only supply 1 week of data at a time or it may display them all. I am hoping for the latter which will require changes to this code.

Title: Re: Pickems help
Post by: Chen Zhen on September 09, 2014, 11:35:50 PM

  Imo I think it might be best just to put the entire schedule into an array and have it in a separate file.
When I create a mod out of it just have it entail releasing a yearly installer that replaces the file with the updated array containing a newer schedule.
Title: Re: Pickems help
Post by: Fog on September 10, 2014, 11:11:21 AM
Here's a complete schedule for the 2014 Season
Title: Re: Pickems help
Post by: Chen Zhen on September 10, 2014, 04:28:09 PM

I can just look at the regular schedule from NFL.com but thanks.

It appears the free API only displays the current week.
This means I will have to develop a means for an admin to manually edit/enter any given week results.
I will still have it auto update the results but it will only do so if the API is available (if NFL.com server has issues for whatever reason it may not) and also either a user or the admin will have to access the NFL section of the site. There are other ways to go about it as in having an option to check when anyone generally logs on or just the specific section of the site plus have a separate file that can be set up for a cron job.
A cron job has to be set up from the server OS level either via a management platform (ie. Cpanel) or directly with the OS files/commands. The best I can do for people is to inform them to make sure to access the NFL section of their site on Tuesdays to ensure it attempts to update and a file for a cron job if they know how to use it. If it misses the auto update the admin will have to key it in manually.
Unless I find another dependable free API that has every week available on the page which Imo may not exist or at least not from an official site such as the one I am using from NFL.com.


Title: Re: Pickems help
Post by: Fog on September 10, 2014, 10:38:11 PM
UD, this is the code that comes with the standalone game I found.

They use ESPN....

<?php
require('includes/application_top.php');

$week = (int)$_GET['week'];

//load source code, depending on the current week, of the website into a variable as a string
$url "http://scores.espn.go.com/nfl/scoreboard?seasonYear=".SEASON_YEAR."&seasonType=2&weekNumber=" $week;
$raw file_get_contents($url);

$teamCodes = array(
'GNB' => 'GB',
'JAC' => 'JAX',
'KAN' => 'KC',
'NWE' => 'NE',
'NOR' => 'NO',
'SDG' => 'SD',
'SFO' => 'SF',
'TAM' => 'TB'
);

$newlines = array("\t","\n","\r","\x20\x20","\0","\x0B");
$content str_replace($newlines""html_entity_decode($raw));

$start strpos($content,'<div class="gameDay-Container">');
$end strpos($content,'<!-- begin sponsored links',$start) + 26;
$content substr($content,$start,$end-$start);

//set search pattern (using regular expressions)
//$find = '|<div class="game-header">(.*?)<div class="game-links">|is';
$find '|<p id=".*?-statusText">(.*?)</p>.*?<a href="/nfl/clubhouse\?team=(.*?)">(.*?)</a>.*?<li class="final" id=".*?-aTotal">(.*?)</li>.*?<a href="/nfl/clubhouse\?team=(.*?)">(.*?)</a>.*?<li class="final" id=".*?-hTotal">(.*?)</li>|is';
preg_match_all($find$content$matches);
//print_r($matches);
//exit;

//initiate scores array, to group teams and scores together in games
$scores = array();

//count number of teams found, to be used in the loop below
$count count($matches[1]);

for (
$i 0$i $count$i++) {
   
$overtime = (($matches[1][$i] == 'Final/OT') ? 0);
   
$away_team strtoupper($matches[2][$i]);
   
$home_team strtoupper($matches[5][$i]);
foreach ($teamCodes as $espnCode => $nflpCode) {
if ($away_team == $espnCode$away_team $nflpCode;
if ($home_team == $espnCode$home_team $nflpCode;
}
   
$away_score = (int)$matches[4][$i];
   
$home_score = (int)$matches[7][$i];

   
$winner = ($away_score $home_score) ? $away_team $home_team;
   
$gameID getGameIDByTeamID($week$home_team);
   if (
is_numeric(strip_tags($home_score)) && is_numeric(strip_tags($away_score))) {
   
if ($away_score || $home_score 0) {
    $scores[] = array(
       'gameID' => $gameID,
       'awayteam' => $away_team,
       'visitorScore' => $away_score,
       'hometeam' => $home_team,
       'homeScore' => $home_score,
       'overtime' => $overtime,
       'winner' => $winner
   
);
   }
   }
}

//see how the scores array looks
//echo '<pre>' . print_r($scores, true) . '</pre>';
echo json_encode($scores);

//game results and winning teams can now be accessed from the scores array
//e.g. $scores[0]['awayteam'] contains the name of the away team (['awayteam'] part) from the first game on the page ([0] part)
?>

Title: Re: Pickems help
Post by: Fog on September 10, 2014, 11:01:30 PM
UD, I'm a dumbass end user and not a developer like you.

I have ideas for the SMF site I help manage and I'm lucky to find and work with someone like you.

I find it tough to portray my ideas probably because I don't know enough.

I can read codes and modify them to understand how they work but to start from scratch is something I wouldn't know how to do.

I'm not sure if you looked at the file I uploaded, but I had to change it from a sql file to a txt file to display it,

I'm sure you can find all kinds of ways to find a 2014 Schedule. This one shows how it creates a Table on a DB at least for the game I'm hosting. 

I think you'll do a great job on this mod.
Title: Re: Pickems help
Post by: Fog on September 17, 2014, 10:30:04 PM
UD...can you put a shoutbox on the 2014 Pool Page?
Title: Re: Pickems help
Post by: Fog on September 26, 2014, 12:22:09 AM
How do I view results and standings?
Title: Re: Pickems help
Post by: Chen Zhen on September 26, 2014, 11:21:18 PM

I have not had the time to work on this as of late as I have been attempting to debug some SMF 2.1 issues.
Mostly related to compatibility with the personalized bbc mod.
When I finish with what I am working on in that regard I will continue with this mod and create a means to display the required info from the database.

Regards.
Title: Re: Pickems help
Post by: Fog on November 23, 2014, 09:10:54 PM
Did you see that catch?

Any updates on this UD...   :D
EhPortal 1.39.6 © 2024, WebDev