<?php
  /**************************************************************************\
  * phpGroupWare - Inventory                                                 *
  * (http://www.phpgroupware.org)                                            *
  * Written by Bettina Gille [ceb@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: deletecategory.php,v 1.17 2001/05/12 02:41:55 bettina Exp $ */

    if (! $cat_id) { Header('Location: ' . $phpgw->link('/inv/index.php')); }

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

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

    $c = CreateObject('phpgwapi.categories');

    if ($confirm)
    {
        if ($subs) { $c->delete($cat_id,'True'); }
        else { $c->delete($cat_id); }
	Header('Location: ' . $phpgw->link('/inv/index.php'));
    }
    else 
    {
	$hidden_vars = "<input type=\"hidden\" name=\"cat_id\" value=\"$cat_id\">\n";
	$t = CreateObject('phpgwapi.Template',PHPGW_APP_TPL);
	$t->set_file(array('category_delete' => 'delete_cat.tpl'));
	$t->set_var('deleteheader',lang('Are you sure you want to delete this category ?'));
	$t->set_var('hidden_vars',$hidden_vars);
	$exists = $c->exists('subs',$cat_name='',$cat_id);

	if ($exists==True)
	{
    	    $t->set_var('lang_subs',lang('Do you also want to delete all subcategories ?'));
    	    $t->set_var('subs','<input type="checkbox" name="subs" value="True">');
	}
	else
	{
    	    $t->set_var('lang_subs','');
    	    $t->set_var('subs', '');
	}

	$t->set_var('nolink', $phpgw->link('/inv/index.php',"cat_id=$cat_id"));
	$t->set_var('lang_no',lang('No'));

	$t->set_var('action_url',$phpgw->link('/inv/deletecategory.php',"cat_id=$cat_id"));
	$t->set_var('lang_yes',lang('Yes'));
	$t->pparse('out','category_delete');
    }

    $phpgw->common->phpgw_footer();
?>
