<?php
  /**************************************************************************\
  * phpGroupWare app (Bookkeeping)                                           *
  * http://www.phpgroupware.org                                              *
  * Written by Rick Bakker <r.bakker@linvision.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.                                              *
  \**************************************************************************/

  // HTTP_GET_VARS
  $order=$HTTP_GET_VARS['order'];
  $selected=$HTTP_GET_VARS['selected'];

  // HTTP_POST_VARS
  $submit=$HTTP_POST_VARS['submit'];
  $description=$HTTP_POST_VARS['description'];
  $income_expense=$HTTP_POST_VARS['income_expense'];

  if (!$submit=='')
  {
    $phpgw_info["flags"]["noheader"] = True;
    $phpgw_info["flags"]["nonavbar"] = True;
  }
  $phpgw_info["flags"]["currentapp"]="bookkeeping";
  include("../header.inc.php");
  include("inc/bookkeeping_header.inc.php");

  if(!$submit=='')
  {
    $sql="insert into phpgw_bk_categories (description,income_expense) values ('$description','$income_expense')";
    $phpgw->db->query($sql);
    header("Location: ".$phpgw->link("/bookkeeping/categories.php","selected=$selected&order=$order"));
  }
  else
  {
    $phpgw->template->set_file(array( "category_add" => "category_add.tpl"));

    $phpgw->template->set_var("header",$header);
    $phpgw->template->set_var("lang_app_title",lang("bookkeeping"));
    $phpgw->template->set_var("lang_title",lang("categories"));
    $phpgw->template->set_var("head_color","D3DCE3");

    if($selected=="expenses")
    {
      $lang_selected=lang("add_expense_category");
      $hidden_vars="<input type=\"hidden\" name=\"income_expense\" value=\"E\">";
    }
    else
    {
      $lang_selected=lang("add_income_category");
      $hidden_vars="<input type=\"hidden\" name=\"income_expense\" value=\"I\">";
    }

    $phpgw->template->set_var("hidden_vars",$hidden_vars);
    $phpgw->template->set_var("lang_selected",$lang_selected);

    $lang_description=lang("description");
    $description="<input type=\"text\" name=\"description\">";

    $phpgw->template->set_var("lang_description",$lang_description);
    $phpgw->template->set_var("description",$description);

    $phpgw->template->set_var("actionurl",$phpgw->link("/bookkeeping/category_add.php","selected=$selected&order=$order"));
    $phpgw->template->set_var("lang_add",lang("add"));
    $phpgw->template->parse("out", "category_add", true);
    $phpgw->template->p("out");
  }

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