<?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_category.php,v 1.4.4.1 2005/06/02 12:51:27 skwashd Exp $ */

	$GLOBALS['phpgw_info'] = array();
	$GLOBALS['phpgw_info']['flags'] = array();
	$GLOBALS['phpgw_info']['flags']['currentapp'] = 'forum';
	if($_REQUEST['action'])
	{
		$GLOBALS['phpgw_info']['flags']['noheader'] = True;
		$GLOBALS['phpgw_info']['flags']['nonavbar'] = True;
	}
	include_once('../header.inc.php');

	$actiontype = 'addcat';
	$buttontext = lang('Add Category');
	$extrahidden = '';
	$db =& $GLOBALS['phpgw']->db;
	$cat_id = intval($_REQUEST['cat_id']);

	if($_REQUEST['act'] == 'edit')
	{
		$newold = lang('Update Category');
		$db->query("SELECT * FROM f_categories WHERE id = $cat_id", __LINE__, __FILE__);
		if( !$db->next_record() )
		{
			print "Error in reading database<br>\n";
			$GLOBALS['phpgw']->common->phpgw_exit();
		}
		else
		{
			$catname = $db->f('name');
			$catdescr = $db->f('descr');
			$cat_id = $db->f('id'); 

			$extrahidden = "<input type=\"hidden\" name=\"cat_id\" value=\"$cat_id\">"; 
			$buttontext = lang("Update Category");
			$actiontype = "updcat";
		}
	}
	else
	{
		$newold = lang('Create New Category');
	}

	if($_REQUEST['action'])
	{
		if($_REQUEST['action'] == 'addcat')
		{
			if(!$db->query("INSERT INTO f_categories(name, descr) VALUES('" 
					. $db->db_addslashes($catname) . "', '" . $db->db_addslashes($catdescr) . "')")) {
				print "Error in adding forum to database<br>\n";
				$GLOBALS['phpgw']->common->phpgw_exit();
			}
			else
			{
				$GLOBALS['phpgw']->redirect_link('/forum/index.php');
				$GLOBALS['phpgw']->common->phpgw_exit();
			}
		}
		elseif ($_REQUEST['action'] == 'updcat' && $cat_id)
		{
			if(!$db->query("UPDATE f_categories SET name = '" . $db->db_addslashes($_REQUEST['catname']) 
					. "', descr = '" . $db->db_addslashes($_REQUEST['catdescr']) . "' WHERE id = $cat_id"))
			{
				echo "Error in adding forum to database<br>\n";
				$GLOBALS['phpgw']->common->phpgw_exit();
			}
			else
			{
				$GLOBALS['phpgw']->redirect_link('/forum/index.php');
				$GLOBALS['phpgw']->common->phpgw_exit();
			}

		}
	} 
?>

	<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/preference_index.php") . "\">" . lang("Return to Admin") ."</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=2 bgcolor="<?php echo $phpgw_info["theme"]["th_bg"]?>">
	<center><?php echo $newold?></center>
	</td>
	</tr>
	<tr>
	<form method="POST" action="<?php echo $GLOBALS['phpgw']->link("/forum/preference_category.php"); ?>">
	<?php echo $extrahidden; ?> 
	<input type="hidden" name="action" value="<?php echo $actiontype?>">
	<td><?php echo lang("Category Name") ?>:</td>
	<td><input type="text" name="catname" size=40 maxlength=49 value="<?php echo $catname ?>"></td>
	</tr>  
	<tr>
	<td><?php echo lang("Category Description") ?>:</td>
	<td><textarea rows="3" cols="40" name="catdescr" virtual-wrap maxlength=240><?php echo $catdescr ?></textarea></td>
	</tr>
	<tr><td colspan=2 align=right><input type="submit" value="<?php echo $buttontext ?>"></td></tr>

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

	</tr>
	</table>
	</center>
	<br>




	</td>
	</tr>
	</table>


	<?php
	$GLOBALS['phpgw']->common->phpgw_footer();
	?>
