<?php
	/**************************************************************************\
	* phpGroupWare - Inventory                                                 *
	* http://www.phpgroupware.org                                              *
	* This file written by Joseph Engo <jengo@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: addstatus.php,v 1.14.2.1 2003/02/01 21:21:02 gugux Exp $ */

	if ($submit)
	{
		$phpgw_info['flags'] = array('noheader' => True,    
									'nonavbar' => True);
	}

	$phpgw_info['flags']['currentapp'] = 'inv';
	include('../header.inc.php');

	$t = CreateObject('phpgwapi.Template',PHPGW_APP_TPL);
	$t->set_file(array('form' => 'status_form.tpl'));

	if ($submit)
	{
		$status_name = addslashes($status_name);
		$phpgw->db->query("select count(*) from phpgw_inv_statuslist where status_name='$status_name'");
		$phpgw->db->next_record();

		if ($phpgw->db->f(0) != 0)
		{
			$error = lang('That name has been used already !');
		}
		else
		{
			$phpgw->db->query("insert into phpgw_inv_statuslist (status_name) values ('$status_name')");
			Header('Location: ' . $phpgw->link('/inv/liststatus.php','lm=statusadded'));
			$phpgw->common->phpgw_exit();
		}
	}

	if ($error)
	{
		$phpgw->common->phpgw_header();
		echo parse_navbar();
		$t->set_var('message',$error);
		$t->set_var('status_name',$status_name);
	}
	else
	{
		$t->set_var('message','');
	}

	$t->set_var('lang_action',lang('Add product status'));
	$t->set_var('form_action',$phpgw->link('/inv/addstatus.php'));
	$t->set_var('lang_name',lang('Name'));
	$t->set_var('status_name',$status_name);
	$t->set_var('lang_submit',lang('Add'));

	$t->pparse('out','form');
	$phpgw->common->phpgw_footer();
?>
