<?php
	/*****************************************************************************\
	* phpGroupWare - Forums                                                       *
	* http://www.phpgroupware.org                                                 *
	* Written by Jani Hirvinen <jpkh@shadownet.com>                               *
	* -------------------------------------------                                 *
	*  This program is free software; you	can redistribute it and/or modify it   *
	*  under the terms of	the GNU	General	Public License as published by the  *
	*  Free Software Foundation; either version 2	of the License,	or (at your *
	*  option) any later version.                                                 *
	\*****************************************************************************/

	/* $Id: preference_index.php 21086 2010-03-25 22:56:09Z Caeies $ */

	$GLOBALS['phpgw_info']['flags'] = array(
						'currentapp'		=> 'forum',
						'enable_nextmatchs_class' => True
						);
	include_once('../header.inc.php');

?>

	<p>
	<table border="0" width=100%>
	<tr>
<?php 
	echo "<td bgcolor=\"" . $phpgw_info["theme"]["th_bg"] . "\" align=\"left\"><b>" . lang("Forums") . " " . lang("Admin") . "</b></td>" . "</tr>"; 
?>

	<tr>
	<td>
	<font size=-1>
<?php
	echo "<a href=\"" . $GLOBALS['phpgw']->link("/forum/preference_category.php") . "\">" . lang("New Category") ."</a>";
	echo " | ";
	echo "<a href=\"" . $GLOBALS['phpgw']->link("/forum/preference_forum.php") . "\">" . lang("New Forum") ."</a>";
	echo " | ";
	echo "<a href=\"" . $GLOBALS['phpgw']->link('/forum/index.php') . "\">" . lang("Return to Forums") ."</a>";
?>
	</font>
	<br><br>
	<center>
	<table border="0" width=80% bgcolor="<?php echo $phpgw_info["theme"]["table_bg"]?>">
	<tr>
	<td colspan=3 bgcolor="<?php echo $phpgw_info["theme"]["th_bg"]?>">
	<center><?php echo lang("Current Categories and Sub Forums")?></center>
	</td>
	</tr>
	<tr>
	<td>
	</td>
	</tr>
<?php
	$f_tree = array();
	$GLOBALS['phpgw']->db->query('SELECT * FROM f_categories', __LINE__, __FILE__);
	while($GLOBALS['phpgw']->db->next_record())
	{
		$f_tree[$GLOBALS['phpgw']->db->f('id')] = array(
								'name'	=> $GLOBALS['phpgw']->db->f('name'),
								'descr'	=> $GLOBALS['phpgw']->db->f('descr'),
								'forums'=> array()
								);
	}
	$GLOBALS['phpgw']->db->query('SELECT * FROM f_forums', __LINE__, __FILE__);
	while($GLOBALS['phpgw']->db->next_record())
	{
		$f_tree[$GLOBALS['phpgw']->db->f('cat_id')]['forums'][$GLOBALS['phpgw']->db->f('id')] = array(
														'name'	=> $GLOBALS['phpgw']->db->f('name'),
														'descr'	=> $GLOBALS['phpgw']->db->f('descr')
														);
	}
	$id = intval($_REQUEST['id']);
	ksort($f_tree);
	foreach ( $f_tree as $ft )
	{
		if($id > 0)
		{
			echo "<tr><td></td></tr>";
			echo "<tr bgcolor=\"" . $phpgw_info["theme"]["bg06"] . "\">\n";
			echo " <td valign=top align=left width=20%>" . $ft['name'] . "</td>\n";
			echo " <td valign=top align=left width=70%>" . $ft['descr'] . "</td>\n";
			echo "   <td nowrap><a href=\"" . $GLOBALS['phpgw']->link('/forum/preference_category.php', array('act' => 'edit', 'cat_id' => $id)) ."\">" . lang("Edit") . "</a> | ";
			echo "<a href=\"" . $GLOBALS['phpgw']->link('/forum/preference_deletecategory.php', array('cat_id' => $id)) . "\">" . lang("Delete") . "</a></td>\n";
			echo "</tr>\n";
			echo "<tr>\n";
			echo " <td colspan=3 align=right valign=top>\n";
			echo "<table border=0 width=95%>\n";
		}
		else
		{
			echo "<tr>\n";
			echo " <td colspan=3 align=right valign=top>\n";
			echo "<table border=0 width=100%>\n";
		}

		$tr_color = $phpgw_info["theme"]["row_off"];

		foreach ( $f_tree[$id]["forums"] as $fid => $forum )
		{
			$tr_color = $GLOBALS['phpgw']->nextmatchs->alternate_row_color($tr_color);
			echo "  <tr bgcolor=\"$tr_color\">\n";
			echo "   <td width=20%>" . $forum['name'] . "</td>\n";
			echo " <td valign=top align=left width=70%>". $forum['descr'] . "</td>\n";
			echo "   <td nowrap><a href=\"" . $GLOBALS['phpgw']->link("/forum/preference_forum.php","act=edit&for_id=$fid") ."\">" . lang("Edit") . "</A> | ";
			echo "<A href=\"" . $GLOBALS['phpgw']->link('/forum/preference_deleteforum.php', array('for_id' => $fid) ) . "\">" . lang("Delete") . "</A></td>\n";
			echo "  </tr>\n";
		}
		echo "  </table>\n";
		echo " </td>\n";
		echo "</tr>\n";
	}
	?>
	</td>
	</tr>
	</table>
	<br>


	<br><br>
	</center>
	</td>
	</tr>
	</table>
<?php

	echo "</center>";
	$GLOBALS['phpgw']->common->phpgw_footer();
?>

