Location: PHPKode > projects > Stack's Wiki > stacks-wiki-0.5.1/www/categories.php
<?
session_start();

require_once("includes/params.php");
require_once("includes/database.php");

?>
<html>
<head>
	<title><? echo $wiki_title ?> :: <?
		if (isset($_REQUEST["category"])) echo $_REQUEST["category"] . " Category";
		else echo "Categories";	?></title>
	<script type="text/javascript" src="scripts/prototype.js"></script>
	<script type="text/javascript" src="scripts/effects.js"></script>
	<script type="text/javascript" src="scripts/messages.js"></script>
	<script type="text/javascript" src="scripts/categories.js"></script>
	<link rel="stylesheet" href="styles/screen.css" type="text/css" />
	<!--[if gte IE 5.5000]>
	<style type="text/css">img { behavior: url('includes/pngbehavior.htc'); }</style>
	<![endif]-->
</head>
<body>
	
	<div id="navigation_panel">
		<a href="index.php" title="Home Page">Home Page</a> ::
		<a href="categories.php" title="Categories">Categories</a>
		<hr />
	</div>
	
	<div id="content_panel">
		<? 
		if (isset($_REQUEST["category"])) {
			if (file_exists("categories/" . $_REQUEST["category"] . ".png"))
			{
				$dimensions = getimagesize("categories/" . $_REQUEST["category"] . ".png");
				echo "<img class=\"category_image\" height=\"" . $dimensions[1] . "\" width=\"" . $dimension[0] . "\" src=\"categories/" . $_REQUEST["category"] . ".png\" />\n";
			}
		?>
		<h1><?echo $_REQUEST["category"] ?> Category</h1>
		<?
			$db = get_connection();
			$sql  = "SELECT * FROM `" . $database_prefix . "pages` WHERE `category` = '";
			$sql .= mysql_real_escape_string($_REQUEST["category"]) . "' ";
			$sql .= "ORDER BY `id`";
			$result = mysql_query($sql, $db);
			
			if (!$result)
			{
				echo "<p>\n";
				echo "\tAn error occurred attempting to pull the categories:\n";
				echo "\t<br />\n";
				echo mysql_error() . "\n";
				echo "</p>\n";
			}
			else if (mysql_num_rows($result) == 0)
			{
				echo "<p>\n";
				echo "\tThis category does not exist.  Please click on the Categories ";
				echo "link above and select an appropriate page.\n";
				echo "</p>\n";
			}
			else
			{
				echo "<p>\n";
				echo "\tBelow are all of the pages for the " . $_REQUEST["category"] . " category.\n";
				echo "\tIf you would like to pick another category, either click the Categories link above,\n";
				echo "\tor pick a category from the bottom of the page.\n";
				echo "</p>\n";
				echo "<ul class=\"category_list\">\n";
				
				while ($row = mysql_fetch_assoc($result))
				{
					echo "\t<li>\n";
					echo "\t\t<a href=\"index.php?id=" . rawurlencode(html_entity_decode($row["id"])) . "\" class=\"page_exists\">";
					echo $row["id"] . "</a>\n";
					echo "\t</li>\n";
				}
				
				echo "</ul>\n";
			?>
			<h2>Other Categories</h2>
			<?
				$sql  = "SELECT DISTINCT(`category`) FROM `" . $database_prefix . "pages` WHERE `category` <> '";
				$sql .= mysql_real_escape_string($_REQUEST["category"]) . "' ORDER BY `category`";
				$result = mysql_query($sql, $db);
				
				if (!$result)
				{
					echo "<p>\n";
					echo "\tAn error occurred attempting to pull the categories:\n";
					echo "\t<br />\n";
					echo mysql_error() . "\n";
					echo "</p>\n";
				}
				else if (mysql_num_rows($result) == 0)
				{
					echo "<p>none...</p>\n";
				}
				else
				{
					$list = array();
					while ($row = mysql_fetch_assoc($result))
					{
						$list[] = "<a href=\"categories.php?category=" . rawurlencode(html_entity_decode($row["category"])) . "\" class=\"page_exists\"> " . $row["category"] . "</a>";
					}
				
					echo "<p>" . implode(", ", $list) . "</p>";
				}
			}
			mysql_close($db);
		} else { 
		?>
		<h1>Categories</h1>
		<?
			$db = get_connection();
			$sql  = "SELECT * FROM `" . $database_prefix . "pages` ORDER BY `category`, `id`";
			$result = mysql_query($sql, $db);
			
			if (!$result)
			{
				echo "<p>\n";
				echo "\tAn error occurred while retrieving the categories: ";
				echo mysql_error() . "\n";
				echo "</p>\n";
			}
			else if (mysql_num_rows($result) == 0)
			{
				echo "<p>\n";
				echo "\tThere are no pages in this wiki.  Click on the Home Page";
				echo " link above and start creating some pages.\n";
				echo "</p>\n";
			}
			else
			{
				echo "<p>\n";
				echo "\tBelow are all of the pages separated by their categories.  All dangling links are \n";
				echo "\tgrouped together at the bottom of the page.\n";
				echo "</p>\n";
				
				$last = "";
				$first = true;
				while ($row = mysql_fetch_assoc($result))
				{
					if ($last != $row["category"])
					{
						if (!$first) echo "</ul>\n";
						else $first = false;
						
						echo "<h2>" . $row["category"] . "</h2>\n";
						echo "<ul class=\"category_list\">\n";
						
						$last = $row["category"];
					}
					
					echo "\t<li>\n";
					echo "\t\t<a href=\"index.php?id=" . rawurlencode(html_entity_decode($row["id"])) . "\" class=\"page_exists\">";
					echo $row["id"] . "</a>\n";
					echo "\t</li>\n";
				}
				echo "</ul>\n";
				
				$sql = "SELECT DISTINCT `link_id` FROM `" . $database_prefix . "links` WHERE `exists` = 0 ORDER BY `link_id`";
				$result = mysql_query($sql, $db);
				
				if (!result)
				{
					echo "<p>\n";
					echo "\tError getting dead links: " . mysql_error() . "\n";
					echo "</p>\n";
				}
				else if  (mysql_num_rows($result) != 0)
				{
					echo "<h2>Dead Links</h2>\n";
					echo "<ul class=\"category_list\">\n";
					while ($row = mysql_fetch_row($result))
					{
						echo "<li><span class=\"missing\">" . $row[0] . "</span>";
						echo "<a href=\"index.php?id=" . rawurlencode(html_entity_decode($row[0])) . "\" ";
						echo "class=\"page_missing\">?</a></li>\n";
					}
					echo "</ul>\n";
				}
					
			}
			
			mysql_close($db);
		?>
		<? } ?>
		<hr />
	</div>
	
	<div id="message_panel"></div>
	
	<div id="control_panel">
	
		<span id="default_controls" style="display: <? echo isset($_SESSION[logged_in]) ? "none" : "inline" ?>">
			<a href="#" id="show_login" title="Login">Login</a>
		</span>
		
		<span id="login_controls" style="display: none">
			<input type="password" id="password" />
			<a href="#" id="login" title="Login">Login</a> ::
			<a href="#" id="cancel_login" title="Cancel">Cancel</a>
			<span id="login_wait" style="display: none">Please wait...</span>
		</span>
		
		<span id="main_controls" style="display: <? echo isset($_SESSION[logged_in]) ? "inline" : "none" ?>">
			<a href="#" id="add_page" title="Add Page">Add A Page</a> ::
			<a href="#" id="logout" title="Log Out">Log Out</a>
			<span id="main_wait" style="display: none">Please wait...</span>
		</span>

		<span id="add_controls" style="display: none">
			<input type="text" id="new_page" />
			<a href="#" id="go_to" title="Go To This Page">Go To This Page</a> ::
			<a href="#" id="cancel_add" title="Cancel">Cancel</a>
			<span id="add_wait" style="display: none">Please wait...</span>
		</span>
	</div>

</body>
</html>
Return current item: Stack's Wiki