<?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.                                              *
  \**************************************************************************/

// --- BEGIN HTTP_GET_VARS ---
  $order=$HTTP_GET_VARS['order'];
  $selected=$HTTP_GET_VARS['selected'];
  $category_id_id=$HTTP_GET_VARS['category_id'];
// --- END HTTP_GET_VARS ---

// --- BEGIN HTTP_POST_VARS ---
  $yesno=$HTTP_POST_VARS["yesno"];
  $submit=$HTTP_POST_VARS["submit"];
// --- END HTTP_POST_VARS ---

  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=='')
  {
    if($yesno=='Yes')
    {
      $sql="delete from phpgw_bk_categories where category_id=$category_id";
      $phpgw->db->query($sql);
      header("Location: ".$phpgw->link('/bookkeeping/categories.php',"selected=$selected&order=$order"));
      exit;
    }
    else
    {
      header("Location: ".$phpgw->link('/bookkeeping/categories.php',"selected=$selected&order=$order"));
      exit;
    }
  }
  else
  {
    $phpgw->template->set_file(array( "category_delete" => "category_delete.tpl"));
    $phpgw->template->set_block("category_delete", "category_fields", "category_fields_t");

    $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("delete_expense_category");
    }
    else
    {
      $lang_selected=lang("delete_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>');

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

    $lang_description=lang("description").": ";
    $phpgw->template->set_var("lang_category_field",$lang_description);
    $description = $phpgw->db->f("description");
    $phpgw->template->set_var("category_field",$description);
    $color=row_color($color);
    $phpgw->template->set_var(color,$color);
    $phpgw->template->parse("category_fields_t", "category_fields", true);

    $phpgw->template->set_var("actionurl",$phpgw->link("/bookkeeping/category_delete","category_id=$category_id&selected=$selected&order=$order"));
    $phpgw->template->set_var("remove_this_category",lang("remove_this_category"));
    $phpgw->template->set_var("submit",lang("submit"));

    $selectbox='<select name="yesno">';
    $selectbox.='<option selected>No<option>Yes';
    $selectbox.="</select>";

    $phpgw->template->set_var("selectbox",$selectbox);
    $phpgw->template->parse("out", "category_delete", true);
    $phpgw->template->p("out");

    $phpgw->common->phpgw_footer();

  }
?>
