Location: PHPKode > projects > Online Fantasy Football League > offl-0.2.6/www/divisions.php
<?php
/**
 * Division viewer
 *
 * Need to test
 *
 * @author Stephen Rochelle <hide@address.com>
 * @version OFFL v0.2
 * @copyright Copyright (c) 2004 Stephen Rochelle.  Some rights reserved.
 * @package offl-ui
 */

$pageTitle = "Division Info";
require_once("offlconfig.php");
require_once($DOC_ROOT . "/lib/header.php");

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

if ( ($_GET["action"] == "delete") && ($_SESSION["admin"] == 1) )
{
	if ($_GET["confirm"] == "on")
	{
		$thisDivision = new OFFL_Division($_GET["division_id"]);
		$thisDivision->deleteDivision();
	}
}

// Stub division object
$thisDivision = new OFFL_Division();

// user is saving info (edit or add)
if($_GET["action"] == "save")
{
  // If edit, get the existing record
	if($_GET["mode"] == "edit")
	{  $thisDivision = new OFFL_Division($_GET["division_id"]);	}

	// Populate fields with form data
	$thisDivision->setDivisionDesc($_GET["division_desc"]);
	// update new league for all member teams
	if ($_GET["league_id"] != $thisDivision->getLeagueID())
	{
		$teams = $thisDivision->getAllDivisionTeams();
		foreach ($teams as $team)
		{
			$team->setLeagueID($_GET["league_id"]);
			$team->save();
		}
	}
	$thisDivision->setLeagueID($_GET["league_id"]);

    // Save
  $thisDivision->save();
?><div class="success">Division <?php echo $thisDivision->getDivisionDesc(); ?> successfully saved.</div><p><?php
}
else
{

  if(($_GET["mode"] == "display") || (!isset($_GET["mode"])))
  {
      // No division_id is selected, show list of divisions and owners
      $divisions = $myleague->getAllDivisions();
      ?>
      <table style="width:50%; border: 1px solid #B4D0F0; max-width: 200px; border-collapse:collapse;" cellpadding="3">
        <tr bgcolor="#B4D0F0">
          <th align="left">Division</th>
        </tr>
        <?php
        foreach($divisions as $i=>$division)
        {
          ?>
          <tr class="<?php if($i % 2) echo "evenrow"; else echo "oddrow"; ?>">
            <td><?php echo $division->getDivisionDesc(); ?></a></td>
          </tr>
          <?php
        }
        ?>
      </table>
      <?php
  }
  elseif($_GET["mode"] == "admin")
  {
    // Present page of add/edit option
    //  Edit has drop-down of options
		$showall = FALSE;
		if (isset($_GET["showalldivisions"]))
	    {	$showall = TRUE;	}

      $divisions = $myleague->getAllDivisions($showall);
      ?>
      <table border="0" cellpadding="3" cellspacing="0" width="50%">
        <tr valign="top">
          <td>
            <form name="adddivision" action="<?php echo $WEB_ROOT; ?>/divisions.php">
              <input type="hidden" name="mode" value="add">
              <input type="submit" value="Add Division">
            </form>
          </td>
        </tr>
        <tr valign="top">
          <td>&nbsp;</td>
        </tr>
        <tr valign="top">
          <td>
            <form name="editdivision" action="<?php echo $WEB_ROOT; ?>/divisions.php">
              <input type="hidden" name="mode" value="edit">
              <select name="division_id" size="1">
                <option value="0"> -- Select One -- </option>
        <?php
        foreach($divisions as $division)
        {
		  $tmp_league = new OFFL_League($division->getLeagueID());
          ?>
                <option value="<?php echo $division->getDivisionID(); ?>"><?php echo $division->getDivisionDesc() . " (" . $tmp_league->getLeagueAbbv() .")"; ?></option>
          <?php
        }
        ?>
              </select>
              <input type="submit" value="Edit Division">
            </form>
          </td>
        </tr>
      </table>
	  <p><a href="<?php echo $WEB_ROOT; ?>/divisions.php?mode=admin&amp;showalldivisions=on">Edit All Divisions</a></p>
      <?php

  }
  else
  {
    if($_GET["mode"] == "edit")
    {
      if(isset($_GET["division_id"]))
      {
        $thisDivision = new OFFL_Division($_GET["division_id"]);
        if(!empty($thisDivision->_emsg))
        {
          ?><div class="alert"><?php echo $thisDivision->_emsg; ?></div><?php
        }
      }
      else
      {
        ?><div class="alert">No division id is set to edit.</div><?php
      }
    }

// $thisDivision variable contains what we need
?>
<form name="divisioninfo" action="<?php echo $WEB_ROOT; ?>/divisions.php">
    <?php if($_GET["mode"] == "edit") { ?>
  <input type="hidden" name="division_id" value="<?php echo $thisDivision->getDivisionID() ?>">
    <?php } ?>
  <input type="hidden" name="mode" value="<?php echo $_GET["mode"] ?>">
  <input type="hidden" name="type" value="<?php echo $type ?>">
  <input type="hidden" name="action" value="save">

  <table border="0">
    <tr>
      <th align="right">Division Name:</th>
      <td><input type="text" name="division_desc" size="20" maxlength="50"<?php if($_GET["mode"] == "edit") { ?> value="<?php echo $thisDivision->getDivisionDesc() ?>"<?php } ?>></td>
    </tr>
	<tr>
	  <th align="right">League:</th>
	  <td><select name="league_id">
        <option value="0"> -- Select One -- </option>
        <option value="0">&lt;&lt;No League&gt;&gt;</option>
<?php
		$leagues = $myleague->getAllLeagues();
		foreach ($leagues as $league)
		{
			echo "\t\t\t\t<option value=\"" . $league->getLeagueID() . "\"";
			if ($league->getLeagueID() == $thisDivision->getLeagueID())
			{	echo " selected";	}
			echo " >" . $league->getLeagueName() . "</option>\n";
		}
?>
	  </select></td>
    <tr>
      <th align="right">&nbsp;</th>
      <td colspan="2"><input type="submit" value="Save Division"></td>
    </tr>
  </table>

</form>
<?php
	if ($_SESSION["admin"] == 1)
	  {
?>
<form name="divisiondel" action="<?php echo $WEB_ROOT; ?>/divisions.php">
	<input type="hidden" name="action" value="delete" />
	<input type="hidden" name="division_id" value="<?php echo $thisDivision->getDivisionID(); ?>" />
I want to delete this division:	<input type="checkbox" name="confirm" />
	<input type="submit" value="Delete Division" />
</form>
<p>(Teams in this division must be reset manually)</p>
<?php	  }

  }
}

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