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

/* $Id: admin_delete.php,v 1.7 2001/05/21 22:09:38 darw1n Exp $ */

// HTTP_POST_VARS 
$yesno = $HTTP_POST_VARS['yesno'];
$submit = $HTTP_POST_VARS['submit'];

// HTTP_GET_VARS
$account_id = $HTTP_GET_VARS['account_id'];

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

if(!$submit == '') {
	if($yesno == 'Yes') {
		$phpgw->db->query("SELECT value FROM phpgw_bk_configuration WHERE name='admins' AND bookkeeping_id=0");
		$phpgw->db->next_record();
		$bk_admin = split(':', $phpgw->db->f('value'));
		$bk_admins = '';
		for($i = 0; $i < count($bk_admin); $i++) {
			if($bk_admin[$i] != $account_id) {
				if($bk_admins == '') {
					$bk_admins .= $bk_admin[$i];
				} else {
					$bk_admins .= ':' . $bk_admin[$i];
				}
			}
		}
		if($bk_admins == '') {
			$phpgw->db->query("UPDATE phpgw_bk_configuration SET value=NULL WHERE name='admins' AND bookkeeping_id=0");
		} else {
			$phpgw->db->query("UPDATE phpgw_bk_configuration SET value='$bk_admins' WHERE name='admins' AND bookkeeping_id=0");
		}
		header("Location: " . $phpgw->link('/bookkeeping/admin.php'));
		exit;
	} else {
		header('Location: ' . $phpgw->link('/bookkeeping/admin.php'));
		exit;
	}
} else {
	$template = CreateObject('phpgwapi.Template',PHPGW_APP_TPL);

	$template->set_file(array('admin_delete' => 'admin_delete.tpl'));

	$tr_color = $phpgw->nextmatchs->alternate_row_color($tr_color);
	$template->set_var('tr_color_1', $tr_color);
	$tr_color = $phpgw->nextmatchs->alternate_row_color($tr_color);
	$template->set_var('tr_color_2', $tr_color);
	$template->set_var('lang_app_title', lang('bookkeeping'));
	$template->set_var('lang_title', lang('bookkeeping admins'));
	$head_color = $phpgw_info['theme']['th_bg'];
	$template->set_var('head_color', $head_color);
	$template->set_var('actionurl', $phpgw->link('/bookkeeping/admin_delete.php','account_id='  . $account_id));
	$template->set_var('remove_this_bookkeeping_admin', lang('remove_this_bookkeeping_admin'));
	$template->set_var('submit', lang('submit'));
	$selectbox  = '<select name="yesno">';
	$selectbox .= '<option selected>No<option>Yes';
	$selectbox .= '</select>';
	$template->set_var('selectbox', $selectbox);

	$template->parse('out', 'admin_delete', true);
	$template->p('out');

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

?>
