Location: PHPKode > projects > Online Fantasy Football League > offl-0.2.6/www/controls.php
<?php
/**
 * League Controls editor
 *
 * Needs work for custom values in particular
 *
 * @author Stephen Rochelle <hide@address.com>
 * @version OFFL v0.2
 * @copyright Copyright (c) 2004 Stephen Rochelle.  Some rights reserved.
 * @package offl-ui
 */

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

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

// user is saving info (edit or add)
if($_GET["action"] == "save")
{
  // Populate fields with form data
  $control->setValue($_GET["k"],$_GET["v"]);
//  $control->save();
?><div class="success">Control keys successfully saved.</div><p>
<META http-equiv="refresh" content="1; URL=<?php echo "$WEB_ROOT/controls.php?mode=admin" ?>"><?php
}
else
{

  if(($_GET["mode"] == "display") || (!isset($_GET["mode"])))
  {
    ?>
    <table id="controls">
      <tr>
        <th>Control Key</th>
        <th>Control Value</th>
      </tr>
      <?php // for loop of all controls
      $controls = $control->getAllControlKeys();

      foreach($controls as $c=>$key)
      {
		if (isset($_GET["view"]))
		  {
			if (stristr($key, $_GET["view"]) === FALSE)
				continue;
		  }
		  else
		  {
			if ( (stristr($key, "CONFIG") === FALSE) && (stristr($key, "SCORING") === FALSE) )
				continue;
		  }

        ?>
        <tr class="<?php if ($c % 2) echo "evenrow"; else echo "oddrow"; ?>">
          <td style="width:350px;"><?php echo $control->getDescription($key); ?></td>
          <td style="width:150px;"><?php echo $control->getValue($key); ?></td>
        </tr>
        <?php
      }
      ?>
    </table>
    <?php
  }
  if($_GET["mode"] == "admin")
  {
    // Display page of all controls (maybe drop-down) and a button to go to "Edit" form
    ?>
    <table id="controls">
      <tr>
        <th></th>
        <th>Control Key</th>
        <th>Control Value</th>
		<th>Control Description</th>
      </tr>
      <?php // for loop of all controls
      $controls = $control->getAllControlKeys();

		if (isset($_GET["view"]))
		{	$_GET["view"] = strtoupper($_GET["view"]);	}

      foreach($controls as $c => $key)
      {
		if (isset($_GET["view"]))
		  {
			if (strpos($key, $_GET["view"]) !== 0)
				continue;
		  }
        ?>
        <tr class="<?php if ($c % 2) echo "evenrow"; else echo "oddrow"; ?>">
          <td><strong><a class="red" href="<?php echo $WEB_ROOT; ?>/controls.php?mode=edit&k=<?php echo $key ?>">[EDIT]</a></strong></td>
          <td><?php echo $key ?></td>
          <td style="width: 150px;"><?php echo $control->getValue($key) ?></td>
		  <td style="width: 300px;"><?php echo $control->getDescription($key); ?></td>
        </tr>
        <?php
        $c++;
      }
      ?>
    </table>
    <?php
  }
  elseif($_GET["mode"] == "edit")
  {
  ?>
  <form name="editcontrol" action="<?php echo $WEB_ROOT; ?>/controls.php">
    <input type="hidden" name="mode" value="$_GET[mode]">
    <input type="hidden" name="action" value="save">
    <input type="hidden" name="k" value="<?php echo $_GET["k"] ?>">
    
    <table border="0">
      <tr valign="top">
        <th align="left">Control Key</th>
        <th align="left">Control Value</th>
        <th align="left"></th>
      </tr>
      <tr valign="top">
        <td><?php echo $_GET["k"] ?></td>
<?php
	$vals = $control->getAllowedValues($_GET["k"]);
	if (is_null($vals))
	  {
?>
        <td><input type="text" name="v" value="<?php echo $control->getValue($_GET["k"]);?>" maxlength="80"></td>
<?php } else { 

		echo "<td>";
		echo "<select name=\"v\">\n";

		foreach ($vals as $val)
		{
			echo "	<option value=\"$val\"";
			if ($val == $control->getValue($_GET["k"]) )
				echo " selected";
			echo ">$val</option>\n";
		}

		echo "</select>\n";
		echo "</td>\n";

		} ?>
        <td><input type="submit" value="Save Control"></td>
      </tr>
    </table>
  </form>
  <?php
  }
  else
  {
    // Invalid mode
  }
}

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