Location: PHPKode > projects > Online Fantasy Football League > offl-0.2.6/www/news.php
<?php
/**
 * News page
 *
 * Not converted to multi-league data format
 *
 * @author Stephen Rochelle <hide@address.com>
 * @version OFFL v0.2
 * @copyright Copyright (c) 2004 Stephen Rochelle.	Some rights reserved.
 * @package offl-ui
 */

$pageTitle = "News";
$adminEditOnly = 1 ;
require_once("offlconfig.php");
require_once($DOC_ROOT . "/lib/header.php");

/* I NEED TO RIG THIS SUCH THAT USERS CAN POST (BUT NOT EDIT) NEWS ITEMS */
// simple - ?mode=post 

// Stub team object
$thisNews = new OFFL_News();

if (!isset($_REQUEST["action"]))
{	$_REQUEST["action"] = NULL;	}

if ( ($_REQUEST["action"] == "delete") && ($_SESSION["admin"] == 1) )
{
	if ($_REQUEST["confirm"] == "on")
	{
		$thisNews = new OFFL_News($_REQUEST["news_id"]);
		$thisNews->deleteNews();
	}
}
// user is saving info (edit or add)
if($_REQUEST["action"] == "save")
{


	// If edit, get the existing record
	if($_REQUEST["mode"] == "edit")
	{	$thisNews = new OFFL_News($_REQUEST["news_id"]);	}
	$_REQUEST["story"] = "<p>" . $_REQUEST["story"] . "</p>";
	$_REQUEST["story"] = str_replace("\r\n\r\n", "</p><p>", $_REQUEST["story"]);
	$_REQUEST["story"] = str_replace("\r\n", "<br />", $_REQUEST["story"]);

	// Populate fields with form data
	$thisNews->setLeagueID($myleague->getLeagueID());
	$thisNews->setHeadline($_REQUEST["headline"]);
	$thisNews->setStory($_REQUEST["story"]);
	$thisNews->setFFLTeamID($_REQUEST["fflteam_id"]);
	$thisNews->setPlayerID($_REQUEST["player_id"]);
	$thisNews->setUserID($_REQUEST["user_id"]);

	$thisNews->save();
?><div class="success">News <?php echo $thisNews->getHeadline(); ?> successfully saved.</div><p><?php
	require($DOC_ROOT . "/lib/footer.php");
	exit();
}

	if((!isset($_REQUEST["mode"]) || ($_REQUEST["mode"] == "display")))
	{
?>		<div id="subnav"><ul>
			<li id="caption">News Pages:</li>
			<li><a href="<?php echo $WEB_ROOT; ?>/news.php?mode=post">Post News</a></li>
			<li><a href="<?php echo $WEB_ROOT; ?>/forum/">Forum</a></li>
		</ul></div>
<?php
			$news = $thisNews->getAllNews($_SESSION["league_id"],5);
			for($i=0; $i<sizeof($news); $i++)
			{
			?>
			<table cellspacing="1" cellpadding="3" class="news">

				<tr>
					<th class="headline"><?php echo $news[$i]->getHeadline(); ?></th>
				</tr>
				<tr>
						<td class="byline">Posted on <?php echo date("M j, Y", GMTOffsetTime($news[$i]->getPostdate())); ?></td>
				</tr>
				<tr>
						<td class="story"> <?php
						if($news[$i]->getNFLProfile() != "")
						{
								$pic="http://images.nfl.com/images/players/60x80"; 
								$pic = $pic . $news[$i]->getNFLProfile();
								$pic = $pic . ".jpg"; 
								if (is_file("$DOC_ROOT/$pic")) { ?>
								<table align="left" border="0" cellpadding="0" cellspacing="0">
								<tr valign="top">
										<td align="center"><img src="<?php echo $pic; ?>"><br><div class="small"><?php echo $news[$i]->getFirstName() . " " . $news[$i]->getLastName(); ?></td>
								</tr>
								</table><?php
								}
						}

						echo $news[$i]->getStory();
						?>
						
				</tr>
			</table>
			<?php
			}
	}
	elseif($_REQUEST["mode"] == "admin")
	{
		// Present page of add/edit option
		//	Edit has drop-down of options
			$news = $thisNews->getAllNews($_SESSION["league_id"]);
			?>
			<table border="0" cellpadding="3" cellspacing="0" width="50%">
				<tr valign="top">
					<td>
						<form name="addnews" action="<?php echo $WEB_ROOT; ?>/news.php">
							<input type="hidden" name="mode" value="add">
							<input type="submit" value="Add News">
						</form>
					</td>
				</tr>
				<tr valign="top">
					<td>&nbsp;</td>
				</tr>
				<tr valign="top">
					<td>
						<form name="editnews" action="<?php echo $WEB_ROOT; ?>/news.php">
							<input type="hidden" name="mode" value="edit">
							<select name="news_id" size="1">
								<option value="0"> -- Select One -- </option>
				<?php
				foreach($news as $newsitem)
				{
					?>
								<option value="<?php echo $newsitem->getNewsID(); ?>"><?php echo $newsitem->getHeadline() . " (" . date("M j, Y", GMTOffsetTime($newsitem->getPostdate())) . ")"; ?></option>
					<?php
				}
				?>
							</select>
							<input type="submit" value="Edit News">
						</form>
					</td>
				</tr>
			</table>
			<?php

	}
	else
	{
	if (!isset($_SESSION["user_id"]) || ($_SESSION["user_id"] < 1))
		{
		echo "<h3 class=\"error\">You must be logged in to post news items</h3>\n";
		}
		else
		{

		if($_REQUEST["mode"] == "edit")
		{
			if(isset($_REQUEST["news_id"]))
			{
				$thisNews = new OFFL_News($_REQUEST["news_id"]);
				if(!empty($thisNews->_emsg))
				{
					?><div class="alert"><?php echo $thisNews->_emsg; ?></div><?php
				}
			}
			else
			{
				// Present drop-down list of ALL news
			}
		}

// $thisNews variable contains what we need
?>
<form name="newsinfo" action="<?php echo $WEB_ROOT; ?>/news.php" method="post">
<?php if ($_REQUEST["mode"] == "edit") { ?>
	<input type="hidden" name="news_id" value="<?php echo $thisNews->getNewsID() ?>" />
	<input type="hidden" name="user_id" value="<?php echo $thisNews->getUserID() ?>" />
<?php } else { ?>
	<input type="hidden" name="user_id" value="<?php echo $_SESSION["user_id"]; ?>" />
<?php } ?>
	<input type="hidden" name="mode" value="<?php echo $_REQUEST["mode"] ?>" />
	<input type="hidden" name="action" value="save">

	<table border="0">
		<tr>
			<th align="right">Headline:</th>
			<td><input type="text" name="headline" size="35" maxlength="50"<?php if($_REQUEST["mode"] == "edit") { ?> value="<?php echo $thisNews->getHeadline() ?>"<?php } ?>></td>
		</tr>
		<tr>
			<th align="right">Player:</th>
			<td colspan="2">
				<select name="player_id" size="1">
					<option value="0"> -- Select One -- </option>
					<?php
//						$players = $myleague->getPlayers();
			$players = array();
						foreach($players as $player)
						{
							?>
								<option value="<?php echo $player->getPlayerID(); ?>"<?php
									if(($_REQUEST["mode"] == "edit") && ($player->getPlayerID() == $thisNews->getPlayerID())) {
										?> selected<?php 
									} ?>><?php echo $player->getName(); ?></option>
							<?php
						}

					?>
				</select>
				<div class="small">Player picture will appear in news story if it exists.</div>
			</td>
		</tr>
		<tr>
			<th align="right">Team:</th>
			<td colspan="2">
				<select name="fflteam_id" size="1">
					<option value="0"> -- Select One -- </option>
					<?php
						$teams = $myleague->getAllFFLTeams();
						foreach($teams as $team)
						{
							?>
								<option value="<?php echo $team->getFFLTeamID(); ?>"<?php
									if(($_REQUEST["mode"] == "edit") && ($team->getFFLTeamID() == $thisNews->getFFLTeamID())) {
										?> selected<?php 
									} ?>><?php echo $team->getFFLTeamFullName(); ?></option>
							<?php
						}

					?>
				</select>
				<div class="small">Currently nothing happens with Teams on the news page.	You can ignore it if you want.<br>Note that the team is not related to the player at all.</div>
			</td>
		</tr>
		<tr valign="top">
				<th align="right">Story:</th>
				<td><textarea name="story" cols="35" rows="8" wrap="virtual"><?php
						$story = $thisNews->getStory();
						$story = str_replace("</p><p>", "\r\n\r\n", $story);
						$story = str_replace("<br />", "\r\n", $story);
						$story = str_replace("<p>", "", $story);
						$story = str_replace("</p>", "", $story);
				
						echo $story;
					?></textarea></td>
		</tr>

		<tr>
			<th align="right">&nbsp;</th>
			<td colspan="2"><input type="submit" value="Save News"></td>
		</tr>
	</table>

</form>
<?php
		}

	if (($_SESSION["admin"] == 1) && ($_REQUEST["mode"] != "post"))
		{
?>
<form name="newsdel" action="<?php echo $WEB_ROOT; ?>/news.php">
	<input type="hidden" name="action" value="delete" />
	<input type="hidden" name="news_id" value="<?php echo $thisNews->getNewsID(); ?>" />
I want to delete this item:	<input type="checkbox" name="confirm" />
	<input type="submit" value="Delete News Item" />
</form>
<?php		}


	}

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