<?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_add.php,v 1.7 2001/05/21 22:09:38 darw1n Exp $ */

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

if (!$account_id == '') {
	$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(!$account_id == '') {
	$phpgw->db->query("SELECT value FROM phpgw_bk_configuration WHERE name='admins' AND bookkeeping_id=0");
	$phpgw->db->next_record();
	$bk_admins = $phpgw->db->f('value');
	if($bk_admins == '') {
		$bk_admins = $account_id;
	} else {
		$bk_admins .= (':' . $account_id);
	}
	$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 {
	$template = CreateObject('phpgwapi.Template',PHPGW_APP_TPL);

	$template->set_file(array('admin_add' => 'admin_add.tpl'));
	$template->set_block('admin_add', 'bk_admin_list', 'bk_admins');

	$template->set_var('lang_app_title', lang('bookkeeping'));
	$template->set_var('lang_title', lang('bookkkeeping admins'));
	$head_color = $phpgw_info['theme']['th_bg'];
	$template->set_var('head_color', $head_color);
	$template->set_var('lang_loginid', lang('loginid'));
	$template->set_var('lang_lastname', lang('lastname'));
	$template->set_var('lang_firstname', lang('firstname'));
	$template->set_var('lang_add', lang('add'));

	$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'));
	$phpgw->db->query("SELECT account_id,account_lid,account_firstname,account_lastname FROM phpgw_accounts WHERE account_status='A' AND account_type='u' ORDER BY account_lastname");
	while($phpgw->db->next_record()) {
		$selected = False;
		for($j = 0; $j < count($bk_admin); $j++) {
			if($phpgw->db->f('account_id') == $bk_admin[$j]) {
				$selected = True;
			}
		}
		if(!$selected) {
			$tr_color = $phpgw->nextmatchs->alternate_row_color($tr_color);
			$template->set_var('tr_color', $tr_color);
			$template->set_var('checkbox', $phpgw->db->f('account_id'));
			$template->set_var('loginid', $phpgw->db->f('account_lid'));
			$template->set_var('firstname', $phpgw->db->f('account_firstname'));
			$template->set_var('lastname', $phpgw->db->f('account_lastname'));
			$template->set_var('add', '<a href="'.$phpgw->link('/bookkeeping/admin_add.php','account_id='.$phpgw->db->f('account_id')).'">'.lang('add').'</a>');
			$template->parse('bk_admins', 'bk_admin_list', true);
		}
	}

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

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

?>
