<?php
  /**************************************************************************\
  * phpGroupWare - Brewer add x                                              *
  * http://www.phpgroupware.org                                              *
  * Written by Miles Lott <milosch@phpgroupware.org>                         *
  * -----------------------------------------------                          *
  *  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: add.php,v 1.2 2001/09/11 12:38:28 milosch Exp $ */

	$GLOBALS['phpgw_info']['flags'] = array(
		'currentapp' => 'brewer',
		'noheader'   => True,
		'nonavbar'   => True
	);
	include('../header.inc.php');

	if (!$type || $cancel)
	{
		$redir = $type .'s.php';
		if (file_exists(PHPGW_APP_ROOT . SEP . $type . 'es.php'))
		{
			$redir = $type .'es.php';
		}
		Header('Location: ' . $GLOBALS['phpgw']->link('/brewer/' . $redir));
	}

	$GLOBALS['phpgw']->template->set_file(array('form' => 'edit_' . $type . '.tpl'));
	$GLOBALS['phpgw']->template->set_block('form','header','header');
	$GLOBALS['phpgw']->template->set_block('form','body','body');
	$GLOBALS['phpgw']->template->set_block('form','footer','footer');

	$hidden_vars =
		  '<input type="hidden" name="sort"   value="' . $sort   . '">' . "\n"
		. '<input type="hidden" name="order"  value="' . $order  . '">' . "\n"
		. '<input type="hidden" name="type"   value="' . $type   . '">' . "\n"
		. '<input type="hidden" name="query"  value="' . $query  . '">' . "\n"
		. '<input type="hidden" name="start"  value="' . $start  . '">' . "\n"
		. '<input type="hidden" name="filter" value="' . $filter . '">' . "\n"
		. '<input type="hidden" name="id"     value="' . $id     . '">' . "\n";

	$b = CreateObject('brewer.brew');
	$add = $b->$type->data;

	if ($submit)
	{
		$b->$type->$type = $b->$type->data;
		$add = $b->$type->$type;
		while (list($key,$val) = @each($newsettings))
		{
			$add[$key] = $val;
		}
		$b->$type->$type = $add;
		$b->$type->set();
	}

	$GLOBALS['phpgw']->template->set_var('title',lang('Add') . ' ' . lang(ucfirst($type)));
	$GLOBALS['phpgw']->template->set_var('action_url',$GLOBALS['phpgw']->link('/brewer/add.php'));
	$GLOBALS['phpgw']->template->set_var('lang_submit',lang('submit'));
	$GLOBALS['phpgw']->template->set_var('lang_cancel',lang('Cancel'));
	$GLOBALS['phpgw']->template->set_var('hidden_vars',$hidden_vars);
	/* Themes and colors */
	$GLOBALS['phpgw']->template->set_var('th_bg',$GLOBALS['phpgw_info']['theme']['th_bg']);
	$GLOBALS['phpgw']->template->set_var('th_text',$GLOBALS['phpgw_info']['theme']['th_text']);
	$GLOBALS['phpgw']->template->set_var('row_on',$GLOBALS['phpgw_info']['theme']['row_on']);
	$GLOBALS['phpgw']->template->set_var('row_off',$GLOBALS['phpgw_info']['theme']['row_off']);

	$vars = $GLOBALS['phpgw']->template->get_undefined('body');
	while (list($null,$value) = each($vars))
	{
		$valarray = explode('_',$value);
		$type = $valarray[0];
		$new = $newval = '';

		while($chunk = next($valarray))
		{
			$new[] = $chunk;
		}
		$newval = implode(' ',$new);

		switch ($type)
		{
			case "lang":
				$GLOBALS['phpgw']->template->set_var($value,lang($newval));
				break;
			default:
				$GLOBALS['phpgw']->template->set_var($value,'');
				break;
		}
	}

	$GLOBALS['phpgw']->common->phpgw_header();
	echo parse_navbar();

	$GLOBALS['phpgw']->template->pfp('out','header');
	$GLOBALS['phpgw']->template->pfp('out','body');
	$GLOBALS['phpgw']->template->pfp('out','footer');

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