Location: PHPKode > projects > Online Fantasy Football League > offl-0.2.6/www/transactions.php
<?php
/**
 * Transaction Report
 *
 * Displays {@link OFFL_Transaction transactions}, optionally sorted by transaction type.  Read-only to all users.
 *
 * An admin section of legacy code is still in place but is non-functional and will be removed at a later date.
 *
 * @author Stephen Rochelle <hide@address.com>
 * @version OFFL v0.2
 * @copyright Copyright (c) 2004 Stephen Rochelle.  Some rights reserved.
 * @package offl-ui
 */

require_once("offlconfig.php");
require_once($DOC_ROOT . "/lib/functions.php");

if(empty($_GET["year"]))
{	$_GET["year"] = getThisYear();	}
if(empty($_GET["type"]))
{	$_GET["type"] = "all";	}
 
$pageTitle = $_GET["year"] . " Transactions";
$adminEditOnly = 1 ;
require_once($DOC_ROOT . "/lib/header.php");

// Stub transaction object
$thisTransaction = new OFFL_Transaction();

// user is saving info (edit or add)
if(isset($_GET["action"]) && ($_GET["action"] == "save"))
{
	if((($_GET["mode"] == "edit")&&isset($_GET["trans_id"])) || (($_GET["mode"] == "add") && !isset($_GET["trans_id"])))
	{
		// If edit, get the existing record
		if($_GET["mode"] == "edit")
		{	$thisTransaction = new OFFL_Transaction($_GET["trans_id"]);	}

		// Populate fields with form data
		$thisTransaction->setTransNote($_GET["trans_note"]);

		// Need to set transaction items
		$thisTransaction->save($_GET["mode"]);

?><div class="success">Transaction <?php echo $thisTransaction->getTransID(); ?> successfully saved.</div><p>
<a href="<?php echo $WEB_ROOT; ?>/transactions.php?mode=add&trans_id=<?php echo $thisTransaction->getTransID(); ?>">Add Transaction Items</a><?php
	}
	elseif((($_GET["mode"] == "edit")&&isset($_GET["transitem_id"])) || (($_GET["mode"] == "add") && isset($_GET["trans_id"])))
	{
		$thisTransactionItem = new OFFL_TransactionItem();
		// If edit, get the existing record
		if($_GET["mode"] == "edit")
			$thisTransactionItem = new OFFL_TransactionItem($_GET["transitem_id"]);
		else
			$thisTransactionItem->setTransID($_GET["trans_id"]);

		// Populate fields with form data
		$thisTransactionItem->setPlayerID($_GET["player_id"]);
		$thisTransactionItem->setFromFFLTeamID($_GET["fromfflteam_id"]);
		$thisTransactionItem->setToFFLTeamID($_GET["tofflteam_id"]);

		// Need to set transaction items
		$thisTransactionItem->save($_GET["mode"]);

?><div class="success">Transaction Item <?php echo $thisTransactionItem->getTransItemID(); ?> successfully saved.</div><p>
<a href="<?php echo $WEB_ROOT; ?>/transactions.php?mode=add&trans_id=<?php echo $thisTransactionItem->getTransID(); ?>">Add More Transaction Items</a><?php
	}
}
else
{

	if(($_GET["mode"] == "display") || (!isset($_GET["mode"])))
	{
			// Need to breakdown by years methinks
			$transactions = $thisTransaction->getTransactionsByType($_GET["type"], $_SESSION["league_id"], $_GET["year"]);
			?>
			<table width="75%">
				<tr valign="bottom">
					<td>View Transaction Season:
				<?php
					$years = $thisTransaction->getTransactionYears();
					for($i=0; $i<sizeof($years); $i++)
					{
						if($i > 0)
							echo " | ";
						?><a href="<?php echo $WEB_ROOT; ?>/transactions.php?mode=display&year=<?php echo $years[$i]; ?>"><?php echo $years[$i]; ?></a><?php
					}
				?>
				</td><td align="right">
		<a href="<?php echo $WEB_ROOT; ?>/transactions.php?mode=display&year=<?php echo $_GET["year"] ?>&type=all">All</a> | 
		<a href="<?php echo $WEB_ROOT; ?>/transactions.php?mode=display&year=<?php echo $_GET["year"] ?>&type=trade">Trades</a> | 
		<a href="<?php echo $WEB_ROOT; ?>/transactions.php?mode=display&year=<?php echo $_GET["year"] ?>&type=adddrop">Adds / Drops</a> | 
		<a href="<?php echo $WEB_ROOT; ?>/transactions.php?mode=display&year=<?php echo $_GET["year"] ?>&type=waiver">Waiver Claims</a> | 
		<a href="<?php echo $WEB_ROOT; ?>/transactions.php?mode=display&year=<?php echo $_GET["year"] ?>&type=lineup">Lineup Changes</a>
		</td>
				</tr>
			</table>

			<table border="0" cellpadding="5" cellspacing="0" width="75%">
				<tr bgcolor="#cccccc">
					<th align="left">Date</th>
					<th align="left">Player</th>
					<th align="left">From</th>
					<th align="left">To</th>
				</tr>
				<?php
				$first = 1;

		$i = 1;
		foreach ($transactions as $transaction)
		{
			$first = 1;
			$transactionItems = $transaction->getTransItems();
			if (sizeof($transactionItems))
				$i++;

			foreach ($transactionItems as $transItem)
			{
				$type = $transItem->getTransType();
				$player = $transItem->getPlayer();
				$fromTeam = new OFFL_FFLTeam($transItem->getFromFFLTeamID());
				$toTeam = new OFFL_FFLTeam($transItem->getToFFLTeamID());
				$datetime = gmdate("g:i A, M j, Y", GMTOffsetTime($transaction->getTransDatetime()));
				
				switch ($type)
				// We'll customize the From and To columns here, since many diverse values are possible
				{
					case "drop": // drop player
						if ($control->getValue("CONFIG_USE_WW") == "Yes")
						{	$To = "Waivers";	}
						else
						{	$To = "Free Agents";	}

						$From = "<a href=\"$WEB_ROOT/teams.php?fflteam_id=" . $fromTeam->getFFLTeamID() . "\">" . $fromTeam->getFFLTeamFullName() . "</a>";
						break;
					case "addfa": // add as a free agent
						$To = "<a href=\"$WEB_ROOT/teams.php?fflteam_id=" . $toTeam->getFFLTeamID() . "\">" . $toTeam->getFFLTeamFullName() . "</a>";
						$From = "Free Agents";
						break;
					case "addw": // add from waivers
						$To = "<a href=\"$WEB_ROOT/teams.php?fflteam_id=" . $toTeam->getFFLTeamID() . "\">" . $toTeam->getFFLTeamFullName() . "</a>";
						$From = "Waivers";
						break;
					case "trade": // trade player
						$To = "<a href=\"$WEB_ROOT/teams.php?fflteam_id=" . $toTeam->getFFLTeamID() . "\">" . $toTeam->getFFLTeamFullName() . "</a>";
						$From = "<a href=\"$WEB_ROOT/teams.php?fflteam_id=" . $fromTeam->getFFLTeamID() . "\">" . $fromTeam->getFFLTeamFullName() . "</a>";
						break;
					case "bench": // bench player
						$To = "Bench";
						$From = "<a href=\"$WEB_ROOT/teams.php?fflteam_id=" . $fromTeam->getFFLTeamID() . "\">" . $fromTeam->getFFLTeamFullName() . "</a> Starting " . $player->getPositionAbbv();
						break;
					case "start": // start player
						$To = "<a href=\"$WEB_ROOT/teams.php?fflteam_id=" . $toTeam->getFFLTeamID() . "\">" . $toTeam->getFFLTeamFullName() . "</a> Starting " . $player->getPositionAbbv();
						$From = "Bench";
						break;
					default: // no idea.	Here in case.
						$To = "";
						$From = "";
				}
					?>
					<tr valign="top"<?php if(($i%2)>0){ ?> class="altline"<?php } ?>>
						<?php if ($first) { ?>
						<td rowspan="<?php echo sizeof($transactionItems) ?>"><?php echo $datetime; ?></td>
						<?php $first = 0; } ?>
						<td><a href="<?php echo $WEB_ROOT; ?>/players.php?player_id=<?php echo $player->getPlayerID(); ?>"><?php echo $player->getName(); ?></a>, <?php echo $player->getPositionAbbv(); ?></td>
<?php
				echo "		<td>$From</td>\n		<td>$To</td>\n	</tr>\n";
			} // end foreach transitem
		} // end foreach transaction
	echo "</table>\n";
	}

	elseif($_GET["mode"] == "admin")
	{
		// Need to breakdown by years methinks
		$transactions = $thisTransaction->getAllTransactions($_GET["year"]);
		?>
		<form name="addtransaction" action="<?php echo $WEB_ROOT; ?>/transactions.php">
			<input type="hidden" name="mode" value="add">
			<input type="submit" value="Add Transaction">
		</form><br><br>
								 
		<table width="50%">
			<tr valign="bottom">
				<td>Edit Transaction Season:
			<?php
				$years = $thisTransaction->getTransactionYears();
				for($i=0; $i<sizeof($years); $i++)
				{
					if($i > 0)
						echo " | ";
					?><a href="<?php echo $WEB_ROOT; ?>/transactions.php?mode=<?php echo $_GET["mode"] ?>&year=<?php echo $years[$i]; ?>"><?php echo $years[$i]; ?></a><?php
				}
			?>
			</td>
			</tr>
		</table>

		<table border="0" cellpadding="5" cellspacing="0" width="75%">
			<tr bgcolor="#cccccc">
				<th align="left"></th>
				<th align="left">Date</th>
				<th align="left">Player</th>
				<th align="left">From</th>
				<th align="left">To</th>
			</tr>
				<?php
				$first = 1;
				for($i=0; $i<sizeof($transactions); $i++)
				{
					$first = 1;
					$transitems = $transactions[$i]->getTransItems();
					$rowspan = max($transitems,1);
					for($j=0; $j<sizeof($transitems); $j++)
					{
						$player = new OFFL_Player($transitems[$j]->getPlayerID());
						$fromteam = new OFFL_FFLTeam($transitems[$j]->getFromFFLTeamID());
						$toteam = new OFFL_FFLTeam($transitems[$j]->getToFFLTeamID());
					?>
					<tr valign="top"<?php if(($i%2)>0){ ?> class="altline"<?php } ?>>
						<?php if ($first) { ?>
						<td rowspan="<?php echo sizeof($transitems) ?>"><strong><a class="red" href="<?php echo $WEB_ROOT; ?>/transactions.php?mode=edit&trans_id=<?php echo $transactions[$i]->getTransID(); ?>">[Edit]</a></strong></td>
						<td rowspan="<?php echo sizeof($transitems) ?>"><?php echo $transactions[$i]->getTransDatetime(); ?></td>
						<?php $first = 0; } ?>
						<td><a href="<?php echo $WEB_ROOT; ?>/players.php?player_id=<?php echo $player->getPlayerID(); ?>"><?php echo $player->getLastName() . ", " . $player->getFirstName(); ?></a>, <?php echo $player->getPositionAbbv(); ?></td>
						<td><a href="<?php echo $WEB_ROOT; ?>/teams.php?fflteam_id=<?php echo $fromteam->getFFLTeamID(); ?>"><?php echo $fromteam->getFFLTeamCity() . " " . $fromteam->getFFLTeamName(); ?></a></td>
						<td><a href="<?php echo $WEB_ROOT; ?>/teams.php?fflteam_id=<?php echo $toteam->getFFLTeamID(); ?>"><?php echo $toteam->getFFLTeamCity() . " " . $toteam->getFFLTeamName(); ?></a></td>
					</tr>
					<?php
					}
					if(empty($transitems))
					{
					?>
					<tr valign="top"<?php if(($i%2)>0){ ?> class="altline"<?php } ?>>
						<td rowspan="<?php echo sizeof($transitems) ?>"><strong><a class="red" href="<?php echo $WEB_ROOT; ?>/transactions.php?mode=edit&trans_id=<?php echo $transactions[$i]->getTransID(); ?>">[Edit]</a></strong></td>
						<td rowspan="<?php echo sizeof($transitems) ?>"><?php echo $transactions[$i]->getTransDateTime(); ?></td>
						<td></td>
						<td></td>
						<td></td>
					</tr>
					<?php
					}
					?>
					<tr valign="top"<?php if(($i%2)>0){ ?> class="altline"<?php } ?>>
						<th align="right" colspan="2">Notes:</th>
						<td colspan="3"><?php echo $transactions[$i]->getTransNote(); ?></td>
					</tr>
					<?php
				}
				?>
			</table>
			<?php
	}
	else
	{
		$thisTransaction;
		$thisTransactionItem;
		$teams;
		$players;

/*
		if($_GET["mode"] == "edit")
		{
			if(isset($_GET["trans_id"]))
			{
				$thisTransaction = new Transaction($_GET["trans_id"]);
				if(!empty($thisTransaction->_emsg))
				{
					?-><div class="alert"><?php echo $thisTransaction->_emsg; ?-></div><?php
				}
			}
			elseif(isset($_GET["transitem_id"]))
			{
				$thisTransactionItem = new TransactionItem($_GET["transitem_id"]);
				if(!empty($thisTransactionItem->_emsg))
				{
					?-><div class="alert"><?php echo $thisTransactionItem->_emsg; ?-></div><?php
				}
				$thisTransaction = $thisTransactionItem->getTransaction();
 
				$x = new FFLTeam();
				$teams = $x->getAllFFLTeams();
				$x = new Player();
				$players = $x->getAllActivePlayers();
			}
		}
		*/

	if((($_GET["mode"] == "edit")&&isset($_GET["trans_id"])) || (($_GET["mode"] == "add") && !isset($_GET["trans_id"])))
	{
		if($_GET["mode"] == "edit")
		{
				$thisTransaction = new Transaction($_GET["trans_id"]);
				if(!empty($thisTransaction->_emsg))
				{
					?><div class="alert"><?php echo $thisTransaction->_emsg; ?></div><?php
				}
		}
// $thisTransaction variable contains what we need
?>
<form name="transinfo" action="<?php echo $WEB_ROOT; ?>/transactions.php">
<?php if ($_GET["mode"] == "edit") { ?>
	<input type="hidden" name="trans_id" value="<?php echo $thisTransaction->getTransID() ?>">
<?php } ?>
	<input type="hidden" name="mode" value="<?php echo $_GET["mode"] ?>">
	<input type="hidden" name="action" value="save">

	<table border="0">
<?php if ($_GET["mode"] == "edit") { ?>
		<tr>
			<th align="right">Transaction ID:</th>
			<td><?php echo $thisTransaction->getTransID(); ?></td>
		</tr>
		<tr>
			<th align="right">Transaction Date:</th>
			<td><?php echo $thisTransaction->getTransDatetime(); ?></td>
		</tr>
<?php } ?>
		<tr valign="top">
			<th align="right">Transaction Note:</th>
			<td><textarea name="trans_note" cols="30" rows="8" wrap="virtual"><?php echo $thisTransaction->getTransNote(); ?></textarea></td>
		</tr>
			
		<tr>
			<th align="right">&nbsp;</th>
			<td colspan="2"><input type="submit" value="Save Transaction Note"></td>
		</tr>
	</table>

</form>
<?php if ($_GET["mode"] == "edit") { ?>
<br>
<div class="big">Transaction Items</div>
			<form name="addtransaction" action="<?php echo $WEB_ROOT; ?>/transactions.php">
				<input type="hidden" name="mode" value="add">
				<input type="hidden" name="trans_id" value="<?php echo $thisTransaction->getTransID() ?>">
				<input type="submit" value="Add Transaction Item">
			</form><br>
				<table cellpadding="3" cellspacing="0" border="0">
				<tr bgcolor="#cccccc">
					<th align="left"></th>
					<th align="left">Player</th>
					<th align="left">From</th>
					<th align="left">To</th>
				</tr>
<?php
					$transitems = $thisTransaction->getTransItems();
					for($j=0; $j<sizeof($transitems); $j++)
					{
						$player = new OFFL_Player($transitems[$j]->getPlayerID());
						$fromteam = new OFFL_FFLTeam($transitems[$j]->getFromFFLTeamID());
						$toteam = new OFFL_FFLTeam($transitems[$j]->getToFFLTeamID());
					?>
					<tr valign="top"<?php if(($i%2)>0){ ?> class="altline"<?php } ?>>
						<td><strong><a class="red" href="<?php echo $WEB_ROOT; ?>/transactions.php?mode=edit&transitem_id=<?php echo $transitems[$j]->getTransItemID(); ?>">[Edit]</a></strong></td>
						<td><a href="<?php echo $WEB_ROOT; ?>/players.php?player_id=<?php echo $player->getPlayerID(); ?>"><?php echo $player->getLastName() . ", " . $player->getFirstName(); ?></a>, <?php echo $player->getPositionAbbv(); ?></td>
						<td><a href="<?php echo $WEB_ROOT; ?>/teams.php?fflteam_id=<?php echo $fromteam->getFFLTeamID(); ?>"><?php echo $fromteam->getFFLTeamCity() . " " . $fromteam->getFFLTeamName(); ?></a></td>
						<td><a href="<?php echo $WEB_ROOT; ?>/teams.php?fflteam_id=<?php echo $toteam->getFFLTeamID(); ?>"><?php echo $toteam->getFFLTeamCity() . " " . $toteam->getFFLTeamName(); ?></a></td>
					</tr>
					<?php
					}
					?></table><?php
					}
				}
				elseif((($_GET["mode"] == "edit") && isset($_GET["transitem_id"])) || (($_GET["mode"] == "add") && isset($_GET["trans_id"])))
				{

				if($_GET["mode"] == "edit")
				{
					$thisTransactionItem = new TransactionItem($_GET["transitem_id"]);
					if(!empty($thisTransactionItem->_emsg))
					{
						?><div class="alert"><?php echo $thisTransactionItem->_emsg; ?></div><?php
					}
					$thisTransaction = $thisTransactionItem->getTransaction();
				}
				else
				{
					$thisTransaction = new Transaction($_GET["trans_id"]);
				}
	
				$x = new FFLTeam();
				$teams = $x->getAllFFLTeams();
				$x = new Player();
				$players = $x->getAllActivePlayers();
// $thisTransaction variable contains what we need
?>
<form name="transiteminfo" action="<?php echo $WEB_ROOT; ?>/transactions.php">
<?php if ($_GET["mode"] == "edit") { ?>
	<input type="hidden" name="transitem_id" value="<?php echo $thisTransactionItem->getTransItemID() ?>">
<?php } else { ?>
	<input type="hidden" name="trans_id" value="<?php echo $thisTransaction->getTransID() ?>">
<?php } ?>
	<input type="hidden" name="mode" value="<?php echo $_GET["mode"] ?>">
	<input type="hidden" name="action" value="save">

	<table border="0">
		<tr>
			<th align="right">Transaction ID:</th>
			<td><?php echo $thisTransaction->getTransID(); ?></td>
		</tr>
		<tr>
			<th align="right">Transaction Date:</th>
			<td><?php echo $thisTransaction->getTransDatetime(); ?></td>
		</tr>
		<tr valign="top">
			<td align="right">Player:</td>
			<td align="left">
				<select name="player_id" size="1">
					<option value="0"> -- Select One -- </option>
			<?php
				for($i=0; $i<sizeof($players); $i++)
				{
					?>
						<option value="<?php echo $players[$i]->getPlayerID(); ?>"<?php if(($_GET["mode"] == "edit") && ($players[$i]->getPlayerID() == $thisTransactionItem->getPlayerID())) { ?> selected<?php } ?>><?php echo $players[$i]->getLastName() . ", " . $players[$i]->getFirstName() . ";	" . $players[$i]->getPositionAbbv() . ", " . $players[$i]->getNFLTeamCity() . " " . $players[$i]->getNFLTeamName(); ?></option>
					<?php
				}
			?>
				</select>
			</td>
		</tr>
		<tr valign="top">
			<td align="right">From Team:</td>
			<td align="left">
				<select name="fromfflteam_id" size="1">
					<option value="0"></option>
			<?php
				for($i=0; $i<sizeof($teams); $i++)
				{
					?>
						<option value="<?php echo $teams[$i]->getFFLTeamID(); ?>"<?php if(($_GET["mode"] == "edit") && ($teams[$i]->getFFLTeamID() == $thisTransactionItem->getFromFFLTeamID())) { ?> selected<?php } ?>><?php echo $teams[$i]->getFFLTeamCity() . " " . $teams[$i]->getFFLTeamName(); ?></option>
					<?php
				}
			?>
				</select>
			</td>
		</tr>
		<tr valign="top">
			<td align="right">To Team:</td>
			<td align="left">
				<select name="tofflteam_id" size="1">
					<option value="0"></option>
			<?php
				for($i=0; $i<sizeof($teams); $i++)
				{
					?>
						<option value="<?php echo $teams[$i]->getFFLTeamID(); ?>"<?php if(($_GET["mode"] == "edit") && ($teams[$i]->getFFLTeamID() == $thisTransactionItem->getToFFLTeamID())) { ?> selected<?php } ?>><?php echo $teams[$i]->getFFLTeamCity() . " " . $teams[$i]->getFFLTeamName(); ?></option>
					<?php
				}
			?>
				</select>
			</td>
		</tr>
			
		<tr>
			<th align="right">&nbsp;</th>
			<td colspan="2"><input type="submit" value="Save Transaction Item"></td>
		</tr>
	</table>

</form>
<?php
			}
	}
}

require($DOC_ROOT . "/lib/footer.php"); ?>
Return current item: Online Fantasy Football League