<?php
/**********************************************************************
    Copyright (C) FrontAccounting, LLC.
	Released under the terms of the GNU General Public License, GPL, 
	as published by the Free Software Foundation, either version 3 
	of the License, or (at your option) any later version.
    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
    See the License here <http://www.gnu.org/licenses/gpl-3.0.html>.
***********************************************************************/
$page_security = 'SA_SETUPCOMPANY';
$path_to_root="../../..";
include_once($path_to_root . "/includes/db_pager.inc");
include($path_to_root . "/includes/session.inc");
add_access_extensions();

page(_($help_context = "Suspense Accounts"));

include_once($path_to_root . "/includes/ui.inc");
include_once($path_to_root . "/modules/church/includes/church_db.inc");
include_once($path_to_root . "/modules/church/includes/church_ui.inc");
include_once($path_to_root . '/modules/kanban/includes/kanban_db.inc');
include_once($path_to_root . '/modules/kanban/includes/kanban_ui.inc');
include_once($path_to_root . "/includes/data_checks.inc");

include_once($path_to_root . "/admin/db/company_db.inc");

//-------------------------------------------------------------------------------------------------
// initialize stuff just in case
$init = 0;
if (get_company_pref('member_suspense_account') === null) {
	set_company_pref('member_suspense_account', 'system.external', 'varchar', 10, 'MAIL');
	$init++;
}

if (get_company_pref('project_suspense_account') === null) {
	set_company_pref('project_suspense_account', 'system.external', 'varchar', 60, 'localhost');
	$init++;
}

//if ($init)
//    refresh_sys_prefs();


function can_process() {
    $errors = 0;
    
    if (empty($_POST['project_suspense_account']) ) {
	$errors++;
	display_error(_("Project must be entered."));
    }

    if (empty($_POST['member_suspense_account']) ) {
	$errors++;
	display_error(_("Member must be entered."));
    }
    
    return ($errors == 0);
}


//-------------------------------------------------------------------------------------------------

if (isset($_POST['submit']) && can_process()) {
	update_company_prefs( get_post( array( 'member_suspense_account', 'project_suspense_account')));

	display_notification(_("Suspense account settings has been updated."));

}

$prefs = get_company_prefs();

$_POST['member_suspense_account'] = $prefs['member_suspense_account'];
$_POST['project_suspense_account'] = $prefs['project_suspense_account'];
//-------------------------------------------------------------------------------------------------


start_form();
div_start('details');
{
    start_table(TABLESTYLE2);
    member_list_row('Suspense Member:', 'member_suspense_account', get_post('member_suspense_account'));
    projects_list_row('Suspense Project:', 'project_suspense_account', get_post('project_suspense_account'));
    end_table(1);
}
div_end();
echo '<center>';
submit('submit', _("Update"), true, '', 'default');
echo '</center>';

end_form(2);

//-------------------------------------------------------------------------------------------------

end_page();

?>
