Card Selection – Draft Code

[insert_php]

// includes our database functions
//include(‘db_fns.php’);

db_connect();

//Remove from Post Content
//remove_filter(‘the_content’, ‘wptexturize’);
//Remove from Post Title
//remove_filter(‘the_title’, ‘wptexturize’);
//Remove from Post Excerpt
//remove_filter(‘the_excerpt’, ‘wptexturize’);
//Remove from Post Comments
//remove_filter(‘comment_text’, ‘wptexturize’);

// Owner’s Draft Number Code to allow for draft pick
$leaguestart = $_GET[‘leaguestart’];

// Owner’s Draft Number Code to allow for draft pick
$teamcount = $_POST[‘teamcount’];

$method = $_SERVER[‘REQUEST_METHOD’];
//$request = explode(“/”, substr(@$_SERVER[‘PATH_INFO’], 1));

if($method == “POST”) {
// Pass Current Page
$draftsection = $_POST[‘draftsection’];
// Owner’s Draft Number Code to allow for draft pick
$draftcode = $_POST[‘draftcode’];
}
else {
// Pass Current Page
$draftsection = $_GET[‘draftsection’];
// Owner’s Draft Number Code to allow for draft pick
$draftcode = $_GET[‘draftcode’];
}
echo “DRAFT SECTION: $draftsection
“;

// Owner’s Draft Number Code to allow for draft pick
$draftfield = $_GET[‘draftfield’];

// Owner’s Pick Selection
$picklocation = $_GET[‘picklocation’];

// SELF LINK
$self = “index.php”;

// GET DIRECTORY
$folder = “http://fantasymasters.com/card-selection/”;

$leaguecode = substr($draftcode, 0, 4);

// CHECK IF THE LEAGUE IS NEW
if ($leaguestart == “yes”) {

echo ” 
“;
echo “

\r\n”;
echo “Team Count: \r\n”;
echo “\r\n”;
echo “\r\n”;
echo “

\r\n”;
echo ” 
“;
echo ” 
“;
}
else
{
// IF NO DATA PASSED WITH GET OR POST, SHOW INPUT FOR DRAFT CODE
if(!$draftsection)
{
echo ” 
“;
echo “

\r\n”;
echo “Draft Code: ” . “
\r\n”;

echo “\r\n”;
echo “\r\n”;
echo “

“;
echo ” 
“;
echo ” 
“;
echo ” 
“;
}
}
// CHECK IF IT’S A NEW LEAGUE AND TIME TO PUT IN ALL EMAILS
if ($draftsection == “emails”) {
if ($teamcount > 0) {
if ($teamcount <= 16) { echo "

\r\n”;
echo “League Name: ” . “
\r\n”;
for ($x=1; $x <= $teamcount; $x++) { echo "Owner Name #" . $x . ": \r\n”;
echo “Email #” . $x . “:
\r\n”;
}
echo “\r\n”;
echo “\r\n”;
echo “\r\n”;
echo “

“;
}
else
{
echo “Team count must be greater than 0 and less than or equal to 16

\r\n”;
}
}
else
{
echo “Team count must be over 0 and less than or equal to 16

\r\n”;
}
}
// CHECK IF EMAILS WERE SUBMITTED AND IF THEY ARE ALL VALID
$emailstatus = “valid”;
if ($draftsection == “checkemails”)
{
echo “CE”;
if ($teamcount <= 16) { // Check if all emails valid for ($x=1; $x <= $teamcount; $x++) { $emailacct = "email" . $x; $emailcheck = $_POST[$emailacct]; echo "$emailcheck
“;
if (!preg_match(“/([\w\-]+\@[\w\-]+\.[\w\-]+)/”,$emailcheck)) {
$emailstatus = “invalid”;
}
}
// IF EMAILS ARE ALL VALID, SAVE ALL OWNERS
if ($emailstatus == “valid”)
{

do {
$leaguecode = rand(1100, 9895);
$query = sprintf(“SELECT * FROM draftpickowners WHERE draftpickowners.leaguecode = ‘%s'”,
mysql_real_escape_string($leaguecode));
$results = mysql_query($query);
$Row = mysql_fetch_assoc($results);
} while ( $Row != false);

// RETRIEVE LEAGUE NAME FROM FORM
$leaguename = $_POST[‘leaguename’];

// RETRIEVE TODAY’S DATE
$today = date(“Ymd”);

// RANDOMIZE DRAFT PICKS
$pickcnt = 1;
$picksum = array(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
$pickorder = array(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);

for ($y=1; $y <= 5; $y++) { for ($z=1; $z<=$teamcount; $z++) { $rannum = rand(125, 999); $picksum[$z] += $rannum; } } for ($a=1; $a<=$teamcount; $a++) { $low = 9999; for ($b=1; $b<=$teamcount; $b++) { if ($picksum[$b]<$low) { $low = $picksum[$b]; $lowpick = $b; } } $picksum[$lowpick] = 99999; $pickorder[$a] = $lowpick; echo "PICK: " . $a . " " . $pickorder[$a] . $picksum[$lowpick] . "
“;
$lowpick = 99;
}

// SAVE RANDOMIZED DRAFT ORDER
$comma_pickorder = implode(“,”, $pickorder);

// SAVE NEW LEAGUE DATA
$sql = “INSERT INTO draftpickleagues (leaguename, leaguecode, teamcount, leaguedate, randomorder) ” .
“VALUES (\”$leaguename\”, $leaguecode, $teamcount, \”$today\”, \”$comma_pickorder\”)”;

//echo “$sql

“;

$retval = mysql_query( $sql);

if(!$retval)
{
die(‘Could not update data: ‘ . mysql_error());
}

for ($t=1; $t <= $teamcount; $t++) { // DEFINE DRAFT CODE FOR INDIVIDUAL OWNER $leaguecodeone = rand(110, 995); $draftcode = $leaguecode . $leaguecodeone . $t; $draftname = $_POST["ownername" . $t]; // RETRIEVE EMAIL ACCOUNT FOR CURRENT OWNER $emailacct = $_POST["email" . $t]; $sql = "INSERT INTO draftpickowners (name, email, teamnumber, leaguecode, draftcode, teamcount) " . "VALUES (\"$draftname\", \"$emailacct\", $t, $leaguecode, $draftcode, $teamcount)"; //echo "$sql “; $retval = mysql_query( $sql); if(!$retval) { die(‘Could not update data: ‘ . mysql_error()); } // REPLACE THE LINE BELOW WITH YOUR E-MAIL ADDRESS. $to = $emailacct; $subject = $_POST [ “leaguename” ] . ” Draft Code”; $message = “Your commissioner has registered your league with FantasyMasters.com for the sole purpose of selecting your draft order. The confirmation code below is specific to your team. Enter the code at www.fantasymasters.com/draftorder to make your selection. If your selection is not made within 72 hours, a draft position will be selected for you at random. ” . “Your confirmation code: ” . $draftcode . “ “; //$message = “It is almost time for your draft. Below, you will find your draft pick code number. This will be used to make your draft order selection. Follow this link to make your selection. Use this confirmation to make the selection: ” . $draftcode;
// NOT SUGGESTED TO CHANGE THESE VALUES
$message = $draftname . PHP_EOL . $message;
$headers = ‘From: ‘ . ‘draft@fantasymasters.com’ . PHP_EOL ;
echo “TO: $to

SUBJECT: $subject

MESSAGE: $message

HEADERS: $headers
“;
//mail ( $to, $subject, $message, $headers ) ;

// THE TEXT IN QUOTES BELOW IS WHAT WILL BE
// DISPLAYED TO USERS AFTER SUBMITTING THE FORM.
echo “Your e-mail has been sent! You should receive a reply within 24 hours!

“;

}

}
// IF EMAILS ARE NOT VALID, DISPLAY ERROR TO USER
else
{
echo “Invalid email, check emails again

“;
for ($x=1; $x <= $teamcount; $x++) { echo "

“;
echo “Team #” . $x . “: “;
echo “Email:
“;
}
echo ““;
echo ““;
echo “

“;
}
}
}

if ($draftsection == “draftcodeinput”) {
// VERIFY DRAFTCODE EXISTS
$query = sprintf(“SELECT * FROM draftpickowners WHERE draftpickowners.draftcode = ‘%s'”,
mysql_real_escape_string($draftcode));

$results = mysql_query($query);
$ownerRow = mysql_fetch_assoc($results);

echo “TEST1 $draftsection
“;
echo “

";
		print_r ($ownerRow);
		echo "

“;

// RETRIEVE WHICH CARDS ARE AVAILABLE AND WHICH WERE ALREADY SELECTED
$query = sprintf(“SELECT * FROM draftpickleagues WHERE draftpickleagues.leaguecode = ‘%s'”,
mysql_real_escape_string($leaguecode));

$results = mysql_query($query);
$leagueRow = mysql_fetch_assoc($results);

echo “TEST1
“;
echo “

";
		print_r ($leagueRow);
		echo "

“;

echo “RANDOM: $teamorder
“;
$teamcount = $leagueRow[‘teamcount’];
$teampicknumber = $ownerRow[‘picknumber’];

for ($m=1; $m <= $teamcount; $m++) { $selections[$m] = $leagueRow["teamorder" . $m]; } echo "TEST1
“;
echo “

";
		print_r ($selections);
		echo "

“;

echo “

“;
echo “ “;
echo “
“;
if ($teampicknumber == 0) {
echo “

“;
}
else {
echo “

“;
}
echo “

“;
echo “

“;
echo “

“;

if ($teampicknumber == 0) {
$twocount = 0;
for ($i=1; $i <= $teamcount; $i++) { $twocount++; $draftfield = "draftpick" . $i; if ($twocount == 1) { echo "

“;
}
if($selections[$i] == 0) {
echo “

“;
}
else {
echo “

“;
}
if ($twocount >= 2) {
echo “

“;
$twocount = 0;
}
}
}
else {
echo “

“;
echo “

“;
echo “

“;
}
echo “

“;
echo “

Choose one of the cards below, Numbers shown represent picks already selected Your Draft Pick
\"\" \"\"
\"\"

“;

}

if ($draftsection == “draftcodeselected”) {
// VERIFY DRAFTCODE EXISTS
$query = sprintf(“SELECT * FROM draftpickowners WHERE draftpickowners.draftcode = ‘%s'”,
mysql_real_escape_string($draftcode));

$results = mysql_query($query);
$ownerRow = mysql_fetch_assoc($results);

//$ownerRow = mysql_fetch_assoc($results);

echo “TEST4 $draftcode
“;
echo “

";
		print_r ($ownerRow);
		echo "

“;

if($ownerRow) {
// RETRIEVE WHICH CARDS ARE AVAILABLE AND WHICH WERE ALREADY SELECTED
$query = sprintf(“SELECT * FROM draftpickleagues WHERE draftpickleagues.leaguecode = ‘%s'”,
mysql_real_escape_string($leaguecode));

$results = mysql_query($query);
$leagueRow = mysql_fetch_assoc($results);

$teamcount = $leagueRow[‘teamcount’];

echo “TEST2
“;
echo “

";
			print_r ($leagueRow);
			echo "

“;

echo “HERE ” . $leagueRow[‘teamorder5’];

for ($n=1; $n <= $teamcount; $n++) { $indx = "teamorder" . $n; $teamselections[$n] = $leagueRow[$indx]; } $randomorder = $leagueRow['randomorder']; echo "RANDOM: $randomorder
“;
$leaguecode = $ownerRow[‘leaguecode’];
$teamnumber = $ownerRow[‘teamnumber’];
$teampicknumber = $ownerRow[‘picknumber’];
$randomselections = explode(“,”, $randomorder);
echo “CARD TAKEN $picklocation T ” . $randomselections[$picklocation] . “T ” . $teamnumber . “
“;
echo “TMS: ” . $teamselections[$picklocation] . “
“;
if ($teamselections[$picklocation] == 0) {
if ($teampicknumber == 0) {

echo “

“;
echo “ “;
echo “
“;
echo “

“;
echo “

“;
echo “

“;
echo “

“;

echo “

“;
echo “

“;
echo “

“;

echo “

“;
echo “

Your Draft Pick
\"\"

“;

$teamselections[$picklocation] = $teamnumber;

$sql = “UPDATE draftpickleagues “.
“SET teamorder” . $picklocation . “=” . $teamnumber . ” “.
“WHERE leaguecode=$leaguecode” ;
mysql_query($sql) or die (“Error: “.mysql_error());
echo “SQL: $sql” . “
“;

$sql = “UPDATE draftpickowners “.
“SET picknumber=” . $randomselections[$picklocation] . ” ” .
“WHERE draftcode=$draftcode” ;
mysql_query($sql) or die (“Error: “.mysql_error());
echo “SQL: $sql” . “
“;
}
}

}
else {
echo “Draft Code is invalid.

Do not edit the links provided

“;
}
}

function db_connect()
{
$connection = mysql_pconnect(‘db537827035.db.1and1.com’, ‘dbo537827035’, ‘pitstop69’);
mysql_set_charset(‘utf8’,$connection);
if(!$connection)
{
return false;
}

if(!mysql_select_db(‘db537827035’))
{
return false;
}

return $connection;
}
[/insert_php]

Leave a Reply

Your email address will not be published. Required fields are marked *