<?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'];
  $catgory_id=$HTTP_GET_VARS['category_id'];

  // 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="update phpgw_bk_categories set description='$description' where category_id=$category_id";
    $phpgw->db->query($sql);
    header("Location: ".$phpgw->link("/bookkeeping/categories.php","selected=$selected&order=$order"));
  }
  else
  {
    $phpgw->template->set_file(array( "category_edit" => "category_edit.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("edit_expense_category");
    }
    else
    {
      $lang_selected=lang("edit_income_category");
    }

    $phpgw->template->set_var("lang_selected",$lang_selected);
    $phpgw->template->set_var("lang_go_back",'<a href="'.$phpgw->link("/bookkeeping/categories.php","selected=$selected&order=$order").'">'.lang("go_back").'</a>');

    $sql="select description from phpgw_bk_categories where category_id=$category_id";
    $phpgw->db->query($sql);
    $phpgw->db->next_record();

    $lang_description=lang("description");
    $description="<input type=\"text\" name=\"description\" value=\"".$phpgw->db->f("description")."\">";

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

    $phpgw->template->set_var("actionurl",$phpgw->link("/bookkeeping/category_edit.php","selected=$selected&order=$order&category_id=$category_id"));
    $phpgw->template->set_var("lang_edit",lang("edit"));
    $phpgw->template->parse("out", "category_edit", true);
    $phpgw->template->p("out");
  }

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