Source

Selador / hilfe.php

Full commit
<?php
/* hilfe.php - Front-end for the "Hilfe" page
 *
 * Copyright (C) 2005, 2006, 2007, 2008   Angel Stoitsov, Mario Stoitsov, Kevin Read, Simone Schaefer
 *
 * This file is part of Selador, a browser-based fantasy strategy game
 * It is based on EasyPHPTree by Angel Stoitsov and Mario Stoitsov which
 * is licensed under the GPL.
 *
 * This program is distributed under the terms of the GNU Affero General Public License.
 *
 *
 *   Selador is free software: you can redistribute it and/or modify
 *   it under the terms of the GNU Affero General Public License as published by
 *   the Free Software Foundation, either version 3 of the License, or
 *   any later version.
 *
 *   Selador is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU Affero General Public License for more details.
 *
 *   You should have received a copy of the GNU Affero General Public License
 *   along with Selador.  If not, see <http://www.gnu.org/licenses/>.
 **/

header ("Content-Type: text/html; charset=UTF-8");
require_once ("php/base/config.inc.php");
require_once ("php/base/user.inc.php");
/* require_once ("php/base/eventmap.php"); */

session_start();
?>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
<title>Selador Online-Hilfe</title>
<link rel="stylesheet" type="text/css" href="styles/hilfe.css"/>
</head>
<body>
<div id="rahmen1" class="inhalt" style="overflow:auto">
<?php
// functions
function printAd()
{
	echo "<div id=\"help-ad\">\n";
	echo "<script src=\"http://www.mmogtrade.de/script.php?id=268&pixel=468x60\"></script>\n";
	echo "<noscript>\n";
	echo "<a href=\"http://www.mmogtrade.de/klick.php?id=268&pixel=468x60&url=noscript\" target=\"_blank\">\n";
	echo "<img src=\"http://www.mmogtrade.de/banner.php?id=268&pixel=468x60&url=noscript\" border=\"0\">\n";
	echo "</a>\n";
	echo "</noscript>\n";
	echo "</div>\n";
}

function printAdminTool ($Page)
{
	echo "<div id=\"admin\">\n";
	echo "<form action=\"hilfe.php\" action=\"POST\"><input type=\"hidden\" name=\"Page\" value=\"".(int)$Page."\">\n";
	echo "Admin: Tochterseite anlegen: <input name=\"new\" size=\"15\"><br>\n";
	echo "Admin: Seite umbenennen: <input name=\"rename\" size=\"15\"><br>\n";
	echo "Admin: Seite <a href=\"hilfe.php?Page=".(int)$Page."&del=1\">l&ouml;schen</a> (geht nur, wenn die Seite keine T&ouml;chter hat)<br>\n";
	echo "<input type=\"submit\" name=\"go\" value=\"Jau\"></form>\n";
	echo "</div>\n";
}

define ("OPEN_FOLDER", "<img src='gfx/fo.gif' width='20' height='20' alt=\"-\" />\n");
define ("FOLDER", "<img src='gfx/f.gif' width=20 height=20 alt=\"+\" />\n");

// ********************************
// EsayPHPtree functions (73 lines)
// ********************************
function MakeTree(&$Page,&$Name)
{
	$MyqslTable = "helptree";
	$usage = "PublicUse=0 Or PublicUse=1";
	$result = mysql_query ("SELECT * FROM ".$MyqslTable." WHERE ".$usage." Order by Name");

	if (@mysql_num_rows ($result) == 0)
		return "<div align=center>No Folders Available</div>\n";

	while ($currFolder = list ($ID,$Name,$Description,$CreateUser,$CreateDate,$ModifyDate,$LastVisit,$Parent,$PublicUse) = mysql_fetch_array ($result))
	{
		$currFolder["Name"] = stripslashes ($currFolder["Name"]);
		$table[$Parent][$ID] = stripslashes ($Name);
		$partable[$ID] = $Parent;
		$Folder[$ID] = $currFolder;
	};

	unset ($currFolder);

	$levels = TreeLevels (0,$table,0);

	if (!isset ($Folder[$Page]["Name"]))
		$Folder[$Page]["Name"] = "&Uuml;berblick";

	$Name = $Folder[$Page]["Name"];

	if ($Page == 0)
	{
		if (!isset ($_SESSION["expandtree"]))
			$_SESSION["expandtree"] = 1;

		$_SESSION["expandtree"] = -$_SESSION["expandtree"];

		if ($_SESSION["expandtree"] < 0)
			$levelexpand = 1;
		else
			$levelexpand = 100000;

		$results = OPEN_FOLDER
			."<span style='height: 20px; font: 11px Arial, Helvetica; font-weight:bold;'>"
			."&nbsp;<a href='?Page=0'>&Uuml;berblick</a></span><br/>\n";

		$results .= TreeExpand(0,$table,$partable,$Folder,$Page,0,$levelexpand);
	}
	else
	{
		$results = FOLDER
			."<span style='height: 20px; font: 11px Arial, Helvetica;'>"
			."&nbsp;<a href='?Page=0'>&Uuml;berblick</a></span><br/>\n";

		$ID = $Page;

		$results .= TreeNodes($ID,$table,$partable,$Folder,$Page,$levels);
		$_SESSION["expandtree"] = 1;
	}

 return $results."</div>\n";
}

function TreeLevels($Parent,$table,$level)
{
	$_SESSION["levels"][$Parent] = $level;

	while (list ($key,$val) = each ($table[$Parent]))
	{
		if (isset ($table[$key]))
		{
			TreeLevels ($key,$table,$level+1);
		}
	}

 	return $_SESSION["levels"];
}

function TreeNodes($ID,$table,$partable,$Folder0,$Page,$levels)
{
	$rez0 = "";
	$imgfolder0 = FOLDER."&nbsp;<span style='height: 20px; font: 11px Arial, Helvetica;'>\n";

	$imgfolder1 = OPEN_FOLDER
		."&nbsp;<span style='height: 20px; font: 11px Arial, Helvetica; font-weight:bold;'>\n";

	if ( isset($table[$ID]))
	{
		$imgwidth = "<img src='gfx/tr.gif' width='".(($levels[$ID]+1)*10)."' height='1' alt=''>\n";
		$lisd = $table[$ID];
		$ID0 = $ID;
		$fiplevel = $levels[$ID];

		while (list ($key,$val) = each ($lisd))
		{
			if ($Page == $key)
			{
				$rez0 .= $imgwidth.$imgfolder1;
			}
			else
			{
				$rez0 .= $imgwidth.$imgfolder0;
			}
			$rez0 .= "<a href='?Page=".$Folder0[$key]["ID"]."'>".$Folder0[$key]["Name"]."</a></span><br/>\n";
		}
	}

	$res = "";

	while ($ID != 0)
	{
		$fip = $partable[$ID];
		$fiplevel = $levels[$fip];
		$fiplist = $table[$fip];
		$imgwidth = "<img src='gfx/tr.gif' width='".(($fiplevel+1)*10)."' height='1' alt=''>";
		$rez = "";

    while (list ($key,$val) = each ($fiplist))
    {
			if($Page == $key)
			{
				$rez .= $imgwidth.$imgfolder1."<a href='?Page=".$Folder0[$key]["ID"]."'>".$Folder0[$key]["Name"]."</a></span><br/>\n".$rez0;
			}
			else
			{
				$rez .= $imgwidth.$imgfolder0."<a href='?Page=".$Folder0[$key]["ID"]."'>".$Folder0[$key]["Name"]."</a></span><br/>\n";
			}

			if ($ID == $key)
			{
				$rez .= $res;
				$res = "";
			}
		}

		$res .= $rez;
		$ID = $partable[$ID];
	}

	return $rez;
}

function TreeExpand ($Parent,$table,$partable,$Folder0,$Page,$level,$levelexpand)
{
	$list = $table[$Parent];
	$width = ($level + 1) * 10;
	$result = '';

	while (list ($key,$val) = each($list))
	{
		if($level < $levelexpand)
		{
			$result .= "<img src='gfx/tr.gif' width='".$width."' height='1'>"
				."<img src='gfx/f.gif'><span style='height: 20px; font: 11px Arial, Helvetica;'>"
				."&nbsp;"
				."<a href='?Page=".$Folder0[$key]["ID"]."'>"
				.$Folder0[$key]["Name"]."</a></span><br>\n";
		}

 		if (isset($table[$key]))
 		{
 			$result .= TreeExpand ($key,$table,$partable,$Folder0,$Page,$level+1,$levelexpand);
 		}
	}

 return $result;
}

$gamedb = new GameDB;

if (isset ($_REQUEST['Page']))
	$Page = (int)$_REQUEST['Page'];
else
	$Page = 0;

if (isset ($_REQUEST['rp']))	// research page search
  $pagesearch = (int)$_REQUEST['rp'] + 20000;

if (isset ($_REQUEST['up']))	// unit page search
  $pagesearch = (int)$_REQUEST['up'] + 30000;

if (isset ($_REQUEST['bp']))	// building page search
  $pagesearch = (int)$_REQUEST['bp'] + 10000;

if (isset ($pagesearch))
{
  $query = "select ID from helptree where CreateUser=".$pagesearch;
	// echo $query;

  if (($res = mysql_query ($query)))
  {
    if ($row = mysql_fetch_row ($res))
      $Page = $row[0];
  }
}

$Name = "";

if ($_SESSION['is_admin'])
{
	$me = $_SESSION['me'];
	$nope = false;

	if (isset ($_REQUEST['go']))
	{
		if (isset ($_REQUEST['new']) && (strlen ($_REQUEST['new']) >= 4))
		{
				$query = "insert into helptree (ID,Name,CreateUser,CreateDate,ModifyDate,LastVisit,Parent,PublicUse)"
					." VALUES  (Null, '".mysql_real_escape_string ($_REQUEST['new'])."',".$me->uid.", now(), now(), now(), ".$Page.", 0)";

				echo "creating: ".$query."...";

				if (mysql_query ($query))
					echo " done<br/>\n";
				else
					echo " error ".mysql_error ()."<br/>\n";
		}
		else
			$nope = true;

		if ($nope)
		{
			$nope = false;
			if (isset ($_REQUEST['rename']))
			{
				if (strlen ($_REQUEST['rename']))
				{
					$query = "update helptree set Name='".mysql_real_escape_string ($_REQUEST['rename'])."' where ID=".$Page;
					echo $query;

					if (!mysql_query ($query))
						echo "Ging nicht :(";
				}
				else
					$nope = true;
			}
			else
				$nope = true;

		}
	}
	else
	{
		if (isset ($_REQUEST['del']))
	  {
			$query = "delete from helptree where ID=".$Page;
			mysql_query ($query);
		}
	}
}

echo MakeTree($Page, $Name);
?>

<div id="rahmen2" class="inhalt">
<div id="header"></div>
<div id="text">
<?php
if (file_exists ("help/".$Page))
{
	require_once ("help/".$Page);
}
else
{
	if (file_exists ("var/help/auto/".$Page))
		require_once ("var/help/auto/".$Page);
	else
		echo "Diese Seite existiert nicht...";
}
?>
</div>

<?php
printAd();

if ($_SESSION['is_admin'])
{
	printAdminTool ($Page);
}
?>
</div>
</body>
</html>